Lines Matching refs:ts

220 static int get_pendown_state(struct ads7846 *ts)  in get_pendown_state()  argument
222 if (ts->get_pendown_state) in get_pendown_state()
223 return ts->get_pendown_state(); in get_pendown_state()
225 return !gpio_get_value(ts->gpio_pendown); in get_pendown_state()
228 static void ads7846_report_pen_up(struct ads7846 *ts) in ads7846_report_pen_up() argument
230 struct input_dev *input = ts->input; in ads7846_report_pen_up()
236 ts->pendown = false; in ads7846_report_pen_up()
237 dev_vdbg(&ts->spi->dev, "UP\n"); in ads7846_report_pen_up()
241 static void ads7846_stop(struct ads7846 *ts) in ads7846_stop() argument
243 if (!ts->disabled && !ts->suspended) { in ads7846_stop()
245 ts->stopped = true; in ads7846_stop()
247 wake_up(&ts->wait); in ads7846_stop()
248 disable_irq(ts->spi->irq); in ads7846_stop()
253 static void ads7846_restart(struct ads7846 *ts) in ads7846_restart() argument
255 if (!ts->disabled && !ts->suspended) { in ads7846_restart()
257 if (ts->pendown && !get_pendown_state(ts)) in ads7846_restart()
258 ads7846_report_pen_up(ts); in ads7846_restart()
261 ts->stopped = false; in ads7846_restart()
263 enable_irq(ts->spi->irq); in ads7846_restart()
268 static void __ads7846_disable(struct ads7846 *ts) in __ads7846_disable() argument
270 ads7846_stop(ts); in __ads7846_disable()
271 regulator_disable(ts->reg); in __ads7846_disable()
280 static void __ads7846_enable(struct ads7846 *ts) in __ads7846_enable() argument
284 error = regulator_enable(ts->reg); in __ads7846_enable()
286 dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error); in __ads7846_enable()
288 ads7846_restart(ts); in __ads7846_enable()
291 static void ads7846_disable(struct ads7846 *ts) in ads7846_disable() argument
293 mutex_lock(&ts->lock); in ads7846_disable()
295 if (!ts->disabled) { in ads7846_disable()
297 if (!ts->suspended) in ads7846_disable()
298 __ads7846_disable(ts); in ads7846_disable()
300 ts->disabled = true; in ads7846_disable()
303 mutex_unlock(&ts->lock); in ads7846_disable()
306 static void ads7846_enable(struct ads7846 *ts) in ads7846_enable() argument
308 mutex_lock(&ts->lock); in ads7846_enable()
310 if (ts->disabled) { in ads7846_enable()
312 ts->disabled = false; in ads7846_enable()
314 if (!ts->suspended) in ads7846_enable()
315 __ads7846_enable(ts); in ads7846_enable()
318 mutex_unlock(&ts->lock); in ads7846_enable()
357 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_read12_ser() local
368 if (ts->use_internal) { in ads7846_read12_ser()
378 req->xfer[1].delay.value = ts->vref_delay_usecs; in ads7846_read12_ser()
412 mutex_lock(&ts->lock); in ads7846_read12_ser()
413 ads7846_stop(ts); in ads7846_read12_ser()
415 ads7846_restart(ts); in ads7846_read12_ser()
416 mutex_unlock(&ts->lock); in ads7846_read12_ser()
432 struct ads7846 *ts = dev_get_drvdata(dev); in ads7845_read12_ser() local
448 mutex_lock(&ts->lock); in ads7845_read12_ser()
449 ads7846_stop(ts); in ads7845_read12_ser()
451 ads7846_restart(ts); in ads7845_read12_ser()
452 mutex_unlock(&ts->lock); in ads7845_read12_ser()
470 struct ads7846 *ts = dev_get_drvdata(dev); \
471 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
475 return sprintf(buf, "%u\n", adjust(ts, v)); \
485 static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v) in null_adjust() argument
498 static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v) in SHOW()
503 retval *= ts->vref_mv; in SHOW()
509 static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) in vbatt_adjust() argument
511 unsigned retval = vaux_adjust(ts, v); in vbatt_adjust()
514 if (ts->model == 7846) in vbatt_adjust()
527 struct ads7846 *ts = dev_get_drvdata(dev); in SHOW() local
529 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
531 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
551 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) in ads784x_hwmon_register() argument
556 switch (ts->model) { in ads784x_hwmon_register()
558 if (!ts->vref_mv) { in ads784x_hwmon_register()
560 ts->vref_mv = 2500; in ads784x_hwmon_register()
561 ts->use_internal = true; in ads784x_hwmon_register()
566 if (!ts->vref_mv) { in ads784x_hwmon_register()
569 ts->model); in ads784x_hwmon_register()
576 spi->modalias, ts, in ads784x_hwmon_register()
584 struct ads7846 *ts) in ads784x_hwmon_register() argument
593 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_pen_down_show() local
595 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
603 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_show() local
605 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
612 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_store() local
621 ads7846_disable(ts); in ads7846_disable_store()
623 ads7846_enable(ts); in ads7846_disable_store()
648 struct ads7846 *ts = ads; in ads7846_debounce_filter() local
650 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
652 ts->read_rep = 0; in ads7846_debounce_filter()
657 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
658 ts->last_read = *val; in ads7846_debounce_filter()
659 ts->read_cnt++; in ads7846_debounce_filter()
668 ts->read_cnt = 0; in ads7846_debounce_filter()
672 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
677 ts->read_cnt = 0; in ads7846_debounce_filter()
678 ts->read_rep = 0; in ads7846_debounce_filter()
682 ts->read_cnt++; in ads7846_debounce_filter()
703 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx, in ads7846_set_cmd_val() argument
706 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
765 static int ads7846_filter(struct ads7846 *ts) in ads7846_filter() argument
767 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
781 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
786 ads7846_set_cmd_val(ts, cmd_idx, val); in ads7846_filter()
798 static void ads7846_read_state(struct ads7846 *ts) in ads7846_read_state() argument
800 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
808 ts->wait_for_sync(); in ads7846_read_state()
810 m = &ts->msg[msg_idx]; in ads7846_read_state()
811 error = spi_sync(ts->spi, m); in ads7846_read_state()
813 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
818 error = ads7846_filter(ts); in ads7846_read_state()
826 static void ads7846_report_state(struct ads7846 *ts) in ads7846_report_state() argument
828 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
834 if (ts->model == 7845) { in ads7846_report_state()
846 if (ts->model == 7843 || ts->model == 7845) { in ads7846_report_state()
847 Rt = ts->pressure_max / 2; in ads7846_report_state()
852 Rt *= ts->x_plate_ohms; in ads7846_report_state()
866 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
867 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
876 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
877 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
878 if (!get_pendown_state(ts)) in ads7846_report_state()
892 struct input_dev *input = ts->input; in ads7846_report_state()
894 if (!ts->pendown) { in ads7846_report_state()
896 ts->pendown = true; in ads7846_report_state()
897 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
900 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
901 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
904 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
910 struct ads7846 *ts = handle; in ads7846_hard_irq() local
912 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
918 struct ads7846 *ts = handle; in ads7846_irq() local
923 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
926 ads7846_read_state(ts); in ads7846_irq()
928 if (!ts->stopped) in ads7846_irq()
929 ads7846_report_state(ts); in ads7846_irq()
931 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
935 if (ts->pendown && !ts->stopped) in ads7846_irq()
936 ads7846_report_pen_up(ts); in ads7846_irq()
943 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
945 mutex_lock(&ts->lock); in ads7846_suspend()
947 if (!ts->suspended) { in ads7846_suspend()
949 if (!ts->disabled) in ads7846_suspend()
950 __ads7846_disable(ts); in ads7846_suspend()
952 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
953 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
955 ts->suspended = true; in ads7846_suspend()
958 mutex_unlock(&ts->lock); in ads7846_suspend()
965 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
967 mutex_lock(&ts->lock); in ads7846_resume()
969 if (ts->suspended) { in ads7846_resume()
971 ts->suspended = false; in ads7846_resume()
973 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
974 disable_irq_wake(ts->spi->irq); in ads7846_resume()
976 if (!ts->disabled) in ads7846_resume()
977 __ads7846_enable(ts); in ads7846_resume()
980 mutex_unlock(&ts->lock); in ads7846_resume()
988 struct ads7846 *ts, in ads7846_setup_pendown() argument
1000 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
1012 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
1029 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1032 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1033 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1034 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1042 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1047 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1050 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1054 if (ts->model == 7846) in ads7846_setup_spi_msg()
1078 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1082 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1086 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1092 ts->model = 7846; in ads7846_setup_spi_msg()
1096 ts->msg_count = 1; in ads7846_setup_spi_msg()
1098 m->context = ts; in ads7846_setup_spi_msg()
1217 struct ads7846 *ts; in ads7846_probe() local
1248 ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1249 if (!ts) in ads7846_probe()
1260 spi_set_drvdata(spi, ts); in ads7846_probe()
1262 ts->packet = packet; in ads7846_probe()
1263 ts->spi = spi; in ads7846_probe()
1264 ts->input = input_dev; in ads7846_probe()
1266 mutex_init(&ts->lock); in ads7846_probe()
1267 init_waitqueue_head(&ts->wait); in ads7846_probe()
1276 ts->model = pdata->model ? : 7846; in ads7846_probe()
1277 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1278 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1279 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1282 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1283 if (ts->debounce_max < 2) in ads7846_probe()
1284 ts->debounce_max = 2; in ads7846_probe()
1285 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1286 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1287 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1288 ts->filter_data = ts; in ads7846_probe()
1290 ts->filter = ads7846_no_filter; in ads7846_probe()
1293 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1298 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1301 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1303 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1304 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1306 input_dev->name = ts->name; in ads7846_probe()
1307 input_dev->phys = ts->phys; in ads7846_probe()
1321 if (ts->model != 7845) in ads7846_probe()
1330 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1331 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1337 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1339 ts->core_prop.swap_x_y = true; in ads7846_probe()
1342 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1344 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1345 if (IS_ERR(ts->reg)) { in ads7846_probe()
1346 err = PTR_ERR(ts->reg); in ads7846_probe()
1351 err = regulator_enable(ts->reg); in ads7846_probe()
1357 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1366 irq_flags, dev->driver->name, ts); in ads7846_probe()
1374 ts); in ads7846_probe()
1382 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1392 if (ts->model == 7845) in ads7846_probe()
1419 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1421 ads7846_stop(ts); in ads7846_remove()