Lines Matching full:ts

114 static void tsc200x_update_pen_state(struct tsc200x *ts,  in tsc200x_update_pen_state()  argument
118 touchscreen_report_pos(ts->idev, &ts->prop, x, y, false); in tsc200x_update_pen_state()
119 input_report_abs(ts->idev, ABS_PRESSURE, pressure); in tsc200x_update_pen_state()
120 if (!ts->pen_down) { in tsc200x_update_pen_state()
121 input_report_key(ts->idev, BTN_TOUCH, !!pressure); in tsc200x_update_pen_state()
122 ts->pen_down = true; in tsc200x_update_pen_state()
125 input_report_abs(ts->idev, ABS_PRESSURE, 0); in tsc200x_update_pen_state()
126 if (ts->pen_down) { in tsc200x_update_pen_state()
127 input_report_key(ts->idev, BTN_TOUCH, 0); in tsc200x_update_pen_state()
128 ts->pen_down = false; in tsc200x_update_pen_state()
131 input_sync(ts->idev); in tsc200x_update_pen_state()
132 dev_dbg(ts->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, in tsc200x_update_pen_state()
138 struct tsc200x *ts = _ts; in tsc200x_irq_thread() local
144 error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata, in tsc200x_irq_thread()
163 if (!ts->pen_down && in tsc200x_irq_thread()
164 ts->in_x == tsdata.x && ts->in_y == tsdata.y && in tsc200x_irq_thread()
165 ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) { in tsc200x_irq_thread()
173 ts->in_x = tsdata.x; in tsc200x_irq_thread()
174 ts->in_y = tsdata.y; in tsc200x_irq_thread()
175 ts->in_z1 = tsdata.z1; in tsc200x_irq_thread()
176 ts->in_z2 = tsdata.z2; in tsc200x_irq_thread()
180 pressure = pressure * ts->x_plate_ohm / 4096; in tsc200x_irq_thread()
184 scoped_guard(spinlock_irqsave, &ts->lock) { in tsc200x_irq_thread()
185 tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); in tsc200x_irq_thread()
186 mod_timer(&ts->penup_timer, in tsc200x_irq_thread()
190 ts->last_valid_interrupt = jiffies; in tsc200x_irq_thread()
197 struct tsc200x *ts = from_timer(ts, t, penup_timer); in tsc200x_penup_timer() local
199 guard(spinlock_irqsave)(&ts->lock); in tsc200x_penup_timer()
200 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_penup_timer()
203 static void tsc200x_start_scan(struct tsc200x *ts) in tsc200x_start_scan() argument
205 regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE); in tsc200x_start_scan()
206 regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE); in tsc200x_start_scan()
207 regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE); in tsc200x_start_scan()
208 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL); in tsc200x_start_scan()
211 static void tsc200x_stop_scan(struct tsc200x *ts) in tsc200x_stop_scan() argument
213 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); in tsc200x_stop_scan()
216 static void tsc200x_reset(struct tsc200x *ts) in tsc200x_reset() argument
218 if (ts->reset_gpio) { in tsc200x_reset()
219 gpiod_set_value_cansleep(ts->reset_gpio, 1); in tsc200x_reset()
221 gpiod_set_value_cansleep(ts->reset_gpio, 0); in tsc200x_reset()
225 /* must be called with ts->mutex held */
226 static void __tsc200x_disable(struct tsc200x *ts) in __tsc200x_disable() argument
228 tsc200x_stop_scan(ts); in __tsc200x_disable()
230 guard(disable_irq)(&ts->irq); in __tsc200x_disable()
232 del_timer_sync(&ts->penup_timer); in __tsc200x_disable()
233 cancel_delayed_work_sync(&ts->esd_work); in __tsc200x_disable()
236 /* must be called with ts->mutex held */
237 static void __tsc200x_enable(struct tsc200x *ts) in __tsc200x_enable() argument
239 tsc200x_start_scan(ts); in __tsc200x_enable()
241 if (ts->esd_timeout && ts->reset_gpio) { in __tsc200x_enable()
242 ts->last_valid_interrupt = jiffies; in __tsc200x_enable()
243 schedule_delayed_work(&ts->esd_work, in __tsc200x_enable()
245 msecs_to_jiffies(ts->esd_timeout))); in __tsc200x_enable()
252 static int tsc200x_do_selftest(struct tsc200x *ts) in tsc200x_do_selftest() argument
259 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); in tsc200x_do_selftest()
261 dev_warn(ts->dev, "selftest failed: read error %d\n", error); in tsc200x_do_selftest()
267 error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); in tsc200x_do_selftest()
269 dev_warn(ts->dev, "selftest failed: write error %d\n", error); in tsc200x_do_selftest()
273 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_do_selftest()
275 dev_warn(ts->dev, in tsc200x_do_selftest()
281 tsc200x_reset(ts); in tsc200x_do_selftest()
284 dev_warn(ts->dev, "selftest failed: %d != %d\n", in tsc200x_do_selftest()
290 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_do_selftest()
292 dev_warn(ts->dev, in tsc200x_do_selftest()
298 dev_warn(ts->dev, "selftest failed after reset: %d != %d\n", in tsc200x_do_selftest()
310 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_selftest_show() local
313 scoped_guard(mutex, &ts->mutex) { in tsc200x_selftest_show()
314 __tsc200x_disable(ts); in tsc200x_selftest_show()
316 error = tsc200x_do_selftest(ts); in tsc200x_selftest_show()
318 __tsc200x_enable(ts); in tsc200x_selftest_show()
335 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_attr_is_visible() local
339 if (!ts->reset_gpio) in tsc200x_attr_is_visible()
359 struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work); in tsc200x_esd_work() local
368 scoped_guard(mutex_try, &ts->mutex) { in tsc200x_esd_work()
369 if (time_is_after_jiffies(ts->last_valid_interrupt + in tsc200x_esd_work()
370 msecs_to_jiffies(ts->esd_timeout))) in tsc200x_esd_work()
377 error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); in tsc200x_esd_work()
388 dev_info(ts->dev, "TSC200X not responding - resetting\n"); in tsc200x_esd_work()
390 scoped_guard(disable_irq, &ts->irq) { in tsc200x_esd_work()
391 del_timer_sync(&ts->penup_timer); in tsc200x_esd_work()
392 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_esd_work()
393 tsc200x_reset(ts); in tsc200x_esd_work()
396 tsc200x_start_scan(ts); in tsc200x_esd_work()
400 schedule_delayed_work(&ts->esd_work, in tsc200x_esd_work()
402 msecs_to_jiffies(ts->esd_timeout))); in tsc200x_esd_work()
407 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_open() local
409 guard(mutex)(&ts->mutex); in tsc200x_open()
411 if (!ts->suspended) in tsc200x_open()
412 __tsc200x_enable(ts); in tsc200x_open()
414 ts->opened = true; in tsc200x_open()
421 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_close() local
423 guard(mutex)(&ts->mutex); in tsc200x_close()
425 if (!ts->suspended) in tsc200x_close()
426 __tsc200x_disable(ts); in tsc200x_close()
428 ts->opened = false; in tsc200x_close()
435 struct tsc200x *ts; in tsc200x_probe() local
454 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in tsc200x_probe()
455 if (!ts) in tsc200x_probe()
462 ts->irq = irq; in tsc200x_probe()
463 ts->dev = dev; in tsc200x_probe()
464 ts->idev = input_dev; in tsc200x_probe()
465 ts->regmap = regmap; in tsc200x_probe()
466 ts->tsc200x_cmd = tsc200x_cmd; in tsc200x_probe()
469 ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; in tsc200x_probe()
473 ts->esd_timeout = error ? 0 : esd_timeout; in tsc200x_probe()
475 mutex_init(&ts->mutex); in tsc200x_probe()
477 spin_lock_init(&ts->lock); in tsc200x_probe()
478 timer_setup(&ts->penup_timer, tsc200x_penup_timer, 0); in tsc200x_probe()
480 INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work); in tsc200x_probe()
482 snprintf(ts->phys, sizeof(ts->phys), in tsc200x_probe()
483 "%s/input-ts", dev_name(dev)); in tsc200x_probe()
495 input_dev->phys = ts->phys; in tsc200x_probe()
501 input_set_drvdata(input_dev, ts); in tsc200x_probe()
513 touchscreen_parse_properties(input_dev, false, &ts->prop); in tsc200x_probe()
515 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in tsc200x_probe()
516 error = PTR_ERR_OR_ZERO(ts->reset_gpio); in tsc200x_probe()
528 tsc200x_reset(ts); in tsc200x_probe()
531 tsc200x_stop_scan(ts); in tsc200x_probe()
534 IRQF_ONESHOT, "tsc200x", ts); in tsc200x_probe()
540 dev_set_drvdata(dev, ts); in tsc200x_probe()
542 error = input_register_device(ts->idev); in tsc200x_probe()
558 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_suspend() local
560 guard(mutex)(&ts->mutex); in tsc200x_suspend()
562 if (!ts->suspended && ts->opened) in tsc200x_suspend()
563 __tsc200x_disable(ts); in tsc200x_suspend()
565 ts->suspended = true; in tsc200x_suspend()
568 ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0; in tsc200x_suspend()
575 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_resume() local
577 guard(mutex)(&ts->mutex); in tsc200x_resume()
579 if (ts->wake_irq_enabled) { in tsc200x_resume()
580 disable_irq_wake(ts->irq); in tsc200x_resume()
581 ts->wake_irq_enabled = false; in tsc200x_resume()
584 if (ts->suspended && ts->opened) in tsc200x_resume()
585 __tsc200x_enable(ts); in tsc200x_resume()
587 ts->suspended = false; in tsc200x_resume()