2 * Freescale MXS LRADC touchscreen driver
4 * Copyright (c) 2012 DENX Software Engineering, GmbH.
5 * Copyright (c) 2017 Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
8 * Marek Vasut <marex@denx.de>
9 * Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
22 #include <linux/device.h>
23 #include <linux/err.h>
24 #include <linux/input.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/mfd/core.h>
28 #include <linux/mfd/mxs-lradc.h>
30 #include <linux/of_irq.h>
31 #include <linux/platform_device.h>
33 static const char * const mxs_lradc_ts_irq_names
[] = {
34 "mxs-lradc-touchscreen",
40 * Touchscreen handling
42 enum mxs_lradc_ts_plate
{
46 LRADC_SAMPLE_PRESSURE
,
51 struct mxs_lradc
*lradc
;
56 * When the touchscreen is enabled, we give it two private virtual
57 * channels: #6 and #7. This means that only 6 virtual channels (instead
58 * of 8) will be available for buffered capture.
60 #define TOUCHSCREEN_VCHANNEL1 7
61 #define TOUCHSCREEN_VCHANNEL2 6
63 struct input_dev
*ts_input
;
65 enum mxs_lradc_ts_plate cur_plate
; /* state machine */
67 unsigned int ts_x_pos
;
68 unsigned int ts_y_pos
;
69 unsigned int ts_pressure
;
71 /* handle touchscreen's physical behaviour */
72 /* samples per coordinate */
73 unsigned int over_sample_cnt
;
74 /* time clocks between samples */
75 unsigned int over_sample_delay
;
76 /* time in clocks to wait after the plates where switched */
77 unsigned int settling_delay
;
89 static struct state_info info
[] = {
90 {LRADC_CTRL0_MX23_PLATE_MASK
, LRADC_CTRL0_MX23_TOUCH_DETECT_ENABLE
,
91 LRADC_CTRL0_MX23_XP
| LRADC_CTRL0_MX23_XM
,
92 LRADC_CTRL0_MX23_YP
| LRADC_CTRL0_MX23_YM
,
93 LRADC_CTRL0_MX23_YP
| LRADC_CTRL0_MX23_XM
},
94 {LRADC_CTRL0_MX28_PLATE_MASK
, LRADC_CTRL0_MX28_TOUCH_DETECT_ENABLE
,
95 LRADC_CTRL0_MX28_XPPSW
| LRADC_CTRL0_MX28_XNNSW
,
96 LRADC_CTRL0_MX28_YPPSW
| LRADC_CTRL0_MX28_YNNSW
,
97 LRADC_CTRL0_MX28_YPPSW
| LRADC_CTRL0_MX28_XNNSW
}
100 static bool mxs_lradc_check_touch_event(struct mxs_lradc_ts
*ts
)
102 return !!(readl(ts
->base
+ LRADC_STATUS
) &
103 LRADC_STATUS_TOUCH_DETECT_RAW
);
106 static void mxs_lradc_map_ts_channel(struct mxs_lradc_ts
*ts
, unsigned int vch
,
109 writel(LRADC_CTRL4_LRADCSELECT_MASK(vch
),
110 ts
->base
+ LRADC_CTRL4
+ STMP_OFFSET_REG_CLR
);
111 writel(LRADC_CTRL4_LRADCSELECT(vch
, ch
),
112 ts
->base
+ LRADC_CTRL4
+ STMP_OFFSET_REG_SET
);
115 static void mxs_lradc_setup_ts_channel(struct mxs_lradc_ts
*ts
, unsigned int ch
)
118 * prepare for oversampling conversion
120 * from the datasheet:
121 * "The ACCUMULATE bit in the appropriate channel register
122 * HW_LRADC_CHn must be set to 1 if NUM_SAMPLES is greater then 0;
123 * otherwise, the IRQs will not fire."
125 writel(LRADC_CH_ACCUMULATE
|
126 LRADC_CH_NUM_SAMPLES(ts
->over_sample_cnt
- 1),
127 ts
->base
+ LRADC_CH(ch
));
129 /* from the datasheet:
130 * "Software must clear this register in preparation for a
131 * multi-cycle accumulation.
133 writel(LRADC_CH_VALUE_MASK
,
134 ts
->base
+ LRADC_CH(ch
) + STMP_OFFSET_REG_CLR
);
137 * prepare the delay/loop unit according to the oversampling count
139 * from the datasheet:
140 * "The DELAY fields in HW_LRADC_DELAY0, HW_LRADC_DELAY1,
141 * HW_LRADC_DELAY2, and HW_LRADC_DELAY3 must be non-zero; otherwise,
142 * the LRADC will not trigger the delay group."
144 writel(LRADC_DELAY_TRIGGER(1 << ch
) | LRADC_DELAY_TRIGGER_DELAYS(0) |
145 LRADC_DELAY_LOOP(ts
->over_sample_cnt
- 1) |
146 LRADC_DELAY_DELAY(ts
->over_sample_delay
- 1),
147 ts
->base
+ LRADC_DELAY(3));
149 writel(LRADC_CTRL1_LRADC_IRQ(ch
),
150 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
153 * after changing the touchscreen plates setting
154 * the signals need some initial time to settle. Start the
155 * SoC's delay unit and start the conversion later
158 writel(LRADC_DELAY_TRIGGER(0) | LRADC_DELAY_TRIGGER_DELAYS(BIT(3)) |
159 LRADC_DELAY_KICK
| LRADC_DELAY_DELAY(ts
->settling_delay
),
160 ts
->base
+ LRADC_DELAY(2));
164 * Pressure detection is special:
165 * We want to do both required measurements for the pressure detection in
166 * one turn. Use the hardware features to chain both conversions and let the
167 * hardware report one interrupt if both conversions are done
169 static void mxs_lradc_setup_ts_pressure(struct mxs_lradc_ts
*ts
,
170 unsigned int ch1
, unsigned int ch2
)
175 * prepare for oversampling conversion
177 * from the datasheet:
178 * "The ACCUMULATE bit in the appropriate channel register
179 * HW_LRADC_CHn must be set to 1 if NUM_SAMPLES is greater then 0;
180 * otherwise, the IRQs will not fire."
182 reg
= LRADC_CH_ACCUMULATE
|
183 LRADC_CH_NUM_SAMPLES(ts
->over_sample_cnt
- 1);
184 writel(reg
, ts
->base
+ LRADC_CH(ch1
));
185 writel(reg
, ts
->base
+ LRADC_CH(ch2
));
187 /* from the datasheet:
188 * "Software must clear this register in preparation for a
189 * multi-cycle accumulation.
191 writel(LRADC_CH_VALUE_MASK
,
192 ts
->base
+ LRADC_CH(ch1
) + STMP_OFFSET_REG_CLR
);
193 writel(LRADC_CH_VALUE_MASK
,
194 ts
->base
+ LRADC_CH(ch2
) + STMP_OFFSET_REG_CLR
);
196 /* prepare the delay/loop unit according to the oversampling count */
197 writel(LRADC_DELAY_TRIGGER(1 << ch1
) | LRADC_DELAY_TRIGGER(1 << ch2
) |
198 LRADC_DELAY_TRIGGER_DELAYS(0) |
199 LRADC_DELAY_LOOP(ts
->over_sample_cnt
- 1) |
200 LRADC_DELAY_DELAY(ts
->over_sample_delay
- 1),
201 ts
->base
+ LRADC_DELAY(3));
203 writel(LRADC_CTRL1_LRADC_IRQ(ch2
),
204 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
207 * after changing the touchscreen plates setting
208 * the signals need some initial time to settle. Start the
209 * SoC's delay unit and start the conversion later
212 writel(LRADC_DELAY_TRIGGER(0) | LRADC_DELAY_TRIGGER_DELAYS(BIT(3)) |
213 LRADC_DELAY_KICK
| LRADC_DELAY_DELAY(ts
->settling_delay
),
214 ts
->base
+ LRADC_DELAY(2));
217 static unsigned int mxs_lradc_ts_read_raw_channel(struct mxs_lradc_ts
*ts
,
218 unsigned int channel
)
221 unsigned int num_samples
, val
;
223 reg
= readl(ts
->base
+ LRADC_CH(channel
));
224 if (reg
& LRADC_CH_ACCUMULATE
)
225 num_samples
= ts
->over_sample_cnt
;
229 val
= (reg
& LRADC_CH_VALUE_MASK
) >> LRADC_CH_VALUE_OFFSET
;
230 return val
/ num_samples
;
233 static unsigned int mxs_lradc_read_ts_pressure(struct mxs_lradc_ts
*ts
,
234 unsigned int ch1
, unsigned int ch2
)
237 unsigned int pressure
, m1
, m2
;
239 mask
= LRADC_CTRL1_LRADC_IRQ(ch1
) | LRADC_CTRL1_LRADC_IRQ(ch2
);
240 reg
= readl(ts
->base
+ LRADC_CTRL1
) & mask
;
242 while (reg
!= mask
) {
243 reg
= readl(ts
->base
+ LRADC_CTRL1
) & mask
;
244 dev_dbg(ts
->dev
, "One channel is still busy: %X\n", reg
);
247 m1
= mxs_lradc_ts_read_raw_channel(ts
, ch1
);
248 m2
= mxs_lradc_ts_read_raw_channel(ts
, ch2
);
251 dev_warn(ts
->dev
, "Cannot calculate pressure\n");
252 return 1 << (LRADC_RESOLUTION
- 1);
255 /* simply scale the value from 0 ... max ADC resolution */
257 pressure
*= (1 << LRADC_RESOLUTION
);
260 dev_dbg(ts
->dev
, "Pressure = %u\n", pressure
);
270 * YP(open)--+-------------+
273 * YM(-)--+-------------+ |
278 * "weak+" means 200k Ohm VDDIO
281 static void mxs_lradc_setup_touch_detection(struct mxs_lradc_ts
*ts
)
283 struct mxs_lradc
*lradc
= ts
->lradc
;
286 * In order to detect a touch event the 'touch detect enable' bit
288 * - a weak pullup to the X+ connector
289 * - a strong ground at the Y- connector
291 writel(info
[lradc
->soc
].mask
,
292 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_CLR
);
293 writel(info
[lradc
->soc
].bit
,
294 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_SET
);
298 * YP(meas)--+-------------+
301 * YM(open)--+-------------+ |
306 * (+) means here 1.85 V
309 static void mxs_lradc_prepare_x_pos(struct mxs_lradc_ts
*ts
)
311 struct mxs_lradc
*lradc
= ts
->lradc
;
313 writel(info
[lradc
->soc
].mask
,
314 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_CLR
);
315 writel(info
[lradc
->soc
].x_plate
,
316 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_SET
);
318 ts
->cur_plate
= LRADC_SAMPLE_X
;
319 mxs_lradc_map_ts_channel(ts
, TOUCHSCREEN_VCHANNEL1
, TS_CH_YP
);
320 mxs_lradc_setup_ts_channel(ts
, TOUCHSCREEN_VCHANNEL1
);
324 * YP(+)--+-------------+
327 * YM(-)--+-------------+ |
332 * (+) means here 1.85 V
335 static void mxs_lradc_prepare_y_pos(struct mxs_lradc_ts
*ts
)
337 struct mxs_lradc
*lradc
= ts
->lradc
;
339 writel(info
[lradc
->soc
].mask
,
340 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_CLR
);
341 writel(info
[lradc
->soc
].y_plate
,
342 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_SET
);
344 ts
->cur_plate
= LRADC_SAMPLE_Y
;
345 mxs_lradc_map_ts_channel(ts
, TOUCHSCREEN_VCHANNEL1
, TS_CH_XM
);
346 mxs_lradc_setup_ts_channel(ts
, TOUCHSCREEN_VCHANNEL1
);
350 * YP(+)--+-------------+
353 * YM(meas)--+-------------+ |
358 * (+) means here 1.85 V
361 static void mxs_lradc_prepare_pressure(struct mxs_lradc_ts
*ts
)
363 struct mxs_lradc
*lradc
= ts
->lradc
;
365 writel(info
[lradc
->soc
].mask
,
366 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_CLR
);
367 writel(info
[lradc
->soc
].pressure
,
368 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_SET
);
370 ts
->cur_plate
= LRADC_SAMPLE_PRESSURE
;
371 mxs_lradc_map_ts_channel(ts
, TOUCHSCREEN_VCHANNEL1
, TS_CH_YM
);
372 mxs_lradc_map_ts_channel(ts
, TOUCHSCREEN_VCHANNEL2
, TS_CH_XP
);
373 mxs_lradc_setup_ts_pressure(ts
, TOUCHSCREEN_VCHANNEL2
,
374 TOUCHSCREEN_VCHANNEL1
);
377 static void mxs_lradc_enable_touch_detection(struct mxs_lradc_ts
*ts
)
379 mxs_lradc_setup_touch_detection(ts
);
381 ts
->cur_plate
= LRADC_TOUCH
;
382 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ
| LRADC_CTRL1_TOUCH_DETECT_IRQ_EN
,
383 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
384 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN
,
385 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_SET
);
388 static void mxs_lradc_start_touch_event(struct mxs_lradc_ts
*ts
)
390 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN
,
391 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
392 writel(LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1
),
393 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_SET
);
395 * start with the Y-pos, because it uses nearly the same plate
396 * settings like the touch detection
398 mxs_lradc_prepare_y_pos(ts
);
401 static void mxs_lradc_report_ts_event(struct mxs_lradc_ts
*ts
)
403 input_report_abs(ts
->ts_input
, ABS_X
, ts
->ts_x_pos
);
404 input_report_abs(ts
->ts_input
, ABS_Y
, ts
->ts_y_pos
);
405 input_report_abs(ts
->ts_input
, ABS_PRESSURE
, ts
->ts_pressure
);
406 input_report_key(ts
->ts_input
, BTN_TOUCH
, 1);
407 input_sync(ts
->ts_input
);
410 static void mxs_lradc_complete_touch_event(struct mxs_lradc_ts
*ts
)
412 mxs_lradc_setup_touch_detection(ts
);
413 ts
->cur_plate
= LRADC_SAMPLE_VALID
;
415 * start a dummy conversion to burn time to settle the signals
416 * note: we are not interested in the conversion's value
418 writel(0, ts
->base
+ LRADC_CH(TOUCHSCREEN_VCHANNEL1
));
419 writel(LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1
) |
420 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2
),
421 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
422 writel(LRADC_DELAY_TRIGGER(1 << TOUCHSCREEN_VCHANNEL1
) |
423 LRADC_DELAY_KICK
| LRADC_DELAY_DELAY(10),
424 ts
->base
+ LRADC_DELAY(2));
428 * in order to avoid false measurements, report only samples where
429 * the surface is still touched after the position measurement
431 static void mxs_lradc_finish_touch_event(struct mxs_lradc_ts
*ts
, bool valid
)
433 /* if it is still touched, report the sample */
434 if (valid
&& mxs_lradc_check_touch_event(ts
)) {
436 mxs_lradc_report_ts_event(ts
);
439 /* if it is even still touched, continue with the next measurement */
440 if (mxs_lradc_check_touch_event(ts
)) {
441 mxs_lradc_prepare_y_pos(ts
);
446 /* signal the release */
447 ts
->ts_valid
= false;
448 input_report_key(ts
->ts_input
, BTN_TOUCH
, 0);
449 input_sync(ts
->ts_input
);
452 /* if it is released, wait for the next touch via IRQ */
453 ts
->cur_plate
= LRADC_TOUCH
;
454 writel(0, ts
->base
+ LRADC_DELAY(2));
455 writel(0, ts
->base
+ LRADC_DELAY(3));
456 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ
|
457 LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1
) |
458 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1
),
459 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
460 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN
,
461 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_SET
);
464 /* touchscreen's state machine */
465 static void mxs_lradc_handle_touch(struct mxs_lradc_ts
*ts
)
467 switch (ts
->cur_plate
) {
469 if (mxs_lradc_check_touch_event(ts
))
470 mxs_lradc_start_touch_event(ts
);
471 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ
,
472 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
477 mxs_lradc_ts_read_raw_channel(ts
, TOUCHSCREEN_VCHANNEL1
);
478 mxs_lradc_prepare_x_pos(ts
);
483 mxs_lradc_ts_read_raw_channel(ts
, TOUCHSCREEN_VCHANNEL1
);
484 mxs_lradc_prepare_pressure(ts
);
487 case LRADC_SAMPLE_PRESSURE
:
489 mxs_lradc_read_ts_pressure(ts
,
490 TOUCHSCREEN_VCHANNEL2
,
491 TOUCHSCREEN_VCHANNEL1
);
492 mxs_lradc_complete_touch_event(ts
);
495 case LRADC_SAMPLE_VALID
:
496 mxs_lradc_finish_touch_event(ts
, 1);
502 static irqreturn_t
mxs_lradc_ts_handle_irq(int irq
, void *data
)
504 struct mxs_lradc_ts
*ts
= data
;
505 struct mxs_lradc
*lradc
= ts
->lradc
;
506 unsigned long reg
= readl(ts
->base
+ LRADC_CTRL1
);
507 u32 clr_irq
= mxs_lradc_irq_mask(lradc
);
508 const u32 ts_irq_mask
=
509 LRADC_CTRL1_TOUCH_DETECT_IRQ
|
510 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1
) |
511 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2
);
514 if (!(reg
& mxs_lradc_irq_mask(lradc
)))
517 if (reg
& ts_irq_mask
) {
518 spin_lock_irqsave(&ts
->lock
, flags
);
519 mxs_lradc_handle_touch(ts
);
520 spin_unlock_irqrestore(&ts
->lock
, flags
);
521 /* Make sure we don't clear the next conversion's interrupt. */
522 clr_irq
&= ~(LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1
) |
523 LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2
));
524 writel(reg
& clr_irq
,
525 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
531 static int mxs_lradc_ts_open(struct input_dev
*dev
)
533 struct mxs_lradc_ts
*ts
= input_get_drvdata(dev
);
535 /* Enable the touch-detect circuitry. */
536 mxs_lradc_enable_touch_detection(ts
);
541 static void mxs_lradc_ts_stop(struct mxs_lradc_ts
*ts
)
544 struct mxs_lradc
*lradc
= ts
->lradc
;
546 /* stop all interrupts from firing */
547 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN
|
548 LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1
) |
549 LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL2
),
550 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
552 /* Power-down touchscreen touch-detect circuitry. */
553 writel(info
[lradc
->soc
].mask
,
554 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_CLR
);
556 writel(lradc
->buffer_vchans
<< LRADC_CTRL1_LRADC_IRQ_EN_OFFSET
,
557 ts
->base
+ LRADC_CTRL1
+ STMP_OFFSET_REG_CLR
);
559 for (i
= 1; i
< LRADC_MAX_DELAY_CHANS
; i
++)
560 writel(0, ts
->base
+ LRADC_DELAY(i
));
563 static void mxs_lradc_ts_close(struct input_dev
*dev
)
565 struct mxs_lradc_ts
*ts
= input_get_drvdata(dev
);
567 mxs_lradc_ts_stop(ts
);
570 static void mxs_lradc_ts_hw_init(struct mxs_lradc_ts
*ts
)
572 struct mxs_lradc
*lradc
= ts
->lradc
;
574 /* Configure the touchscreen type */
575 if (lradc
->soc
== IMX28_LRADC
) {
576 writel(LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE
,
577 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_CLR
);
579 if (lradc
->touchscreen_wire
== MXS_LRADC_TOUCHSCREEN_5WIRE
)
580 writel(LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE
,
581 ts
->base
+ LRADC_CTRL0
+ STMP_OFFSET_REG_SET
);
585 static int mxs_lradc_ts_register(struct mxs_lradc_ts
*ts
)
587 struct input_dev
*input
;
588 struct device
*dev
= ts
->dev
;
590 input
= devm_input_allocate_device(dev
);
594 input
->name
= "mxs-lradc-ts";
595 input
->id
.bustype
= BUS_HOST
;
596 input
->open
= mxs_lradc_ts_open
;
597 input
->close
= mxs_lradc_ts_close
;
599 __set_bit(INPUT_PROP_DIRECT
, input
->propbit
);
600 input_set_capability(input
, EV_KEY
, BTN_TOUCH
);
601 input_set_abs_params(input
, ABS_X
, 0, LRADC_SINGLE_SAMPLE_MASK
, 0, 0);
602 input_set_abs_params(input
, ABS_Y
, 0, LRADC_SINGLE_SAMPLE_MASK
, 0, 0);
603 input_set_abs_params(input
, ABS_PRESSURE
, 0, LRADC_SINGLE_SAMPLE_MASK
,
606 ts
->ts_input
= input
;
607 input_set_drvdata(input
, ts
);
609 return input_register_device(input
);
612 static int mxs_lradc_ts_probe(struct platform_device
*pdev
)
614 struct device
*dev
= &pdev
->dev
;
615 struct device_node
*node
= dev
->parent
->of_node
;
616 struct mxs_lradc
*lradc
= dev_get_drvdata(dev
->parent
);
617 struct mxs_lradc_ts
*ts
;
618 struct resource
*iores
;
619 int ret
, irq
, virq
, i
;
620 u32 ts_wires
= 0, adapt
;
622 ts
= devm_kzalloc(dev
, sizeof(*ts
), GFP_KERNEL
);
626 platform_set_drvdata(pdev
, ts
);
630 spin_lock_init(&ts
->lock
);
632 iores
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
635 ts
->base
= devm_ioremap(dev
, iores
->start
, resource_size(iores
));
639 ret
= of_property_read_u32(node
, "fsl,lradc-touchscreen-wires",
644 if (of_property_read_u32(node
, "fsl,ave-ctrl", &adapt
)) {
645 ts
->over_sample_cnt
= 4;
647 if (adapt
>= 1 && adapt
<= 32) {
648 ts
->over_sample_cnt
= adapt
;
650 dev_err(ts
->dev
, "Invalid sample count (%u)\n",
656 if (of_property_read_u32(node
, "fsl,ave-delay", &adapt
)) {
657 ts
->over_sample_delay
= 2;
659 if (adapt
>= 2 && adapt
<= LRADC_DELAY_DELAY_MASK
+ 1) {
660 ts
->over_sample_delay
= adapt
;
662 dev_err(ts
->dev
, "Invalid sample delay (%u)\n",
668 if (of_property_read_u32(node
, "fsl,settling", &adapt
)) {
669 ts
->settling_delay
= 10;
671 if (adapt
>= 1 && adapt
<= LRADC_DELAY_DELAY_MASK
) {
672 ts
->settling_delay
= adapt
;
674 dev_err(ts
->dev
, "Invalid settling delay (%u)\n",
680 ret
= stmp_reset_block(ts
->base
);
684 mxs_lradc_ts_hw_init(ts
);
686 for (i
= 0; i
< 3; i
++) {
687 irq
= platform_get_irq_byname(pdev
, mxs_lradc_ts_irq_names
[i
]);
691 virq
= irq_of_parse_and_map(node
, irq
);
693 mxs_lradc_ts_stop(ts
);
695 ret
= devm_request_irq(dev
, virq
,
696 mxs_lradc_ts_handle_irq
,
697 0, mxs_lradc_ts_irq_names
[i
], ts
);
702 return mxs_lradc_ts_register(ts
);
705 static struct platform_driver mxs_lradc_ts_driver
= {
707 .name
= "mxs-lradc-ts",
709 .probe
= mxs_lradc_ts_probe
,
711 module_platform_driver(mxs_lradc_ts_driver
);
713 MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
714 MODULE_DESCRIPTION("Freescale MXS LRADC touchscreen driver");
715 MODULE_LICENSE("GPL");
716 MODULE_ALIAS("platform:mxs-lradc-ts");