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