19 #include <linux/device.h>
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
25 #include <linux/list.h>
27 #include <linux/module.h>
30 #include <linux/wait.h>
31 #include <linux/sched.h>
33 #include <linux/bitops.h>
37 #include <mach/common.h>
45 #define DRIVER_NAME "mxs-lradc"
47 #define LRADC_MAX_DELAY_CHANS 4
48 #define LRADC_MAX_MAPPED_CHANS 8
49 #define LRADC_MAX_TOTAL_CHANS 16
51 #define LRADC_DELAY_TIMER_HZ 2000
59 #define LRADC_DELAY_TIMER_PER 200
60 #define LRADC_DELAY_TIMER_LOOP 5
62 static const char *
const mxs_lradc_irq_name[] = {
63 "mxs-lradc-touchscreen",
98 #define LRADC_CTRL0 0x00
99 #define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23)
100 #define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22)
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)
108 #define LRADC_CTRL2 0x20
109 #define LRADC_CTRL2_TEMPSENSE_PWD (1 << 15)
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
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
129 #define LRADC_CTRL4 0x140
130 #define LRADC_CTRL4_LRADCSELECT_MASK(n) (0xf << ((n) * 4))
131 #define LRADC_CTRL4_LRADCSELECT_OFFSET(n) ((n) * 4)
138 int *
val,
int *val2,
long m)
199 static const struct iio_info mxs_lradc_iio_info = {
201 .read_raw = mxs_lradc_read_raw,
221 if (iio_buffer_enabled(iio))
226 writel(reg & LRADC_CTRL1_LRADC_IRQ_MASK,
235 static irqreturn_t mxs_lradc_trigger_handler(
int irq,
void *
p)
266 static int mxs_lradc_configure_trigger(
struct iio_trigger *trig,
bool state)
279 .set_trigger_state = &mxs_lradc_configure_trigger,
282 static int mxs_lradc_trigger_init(
struct iio_dev *iio)
291 trig->
dev.parent = iio->
dev.parent;
293 trig->
ops = &mxs_lradc_trigger_ops;
306 static void mxs_lradc_trigger_remove(
struct iio_dev *iio)
312 static int mxs_lradc_buffer_preenable(
struct iio_dev *iio)
315 struct iio_buffer *buffer = iio->
buffer;
374 static int mxs_lradc_buffer_postdisable(
struct iio_dev *iio)
391 static bool mxs_lradc_validate_scan_mask(
struct iio_dev *iio,
392 const unsigned long *
mask)
394 const int mw = bitmap_weight(mask, iio->
masklength);
400 .preenable = &mxs_lradc_buffer_preenable,
403 .postdisable = &mxs_lradc_buffer_postdisable,
404 .validate_scan_mask = &mxs_lradc_validate_scan_mask,
411 #define MXS_ADC_CHAN(idx, chan_type) { \
412 .type = (chan_type), \
414 .scan_index = (idx), \
415 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
443 static void mxs_lradc_hw_init(
struct mxs_lradc *lradc)
459 static void mxs_lradc_hw_stop(
struct mxs_lradc *lradc)
482 dev_err(dev,
"Failed to allocate IIO device\n");
486 lradc = iio_priv(iio);
498 for (i = 0; i < 13; i++) {
500 if (lradc->
irq[i] < 0) {
505 ret = devm_request_irq(dev, lradc->
irq[i],
506 mxs_lradc_handle_irq, 0,
507 mxs_lradc_irq_name[i], iio);
512 platform_set_drvdata(pdev, iio);
518 iio->
dev.parent = &pdev->
dev;
519 iio->
info = &mxs_lradc_iio_info;
521 iio->
channels = mxs_lradc_chan_spec;
525 &mxs_lradc_trigger_handler,
526 &mxs_lradc_buffer_ops);
530 ret = mxs_lradc_trigger_init(iio);
537 dev_err(dev,
"Failed to register IIO device\n");
542 mxs_lradc_hw_init(lradc);
547 mxs_lradc_trigger_remove(iio);
557 struct iio_dev *iio = platform_get_drvdata(pdev);
560 mxs_lradc_hw_stop(lradc);
564 mxs_lradc_trigger_remove(iio);
571 { .compatible =
"fsl,imx28-lradc", },
580 .of_match_table = mxs_lradc_dt_ids,
582 .probe = mxs_lradc_probe,