Lines Matching +full:x +full:- +full:plate +full:- +full:resistance

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2006-2010 Nokia Corporation
24 #include "tsc200x-core.h"
33 * 5) tsc200x_irq_thread() queues up a transfer to fetch the x, y, z1, z2
68 u16 x; member
85 /* raw copy of previous x,y,z */
115 int x, int y, int pressure) 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()
144 error = regmap_bulk_read(ts->regmap, TSC200X_REG_X, &tsdata, in tsc200x_irq_thread()
150 if (unlikely(tsdata.x > MAX_12BIT || tsdata.y > MAX_12BIT)) in tsc200x_irq_thread()
161 * the value before pen-up - that implies SPI fed us stale data 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()
178 /* Compute touch pressure resistance using equation #1 */ in tsc200x_irq_thread()
179 pressure = tsdata.x * (tsdata.z2 - tsdata.z1) / tsdata.z1; 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()
199 guard(spinlock_irqsave)(&ts->lock); in tsc200x_penup_timer()
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()
213 ts->tsc200x_cmd(ts->dev, TSC200X_CMD_STOP); in tsc200x_stop_scan()
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 */
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 */
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()
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()
265 temp_high_test = (temp_high_orig - 1) & MAX_12BIT; 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()
284 dev_warn(ts->dev, "selftest failed: %d != %d\n", in tsc200x_do_selftest()
286 return -EINVAL; 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()
300 return -EINVAL; in tsc200x_do_selftest()
313 scoped_guard(mutex, &ts->mutex) { in tsc200x_selftest_show()
336 umode_t mode = attr->mode; in tsc200x_attr_is_visible()
339 if (!ts->reset_gpio) in tsc200x_attr_is_visible()
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()
386 * power-up and start scanning again. 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()
399 /* re-arm the watchdog */ 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()
409 guard(mutex)(&ts->mutex); in tsc200x_open()
411 if (!ts->suspended) in tsc200x_open()
414 ts->opened = true; in tsc200x_open()
423 guard(mutex)(&ts->mutex); in tsc200x_close()
425 if (!ts->suspended) in tsc200x_close()
428 ts->opened = false; in tsc200x_close()
443 return -ENODEV; in tsc200x_probe()
451 return -ENODEV; in tsc200x_probe()
456 return -ENOMEM; in tsc200x_probe()
460 return -ENOMEM; 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()
468 error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm); in tsc200x_probe()
469 ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm; in tsc200x_probe()
471 error = device_property_read_u32(dev, "ti,esd-recovery-timeout-ms", 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()
485 if (tsc_id->product == 2004) { in tsc200x_probe()
486 input_dev->name = "TSC200X touchscreen"; in tsc200x_probe()
488 input_dev->name = devm_kasprintf(dev, GFP_KERNEL, in tsc200x_probe()
490 tsc_id->product); in tsc200x_probe()
491 if (!input_dev->name) in tsc200x_probe()
492 return -ENOMEM; in tsc200x_probe()
495 input_dev->phys = ts->phys; in tsc200x_probe()
496 input_dev->id = *tsc_id; in tsc200x_probe()
498 input_dev->open = tsc200x_open; in tsc200x_probe()
499 input_dev->close = tsc200x_close; in tsc200x_probe()
503 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit); 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()
542 error = input_register_device(ts->idev); in tsc200x_probe()
550 device_property_read_bool(dev, "wakeup-source")); in tsc200x_probe()
560 guard(mutex)(&ts->mutex); in tsc200x_suspend()
562 if (!ts->suspended && ts->opened) in tsc200x_suspend()
565 ts->suspended = true; in tsc200x_suspend()
568 ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0; in tsc200x_suspend()
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()
587 ts->suspended = false; in tsc200x_resume()