Lines Matching +full:touchscreen +full:- +full:max +full:- +full:pressure

1 // SPDX-License-Identifier: GPL-2.0-only
3 * ADS7846 based touchscreen and sensor driver
10 * - corgi_ts.c
11 * Copyright (C) 2004-2005 Richard Purdie
12 * - omap_ts.[hc], ads7846.h, ts_osk.c
23 #include <linux/input/touchscreen.h>
41 * Support for ads7843 tested on Atmel at91sam926x-EK.
55 * note. The strength of filtering can be set in the board-* specific
69 * with msbs zeroed). Instead, we read them as two 8-bit values,
82 * driver is used with DMA-based SPI controllers (like atmel_spi) on
83 * systems where main memory is not DMA-coherent (most non-x86 boards).
89 /* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
149 /* leave chip selected when we're done, for quicker re-select? */
156 /*--------------------------------------------------------------------------*/
158 /* The ADS7846 has touchscreen and other sensors.
166 #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */
167 #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */
168 #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */
169 #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */
172 #define ADS_SER (1 << 2) /* non-differential */
179 #define MAX_12BIT ((1<<12)-1)
193 /* single-ended samples need to first power up reference voltage;
202 /* Must be called with ts->lock held */
205 if (!ts->disabled && !ts->suspended) { in ads7846_stop()
207 ts->stopped = true; in ads7846_stop()
209 wake_up(&ts->wait); in ads7846_stop()
210 disable_irq(ts->spi->irq); in ads7846_stop()
214 /* Must be called with ts->lock held */
217 if (!ts->disabled && !ts->suspended) { in ads7846_restart()
219 ts->stopped = false; in ads7846_restart()
221 enable_irq(ts->spi->irq); in ads7846_restart()
225 /* Must be called with ts->lock held */
229 regulator_disable(ts->reg); in __ads7846_disable()
237 /* Must be called with ts->lock held */
242 error = regulator_enable(ts->reg); in __ads7846_enable()
244 dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error); in __ads7846_enable()
251 mutex_lock(&ts->lock); in ads7846_disable()
253 if (!ts->disabled) { in ads7846_disable()
255 if (!ts->suspended) in ads7846_disable()
258 ts->disabled = true; in ads7846_disable()
261 mutex_unlock(&ts->lock); in ads7846_disable()
266 mutex_lock(&ts->lock); in ads7846_enable()
268 if (ts->disabled) { in ads7846_enable()
270 ts->disabled = false; in ads7846_enable()
272 if (!ts->suspended) in ads7846_enable()
276 mutex_unlock(&ts->lock); in ads7846_enable()
279 /*--------------------------------------------------------------------------*/
282 * Non-touchscreen sensors only use single-ended conversions.
321 return -ENOMEM; in ads7846_read12_ser()
323 spi_message_init(&req->msg); in ads7846_read12_ser()
326 if (ts->use_internal) { in ads7846_read12_ser()
327 req->ref_on = REF_ON; in ads7846_read12_ser()
328 req->xfer[0].tx_buf = &req->ref_on; in ads7846_read12_ser()
329 req->xfer[0].len = 1; in ads7846_read12_ser()
330 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7846_read12_ser()
332 req->xfer[1].rx_buf = &req->scratch; in ads7846_read12_ser()
333 req->xfer[1].len = 2; in ads7846_read12_ser()
336 req->xfer[1].delay.value = ts->vref_delay_usecs; in ads7846_read12_ser()
337 req->xfer[1].delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_read12_ser()
338 spi_message_add_tail(&req->xfer[1], &req->msg); in ads7846_read12_ser()
348 req->command = (u8) command; in ads7846_read12_ser()
349 req->xfer[2].tx_buf = &req->command; in ads7846_read12_ser()
350 req->xfer[2].len = 1; in ads7846_read12_ser()
351 spi_message_add_tail(&req->xfer[2], &req->msg); in ads7846_read12_ser()
353 req->xfer[3].rx_buf = &req->sample; in ads7846_read12_ser()
354 req->xfer[3].len = 2; in ads7846_read12_ser()
355 spi_message_add_tail(&req->xfer[3], &req->msg); in ads7846_read12_ser()
360 req->ref_off = PWRDOWN; in ads7846_read12_ser()
361 req->xfer[4].tx_buf = &req->ref_off; in ads7846_read12_ser()
362 req->xfer[4].len = 1; in ads7846_read12_ser()
363 spi_message_add_tail(&req->xfer[4], &req->msg); in ads7846_read12_ser()
365 req->xfer[5].rx_buf = &req->scratch; in ads7846_read12_ser()
366 req->xfer[5].len = 2; in ads7846_read12_ser()
367 CS_CHANGE(req->xfer[5]); in ads7846_read12_ser()
368 spi_message_add_tail(&req->xfer[5], &req->msg); in ads7846_read12_ser()
370 mutex_lock(&ts->lock); in ads7846_read12_ser()
372 status = spi_sync(spi, &req->msg); in ads7846_read12_ser()
374 mutex_unlock(&ts->lock); in ads7846_read12_ser()
377 /* on-wire is a must-ignore bit, a BE12 value, then padding */ in ads7846_read12_ser()
378 status = be16_to_cpu(req->sample); in ads7846_read12_ser()
396 return -ENOMEM; in ads7845_read12_ser()
398 spi_message_init(&req->msg); in ads7845_read12_ser()
400 req->command[0] = (u8) command; in ads7845_read12_ser()
401 req->xfer[0].tx_buf = req->command; in ads7845_read12_ser()
402 req->xfer[0].rx_buf = req->sample; in ads7845_read12_ser()
403 req->xfer[0].len = 3; in ads7845_read12_ser()
404 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7845_read12_ser()
406 mutex_lock(&ts->lock); in ads7845_read12_ser()
408 status = spi_sync(spi, &req->msg); in ads7845_read12_ser()
410 mutex_unlock(&ts->lock); in ads7845_read12_ser()
414 status = be16_to_cpu(*((u16 *)&req->sample[1])); in ads7845_read12_ser()
429 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
439 * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high
461 retval *= ts->vref_mv; in SHOW()
472 if (ts->model == 7846) in vbatt_adjust()
487 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
489 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
492 return attr->mode; in SHOW()
512 switch (ts->model) { in ads784x_hwmon_register()
514 if (!ts->vref_mv) { in ads784x_hwmon_register()
515 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); in ads784x_hwmon_register()
516 ts->vref_mv = 2500; in ads784x_hwmon_register()
517 ts->use_internal = true; in ads784x_hwmon_register()
522 if (!ts->vref_mv) { in ads784x_hwmon_register()
523 dev_warn(&spi->dev, in ads784x_hwmon_register()
525 ts->model); in ads784x_hwmon_register()
531 ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, in ads784x_hwmon_register()
534 return PTR_ERR_OR_ZERO(ts->hwmon); in ads784x_hwmon_register()
540 if (ts->hwmon) in ads784x_hwmon_unregister()
541 hwmon_device_unregister(ts->hwmon); in ads784x_hwmon_unregister()
562 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
572 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
607 /*--------------------------------------------------------------------------*/
611 if (ts->get_pendown_state) in get_pendown_state()
612 return ts->get_pendown_state(); in get_pendown_state()
614 return !gpio_get_value(ts->gpio_pendown); in get_pendown_state()
625 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
627 ts->read_rep = 0; in ads7846_debounce_filter()
632 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
633 ts->last_read = *val; in ads7846_debounce_filter()
634 ts->read_cnt++; in ads7846_debounce_filter()
643 ts->read_cnt = 0; in ads7846_debounce_filter()
647 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
652 ts->read_cnt = 0; in ads7846_debounce_filter()
653 ts->read_rep = 0; in ads7846_debounce_filter()
657 ts->read_cnt++; in ads7846_debounce_filter()
672 list_entry(m->transfers.prev, struct spi_transfer, transfer_list); in ads7846_get_value()
674 if (ts->model == 7845) { in ads7846_get_value()
675 value = be16_to_cpup((__be16 *)&(((char *)t->rx_buf)[1])); in ads7846_get_value()
678 * adjust: on-wire is a must-ignore bit, a BE12 value, then in ads7846_get_value()
679 * padding; built from two 8 bit values written msb-first. in ads7846_get_value()
681 value = be16_to_cpup((__be16 *)t->rx_buf); in ads7846_get_value()
691 list_entry(m->transfers.prev, struct spi_transfer, transfer_list); in ads7846_update_value()
693 *(u16 *)t->rx_buf = val; in ads7846_update_value()
698 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
705 while (msg_idx < ts->msg_count) { in ads7846_read_state()
707 ts->wait_for_sync(); in ads7846_read_state()
709 m = &ts->msg[msg_idx]; in ads7846_read_state()
710 error = spi_sync(ts->spi, m); in ads7846_read_state()
712 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
713 packet->tc.ignore = true; in ads7846_read_state()
721 if (msg_idx < ts->msg_count - 1) { in ads7846_read_state()
725 action = ts->filter(ts->filter_data, msg_idx, &val); in ads7846_read_state()
731 packet->tc.ignore = true; in ads7846_read_state()
732 msg_idx = ts->msg_count - 1; in ads7846_read_state()
737 packet->tc.ignore = false; in ads7846_read_state()
752 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
757 * ads7846_get_value() does in-place conversion (including byte swap) in ads7846_report_state()
758 * from on-the-wire format as part of debouncing to get stable in ads7846_report_state()
761 if (ts->model == 7845) { in ads7846_report_state()
762 x = *(u16 *)packet->tc.x_buf; in ads7846_report_state()
763 y = *(u16 *)packet->tc.y_buf; in ads7846_report_state()
767 x = packet->tc.x; in ads7846_report_state()
768 y = packet->tc.y; in ads7846_report_state()
769 z1 = packet->tc.z1; in ads7846_report_state()
770 z2 = packet->tc.z2; in ads7846_report_state()
777 if (ts->model == 7843) { in ads7846_report_state()
778 Rt = ts->pressure_max / 2; in ads7846_report_state()
779 } else if (ts->model == 7845) { in ads7846_report_state()
781 Rt = ts->pressure_max / 2; in ads7846_report_state()
784 dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt); in ads7846_report_state()
786 /* compute touch pressure resistance using equation #2 */ in ads7846_report_state()
788 Rt -= z1; in ads7846_report_state()
790 Rt *= ts->x_plate_ohms; in ads7846_report_state()
798 * Sample found inconsistent by debouncing or pressure is beyond in ads7846_report_state()
802 if (packet->tc.ignore || Rt > ts->pressure_max) { in ads7846_report_state()
803 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
804 packet->tc.ignore, Rt); in ads7846_report_state()
812 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
813 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
819 * NOTE: We can't rely on the pressure to determine the pen down in ads7846_report_state()
820 * state, even this controller has a pressure sensor. The pressure in ads7846_report_state()
828 struct input_dev *input = ts->input; in ads7846_report_state()
830 if (!ts->pendown) { in ads7846_report_state()
832 ts->pendown = true; in ads7846_report_state()
833 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
836 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
837 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
840 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
859 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
864 if (!ts->stopped) in ads7846_irq()
867 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
871 if (ts->pendown && !ts->stopped) { in ads7846_irq()
872 struct input_dev *input = ts->input; in ads7846_irq()
878 ts->pendown = false; in ads7846_irq()
879 dev_vdbg(&ts->spi->dev, "UP\n"); in ads7846_irq()
889 mutex_lock(&ts->lock); in ads7846_suspend()
891 if (!ts->suspended) { in ads7846_suspend()
893 if (!ts->disabled) in ads7846_suspend()
896 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
897 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
899 ts->suspended = true; in ads7846_suspend()
902 mutex_unlock(&ts->lock); in ads7846_suspend()
911 mutex_lock(&ts->lock); in ads7846_resume()
913 if (ts->suspended) { in ads7846_resume()
915 ts->suspended = false; in ads7846_resume()
917 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
918 disable_irq_wake(ts->spi->irq); in ads7846_resume()
920 if (!ts->disabled) in ads7846_resume()
924 mutex_unlock(&ts->lock); in ads7846_resume()
938 * REVISIT when the irq can be triggered active-low, or if for some in ads7846_setup_pendown()
939 * reason the touchscreen isn't hooked up, we don't need to access in ads7846_setup_pendown()
943 if (pdata->get_pendown_state) { in ads7846_setup_pendown()
944 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
945 } else if (gpio_is_valid(pdata->gpio_pendown)) { in ads7846_setup_pendown()
947 err = gpio_request_one(pdata->gpio_pendown, GPIOF_IN, in ads7846_setup_pendown()
950 dev_err(&spi->dev, in ads7846_setup_pendown()
952 pdata->gpio_pendown, err); in ads7846_setup_pendown()
956 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
958 if (pdata->gpio_pendown_debounce) in ads7846_setup_pendown()
959 gpio_set_debounce(pdata->gpio_pendown, in ads7846_setup_pendown()
960 pdata->gpio_pendown_debounce); in ads7846_setup_pendown()
962 dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); in ads7846_setup_pendown()
963 return -EINVAL; in ads7846_setup_pendown()
970 * Set up the transfers to read touchscreen state; this assumes we
971 * use formula #2 for pressure, not #3.
976 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
977 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
978 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
979 int vref = pdata->keep_vref_on; in ads7846_setup_spi_msg()
981 if (ts->model == 7873) { in ads7846_setup_spi_msg()
987 ts->model = 7846; in ads7846_setup_spi_msg()
991 ts->msg_count = 1; in ads7846_setup_spi_msg()
993 m->context = ts; in ads7846_setup_spi_msg()
995 if (ts->model == 7845) { in ads7846_setup_spi_msg()
996 packet->read_y_cmd[0] = READ_Y(vref); in ads7846_setup_spi_msg()
997 packet->read_y_cmd[1] = 0; in ads7846_setup_spi_msg()
998 packet->read_y_cmd[2] = 0; in ads7846_setup_spi_msg()
999 x->tx_buf = &packet->read_y_cmd[0]; in ads7846_setup_spi_msg()
1000 x->rx_buf = &packet->tc.y_buf[0]; in ads7846_setup_spi_msg()
1001 x->len = 3; in ads7846_setup_spi_msg()
1004 /* y- still on; turn on only y+ (and ADC) */ in ads7846_setup_spi_msg()
1005 packet->read_y = READ_Y(vref); in ads7846_setup_spi_msg()
1006 x->tx_buf = &packet->read_y; in ads7846_setup_spi_msg()
1007 x->len = 1; in ads7846_setup_spi_msg()
1011 x->rx_buf = &packet->tc.y; in ads7846_setup_spi_msg()
1012 x->len = 2; in ads7846_setup_spi_msg()
1021 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1022 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1023 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1026 x->tx_buf = &packet->read_y; in ads7846_setup_spi_msg()
1027 x->len = 1; in ads7846_setup_spi_msg()
1031 x->rx_buf = &packet->tc.y; in ads7846_setup_spi_msg()
1032 x->len = 2; in ads7846_setup_spi_msg()
1036 ts->msg_count++; in ads7846_setup_spi_msg()
1039 m->context = ts; in ads7846_setup_spi_msg()
1041 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1043 packet->read_x_cmd[0] = READ_X(vref); in ads7846_setup_spi_msg()
1044 packet->read_x_cmd[1] = 0; in ads7846_setup_spi_msg()
1045 packet->read_x_cmd[2] = 0; in ads7846_setup_spi_msg()
1046 x->tx_buf = &packet->read_x_cmd[0]; in ads7846_setup_spi_msg()
1047 x->rx_buf = &packet->tc.x_buf[0]; in ads7846_setup_spi_msg()
1048 x->len = 3; in ads7846_setup_spi_msg()
1051 /* turn y- off, x+ on, then leave in lowpower */ in ads7846_setup_spi_msg()
1053 packet->read_x = READ_X(vref); in ads7846_setup_spi_msg()
1054 x->tx_buf = &packet->read_x; in ads7846_setup_spi_msg()
1055 x->len = 1; in ads7846_setup_spi_msg()
1059 x->rx_buf = &packet->tc.x; in ads7846_setup_spi_msg()
1060 x->len = 2; in ads7846_setup_spi_msg()
1065 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1066 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1067 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1070 x->tx_buf = &packet->read_x; in ads7846_setup_spi_msg()
1071 x->len = 1; in ads7846_setup_spi_msg()
1075 x->rx_buf = &packet->tc.x; in ads7846_setup_spi_msg()
1076 x->len = 2; in ads7846_setup_spi_msg()
1080 /* turn y+ off, x- on; we'll use formula #2 */ in ads7846_setup_spi_msg()
1081 if (ts->model == 7846) { in ads7846_setup_spi_msg()
1082 ts->msg_count++; in ads7846_setup_spi_msg()
1085 m->context = ts; in ads7846_setup_spi_msg()
1088 packet->read_z1 = READ_Z1(vref); in ads7846_setup_spi_msg()
1089 x->tx_buf = &packet->read_z1; in ads7846_setup_spi_msg()
1090 x->len = 1; in ads7846_setup_spi_msg()
1094 x->rx_buf = &packet->tc.z1; in ads7846_setup_spi_msg()
1095 x->len = 2; in ads7846_setup_spi_msg()
1099 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1100 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1101 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1104 x->tx_buf = &packet->read_z1; in ads7846_setup_spi_msg()
1105 x->len = 1; in ads7846_setup_spi_msg()
1109 x->rx_buf = &packet->tc.z1; in ads7846_setup_spi_msg()
1110 x->len = 2; in ads7846_setup_spi_msg()
1114 ts->msg_count++; in ads7846_setup_spi_msg()
1117 m->context = ts; in ads7846_setup_spi_msg()
1120 packet->read_z2 = READ_Z2(vref); in ads7846_setup_spi_msg()
1121 x->tx_buf = &packet->read_z2; in ads7846_setup_spi_msg()
1122 x->len = 1; in ads7846_setup_spi_msg()
1126 x->rx_buf = &packet->tc.z2; in ads7846_setup_spi_msg()
1127 x->len = 2; in ads7846_setup_spi_msg()
1131 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1132 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1133 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1136 x->tx_buf = &packet->read_z2; in ads7846_setup_spi_msg()
1137 x->len = 1; in ads7846_setup_spi_msg()
1141 x->rx_buf = &packet->tc.z2; in ads7846_setup_spi_msg()
1142 x->len = 2; in ads7846_setup_spi_msg()
1148 ts->msg_count++; in ads7846_setup_spi_msg()
1151 m->context = ts; in ads7846_setup_spi_msg()
1153 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1155 packet->pwrdown_cmd[0] = PWRDOWN; in ads7846_setup_spi_msg()
1156 packet->pwrdown_cmd[1] = 0; in ads7846_setup_spi_msg()
1157 packet->pwrdown_cmd[2] = 0; in ads7846_setup_spi_msg()
1158 x->tx_buf = &packet->pwrdown_cmd[0]; in ads7846_setup_spi_msg()
1159 x->len = 3; in ads7846_setup_spi_msg()
1162 packet->pwrdown = PWRDOWN; in ads7846_setup_spi_msg()
1163 x->tx_buf = &packet->pwrdown; in ads7846_setup_spi_msg()
1164 x->len = 1; in ads7846_setup_spi_msg()
1168 x->rx_buf = &packet->dummy; in ads7846_setup_spi_msg()
1169 x->len = 2; in ads7846_setup_spi_msg()
1190 struct device_node *node = dev->of_node; in ads7846_probe_dt()
1196 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1202 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1207 return ERR_PTR(-ENOMEM); in ads7846_probe_dt()
1209 pdata->model = (unsigned long)match->data; in ads7846_probe_dt()
1211 of_property_read_u16(node, "ti,vref-delay-usecs", in ads7846_probe_dt()
1212 &pdata->vref_delay_usecs); in ads7846_probe_dt()
1213 of_property_read_u16(node, "ti,vref-mv", &pdata->vref_mv); in ads7846_probe_dt()
1214 pdata->keep_vref_on = of_property_read_bool(node, "ti,keep-vref-on"); in ads7846_probe_dt()
1216 pdata->swap_xy = of_property_read_bool(node, "ti,swap-xy"); in ads7846_probe_dt()
1218 of_property_read_u16(node, "ti,settle-delay-usec", in ads7846_probe_dt()
1219 &pdata->settle_delay_usecs); in ads7846_probe_dt()
1220 of_property_read_u16(node, "ti,penirq-recheck-delay-usecs", in ads7846_probe_dt()
1221 &pdata->penirq_recheck_delay_usecs); in ads7846_probe_dt()
1223 of_property_read_u16(node, "ti,x-plate-ohms", &pdata->x_plate_ohms); in ads7846_probe_dt()
1224 of_property_read_u16(node, "ti,y-plate-ohms", &pdata->y_plate_ohms); in ads7846_probe_dt()
1226 of_property_read_u16(node, "ti,x-min", &pdata->x_min); in ads7846_probe_dt()
1227 of_property_read_u16(node, "ti,y-min", &pdata->y_min); in ads7846_probe_dt()
1228 of_property_read_u16(node, "ti,x-max", &pdata->x_max); in ads7846_probe_dt()
1229 of_property_read_u16(node, "ti,y-max", &pdata->y_max); in ads7846_probe_dt()
1232 * touchscreen-max-pressure gets parsed during in ads7846_probe_dt()
1235 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min); in ads7846_probe_dt()
1236 if (!of_property_read_u32(node, "touchscreen-min-pressure", &value)) in ads7846_probe_dt()
1237 pdata->pressure_min = (u16) value; in ads7846_probe_dt()
1238 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); in ads7846_probe_dt()
1240 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max); in ads7846_probe_dt()
1241 if (!of_property_read_u32(node, "touchscreen-average-samples", &value)) in ads7846_probe_dt()
1242 pdata->debounce_max = (u16) value; in ads7846_probe_dt()
1243 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); in ads7846_probe_dt()
1244 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); in ads7846_probe_dt()
1246 of_property_read_u32(node, "ti,pendown-gpio-debounce", in ads7846_probe_dt()
1247 &pdata->gpio_pendown_debounce); in ads7846_probe_dt()
1249 pdata->wakeup = of_property_read_bool(node, "wakeup-source") || in ads7846_probe_dt()
1252 pdata->gpio_pendown = of_get_named_gpio(dev->of_node, "pendown-gpio", 0); in ads7846_probe_dt()
1260 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1273 if (!spi->irq) { in ads7846_probe()
1274 dev_dbg(&spi->dev, "no IRQ?\n"); in ads7846_probe()
1275 return -EINVAL; in ads7846_probe()
1278 /* don't exceed max specified sample rate */ in ads7846_probe()
1279 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { in ads7846_probe()
1280 dev_err(&spi->dev, "f(sample) %d KHz?\n", in ads7846_probe()
1281 (spi->max_speed_hz/SAMPLE_BITS)/1000); in ads7846_probe()
1282 return -EINVAL; in ads7846_probe()
1288 * may not. So we stick to very-portable 8 bit words, both RX and TX. in ads7846_probe()
1290 spi->bits_per_word = 8; in ads7846_probe()
1291 spi->mode = SPI_MODE_0; in ads7846_probe()
1300 err = -ENOMEM; in ads7846_probe()
1306 ts->packet = packet; in ads7846_probe()
1307 ts->spi = spi; in ads7846_probe()
1308 ts->input = input_dev; in ads7846_probe()
1310 mutex_init(&ts->lock); in ads7846_probe()
1311 init_waitqueue_head(&ts->wait); in ads7846_probe()
1313 pdata = dev_get_platdata(&spi->dev); in ads7846_probe()
1315 pdata = ads7846_probe_dt(&spi->dev); in ads7846_probe()
1322 ts->model = pdata->model ? : 7846; in ads7846_probe()
1323 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1324 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1325 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1327 if (pdata->filter != NULL) { in ads7846_probe()
1328 if (pdata->filter_init != NULL) { in ads7846_probe()
1329 err = pdata->filter_init(pdata, &ts->filter_data); in ads7846_probe()
1333 ts->filter = pdata->filter; in ads7846_probe()
1334 ts->filter_cleanup = pdata->filter_cleanup; in ads7846_probe()
1335 } else if (pdata->debounce_max) { in ads7846_probe()
1336 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1337 if (ts->debounce_max < 2) in ads7846_probe()
1338 ts->debounce_max = 2; in ads7846_probe()
1339 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1340 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1341 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1342 ts->filter_data = ts; in ads7846_probe()
1344 ts->filter = ads7846_no_filter; in ads7846_probe()
1351 if (pdata->penirq_recheck_delay_usecs) in ads7846_probe()
1352 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1353 pdata->penirq_recheck_delay_usecs; in ads7846_probe()
1355 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1357 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); in ads7846_probe()
1358 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1360 input_dev->name = ts->name; in ads7846_probe()
1361 input_dev->phys = ts->phys; in ads7846_probe()
1362 input_dev->dev.parent = &spi->dev; in ads7846_probe()
1364 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in ads7846_probe()
1365 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); in ads7846_probe()
1367 pdata->x_min ? : 0, in ads7846_probe()
1368 pdata->x_max ? : MAX_12BIT, in ads7846_probe()
1371 pdata->y_min ? : 0, in ads7846_probe()
1372 pdata->y_max ? : MAX_12BIT, in ads7846_probe()
1375 pdata->pressure_min, pdata->pressure_max, 0, 0); in ads7846_probe()
1382 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1383 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1386 * Check if legacy ti,swap-xy binding is used instead of in ads7846_probe()
1387 * touchscreen-swapped-x-y in ads7846_probe()
1389 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1390 swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]); in ads7846_probe()
1391 ts->core_prop.swap_x_y = true; in ads7846_probe()
1396 ts->reg = regulator_get(&spi->dev, "vcc"); in ads7846_probe()
1397 if (IS_ERR(ts->reg)) { in ads7846_probe()
1398 err = PTR_ERR(ts->reg); in ads7846_probe()
1399 dev_err(&spi->dev, "unable to get regulator: %d\n", err); in ads7846_probe()
1403 err = regulator_enable(ts->reg); in ads7846_probe()
1405 dev_err(&spi->dev, "unable to enable regulator: %d\n", err); in ads7846_probe()
1409 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; in ads7846_probe()
1412 err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, in ads7846_probe()
1413 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1414 if (err && !pdata->irq_flags) { in ads7846_probe()
1415 dev_info(&spi->dev, in ads7846_probe()
1416 "trying pin change workaround on irq %d\n", spi->irq); in ads7846_probe()
1418 err = request_threaded_irq(spi->irq, in ads7846_probe()
1420 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1424 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); in ads7846_probe()
1432 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); in ads7846_probe()
1436 * the touchscreen, in case it's not connected. in ads7846_probe()
1438 if (ts->model == 7845) in ads7846_probe()
1439 ads7845_read12_ser(&spi->dev, PWRDOWN); in ads7846_probe()
1441 (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux)); in ads7846_probe()
1443 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1451 device_init_wakeup(&spi->dev, pdata->wakeup); in ads7846_probe()
1457 if (!dev_get_platdata(&spi->dev)) in ads7846_probe()
1458 devm_kfree(&spi->dev, (void *)pdata); in ads7846_probe()
1463 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1467 free_irq(spi->irq, ts); in ads7846_probe()
1469 regulator_disable(ts->reg); in ads7846_probe()
1471 regulator_put(ts->reg); in ads7846_probe()
1473 if (!ts->get_pendown_state) in ads7846_probe()
1474 gpio_free(ts->gpio_pendown); in ads7846_probe()
1476 if (ts->filter_cleanup) in ads7846_probe()
1477 ts->filter_cleanup(ts->filter_data); in ads7846_probe()
1489 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_remove()
1492 free_irq(ts->spi->irq, ts); in ads7846_remove()
1494 input_unregister_device(ts->input); in ads7846_remove()
1498 regulator_put(ts->reg); in ads7846_remove()
1500 if (!ts->get_pendown_state) { in ads7846_remove()
1505 gpio_free(ts->gpio_pendown); in ads7846_remove()
1508 if (ts->filter_cleanup) in ads7846_remove()
1509 ts->filter_cleanup(ts->filter_data); in ads7846_remove()
1511 kfree(ts->packet); in ads7846_remove()
1514 dev_dbg(&spi->dev, "unregistered touchscreen\n"); in ads7846_remove()
1531 MODULE_DESCRIPTION("ADS7846 TouchScreen Driver");