Lines Matching full:ts

218 static int get_pendown_state(struct ads7846 *ts)  in get_pendown_state()  argument
220 if (ts->get_pendown_state) in get_pendown_state()
221 return ts->get_pendown_state(); in get_pendown_state()
223 return gpiod_get_value(ts->gpio_pendown); in get_pendown_state()
226 static void ads7846_report_pen_up(struct ads7846 *ts) in ads7846_report_pen_up() argument
228 struct input_dev *input = ts->input; in ads7846_report_pen_up()
234 ts->pendown = false; in ads7846_report_pen_up()
235 dev_vdbg(&ts->spi->dev, "UP\n"); in ads7846_report_pen_up()
238 /* Must be called with ts->lock held */
239 static void ads7846_stop(struct ads7846 *ts) in ads7846_stop() argument
241 if (!ts->disabled && !ts->suspended) { in ads7846_stop()
243 ts->stopped = true; in ads7846_stop()
245 wake_up(&ts->wait); in ads7846_stop()
246 disable_irq(ts->spi->irq); in ads7846_stop()
250 /* Must be called with ts->lock held */
251 static void ads7846_restart(struct ads7846 *ts) in ads7846_restart() argument
253 if (!ts->disabled && !ts->suspended) { in ads7846_restart()
255 if (ts->pendown && !get_pendown_state(ts)) in ads7846_restart()
256 ads7846_report_pen_up(ts); in ads7846_restart()
259 ts->stopped = false; in ads7846_restart()
261 enable_irq(ts->spi->irq); in ads7846_restart()
265 /* Must be called with ts->lock held */
266 static void __ads7846_disable(struct ads7846 *ts) in __ads7846_disable() argument
268 ads7846_stop(ts); in __ads7846_disable()
269 regulator_disable(ts->reg); in __ads7846_disable()
277 /* Must be called with ts->lock held */
278 static void __ads7846_enable(struct ads7846 *ts) in __ads7846_enable() argument
282 error = regulator_enable(ts->reg); in __ads7846_enable()
284 dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error); in __ads7846_enable()
286 ads7846_restart(ts); in __ads7846_enable()
289 static void ads7846_disable(struct ads7846 *ts) in ads7846_disable() argument
291 mutex_lock(&ts->lock); in ads7846_disable()
293 if (!ts->disabled) { in ads7846_disable()
295 if (!ts->suspended) in ads7846_disable()
296 __ads7846_disable(ts); in ads7846_disable()
298 ts->disabled = true; in ads7846_disable()
301 mutex_unlock(&ts->lock); in ads7846_disable()
304 static void ads7846_enable(struct ads7846 *ts) in ads7846_enable() argument
306 mutex_lock(&ts->lock); in ads7846_enable()
308 if (ts->disabled) { in ads7846_enable()
310 ts->disabled = false; in ads7846_enable()
312 if (!ts->suspended) in ads7846_enable()
313 __ads7846_enable(ts); in ads7846_enable()
316 mutex_unlock(&ts->lock); in ads7846_enable()
355 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_read12_ser() local
366 if (ts->use_internal) { in ads7846_read12_ser()
376 req->xfer[1].delay.value = ts->vref_delay_usecs; in ads7846_read12_ser()
410 mutex_lock(&ts->lock); in ads7846_read12_ser()
411 ads7846_stop(ts); in ads7846_read12_ser()
413 ads7846_restart(ts); in ads7846_read12_ser()
414 mutex_unlock(&ts->lock); in ads7846_read12_ser()
430 struct ads7846 *ts = dev_get_drvdata(dev); in ads7845_read12_ser() local
446 mutex_lock(&ts->lock); in ads7845_read12_ser()
447 ads7846_stop(ts); in ads7845_read12_ser()
449 ads7846_restart(ts); in ads7845_read12_ser()
450 mutex_unlock(&ts->lock); in ads7845_read12_ser()
468 struct ads7846 *ts = dev_get_drvdata(dev); \
469 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
473 return sprintf(buf, "%u\n", adjust(ts, v)); \
483 static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v) in null_adjust() argument
496 static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v) in SHOW()
501 retval *= ts->vref_mv; in SHOW()
507 static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) in vbatt_adjust() argument
509 unsigned retval = vaux_adjust(ts, v); in vbatt_adjust()
512 if (ts->model == 7846) in vbatt_adjust()
525 struct ads7846 *ts = dev_get_drvdata(dev); in SHOW() local
527 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
529 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
549 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) in ads784x_hwmon_register() argument
554 switch (ts->model) { in ads784x_hwmon_register()
556 if (!ts->vref_mv) { in ads784x_hwmon_register()
558 ts->vref_mv = 2500; in ads784x_hwmon_register()
559 ts->use_internal = true; in ads784x_hwmon_register()
564 if (!ts->vref_mv) { in ads784x_hwmon_register()
567 ts->model); in ads784x_hwmon_register()
574 spi->modalias, ts, in ads784x_hwmon_register()
582 struct ads7846 *ts) in ads784x_hwmon_register() argument
591 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_pen_down_show() local
593 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
601 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_show() local
603 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
610 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_store() local
619 ads7846_disable(ts); in ads7846_disable_store()
621 ads7846_enable(ts); in ads7846_disable_store()
643 struct ads7846 *ts = ads; in ads7846_debounce_filter() local
645 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
647 ts->read_rep = 0; in ads7846_debounce_filter()
652 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
653 ts->last_read = *val; in ads7846_debounce_filter()
654 ts->read_cnt++; in ads7846_debounce_filter()
663 ts->read_cnt = 0; in ads7846_debounce_filter()
667 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
672 ts->read_cnt = 0; in ads7846_debounce_filter()
673 ts->read_rep = 0; in ads7846_debounce_filter()
677 ts->read_cnt++; in ads7846_debounce_filter()
698 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx, in ads7846_set_cmd_val() argument
701 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
760 static int ads7846_filter(struct ads7846 *ts) in ads7846_filter() argument
762 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
776 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
781 ads7846_set_cmd_val(ts, cmd_idx, val); in ads7846_filter()
793 static void ads7846_read_state(struct ads7846 *ts) in ads7846_read_state() argument
795 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
803 ts->wait_for_sync(); in ads7846_read_state()
805 m = &ts->msg[msg_idx]; in ads7846_read_state()
806 error = spi_sync(ts->spi, m); in ads7846_read_state()
808 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
813 error = ads7846_filter(ts); in ads7846_read_state()
821 static void ads7846_report_state(struct ads7846 *ts) in ads7846_report_state() argument
823 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
829 if (ts->model == 7845) { in ads7846_report_state()
841 if (ts->model == 7843 || ts->model == 7845) { in ads7846_report_state()
842 Rt = ts->pressure_max / 2; in ads7846_report_state()
847 Rt *= ts->x_plate_ohms; in ads7846_report_state()
861 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
862 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
871 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
872 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
873 if (!get_pendown_state(ts)) in ads7846_report_state()
887 struct input_dev *input = ts->input; in ads7846_report_state()
889 if (!ts->pendown) { in ads7846_report_state()
891 ts->pendown = true; in ads7846_report_state()
892 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
895 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
896 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
899 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
905 struct ads7846 *ts = handle; in ads7846_hard_irq() local
907 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
913 struct ads7846 *ts = handle; in ads7846_irq() local
918 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
921 ads7846_read_state(ts); in ads7846_irq()
923 if (!ts->stopped) in ads7846_irq()
924 ads7846_report_state(ts); in ads7846_irq()
926 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
930 if (ts->pendown && !ts->stopped) in ads7846_irq()
931 ads7846_report_pen_up(ts); in ads7846_irq()
938 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
940 mutex_lock(&ts->lock); in ads7846_suspend()
942 if (!ts->suspended) { in ads7846_suspend()
944 if (!ts->disabled) in ads7846_suspend()
945 __ads7846_disable(ts); in ads7846_suspend()
947 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
948 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
950 ts->suspended = true; in ads7846_suspend()
953 mutex_unlock(&ts->lock); in ads7846_suspend()
960 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
962 mutex_lock(&ts->lock); in ads7846_resume()
964 if (ts->suspended) { in ads7846_resume()
966 ts->suspended = false; in ads7846_resume()
968 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
969 disable_irq_wake(ts->spi->irq); in ads7846_resume()
971 if (!ts->disabled) in ads7846_resume()
972 __ads7846_enable(ts); in ads7846_resume()
975 mutex_unlock(&ts->lock); in ads7846_resume()
983 struct ads7846 *ts, in ads7846_setup_pendown() argument
993 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
995 ts->gpio_pendown = gpiod_get(&spi->dev, "pendown", GPIOD_IN); in ads7846_setup_pendown()
996 if (IS_ERR(ts->gpio_pendown)) { in ads7846_setup_pendown()
998 return PTR_ERR(ts->gpio_pendown); in ads7846_setup_pendown()
1001 gpiod_set_debounce(ts->gpio_pendown, in ads7846_setup_pendown()
1012 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1015 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1016 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1017 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1025 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1030 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1031 /* ads7846_debounce_filter() is making ts->debounce_rep + 2 in ads7846_setup_spi_msg()
1033 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1037 if (ts->model == 7846) in ads7846_setup_spi_msg()
1061 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1065 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1069 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1075 ts->model = 7846; in ads7846_setup_spi_msg()
1079 ts->msg_count = 1; in ads7846_setup_spi_msg()
1081 m->context = ts; in ads7846_setup_spi_msg()
1177 struct ads7846 *ts; in ads7846_probe() local
1208 ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1209 if (!ts) in ads7846_probe()
1220 spi_set_drvdata(spi, ts); in ads7846_probe()
1222 ts->packet = packet; in ads7846_probe()
1223 ts->spi = spi; in ads7846_probe()
1224 ts->input = input_dev; in ads7846_probe()
1226 mutex_init(&ts->lock); in ads7846_probe()
1227 init_waitqueue_head(&ts->wait); in ads7846_probe()
1236 ts->model = pdata->model ? : 7846; in ads7846_probe()
1237 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1238 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1239 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1242 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1243 if (ts->debounce_max < 2) in ads7846_probe()
1244 ts->debounce_max = 2; in ads7846_probe()
1245 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1246 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1247 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1248 ts->filter_data = ts; in ads7846_probe()
1250 ts->filter = ads7846_no_filter; in ads7846_probe()
1253 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1258 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1261 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1263 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1264 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1266 input_dev->name = ts->name; in ads7846_probe()
1267 input_dev->phys = ts->phys; in ads7846_probe()
1281 if (ts->model != 7845) in ads7846_probe()
1290 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1291 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1297 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1299 ts->core_prop.swap_x_y = true; in ads7846_probe()
1302 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1304 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1305 if (IS_ERR(ts->reg)) { in ads7846_probe()
1306 err = PTR_ERR(ts->reg); in ads7846_probe()
1311 err = regulator_enable(ts->reg); in ads7846_probe()
1317 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1326 irq_flags, dev->driver->name, ts); in ads7846_probe()
1334 ts); in ads7846_probe()
1342 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1352 if (ts->model == 7845) in ads7846_probe()
1375 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1377 ads7846_stop(ts); in ads7846_remove()