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) { in ads7846_report_state()
847 Rt = ts->pressure_max / 2; in ads7846_report_state()
848 } else if (ts->model == 7845) { in ads7846_report_state()
849 if (get_pendown_state(ts)) in ads7846_report_state()
850 Rt = ts->pressure_max / 2; in ads7846_report_state()
853 dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt); in ads7846_report_state()
858 Rt *= ts->x_plate_ohms; in ads7846_report_state()
872 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
873 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
882 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
883 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
884 if (!get_pendown_state(ts)) in ads7846_report_state()
898 struct input_dev *input = ts->input; in ads7846_report_state()
900 if (!ts->pendown) { in ads7846_report_state()
902 ts->pendown = true; in ads7846_report_state()
903 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
906 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
907 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
910 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
916 struct ads7846 *ts = handle; in ads7846_hard_irq() local
918 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
924 struct ads7846 *ts = handle; in ads7846_irq() local
929 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
932 ads7846_read_state(ts); in ads7846_irq()
934 if (!ts->stopped) in ads7846_irq()
935 ads7846_report_state(ts); in ads7846_irq()
937 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
941 if (ts->pendown && !ts->stopped) in ads7846_irq()
942 ads7846_report_pen_up(ts); in ads7846_irq()
949 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
951 mutex_lock(&ts->lock); in ads7846_suspend()
953 if (!ts->suspended) { in ads7846_suspend()
955 if (!ts->disabled) in ads7846_suspend()
956 __ads7846_disable(ts); in ads7846_suspend()
958 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
959 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
961 ts->suspended = true; in ads7846_suspend()
964 mutex_unlock(&ts->lock); in ads7846_suspend()
971 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
973 mutex_lock(&ts->lock); in ads7846_resume()
975 if (ts->suspended) { in ads7846_resume()
977 ts->suspended = false; in ads7846_resume()
979 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
980 disable_irq_wake(ts->spi->irq); in ads7846_resume()
982 if (!ts->disabled) in ads7846_resume()
983 __ads7846_enable(ts); in ads7846_resume()
986 mutex_unlock(&ts->lock); in ads7846_resume()
994 struct ads7846 *ts, in ads7846_setup_pendown() argument
1006 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
1018 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
1035 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1038 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1039 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1040 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1048 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1053 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1056 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1060 if (ts->model == 7846) in ads7846_setup_spi_msg()
1081 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1085 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1089 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1095 ts->model = 7846; in ads7846_setup_spi_msg()
1099 ts->msg_count = 1; in ads7846_setup_spi_msg()
1101 m->context = ts; in ads7846_setup_spi_msg()
1215 struct ads7846 *ts; in ads7846_probe() local
1246 ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1247 if (!ts) in ads7846_probe()
1258 spi_set_drvdata(spi, ts); in ads7846_probe()
1260 ts->packet = packet; in ads7846_probe()
1261 ts->spi = spi; in ads7846_probe()
1262 ts->input = input_dev; in ads7846_probe()
1264 mutex_init(&ts->lock); in ads7846_probe()
1265 init_waitqueue_head(&ts->wait); in ads7846_probe()
1274 ts->model = pdata->model ? : 7846; in ads7846_probe()
1275 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1276 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1277 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1280 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1281 if (ts->debounce_max < 2) in ads7846_probe()
1282 ts->debounce_max = 2; in ads7846_probe()
1283 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1284 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1285 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1286 ts->filter_data = ts; in ads7846_probe()
1288 ts->filter = ads7846_no_filter; in ads7846_probe()
1291 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1296 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1299 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1301 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1302 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1304 input_dev->name = ts->name; in ads7846_probe()
1305 input_dev->phys = ts->phys; in ads7846_probe()
1327 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1328 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1334 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1336 ts->core_prop.swap_x_y = true; in ads7846_probe()
1339 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1341 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1342 if (IS_ERR(ts->reg)) { in ads7846_probe()
1343 err = PTR_ERR(ts->reg); in ads7846_probe()
1348 err = regulator_enable(ts->reg); in ads7846_probe()
1354 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1363 irq_flags, dev->driver->name, ts); in ads7846_probe()
1371 ts); in ads7846_probe()
1379 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1389 if (ts->model == 7845) in ads7846_probe()
1416 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1418 ads7846_stop(ts); in ads7846_remove()