Lines Matching refs:ts
112 static void tsc200x_update_pen_state(struct tsc200x *ts, in tsc200x_update_pen_state() argument
116 input_report_abs(ts->idev, ABS_X, x); in tsc200x_update_pen_state()
117 input_report_abs(ts->idev, ABS_Y, y); in tsc200x_update_pen_state()
118 input_report_abs(ts->idev, ABS_PRESSURE, pressure); in tsc200x_update_pen_state()
119 if (!ts->pen_down) { in tsc200x_update_pen_state()
120 input_report_key(ts->idev, BTN_TOUCH, !!pressure); in tsc200x_update_pen_state()
121 ts->pen_down = true; in tsc200x_update_pen_state()
124 input_report_abs(ts->idev, ABS_PRESSURE, 0); in tsc200x_update_pen_state()
125 if (ts->pen_down) { in tsc200x_update_pen_state()
126 input_report_key(ts->idev, BTN_TOUCH, 0); in tsc200x_update_pen_state()
127 ts->pen_down = false; in tsc200x_update_pen_state()
130 input_sync(ts->idev); in tsc200x_update_pen_state()
131 dev_dbg(ts->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, in tsc200x_update_pen_state()
137 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 spin_lock_irqsave(&ts->lock, flags); in tsc200x_irq_thread()
186 tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); in tsc200x_irq_thread()
187 mod_timer(&ts->penup_timer, in tsc200x_irq_thread()
190 spin_unlock_irqrestore(&ts->lock, flags); in tsc200x_irq_thread()
192 ts->last_valid_interrupt = jiffies; in tsc200x_irq_thread()
199 struct tsc200x *ts = from_timer(ts, t, penup_timer); in tsc200x_penup_timer() local
202 spin_lock_irqsave(&ts->lock, flags); in tsc200x_penup_timer()
203 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_penup_timer()
204 spin_unlock_irqrestore(&ts->lock, flags); in tsc200x_penup_timer()
207 static void tsc200x_start_scan(struct tsc200x *ts) in tsc200x_start_scan() argument
209 regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE); in tsc200x_start_scan()
210 regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE); in tsc200x_start_scan()
211 regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE); in tsc200x_start_scan()
212 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL); in tsc200x_start_scan()
215 static void tsc200x_stop_scan(struct tsc200x *ts) in tsc200x_stop_scan() argument
217 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); in tsc200x_stop_scan()
220 static void tsc200x_reset(struct tsc200x *ts) in tsc200x_reset() argument
222 if (ts->reset_gpio) { in tsc200x_reset()
223 gpiod_set_value_cansleep(ts->reset_gpio, 1); in tsc200x_reset()
225 gpiod_set_value_cansleep(ts->reset_gpio, 0); in tsc200x_reset()
230 static void __tsc200x_disable(struct tsc200x *ts) in __tsc200x_disable() argument
232 tsc200x_stop_scan(ts); in __tsc200x_disable()
234 disable_irq(ts->irq); in __tsc200x_disable()
235 del_timer_sync(&ts->penup_timer); in __tsc200x_disable()
237 cancel_delayed_work_sync(&ts->esd_work); in __tsc200x_disable()
239 enable_irq(ts->irq); in __tsc200x_disable()
243 static void __tsc200x_enable(struct tsc200x *ts) in __tsc200x_enable() argument
245 tsc200x_start_scan(ts); in __tsc200x_enable()
247 if (ts->esd_timeout && ts->reset_gpio) { in __tsc200x_enable()
248 ts->last_valid_interrupt = jiffies; in __tsc200x_enable()
249 schedule_delayed_work(&ts->esd_work, in __tsc200x_enable()
251 msecs_to_jiffies(ts->esd_timeout))); in __tsc200x_enable()
259 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_selftest_show() local
266 mutex_lock(&ts->mutex); in tsc200x_selftest_show()
271 __tsc200x_disable(ts); in tsc200x_selftest_show()
273 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); in tsc200x_selftest_show()
282 error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); in tsc200x_selftest_show()
289 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_selftest_show()
304 tsc200x_reset(ts); in tsc200x_selftest_show()
310 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_selftest_show()
325 __tsc200x_enable(ts); in tsc200x_selftest_show()
326 mutex_unlock(&ts->mutex); in tsc200x_selftest_show()
342 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_attr_is_visible() local
346 if (!ts->reset_gpio) in tsc200x_attr_is_visible()
360 struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work); in tsc200x_esd_work() local
364 if (!mutex_trylock(&ts->mutex)) { in tsc200x_esd_work()
373 if (time_is_after_jiffies(ts->last_valid_interrupt + in tsc200x_esd_work()
374 msecs_to_jiffies(ts->esd_timeout))) in tsc200x_esd_work()
378 error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); in tsc200x_esd_work()
389 dev_info(ts->dev, "TSC200X not responding - resetting\n"); in tsc200x_esd_work()
391 disable_irq(ts->irq); in tsc200x_esd_work()
392 del_timer_sync(&ts->penup_timer); in tsc200x_esd_work()
394 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_esd_work()
396 tsc200x_reset(ts); in tsc200x_esd_work()
398 enable_irq(ts->irq); in tsc200x_esd_work()
399 tsc200x_start_scan(ts); in tsc200x_esd_work()
402 mutex_unlock(&ts->mutex); in tsc200x_esd_work()
405 schedule_delayed_work(&ts->esd_work, in tsc200x_esd_work()
407 msecs_to_jiffies(ts->esd_timeout))); in tsc200x_esd_work()
412 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_open() local
414 mutex_lock(&ts->mutex); in tsc200x_open()
416 if (!ts->suspended) in tsc200x_open()
417 __tsc200x_enable(ts); in tsc200x_open()
419 ts->opened = true; in tsc200x_open()
421 mutex_unlock(&ts->mutex); in tsc200x_open()
428 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_close() local
430 mutex_lock(&ts->mutex); in tsc200x_close()
432 if (!ts->suspended) in tsc200x_close()
433 __tsc200x_disable(ts); in tsc200x_close()
435 ts->opened = false; in tsc200x_close()
437 mutex_unlock(&ts->mutex); in tsc200x_close()
444 struct tsc200x *ts; in tsc200x_probe() local
463 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in tsc200x_probe()
464 if (!ts) in tsc200x_probe()
471 ts->irq = irq; in tsc200x_probe()
472 ts->dev = dev; in tsc200x_probe()
473 ts->idev = input_dev; in tsc200x_probe()
474 ts->regmap = regmap; in tsc200x_probe()
475 ts->tsc200x_cmd = tsc200x_cmd; in tsc200x_probe()
478 ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; in tsc200x_probe()
482 ts->esd_timeout = error ? 0 : esd_timeout; in tsc200x_probe()
484 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in tsc200x_probe()
485 if (IS_ERR(ts->reset_gpio)) { in tsc200x_probe()
486 error = PTR_ERR(ts->reset_gpio); in tsc200x_probe()
491 ts->vio = devm_regulator_get(dev, "vio"); in tsc200x_probe()
492 if (IS_ERR(ts->vio)) { in tsc200x_probe()
493 error = PTR_ERR(ts->vio); in tsc200x_probe()
498 mutex_init(&ts->mutex); in tsc200x_probe()
500 spin_lock_init(&ts->lock); in tsc200x_probe()
501 timer_setup(&ts->penup_timer, tsc200x_penup_timer, 0); in tsc200x_probe()
503 INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work); in tsc200x_probe()
505 snprintf(ts->phys, sizeof(ts->phys), in tsc200x_probe()
518 input_dev->phys = ts->phys; in tsc200x_probe()
524 input_set_drvdata(input_dev, ts); in tsc200x_probe()
539 tsc200x_stop_scan(ts); in tsc200x_probe()
544 "tsc200x", ts); in tsc200x_probe()
550 error = regulator_enable(ts->vio); in tsc200x_probe()
554 dev_set_drvdata(dev, ts); in tsc200x_probe()
562 error = input_register_device(ts->idev); in tsc200x_probe()
575 regulator_disable(ts->vio); in tsc200x_probe()
582 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_remove() local
586 regulator_disable(ts->vio); in tsc200x_remove()
592 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_suspend() local
594 mutex_lock(&ts->mutex); in tsc200x_suspend()
596 if (!ts->suspended && ts->opened) in tsc200x_suspend()
597 __tsc200x_disable(ts); in tsc200x_suspend()
599 ts->suspended = true; in tsc200x_suspend()
601 mutex_unlock(&ts->mutex); in tsc200x_suspend()
608 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_resume() local
610 mutex_lock(&ts->mutex); in tsc200x_resume()
612 if (ts->suspended && ts->opened) in tsc200x_resume()
613 __tsc200x_enable(ts); in tsc200x_resume()
615 ts->suspended = false; in tsc200x_resume()
617 mutex_unlock(&ts->mutex); in tsc200x_resume()