Lines Matching refs:ts

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