• Home
  • Raw
  • Download

Lines Matching +full:tx +full:- +full:ts +full:- +full:max

1 // SPDX-License-Identifier: GPL-2.0-only
10 * - corgi_ts.c
11 * Copyright (C) 2004-2005 Richard Purdie
12 * - omap_ts.[hc], ads7846.h, ts_osk.c
42 * Support for ads7843 tested on Atmel at91sam926x-EK.
56 * note. The strength of filtering can be set in the board-* specific
79 * driver is used with DMA-based SPI controllers (like atmel_spi) on
80 * systems where main memory is not DMA-coherent (most non-x86 boards).
89 struct ads7846_buf *tx; member
153 /* leave chip selected when we're done, for quicker re-select? */
160 /*--------------------------------------------------------------------------*/
170 #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */
171 #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */
172 #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */
173 #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */
176 #define ADS_SER (1 << 2) /* non-differential */
183 #define MAX_12BIT ((1<<12)-1)
196 /* single-ended samples need to first power up reference voltage;
207 * Measure: X; Vref: X+, X-; IN: Y+
208 * Measure: Y; Vref: Y+, Y-; IN: X+
209 * Measure: Z1; Vref: Y+, X-; IN: X+
210 * Measure: Z2; Vref: Y+, X-; IN: Y-
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()
240 /* Must be called with ts->lock held */
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()
252 /* Must be called with ts->lock held */
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()
267 /* Must be called with ts->lock held */
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()
279 /* Must be called with ts->lock held */
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()
321 /*--------------------------------------------------------------------------*/
324 * Non-touchscreen sensors only use single-ended conversions.
357 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_read12_ser() local
363 return -ENOMEM; in ads7846_read12_ser()
365 spi_message_init(&req->msg); in ads7846_read12_ser()
368 if (ts->use_internal) { in ads7846_read12_ser()
369 req->ref_on = REF_ON; in ads7846_read12_ser()
370 req->xfer[0].tx_buf = &req->ref_on; in ads7846_read12_ser()
371 req->xfer[0].len = 1; in ads7846_read12_ser()
372 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7846_read12_ser()
374 req->xfer[1].rx_buf = &req->scratch; in ads7846_read12_ser()
375 req->xfer[1].len = 2; in ads7846_read12_ser()
378 req->xfer[1].delay.value = ts->vref_delay_usecs; in ads7846_read12_ser()
379 req->xfer[1].delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_read12_ser()
380 spi_message_add_tail(&req->xfer[1], &req->msg); in ads7846_read12_ser()
390 req->command = (u8) command; in ads7846_read12_ser()
391 req->xfer[2].tx_buf = &req->command; in ads7846_read12_ser()
392 req->xfer[2].len = 1; in ads7846_read12_ser()
393 spi_message_add_tail(&req->xfer[2], &req->msg); in ads7846_read12_ser()
395 req->xfer[3].rx_buf = &req->sample; in ads7846_read12_ser()
396 req->xfer[3].len = 2; in ads7846_read12_ser()
397 spi_message_add_tail(&req->xfer[3], &req->msg); in ads7846_read12_ser()
402 req->ref_off = PWRDOWN; in ads7846_read12_ser()
403 req->xfer[4].tx_buf = &req->ref_off; in ads7846_read12_ser()
404 req->xfer[4].len = 1; in ads7846_read12_ser()
405 spi_message_add_tail(&req->xfer[4], &req->msg); in ads7846_read12_ser()
407 req->xfer[5].rx_buf = &req->scratch; in ads7846_read12_ser()
408 req->xfer[5].len = 2; in ads7846_read12_ser()
409 CS_CHANGE(req->xfer[5]); in ads7846_read12_ser()
410 spi_message_add_tail(&req->xfer[5], &req->msg); in ads7846_read12_ser()
412 mutex_lock(&ts->lock); in ads7846_read12_ser()
413 ads7846_stop(ts); in ads7846_read12_ser()
414 status = spi_sync(spi, &req->msg); in ads7846_read12_ser()
415 ads7846_restart(ts); in ads7846_read12_ser()
416 mutex_unlock(&ts->lock); in ads7846_read12_ser()
419 /* on-wire is a must-ignore bit, a BE12 value, then padding */ in ads7846_read12_ser()
420 status = be16_to_cpu(req->sample); in ads7846_read12_ser()
432 struct ads7846 *ts = dev_get_drvdata(dev); in ads7845_read12_ser() local
438 return -ENOMEM; in ads7845_read12_ser()
440 spi_message_init(&req->msg); in ads7845_read12_ser()
442 req->command[0] = (u8) command; in ads7845_read12_ser()
443 req->xfer[0].tx_buf = req->command; in ads7845_read12_ser()
444 req->xfer[0].rx_buf = req->sample; in ads7845_read12_ser()
445 req->xfer[0].len = 3; in ads7845_read12_ser()
446 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7845_read12_ser()
448 mutex_lock(&ts->lock); in ads7845_read12_ser()
449 ads7846_stop(ts); in ads7845_read12_ser()
450 status = spi_sync(spi, &req->msg); in ads7845_read12_ser()
451 ads7846_restart(ts); in ads7845_read12_ser()
452 mutex_unlock(&ts->lock); in ads7845_read12_ser()
456 status = get_unaligned_be16(&req->sample[1]); 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)); \
481 * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high
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()
534 return attr->mode; in SHOW()
551 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()
557 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); 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()
565 dev_warn(&spi->dev, in ads784x_hwmon_register()
567 ts->model); in ads784x_hwmon_register()
573 ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, in ads784x_hwmon_register()
574 ts, ads7846_attr_groups); in ads784x_hwmon_register()
576 return PTR_ERR_OR_ZERO(ts->hwmon); in ads784x_hwmon_register()
580 struct ads7846 *ts) in ads784x_hwmon_unregister() argument
582 if (ts->hwmon) in ads784x_hwmon_unregister()
583 hwmon_device_unregister(ts->hwmon); in ads784x_hwmon_unregister()
588 struct ads7846 *ts) in ads784x_hwmon_register() argument
594 struct ads7846 *ts) in ads784x_hwmon_unregister() argument
602 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_pen_down_show() local
604 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
612 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_show() local
614 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
621 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_disable_store() local
630 ads7846_disable(ts); in ads7846_disable_store()
632 ads7846_enable(ts); in ads7846_disable_store()
649 /*--------------------------------------------------------------------------*/
657 struct ads7846 *ts = ads; in ads7846_debounce_filter() local
659 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
661 ts->read_rep = 0; in ads7846_debounce_filter()
666 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
667 ts->last_read = *val; in ads7846_debounce_filter()
668 ts->read_cnt++; in ads7846_debounce_filter()
677 ts->read_cnt = 0; in ads7846_debounce_filter()
681 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
686 ts->read_cnt = 0; in ads7846_debounce_filter()
687 ts->read_rep = 0; in ads7846_debounce_filter()
691 ts->read_cnt++; in ads7846_debounce_filter()
706 value = be16_to_cpup(&buf->data); in ads7846_get_value()
712 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx, in ads7846_set_cmd_val() argument
715 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
719 packet->y = val; in ads7846_set_cmd_val()
722 packet->x = val; in ads7846_set_cmd_val()
725 packet->z1 = val; in ads7846_set_cmd_val()
728 packet->z2 = val; in ads7846_set_cmd_val()
774 static int ads7846_filter(struct ads7846 *ts) in ads7846_filter() argument
776 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
781 packet->ignore = false; in ads7846_filter()
782 for (cmd_idx = packet->last_cmd_idx; cmd_idx < packet->cmds - 1; cmd_idx++) { in ads7846_filter()
783 struct ads7846_buf_layout *l = &packet->l[cmd_idx]; in ads7846_filter()
785 packet->last_cmd_idx = cmd_idx; in ads7846_filter()
787 for (b = l->skip; b < l->count; b++) { in ads7846_filter()
788 val = ads7846_get_value(&packet->rx[l->offset + b]); in ads7846_filter()
790 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
792 if (b == l->count - 1) in ads7846_filter()
793 return -EAGAIN; in ads7846_filter()
795 ads7846_set_cmd_val(ts, cmd_idx, val); in ads7846_filter()
798 packet->ignore = true; in ads7846_filter()
807 static void ads7846_read_state(struct ads7846 *ts) in ads7846_read_state() argument
809 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
814 packet->last_cmd_idx = 0; in ads7846_read_state()
817 ts->wait_for_sync(); in ads7846_read_state()
819 m = &ts->msg[msg_idx]; in ads7846_read_state()
820 error = spi_sync(ts->spi, m); in ads7846_read_state()
822 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
823 packet->ignore = true; in ads7846_read_state()
827 error = ads7846_filter(ts); in ads7846_read_state()
835 static void ads7846_report_state(struct ads7846 *ts) in ads7846_report_state() argument
837 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
841 x = packet->x; in ads7846_report_state()
842 y = packet->y; in ads7846_report_state()
843 if (ts->model == 7845) { in ads7846_report_state()
847 z1 = packet->z1; in ads7846_report_state()
848 z2 = packet->z2; in ads7846_report_state()
855 if (ts->model == 7843 || ts->model == 7845) { in ads7846_report_state()
856 Rt = ts->pressure_max / 2; in ads7846_report_state()
860 Rt -= z1; in ads7846_report_state()
861 Rt *= ts->x_plate_ohms; in ads7846_report_state()
875 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
876 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
877 packet->ignore, Rt); in ads7846_report_state()
885 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
886 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
887 if (!get_pendown_state(ts)) in ads7846_report_state()
901 struct input_dev *input = ts->input; in ads7846_report_state()
903 if (!ts->pendown) { in ads7846_report_state()
905 ts->pendown = true; in ads7846_report_state()
906 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
909 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
910 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
913 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
919 struct ads7846 *ts = handle; in ads7846_hard_irq() local
921 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED; in ads7846_hard_irq()
927 struct ads7846 *ts = handle; in ads7846_irq() local
932 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
935 ads7846_read_state(ts); in ads7846_irq()
937 if (!ts->stopped) in ads7846_irq()
938 ads7846_report_state(ts); in ads7846_irq()
940 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
944 if (ts->pendown && !ts->stopped) in ads7846_irq()
945 ads7846_report_pen_up(ts); in ads7846_irq()
952 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_suspend() local
954 mutex_lock(&ts->lock); in ads7846_suspend()
956 if (!ts->suspended) { in ads7846_suspend()
958 if (!ts->disabled) in ads7846_suspend()
959 __ads7846_disable(ts); in ads7846_suspend()
961 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
962 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
964 ts->suspended = true; in ads7846_suspend()
967 mutex_unlock(&ts->lock); in ads7846_suspend()
974 struct ads7846 *ts = dev_get_drvdata(dev); in ads7846_resume() local
976 mutex_lock(&ts->lock); in ads7846_resume()
978 if (ts->suspended) { in ads7846_resume()
980 ts->suspended = false; in ads7846_resume()
982 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
983 disable_irq_wake(ts->spi->irq); in ads7846_resume()
985 if (!ts->disabled) in ads7846_resume()
986 __ads7846_enable(ts); in ads7846_resume()
989 mutex_unlock(&ts->lock); in ads7846_resume()
997 struct ads7846 *ts, in ads7846_setup_pendown() argument
1003 * REVISIT when the irq can be triggered active-low, or if for some in ads7846_setup_pendown()
1008 if (pdata->get_pendown_state) { in ads7846_setup_pendown()
1009 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
1010 } else if (gpio_is_valid(pdata->gpio_pendown)) { in ads7846_setup_pendown()
1012 err = gpio_request_one(pdata->gpio_pendown, GPIOF_IN, in ads7846_setup_pendown()
1015 dev_err(&spi->dev, in ads7846_setup_pendown()
1017 pdata->gpio_pendown, err); in ads7846_setup_pendown()
1021 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
1023 if (pdata->gpio_pendown_debounce) in ads7846_setup_pendown()
1024 gpio_set_debounce(pdata->gpio_pendown, in ads7846_setup_pendown()
1025 pdata->gpio_pendown_debounce); in ads7846_setup_pendown()
1027 dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); in ads7846_setup_pendown()
1028 return -EINVAL; in ads7846_setup_pendown()
1038 static int ads7846_setup_spi_msg(struct ads7846 *ts, in ads7846_setup_spi_msg() argument
1041 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1042 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1043 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1044 int vref = pdata->keep_vref_on; in ads7846_setup_spi_msg()
1051 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1053 count = pdata->settle_delay_usecs * NSEC_PER_USEC / time; in ads7846_setup_spi_msg()
1054 packet->count_skip = DIV_ROUND_UP(count, 24); in ads7846_setup_spi_msg()
1056 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1057 /* ads7846_debounce_filter() is making ts->debounce_rep + 2 in ads7846_setup_spi_msg()
1059 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1061 packet->count = 1; in ads7846_setup_spi_msg()
1063 if (ts->model == 7846) in ads7846_setup_spi_msg()
1064 packet->cmds = 5; /* x, y, z1, z2, pwdown */ in ads7846_setup_spi_msg()
1066 packet->cmds = 3; /* x, y, pwdown */ in ads7846_setup_spi_msg()
1068 for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) { in ads7846_setup_spi_msg()
1069 struct ads7846_buf_layout *l = &packet->l[cmd_idx]; in ads7846_setup_spi_msg()
1072 if (cmd_idx == packet->cmds - 1) in ads7846_setup_spi_msg()
1076 max_count = packet->count + packet->count_skip; in ads7846_setup_spi_msg()
1078 max_count = packet->count; in ads7846_setup_spi_msg()
1080 l->offset = offset; in ads7846_setup_spi_msg()
1082 l->count = max_count; in ads7846_setup_spi_msg()
1083 l->skip = packet->count_skip; in ads7846_setup_spi_msg()
1084 size += sizeof(*packet->tx) * max_count; in ads7846_setup_spi_msg()
1087 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1088 if (!packet->tx) in ads7846_setup_spi_msg()
1089 return -ENOMEM; in ads7846_setup_spi_msg()
1091 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1092 if (!packet->rx) in ads7846_setup_spi_msg()
1093 return -ENOMEM; in ads7846_setup_spi_msg()
1095 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1101 ts->model = 7846; in ads7846_setup_spi_msg()
1105 ts->msg_count = 1; in ads7846_setup_spi_msg()
1107 m->context = ts; in ads7846_setup_spi_msg()
1109 for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) { in ads7846_setup_spi_msg()
1110 struct ads7846_buf_layout *l = &packet->l[cmd_idx]; in ads7846_setup_spi_msg()
1113 if (cmd_idx == packet->cmds - 1) in ads7846_setup_spi_msg()
1118 for (b = 0; b < l->count; b++) in ads7846_setup_spi_msg()
1119 packet->tx[l->offset + b].cmd = cmd; in ads7846_setup_spi_msg()
1122 x->tx_buf = packet->tx; in ads7846_setup_spi_msg()
1123 x->rx_buf = packet->rx; in ads7846_setup_spi_msg()
1124 x->len = size; in ads7846_setup_spi_msg()
1144 struct device_node *node = dev->of_node; in ads7846_probe_dt()
1150 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1156 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1161 return ERR_PTR(-ENOMEM); in ads7846_probe_dt()
1163 pdata->model = (unsigned long)match->data; in ads7846_probe_dt()
1165 of_property_read_u16(node, "ti,vref-delay-usecs", in ads7846_probe_dt()
1166 &pdata->vref_delay_usecs); in ads7846_probe_dt()
1167 of_property_read_u16(node, "ti,vref-mv", &pdata->vref_mv); in ads7846_probe_dt()
1168 pdata->keep_vref_on = of_property_read_bool(node, "ti,keep-vref-on"); in ads7846_probe_dt()
1170 pdata->swap_xy = of_property_read_bool(node, "ti,swap-xy"); in ads7846_probe_dt()
1172 of_property_read_u16(node, "ti,settle-delay-usec", in ads7846_probe_dt()
1173 &pdata->settle_delay_usecs); in ads7846_probe_dt()
1174 of_property_read_u16(node, "ti,penirq-recheck-delay-usecs", in ads7846_probe_dt()
1175 &pdata->penirq_recheck_delay_usecs); in ads7846_probe_dt()
1177 of_property_read_u16(node, "ti,x-plate-ohms", &pdata->x_plate_ohms); in ads7846_probe_dt()
1178 of_property_read_u16(node, "ti,y-plate-ohms", &pdata->y_plate_ohms); in ads7846_probe_dt()
1180 of_property_read_u16(node, "ti,x-min", &pdata->x_min); in ads7846_probe_dt()
1181 of_property_read_u16(node, "ti,y-min", &pdata->y_min); in ads7846_probe_dt()
1182 of_property_read_u16(node, "ti,x-max", &pdata->x_max); in ads7846_probe_dt()
1183 of_property_read_u16(node, "ti,y-max", &pdata->y_max); in ads7846_probe_dt()
1186 * touchscreen-max-pressure gets parsed during in ads7846_probe_dt()
1189 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min); in ads7846_probe_dt()
1190 if (!of_property_read_u32(node, "touchscreen-min-pressure", &value)) in ads7846_probe_dt()
1191 pdata->pressure_min = (u16) value; in ads7846_probe_dt()
1192 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); in ads7846_probe_dt()
1194 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max); in ads7846_probe_dt()
1195 if (!of_property_read_u32(node, "touchscreen-average-samples", &value)) in ads7846_probe_dt()
1196 pdata->debounce_max = (u16) value; in ads7846_probe_dt()
1197 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); in ads7846_probe_dt()
1198 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); in ads7846_probe_dt()
1200 of_property_read_u32(node, "ti,pendown-gpio-debounce", in ads7846_probe_dt()
1201 &pdata->gpio_pendown_debounce); in ads7846_probe_dt()
1203 pdata->wakeup = of_property_read_bool(node, "wakeup-source") || in ads7846_probe_dt()
1206 pdata->gpio_pendown = of_get_named_gpio(dev->of_node, "pendown-gpio", 0); in ads7846_probe_dt()
1214 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1221 struct ads7846 *ts; in ads7846_probe() local
1227 if (!spi->irq) { in ads7846_probe()
1228 dev_dbg(&spi->dev, "no IRQ?\n"); in ads7846_probe()
1229 return -EINVAL; in ads7846_probe()
1232 /* don't exceed max specified sample rate */ in ads7846_probe()
1233 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { in ads7846_probe()
1234 dev_err(&spi->dev, "f(sample) %d KHz?\n", in ads7846_probe()
1235 (spi->max_speed_hz/SAMPLE_BITS)/1000); in ads7846_probe()
1236 return -EINVAL; in ads7846_probe()
1240 * We'd set TX word size 8 bits and RX word size to 13 bits ... except in ads7846_probe()
1242 * may not. So we stick to very-portable 8 bit words, both RX and TX. in ads7846_probe()
1244 spi->bits_per_word = 8; in ads7846_probe()
1245 spi->mode = SPI_MODE_0; in ads7846_probe()
1250 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); in ads7846_probe()
1253 if (!ts || !packet || !input_dev) { in ads7846_probe()
1254 err = -ENOMEM; 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()
1267 pdata = dev_get_platdata(&spi->dev); in ads7846_probe()
1269 pdata = ads7846_probe_dt(&spi->dev); 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()
1281 if (pdata->filter != NULL) { in ads7846_probe()
1282 if (pdata->filter_init != NULL) { in ads7846_probe()
1283 err = pdata->filter_init(pdata, &ts->filter_data); in ads7846_probe()
1287 ts->filter = pdata->filter; in ads7846_probe()
1288 ts->filter_cleanup = pdata->filter_cleanup; in ads7846_probe()
1289 } else if (pdata->debounce_max) { in ads7846_probe()
1290 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1291 if (ts->debounce_max < 2) in ads7846_probe()
1292 ts->debounce_max = 2; in ads7846_probe()
1293 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1294 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1295 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1296 ts->filter_data = ts; in ads7846_probe()
1298 ts->filter = ads7846_no_filter; in ads7846_probe()
1301 err = ads7846_setup_pendown(spi, ts, pdata); in ads7846_probe()
1305 if (pdata->penirq_recheck_delay_usecs) in ads7846_probe()
1306 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1307 pdata->penirq_recheck_delay_usecs; in ads7846_probe()
1309 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1311 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); in ads7846_probe()
1312 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1314 input_dev->name = ts->name; in ads7846_probe()
1315 input_dev->phys = ts->phys; in ads7846_probe()
1316 input_dev->dev.parent = &spi->dev; in ads7846_probe()
1318 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in ads7846_probe()
1319 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); in ads7846_probe()
1321 pdata->x_min ? : 0, in ads7846_probe()
1322 pdata->x_max ? : MAX_12BIT, in ads7846_probe()
1325 pdata->y_min ? : 0, in ads7846_probe()
1326 pdata->y_max ? : MAX_12BIT, in ads7846_probe()
1328 if (ts->model != 7845) in ads7846_probe()
1330 pdata->pressure_min, pdata->pressure_max, 0, 0); in ads7846_probe()
1337 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1338 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1341 * Check if legacy ti,swap-xy binding is used instead of in ads7846_probe()
1342 * touchscreen-swapped-x-y in ads7846_probe()
1344 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1345 swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]); in ads7846_probe()
1346 ts->core_prop.swap_x_y = true; in ads7846_probe()
1349 ads7846_setup_spi_msg(ts, pdata); in ads7846_probe()
1351 ts->reg = regulator_get(&spi->dev, "vcc"); in ads7846_probe()
1352 if (IS_ERR(ts->reg)) { in ads7846_probe()
1353 err = PTR_ERR(ts->reg); in ads7846_probe()
1354 dev_err(&spi->dev, "unable to get regulator: %d\n", err); in ads7846_probe()
1358 err = regulator_enable(ts->reg); in ads7846_probe()
1360 dev_err(&spi->dev, "unable to enable regulator: %d\n", err); in ads7846_probe()
1364 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; in ads7846_probe()
1367 err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, in ads7846_probe()
1368 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1369 if (err && !pdata->irq_flags) { in ads7846_probe()
1370 dev_info(&spi->dev, in ads7846_probe()
1371 "trying pin change workaround on irq %d\n", spi->irq); in ads7846_probe()
1373 err = request_threaded_irq(spi->irq, in ads7846_probe()
1375 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1379 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); in ads7846_probe()
1383 err = ads784x_hwmon_register(spi, ts); in ads7846_probe()
1387 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); in ads7846_probe()
1393 if (ts->model == 7845) in ads7846_probe()
1394 ads7845_read12_ser(&spi->dev, PWRDOWN); in ads7846_probe()
1396 (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux)); in ads7846_probe()
1398 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1406 device_init_wakeup(&spi->dev, pdata->wakeup); in ads7846_probe()
1412 if (!dev_get_platdata(&spi->dev)) in ads7846_probe()
1413 devm_kfree(&spi->dev, (void *)pdata); in ads7846_probe()
1418 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1420 ads784x_hwmon_unregister(spi, ts); in ads7846_probe()
1422 free_irq(spi->irq, ts); in ads7846_probe()
1424 regulator_disable(ts->reg); in ads7846_probe()
1426 regulator_put(ts->reg); in ads7846_probe()
1428 if (!ts->get_pendown_state) in ads7846_probe()
1429 gpio_free(ts->gpio_pendown); in ads7846_probe()
1431 if (ts->filter_cleanup) in ads7846_probe()
1432 ts->filter_cleanup(ts->filter_data); in ads7846_probe()
1436 kfree(ts); in ads7846_probe()
1442 struct ads7846 *ts = spi_get_drvdata(spi); in ads7846_remove() local
1444 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_remove()
1446 ads7846_disable(ts); in ads7846_remove()
1447 free_irq(ts->spi->irq, ts); in ads7846_remove()
1449 input_unregister_device(ts->input); in ads7846_remove()
1451 ads784x_hwmon_unregister(spi, ts); in ads7846_remove()
1453 regulator_put(ts->reg); in ads7846_remove()
1455 if (!ts->get_pendown_state) { in ads7846_remove()
1460 gpio_free(ts->gpio_pendown); in ads7846_remove()
1463 if (ts->filter_cleanup) in ads7846_remove()
1464 ts->filter_cleanup(ts->filter_data); in ads7846_remove()
1466 kfree(ts->packet); in ads7846_remove()
1467 kfree(ts); in ads7846_remove()
1469 dev_dbg(&spi->dev, "unregistered touchscreen\n"); in ads7846_remove()