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()
421 mutex_lock(&ts->lock); in ads7846_read12_ser()
422 ads7846_stop(ts); in ads7846_read12_ser()
424 ads7846_restart(ts); in ads7846_read12_ser()
425 mutex_unlock(&ts->lock); in ads7846_read12_ser()
441 struct ads7846 *ts = dev_get_drvdata(dev); in ads7845_read12_ser() local
457 mutex_lock(&ts->lock); in ads7845_read12_ser()
458 ads7846_stop(ts); in ads7845_read12_ser()
460 ads7846_restart(ts); in ads7845_read12_ser()
461 mutex_unlock(&ts->lock); in ads7845_read12_ser()
479 struct ads7846 *ts = dev_get_drvdata(dev); \
480 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
484 return sprintf(buf, "%u\n", adjust(ts, v)); \
494 static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v) in null_adjust() argument
507 static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v) in SHOW()
512 retval *= ts->vref_mv; in SHOW()
518 static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) in vbatt_adjust() argument
520 unsigned retval = vaux_adjust(ts, v); in vbatt_adjust()
523 if (ts->model == 7846) in vbatt_adjust()
536 struct ads7846 *ts = dev_get_drvdata(dev); in SHOW() local
538 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
540 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
560 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) in ads784x_hwmon_register() argument
565 switch (ts->model) { in ads784x_hwmon_register()
567 if (!ts->vref_mv) { in ads784x_hwmon_register()
569 ts->vref_mv = 2500; in ads784x_hwmon_register()
570 ts->use_internal = true; in ads784x_hwmon_register()
575 if (!ts->vref_mv) { in ads784x_hwmon_register()
578 ts->model); in ads784x_hwmon_register()
585 spi->modalias, ts, in ads784x_hwmon_register()
593 struct ads7846 *ts) in ads784x_hwmon_register() argument
602 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_pen_down_show() local
604 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
612 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_show() local
614 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
621 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_store() local
630 ads7846_disable(ts); in ads7846_disable_store()
632 ads7846_enable(ts); in ads7846_disable_store()
650 struct ads7846 *ts = ads; in ads7846_debounce_filter() local
652 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
654 ts->read_rep = 0; in ads7846_debounce_filter()
659 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
660 ts->last_read = *val; in ads7846_debounce_filter()
661 ts->read_cnt++; in ads7846_debounce_filter()
670 ts->read_cnt = 0; in ads7846_debounce_filter()
674 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
679 ts->read_cnt = 0; in ads7846_debounce_filter()
680 ts->read_rep = 0; in ads7846_debounce_filter()
684 ts->read_cnt++; in ads7846_debounce_filter()
705 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx, in ads7846_set_cmd_val() argument
708 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
767 static int ads7846_filter(struct ads7846 *ts) in ads7846_filter() argument
769 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
783 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
788 ads7846_set_cmd_val(ts, cmd_idx, val); in ads7846_filter()
800 static void ads7846_wait_for_hsync(struct ads7846 *ts) in ads7846_wait_for_hsync() argument
802 if (ts->wait_for_sync) { in ads7846_wait_for_hsync()
803 ts->wait_for_sync(); in ads7846_wait_for_hsync()
807 if (!ts->gpio_hsync) in ads7846_wait_for_hsync()
814 while (!gpiod_get_value(ts->gpio_hsync)) in ads7846_wait_for_hsync()
818 while (gpiod_get_value(ts->gpio_hsync)) in ads7846_wait_for_hsync()
822 static void ads7846_read_state(struct ads7846 *ts) in ads7846_read_state() argument
824 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
832 ads7846_wait_for_hsync(ts); in ads7846_read_state()
834 m = &ts->msg[msg_idx]; in ads7846_read_state()
835 error = spi_sync(ts->spi, m); in ads7846_read_state()
837 dev_err_ratelimited(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
842 error = ads7846_filter(ts); in ads7846_read_state()
850 static void ads7846_report_state(struct ads7846 *ts) in ads7846_report_state() argument
852 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
858 if (ts->model == 7845) { in ads7846_report_state()
870 if (ts->model == 7843 || ts->model == 7845) { in ads7846_report_state()
871 Rt = ts->pressure_max / 2; in ads7846_report_state()
876 Rt *= ts->x_plate_ohms; in ads7846_report_state()
890 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
891 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
900 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
901 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
902 if (!get_pendown_state(ts)) in ads7846_report_state()
916 struct input_dev *input = ts->input; in ads7846_report_state()
918 if (!ts->pendown) { in ads7846_report_state()
920 ts->pendown = true; in ads7846_report_state()
921 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
924 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
925 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
928 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
934 struct ads7846 *ts = handle; in ads7846_hard_irq() local
936 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
942 struct ads7846 *ts = handle; in ads7846_irq() local
947 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
950 ads7846_read_state(ts); in ads7846_irq()
952 if (!ts->stopped) in ads7846_irq()
953 ads7846_report_state(ts); in ads7846_irq()
955 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
959 if (ts->pendown && !ts->stopped) in ads7846_irq()
960 ads7846_report_pen_up(ts); in ads7846_irq()
967 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
969 mutex_lock(&ts->lock); in ads7846_suspend()
971 if (!ts->suspended) { in ads7846_suspend()
973 if (!ts->disabled) in ads7846_suspend()
974 __ads7846_disable(ts); in ads7846_suspend()
976 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
977 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
979 ts->suspended = true; in ads7846_suspend()
982 mutex_unlock(&ts->lock); in ads7846_suspend()
989 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
991 mutex_lock(&ts->lock); in ads7846_resume()
993 if (ts->suspended) { in ads7846_resume()
995 ts->suspended = false; in ads7846_resume()
997 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
998 disable_irq_wake(ts->spi->irq); in ads7846_resume()
1000 if (!ts->disabled) in ads7846_resume()
1001 __ads7846_enable(ts); in ads7846_resume()
1004 mutex_unlock(&ts->lock); in ads7846_resume()
1012 struct ads7846 *ts, in ads7846_setup_pendown() argument
1022 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
1024 ts->gpio_pendown = devm_gpiod_get(&spi->dev, "pendown", GPIOD_IN); in ads7846_setup_pendown()
1025 if (IS_ERR(ts->gpio_pendown)) { in ads7846_setup_pendown()
1027 return PTR_ERR(ts->gpio_pendown); in ads7846_setup_pendown()
1030 gpiod_set_debounce(ts->gpio_pendown, in ads7846_setup_pendown()
1041 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1044 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1045 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1046 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1054 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1059 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1060 /* ads7846_debounce_filter() is making ts->debounce_rep + 2 in ads7846_setup_spi_msg()
1062 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1066 if (ts->model == 7846) in ads7846_setup_spi_msg()
1090 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1094 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1098 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1104 ts->model = 7846; in ads7846_setup_spi_msg()
1108 ts->msg_count = 1; in ads7846_setup_spi_msg()
1110 m->context = ts; in ads7846_setup_spi_msg()
1216 struct ads7846 *ts; in ads7846_probe() local
1247 ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1248 if (!ts) in ads7846_probe()
1259 spi_set_drvdata(spi, ts); in ads7846_probe()
1261 ts->packet = packet; in ads7846_probe()
1262 ts->spi = spi; in ads7846_probe()
1263 ts->input = input_dev; in ads7846_probe()
1265 mutex_init(&ts->lock); in ads7846_probe()
1266 init_waitqueue_head(&ts->wait); in ads7846_probe()
1275 ts->model = pdata->model ? : 7846; in ads7846_probe()
1276 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1277 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1278 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1281 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1282 if (ts->debounce_max < 2) in ads7846_probe()
1283 ts->debounce_max = 2; in ads7846_probe()
1284 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1285 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1286 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1287 ts->filter_data = ts; in ads7846_probe()
1289 ts->filter = ads7846_no_filter; in ads7846_probe()
1292 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1297 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1300 ts->wait_for_sync = pdata->wait_for_sync; in ads7846_probe()
1302 ts->gpio_hsync = devm_gpiod_get_optional(dev, "ti,hsync", GPIOD_IN); in ads7846_probe()
1303 if (IS_ERR(ts->gpio_hsync)) in ads7846_probe()
1304 return PTR_ERR(ts->gpio_hsync); in ads7846_probe()
1306 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1307 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1309 input_dev->name = ts->name; in ads7846_probe()
1310 input_dev->phys = ts->phys; in ads7846_probe()
1324 if (ts->model != 7845) in ads7846_probe()
1333 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1334 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1340 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1342 ts->core_prop.swap_x_y = true; in ads7846_probe()
1345 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1347 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1348 if (IS_ERR(ts->reg)) { in ads7846_probe()
1349 err = PTR_ERR(ts->reg); in ads7846_probe()
1354 err = regulator_enable(ts->reg); in ads7846_probe()
1360 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1369 irq_flags, dev->driver->name, ts); in ads7846_probe()
1377 ts); in ads7846_probe()
1385 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1395 if (ts->model == 7845) in ads7846_probe()
1418 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1420 ads7846_stop(ts); in ads7846_remove()