Lines Matching refs: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()
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()
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()
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()
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()
646 struct ads7846 *ts = ads; in ads7846_debounce_filter() local
648 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
650 ts->read_rep = 0; in ads7846_debounce_filter()
655 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
656 ts->last_read = *val; in ads7846_debounce_filter()
657 ts->read_cnt++; in ads7846_debounce_filter()
666 ts->read_cnt = 0; in ads7846_debounce_filter()
670 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
675 ts->read_cnt = 0; in ads7846_debounce_filter()
676 ts->read_rep = 0; in ads7846_debounce_filter()
680 ts->read_cnt++; in ads7846_debounce_filter()
701 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx, in ads7846_set_cmd_val() argument
704 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
763 static int ads7846_filter(struct ads7846 *ts) in ads7846_filter() argument
765 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
779 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
784 ads7846_set_cmd_val(ts, cmd_idx, val); in ads7846_filter()
796 static void ads7846_read_state(struct ads7846 *ts) in ads7846_read_state() argument
798 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
806 ts->wait_for_sync(); in ads7846_read_state()
808 m = &ts->msg[msg_idx]; in ads7846_read_state()
809 error = spi_sync(ts->spi, m); in ads7846_read_state()
811 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
816 error = ads7846_filter(ts); in ads7846_read_state()
824 static void ads7846_report_state(struct ads7846 *ts) in ads7846_report_state() argument
826 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
832 if (ts->model == 7845) { in ads7846_report_state()
844 if (ts->model == 7843 || ts->model == 7845) { in ads7846_report_state()
845 Rt = ts->pressure_max / 2; in ads7846_report_state()
850 Rt *= ts->x_plate_ohms; in ads7846_report_state()
864 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
865 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
874 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
875 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
876 if (!get_pendown_state(ts)) in ads7846_report_state()
890 struct input_dev *input = ts->input; in ads7846_report_state()
892 if (!ts->pendown) { in ads7846_report_state()
894 ts->pendown = true; in ads7846_report_state()
895 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
898 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
899 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
902 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
908 struct ads7846 *ts = handle; in ads7846_hard_irq() local
910 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
916 struct ads7846 *ts = handle; in ads7846_irq() local
921 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
924 ads7846_read_state(ts); in ads7846_irq()
926 if (!ts->stopped) in ads7846_irq()
927 ads7846_report_state(ts); in ads7846_irq()
929 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
933 if (ts->pendown && !ts->stopped) in ads7846_irq()
934 ads7846_report_pen_up(ts); in ads7846_irq()
941 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
943 mutex_lock(&ts->lock); in ads7846_suspend()
945 if (!ts->suspended) { in ads7846_suspend()
947 if (!ts->disabled) in ads7846_suspend()
948 __ads7846_disable(ts); in ads7846_suspend()
950 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
951 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
953 ts->suspended = true; in ads7846_suspend()
956 mutex_unlock(&ts->lock); in ads7846_suspend()
963 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
965 mutex_lock(&ts->lock); in ads7846_resume()
967 if (ts->suspended) { in ads7846_resume()
969 ts->suspended = false; in ads7846_resume()
971 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
972 disable_irq_wake(ts->spi->irq); in ads7846_resume()
974 if (!ts->disabled) in ads7846_resume()
975 __ads7846_enable(ts); in ads7846_resume()
978 mutex_unlock(&ts->lock); in ads7846_resume()
986 struct ads7846 *ts, in ads7846_setup_pendown() argument
996 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
998 ts->gpio_pendown = gpiod_get(&spi->dev, "pendown", GPIOD_IN); in ads7846_setup_pendown()
999 if (IS_ERR(ts->gpio_pendown)) { in ads7846_setup_pendown()
1001 return PTR_ERR(ts->gpio_pendown); in ads7846_setup_pendown()
1004 gpiod_set_debounce(ts->gpio_pendown, in ads7846_setup_pendown()
1015 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1018 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1019 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1020 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1028 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1033 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1036 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1040 if (ts->model == 7846) in ads7846_setup_spi_msg()
1064 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1068 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1072 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1078 ts->model = 7846; in ads7846_setup_spi_msg()
1082 ts->msg_count = 1; in ads7846_setup_spi_msg()
1084 m->context = ts; in ads7846_setup_spi_msg()
1180 struct ads7846 *ts; in ads7846_probe() local
1211 ts = devm_kzalloc(dev, sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1212 if (!ts) in ads7846_probe()
1223 spi_set_drvdata(spi, ts); in ads7846_probe()
1225 ts->packet = packet; in ads7846_probe()
1226 ts->spi = spi; in ads7846_probe()
1227 ts->input = input_dev; in ads7846_probe()
1229 mutex_init(&ts->lock); in ads7846_probe()
1230 init_waitqueue_head(&ts->wait); in ads7846_probe()
1239 ts->model = pdata->model ? : 7846; in ads7846_probe()
1240 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1241 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1242 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1245 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1246 if (ts->debounce_max < 2) in ads7846_probe()
1247 ts->debounce_max = 2; in ads7846_probe()
1248 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1249 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1250 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1251 ts->filter_data = ts; in ads7846_probe()
1253 ts->filter = ads7846_no_filter; in ads7846_probe()
1256 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1261 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1264 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1266 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1267 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1269 input_dev->name = ts->name; in ads7846_probe()
1270 input_dev->phys = ts->phys; in ads7846_probe()
1284 if (ts->model != 7845) in ads7846_probe()
1293 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1294 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1300 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1302 ts->core_prop.swap_x_y = true; in ads7846_probe()
1305 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1307 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1308 if (IS_ERR(ts->reg)) { in ads7846_probe()
1309 err = PTR_ERR(ts->reg); in ads7846_probe()
1314 err = regulator_enable(ts->reg); in ads7846_probe()
1320 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1329 irq_flags, dev->driver->name, ts); in ads7846_probe()
1337 ts); in ads7846_probe()
1345 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1355 if (ts->model == 7845) in ads7846_probe()
1382 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1384 ads7846_stop(ts); in ads7846_remove()