Lines Matching refs:ts
91 static bool mxs_lradc_check_touch_event(struct mxs_lradc_ts *ts) in mxs_lradc_check_touch_event() argument
93 return !!(readl(ts->base + LRADC_STATUS) & in mxs_lradc_check_touch_event()
97 static void mxs_lradc_map_ts_channel(struct mxs_lradc_ts *ts, unsigned int vch, in mxs_lradc_map_ts_channel() argument
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()
106 static void mxs_lradc_setup_ts_channel(struct mxs_lradc_ts *ts, unsigned int ch) in mxs_lradc_setup_ts_channel() argument
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()
125 ts->base + LRADC_CH(ch) + STMP_OFFSET_REG_CLR); 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()
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()
160 static void mxs_lradc_setup_ts_pressure(struct mxs_lradc_ts *ts, in mxs_lradc_setup_ts_pressure() argument
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()
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()
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()
208 static unsigned int mxs_lradc_ts_read_raw_channel(struct mxs_lradc_ts *ts, in mxs_lradc_ts_read_raw_channel() argument
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()
224 static unsigned int mxs_lradc_read_ts_pressure(struct mxs_lradc_ts *ts, in mxs_lradc_read_ts_pressure() argument
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()
238 m1 = mxs_lradc_ts_read_raw_channel(ts, ch1); in mxs_lradc_read_ts_pressure()
239 m2 = mxs_lradc_ts_read_raw_channel(ts, ch2); in mxs_lradc_read_ts_pressure()
242 dev_warn(ts->dev, "Cannot calculate pressure\n"); in mxs_lradc_read_ts_pressure()
251 dev_dbg(ts->dev, "Pressure = %u\n", pressure); in mxs_lradc_read_ts_pressure()
272 static void mxs_lradc_setup_touch_detection(struct mxs_lradc_ts *ts) in mxs_lradc_setup_touch_detection() argument
274 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_setup_touch_detection()
283 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_setup_touch_detection()
285 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_setup_touch_detection()
300 static void mxs_lradc_prepare_x_pos(struct mxs_lradc_ts *ts) in mxs_lradc_prepare_x_pos() argument
302 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_prepare_x_pos()
305 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 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()
310 mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL1, TS_CH_YP); in mxs_lradc_prepare_x_pos()
311 mxs_lradc_setup_ts_channel(ts, TOUCHSCREEN_VCHANNEL1); in mxs_lradc_prepare_x_pos()
326 static void mxs_lradc_prepare_y_pos(struct mxs_lradc_ts *ts) in mxs_lradc_prepare_y_pos() argument
328 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_prepare_y_pos()
331 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 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()
336 mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL1, TS_CH_XM); in mxs_lradc_prepare_y_pos()
337 mxs_lradc_setup_ts_channel(ts, TOUCHSCREEN_VCHANNEL1); in mxs_lradc_prepare_y_pos()
352 static void mxs_lradc_prepare_pressure(struct mxs_lradc_ts *ts) in mxs_lradc_prepare_pressure() argument
354 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_prepare_pressure()
357 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 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()
362 mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL1, TS_CH_YM); in mxs_lradc_prepare_pressure()
363 mxs_lradc_map_ts_channel(ts, TOUCHSCREEN_VCHANNEL2, TS_CH_XP); in mxs_lradc_prepare_pressure()
364 mxs_lradc_setup_ts_pressure(ts, TOUCHSCREEN_VCHANNEL2, in mxs_lradc_prepare_pressure()
368 static void mxs_lradc_enable_touch_detection(struct mxs_lradc_ts *ts) in mxs_lradc_enable_touch_detection() argument
370 mxs_lradc_setup_touch_detection(ts); in mxs_lradc_enable_touch_detection()
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()
379 static void mxs_lradc_start_touch_event(struct mxs_lradc_ts *ts) in mxs_lradc_start_touch_event() argument
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()
389 mxs_lradc_prepare_y_pos(ts); in mxs_lradc_start_touch_event()
392 static void mxs_lradc_report_ts_event(struct mxs_lradc_ts *ts) in mxs_lradc_report_ts_event() argument
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()
401 static void mxs_lradc_complete_touch_event(struct mxs_lradc_ts *ts) in mxs_lradc_complete_touch_event() argument
403 mxs_lradc_setup_touch_detection(ts); in mxs_lradc_complete_touch_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()
422 static void mxs_lradc_finish_touch_event(struct mxs_lradc_ts *ts, bool valid) in mxs_lradc_finish_touch_event() argument
425 if (valid && mxs_lradc_check_touch_event(ts)) { in mxs_lradc_finish_touch_event()
426 ts->ts_valid = true; in mxs_lradc_finish_touch_event()
427 mxs_lradc_report_ts_event(ts); in mxs_lradc_finish_touch_event()
431 if (mxs_lradc_check_touch_event(ts)) { in mxs_lradc_finish_touch_event()
432 mxs_lradc_prepare_y_pos(ts); 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()
456 static void mxs_lradc_handle_touch(struct mxs_lradc_ts *ts) in mxs_lradc_handle_touch() argument
458 switch (ts->cur_plate) { in mxs_lradc_handle_touch()
460 if (mxs_lradc_check_touch_event(ts)) in mxs_lradc_handle_touch()
461 mxs_lradc_start_touch_event(ts); 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()
468 mxs_lradc_ts_read_raw_channel(ts, TOUCHSCREEN_VCHANNEL1); in mxs_lradc_handle_touch()
469 mxs_lradc_prepare_x_pos(ts); in mxs_lradc_handle_touch()
473 ts->ts_x_pos = in mxs_lradc_handle_touch()
474 mxs_lradc_ts_read_raw_channel(ts, TOUCHSCREEN_VCHANNEL1); in mxs_lradc_handle_touch()
475 mxs_lradc_prepare_pressure(ts); in mxs_lradc_handle_touch()
479 ts->ts_pressure = in mxs_lradc_handle_touch()
480 mxs_lradc_read_ts_pressure(ts, in mxs_lradc_handle_touch()
483 mxs_lradc_complete_touch_event(ts); in mxs_lradc_handle_touch()
487 mxs_lradc_finish_touch_event(ts, 1); in mxs_lradc_handle_touch()
495 struct mxs_lradc_ts *ts = data; in mxs_lradc_ts_handle_irq() local
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()
510 mxs_lradc_handle_touch(ts); 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()
524 struct mxs_lradc_ts *ts = input_get_drvdata(dev); in mxs_lradc_ts_open() local
527 mxs_lradc_enable_touch_detection(ts); in mxs_lradc_ts_open()
532 static void mxs_lradc_ts_stop(struct mxs_lradc_ts *ts) in mxs_lradc_ts_stop() argument
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()
545 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 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()
556 struct mxs_lradc_ts *ts = input_get_drvdata(dev); in mxs_lradc_ts_close() local
558 mxs_lradc_ts_stop(ts); in mxs_lradc_ts_close()
561 static void mxs_lradc_ts_hw_init(struct mxs_lradc_ts *ts) in mxs_lradc_ts_hw_init() argument
563 struct mxs_lradc *lradc = ts->lradc; in mxs_lradc_ts_hw_init()
568 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); in mxs_lradc_ts_hw_init()
572 ts->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET); in mxs_lradc_ts_hw_init()
576 static int mxs_lradc_ts_register(struct mxs_lradc_ts *ts) in mxs_lradc_ts_register() argument
579 struct device *dev = ts->dev; in mxs_lradc_ts_register()
597 ts->ts_input = input; in mxs_lradc_ts_register()
598 input_set_drvdata(input, ts); in mxs_lradc_ts_register()
608 struct mxs_lradc_ts *ts; in mxs_lradc_ts_probe() local
612 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in mxs_lradc_ts_probe()
613 if (!ts) in mxs_lradc_ts_probe()
616 platform_set_drvdata(pdev, ts); 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()
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()
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()
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()
667 ret = stmp_reset_block(ts->base); in mxs_lradc_ts_probe()
671 mxs_lradc_ts_hw_init(ts); in mxs_lradc_ts_probe()
680 mxs_lradc_ts_stop(ts); in mxs_lradc_ts_probe()
684 0, mxs_lradc_ts_irq_names[i], ts); in mxs_lradc_ts_probe()
689 return mxs_lradc_ts_register(ts); in mxs_lradc_ts_probe()