aboutsummaryrefslogtreecommitdiff
path: root/drivers/misc/mmi-sar.c
blob: 845bab364a01169b9eef90c763b4ae507991d6d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (C) 2014 Motorola Mobility LLC
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <linux/module.h>
#include <linux/platform_device.h>

static BLOCKING_NOTIFIER_HEAD(sar_wifi_notifier_list);

static int wifi_max_tx_power = -1;

int register_notifier_by_sar(struct notifier_block *nb)
{
	int ret;
	ret = blocking_notifier_chain_register(
		&sar_wifi_notifier_list, nb);
	if (ret == 0 && wifi_max_tx_power > 0) {
		blocking_notifier_call_chain(
				&sar_wifi_notifier_list,
				0, &wifi_max_tx_power);
	}
	return ret;
}

int unregister_notifier_by_sar(struct notifier_block *nb)
{
	return blocking_notifier_chain_unregister(
			&sar_wifi_notifier_list, nb);
}

static ssize_t store_sar_wifi(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t count)
{
	sscanf(buf, "%d", &wifi_max_tx_power);
	pr_info("%s: set wifi tx power limit = %d\n", __func__, wifi_max_tx_power);
	blocking_notifier_call_chain(&sar_wifi_notifier_list,
			0, &wifi_max_tx_power);
	return count;
}

static struct kobj_attribute mmi_sar_wifi =
	__ATTR(sar_wifi, 0220, (void *)NULL, (void *)store_sar_wifi);

static struct attribute *mmi_sar_attrs[] = {
	&mmi_sar_wifi.attr,
	NULL,
};

static struct attribute_group mmi_sar_attr_grp = {
	.attrs = mmi_sar_attrs,
};

static int mmi_sar_probe(struct platform_device *pdev)
{
	int ret;
	pr_debug("%s\n", __func__);
	ret = sysfs_create_group(&pdev->dev.kobj, &mmi_sar_attr_grp);
	return ret;
}

static int mmi_sar_remove(struct platform_device *pdev)
{
	pr_debug("%s\n", __func__);
	sysfs_remove_group(&pdev->dev.kobj, &mmi_sar_attr_grp);
	return 0;
}

static const struct of_device_id mmi_sar_ctrl_match[] = {
	{ .compatible = "mmi,mmi_sar_ctrl", },
	{}
};
MODULE_DEVICE_TABLE(of, mmi_sar_ctrl_match);

static struct platform_driver mmi_sar_plat_driver = {
	.probe = mmi_sar_probe,
	.remove = mmi_sar_remove,
	.driver = {
		.name = "mmi_sar_ctrl",
		.owner = THIS_MODULE,
		.of_match_table = mmi_sar_ctrl_match,
	},
};

module_platform_driver(mmi_sar_plat_driver);

MODULE_ALIAS("platform:mmi_sar");
MODULE_AUTHOR("Motorola Mobility LLC");
MODULE_DESCRIPTION("Motorola Mobility SAR Controls");
MODULE_LICENSE("GPL");