aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/viperboard_adc.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-16 21:55:20 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-16 21:55:20 -0500
commit2dfea3803dcf70983d14ce1dcbb3e97a7459a28b (patch)
tree59bffc7389ff554585f79d7cc06021790dc2b317 /drivers/iio/adc/viperboard_adc.c
parentaed606e3bc1f10753254db308d3fd8c053c41328 (diff)
parent1881b68b8961a86d40c3c5c205e533515a2dc9c6 (diff)
Merge tag 'mfd-3.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6
Pull MFS update from Samuel Ortiz: "This is the MFD patch set for the 3.8 merge window. We have several new drivers, most of the time coming with their sub devices drivers: - Austria Microsystem's AS3711 - Nano River's viperboard - TI's TPS80031, AM335x TS/ADC, - Realtek's MMC/memstick card reader - Nokia's retu We also got some notable cleanups and improvements: - tps6586x got converted to IRQ domains. - tps65910 and tps65090 moved to the regmap IRQ API. - STMPE is now Device Tree aware. - A general twl6040 and twl-core cleanup, with moves to the regmap I/O and IRQ APIs and a conversion to the recently added PWM framework. - sta2x11 gained regmap support. Then the rest is mostly tiny cleanups and fixes, among which we have Mark's wm5xxx and wm8xxx patchset." Far amount of annoying but largely trivial conflicts. Many due to __devinit/exit removal, others due to one or two of the new drivers also having come in through another tree. * tag 'mfd-3.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6: (119 commits) mfd: tps6507x: Convert to devm_kzalloc mfd: stmpe: Update DT support for stmpe driver mfd: wm5102: Add readback of DSP status 3 register mfd: arizona: Log if we fail to create the primary IRQ domain mfd: tps80031: MFD_TPS80031 needs to select REGMAP_IRQ mfd: tps80031: Add terminating entry for tps80031_id_table mfd: sta2x11: Fix potential NULL pointer dereference in __sta2x11_mfd_mask() mfd: wm5102: Add tuning for revision B mfd: arizona: Defer patch initialistation until after first device boot mfd: tps65910: Fix wrong ack_base register mfd: tps65910: Remove unused data mfd: stmpe: Get rid of irq_invert_polarity mfd: ab8500-core: Fix invalid free of devm_ allocated data mfd: wm5102: Mark DSP memory regions as volatile mfd: wm5102: Correct default for LDO1_CONTROL_2 mfd: arizona: Register haptics devices mfd: wm8994: Make current device behaviour the default mfd: tps65090: MFD_TPS65090 needs to select REGMAP_IRQ mfd: Fix stmpe.c build when OF is not enabled mfd: jz4740-adc: Use devm_kzalloc ...
Diffstat (limited to 'drivers/iio/adc/viperboard_adc.c')
-rw-r--r--drivers/iio/adc/viperboard_adc.c181
1 files changed, 181 insertions, 0 deletions
diff --git a/drivers/iio/adc/viperboard_adc.c b/drivers/iio/adc/viperboard_adc.c
new file mode 100644
index 000000000000..10136a8b20d4
--- /dev/null
+++ b/drivers/iio/adc/viperboard_adc.c
@@ -0,0 +1,181 @@
1/*
2 * Nano River Technologies viperboard IIO ADC driver
3 *
4 * (C) 2012 by Lemonage GmbH
5 * Author: Lars Poeschel <poeschel@lemonage.de>
6 * All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 */
14
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/types.h>
20#include <linux/mutex.h>
21#include <linux/platform_device.h>
22
23#include <linux/usb.h>
24#include <linux/iio/iio.h>
25
26#include <linux/mfd/viperboard.h>
27
28#define VPRBRD_ADC_CMD_GET 0x00
29
30struct vprbrd_adc_msg {
31 u8 cmd;
32 u8 chan;
33 u8 val;
34} __packed;
35
36struct vprbrd_adc {
37 struct vprbrd *vb;
38};
39
40#define VPRBRD_ADC_CHANNEL(_index) { \
41 .type = IIO_VOLTAGE, \
42 .indexed = 1, \
43 .channel = _index, \
44 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
45 .scan_index = _index, \
46 .scan_type = { \
47 .sign = 'u', \
48 .realbits = 8, \
49 .storagebits = 8, \
50 }, \
51}
52
53static struct iio_chan_spec const vprbrd_adc_iio_channels[] = {
54 VPRBRD_ADC_CHANNEL(0),
55 VPRBRD_ADC_CHANNEL(1),
56 VPRBRD_ADC_CHANNEL(2),
57 VPRBRD_ADC_CHANNEL(3),
58};
59
60static int vprbrd_iio_read_raw(struct iio_dev *iio_dev,
61 struct iio_chan_spec const *chan,
62 int *val,
63 int *val2,
64 long info)
65{
66 int ret, error = 0;
67 struct vprbrd_adc *adc = iio_priv(iio_dev);
68 struct vprbrd *vb = adc->vb;
69 struct vprbrd_adc_msg *admsg = (struct vprbrd_adc_msg *)vb->buf;
70
71 switch (info) {
72 case IIO_CHAN_INFO_RAW:
73 mutex_lock(&vb->lock);
74
75 admsg->cmd = VPRBRD_ADC_CMD_GET;
76 admsg->chan = chan->scan_index;
77 admsg->val = 0x00;
78
79 ret = usb_control_msg(vb->usb_dev,
80 usb_sndctrlpipe(vb->usb_dev, 0), VPRBRD_USB_REQUEST_ADC,
81 VPRBRD_USB_TYPE_OUT, 0x0000, 0x0000, admsg,
82 sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS);
83 if (ret != sizeof(struct vprbrd_adc_msg)) {
84 dev_err(&iio_dev->dev, "usb send error on adc read\n");
85 error = -EREMOTEIO;
86 }
87
88 ret = usb_control_msg(vb->usb_dev,
89 usb_rcvctrlpipe(vb->usb_dev, 0), VPRBRD_USB_REQUEST_ADC,
90 VPRBRD_USB_TYPE_IN, 0x0000, 0x0000, admsg,
91 sizeof(struct vprbrd_adc_msg), VPRBRD_USB_TIMEOUT_MS);
92
93 *val = admsg->val;
94
95 mutex_unlock(&vb->lock);
96
97 if (ret != sizeof(struct vprbrd_adc_msg)) {
98 dev_err(&iio_dev->dev, "usb recv error on adc read\n");
99 error = -EREMOTEIO;
100 }
101
102 if (error)
103 goto error;
104
105 return IIO_VAL_INT;
106 default:
107 error = -EINVAL;
108 break;
109 }
110error:
111 return error;
112}
113
114static const struct iio_info vprbrd_adc_iio_info = {
115 .read_raw = &vprbrd_iio_read_raw,
116 .driver_module = THIS_MODULE,
117};
118
119static int __devinit vprbrd_adc_probe(struct platform_device *pdev)
120{
121 struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent);
122 struct vprbrd_adc *adc;
123 struct iio_dev *indio_dev;
124 int ret;
125
126 /* registering iio */
127 indio_dev = iio_device_alloc(sizeof(*adc));
128 if (!indio_dev) {
129 dev_err(&pdev->dev, "failed allocating iio device\n");
130 return -ENOMEM;
131 }
132
133 adc = iio_priv(indio_dev);
134 adc->vb = vb;
135 indio_dev->name = "viperboard adc";
136 indio_dev->dev.parent = &pdev->dev;
137 indio_dev->info = &vprbrd_adc_iio_info;
138 indio_dev->modes = INDIO_DIRECT_MODE;
139 indio_dev->channels = vprbrd_adc_iio_channels;
140 indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
141
142 ret = iio_device_register(indio_dev);
143 if (ret) {
144 dev_err(&pdev->dev, "could not register iio (adc)");
145 goto error;
146 }
147
148 platform_set_drvdata(pdev, indio_dev);
149
150 return 0;
151
152error:
153 iio_device_free(indio_dev);
154 return ret;
155}
156
157static int __devexit vprbrd_adc_remove(struct platform_device *pdev)
158{
159 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
160
161 iio_device_unregister(indio_dev);
162 iio_device_free(indio_dev);
163
164 return 0;
165}
166
167static struct platform_driver vprbrd_adc_driver = {
168 .driver = {
169 .name = "viperboard-adc",
170 .owner = THIS_MODULE,
171 },
172 .probe = vprbrd_adc_probe,
173 .remove = __devexit_p(vprbrd_adc_remove),
174};
175
176module_platform_driver(vprbrd_adc_driver);
177
178MODULE_AUTHOR("Lars Poeschel <poeschel@lemonage.de>");
179MODULE_DESCRIPTION("IIO ADC driver for Nano River Techs Viperboard");
180MODULE_LICENSE("GPL");
181MODULE_ALIAS("platform:viperboard-adc");