aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2012-08-12 11:21:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-08-16 15:18:38 -0400
commitbc2c90c974a0ed390327bbd94f49269e9f24e280 (patch)
tree515cf5f112c5b4662e36681a8f7c479e2847bf94
parent6cffc1f814b25d59ca6f0cd75b64bb159801c0fa (diff)
IIO: Add basic MXS LRADC driver
This driver is very basic. It supports userland trigger, buffer and raw access to channels. The support for delay channels is missing altogether. Signed-off-by: Marek Vasut <marex@denx.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Cc: Jonathan Cameron <jic23@kernel.org> Cc: Juergen Beisert <jbe@pengutronix.de> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Shawn Guo <shawn.guo@linaro.org> Cc: Wolfgang Denk <wd@denx.de>
-rw-r--r--Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt15
-rw-r--r--drivers/staging/iio/adc/Kconfig12
-rw-r--r--drivers/staging/iio/adc/Makefile1
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c590
4 files changed, 618 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
new file mode 100644
index 000000000000..801d58cb6d4d
--- /dev/null
+++ b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
@@ -0,0 +1,15 @@
1* Freescale i.MX28 LRADC device driver
2
3Required properties:
4- compatible: Should be "fsl,imx28-lradc"
5- reg: Address and length of the register set for the device
6- interrupts: Should contain the LRADC interrupts
7
8Examples:
9
10 lradc@80050000 {
11 compatible = "fsl,imx28-lradc";
12 reg = <0x80050000 0x2000>;
13 interrupts = <10 14 15 16 17 18 19
14 20 21 22 23 24 25>;
15 };
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 67711b7d718a..845fb6c70ca3 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -200,6 +200,18 @@ config LPC32XX_ADC
200 activate only one via device tree selection. Provides direct access 200 activate only one via device tree selection. Provides direct access
201 via sysfs. 201 via sysfs.
202 202
203config MXS_LRADC
204 tristate "Freescale i.MX28 LRADC"
205 depends on ARCH_MXS
206 select IIO_BUFFER
207 select IIO_TRIGGERED_BUFFER
208 help
209 Say yes here to build support for i.MX28 LRADC convertor
210 built into these chips.
211
212 To compile this driver as a module, choose M here: the
213 module will be called mxs-lradc.
214
203config SPEAR_ADC 215config SPEAR_ADC
204 tristate "ST SPEAr ADC" 216 tristate "ST SPEAr ADC"
205 depends on PLAT_SPEAR 217 depends on PLAT_SPEAR
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index 14e98b62b70a..ecac9a0bb358 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -38,4 +38,5 @@ obj-$(CONFIG_ADT7310) += adt7310.o
38obj-$(CONFIG_ADT7410) += adt7410.o 38obj-$(CONFIG_ADT7410) += adt7410.o
39obj-$(CONFIG_AD7280) += ad7280a.o 39obj-$(CONFIG_AD7280) += ad7280a.o
40obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o 40obj-$(CONFIG_LPC32XX_ADC) += lpc32xx_adc.o
41obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
41obj-$(CONFIG_SPEAR_ADC) += spear_adc.o 42obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
new file mode 100644
index 000000000000..ae549e572e5d
--- /dev/null
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -0,0 +1,590 @@
1/*
2 * Freescale i.MX28 LRADC driver
3 *
4 * Copyright (c) 2012 DENX Software Engineering, GmbH.
5 * Marek Vasut <marex@denx.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/interrupt.h>
19#include <linux/device.h>
20#include <linux/kernel.h>
21#include <linux/slab.h>
22#include <linux/of.h>
23#include <linux/of_device.h>
24#include <linux/sysfs.h>
25#include <linux/list.h>
26#include <linux/io.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
29#include <linux/spinlock.h>
30#include <linux/wait.h>
31#include <linux/sched.h>
32#include <linux/stmp_device.h>
33#include <linux/bitops.h>
34#include <linux/completion.h>
35
36#include <mach/mxs.h>
37#include <mach/common.h>
38
39#include <linux/iio/iio.h>
40#include <linux/iio/buffer.h>
41#include <linux/iio/trigger.h>
42#include <linux/iio/trigger_consumer.h>
43#include <linux/iio/triggered_buffer.h>
44
45#define DRIVER_NAME "mxs-lradc"
46
47#define LRADC_MAX_DELAY_CHANS 4
48#define LRADC_MAX_MAPPED_CHANS 8
49#define LRADC_MAX_TOTAL_CHANS 16
50
51#define LRADC_DELAY_TIMER_HZ 2000
52
53/*
54 * Make this runtime configurable if necessary. Currently, if the buffered mode
55 * is enabled, the LRADC takes LRADC_DELAY_TIMER_LOOP samples of data before
56 * triggering IRQ. The sampling happens every (LRADC_DELAY_TIMER_PER / 2000)
57 * seconds. The result is that the samples arrive every 500mS.
58 */
59#define LRADC_DELAY_TIMER_PER 200
60#define LRADC_DELAY_TIMER_LOOP 5
61
62static const char * const mxs_lradc_irq_name[] = {
63 "mxs-lradc-touchscreen",
64 "mxs-lradc-thresh0",
65 "mxs-lradc-thresh1",
66 "mxs-lradc-channel0",
67 "mxs-lradc-channel1",
68 "mxs-lradc-channel2",
69 "mxs-lradc-channel3",
70 "mxs-lradc-channel4",
71 "mxs-lradc-channel5",
72 "mxs-lradc-channel6",
73 "mxs-lradc-channel7",
74 "mxs-lradc-button0",
75 "mxs-lradc-button1",
76};
77
78struct mxs_lradc_chan {
79 uint8_t slot;
80 uint8_t flags;
81};
82
83struct mxs_lradc {
84 struct device *dev;
85 void __iomem *base;
86 int irq[13];
87
88 uint32_t *buffer;
89 struct iio_trigger *trig;
90
91 struct mutex lock;
92
93 uint8_t enable;
94
95 struct completion completion;
96};
97
98#define LRADC_CTRL0 0x00
99#define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23)
100#define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22)
101
102#define LRADC_CTRL1 0x10
103#define LRADC_CTRL1_LRADC_IRQ(n) (1 << (n))
104#define LRADC_CTRL1_LRADC_IRQ_MASK 0x1fff
105#define LRADC_CTRL1_LRADC_IRQ_EN(n) (1 << ((n) + 16))
106#define LRADC_CTRL1_LRADC_IRQ_EN_MASK (0x1fff << 16)
107
108#define LRADC_CTRL2 0x20
109#define LRADC_CTRL2_TEMPSENSE_PWD (1 << 15)
110
111#define LRADC_CH(n) (0x50 + (0x10 * (n)))
112#define LRADC_CH_ACCUMULATE (1 << 29)
113#define LRADC_CH_NUM_SAMPLES_MASK (0x1f << 24)
114#define LRADC_CH_NUM_SAMPLES_OFFSET 24
115#define LRADC_CH_VALUE_MASK 0x3ffff
116#define LRADC_CH_VALUE_OFFSET 0
117
118#define LRADC_DELAY(n) (0xd0 + (0x10 * (n)))
119#define LRADC_DELAY_TRIGGER_LRADCS_MASK (0xff << 24)
120#define LRADC_DELAY_TRIGGER_LRADCS_OFFSET 24
121#define LRADC_DELAY_KICK (1 << 20)
122#define LRADC_DELAY_TRIGGER_DELAYS_MASK (0xf << 16)
123#define LRADC_DELAY_TRIGGER_DELAYS_OFFSET 16
124#define LRADC_DELAY_LOOP_COUNT_MASK (0x1f << 11)
125#define LRADC_DELAY_LOOP_COUNT_OFFSET 11
126#define LRADC_DELAY_DELAY_MASK 0x7ff
127#define LRADC_DELAY_DELAY_OFFSET 0
128
129#define LRADC_CTRL4 0x140
130#define LRADC_CTRL4_LRADCSELECT_MASK(n) (0xf << ((n) * 4))
131#define LRADC_CTRL4_LRADCSELECT_OFFSET(n) ((n) * 4)
132
133/*