Lines Matching refs:ts
149 static int tsc2005_cmd(struct tsc2005 *ts, u8 cmd) in tsc2005_cmd() argument
163 error = spi_sync(ts->spi, &msg); in tsc2005_cmd()
165 dev_err(&ts->spi->dev, "%s: failed, command: %x, error: %d\n", in tsc2005_cmd()
173 static int tsc2005_write(struct tsc2005 *ts, u8 reg, u16 value) in tsc2005_write() argument
187 error = spi_sync(ts->spi, &msg); in tsc2005_write()
189 dev_err(&ts->spi->dev, in tsc2005_write()
210 static int tsc2005_read(struct tsc2005 *ts, u8 reg, u16 *value) in tsc2005_read() argument
221 error = spi_sync(ts->spi, &msg); in tsc2005_read()
229 static void tsc2005_update_pen_state(struct tsc2005 *ts, in tsc2005_update_pen_state() argument
233 input_report_abs(ts->idev, ABS_X, x); in tsc2005_update_pen_state()
234 input_report_abs(ts->idev, ABS_Y, y); in tsc2005_update_pen_state()
235 input_report_abs(ts->idev, ABS_PRESSURE, pressure); in tsc2005_update_pen_state()
236 if (!ts->pen_down) { in tsc2005_update_pen_state()
237 input_report_key(ts->idev, BTN_TOUCH, !!pressure); in tsc2005_update_pen_state()
238 ts->pen_down = true; in tsc2005_update_pen_state()
241 input_report_abs(ts->idev, ABS_PRESSURE, 0); in tsc2005_update_pen_state()
242 if (ts->pen_down) { in tsc2005_update_pen_state()
243 input_report_key(ts->idev, BTN_TOUCH, 0); in tsc2005_update_pen_state()
244 ts->pen_down = false; in tsc2005_update_pen_state()
247 input_sync(ts->idev); in tsc2005_update_pen_state()
248 dev_dbg(&ts->spi->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, in tsc2005_update_pen_state()
254 struct tsc2005 *ts = _ts; in tsc2005_irq_thread() local
262 error = spi_sync(ts->spi, &ts->spi_read_msg); in tsc2005_irq_thread()
266 x = ts->spi_x.spi_rx; in tsc2005_irq_thread()
267 y = ts->spi_y.spi_rx; in tsc2005_irq_thread()
268 z1 = ts->spi_z1.spi_rx; in tsc2005_irq_thread()
269 z2 = ts->spi_z2.spi_rx; in tsc2005_irq_thread()
283 if (!ts->pen_down && in tsc2005_irq_thread()
284 ts->in_x == x && ts->in_y == y && in tsc2005_irq_thread()
285 ts->in_z1 == z1 && ts->in_z2 == z2) { in tsc2005_irq_thread()
293 ts->in_x = x; in tsc2005_irq_thread()
294 ts->in_y = y; in tsc2005_irq_thread()
295 ts->in_z1 = z1; in tsc2005_irq_thread()
296 ts->in_z2 = z2; in tsc2005_irq_thread()
300 pressure = pressure * ts->x_plate_ohm / 4096; in tsc2005_irq_thread()
304 spin_lock_irqsave(&ts->lock, flags); in tsc2005_irq_thread()
306 tsc2005_update_pen_state(ts, x, y, pressure); in tsc2005_irq_thread()
307 mod_timer(&ts->penup_timer, in tsc2005_irq_thread()
310 spin_unlock_irqrestore(&ts->lock, flags); in tsc2005_irq_thread()
312 ts->last_valid_interrupt = jiffies; in tsc2005_irq_thread()
319 struct tsc2005 *ts = (struct tsc2005 *)data; in tsc2005_penup_timer() local
322 spin_lock_irqsave(&ts->lock, flags); in tsc2005_penup_timer()
323 tsc2005_update_pen_state(ts, 0, 0, 0); in tsc2005_penup_timer()
324 spin_unlock_irqrestore(&ts->lock, flags); in tsc2005_penup_timer()
327 static void tsc2005_start_scan(struct tsc2005 *ts) in tsc2005_start_scan() argument
329 tsc2005_write(ts, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE); in tsc2005_start_scan()
330 tsc2005_write(ts, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE); in tsc2005_start_scan()
331 tsc2005_write(ts, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE); in tsc2005_start_scan()
332 tsc2005_cmd(ts, TSC2005_CMD_NORMAL); in tsc2005_start_scan()
335 static void tsc2005_stop_scan(struct tsc2005 *ts) in tsc2005_stop_scan() argument
337 tsc2005_cmd(ts, TSC2005_CMD_STOP); in tsc2005_stop_scan()
341 static void __tsc2005_disable(struct tsc2005 *ts) in __tsc2005_disable() argument
343 tsc2005_stop_scan(ts); in __tsc2005_disable()
345 disable_irq(ts->spi->irq); in __tsc2005_disable()
346 del_timer_sync(&ts->penup_timer); in __tsc2005_disable()
348 cancel_delayed_work_sync(&ts->esd_work); in __tsc2005_disable()
350 enable_irq(ts->spi->irq); in __tsc2005_disable()
354 static void __tsc2005_enable(struct tsc2005 *ts) in __tsc2005_enable() argument
356 tsc2005_start_scan(ts); in __tsc2005_enable()
358 if (ts->esd_timeout && ts->set_reset) { in __tsc2005_enable()
359 ts->last_valid_interrupt = jiffies; in __tsc2005_enable()
360 schedule_delayed_work(&ts->esd_work, in __tsc2005_enable()
362 msecs_to_jiffies(ts->esd_timeout))); in __tsc2005_enable()
372 struct tsc2005 *ts = spi_get_drvdata(spi); in tsc2005_selftest_show() local
379 mutex_lock(&ts->mutex); in tsc2005_selftest_show()
384 __tsc2005_disable(ts); in tsc2005_selftest_show()
386 error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig); in tsc2005_selftest_show()
395 error = tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test); in tsc2005_selftest_show()
402 error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high); in tsc2005_selftest_show()
417 ts->set_reset(false); in tsc2005_selftest_show()
419 ts->set_reset(true); in tsc2005_selftest_show()
425 error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high); in tsc2005_selftest_show()
440 __tsc2005_enable(ts); in tsc2005_selftest_show()
441 mutex_unlock(&ts->mutex); in tsc2005_selftest_show()
458 struct tsc2005 *ts = spi_get_drvdata(spi); in tsc2005_attr_is_visible() local
462 if (!ts->set_reset) in tsc2005_attr_is_visible()
476 struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work.work); in tsc2005_esd_work() local
480 if (!mutex_trylock(&ts->mutex)) { in tsc2005_esd_work()
489 if (time_is_after_jiffies(ts->last_valid_interrupt + in tsc2005_esd_work()
490 msecs_to_jiffies(ts->esd_timeout))) in tsc2005_esd_work()
494 error = tsc2005_read(ts, TSC2005_REG_CFR0, &r); in tsc2005_esd_work()
505 dev_info(&ts->spi->dev, "TSC2005 not responding - resetting\n"); in tsc2005_esd_work()
507 disable_irq(ts->spi->irq); in tsc2005_esd_work()
508 del_timer_sync(&ts->penup_timer); in tsc2005_esd_work()
510 tsc2005_update_pen_state(ts, 0, 0, 0); in tsc2005_esd_work()
512 ts->set_reset(false); in tsc2005_esd_work()
514 ts->set_reset(true); in tsc2005_esd_work()
516 enable_irq(ts->spi->irq); in tsc2005_esd_work()
517 tsc2005_start_scan(ts); in tsc2005_esd_work()
520 mutex_unlock(&ts->mutex); in tsc2005_esd_work()
523 schedule_delayed_work(&ts->esd_work, in tsc2005_esd_work()
525 msecs_to_jiffies(ts->esd_timeout))); in tsc2005_esd_work()
530 struct tsc2005 *ts = input_get_drvdata(input); in tsc2005_open() local
532 mutex_lock(&ts->mutex); in tsc2005_open()
534 if (!ts->suspended) in tsc2005_open()
535 __tsc2005_enable(ts); in tsc2005_open()
537 ts->opened = true; in tsc2005_open()
539 mutex_unlock(&ts->mutex); in tsc2005_open()
546 struct tsc2005 *ts = input_get_drvdata(input); in tsc2005_close() local
548 mutex_lock(&ts->mutex); in tsc2005_close()
550 if (!ts->suspended) in tsc2005_close()
551 __tsc2005_disable(ts); in tsc2005_close()
553 ts->opened = false; in tsc2005_close()
555 mutex_unlock(&ts->mutex); in tsc2005_close()
558 static void tsc2005_setup_spi_xfer(struct tsc2005 *ts) in tsc2005_setup_spi_xfer() argument
560 tsc2005_setup_read(&ts->spi_x, TSC2005_REG_X, false); in tsc2005_setup_spi_xfer()
561 tsc2005_setup_read(&ts->spi_y, TSC2005_REG_Y, false); in tsc2005_setup_spi_xfer()
562 tsc2005_setup_read(&ts->spi_z1, TSC2005_REG_Z1, false); in tsc2005_setup_spi_xfer()
563 tsc2005_setup_read(&ts->spi_z2, TSC2005_REG_Z2, true); in tsc2005_setup_spi_xfer()
565 spi_message_init(&ts->spi_read_msg); in tsc2005_setup_spi_xfer()
566 spi_message_add_tail(&ts->spi_x.spi_xfer, &ts->spi_read_msg); in tsc2005_setup_spi_xfer()
567 spi_message_add_tail(&ts->spi_y.spi_xfer, &ts->spi_read_msg); in tsc2005_setup_spi_xfer()
568 spi_message_add_tail(&ts->spi_z1.spi_xfer, &ts->spi_read_msg); in tsc2005_setup_spi_xfer()
569 spi_message_add_tail(&ts->spi_z2.spi_xfer, &ts->spi_read_msg); in tsc2005_setup_spi_xfer()
575 struct tsc2005 *ts; in tsc2005_probe() local
607 ts = kzalloc(sizeof(*ts), GFP_KERNEL); in tsc2005_probe()
609 if (!ts || !input_dev) { in tsc2005_probe()
614 ts->spi = spi; in tsc2005_probe()
615 ts->idev = input_dev; in tsc2005_probe()
617 ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280; in tsc2005_probe()
618 ts->esd_timeout = pdata->esd_timeout_ms; in tsc2005_probe()
619 ts->set_reset = pdata->set_reset; in tsc2005_probe()
621 mutex_init(&ts->mutex); in tsc2005_probe()
623 spin_lock_init(&ts->lock); in tsc2005_probe()
624 setup_timer(&ts->penup_timer, tsc2005_penup_timer, (unsigned long)ts); in tsc2005_probe()
626 INIT_DELAYED_WORK(&ts->esd_work, tsc2005_esd_work); in tsc2005_probe()
628 tsc2005_setup_spi_xfer(ts); in tsc2005_probe()
630 snprintf(ts->phys, sizeof(ts->phys), in tsc2005_probe()
634 input_dev->phys = ts->phys; in tsc2005_probe()
647 input_set_drvdata(input_dev, ts); in tsc2005_probe()
650 tsc2005_stop_scan(ts); in tsc2005_probe()
654 "tsc2005", ts); in tsc2005_probe()
660 spi_set_drvdata(spi, ts); in tsc2005_probe()
668 error = input_register_device(ts->idev); in tsc2005_probe()
682 free_irq(spi->irq, ts); in tsc2005_probe()
685 kfree(ts); in tsc2005_probe()
691 struct tsc2005 *ts = spi_get_drvdata(spi); in tsc2005_remove() local
693 sysfs_remove_group(&ts->spi->dev.kobj, &tsc2005_attr_group); in tsc2005_remove()
695 free_irq(ts->spi->irq, ts); in tsc2005_remove()
696 input_unregister_device(ts->idev); in tsc2005_remove()
697 kfree(ts); in tsc2005_remove()
707 struct tsc2005 *ts = spi_get_drvdata(spi); in tsc2005_suspend() local
709 mutex_lock(&ts->mutex); in tsc2005_suspend()
711 if (!ts->suspended && ts->opened) in tsc2005_suspend()
712 __tsc2005_disable(ts); in tsc2005_suspend()
714 ts->suspended = true; in tsc2005_suspend()
716 mutex_unlock(&ts->mutex); in tsc2005_suspend()
724 struct tsc2005 *ts = spi_get_drvdata(spi); in tsc2005_resume() local
726 mutex_lock(&ts->mutex); in tsc2005_resume()
728 if (ts->suspended && ts->opened) in tsc2005_resume()
729 __tsc2005_enable(ts); in tsc2005_resume()
731 ts->suspended = false; in tsc2005_resume()
733 mutex_unlock(&ts->mutex); in tsc2005_resume()