Lines Matching refs: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
145 error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata, in tsc200x_irq_thread()
164 if (!ts->pen_down && in tsc200x_irq_thread()
165 ts->in_x == tsdata.x && ts->in_y == tsdata.y && in tsc200x_irq_thread()
166 ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) { in tsc200x_irq_thread()
174 ts->in_x = tsdata.x; in tsc200x_irq_thread()
175 ts->in_y = tsdata.y; in tsc200x_irq_thread()
176 ts->in_z1 = tsdata.z1; in tsc200x_irq_thread()
177 ts->in_z2 = tsdata.z2; in tsc200x_irq_thread()
181 pressure = pressure * ts->x_plate_ohm / 4096; in tsc200x_irq_thread()
185 spin_lock_irqsave(&ts->lock, flags); in tsc200x_irq_thread()
187 tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); in tsc200x_irq_thread()
188 mod_timer(&ts->penup_timer, in tsc200x_irq_thread()
191 spin_unlock_irqrestore(&ts->lock, flags); in tsc200x_irq_thread()
193 ts->last_valid_interrupt = jiffies; in tsc200x_irq_thread()
200 struct tsc200x *ts = from_timer(ts, t, penup_timer); in tsc200x_penup_timer() local
203 spin_lock_irqsave(&ts->lock, flags); in tsc200x_penup_timer()
204 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_penup_timer()
205 spin_unlock_irqrestore(&ts->lock, flags); in tsc200x_penup_timer()
208 static void tsc200x_start_scan(struct tsc200x *ts) in tsc200x_start_scan() argument
210 regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE); in tsc200x_start_scan()
211 regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE); in tsc200x_start_scan()
212 regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE); in tsc200x_start_scan()
213 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL); in tsc200x_start_scan()
216 static void tsc200x_stop_scan(struct tsc200x *ts) in tsc200x_stop_scan() argument
218 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); in tsc200x_stop_scan()
221 static void tsc200x_reset(struct tsc200x *ts) in tsc200x_reset() argument
223 if (ts->reset_gpio) { in tsc200x_reset()
224 gpiod_set_value_cansleep(ts->reset_gpio, 1); in tsc200x_reset()
226 gpiod_set_value_cansleep(ts->reset_gpio, 0); in tsc200x_reset()
231 static void __tsc200x_disable(struct tsc200x *ts) in __tsc200x_disable() argument
233 tsc200x_stop_scan(ts); in __tsc200x_disable()
235 disable_irq(ts->irq); in __tsc200x_disable()
236 del_timer_sync(&ts->penup_timer); in __tsc200x_disable()
238 cancel_delayed_work_sync(&ts->esd_work); in __tsc200x_disable()
240 enable_irq(ts->irq); in __tsc200x_disable()
244 static void __tsc200x_enable(struct tsc200x *ts) in __tsc200x_enable() argument
246 tsc200x_start_scan(ts); in __tsc200x_enable()
248 if (ts->esd_timeout && ts->reset_gpio) { in __tsc200x_enable()
249 ts->last_valid_interrupt = jiffies; in __tsc200x_enable()
250 schedule_delayed_work(&ts->esd_work, in __tsc200x_enable()
252 msecs_to_jiffies(ts->esd_timeout))); in __tsc200x_enable()
260 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_selftest_show() local
267 mutex_lock(&ts->mutex); in tsc200x_selftest_show()
272 __tsc200x_disable(ts); in tsc200x_selftest_show()
274 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); in tsc200x_selftest_show()
283 error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); in tsc200x_selftest_show()
290 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_selftest_show()
305 tsc200x_reset(ts); in tsc200x_selftest_show()
311 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_selftest_show()
326 __tsc200x_enable(ts); in tsc200x_selftest_show()
327 mutex_unlock(&ts->mutex); in tsc200x_selftest_show()
343 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_attr_is_visible() local
347 if (!ts->reset_gpio) in tsc200x_attr_is_visible()
361 struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work); in tsc200x_esd_work() local
365 if (!mutex_trylock(&ts->mutex)) { in tsc200x_esd_work()
374 if (time_is_after_jiffies(ts->last_valid_interrupt + in tsc200x_esd_work()
375 msecs_to_jiffies(ts->esd_timeout))) in tsc200x_esd_work()
379 error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); in tsc200x_esd_work()
390 dev_info(ts->dev, "TSC200X not responding - resetting\n"); in tsc200x_esd_work()
392 disable_irq(ts->irq); in tsc200x_esd_work()
393 del_timer_sync(&ts->penup_timer); in tsc200x_esd_work()
395 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_esd_work()
397 tsc200x_reset(ts); in tsc200x_esd_work()
399 enable_irq(ts->irq); in tsc200x_esd_work()
400 tsc200x_start_scan(ts); in tsc200x_esd_work()
403 mutex_unlock(&ts->mutex); in tsc200x_esd_work()
406 schedule_delayed_work(&ts->esd_work, in tsc200x_esd_work()
408 msecs_to_jiffies(ts->esd_timeout))); in tsc200x_esd_work()
413 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_open() local
415 mutex_lock(&ts->mutex); in tsc200x_open()
417 if (!ts->suspended) in tsc200x_open()
418 __tsc200x_enable(ts); in tsc200x_open()
420 ts->opened = true; in tsc200x_open()
422 mutex_unlock(&ts->mutex); in tsc200x_open()
429 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_close() local
431 mutex_lock(&ts->mutex); in tsc200x_close()
433 if (!ts->suspended) in tsc200x_close()
434 __tsc200x_disable(ts); in tsc200x_close()
436 ts->opened = false; in tsc200x_close()
438 mutex_unlock(&ts->mutex); in tsc200x_close()
445 struct tsc200x *ts; in tsc200x_probe() local
464 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in tsc200x_probe()
465 if (!ts) in tsc200x_probe()
472 ts->irq = irq; in tsc200x_probe()
473 ts->dev = dev; in tsc200x_probe()
474 ts->idev = input_dev; in tsc200x_probe()
475 ts->regmap = regmap; in tsc200x_probe()
476 ts->tsc200x_cmd = tsc200x_cmd; in tsc200x_probe()
479 ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; in tsc200x_probe()
483 ts->esd_timeout = error ? 0 : esd_timeout; in tsc200x_probe()
485 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in tsc200x_probe()
486 if (IS_ERR(ts->reset_gpio)) { in tsc200x_probe()
487 error = PTR_ERR(ts->reset_gpio); in tsc200x_probe()
492 ts->vio = devm_regulator_get(dev, "vio"); in tsc200x_probe()
493 if (IS_ERR(ts->vio)) { in tsc200x_probe()
494 error = PTR_ERR(ts->vio); in tsc200x_probe()
499 mutex_init(&ts->mutex); in tsc200x_probe()
501 spin_lock_init(&ts->lock); in tsc200x_probe()
502 timer_setup(&ts->penup_timer, tsc200x_penup_timer, 0); in tsc200x_probe()
504 INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work); in tsc200x_probe()
506 snprintf(ts->phys, sizeof(ts->phys), in tsc200x_probe()
519 input_dev->phys = ts->phys; in tsc200x_probe()
525 input_set_drvdata(input_dev, ts); in tsc200x_probe()
537 touchscreen_parse_properties(input_dev, false, &ts->prop); in tsc200x_probe()
540 tsc200x_stop_scan(ts); in tsc200x_probe()
545 "tsc200x", ts); in tsc200x_probe()
551 error = regulator_enable(ts->vio); in tsc200x_probe()
555 dev_set_drvdata(dev, ts); in tsc200x_probe()
563 error = input_register_device(ts->idev); in tsc200x_probe()
576 regulator_disable(ts->vio); in tsc200x_probe()
583 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_remove() local
587 regulator_disable(ts->vio); in tsc200x_remove()
593 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_suspend() local
595 mutex_lock(&ts->mutex); in tsc200x_suspend()
597 if (!ts->suspended && ts->opened) in tsc200x_suspend()
598 __tsc200x_disable(ts); in tsc200x_suspend()
600 ts->suspended = true; in tsc200x_suspend()
602 mutex_unlock(&ts->mutex); in tsc200x_suspend()
609 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_resume() local
611 mutex_lock(&ts->mutex); in tsc200x_resume()
613 if (ts->suspended && ts->opened) in tsc200x_resume()
614 __tsc200x_enable(ts); in tsc200x_resume()
616 ts->suspended = false; in tsc200x_resume()
618 mutex_unlock(&ts->mutex); in tsc200x_resume()