Lines Matching +full:vref +full:- +full:source
9 * - corgi_ts.c
10 * Copyright (C) 2004-2005 Richard Purdie
11 * - omap_ts.[hc], ads7846.h, ts_osk.c
43 * Support for ads7843 tested on Atmel at91sam926x-EK.
57 * note. The strength of filtering can be set in the board-* specific
71 * with msbs zeroed). Instead, we read them as two 8-bit values,
84 * driver is used with DMA-based SPI controllers (like atmel_spi) on
85 * systems where main memory is not DMA-coherent (most non-x86 boards).
91 /* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
149 /* leave chip selected when we're done, for quicker re-select? */
156 /*--------------------------------------------------------------------------*/
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 */
176 #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */
177 #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
179 #define MAX_12BIT ((1<<12)-1)
182 #define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \ argument
184 (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0))
186 #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref)) argument
187 #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref)) argument
188 #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref)) argument
190 #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref)) argument
193 /* single-ended samples need to first power up reference voltage;
194 * we leave both ADC and VREF powered
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.
283 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
284 * ads7846 lets that pin be unconnected, to use internal vREF.
321 return -ENOMEM; in ads7846_read12_ser()
323 spi_message_init(&req->msg); in ads7846_read12_ser()
325 /* maybe turn on internal vREF, and let it settle */ 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_usecs = ts->vref_delay_usecs; in ads7846_read12_ser()
337 spi_message_add_tail(&req->xfer[1], &req->msg); in ads7846_read12_ser()
347 req->command = (u8) command; in ads7846_read12_ser()
348 req->xfer[2].tx_buf = &req->command; in ads7846_read12_ser()
349 req->xfer[2].len = 1; in ads7846_read12_ser()
350 spi_message_add_tail(&req->xfer[2], &req->msg); in ads7846_read12_ser()
352 req->xfer[3].rx_buf = &req->sample; in ads7846_read12_ser()
353 req->xfer[3].len = 2; in ads7846_read12_ser()
354 spi_message_add_tail(&req->xfer[3], &req->msg); in ads7846_read12_ser()
359 req->ref_off = PWRDOWN; in ads7846_read12_ser()
360 req->xfer[4].tx_buf = &req->ref_off; in ads7846_read12_ser()
361 req->xfer[4].len = 1; in ads7846_read12_ser()
362 spi_message_add_tail(&req->xfer[4], &req->msg); in ads7846_read12_ser()
364 req->xfer[5].rx_buf = &req->scratch; in ads7846_read12_ser()
365 req->xfer[5].len = 2; in ads7846_read12_ser()
366 CS_CHANGE(req->xfer[5]); in ads7846_read12_ser()
367 spi_message_add_tail(&req->xfer[5], &req->msg); in ads7846_read12_ser()
369 mutex_lock(&ts->lock); in ads7846_read12_ser()
371 status = spi_sync(spi, &req->msg); in ads7846_read12_ser()
373 mutex_unlock(&ts->lock); in ads7846_read12_ser()
376 /* on-wire is a must-ignore bit, a BE12 value, then padding */ in ads7846_read12_ser()
377 status = be16_to_cpu(req->sample); in ads7846_read12_ser()
395 return -ENOMEM; in ads7845_read12_ser()
397 spi_message_init(&req->msg); in ads7845_read12_ser()
399 req->command[0] = (u8) command; in ads7845_read12_ser()
400 req->xfer[0].tx_buf = req->command; in ads7845_read12_ser()
401 req->xfer[0].rx_buf = req->sample; in ads7845_read12_ser()
402 req->xfer[0].len = 3; in ads7845_read12_ser()
403 spi_message_add_tail(&req->xfer[0], &req->msg); in ads7845_read12_ser()
405 mutex_lock(&ts->lock); in ads7845_read12_ser()
407 status = spi_sync(spi, &req->msg); in ads7845_read12_ser()
409 mutex_unlock(&ts->lock); in ads7845_read12_ser()
413 status = be16_to_cpu(*((u16 *)&req->sample[1])); in ads7845_read12_ser()
428 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
438 * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high
452 * if we know vREF. userspace may need to scale vAUX to match the board's in SHOW()
459 /* external resistors may scale vAUX into 0..vREF */ in SHOW()
460 retval *= ts->vref_mv; in SHOW()
471 if (ts->model == 7846) in vbatt_adjust()
486 if (ts->model == 7843 && index < 2) /* in0, in1 */ in SHOW()
488 if (ts->model == 7845 && index != 2) /* in0 */ in SHOW()
491 return attr->mode; in SHOW()
511 switch (ts->model) { in ads784x_hwmon_register()
513 if (!ts->vref_mv) { in ads784x_hwmon_register()
514 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); in ads784x_hwmon_register()
515 ts->vref_mv = 2500; in ads784x_hwmon_register()
516 ts->use_internal = true; in ads784x_hwmon_register()
521 if (!ts->vref_mv) { in ads784x_hwmon_register()
522 dev_warn(&spi->dev, in ads784x_hwmon_register()
523 "external vREF for ADS%d not specified\n", in ads784x_hwmon_register()
524 ts->model); in ads784x_hwmon_register()
530 ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, in ads784x_hwmon_register()
533 return PTR_ERR_OR_ZERO(ts->hwmon); in ads784x_hwmon_register()
539 if (ts->hwmon) in ads784x_hwmon_unregister()
540 hwmon_device_unregister(ts->hwmon); in ads784x_hwmon_unregister()
561 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
571 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
606 /*--------------------------------------------------------------------------*/
610 if (ts->get_pendown_state) in get_pendown_state()
611 return ts->get_pendown_state(); in get_pendown_state()
613 return !gpio_get_value(ts->gpio_pendown); in get_pendown_state()
624 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
626 ts->read_rep = 0; in ads7846_debounce_filter()
631 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
632 ts->last_read = *val; in ads7846_debounce_filter()
633 ts->read_cnt++; in ads7846_debounce_filter()
642 ts->read_cnt = 0; in ads7846_debounce_filter()
646 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
651 ts->read_cnt = 0; in ads7846_debounce_filter()
652 ts->read_rep = 0; in ads7846_debounce_filter()
656 ts->read_cnt++; in ads7846_debounce_filter()
671 list_entry(m->transfers.prev, struct spi_transfer, transfer_list); in ads7846_get_value()
673 if (ts->model == 7845) { in ads7846_get_value()
674 value = be16_to_cpup((__be16 *)&(((char *)t->rx_buf)[1])); in ads7846_get_value()
677 * adjust: on-wire is a must-ignore bit, a BE12 value, then in ads7846_get_value()
678 * padding; built from two 8 bit values written msb-first. in ads7846_get_value()
680 value = be16_to_cpup((__be16 *)t->rx_buf); in ads7846_get_value()
690 list_entry(m->transfers.prev, struct spi_transfer, transfer_list); in ads7846_update_value()
692 *(u16 *)t->rx_buf = val; in ads7846_update_value()
697 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
704 while (msg_idx < ts->msg_count) { in ads7846_read_state()
706 ts->wait_for_sync(); in ads7846_read_state()
708 m = &ts->msg[msg_idx]; in ads7846_read_state()
709 error = spi_sync(ts->spi, m); in ads7846_read_state()
711 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
712 packet->tc.ignore = true; in ads7846_read_state()
720 if (msg_idx < ts->msg_count - 1) { in ads7846_read_state()
724 action = ts->filter(ts->filter_data, msg_idx, &val); in ads7846_read_state()
730 packet->tc.ignore = true; in ads7846_read_state()
731 msg_idx = ts->msg_count - 1; in ads7846_read_state()
736 packet->tc.ignore = false; in ads7846_read_state()
751 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
756 * ads7846_get_value() does in-place conversion (including byte swap) in ads7846_report_state()
757 * from on-the-wire format as part of debouncing to get stable in ads7846_report_state()
760 if (ts->model == 7845) { in ads7846_report_state()
761 x = *(u16 *)packet->tc.x_buf; in ads7846_report_state()
762 y = *(u16 *)packet->tc.y_buf; in ads7846_report_state()
766 x = packet->tc.x; in ads7846_report_state()
767 y = packet->tc.y; in ads7846_report_state()
768 z1 = packet->tc.z1; in ads7846_report_state()
769 z2 = packet->tc.z2; in ads7846_report_state()
776 if (ts->model == 7843) { in ads7846_report_state()
777 Rt = ts->pressure_max / 2; in ads7846_report_state()
778 } else if (ts->model == 7845) { in ads7846_report_state()
780 Rt = ts->pressure_max / 2; in ads7846_report_state()
783 dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt); in ads7846_report_state()
787 Rt -= z1; in ads7846_report_state()
789 Rt *= ts->x_plate_ohms; in ads7846_report_state()
801 if (packet->tc.ignore || Rt > ts->pressure_max) { in ads7846_report_state()
802 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
803 packet->tc.ignore, Rt); in ads7846_report_state()
811 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
812 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
827 struct input_dev *input = ts->input; in ads7846_report_state()
829 if (ts->swap_xy) in ads7846_report_state()
832 if (!ts->pendown) { in ads7846_report_state()
834 ts->pendown = true; in ads7846_report_state()
835 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
840 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
843 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
862 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
867 if (!ts->stopped) in ads7846_irq()
870 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
874 if (ts->pendown && !ts->stopped) { in ads7846_irq()
875 struct input_dev *input = ts->input; in ads7846_irq()
881 ts->pendown = false; in ads7846_irq()
882 dev_vdbg(&ts->spi->dev, "UP\n"); in ads7846_irq()
892 mutex_lock(&ts->lock); in ads7846_suspend()
894 if (!ts->suspended) { in ads7846_suspend()
896 if (!ts->disabled) in ads7846_suspend()
899 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
900 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
902 ts->suspended = true; in ads7846_suspend()
905 mutex_unlock(&ts->lock); in ads7846_suspend()
914 mutex_lock(&ts->lock); in ads7846_resume()
916 if (ts->suspended) { in ads7846_resume()
918 ts->suspended = false; in ads7846_resume()
920 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
921 disable_irq_wake(ts->spi->irq); in ads7846_resume()
923 if (!ts->disabled) in ads7846_resume()
927 mutex_unlock(&ts->lock); in ads7846_resume()
941 * REVISIT when the irq can be triggered active-low, or if for some in ads7846_setup_pendown()
946 if (pdata->get_pendown_state) { in ads7846_setup_pendown()
947 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
948 } else if (gpio_is_valid(pdata->gpio_pendown)) { in ads7846_setup_pendown()
950 err = gpio_request_one(pdata->gpio_pendown, GPIOF_IN, in ads7846_setup_pendown()
953 dev_err(&spi->dev, in ads7846_setup_pendown()
955 pdata->gpio_pendown, err); in ads7846_setup_pendown()
959 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
961 if (pdata->gpio_pendown_debounce) in ads7846_setup_pendown()
962 gpio_set_debounce(pdata->gpio_pendown, in ads7846_setup_pendown()
963 pdata->gpio_pendown_debounce); in ads7846_setup_pendown()
965 dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); in ads7846_setup_pendown()
966 return -EINVAL; in ads7846_setup_pendown()
979 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
980 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
981 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
982 int vref = pdata->keep_vref_on; in ads7846_setup_spi_msg() local
984 if (ts->model == 7873) { in ads7846_setup_spi_msg()
987 * keep VREF off during differential/ratiometric in ads7846_setup_spi_msg()
990 ts->model = 7846; in ads7846_setup_spi_msg()
991 vref = 0; in ads7846_setup_spi_msg()
994 ts->msg_count = 1; in ads7846_setup_spi_msg()
996 m->context = ts; in ads7846_setup_spi_msg()
998 if (ts->model == 7845) { in ads7846_setup_spi_msg()
999 packet->read_y_cmd[0] = READ_Y(vref); in ads7846_setup_spi_msg()
1000 packet->read_y_cmd[1] = 0; in ads7846_setup_spi_msg()
1001 packet->read_y_cmd[2] = 0; in ads7846_setup_spi_msg()
1002 x->tx_buf = &packet->read_y_cmd[0]; in ads7846_setup_spi_msg()
1003 x->rx_buf = &packet->tc.y_buf[0]; in ads7846_setup_spi_msg()
1004 x->len = 3; in ads7846_setup_spi_msg()
1007 /* y- still on; turn on only y+ (and ADC) */ in ads7846_setup_spi_msg()
1008 packet->read_y = READ_Y(vref); in ads7846_setup_spi_msg()
1009 x->tx_buf = &packet->read_y; in ads7846_setup_spi_msg()
1010 x->len = 1; in ads7846_setup_spi_msg()
1014 x->rx_buf = &packet->tc.y; in ads7846_setup_spi_msg()
1015 x->len = 2; in ads7846_setup_spi_msg()
1024 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1025 x->delay_usecs = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1028 x->tx_buf = &packet->read_y; in ads7846_setup_spi_msg()
1029 x->len = 1; in ads7846_setup_spi_msg()
1033 x->rx_buf = &packet->tc.y; in ads7846_setup_spi_msg()
1034 x->len = 2; in ads7846_setup_spi_msg()
1038 ts->msg_count++; in ads7846_setup_spi_msg()
1041 m->context = ts; in ads7846_setup_spi_msg()
1043 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1045 packet->read_x_cmd[0] = READ_X(vref); in ads7846_setup_spi_msg()
1046 packet->read_x_cmd[1] = 0; in ads7846_setup_spi_msg()
1047 packet->read_x_cmd[2] = 0; in ads7846_setup_spi_msg()
1048 x->tx_buf = &packet->read_x_cmd[0]; in ads7846_setup_spi_msg()
1049 x->rx_buf = &packet->tc.x_buf[0]; in ads7846_setup_spi_msg()
1050 x->len = 3; in ads7846_setup_spi_msg()
1053 /* turn y- off, x+ on, then leave in lowpower */ in ads7846_setup_spi_msg()
1055 packet->read_x = READ_X(vref); in ads7846_setup_spi_msg()
1056 x->tx_buf = &packet->read_x; in ads7846_setup_spi_msg()
1057 x->len = 1; in ads7846_setup_spi_msg()
1061 x->rx_buf = &packet->tc.x; in ads7846_setup_spi_msg()
1062 x->len = 2; in ads7846_setup_spi_msg()
1067 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1068 x->delay_usecs = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1071 x->tx_buf = &packet->read_x; in ads7846_setup_spi_msg()
1072 x->len = 1; in ads7846_setup_spi_msg()
1076 x->rx_buf = &packet->tc.x; in ads7846_setup_spi_msg()
1077 x->len = 2; in ads7846_setup_spi_msg()
1081 /* turn y+ off, x- on; we'll use formula #2 */ in ads7846_setup_spi_msg()
1082 if (ts->model == 7846) { in ads7846_setup_spi_msg()
1083 ts->msg_count++; in ads7846_setup_spi_msg()
1086 m->context = ts; in ads7846_setup_spi_msg()
1089 packet->read_z1 = READ_Z1(vref); in ads7846_setup_spi_msg()
1090 x->tx_buf = &packet->read_z1; in ads7846_setup_spi_msg()
1091 x->len = 1; in ads7846_setup_spi_msg()
1095 x->rx_buf = &packet->tc.z1; in ads7846_setup_spi_msg()
1096 x->len = 2; in ads7846_setup_spi_msg()
1100 if (pdata->settle_delay_usecs) { in ads7846_setup_spi_msg()
1101 x->delay_usecs = pdata->settle_delay_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_usecs = pdata->settle_delay_usecs; in ads7846_setup_spi_msg()
1135 x->tx_buf = &packet->read_z2; in ads7846_setup_spi_msg()
1136 x->len = 1; in ads7846_setup_spi_msg()
1140 x->rx_buf = &packet->tc.z2; in ads7846_setup_spi_msg()
1141 x->len = 2; in ads7846_setup_spi_msg()
1147 ts->msg_count++; in ads7846_setup_spi_msg()
1150 m->context = ts; in ads7846_setup_spi_msg()
1152 if (ts->model == 7845) { in ads7846_setup_spi_msg()
1154 packet->pwrdown_cmd[0] = PWRDOWN; in ads7846_setup_spi_msg()
1155 packet->pwrdown_cmd[1] = 0; in ads7846_setup_spi_msg()
1156 packet->pwrdown_cmd[2] = 0; in ads7846_setup_spi_msg()
1157 x->tx_buf = &packet->pwrdown_cmd[0]; in ads7846_setup_spi_msg()
1158 x->len = 3; in ads7846_setup_spi_msg()
1161 packet->pwrdown = PWRDOWN; in ads7846_setup_spi_msg()
1162 x->tx_buf = &packet->pwrdown; in ads7846_setup_spi_msg()
1163 x->len = 1; in ads7846_setup_spi_msg()
1167 x->rx_buf = &packet->dummy; in ads7846_setup_spi_msg()
1168 x->len = 2; in ads7846_setup_spi_msg()
1189 struct device_node *node = dev->of_node; in ads7846_probe_dt()
1194 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1200 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1205 return ERR_PTR(-ENOMEM); in ads7846_probe_dt()
1207 pdata->model = (unsigned long)match->data; in ads7846_probe_dt()
1209 of_property_read_u16(node, "ti,vref-delay-usecs", in ads7846_probe_dt()
1210 &pdata->vref_delay_usecs); in ads7846_probe_dt()
1211 of_property_read_u16(node, "ti,vref-mv", &pdata->vref_mv); in ads7846_probe_dt()
1212 pdata->keep_vref_on = of_property_read_bool(node, "ti,keep-vref-on"); in ads7846_probe_dt()
1214 pdata->swap_xy = of_property_read_bool(node, "ti,swap-xy"); in ads7846_probe_dt()
1216 of_property_read_u16(node, "ti,settle-delay-usec", in ads7846_probe_dt()
1217 &pdata->settle_delay_usecs); in ads7846_probe_dt()
1218 of_property_read_u16(node, "ti,penirq-recheck-delay-usecs", in ads7846_probe_dt()
1219 &pdata->penirq_recheck_delay_usecs); in ads7846_probe_dt()
1221 of_property_read_u16(node, "ti,x-plate-ohms", &pdata->x_plate_ohms); in ads7846_probe_dt()
1222 of_property_read_u16(node, "ti,y-plate-ohms", &pdata->y_plate_ohms); in ads7846_probe_dt()
1224 of_property_read_u16(node, "ti,x-min", &pdata->x_min); in ads7846_probe_dt()
1225 of_property_read_u16(node, "ti,y-min", &pdata->y_min); in ads7846_probe_dt()
1226 of_property_read_u16(node, "ti,x-max", &pdata->x_max); in ads7846_probe_dt()
1227 of_property_read_u16(node, "ti,y-max", &pdata->y_max); in ads7846_probe_dt()
1229 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min); in ads7846_probe_dt()
1230 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); in ads7846_probe_dt()
1232 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max); in ads7846_probe_dt()
1233 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); in ads7846_probe_dt()
1234 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); in ads7846_probe_dt()
1236 of_property_read_u32(node, "ti,pendown-gpio-debounce", in ads7846_probe_dt()
1237 &pdata->gpio_pendown_debounce); in ads7846_probe_dt()
1239 pdata->wakeup = of_property_read_bool(node, "wakeup-source") || in ads7846_probe_dt()
1242 pdata->gpio_pendown = of_get_named_gpio(dev->of_node, "pendown-gpio", 0); in ads7846_probe_dt()
1250 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1263 if (!spi->irq) { in ads7846_probe()
1264 dev_dbg(&spi->dev, "no IRQ?\n"); in ads7846_probe()
1265 return -EINVAL; in ads7846_probe()
1269 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { in ads7846_probe()
1270 dev_err(&spi->dev, "f(sample) %d KHz?\n", in ads7846_probe()
1271 (spi->max_speed_hz/SAMPLE_BITS)/1000); in ads7846_probe()
1272 return -EINVAL; in ads7846_probe()
1278 * may not. So we stick to very-portable 8 bit words, both RX and TX. in ads7846_probe()
1280 spi->bits_per_word = 8; in ads7846_probe()
1281 spi->mode = SPI_MODE_0; in ads7846_probe()
1290 err = -ENOMEM; in ads7846_probe()
1296 ts->packet = packet; in ads7846_probe()
1297 ts->spi = spi; in ads7846_probe()
1298 ts->input = input_dev; in ads7846_probe()
1300 mutex_init(&ts->lock); in ads7846_probe()
1301 init_waitqueue_head(&ts->wait); in ads7846_probe()
1303 pdata = dev_get_platdata(&spi->dev); in ads7846_probe()
1305 pdata = ads7846_probe_dt(&spi->dev); in ads7846_probe()
1312 ts->model = pdata->model ? : 7846; in ads7846_probe()
1313 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1314 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1315 ts->pressure_max = pdata->pressure_max ? : ~0; in ads7846_probe()
1317 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1318 ts->swap_xy = pdata->swap_xy; in ads7846_probe()
1320 if (pdata->filter != NULL) { in ads7846_probe()
1321 if (pdata->filter_init != NULL) { in ads7846_probe()
1322 err = pdata->filter_init(pdata, &ts->filter_data); in ads7846_probe()
1326 ts->filter = pdata->filter; in ads7846_probe()
1327 ts->filter_cleanup = pdata->filter_cleanup; in ads7846_probe()
1328 } else if (pdata->debounce_max) { in ads7846_probe()
1329 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1330 if (ts->debounce_max < 2) in ads7846_probe()
1331 ts->debounce_max = 2; in ads7846_probe()
1332 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1333 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1334 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1335 ts->filter_data = ts; in ads7846_probe()
1337 ts->filter = ads7846_no_filter; in ads7846_probe()
1344 if (pdata->penirq_recheck_delay_usecs) in ads7846_probe()
1345 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1346 pdata->penirq_recheck_delay_usecs; in ads7846_probe()
1348 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1350 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev)); in ads7846_probe()
1351 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1353 input_dev->name = ts->name; in ads7846_probe()
1354 input_dev->phys = ts->phys; in ads7846_probe()
1355 input_dev->dev.parent = &spi->dev; in ads7846_probe()
1357 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in ads7846_probe()
1358 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); in ads7846_probe()
1360 pdata->x_min ? : 0, in ads7846_probe()
1361 pdata->x_max ? : MAX_12BIT, in ads7846_probe()
1364 pdata->y_min ? : 0, in ads7846_probe()
1365 pdata->y_max ? : MAX_12BIT, in ads7846_probe()
1368 pdata->pressure_min, pdata->pressure_max, 0, 0); in ads7846_probe()
1372 ts->reg = regulator_get(&spi->dev, "vcc"); in ads7846_probe()
1373 if (IS_ERR(ts->reg)) { in ads7846_probe()
1374 err = PTR_ERR(ts->reg); in ads7846_probe()
1375 dev_err(&spi->dev, "unable to get regulator: %d\n", err); in ads7846_probe()
1379 err = regulator_enable(ts->reg); in ads7846_probe()
1381 dev_err(&spi->dev, "unable to enable regulator: %d\n", err); in ads7846_probe()
1385 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; in ads7846_probe()
1388 err = request_threaded_irq(spi->irq, ads7846_hard_irq, ads7846_irq, in ads7846_probe()
1389 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1390 if (err && !pdata->irq_flags) { in ads7846_probe()
1391 dev_info(&spi->dev, in ads7846_probe()
1392 "trying pin change workaround on irq %d\n", spi->irq); in ads7846_probe()
1394 err = request_threaded_irq(spi->irq, in ads7846_probe()
1396 irq_flags, spi->dev.driver->name, ts); in ads7846_probe()
1400 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); in ads7846_probe()
1408 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); in ads7846_probe()
1411 * Take a first sample, leaving nPENIRQ active and vREF off; avoid in ads7846_probe()
1414 if (ts->model == 7845) in ads7846_probe()
1415 ads7845_read12_ser(&spi->dev, PWRDOWN); in ads7846_probe()
1417 (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux)); in ads7846_probe()
1419 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1427 device_init_wakeup(&spi->dev, pdata->wakeup); in ads7846_probe()
1433 if (!dev_get_platdata(&spi->dev)) in ads7846_probe()
1434 devm_kfree(&spi->dev, (void *)pdata); in ads7846_probe()
1439 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_probe()
1443 free_irq(spi->irq, ts); in ads7846_probe()
1445 regulator_disable(ts->reg); in ads7846_probe()
1447 regulator_put(ts->reg); in ads7846_probe()
1449 if (!ts->get_pendown_state) in ads7846_probe()
1450 gpio_free(ts->gpio_pendown); in ads7846_probe()
1452 if (ts->filter_cleanup) in ads7846_probe()
1453 ts->filter_cleanup(ts->filter_data); in ads7846_probe()
1465 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group); in ads7846_remove()
1468 free_irq(ts->spi->irq, ts); in ads7846_remove()
1470 input_unregister_device(ts->input); in ads7846_remove()
1474 regulator_put(ts->reg); in ads7846_remove()
1476 if (!ts->get_pendown_state) { in ads7846_remove()
1481 gpio_free(ts->gpio_pendown); in ads7846_remove()
1484 if (ts->filter_cleanup) in ads7846_remove()
1485 ts->filter_cleanup(ts->filter_data); in ads7846_remove()
1487 kfree(ts->packet); in ads7846_remove()
1490 dev_dbg(&spi->dev, "unregistered touchscreen\n"); in ads7846_remove()