Lines Matching +full:vref +full:- +full:p
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
70 * with msbs zeroed). Instead, we read them as two 8-bit values,
83 * driver is used with DMA-based SPI controllers (like atmel_spi) on
84 * systems where main memory is not DMA-coherent (most non-x86 boards).
90 /* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
137 bool stopped; /* P: lock */
138 bool disabled; /* P: lock */
139 bool suspended; /* P: lock */
150 /* leave chip selected when we're done, for quicker re-select? */
157 /*--------------------------------------------------------------------------*/
167 #define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */
168 #define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */
169 #define ADS_A2A1A0_vaux (6 << 4) /* non-differential */
170 #define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */
173 #define ADS_SER (1 << 2) /* non-differential */
177 #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */
178 #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
180 #define MAX_12BIT ((1<<12)-1)
183 #define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \ argument
185 (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0))
187 #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref)) argument
188 #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref)) argument
189 #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref)) argument
191 #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref)) argument
194 /* single-ended samples need to first power up reference voltage;
195 * we leave both ADC and VREF powered
205 if (ts->get_pendown_state) in get_pendown_state()
206 return ts->get_pendown_state(); in get_pendown_state()
208 return !gpio_get_value(ts->gpio_pendown); in get_pendown_state()
213 struct input_dev *input = ts->input; in ads7846_report_pen_up()
219 ts->pendown = false; in ads7846_report_pen_up()
220 dev_vdbg(&ts->spi->dev, "UP\n"); in ads7846_report_pen_up()
223 /* Must be called with ts->lock held */
226 if (!ts->disabled && !ts->suspended) { in ads7846_stop()
228 ts->stopped = true; in ads7846_stop()
230 wake_up(&ts->wait); in ads7846_stop()
231 disable_irq(ts->spi->irq); in ads7846_stop()
235 /* Must be called with ts->lock held */
238 if (!ts->disabled && !ts->suspended) { in ads7846_restart()
240 if (ts->pendown && !get_pendown_state(ts)) in ads7846_restart()
244 ts->stopped = false; in ads7846_restart()
246 enable_irq(ts->spi->irq); in ads7846_restart()
250 /* Must be called with ts->lock held */
254 regulator_disable(ts->reg); in __ads7846_disable()
262 /* Must be called with ts->lock held */
267 error = regulator_enable(ts->reg); in __ads7846_enable()
269 dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error); in __ads7846_enable()
276 mutex_lock(&ts->lock); in ads7846_disable()
278 if (!ts->disabled) { in ads7846_disable()
280 if (!ts->suspended) in ads7846_disable()
283 ts->disabled = true; in ads7846_disable()
286 mutex_unlock(&ts->lock); in ads7846_disable()
291 mutex_lock(&ts->lock); in ads7846_enable()
293 if (ts->disabled) { in ads7846_enable()
295 ts->disabled = false; in ads7846_enable()
297 if (!ts->suspended) in ads7846_enable()
301 mutex_unlock(&ts->lock); in ads7846_enable()
304 /*--------------------------------------------------------------------------*/
307 * Non-touchscreen sensors only use single-ended conversions.
308 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
309 * ads7846 lets that pin be unconnected, to use internal vREF.
346 return -ENOMEM; in ads7846_read12_ser()
348 spi_message_init(&req->msg); in ads7846_read12_ser()
350 /* maybe turn on internal vREF, and let it settle */ in ads7846_read12_ser()
351 if (ts->use_internal) { in ads7846_read12_ser()
352 req->ref_on = REF_ON; in ads7846_read12_ser()
353 req->xfer[0].tx_buf = &req->ref_on; in ads7846_read12_ser()
354 req->xfer[0].len = 1; in ads7846_read12_ser()
355 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7846_read12_ser()
357 req->xfer[1].rx_buf = &req->scratch; in ads7846_read12_ser()
358 req->xfer[1].len = 2; in ads7846_read12_ser()
361 req->xfer[1].delay.value = ts->vref_delay_usecs; in ads7846_read12_ser()
362 req->xfer[1].delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_read12_ser()
363 spi_message_add_tail(&req->xfer[1], &req->msg); in ads7846_read12_ser()
373 req->command = (u8) command; in ads7846_read12_ser()
374 req->xfer[2].tx_buf = &req->command; in ads7846_read12_ser()
375 req->xfer[2].len = 1; in ads7846_read12_ser()
376 spi_message_add_tail(&req->xfer[2], &req->msg); in ads7846_read12_ser()
378 req->xfer[3].rx_buf = &req->sample; in ads7846_read12_ser()
379 req->xfer[3].len = 2; in ads7846_read12_ser()
380 spi_message_add_tail(&req->xfer[3], &req->msg); in ads7846_read12_ser()
385 req->ref_off = PWRDOWN; in ads7846_read12_ser()
386 req->xfer[4].tx_buf = &req->ref_off; in ads7846_read12_ser()
387 req->xfer[4].len = 1; in ads7846_read12_ser()
388 spi_message_add_tail(&req->xfer[4], &req->msg); in ads7846_read12_ser()
390 req->xfer[5].rx_buf = &req->scratch; in ads7846_read12_ser()
391 req->xfer[5].len = 2; in ads7846_read12_ser()
392 CS_CHANGE(req->xfer[5]); in ads7846_read12_ser()
393 spi_message_add_tail(&req->xfer[5], &req->msg); in ads7846_read12_ser()
395 mutex_lock(&ts->lock); in ads7846_read12_ser()
397 status = spi_sync(spi, &req->msg); in ads7846_read12_ser()
399 mutex_unlock(&ts->lock); in ads7846_read12_ser()
402 /* on-wire is a must-ignore bit, a BE12 value, then padding */ in ads7846_read12_ser()
403 status = be16_to_cpu(req->sample); in ads7846_read12_ser()
421 return -ENOMEM; in ads7845_read12_ser()
423 spi_message_init(&req->msg); in ads7845_read12_ser()
425 req->command[0] = (u8) command; in ads7845_read12_ser()
426 req->xfer[0].tx_buf = req->command; in ads7845_read12_ser()
427 req->xfer[0].rx_buf = req->sample; in ads7845_read12_ser()
428 req->xfer[0].len = 3; in ads7845_read12_ser()
429 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7845_read12_ser()
431 mutex_lock(&ts->lock); in ads7845_read12_ser()
433 status = spi_sync(spi, &req->msg); in ads7845_read12_ser()
435 mutex_unlock(&ts->lock); in ads7845_read12_ser()
439 status = get_unaligned_be16(&req->sample[1]); in ads7845_read12_ser()
454 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
464 * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high
478 * if we know vREF. userspace may need to scale vAUX to match the board's in SHOW()
485 /* external resistors may scale vAUX into 0..vREF */ in SHOW()
486 retval *= ts->vref_mv; in SHOW()
497 if (ts->model == 7846) in vbatt_adjust()
512 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
514 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
517 return attr->mode; in SHOW()
537 switch (ts->model) { in ads784x_hwmon_register()
539 if (!ts->vref_mv) { in ads784x_hwmon_register()
540 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); in ads784x_hwmon_register()
541 ts->vref_mv = 2500; in ads784x_hwmon_register()
542 ts->use_internal = true; in ads784x_hwmon_register()
547 if (!ts->vref_mv) { in ads784x_hwmon_register()
548 dev_warn(&spi->dev, in ads784x_hwmon_register()
549 "external vREF for ADS%d not specified\n", in ads784x_hwmon_register()
550 ts->model); in ads784x_hwmon_register()
556 ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, in ads784x_hwmon_register()
559 return PTR_ERR_OR_ZERO(ts->hwmon); in ads784x_hwmon_register()
565 if (ts->hwmon) in ads784x_hwmon_unregister()
566 hwmon_device_unregister(ts->hwmon); in ads784x_hwmon_unregister()
587 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
597 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
632 /*--------------------------------------------------------------------------*/
642 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
644 ts->read_rep = 0; in ads7846_debounce_filter()
649 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
650 ts->last_read = *val; in ads7846_debounce_filter()
651 ts->read_cnt++; in ads7846_debounce_filter()
660 ts->read_cnt = 0; in ads7846_debounce_filter()
664 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
669 ts->read_cnt = 0; in ads7846_debounce_filter()
670 ts->read_rep = 0; in ads7846_debounce_filter()
674 ts->read_cnt++; in ads7846_debounce_filter()
689 list_entry(m->transfers.prev, struct spi_transfer, transfer_list); in ads7846_get_value()
691 if (ts->model == 7845) { in ads7846_get_value()
692 value = be16_to_cpup((__be16 *)&(((char *)t->rx_buf)[1])); in ads7846_get_value()
695 * adjust: on-wire is a must-ignore bit, a BE12 value, then in ads7846_get_value()
696 * padding; built from two 8 bit values written msb-first. in ads7846_get_value()
698 value = be16_to_cpup((__be16 *)t->rx_buf); in ads7846_get_value()
708 list_entry(m->transfers.prev, struct spi_transfer, transfer_list); in ads7846_update_value()
710 *(u16 *)t->rx_buf = val; in ads7846_update_value()
715 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
722 while (msg_idx < ts->msg_count) { in ads7846_read_state()
724 ts->wait_for_sync(); in ads7846_read_state()
726 m = &ts->msg[msg_idx]; in ads7846_read_state()
727 error = spi_sync(ts->spi, m); in ads7846_read_state()
729 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
730 packet->tc.ignore = true; in ads7846_read_state()
738 if (msg_idx < ts->msg_count - 1) { in ads7846_read_state()
742 action = ts->filter(ts->filter_data, msg_idx, &val); in ads7846_read_state()
748 packet->tc.ignore = true; in ads7846_read_state()
749 msg_idx = ts->msg_count - 1; in ads7846_read_state()
754 packet->tc.ignore = false; in ads7846_read_state()
769 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
774 * ads7846_get_value() does in-place conversion (including byte swap) in ads7846_report_state()
775 * from on-the-wire format as part of debouncing to get stable in ads7846_report_state()
778 if (ts->model == 7845) { in ads7846_report_state()
779 x = *(u16 *)packet->tc.x_buf; in ads7846_report_state()
780 y = *(u16 *)packet->tc.y_buf; in ads7846_report_state()
784 x = packet->tc.x; in ads7846_report_state()
785 y = packet->tc.y; in ads7846_report_state()
786 z1 = packet->tc.z1; in ads7846_report_state()
787 z2 = packet->tc.z2; in ads7846_report_state()
794 if (ts->model == 7843) { in ads7846_report_state()
795 Rt = ts->pressure_max / 2; in ads7846_report_state()
796 } else if (ts->model == 7845) { in ads7846_report_state()
798 Rt = ts->pressure_max / 2; in ads7846_report_state()
801 dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt); in ads7846_report_state()
805 Rt -= z1; in ads7846_report_state()
806 Rt *= ts->x_plate_ohms; in ads7846_report_state()
820 if (packet->tc.ignore || Rt > ts->pressure_max) { in ads7846_report_state()
821 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
822 packet->tc.ignore, Rt); in ads7846_report_state()
830 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
831 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
846 struct input_dev *input = ts->input; in ads7846_report_state()
848 if (!ts->pendown) { in ads7846_report_state()
850 ts->pendown = true; in ads7846_report_state()
851 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
854 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
855 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
858 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
877 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
882 if (!ts->stopped) in ads7846_irq()
885 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
889 if (ts->pendown && !ts->stopped) in ads7846_irq()
899 mutex_lock(&ts->lock); in ads7846_suspend()
901 if (!ts->suspended) { in ads7846_suspend()
903 if (!ts->disabled) in ads7846_suspend()
906 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
907 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
909 ts->suspended = true; in ads7846_suspend()
912 mutex_unlock(&ts->lock); in ads7846_suspend()
921 mutex_lock(&ts->lock); in ads7846_resume()
923 if (ts->suspended) { in ads7846_resume()
925 ts->suspended = false; in ads7846_resume()
927 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
928 disable_irq_wake(ts->spi->irq); in ads7846_resume()
930 if (!ts->disabled) in ads7846_resume()
934 mutex_unlock(&ts->lock); in ads7846_resume()
948 * REVISIT when the irq can be triggered active-low, or if for some in ads7846_setup_pendown()
953 if (pdata->get_pendown_state) { in ads7846_setup_pendown()
954 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
955 } else if (gpio_is_valid(pdata->gpio_pendown)) { in ads7846_setup_pendown()
957 err = gpio_request_one(pdata->gpio_pendown, GPIOF_IN, in ads7846_setup_pendown()
960 dev_err(&spi->dev, in ads7846_setup_pendown()
962 pdata->gpio_pendown, err); in ads7846_setup_pendown()
966 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
968 if (pdata->gpio_pendown_debounce) in ads7846_setup_pendown()
969 gpio_set_debounce(pdata->gpio_pendown, in ads7846_setup_pendown()
970 pdata->gpio_pendown_debounce); in ads7846_setup_pendown()
972 dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); in ads7846_setup_pendown()
973 return -EINVAL; in ads7846_setup_pendown()
986 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
987 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
988 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
989 int vref = pdata->keep_vref_on; in ads7846_setup_spi_msg() local
991 if (ts->model == 7873) { in ads7846_setup_spi_msg()
994 * keep VREF off during differential/ratiometric in ads7846_setup_spi_msg()
997 ts->model = 7846; in ads7846_setup_spi_msg()
998 vref = 0; in ads7846_setup_spi_msg()
1001 ts->msg_count = 1; in ads7846_setup_spi_msg()
1003 m->context = ts; in ads7846_setup_spi_msg()
1005 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1006 packet->read_y_cmd[0] = READ_Y(vref); in ads7846_setup_spi_msg()
1007 packet->read_y_cmd[1] = 0; in ads7846_setup_spi_msg()
1008 packet->read_y_cmd[2] = 0; in ads7846_setup_spi_msg()
1009 x->tx_buf = &packet->read_y_cmd[0]; in ads7846_setup_spi_msg()
1010 x->rx_buf = &packet->tc.y_buf[0]; in ads7846_setup_spi_msg()
1011 x->len = 3; in ads7846_setup_spi_msg()
1014 /* y- still on; turn on only y+ (and ADC) */ in ads7846_setup_spi_msg()
1015 packet->read_y = READ_Y(vref); in ads7846_setup_spi_msg()
1016 x->tx_buf = &packet->read_y; in ads7846_setup_spi_msg()
1017 x->len = 1; in ads7846_setup_spi_msg()
1021 x->rx_buf = &packet->tc.y; in ads7846_setup_spi_msg()
1022 x->len = 2; in ads7846_setup_spi_msg()
1031 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1032 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1033 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1036 x->tx_buf = &packet->read_y; in ads7846_setup_spi_msg()
1037 x->len = 1; in ads7846_setup_spi_msg()
1041 x->rx_buf = &packet->tc.y; in ads7846_setup_spi_msg()
1042 x->len = 2; in ads7846_setup_spi_msg()
1046 ts->msg_count++; in ads7846_setup_spi_msg()
1049 m->context = ts; in ads7846_setup_spi_msg()
1051 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1053 packet->read_x_cmd[0] = READ_X(vref); in ads7846_setup_spi_msg()
1054 packet->read_x_cmd[1] = 0; in ads7846_setup_spi_msg()
1055 packet->read_x_cmd[2] = 0; in ads7846_setup_spi_msg()
1056 x->tx_buf = &packet->read_x_cmd[0]; in ads7846_setup_spi_msg()
1057 x->rx_buf = &packet->tc.x_buf[0]; in ads7846_setup_spi_msg()
1058 x->len = 3; in ads7846_setup_spi_msg()
1061 /* turn y- off, x+ on, then leave in lowpower */ in ads7846_setup_spi_msg()
1063 packet->read_x = READ_X(vref); in ads7846_setup_spi_msg()
1064 x->tx_buf = &packet->read_x; in ads7846_setup_spi_msg()
1065 x->len = 1; in ads7846_setup_spi_msg()
1069 x->rx_buf = &packet->tc.x; in ads7846_setup_spi_msg()
1070 x->len = 2; in ads7846_setup_spi_msg()
1075 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1076 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1077 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1080 x->tx_buf = &packet->read_x; in ads7846_setup_spi_msg()
1081 x->len = 1; in ads7846_setup_spi_msg()
1085 x->rx_buf = &packet->tc.x; in ads7846_setup_spi_msg()
1086 x->len = 2; in ads7846_setup_spi_msg()
1090 /* turn y+ off, x- on; we'll use formula #2 */ in ads7846_setup_spi_msg()
1091 if (ts->model == 7846) { in ads7846_setup_spi_msg()
1092 ts->msg_count++; in ads7846_setup_spi_msg()
1095 m->context = ts; in ads7846_setup_spi_msg()
1098 packet->read_z1 = READ_Z1(vref); in ads7846_setup_spi_msg()
1099 x->tx_buf = &packet->read_z1; in ads7846_setup_spi_msg()
1100 x->len = 1; in ads7846_setup_spi_msg()
1104 x->rx_buf = &packet->tc.z1; in ads7846_setup_spi_msg()
1105 x->len = 2; in ads7846_setup_spi_msg()
1109 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1110 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1111 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1114 x->tx_buf = &packet->read_z1; in ads7846_setup_spi_msg()
1115 x->len = 1; in ads7846_setup_spi_msg()
1119 x->rx_buf = &packet->tc.z1; in ads7846_setup_spi_msg()
1120 x->len = 2; in ads7846_setup_spi_msg()
1124 ts->msg_count++; in ads7846_setup_spi_msg()
1127 m->context = ts; in ads7846_setup_spi_msg()
1130 packet->read_z2 = READ_Z2(vref); in ads7846_setup_spi_msg()
1131 x->tx_buf = &packet->read_z2; in ads7846_setup_spi_msg()
1132 x->len = 1; in ads7846_setup_spi_msg()
1136 x->rx_buf = &packet->tc.z2; in ads7846_setup_spi_msg()
1137 x->len = 2; in ads7846_setup_spi_msg()
1141 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1142 x->delay.value = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1143 x->delay.unit = SPI_DELAY_UNIT_USECS; in ads7846_setup_spi_msg()
1146 x->tx_buf = &packet->read_z2; in ads7846_setup_spi_msg()
1147 x->len = 1; in ads7846_setup_spi_msg()
1151 x->rx_buf = &packet->tc.z2; in ads7846_setup_spi_msg()
1152 x->len = 2; in ads7846_setup_spi_msg()
1158 ts->msg_count++; in ads7846_setup_spi_msg()
1161 m->context = ts; in ads7846_setup_spi_msg()
1163 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1165 packet->pwrdown_cmd[0] = PWRDOWN; in ads7846_setup_spi_msg()
1166 packet->pwrdown_cmd[1] = 0; in ads7846_setup_spi_msg()
1167 packet->pwrdown_cmd[2] = 0; in ads7846_setup_spi_msg()
1168 x->tx_buf = &packet->pwrdown_cmd[0]; in ads7846_setup_spi_msg()
1169 x->len = 3; in ads7846_setup_spi_msg()
1172 packet->pwrdown = PWRDOWN; in ads7846_setup_spi_msg()
1173 x->tx_buf = &packet->pwrdown; in ads7846_setup_spi_msg()
1174 x->len = 1; in ads7846_setup_spi_msg()
1178 x->rx_buf = &packet->dummy; in ads7846_setup_spi_msg()
1179 x->len = 2; in ads7846_setup_spi_msg()
1200 struct device_node *node = dev->of_node; in ads7846_probe_dt()
1206 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1212 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1217 return ERR_PTR(-ENOMEM); in ads7846_probe_dt()
1219 pdata->model = (unsigned long)match->data; in ads7846_probe_dt()
1221 of_property_read_u16(node, "ti,vref-delay-usecs", in ads7846_probe_dt()
1222 &pdata->vref_delay_usecs); in ads7846_probe_dt()
1223 of_property_read_u16(node, "ti,vref-mv", &pdata->vref_mv); in ads7846_probe_dt()
1224 pdata->keep_vref_on = of_property_read_bool(node, "ti,keep-vref-on"); in ads7846_probe_dt()
1226 pdata->swap_xy = of_property_read_bool(node, "ti,swap-xy"); in ads7846_probe_dt()
1228 of_property_read_u16(node, "ti,settle-delay-usec", in ads7846_probe_dt()
1229 &pdata->settle_delay_usecs); in ads7846_probe_dt()
1230 of_property_read_u16(node, "ti,penirq-recheck-delay-usecs", in ads7846_probe_dt()
1231 &pdata->penirq_recheck_delay_usecs); in ads7846_probe_dt()
1233 of_property_read_u16(node, "ti,x-plate-ohms", &pdata->x_plate_ohms); in ads7846_probe_dt()
1234 of_property_read_u16(node, "ti,y-plate-ohms", &pdata->y_plate_ohms); in ads7846_probe_dt()
1236 of_property_read_u16(node, "ti,x-min", &pdata->x_min); in ads7846_probe_dt()
1237 of_property_read_u16(node, "ti,y-min", &pdata->y_min); in ads7846_probe_dt()
1238 of_property_read_u16(node, "ti,x-max", &pdata->x_max); in ads7846_probe_dt()
1239 of_property_read_u16(node, "ti,y-max", &pdata->y_max); in ads7846_probe_dt()
1242 * touchscreen-max-pressure gets parsed during in ads7846_probe_dt()
1245 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min); in ads7846_probe_dt()
1246 if (!of_property_read_u32(node, "touchscreen-min-pressure", &value)) in ads7846_probe_dt()
1247 pdata->pressure_min = (u16) value; in ads7846_probe_dt()
1248 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); in ads7846_probe_dt()
1250 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max); in ads7846_probe_dt()
1251 if (!of_property_read_u32(node, "touchscreen-average-samples", &value)) in ads7846_probe_dt()
1252 pdata->debounce_max = (u16) value; in ads7846_probe_dt()
1253 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); in ads7846_probe_dt()
1254 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); in ads7846_probe_dt()
1256 of_property_read_u32(node, "ti,pendown-gpio-debounce", in ads7846_probe_dt()
1257 &pdata->gpio_pendown_debounce); in ads7846_probe_dt()
1259 pdata->wakeup = of_property_read_bool(node, "wakeup-source") || in ads7846_probe_dt()
1262 pdata->gpio_pendown = of_get_named_gpio(dev->of_node, "pendown-gpio", 0); in ads7846_probe_dt()
1270 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1283 if (!spi->irq) { in ads7846_probe()
1284 dev_dbg(&spi->dev, "no IRQ?\n"); in ads7846_probe()
1285 return -EINVAL; in ads7846_probe()
1289 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { in ads7846_probe()
1290 dev_err(&spi->dev, "f(sample) %d KHz?\n", in ads7846_probe()
1291 (spi->max_speed_hz/SAMPLE_BITS)/1000); in ads7846_probe()
1292 return -EINVAL; in ads7846_probe()
1298 * may not. So we stick to very-portable 8 bit words, both RX and TX. in ads7846_probe()
1300 spi->bits_per_word = 8; in ads7846_probe()
1301 spi->mode = SPI_MODE_0; in ads7846_probe()
1310 err = -ENOMEM; in ads7846_probe()
1316 ts->packet = packet; in ads7846_probe()
1317 ts->spi = spi; in ads7846_probe()
1318 ts->input = input_dev; in ads7846_probe()
1320 mutex_init(&ts->lock); in ads7846_probe()
1321 init_waitqueue_head(&ts->wait); in ads7846_probe()
1323 pdata = dev_get_platdata(&spi->dev); in ads7846_probe()
1325 pdata = ads7846_probe_dt(&spi->dev); in ads7846_probe()
1332 ts->model = pdata->model ? : 7846; in ads7846_probe()
1333 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1334 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1335 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1337 if (pdata->filter != NULL) { in ads7846_probe()
1338 if (pdata->filter_init != NULL) { in ads7846_probe()
1339 err = pdata->filter_init(pdata, &ts->filter_data); in ads7846_probe()
1343 ts->filter = pdata->filter; in ads7846_probe()
1344 ts->filter_cleanup = pdata->filter_cleanup; in ads7846_probe()
1345 } else if (pdata->debounce_max) { in ads7846_probe()
1346 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1347 if (ts->debounce_max < 2) in ads7846_probe()
1348 ts->debounce_max = 2; in ads7846_probe()
1349 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1350 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1351 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1352 ts->filter_data = ts; in ads7846_probe()
1354 ts->filter = ads7846_no_filter; in ads7846_probe()
1361 if (pdata->penirq_recheck_delay_usecs) in ads7846_probe()
1362 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1363 pdata->penirq_recheck_delay_usecs; in ads7846_probe()
1365 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1367 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); in ads7846_probe()
1368 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1370 input_dev->name = ts->name; in ads7846_probe()
1371 input_dev->phys = ts->phys; in ads7846_probe()
1372 input_dev->dev.parent = &spi->dev; in ads7846_probe()
1374 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in ads7846_probe()
1375 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); in ads7846_probe()
1377 pdata->x_min ? : 0, in ads7846_probe()
1378 pdata->x_max ? : MAX_12BIT, in ads7846_probe()
1381 pdata->y_min ? : 0, in ads7846_probe()
1382 pdata->y_max ? : MAX_12BIT, in ads7846_probe()
1385 pdata->pressure_min, pdata->pressure_max, 0, 0); in ads7846_probe()
1392 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1393 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1396 * Check if legacy ti,swap-xy binding is used instead of in ads7846_probe()
1397 * touchscreen-swapped-x-y in ads7846_probe()
1399 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1400 swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]); in ads7846_probe()
1401 ts->core_prop.swap_x_y = true; in ads7846_probe()
1406 ts->reg = regulator_get(&spi->dev, "vcc"); in ads7846_probe()
1407 if (IS_ERR(ts->reg)) { in ads7846_probe()
1408 err = PTR_ERR(ts->reg); in ads7846_probe()
1409 dev_err(&spi->dev, "unable to get regulator: %d\n", err); in ads7846_probe()
1413 err = regulator_enable(ts->reg); in ads7846_probe()
1415 dev_err(&spi->dev, "unable to enable regulator: %d\n", err); in ads7846_probe()
1419 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; in ads7846_probe()
1422 err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, in ads7846_probe()
1423 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1424 if (err && !pdata->irq_flags) { in ads7846_probe()
1425 dev_info(&spi->dev, in ads7846_probe()
1426 "trying pin change workaround on irq %d\n", spi->irq); in ads7846_probe()
1428 err = request_threaded_irq(spi->irq, in ads7846_probe()
1430 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1434 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); in ads7846_probe()
1442 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); in ads7846_probe()
1445 * Take a first sample, leaving nPENIRQ active and vREF off; avoid in ads7846_probe()
1448 if (ts->model == 7845) in ads7846_probe()
1449 ads7845_read12_ser(&spi->dev, PWRDOWN); in ads7846_probe()
1451 (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux)); in ads7846_probe()
1453 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1461 device_init_wakeup(&spi->dev, pdata->wakeup); in ads7846_probe()
1467 if (!dev_get_platdata(&spi->dev)) in ads7846_probe()
1468 devm_kfree(&spi->dev, (void *)pdata); in ads7846_probe()
1473 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1477 free_irq(spi->irq, ts); in ads7846_probe()
1479 regulator_disable(ts->reg); in ads7846_probe()
1481 regulator_put(ts->reg); in ads7846_probe()
1483 if (!ts->get_pendown_state) in ads7846_probe()
1484 gpio_free(ts->gpio_pendown); in ads7846_probe()
1486 if (ts->filter_cleanup) in ads7846_probe()
1487 ts->filter_cleanup(ts->filter_data); in ads7846_probe()
1499 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_remove()
1502 free_irq(ts->spi->irq, ts); in ads7846_remove()
1504 input_unregister_device(ts->input); in ads7846_remove()
1508 regulator_put(ts->reg); in ads7846_remove()
1510 if (!ts->get_pendown_state) { in ads7846_remove()
1515 gpio_free(ts->gpio_pendown); in ads7846_remove()
1518 if (ts->filter_cleanup) in ads7846_remove()
1519 ts->filter_cleanup(ts->filter_data); in ads7846_remove()
1521 kfree(ts->packet); in ads7846_remove()
1524 dev_dbg(&spi->dev, "unregistered touchscreen\n"); in ads7846_remove()