Lines Matching +full:touchscreen +full:- +full:max +full:- +full:pressure
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Freescale MXS LRADC touchscreen driver
19 #include <linux/mfd/mxs-lradc.h>
25 "mxs-lradc-touchscreen",
26 "mxs-lradc-channel6",
27 "mxs-lradc-channel7",
31 * Touchscreen handling
47 * When the touchscreen is enabled, we give it two private virtual
62 /* handle touchscreen's physical behaviour */
77 u32 pressure; member
93 return !!(readl(ts->base + LRADC_STATUS) & in mxs_lradc_check_touch_event()
101 ts->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR); in mxs_lradc_map_ts_channel()
103 ts->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET); in mxs_lradc_map_ts_channel()
117 LRADC_CH_NUM_SAMPLES(ts->over_sample_cnt - 1), in mxs_lradc_setup_ts_channel()
118 ts->base + LRADC_CH(ch)); in mxs_lradc_setup_ts_channel()
122 * multi-cycle accumulation. in mxs_lradc_setup_ts_channel()
125 ts->base + LRADC_CH(ch) + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_ts_channel()
132 * HW_LRADC_DELAY2, and HW_LRADC_DELAY3 must be non-zero; otherwise, in mxs_lradc_setup_ts_channel()
136 LRADC_DELAY_LOOP(ts->over_sample_cnt - 1) | in mxs_lradc_setup_ts_channel()
137 LRADC_DELAY_DELAY(ts->over_sample_delay - 1), in mxs_lradc_setup_ts_channel()
138 ts->base + LRADC_DELAY(3)); in mxs_lradc_setup_ts_channel()
141 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_ts_channel()
144 * after changing the touchscreen plates setting in mxs_lradc_setup_ts_channel()
150 LRADC_DELAY_KICK | LRADC_DELAY_DELAY(ts->settling_delay), in mxs_lradc_setup_ts_channel()
151 ts->base + LRADC_DELAY(2)); in mxs_lradc_setup_ts_channel()
155 * Pressure detection is special:
156 * We want to do both required measurements for the pressure detection in
174 LRADC_CH_NUM_SAMPLES(ts->over_sample_cnt - 1); in mxs_lradc_setup_ts_pressure()
175 writel(reg, ts->base + LRADC_CH(ch1)); in mxs_lradc_setup_ts_pressure()
176 writel(reg, ts->base + LRADC_CH(ch2)); in mxs_lradc_setup_ts_pressure()
180 * multi-cycle accumulation. in mxs_lradc_setup_ts_pressure()
183 ts->base + LRADC_CH(ch1) + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_ts_pressure()
185 ts->base + LRADC_CH(ch2) + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_ts_pressure()
190 LRADC_DELAY_LOOP(ts->over_sample_cnt - 1) | in mxs_lradc_setup_ts_pressure()
191 LRADC_DELAY_DELAY(ts->over_sample_delay - 1), in mxs_lradc_setup_ts_pressure()
192 ts->base + LRADC_DELAY(3)); in mxs_lradc_setup_ts_pressure()
195 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_ts_pressure()
198 * after changing the touchscreen plates setting in mxs_lradc_setup_ts_pressure()
204 LRADC_DELAY_KICK | LRADC_DELAY_DELAY(ts->settling_delay), in mxs_lradc_setup_ts_pressure()
205 ts->base + LRADC_DELAY(2)); in mxs_lradc_setup_ts_pressure()
214 reg = readl(ts->base + LRADC_CH(channel)); in mxs_lradc_ts_read_raw_channel()
216 num_samples = ts->over_sample_cnt; in mxs_lradc_ts_read_raw_channel()
228 unsigned int pressure, m1, m2; in mxs_lradc_read_ts_pressure() local
231 reg = readl(ts->base + LRADC_CTRL1) & mask; in mxs_lradc_read_ts_pressure()
234 reg = readl(ts->base + LRADC_CTRL1) & mask; in mxs_lradc_read_ts_pressure()
235 dev_dbg(ts->dev, "One channel is still busy: %X\n", reg); in mxs_lradc_read_ts_pressure()
242 dev_warn(ts->dev, "Cannot calculate pressure\n"); in mxs_lradc_read_ts_pressure()
243 return 1 << (LRADC_RESOLUTION - 1); in mxs_lradc_read_ts_pressure()
246 /* simply scale the value from 0 ... max ADC resolution */ in mxs_lradc_read_ts_pressure()
247 pressure = m1; in mxs_lradc_read_ts_pressure()
248 pressure *= (1 << LRADC_RESOLUTION); in mxs_lradc_read_ts_pressure()
249 pressure /= m2; in mxs_lradc_read_ts_pressure()
251 dev_dbg(ts->dev, "Pressure = %u\n", pressure); in mxs_lradc_read_ts_pressure()
252 return pressure; in mxs_lradc_read_ts_pressure()
261 * YP(open)--+-------------+
262 * | |--+
264 * YM(-)--+-------------+ |
265 * +--------------+
270 * (-) means GND
274 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_setup_touch_detection()
279 * - a weak pullup to the X+ connector in mxs_lradc_setup_touch_detection()
280 * - a strong ground at the Y- connector in mxs_lradc_setup_touch_detection()
282 writel(info[lradc->soc].mask, in mxs_lradc_setup_touch_detection()
283 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_touch_detection()
284 writel(info[lradc->soc].bit, in mxs_lradc_setup_touch_detection()
285 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_setup_touch_detection()
289 * YP(meas)--+-------------+
290 * | |--+
292 * YM(open)--+-------------+ |
293 * +--------------+
295 * XP(+) XM(-)
298 * (-) means here GND
302 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_prepare_x_pos()
304 writel(info[lradc->soc].mask, in mxs_lradc_prepare_x_pos()
305 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_prepare_x_pos()
306 writel(info[lradc->soc].x_plate, in mxs_lradc_prepare_x_pos()
307 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_prepare_x_pos()
309 ts->cur_plate = LRADC_SAMPLE_X; in mxs_lradc_prepare_x_pos()
315 * YP(+)--+-------------+
316 * | |--+
318 * YM(-)--+-------------+ |
319 * +--------------+
324 * (-) means here GND
328 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_prepare_y_pos()
330 writel(info[lradc->soc].mask, in mxs_lradc_prepare_y_pos()
331 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_prepare_y_pos()
332 writel(info[lradc->soc].y_plate, in mxs_lradc_prepare_y_pos()
333 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_prepare_y_pos()
335 ts->cur_plate = LRADC_SAMPLE_Y; in mxs_lradc_prepare_y_pos()
341 * YP(+)--+-------------+
342 * | |--+
344 * YM(meas)--+-------------+ |
345 * +--------------+
347 * XP(meas) XM(-)
350 * (-) means here GND
354 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_prepare_pressure()
356 writel(info[lradc->soc].mask, in mxs_lradc_prepare_pressure()
357 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_prepare_pressure()
358 writel(info[lradc->soc].pressure, in mxs_lradc_prepare_pressure()
359 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_prepare_pressure()
361 ts->cur_plate = LRADC_SAMPLE_PRESSURE; in mxs_lradc_prepare_pressure()
372 ts->cur_plate = LRADC_TOUCH; in mxs_lradc_enable_touch_detection()
374 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_enable_touch_detection()
376 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); in mxs_lradc_enable_touch_detection()
382 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_start_touch_event()
384 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); in mxs_lradc_start_touch_event()
386 * start with the Y-pos, because it uses nearly the same plate in mxs_lradc_start_touch_event()
394 input_report_abs(ts->ts_input, ABS_X, ts->ts_x_pos); in mxs_lradc_report_ts_event()
395 input_report_abs(ts->ts_input, ABS_Y, ts->ts_y_pos); in mxs_lradc_report_ts_event()
396 input_report_abs(ts->ts_input, ABS_PRESSURE, ts->ts_pressure); in mxs_lradc_report_ts_event()
397 input_report_key(ts->ts_input, BTN_TOUCH, 1); in mxs_lradc_report_ts_event()
398 input_sync(ts->ts_input); in mxs_lradc_report_ts_event()
404 ts->cur_plate = LRADC_SAMPLE_VALID; in mxs_lradc_complete_touch_event()
409 writel(0, ts->base + LRADC_CH(TOUCHSCREEN_VCHANNEL1)); in mxs_lradc_complete_touch_event()
412 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_complete_touch_event()
415 ts->base + LRADC_DELAY(2)); in mxs_lradc_complete_touch_event()
426 ts->ts_valid = true; in mxs_lradc_finish_touch_event()
436 if (ts->ts_valid) { in mxs_lradc_finish_touch_event()
438 ts->ts_valid = false; in mxs_lradc_finish_touch_event()
439 input_report_key(ts->ts_input, BTN_TOUCH, 0); in mxs_lradc_finish_touch_event()
440 input_sync(ts->ts_input); in mxs_lradc_finish_touch_event()
444 ts->cur_plate = LRADC_TOUCH; in mxs_lradc_finish_touch_event()
445 writel(0, ts->base + LRADC_DELAY(2)); in mxs_lradc_finish_touch_event()
446 writel(0, ts->base + LRADC_DELAY(3)); in mxs_lradc_finish_touch_event()
450 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_finish_touch_event()
452 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); in mxs_lradc_finish_touch_event()
455 /* touchscreen's state machine */
458 switch (ts->cur_plate) { in mxs_lradc_handle_touch()
463 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_handle_touch()
467 ts->ts_y_pos = in mxs_lradc_handle_touch()
473 ts->ts_x_pos = in mxs_lradc_handle_touch()
479 ts->ts_pressure = in mxs_lradc_handle_touch()
496 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_ts_handle_irq()
497 unsigned long reg = readl(ts->base + LRADC_CTRL1); in mxs_lradc_ts_handle_irq()
509 spin_lock_irqsave(&ts->lock, flags); in mxs_lradc_ts_handle_irq()
511 spin_unlock_irqrestore(&ts->lock, flags); in mxs_lradc_ts_handle_irq()
516 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_ts_handle_irq()
526 /* Enable the touch-detect circuitry. */ in mxs_lradc_ts_open()
535 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_ts_stop()
541 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_ts_stop()
543 /* Power-down touchscreen touch-detect circuitry. */ in mxs_lradc_ts_stop()
544 writel(info[lradc->soc].mask, in mxs_lradc_ts_stop()
545 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_ts_stop()
547 writel(lradc->buffer_vchans << LRADC_CTRL1_LRADC_IRQ_EN_OFFSET, in mxs_lradc_ts_stop()
548 ts->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); in mxs_lradc_ts_stop()
551 writel(0, ts->base + LRADC_DELAY(i)); in mxs_lradc_ts_stop()
563 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_ts_hw_init()
565 /* Configure the touchscreen type */ in mxs_lradc_ts_hw_init()
566 if (lradc->soc == IMX28_LRADC) { in mxs_lradc_ts_hw_init()
568 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_ts_hw_init()
570 if (lradc->touchscreen_wire == MXS_LRADC_TOUCHSCREEN_5WIRE) in mxs_lradc_ts_hw_init()
572 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_ts_hw_init()
579 struct device *dev = ts->dev; in mxs_lradc_ts_register()
583 return -ENOMEM; in mxs_lradc_ts_register()
585 input->name = "mxs-lradc-ts"; in mxs_lradc_ts_register()
586 input->id.bustype = BUS_HOST; in mxs_lradc_ts_register()
587 input->open = mxs_lradc_ts_open; in mxs_lradc_ts_register()
588 input->close = mxs_lradc_ts_close; in mxs_lradc_ts_register()
590 __set_bit(INPUT_PROP_DIRECT, input->propbit); in mxs_lradc_ts_register()
597 ts->ts_input = input; in mxs_lradc_ts_register()
605 struct device *dev = &pdev->dev; in mxs_lradc_ts_probe()
606 struct device_node *node = dev->parent->of_node; in mxs_lradc_ts_probe()
607 struct mxs_lradc *lradc = dev_get_drvdata(dev->parent); in mxs_lradc_ts_probe()
614 return -ENOMEM; in mxs_lradc_ts_probe()
618 ts->lradc = lradc; in mxs_lradc_ts_probe()
619 ts->dev = dev; in mxs_lradc_ts_probe()
620 spin_lock_init(&ts->lock); in mxs_lradc_ts_probe()
622 ts->base = devm_platform_ioremap_resource(pdev, 0); in mxs_lradc_ts_probe()
623 if (IS_ERR(ts->base)) in mxs_lradc_ts_probe()
624 return PTR_ERR(ts->base); in mxs_lradc_ts_probe()
626 ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires", in mxs_lradc_ts_probe()
631 if (of_property_read_u32(node, "fsl,ave-ctrl", &adapt)) { in mxs_lradc_ts_probe()
632 ts->over_sample_cnt = 4; in mxs_lradc_ts_probe()
635 ts->over_sample_cnt = adapt; in mxs_lradc_ts_probe()
637 dev_err(ts->dev, "Invalid sample count (%u)\n", in mxs_lradc_ts_probe()
639 return -EINVAL; in mxs_lradc_ts_probe()
643 if (of_property_read_u32(node, "fsl,ave-delay", &adapt)) { in mxs_lradc_ts_probe()
644 ts->over_sample_delay = 2; in mxs_lradc_ts_probe()
647 ts->over_sample_delay = adapt; in mxs_lradc_ts_probe()
649 dev_err(ts->dev, "Invalid sample delay (%u)\n", in mxs_lradc_ts_probe()
651 return -EINVAL; in mxs_lradc_ts_probe()
656 ts->settling_delay = 10; in mxs_lradc_ts_probe()
659 ts->settling_delay = adapt; in mxs_lradc_ts_probe()
661 dev_err(ts->dev, "Invalid settling delay (%u)\n", in mxs_lradc_ts_probe()
663 return -EINVAL; in mxs_lradc_ts_probe()
667 ret = stmp_reset_block(ts->base); in mxs_lradc_ts_probe()
694 .name = "mxs-lradc-ts",
701 MODULE_DESCRIPTION("Freescale MXS LRADC touchscreen driver");
703 MODULE_ALIAS("platform:mxs-lradc-ts");