diff options
-rw-r--r-- | Documentation/hwmon/twl4030-madc-hwmon | 45 | ||||
-rw-r--r-- | drivers/hwmon/Kconfig | 10 | ||||
-rw-r--r-- | drivers/hwmon/Makefile | 1 | ||||
-rw-r--r-- | drivers/hwmon/twl4030-madc-hwmon.c | 157 |
4 files changed, 213 insertions, 0 deletions
diff --git a/Documentation/hwmon/twl4030-madc-hwmon b/Documentation/hwmon/twl4030-madc-hwmon new file mode 100644 index 000000000000..ef7984317cec --- /dev/null +++ b/Documentation/hwmon/twl4030-madc-hwmon | |||
@@ -0,0 +1,45 @@ | |||
1 | Kernel driver twl4030-madc | ||
2 | ========================= | ||
3 | |||
4 | Supported chips: | ||
5 | * Texas Instruments TWL4030 | ||
6 | Prefix: 'twl4030-madc' | ||
7 | |||
8 | |||
9 | Authors: | ||
10 | J Keerthy <j-keerthy@ti.com> | ||
11 | |||
12 | Description | ||
13 | ----------- | ||
14 | |||
15 | The Texas Instruments TWL4030 is a Power Management and Audio Circuit. Among | ||
16 | other things it contains a 10-bit A/D converter MADC. The converter has 16 | ||
17 | channels which can be used in different modes. | ||
18 | |||
19 | |||
20 | See this table for the meaning of the different channels | ||
21 | |||
22 | Channel Signal | ||
23 | ------------------------------------------ | ||
24 | 0 Battery type(BTYPE) | ||
25 | 1 BCI: Battery temperature (BTEMP) | ||
26 | 2 GP analog input | ||
27 | 3 GP analog input | ||
28 | 4 GP analog input | ||
29 | 5 GP analog input | ||
30 | 6 GP analog input | ||
31 | 7 GP analog input | ||
32 | 8 BCI: VBUS voltage(VBUS) | ||
33 | 9 Backup Battery voltage (VBKP) | ||
34 | 10 BCI: Battery charger current (ICHG) | ||
35 | 11 BCI: Battery charger voltage (VCHG) | ||
36 | 12 BCI: Main battery voltage (VBAT) | ||
37 | 13 Reserved | ||
38 | 14 Reserved | ||
39 | 15 VRUSB Supply/Speaker left/Speaker right polarization level | ||
40 | |||
41 | |||
42 | The Sysfs nodes will represent the voltage in the units of mV, | ||
43 | the temperature channel shows the converted temperature in | ||
44 | degree celcius. The Battery charging current channel represents | ||
45 | battery charging current in mA. | ||
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index e4bd13b3cd8b..81131eda5544 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -1047,6 +1047,16 @@ config SENSORS_TMP421 | |||
1047 | This driver can also be built as a module. If so, the module | 1047 | This driver can also be built as a module. If so, the module |
1048 | will be called tmp421. | 1048 | will be called tmp421. |
1049 | 1049 | ||
1050 | config SENSORS_TWL4030_MADC | ||
1051 | tristate "Texas Instruments TWL4030 MADC Hwmon" | ||
1052 | depends on TWL4030_MADC | ||
1053 | help | ||
1054 | If you say yes here you get hwmon support for triton | ||
1055 | TWL4030-MADC. | ||
1056 | |||
1057 | This driver can also be built as a module. If so it will be called | ||
1058 | twl4030-madc-hwmon. | ||
1059 | |||
1050 | config SENSORS_VIA_CPUTEMP | 1060 | config SENSORS_VIA_CPUTEMP |
1051 | tristate "VIA CPU temperature sensor" | 1061 | tristate "VIA CPU temperature sensor" |
1052 | depends on X86 | 1062 | depends on X86 |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 54ca5939d028..967d0ea9447f 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -104,6 +104,7 @@ obj-$(CONFIG_SENSORS_THMC50) += thmc50.o | |||
104 | obj-$(CONFIG_SENSORS_TMP102) += tmp102.o | 104 | obj-$(CONFIG_SENSORS_TMP102) += tmp102.o |
105 | obj-$(CONFIG_SENSORS_TMP401) += tmp401.o | 105 | obj-$(CONFIG_SENSORS_TMP401) += tmp401.o |
106 | obj-$(CONFIG_SENSORS_TMP421) += tmp421.o | 106 | obj-$(CONFIG_SENSORS_TMP421) += tmp421.o |
107 | obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o | ||
107 | obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o | 108 | obj-$(CONFIG_SENSORS_VIA_CPUTEMP)+= via-cputemp.o |
108 | obj-$(CONFIG_SENSORS_VIA686A) += via686a.o | 109 | obj-$(CONFIG_SENSORS_VIA686A) += via686a.o |
109 | obj-$(CONFIG_SENSORS_VT1211) += vt1211.o | 110 | obj-$(CONFIG_SENSORS_VT1211) += vt1211.o |
diff --git a/drivers/hwmon/twl4030-madc-hwmon.c b/drivers/hwmon/twl4030-madc-hwmon.c new file mode 100644 index 000000000000..97e22bef85ab --- /dev/null +++ b/drivers/hwmon/twl4030-madc-hwmon.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /* | ||
2 | * | ||
3 | * TWL4030 MADC Hwmon driver-This driver monitors the real time | ||
4 | * conversion of analog signals like battery temperature, | ||
5 | * battery type, battery level etc. User can ask for the conversion on a | ||
6 | * particular channel using the sysfs nodes. | ||
7 | * | ||
8 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ | ||
9 | * J Keerthy <j-keerthy@ti.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * version 2 as published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, but | ||
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
23 | * 02110-1301 USA | ||
24 | * | ||
25 | */ | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/i2c/twl.h> | ||
30 | #include <linux/device.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/i2c/twl4030-madc.h> | ||
33 | #include <linux/hwmon.h> | ||
34 | #include <linux/hwmon-sysfs.h> | ||
35 | #include <linux/stddef.h> | ||
36 | #include <linux/sysfs.h> | ||
37 | #include <linux/err.h> | ||
38 | #include <linux/types.h> | ||
39 | |||
40 | /* | ||
41 | * sysfs hook function | ||
42 | */ | ||
43 | static ssize_t madc_read(struct device *dev, | ||
44 | struct device_attribute *devattr, char *buf) | ||
45 | { | ||
46 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
47 | struct twl4030_madc_request req; | ||
48 | long val; | ||
49 | |||
50 | req.channels = (1 << attr->index); | ||
51 | req.method = TWL4030_MADC_SW2; | ||
52 | req.func_cb = NULL; | ||
53 | val = twl4030_madc_conversion(&req); | ||
54 | if (val < 0) | ||
55 | return val; | ||
56 | |||
57 | return sprintf(buf, "%d\n", req.rbuf[attr->index]); | ||
58 | } | ||
59 | |||
60 | /* sysfs nodes to read individual channels from user side */ | ||
61 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, madc_read, NULL, 0); | ||
62 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, madc_read, NULL, 1); | ||
63 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, madc_read, NULL, 2); | ||
64 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, madc_read, NULL, 3); | ||
65 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, madc_read, NULL, 4); | ||
66 | static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, madc_read, NULL, 5); | ||
67 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, madc_read, NULL, 6); | ||
68 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, madc_read, NULL, 7); | ||
69 | static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, madc_read, NULL, 8); | ||
70 | static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, madc_read, NULL, 9); | ||
71 | static SENSOR_DEVICE_ATTR(curr10_input, S_IRUGO, madc_read, NULL, 10); | ||
72 | static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, madc_read, NULL, 11); | ||
73 | static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, madc_read, NULL, 12); | ||
74 | static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, madc_read, NULL, 15); | ||
75 | |||
76 | static struct attribute *twl4030_madc_attributes[] = { | ||
77 | &sensor_dev_attr_in0_input.dev_attr.attr, | ||
78 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
79 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
80 | &sensor_dev_attr_in3_input.dev_attr.attr, | ||
81 | &sensor_dev_attr_in4_input.dev_attr.attr, | ||
82 | &sensor_dev_attr_in5_input.dev_attr.attr, | ||
83 | &sensor_dev_attr_in6_input.dev_attr.attr, | ||
84 | &sensor_dev_attr_in7_input.dev_attr.attr, | ||
85 | &sensor_dev_attr_in8_input.dev_attr.attr, | ||
86 | &sensor_dev_attr_in9_input.dev_attr.attr, | ||
87 | &sensor_dev_attr_curr10_input.dev_attr.attr, | ||
88 | &sensor_dev_attr_in11_input.dev_attr.attr, | ||
89 | &sensor_dev_attr_in12_input.dev_attr.attr, | ||
90 | &sensor_dev_attr_in15_input.dev_attr.attr, | ||
91 | NULL | ||
92 | }; | ||
93 | |||
94 | static const struct attribute_group twl4030_madc_group = { | ||
95 | .attrs = twl4030_madc_attributes, | ||
96 | }; | ||
97 | |||
98 | static int __devinit twl4030_madc_hwmon_probe(struct platform_device *pdev) | ||
99 | { | ||
100 | int ret; | ||
101 | int status; | ||
102 | struct device *hwmon; | ||
103 | |||
104 | ret = sysfs_create_group(&pdev->dev.kobj, &twl4030_madc_group); | ||
105 | if (ret) | ||
106 | goto err_sysfs; | ||
107 | hwmon = hwmon_device_register(&pdev->dev); | ||
108 | if (IS_ERR(hwmon)) { | ||
109 | dev_err(&pdev->dev, "hwmon_device_register failed.\n"); | ||
110 | status = PTR_ERR(hwmon); | ||
111 | goto err_reg; | ||
112 | } | ||
113 | |||
114 | return 0; | ||
115 | |||
116 | err_reg: | ||
117 | sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group); | ||
118 | err_sysfs: | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | static int __devexit twl4030_madc_hwmon_remove(struct platform_device *pdev) | ||
124 | { | ||
125 | hwmon_device_unregister(&pdev->dev); | ||
126 | sysfs_remove_group(&pdev->dev.kobj, &twl4030_madc_group); | ||
127 | |||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static struct platform_driver twl4030_madc_hwmon_driver = { | ||
132 | .probe = twl4030_madc_hwmon_probe, | ||
133 | .remove = __exit_p(twl4030_madc_hwmon_remove), | ||
134 | .driver = { | ||
135 | .name = "twl4030_madc_hwmon", | ||
136 | .owner = THIS_MODULE, | ||
137 | }, | ||
138 | }; | ||
139 | |||
140 | static int __init twl4030_madc_hwmon_init(void) | ||
141 | { | ||
142 | return platform_driver_register(&twl4030_madc_hwmon_driver); | ||
143 | } | ||
144 | |||
145 | module_init(twl4030_madc_hwmon_init); | ||
146 | |||
147 | static void __exit twl4030_madc_hwmon_exit(void) | ||
148 | { | ||
149 | platform_driver_unregister(&twl4030_madc_hwmon_driver); | ||
150 | } | ||
151 | |||
152 | module_exit(twl4030_madc_hwmon_exit); | ||
153 | |||
154 | MODULE_DESCRIPTION("TWL4030 ADC Hwmon driver"); | ||
155 | MODULE_LICENSE("GPL"); | ||
156 | MODULE_AUTHOR("J Keerthy"); | ||
157 | MODULE_ALIAS("twl4030_madc_hwmon"); | ||