Lines Matching full:ts

219 static int get_pendown_state(struct ads7846 *ts)  in get_pendown_state()  argument
221 if (ts->get_pendown_state) in get_pendown_state()
222 return ts->get_pendown_state(); in get_pendown_state()
224 return gpiod_get_value(ts->gpio_pendown); in get_pendown_state()
227 static void ads7846_report_pen_up(struct ads7846 *ts) in ads7846_report_pen_up() argument
229 struct input_dev *input = ts->input; in ads7846_report_pen_up()
235 ts->pendown = false; in ads7846_report_pen_up()
236 dev_vdbg(&ts->spi->dev, "UP\n"); in ads7846_report_pen_up()
239 /* Must be called with ts->lock held */
240 static void ads7846_stop(struct ads7846 *ts) in ads7846_stop() argument
242 if (!ts->disabled && !ts->suspended) { in ads7846_stop()
244 ts->stopped = true; in ads7846_stop()
246 wake_up(&ts->wait); in ads7846_stop()
247 disable_irq(ts->spi->irq); in ads7846_stop()
251 /* Must be called with ts->lock held */
252 static void ads7846_restart(struct ads7846 *ts) in ads7846_restart() argument
254 if (!ts->disabled && !ts->suspended) { in ads7846_restart()
256 if (ts->pendown && !get_pendown_state(ts)) in ads7846_restart()
257 ads7846_report_pen_up(ts); in ads7846_restart()
260 ts->stopped = false; in ads7846_restart()
262 enable_irq(ts->spi->irq); in ads7846_restart()
266 /* Must be called with ts->lock held */
267 static void __ads7846_disable(struct ads7846 *ts) in __ads7846_disable() argument
269 ads7846_stop(ts); in __ads7846_disable()
270 regulator_disable(ts->reg); in __ads7846_disable()
278 /* Must be called with ts->lock held */
279 static void __ads7846_enable(struct ads7846 *ts) in __ads7846_enable() argument
283 error = regulator_enable(ts->reg); in __ads7846_enable()
285 dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error); in __ads7846_enable()
287 ads7846_restart(ts); in __ads7846_enable()
290 static void ads7846_disable(struct ads7846 *ts) in ads7846_disable() argument
292 mutex_lock(&ts->lock); in ads7846_disable()
294 if (!ts->disabled) { in ads7846_disable()
296 if (!ts->suspended) in ads7846_disable()
297 __ads7846_disable(ts); in ads7846_disable()
299 ts->disabled = true; in ads7846_disable()
302 mutex_unlock(&ts->lock); in ads7846_disable()
305 static void ads7846_enable(struct ads7846 *ts) in ads7846_enable() argument
307 mutex_lock(&ts->lock); in ads7846_enable()
309 if (ts->disabled) { in ads7846_enable()
311 ts->disabled = false; in ads7846_enable()
313 if (!ts->suspended) in ads7846_enable()
314 __ads7846_enable(ts); in ads7846_enable()
317 mutex_unlock(&ts->lock); in ads7846_enable()
356 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_read12_ser() local
367 if (ts->use_internal) { in ads7846_read12_ser()
377 req->xfer[1].delay.value = ts->vref_delay_usecs; in ads7846_read12_ser()
411 mutex_lock(&ts->lock); in ads7846_read12_ser()
412 ads7846_stop(ts); in ads7846_read12_ser()
414 ads7846_restart(ts); in ads7846_read12_ser()
415 mutex_unlock(&ts->lock); in ads7846_read12_ser()
431 struct ads7846 *ts = dev_get_drvdata(dev); in ads7845_read12_ser() local
447 mutex_lock(&ts->lock); in ads7845_read12_ser()
448 ads7846_stop(ts); in ads7845_read12_ser()
450 ads7846_restart(ts); in ads7845_read12_ser()
451 mutex_unlock(&ts->lock); in ads7845_read12_ser()
469 struct ads7846 *ts = dev_get_drvdata(dev); \
470 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
474 return sprintf(buf, "%u\n", adjust(ts, v)); \
484 static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v) in null_adjust() argument
497 static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v) in SHOW()
502 retval *= ts->vref_mv; in SHOW()
508 static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) in vbatt_adjust() argument
510 unsigned retval = vaux_adjust(ts, v); in vbatt_adjust()
513 if (ts->model == 7846) in vbatt_adjust()
526 struct ads7846 *ts = dev_get_drvdata(dev); in SHOW() local
528 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
530 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
550 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) in ads784x_hwmon_register() argument
555 switch (ts->model) { in ads784x_hwmon_register()
557 if (!ts->vref_mv) { in ads784x_hwmon_register()
559 ts->vref_mv = 2500; in ads784x_hwmon_register()
560 ts->use_internal = true; in ads784x_hwmon_register()
565 if (!ts->vref_mv) { in ads784x_hwmon_register()
568 ts->model); in ads784x_hwmon_register()
575 spi->modalias, ts, in ads784x_hwmon_register()
583 struct ads7846 *ts) in ads784x_hwmon_register() argument
592 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_pen_down_show() local
594 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
602 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_show() local
604 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
611 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_store() local
620 ads7846_disable(ts); in ads7846_disable_store()
622 ads7846_enable(ts); in ads7846_disable_store()
640 struct ads7846 *ts = ads; in ads7846_debounce_filter() local
642 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
644 ts->read_rep = 0; in ads7846_debounce_filter()
649 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
650 ts->last_read = *val; in ads7846_debounce_filter()
651 ts->read_cnt++; in ads7846_debounce_filter()
660 ts->read_cnt = 0; in ads7846_debounce_filter()
664 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
669 ts->read_cnt = 0; in ads7846_debounce_filter()
670 ts->read_rep = 0; in ads7846_debounce_filter()
674 ts->read_cnt++; in ads7846_debounce_filter()
695 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx, in ads7846_set_cmd_val() argument
698 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
757 static int ads7846_filter(struct ads7846 *ts) in ads7846_filter() argument
759 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
773 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
778 ads7846_set_cmd_val(ts, cmd_idx, val); in ads7846_filter()
790 static void ads7846_wait_for_hsync(struct ads7846 *ts) in ads7846_wait_for_hsync() argument
792 if (ts->wait_for_sync) { in ads7846_wait_for_hsync()
793 ts->wait_for_sync(); in ads7846_wait_for_hsync()
797 if (!ts->gpio_hsync) in ads7846_wait_for_hsync()
804 while (!gpiod_get_value(ts->gpio_hsync)) in ads7846_wait_for_hsync()
808 while (gpiod_get_value(ts->gpio_hsync)) in ads7846_wait_for_hsync()
812 static void ads7846_read_state(struct ads7846 *ts) in ads7846_read_state() argument
814 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
822 ads7846_wait_for_hsync(ts); in ads7846_read_state()
824 m = &ts->msg[msg_idx]; in ads7846_read_state()
825 error = spi_sync(ts->spi, m); in ads7846_read_state()
827 dev_err_ratelimited(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
832 error = ads7846_filter(ts); in ads7846_read_state()
840 static void ads7846_report_state(struct ads7846 *ts) in ads7846_report_state() argument
842 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
848 if (ts->model == 7845) { in ads7846_report_state()
860 if (ts->model == 7843 || ts->model == 7845) { in ads7846_report_state()
861 Rt = ts->pressure_max / 2; in ads7846_report_state()
866 Rt *= ts->x_plate_ohms; in ads7846_report_state()
880 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
881 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
890 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
891 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
892 if (!get_pendown_state(ts)) in ads7846_report_state()
906 struct input_dev *input = ts->input; in ads7846_report_state()
908 if (!ts->pendown) { in ads7846_report_state()
910 ts->pendown = true; in ads7846_report_state()
911 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
914 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
915 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
918 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
924 struct ads7846 *ts = handle; in ads7846_hard_irq() local
926 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
932 struct ads7846 *ts = handle; in ads7846_irq() local
937 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
940 ads7846_read_state(ts); in ads7846_irq()
942 if (!ts->stopped) in ads7846_irq()
943 ads7846_report_state(ts); in ads7846_irq()
945 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
949 if (ts->pendown && !ts->stopped) in ads7846_irq()
950 ads7846_report_pen_up(ts); in ads7846_irq()
957 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
959 mutex_lock(&ts->lock); in ads7846_suspend()
961 if (!ts->suspended) { in ads7846_suspend()
963 if (!ts->disabled) in ads7846_suspend()
964 __ads7846_disable(ts); in ads7846_suspend()
966 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
967 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
969 ts->suspended = true; in ads7846_suspend()
972 mutex_unlock(&ts->lock); in ads7846_suspend()
979 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
981 mutex_lock(&ts->lock); in ads7846_resume()
983 if (ts->suspended) { in ads7846_resume()
985 ts->suspended = false; in ads7846_resume()
987 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
988 disable_irq_wake(ts->spi->irq); in ads7846_resume()
990 if (!ts->disabled) in ads7846_resume()
991 __ads7846_enable(ts); in ads7846_resume()
994 mutex_unlock(&ts->lock); in ads7846_resume()
1002 struct ads7846 *ts, in ads7846_setup_pendown() argument
1012 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
1014 ts->gpio_pendown = gpiod_get(&spi->dev, "pendown", GPIOD_IN); in ads7846_setup_pendown()
1015 if (IS_ERR(ts->gpio_pendown)) { in ads7846_setup_pendown()
1017 return PTR_ERR(ts->gpio_pendown); in ads7846_setup_pendown()
1020 gpiod_set_debounce(ts->gpio_pendown, in ads7846_setup_pendown()
1031 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1034 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1035 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1036 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1044 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1049 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1050 /* ads7846_debounce_filter() is making ts->debounce_rep + 2 in ads7846_setup_spi_msg()
1052 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1056 if (ts->model == 7846) in ads7846_setup_spi_msg()
1080 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1084 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1088 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1094 ts->model = 7846; in ads7846_setup_spi_msg()
1098 ts->msg_count = 1; in ads7846_setup_spi_msg()
1100 m->context = ts; in ads7846_setup_spi_msg()
1206 struct ads7846 *ts; in ads7846_probe() local
1237 ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1238 if (!ts) in ads7846_probe()
1249 spi_set_drvdata(spi, ts); in ads7846_probe()
1251 ts->packet = packet; in ads7846_probe()
1252 ts->spi = spi; in ads7846_probe()
1253 ts->input = input_dev; in ads7846_probe()
1255 mutex_init(&ts->lock); in ads7846_probe()
1256 init_waitqueue_head(&ts->wait); in ads7846_probe()
1265 ts->model = pdata->model ? : 7846; in ads7846_probe()
1266 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1267 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1268 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1271 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1272 if (ts->debounce_max < 2) in ads7846_probe()
1273 ts->debounce_max = 2; in ads7846_probe()
1274 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1275 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1276 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1277 ts->filter_data = ts; in ads7846_probe()
1279 ts->filter = ads7846_no_filter; in ads7846_probe()
1282 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1287 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1290 ts->wait_for_sync = pdata->wait_for_sync; in ads7846_probe()
1292 ts->gpio_hsync = devm_gpiod_get_optional(dev, "ti,hsync", GPIOD_IN); in ads7846_probe()
1293 if (IS_ERR(ts->gpio_hsync)) in ads7846_probe()
1294 return PTR_ERR(ts->gpio_hsync); in ads7846_probe()
1296 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1297 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1299 input_dev->name = ts->name; in ads7846_probe()
1300 input_dev->phys = ts->phys; in ads7846_probe()
1314 if (ts->model != 7845) in ads7846_probe()
1323 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1324 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1330 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1332 ts->core_prop.swap_x_y = true; in ads7846_probe()
1335 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1337 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1338 if (IS_ERR(ts->reg)) { in ads7846_probe()
1339 err = PTR_ERR(ts->reg); in ads7846_probe()
1344 err = regulator_enable(ts->reg); in ads7846_probe()
1350 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1359 irq_flags, dev->driver->name, ts); in ads7846_probe()
1367 ts); in ads7846_probe()
1375 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1385 if (ts->model == 7845) in ads7846_probe()
1408 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1410 ads7846_stop(ts); in ads7846_remove()