aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/hwmon/mc13783-adc50
-rw-r--r--drivers/hwmon/Kconfig6
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/mc13783-adc.c236
4 files changed, 293 insertions, 0 deletions
diff --git a/Documentation/hwmon/mc13783-adc b/Documentation/hwmon/mc13783-adc
new file mode 100644
index 000000000000..044531a86405
--- /dev/null
+++ b/Documentation/hwmon/mc13783-adc
@@ -0,0 +1,50 @@
1Kernel driver mc13783-adc
2=========================
3
4Supported chips:
5 * Freescale Atlas MC13783
6 Prefix: 'mc13783_adc'
7 Datasheet: http://www.freescale.com/files/rf_if/doc/data_sheet/MC13783.pdf?fsrch=1
8
9Authors:
10 Sascha Hauer <s.hauer@pengutronix.de>
11 Luotao Fu <l.fu@pengutronix.de>
12
13Description
14-----------
15
16The Freescale MC13783 is a Power Management and Audio Circuit. Among
17other things it contains a 10-bit A/D converter. The converter has 16
18channels which can be used in different modes.
19The A/D converter has a resolution of 2.25mV. Channels 0-4 have
20a dedicated meaning with chip internal scaling applied. Channels 5-7
21can be used as general purpose inputs or alternatively in a dedicated
22mode. Channels 12-15 are occupied by the touchscreen if it's active.
23
24Currently the driver only supports channels 2 and 5-15 with no alternative
25modes for channels 5-7.
26
27See this table for the meaning of the different channels and their chip
28internal scaling:
29
30Channel Signal Input Range Scaling
31-------------------------------------------------------------------------------
320 Battery Voltage (BATT) 2.50 - 4.65V -2.40V
331 Battery Current (BATT - BATTISNS) -50 - 50 mV x20
342 Application Supply (BP) 2.50 - 4.65V -2.40V
353 Charger Voltage (CHRGRAW) 0 - 10V / /5
36 0 - 20V /10
374 Charger Current (CHRGISNSP-CHRGISNSN) -0.25V - 0.25V x4
385 General Purpose ADIN5 / Battery Pack Thermistor 0 - 2.30V No
396 General Purpose ADIN6 / Backup Voltage (LICELL) 0 - 2.30V / No /
40 1.50 - 3.50V -1.20V
417 General Purpose ADIN7 / UID / Die Temperature 0 - 2.30V / No /
42 0 - 2.55V / x0.9 / No
438 General Purpose ADIN8 0 - 2.30V No
449 General Purpose ADIN9 0 - 2.30V No
4510 General Purpose ADIN10 0 - 2.30V No
4611 General Purpose ADIN11 0 - 2.30V No
4712 General Purpose TSX1 / Touchscreen X-plate 1 0 - 2.30V No
4813 General Purpose TSX2 / Touchscreen X-plate 2 0 - 2.30V No
4914 General Purpose TSY1 / Touchscreen Y-plate 1 0 - 2.30V No
5015 General Purpose TSY2 / Touchscreen Y-plate 2 0 - 2.30V No
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 6e7c30b8caab..dd6939370f75 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1017,6 +1017,12 @@ config SENSORS_APPLESMC
1017 Say Y here if you have an applicable laptop and want to experience 1017 Say Y here if you have an applicable laptop and want to experience
1018 the awesome power of applesmc. 1018 the awesome power of applesmc.
1019 1019
1020config SENSORS_MC13783_ADC
1021 tristate "Freescale MC13783 ADC"
1022 depends on MFD_MC13783
1023 help
1024 Support for the A/D converter on MC13783 PMIC.
1025
1020if ACPI 1026if ACPI
1021 1027
1022comment "ACPI drivers" 1028comment "ACPI drivers"
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index a24a52d12dc5..33c2ee105284 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -74,6 +74,7 @@ obj-$(CONFIG_SENSORS_LTC4245) += ltc4245.o
74obj-$(CONFIG_SENSORS_MAX1111) += max1111.o 74obj-$(CONFIG_SENSORS_MAX1111) += max1111.o
75obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 75obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
76obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 76obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
77obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
77obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 78obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
78obj-$(CONFIG_SENSORS_PC87427) += pc87427.o 79obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
79obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 80obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
new file mode 100644
index 000000000000..883fa8197da4
--- /dev/null
+++ b/drivers/hwmon/mc13783-adc.c
@@ -0,0 +1,236 @@
1/*
2 * Driver for the Freescale Semiconductor MC13783 adc.
3 *
4 * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
5 * Copyright (C) 2009 Sascha Hauer, Pengutronix
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 51
18 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <linux/mfd/mc13783-private.h>
22#include <linux/platform_device.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/hwmon.h>
27#include <linux/init.h>
28#include <linux/err.h>
29
30#define MC13783_ADC_NAME "mc13783-adc"
31
32struct mc13783_adc_priv {
33 struct mc13783 *mc13783;
34 struct device *hwmon_dev;
35};
36
37static ssize_t mc13783_adc_show_name(struct device *dev, struct device_attribute
38 *devattr, char *buf)
39{
40 return sprintf(buf, "mc13783_adc\n");
41}
42
43static int mc13783_adc_read(struct device *dev,
44 struct device_attribute *devattr, unsigned int *val)
45{
46 struct platform_device *pdev = to_platform_device(dev);
47 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
48 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
49 unsigned int channel = attr->index;
50 unsigned int sample[4];
51 int ret;
52
53 ret = mc13783_adc_do_conversion(priv->mc13783,
54 MC13783_ADC_MODE_MULT_CHAN,
55 channel, sample);
56 if (ret)
57 return ret;
58
59 channel &= 0x7;
60
61 *val = (sample[channel % 4] >> (channel > 3 ? 14 : 2)) & 0x3ff;
62
63 return 0;
64}
65
66static ssize_t mc13783_adc_read_bp(struct device *dev,
67 struct device_attribute *devattr, char *buf)
68{
69 unsigned val;
70 int ret = mc13783_adc_read(dev, devattr, &val);
71
72 if (ret)
73 return ret;
74
75 /*
76 * BP (channel 2) reports with offset 2.4V to the actual value to fit
77 * the input range of the ADC. unit = 2.25mV = 9/4 mV.
78 */
79 val = DIV_ROUND_CLOSEST(val * 9, 4) + 2400;
80
81 return sprintf(buf, "%u\n", val);
82}
83
84static ssize_t mc13783_adc_read_gp(struct device *dev,
85 struct device_attribute *devattr, char *buf)
86{
87 unsigned val;
88 int ret = mc13783_adc_read(dev, devattr, &val);
89
90 if (ret)
91 return ret;
92
93 /*
94 * input range is [0, 2.3V], val has 10 bits, so each bit
95 * is worth 9/4 mV.
96 */
97 val = DIV_ROUND_CLOSEST(val * 9, 4);
98
99 return sprintf(buf, "%u\n", val);
100}
101
102static DEVICE_ATTR(name, S_IRUGO, mc13783_adc_show_name, NULL);
103static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, mc13783_adc_read_bp, NULL, 2);
104static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, mc13783_adc_read_gp, NULL, 5);
105static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, mc13783_adc_read_gp, NULL, 6);
106static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, mc13783_adc_read_gp, NULL, 7);
107static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, mc13783_adc_read_gp, NULL, 8);
108static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, mc13783_adc_read_gp, NULL, 9);
109static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, mc13783_adc_read_gp, NULL, 10);
110static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, mc13783_adc_read_gp, NULL, 11);
111static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, mc13783_adc_read_gp, NULL, 12);
112static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, mc13783_adc_read_gp, NULL, 13);
113static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, mc13783_adc_read_gp, NULL, 14);
114static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, mc13783_adc_read_gp, NULL, 15);
115
116static struct attribute *mc13783_attr[] = {
117 &dev_attr_name.attr,
118 &sensor_dev_attr_in2_input.dev_attr.attr,
119 &sensor_dev_attr_in5_input.dev_attr.attr,
120 &sensor_dev_attr_in6_input.dev_attr.attr,
121 &sensor_dev_attr_in7_input.dev_attr.attr,
122 &sensor_dev_attr_in8_input.dev_attr.attr,
123 &sensor_dev_attr_in9_input.dev_attr.attr,
124 &sensor_dev_attr_in10_input.dev_attr.attr,
125 &sensor_dev_attr_in11_input.dev_attr.attr,
126 NULL
127};
128
129static const struct attribute_group mc13783_group = {
130 .attrs = mc13783_attr,
131};
132
133/* last four channels may be occupied by the touchscreen */
134static struct attribute *mc13783_attr_ts[] = {
135 &sensor_dev_attr_in12_input.dev_attr.attr,
136 &sensor_dev_attr_in13_input.dev_attr.attr,
137 &sensor_dev_attr_in14_input.dev_attr.attr,
138 &sensor_dev_attr_in15_input.dev_attr.attr,
139 NULL
140};
141
142static const struct attribute_group mc13783_group_ts = {
143 .attrs = mc13783_attr_ts,
144};
145
146static int __init mc13783_adc_probe(struct platform_device *pdev)
147{
148 struct mc13783_adc_priv *priv;
149 int ret;
150
151 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
152 if (!priv)
153 return -ENOMEM;
154
155 priv->mc13783 = dev_get_drvdata(pdev->dev.parent);
156
157 platform_set_drvdata(pdev, priv);
158
159 /* Register sysfs hooks */
160 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group);
161 if (ret)
162 goto out_err_create1;
163
164 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN))
165 ret = sysfs_create_group(&pdev->dev.kobj, &mc13783_group_ts);
166 if (ret)
167 goto out_err_create2;
168
169 priv->hwmon_dev = hwmon_device_register(&pdev->dev);
170 if (IS_ERR(priv->hwmon_dev)) {
171 ret = PTR_ERR(priv->hwmon_dev);
172 dev_err(&pdev->dev,
173 "hwmon_device_register failed with %d.\n", ret);
174 goto out_err_register;
175 }
176
177
178 return 0;
179
180out_err_register:
181
182 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN))
183 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
184out_err_create2:
185
186 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
187out_err_create1:
188
189 platform_set_drvdata(pdev, NULL);
190 kfree(priv);
191
192 return ret;
193}
194
195static int __devexit mc13783_adc_remove(struct platform_device *pdev)
196{
197 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
198
199 hwmon_device_unregister(priv->hwmon_dev);
200
201 if (!(priv->mc13783->flags & MC13783_USE_TOUCHSCREEN))
202 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group_ts);
203
204 sysfs_remove_group(&pdev->dev.kobj, &mc13783_group);
205
206 platform_set_drvdata(pdev, NULL);
207 kfree(priv);
208
209 return 0;
210}
211
212static struct platform_driver mc13783_adc_driver = {
213 .remove = __devexit_p(mc13783_adc_remove),
214 .driver = {
215 .owner = THIS_MODULE,
216 .name = MC13783_ADC_NAME,
217 },
218};
219
220static int __init mc13783_adc_init(void)
221{
222 return platform_driver_probe(&mc13783_adc_driver, mc13783_adc_probe);
223}
224
225static void __exit mc13783_adc_exit(void)
226{
227 platform_driver_unregister(&mc13783_adc_driver);
228}
229
230module_init(mc13783_adc_init);
231module_exit(mc13783_adc_exit);
232
233MODULE_DESCRIPTION("MC13783 ADC driver");
234MODULE_AUTHOR("Luotao Fu <l.fu@pengutronix.de>");
235MODULE_LICENSE("GPL");
236MODULE_ALIAS("platform:" MC13783_ADC_NAME);