aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2010-06-19 14:32:58 -0400
committerRalf Baechle <ralf@linux-mips.org>2010-08-05 08:26:19 -0400
commit7f983ba93d449972d5f372f12c6ad32d86ef30b4 (patch)
treeea152a93fd73526209dbf17e31d11d28b581e17f /drivers/hwmon
parent2249071b3e03747884d0781ab10b0b9ceac5756b (diff)
HWMON: Add JZ4740 ADC driver
Add support for reading the ADCIN pin of the ADC unit on JZ4740 SoCs. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Cc: lm-sensors@lm-sensors.org Acked-by: Jean Delvare <khali@linux-fr.org> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/1425/ Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig10
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/jz4740-hwmon.c230
3 files changed, 241 insertions, 0 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index e19cf8eb6ccf..c57e530d07c7 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -446,6 +446,16 @@ config SENSORS_IT87
446 This driver can also be built as a module. If so, the module 446 This driver can also be built as a module. If so, the module
447 will be called it87. 447 will be called it87.
448 448
449config SENSORS_JZ4740
450 tristate "Ingenic JZ4740 SoC ADC driver"
451 depends on MACH_JZ4740 && MFD_JZ4740_ADC
452 help
453 If you say yes here you get support for reading adc values from the ADCIN
454 pin on Ingenic JZ4740 SoC based boards.
455
456 This driver can also be build as a module. If so, the module will be
457 called jz4740-hwmon.
458
449config SENSORS_LM63 459config SENSORS_LM63
450 tristate "National Semiconductor LM63 and LM64" 460 tristate "National Semiconductor LM63 and LM64"
451 depends on I2C 461 depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 2138ceb1a713..c5057745b068 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o
55obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o 55obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
56obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o 56obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
57obj-$(CONFIG_SENSORS_IT87) += it87.o 57obj-$(CONFIG_SENSORS_IT87) += it87.o
58obj-$(CONFIG_SENSORS_JZ4740) += jz4740-hwmon.o
58obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o 59obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
59obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o 60obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
60obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o 61obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o hp_accel.o
diff --git a/drivers/hwmon/jz4740-hwmon.c b/drivers/hwmon/jz4740-hwmon.c
new file mode 100644
index 000000000000..1c8b3d9e2051
--- /dev/null
+++ b/drivers/hwmon/jz4740-hwmon.c
@@ -0,0 +1,230 @@
1/*
2 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
3 * JZ4740 SoC HWMON driver
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * You should have received a copy of the GNU General Public License along
11 * with this program; if not, write to the Free Software Foundation, Inc.,
12 * 675 Mass Ave, Cambridge, MA 02139, USA.
13 *
14 */
15
16#include <linux/err.h>
17#include <linux/interrupt.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/mutex.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23
24#include <linux/completion.h>
25#include <linux/mfd/core.h>
26
27#include <linux/hwmon.h>
28
29struct jz4740_hwmon {
30 struct resource *mem;
31 void __iomem *base;
32
33 int irq;
34
35 struct mfd_cell *cell;
36 struct device *hwmon;
37
38 struct completion read_completion;
39
40 struct mutex lock;
41};
42
43static ssize_t jz4740_hwmon_show_name(struct device *dev,
44 struct device_attribute *dev_attr, char *buf)
45{
46 return sprintf(buf, "jz4740\n");
47}
48
49static irqreturn_t jz4740_hwmon_irq(int irq, void *data)
50{
51 struct jz4740_hwmon *hwmon = data;
52
53 complete(&hwmon->read_completion);
54 return IRQ_HANDLED;
55}
56
57static ssize_t jz4740_hwmon_read_adcin(struct device *dev,
58 struct device_attribute *dev_attr, char *buf)
59{
60 struct jz4740_hwmon *hwmon = dev_get_drvdata(dev);
61 struct completion *completion = &hwmon->read_completion;
62 unsigned long t;
63 unsigned long val;
64 int ret;
65
66 mutex_lock(&hwmon->lock);
67
68 INIT_COMPLETION(*completion);
69
70 enable_irq(hwmon->irq);
71 hwmon->cell->enable(to_platform_device(dev));
72
73 t = wait_for_completion_interruptible_timeout(completion, HZ);
74
75 if (t > 0) {
76 val = readw(hwmon->base) & 0xfff;
77 val = (val * 3300) >> 12;
78 ret = sprintf(buf, "%lu\n", val);
79 } else {
80 ret = t ? t : -ETIMEDOUT;
81 }
82
83 hwmon->cell->disable(to_platform_device(dev));
84 disable_irq(hwmon->irq);
85
86 mutex_unlock(&hwmon->lock);
87
88 return ret;
89}
90
91static DEVICE_ATTR(name, S_IRUGO, jz4740_hwmon_show_name, NULL);
92static DEVICE_ATTR(in0_input, S_IRUGO, jz4740_hwmon_read_adcin, NULL);
93
94static struct attribute *jz4740_hwmon_attributes[] = {
95 &dev_attr_name.attr,
96 &dev_attr_in0_input.attr,
97 NULL
98};
99
100static const struct attribute_group jz4740_hwmon_attr_group = {
101 .attrs = jz4740_hwmon_attributes,
102};
103
104static int __devinit jz4740_hwmon_probe(struct platform_device *pdev)
105{
106 int ret;
107 struct jz4740_hwmon *hwmon;
108
109 hwmon = kmalloc(sizeof(*hwmon), GFP_KERNEL);
110 if (!hwmon) {
111 dev_err(&pdev->dev, "Failed to allocate driver structure\n");
112 return -ENOMEM;
113 }
114
115 hwmon->cell = pdev->dev.platform_data;
116
117 hwmon->irq = platform_get_irq(pdev, 0);
118 if (hwmon->irq < 0) {
119 ret = hwmon->irq;
120 dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
121 goto err_free;
122 }
123
124 hwmon->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
125 if (!hwmon->mem) {
126 ret = -ENOENT;
127 dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
128 goto err_free;
129 }
130
131 hwmon->mem = request_mem_region(hwmon->mem->start,
132 resource_size(hwmon->mem), pdev->name);
133 if (!hwmon->mem) {
134 ret = -EBUSY;
135 dev_err(&pdev->dev, "Failed to request mmio memory region\n");
136 goto err_free;
137 }
138
139 hwmon->base = ioremap_nocache(hwmon->mem->start,
140 resource_size(hwmon->mem));
141 if (!hwmon->base) {
142 ret = -EBUSY;
143 dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
144 goto err_release_mem_region;
145 }
146
147 init_completion(&hwmon->read_completion);
148 mutex_init(&hwmon->lock);
149
150 platform_set_drvdata(pdev, hwmon);
151
152 ret = request_irq(hwmon->irq, jz4740_hwmon_irq, 0, pdev->name, hwmon);
153 if (ret) {
154 dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
155 goto err_iounmap;
156 }
157 disable_irq(hwmon->irq);
158
159 ret = sysfs_create_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
160 if (ret) {
161 dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", ret);
162 goto err_free_irq;
163 }
164
165 hwmon->hwmon = hwmon_device_register(&pdev->dev);
166 if (IS_ERR(hwmon->hwmon)) {
167 ret = PTR_ERR(hwmon->hwmon);
168 goto err_remove_file;
169 }
170
171 return 0;
172
173err_remove_file:
174 sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
175err_free_irq:
176 free_irq(hwmon->irq, hwmon);
177err_iounmap:
178 platform_set_drvdata(pdev, NULL);
179 iounmap(hwmon->base);
180err_release_mem_region:
181 release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
182err_free:
183 kfree(hwmon);
184
185 return ret;
186}
187
188static int __devexit jz4740_hwmon_remove(struct platform_device *pdev)
189{
190 struct jz4740_hwmon *hwmon = platform_get_drvdata(pdev);
191
192 hwmon_device_unregister(hwmon->hwmon);
193 sysfs_remove_group(&pdev->dev.kobj, &jz4740_hwmon_attr_group);
194
195 free_irq(hwmon->irq, hwmon);
196
197 iounmap(hwmon->base);
198 release_mem_region(hwmon->mem->start, resource_size(hwmon->mem));
199
200 platform_set_drvdata(pdev, NULL);
201 kfree(hwmon);
202
203 return 0;
204}
205
206struct platform_driver jz4740_hwmon_driver = {
207 .probe = jz4740_hwmon_probe,
208 .remove = __devexit_p(jz4740_hwmon_remove),
209 .driver = {
210 .name = "jz4740-hwmon",
211 .owner = THIS_MODULE,
212 },
213};
214
215static int __init jz4740_hwmon_init(void)
216{
217 return platform_driver_register(&jz4740_hwmon_driver);
218}
219module_init(jz4740_hwmon_init);
220
221static void __exit jz4740_hwmon_exit(void)
222{
223 platform_driver_unregister(&jz4740_hwmon_driver);
224}
225module_exit(jz4740_hwmon_exit);
226
227MODULE_DESCRIPTION("JZ4740 SoC HWMON driver");
228MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
229MODULE_LICENSE("GPL");
230MODULE_ALIAS("platform:jz4740-hwmon");