Lines Matching refs:ts
120 static void tsc200x_update_pen_state(struct tsc200x *ts, in tsc200x_update_pen_state() argument
124 input_report_abs(ts->idev, ABS_X, x); in tsc200x_update_pen_state()
125 input_report_abs(ts->idev, ABS_Y, y); in tsc200x_update_pen_state()
126 input_report_abs(ts->idev, ABS_PRESSURE, pressure); in tsc200x_update_pen_state()
127 if (!ts->pen_down) { in tsc200x_update_pen_state()
128 input_report_key(ts->idev, BTN_TOUCH, !!pressure); in tsc200x_update_pen_state()
129 ts->pen_down = true; in tsc200x_update_pen_state()
132 input_report_abs(ts->idev, ABS_PRESSURE, 0); in tsc200x_update_pen_state()
133 if (ts->pen_down) { in tsc200x_update_pen_state()
134 input_report_key(ts->idev, BTN_TOUCH, 0); in tsc200x_update_pen_state()
135 ts->pen_down = false; in tsc200x_update_pen_state()
138 input_sync(ts->idev); in tsc200x_update_pen_state()
139 dev_dbg(ts->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, in tsc200x_update_pen_state()
145 struct tsc200x *ts = _ts; in tsc200x_irq_thread() local
152 error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata, in tsc200x_irq_thread()
171 if (!ts->pen_down && in tsc200x_irq_thread()
172 ts->in_x == tsdata.x && ts->in_y == tsdata.y && in tsc200x_irq_thread()
173 ts->in_z1 == tsdata.z1 && ts->in_z2 == tsdata.z2) { in tsc200x_irq_thread()
181 ts->in_x = tsdata.x; in tsc200x_irq_thread()
182 ts->in_y = tsdata.y; in tsc200x_irq_thread()
183 ts->in_z1 = tsdata.z1; in tsc200x_irq_thread()
184 ts->in_z2 = tsdata.z2; in tsc200x_irq_thread()
188 pressure = pressure * ts->x_plate_ohm / 4096; in tsc200x_irq_thread()
192 spin_lock_irqsave(&ts->lock, flags); in tsc200x_irq_thread()
194 tsc200x_update_pen_state(ts, tsdata.x, tsdata.y, pressure); in tsc200x_irq_thread()
195 mod_timer(&ts->penup_timer, in tsc200x_irq_thread()
198 spin_unlock_irqrestore(&ts->lock, flags); in tsc200x_irq_thread()
200 ts->last_valid_interrupt = jiffies; in tsc200x_irq_thread()
207 struct tsc200x *ts = from_timer(ts, t, penup_timer); in tsc200x_penup_timer() local
210 spin_lock_irqsave(&ts->lock, flags); in tsc200x_penup_timer()
211 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_penup_timer()
212 spin_unlock_irqrestore(&ts->lock, flags); in tsc200x_penup_timer()
215 static void tsc200x_start_scan(struct tsc200x *ts) in tsc200x_start_scan() argument
217 regmap_write(ts->regmap, TSC200X_REG_CFR0, TSC200X_CFR0_INITVALUE); in tsc200x_start_scan()
218 regmap_write(ts->regmap, TSC200X_REG_CFR1, TSC200X_CFR1_INITVALUE); in tsc200x_start_scan()
219 regmap_write(ts->regmap, TSC200X_REG_CFR2, TSC200X_CFR2_INITVALUE); in tsc200x_start_scan()
220 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_NORMAL); in tsc200x_start_scan()
223 static void tsc200x_stop_scan(struct tsc200x *ts) in tsc200x_stop_scan() argument
225 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); in tsc200x_stop_scan()
228 static void tsc200x_reset(struct tsc200x *ts) in tsc200x_reset() argument
230 if (ts->reset_gpio) { in tsc200x_reset()
231 gpiod_set_value_cansleep(ts->reset_gpio, 1); in tsc200x_reset()
233 gpiod_set_value_cansleep(ts->reset_gpio, 0); in tsc200x_reset()
238 static void __tsc200x_disable(struct tsc200x *ts) in __tsc200x_disable() argument
240 tsc200x_stop_scan(ts); in __tsc200x_disable()
242 disable_irq(ts->irq); in __tsc200x_disable()
243 del_timer_sync(&ts->penup_timer); in __tsc200x_disable()
245 cancel_delayed_work_sync(&ts->esd_work); in __tsc200x_disable()
247 enable_irq(ts->irq); in __tsc200x_disable()
251 static void __tsc200x_enable(struct tsc200x *ts) in __tsc200x_enable() argument
253 tsc200x_start_scan(ts); in __tsc200x_enable()
255 if (ts->esd_timeout && ts->reset_gpio) { in __tsc200x_enable()
256 ts->last_valid_interrupt = jiffies; in __tsc200x_enable()
257 schedule_delayed_work(&ts->esd_work, in __tsc200x_enable()
259 msecs_to_jiffies(ts->esd_timeout))); in __tsc200x_enable()
267 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_selftest_show() local
274 mutex_lock(&ts->mutex); in tsc200x_selftest_show()
279 __tsc200x_disable(ts); in tsc200x_selftest_show()
281 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high_orig); in tsc200x_selftest_show()
290 error = regmap_write(ts->regmap, TSC200X_REG_TEMP_HIGH, temp_high_test); in tsc200x_selftest_show()
297 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_selftest_show()
312 tsc200x_reset(ts); in tsc200x_selftest_show()
318 error = regmap_read(ts->regmap, TSC200X_REG_TEMP_HIGH, &temp_high); in tsc200x_selftest_show()
333 __tsc200x_enable(ts); in tsc200x_selftest_show()
334 mutex_unlock(&ts->mutex); in tsc200x_selftest_show()
350 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_attr_is_visible() local
354 if (!ts->reset_gpio) in tsc200x_attr_is_visible()
368 struct tsc200x *ts = container_of(work, struct tsc200x, esd_work.work); in tsc200x_esd_work() local
372 if (!mutex_trylock(&ts->mutex)) { in tsc200x_esd_work()
381 if (time_is_after_jiffies(ts->last_valid_interrupt + in tsc200x_esd_work()
382 msecs_to_jiffies(ts->esd_timeout))) in tsc200x_esd_work()
386 error = regmap_read(ts->regmap, TSC200X_REG_CFR0, &r); in tsc200x_esd_work()
397 dev_info(ts->dev, "TSC200X not responding - resetting\n"); in tsc200x_esd_work()
399 disable_irq(ts->irq); in tsc200x_esd_work()
400 del_timer_sync(&ts->penup_timer); in tsc200x_esd_work()
402 tsc200x_update_pen_state(ts, 0, 0, 0); in tsc200x_esd_work()
404 tsc200x_reset(ts); in tsc200x_esd_work()
406 enable_irq(ts->irq); in tsc200x_esd_work()
407 tsc200x_start_scan(ts); in tsc200x_esd_work()
410 mutex_unlock(&ts->mutex); in tsc200x_esd_work()
413 schedule_delayed_work(&ts->esd_work, in tsc200x_esd_work()
415 msecs_to_jiffies(ts->esd_timeout))); in tsc200x_esd_work()
420 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_open() local
422 mutex_lock(&ts->mutex); in tsc200x_open()
424 if (!ts->suspended) in tsc200x_open()
425 __tsc200x_enable(ts); in tsc200x_open()
427 ts->opened = true; in tsc200x_open()
429 mutex_unlock(&ts->mutex); in tsc200x_open()
436 struct tsc200x *ts = input_get_drvdata(input); in tsc200x_close() local
438 mutex_lock(&ts->mutex); in tsc200x_close()
440 if (!ts->suspended) in tsc200x_close()
441 __tsc200x_disable(ts); in tsc200x_close()
443 ts->opened = false; in tsc200x_close()
445 mutex_unlock(&ts->mutex); in tsc200x_close()
452 struct tsc200x *ts; in tsc200x_probe() local
471 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in tsc200x_probe()
472 if (!ts) in tsc200x_probe()
479 ts->irq = irq; in tsc200x_probe()
480 ts->dev = dev; in tsc200x_probe()
481 ts->idev = input_dev; in tsc200x_probe()
482 ts->regmap = regmap; in tsc200x_probe()
483 ts->tsc200x_cmd = tsc200x_cmd; in tsc200x_probe()
486 ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; in tsc200x_probe()
490 ts->esd_timeout = error ? 0 : esd_timeout; in tsc200x_probe()
492 ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); in tsc200x_probe()
493 if (IS_ERR(ts->reset_gpio)) { in tsc200x_probe()
494 error = PTR_ERR(ts->reset_gpio); in tsc200x_probe()
499 ts->vio = devm_regulator_get(dev, "vio"); in tsc200x_probe()
500 if (IS_ERR(ts->vio)) { in tsc200x_probe()
501 error = PTR_ERR(ts->vio); in tsc200x_probe()
506 mutex_init(&ts->mutex); in tsc200x_probe()
508 spin_lock_init(&ts->lock); in tsc200x_probe()
509 timer_setup(&ts->penup_timer, tsc200x_penup_timer, 0); in tsc200x_probe()
511 INIT_DELAYED_WORK(&ts->esd_work, tsc200x_esd_work); in tsc200x_probe()
513 snprintf(ts->phys, sizeof(ts->phys), in tsc200x_probe()
526 input_dev->phys = ts->phys; in tsc200x_probe()
532 input_set_drvdata(input_dev, ts); in tsc200x_probe()
547 tsc200x_stop_scan(ts); in tsc200x_probe()
552 "tsc200x", ts); in tsc200x_probe()
558 error = regulator_enable(ts->vio); in tsc200x_probe()
562 dev_set_drvdata(dev, ts); in tsc200x_probe()
570 error = input_register_device(ts->idev); in tsc200x_probe()
583 regulator_disable(ts->vio); in tsc200x_probe()
590 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_remove() local
594 regulator_disable(ts->vio); in tsc200x_remove()
602 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_suspend() local
604 mutex_lock(&ts->mutex); in tsc200x_suspend()
606 if (!ts->suspended && ts->opened) in tsc200x_suspend()
607 __tsc200x_disable(ts); in tsc200x_suspend()
609 ts->suspended = true; in tsc200x_suspend()
611 mutex_unlock(&ts->mutex); in tsc200x_suspend()
618 struct tsc200x *ts = dev_get_drvdata(dev); in tsc200x_resume() local
620 mutex_lock(&ts->mutex); in tsc200x_resume()
622 if (ts->suspended && ts->opened) in tsc200x_resume()
623 __tsc200x_enable(ts); in tsc200x_resume()
625 ts->suspended = false; in tsc200x_resume()
627 mutex_unlock(&ts->mutex); in tsc200x_resume()