Lines Matching +full:vref +full:- +full:n +full:- +full:supply
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
41 * Support for ads7843 tested on Atmel at91sam926x-EK.
55 * note. The strength of filtering can be set in the board-* specific
78 * driver is used with DMA-based SPI controllers (like atmel_spi) on
79 * systems where main memory is not DMA-coherent (most non-x86 boards).
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 */
180 #define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */
181 #define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */
183 #define MAX_12BIT ((1<<12)-1)
186 #define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \ argument
188 (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0))
190 #define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref)) argument
191 #define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref)) argument
192 #define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref)) argument
193 #define READ_X(vref) (READ_12BIT_DFR(x, 1, vref)) argument
196 /* single-ended samples need to first power up reference voltage;
197 * we leave both ADC and VREF powered
205 /* Order commands in the most optimal way to reduce Vref switching and
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-
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()
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 */
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 */
255 if (!ts->disabled && !ts->suspended) { in ads7846_restart()
257 if (ts->pendown && !get_pendown_state(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 */
271 regulator_disable(ts->reg); in __ads7846_disable()
279 /* Must be called with ts->lock held */
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()
293 mutex_lock(&ts->lock); in ads7846_disable()
295 if (!ts->disabled) { in ads7846_disable()
297 if (!ts->suspended) in ads7846_disable()
300 ts->disabled = true; in ads7846_disable()
303 mutex_unlock(&ts->lock); in ads7846_disable()
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()
318 mutex_unlock(&ts->lock); in ads7846_enable()
321 /*--------------------------------------------------------------------------*/
324 * Non-touchscreen sensors only use single-ended conversions.
325 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
326 * ads7846 lets that pin be unconnected, to use internal vREF.
363 return -ENOMEM; in ads7846_read12_ser()
365 spi_message_init(&req->msg); in ads7846_read12_ser()
367 /* maybe turn on internal vREF, and let it settle */ 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()
414 status = spi_sync(spi, &req->msg); 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()
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()
450 status = spi_sync(spi, &req->msg); 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()
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
495 * if we know vREF. userspace may need to scale vAUX to match the board's in SHOW()
502 /* external resistors may scale vAUX into 0..vREF */ in SHOW()
503 retval *= ts->vref_mv; in SHOW()
514 if (ts->model == 7846) in vbatt_adjust()
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()
556 switch (ts->model) { in ads784x_hwmon_register()
558 if (!ts->vref_mv) { in ads784x_hwmon_register()
559 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); in ads784x_hwmon_register()
560 ts->vref_mv = 2500; in ads784x_hwmon_register()
561 ts->use_internal = true; in ads784x_hwmon_register()
566 if (!ts->vref_mv) { in ads784x_hwmon_register()
567 dev_warn(&spi->dev, in ads784x_hwmon_register()
568 "external vREF for ADS%d not specified\n", in ads784x_hwmon_register()
569 ts->model); in ads784x_hwmon_register()
575 hwmon = devm_hwmon_device_register_with_groups(&spi->dev, in ads784x_hwmon_register()
576 spi->modalias, ts, in ads784x_hwmon_register()
595 return sprintf(buf, "%u\n", ts->pendown); in ads7846_pen_down_show()
605 return sprintf(buf, "%u\n", ts->disabled); in ads7846_disable_show()
640 /*--------------------------------------------------------------------------*/
650 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { in ads7846_debounce_filter()
652 ts->read_rep = 0; in ads7846_debounce_filter()
657 if (ts->read_cnt < ts->debounce_max) { in ads7846_debounce_filter()
658 ts->last_read = *val; in ads7846_debounce_filter()
659 ts->read_cnt++; in ads7846_debounce_filter()
668 ts->read_cnt = 0; in ads7846_debounce_filter()
672 if (++ts->read_rep > ts->debounce_rep) { in ads7846_debounce_filter()
677 ts->read_cnt = 0; in ads7846_debounce_filter()
678 ts->read_rep = 0; in ads7846_debounce_filter()
682 ts->read_cnt++; in ads7846_debounce_filter()
697 value = be16_to_cpup(&buf->data); in ads7846_get_value()
706 struct ads7846_packet *packet = ts->packet; in ads7846_set_cmd_val()
710 packet->y = val; in ads7846_set_cmd_val()
713 packet->x = val; in ads7846_set_cmd_val()
716 packet->z1 = val; in ads7846_set_cmd_val()
719 packet->z2 = val; in ads7846_set_cmd_val()
726 static u8 ads7846_get_cmd(enum ads7846_cmds cmd_idx, int vref) in ads7846_get_cmd() argument
730 return READ_Y(vref); in ads7846_get_cmd()
732 return READ_X(vref); in ads7846_get_cmd()
736 return READ_Z1(vref); in ads7846_get_cmd()
738 return READ_Z2(vref); in ads7846_get_cmd()
767 struct ads7846_packet *packet = ts->packet; in ads7846_filter()
772 packet->ignore = false; in ads7846_filter()
773 for (cmd_idx = packet->last_cmd_idx; cmd_idx < packet->cmds - 1; cmd_idx++) { in ads7846_filter()
774 struct ads7846_buf_layout *l = &packet->l[cmd_idx]; in ads7846_filter()
776 packet->last_cmd_idx = cmd_idx; in ads7846_filter()
778 for (b = l->skip; b < l->count; b++) { in ads7846_filter()
779 val = ads7846_get_value(&packet->rx[l->offset + b]); in ads7846_filter()
781 action = ts->filter(ts->filter_data, cmd_idx, &val); in ads7846_filter()
783 if (b == l->count - 1) in ads7846_filter()
784 return -EAGAIN; in ads7846_filter()
789 packet->ignore = true; in ads7846_filter()
800 struct ads7846_packet *packet = ts->packet; in ads7846_read_state()
805 packet->last_cmd_idx = 0; in ads7846_read_state()
808 ts->wait_for_sync(); in ads7846_read_state()
810 m = &ts->msg[msg_idx]; in ads7846_read_state()
811 error = spi_sync(ts->spi, m); in ads7846_read_state()
813 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); in ads7846_read_state()
814 packet->ignore = true; in ads7846_read_state()
828 struct ads7846_packet *packet = ts->packet; in ads7846_report_state()
832 x = packet->x; in ads7846_report_state()
833 y = packet->y; in ads7846_report_state()
834 if (ts->model == 7845) { in ads7846_report_state()
838 z1 = packet->z1; in ads7846_report_state()
839 z2 = packet->z2; in ads7846_report_state()
846 if (ts->model == 7843) { in ads7846_report_state()
847 Rt = ts->pressure_max / 2; in ads7846_report_state()
848 } else if (ts->model == 7845) { in ads7846_report_state()
850 Rt = ts->pressure_max / 2; in ads7846_report_state()
853 dev_vdbg(&ts->spi->dev, "x/y: %d/%d, PD %d\n", x, y, Rt); in ads7846_report_state()
857 Rt -= z1; in ads7846_report_state()
858 Rt *= ts->x_plate_ohms; in ads7846_report_state()
872 if (packet->ignore || Rt > ts->pressure_max) { in ads7846_report_state()
873 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n", in ads7846_report_state()
874 packet->ignore, Rt); in ads7846_report_state()
882 if (ts->penirq_recheck_delay_usecs) { in ads7846_report_state()
883 udelay(ts->penirq_recheck_delay_usecs); in ads7846_report_state()
898 struct input_dev *input = ts->input; in ads7846_report_state()
900 if (!ts->pendown) { in ads7846_report_state()
902 ts->pendown = true; in ads7846_report_state()
903 dev_vdbg(&ts->spi->dev, "DOWN\n"); in ads7846_report_state()
906 touchscreen_report_pos(input, &ts->core_prop, x, y, false); in ads7846_report_state()
907 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt); in ads7846_report_state()
910 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt); in ads7846_report_state()
929 while (!ts->stopped && get_pendown_state(ts)) { in ads7846_irq()
934 if (!ts->stopped) in ads7846_irq()
937 wait_event_timeout(ts->wait, ts->stopped, in ads7846_irq()
941 if (ts->pendown && !ts->stopped) in ads7846_irq()
951 mutex_lock(&ts->lock); in ads7846_suspend()
953 if (!ts->suspended) { in ads7846_suspend()
955 if (!ts->disabled) in ads7846_suspend()
958 if (device_may_wakeup(&ts->spi->dev)) in ads7846_suspend()
959 enable_irq_wake(ts->spi->irq); in ads7846_suspend()
961 ts->suspended = true; in ads7846_suspend()
964 mutex_unlock(&ts->lock); in ads7846_suspend()
973 mutex_lock(&ts->lock); in ads7846_resume()
975 if (ts->suspended) { in ads7846_resume()
977 ts->suspended = false; in ads7846_resume()
979 if (device_may_wakeup(&ts->spi->dev)) in ads7846_resume()
980 disable_irq_wake(ts->spi->irq); in ads7846_resume()
982 if (!ts->disabled) in ads7846_resume()
986 mutex_unlock(&ts->lock); in ads7846_resume()
1000 * REVISIT when the irq can be triggered active-low, or if for some in ads7846_setup_pendown()
1005 if (pdata->get_pendown_state) { in ads7846_setup_pendown()
1006 ts->get_pendown_state = pdata->get_pendown_state; in ads7846_setup_pendown()
1007 } else if (gpio_is_valid(pdata->gpio_pendown)) { in ads7846_setup_pendown()
1009 err = devm_gpio_request_one(&spi->dev, pdata->gpio_pendown, in ads7846_setup_pendown()
1012 dev_err(&spi->dev, in ads7846_setup_pendown()
1013 "failed to request/setup pendown GPIO%d: %d\n", in ads7846_setup_pendown()
1014 pdata->gpio_pendown, err); in ads7846_setup_pendown()
1018 ts->gpio_pendown = pdata->gpio_pendown; in ads7846_setup_pendown()
1020 if (pdata->gpio_pendown_debounce) in ads7846_setup_pendown()
1021 gpio_set_debounce(pdata->gpio_pendown, in ads7846_setup_pendown()
1022 pdata->gpio_pendown_debounce); in ads7846_setup_pendown()
1024 dev_err(&spi->dev, "no get_pendown_state nor gpio_pendown?\n"); in ads7846_setup_pendown()
1025 return -EINVAL; in ads7846_setup_pendown()
1038 struct spi_message *m = &ts->msg[0]; in ads7846_setup_spi_msg()
1039 struct spi_transfer *x = ts->xfer; in ads7846_setup_spi_msg()
1040 struct ads7846_packet *packet = ts->packet; in ads7846_setup_spi_msg()
1041 int vref = pdata->keep_vref_on; in ads7846_setup_spi_msg() local
1048 time = NSEC_PER_SEC / ts->spi->max_speed_hz; in ads7846_setup_spi_msg()
1050 count = pdata->settle_delay_usecs * NSEC_PER_USEC / time; in ads7846_setup_spi_msg()
1051 packet->count_skip = DIV_ROUND_UP(count, 24); in ads7846_setup_spi_msg()
1053 if (ts->debounce_max && ts->debounce_rep) in ads7846_setup_spi_msg()
1054 /* ads7846_debounce_filter() is making ts->debounce_rep + 2 in ads7846_setup_spi_msg()
1056 packet->count = ts->debounce_rep + 2; in ads7846_setup_spi_msg()
1058 packet->count = 1; in ads7846_setup_spi_msg()
1060 if (ts->model == 7846) in ads7846_setup_spi_msg()
1061 packet->cmds = 5; /* x, y, z1, z2, pwdown */ in ads7846_setup_spi_msg()
1063 packet->cmds = 3; /* x, y, pwdown */ in ads7846_setup_spi_msg()
1065 for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) { in ads7846_setup_spi_msg()
1066 struct ads7846_buf_layout *l = &packet->l[cmd_idx]; in ads7846_setup_spi_msg()
1070 max_count = packet->count + packet->count_skip; in ads7846_setup_spi_msg()
1072 max_count = packet->count; in ads7846_setup_spi_msg()
1074 l->offset = offset; in ads7846_setup_spi_msg()
1076 l->count = max_count; in ads7846_setup_spi_msg()
1077 l->skip = packet->count_skip; in ads7846_setup_spi_msg()
1078 size += sizeof(*packet->tx) * max_count; in ads7846_setup_spi_msg()
1081 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1082 if (!packet->tx) in ads7846_setup_spi_msg()
1083 return -ENOMEM; in ads7846_setup_spi_msg()
1085 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL); in ads7846_setup_spi_msg()
1086 if (!packet->rx) in ads7846_setup_spi_msg()
1087 return -ENOMEM; in ads7846_setup_spi_msg()
1089 if (ts->model == 7873) { in ads7846_setup_spi_msg()
1092 * keep VREF off during differential/ratiometric in ads7846_setup_spi_msg()
1095 ts->model = 7846; in ads7846_setup_spi_msg()
1096 vref = 0; in ads7846_setup_spi_msg()
1099 ts->msg_count = 1; in ads7846_setup_spi_msg()
1101 m->context = ts; in ads7846_setup_spi_msg()
1103 for (cmd_idx = 0; cmd_idx < packet->cmds; cmd_idx++) { in ads7846_setup_spi_msg()
1104 struct ads7846_buf_layout *l = &packet->l[cmd_idx]; in ads7846_setup_spi_msg()
1105 u8 cmd = ads7846_get_cmd(cmd_idx, vref); in ads7846_setup_spi_msg()
1107 for (b = 0; b < l->count; b++) in ads7846_setup_spi_msg()
1108 packet->tx[l->offset + b].cmd = cmd; in ads7846_setup_spi_msg()
1111 x->tx_buf = packet->tx; in ads7846_setup_spi_msg()
1112 x->rx_buf = packet->rx; in ads7846_setup_spi_msg()
1113 x->len = size; in ads7846_setup_spi_msg()
1133 struct device_node *node = dev->of_node; in ads7846_probe_dt()
1138 dev_err(dev, "Device does not have associated DT data\n"); in ads7846_probe_dt()
1139 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1144 dev_err(dev, "Unknown device model\n"); in ads7846_probe_dt()
1145 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1150 return ERR_PTR(-ENOMEM); in ads7846_probe_dt()
1152 pdata->model = (unsigned long)match->data; in ads7846_probe_dt()
1154 of_property_read_u16(node, "ti,vref-delay-usecs", in ads7846_probe_dt()
1155 &pdata->vref_delay_usecs); in ads7846_probe_dt()
1156 of_property_read_u16(node, "ti,vref-mv", &pdata->vref_mv); in ads7846_probe_dt()
1157 pdata->keep_vref_on = of_property_read_bool(node, "ti,keep-vref-on"); in ads7846_probe_dt()
1159 pdata->swap_xy = of_property_read_bool(node, "ti,swap-xy"); in ads7846_probe_dt()
1161 of_property_read_u16(node, "ti,settle-delay-usec", in ads7846_probe_dt()
1162 &pdata->settle_delay_usecs); in ads7846_probe_dt()
1163 of_property_read_u16(node, "ti,penirq-recheck-delay-usecs", in ads7846_probe_dt()
1164 &pdata->penirq_recheck_delay_usecs); in ads7846_probe_dt()
1166 of_property_read_u16(node, "ti,x-plate-ohms", &pdata->x_plate_ohms); in ads7846_probe_dt()
1167 of_property_read_u16(node, "ti,y-plate-ohms", &pdata->y_plate_ohms); in ads7846_probe_dt()
1169 of_property_read_u16(node, "ti,x-min", &pdata->x_min); in ads7846_probe_dt()
1170 of_property_read_u16(node, "ti,y-min", &pdata->y_min); in ads7846_probe_dt()
1171 of_property_read_u16(node, "ti,x-max", &pdata->x_max); in ads7846_probe_dt()
1172 of_property_read_u16(node, "ti,y-max", &pdata->y_max); in ads7846_probe_dt()
1175 * touchscreen-max-pressure gets parsed during in ads7846_probe_dt()
1178 of_property_read_u16(node, "ti,pressure-min", &pdata->pressure_min); in ads7846_probe_dt()
1179 if (!of_property_read_u32(node, "touchscreen-min-pressure", &value)) in ads7846_probe_dt()
1180 pdata->pressure_min = (u16) value; in ads7846_probe_dt()
1181 of_property_read_u16(node, "ti,pressure-max", &pdata->pressure_max); in ads7846_probe_dt()
1183 of_property_read_u16(node, "ti,debounce-max", &pdata->debounce_max); in ads7846_probe_dt()
1184 if (!of_property_read_u32(node, "touchscreen-average-samples", &value)) in ads7846_probe_dt()
1185 pdata->debounce_max = (u16) value; in ads7846_probe_dt()
1186 of_property_read_u16(node, "ti,debounce-tol", &pdata->debounce_tol); in ads7846_probe_dt()
1187 of_property_read_u16(node, "ti,debounce-rep", &pdata->debounce_rep); in ads7846_probe_dt()
1189 of_property_read_u32(node, "ti,pendown-gpio-debounce", in ads7846_probe_dt()
1190 &pdata->gpio_pendown_debounce); in ads7846_probe_dt()
1192 pdata->wakeup = of_property_read_bool(node, "wakeup-source") || in ads7846_probe_dt()
1195 pdata->gpio_pendown = of_get_named_gpio(dev->of_node, "pendown-gpio", 0); in ads7846_probe_dt()
1202 dev_err(dev, "no platform data defined\n"); in ads7846_probe_dt()
1203 return ERR_PTR(-EINVAL); in ads7846_probe_dt()
1216 struct device *dev = &spi->dev; in ads7846_probe()
1222 if (!spi->irq) { in ads7846_probe()
1223 dev_dbg(dev, "no IRQ?\n"); in ads7846_probe()
1224 return -EINVAL; in ads7846_probe()
1228 if (spi->max_speed_hz > (125000 * SAMPLE_BITS)) { in ads7846_probe()
1229 dev_err(dev, "f(sample) %d KHz?\n", in ads7846_probe()
1230 (spi->max_speed_hz/SAMPLE_BITS)/1000); in ads7846_probe()
1231 return -EINVAL; in ads7846_probe()
1237 * may not. So we stick to very-portable 8 bit words, both RX and TX. in ads7846_probe()
1239 spi->bits_per_word = 8; in ads7846_probe()
1240 spi->mode &= ~SPI_MODE_X_MASK; in ads7846_probe()
1241 spi->mode |= SPI_MODE_0; in ads7846_probe()
1248 return -ENOMEM; in ads7846_probe()
1252 return -ENOMEM; in ads7846_probe()
1256 return -ENOMEM; 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()
1274 ts->model = pdata->model ? : 7846; in ads7846_probe()
1275 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; in ads7846_probe()
1276 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ads7846_probe()
1277 ts->vref_mv = pdata->vref_mv; in ads7846_probe()
1279 if (pdata->debounce_max) { in ads7846_probe()
1280 ts->debounce_max = pdata->debounce_max; in ads7846_probe()
1281 if (ts->debounce_max < 2) in ads7846_probe()
1282 ts->debounce_max = 2; in ads7846_probe()
1283 ts->debounce_tol = pdata->debounce_tol; in ads7846_probe()
1284 ts->debounce_rep = pdata->debounce_rep; in ads7846_probe()
1285 ts->filter = ads7846_debounce_filter; in ads7846_probe()
1286 ts->filter_data = ts; in ads7846_probe()
1288 ts->filter = ads7846_no_filter; in ads7846_probe()
1295 if (pdata->penirq_recheck_delay_usecs) in ads7846_probe()
1296 ts->penirq_recheck_delay_usecs = in ads7846_probe()
1297 pdata->penirq_recheck_delay_usecs; in ads7846_probe()
1299 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync; in ads7846_probe()
1301 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ads7846_probe()
1302 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model); in ads7846_probe()
1304 input_dev->name = ts->name; in ads7846_probe()
1305 input_dev->phys = ts->phys; in ads7846_probe()
1307 input_dev->id.bustype = BUS_SPI; in ads7846_probe()
1308 input_dev->id.product = pdata->model; in ads7846_probe()
1312 pdata->x_min ? : 0, in ads7846_probe()
1313 pdata->x_max ? : MAX_12BIT, in ads7846_probe()
1316 pdata->y_min ? : 0, in ads7846_probe()
1317 pdata->y_max ? : MAX_12BIT, in ads7846_probe()
1320 pdata->pressure_min, pdata->pressure_max, 0, 0); in ads7846_probe()
1327 touchscreen_parse_properties(ts->input, false, &ts->core_prop); in ads7846_probe()
1328 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0; in ads7846_probe()
1331 * Check if legacy ti,swap-xy binding is used instead of in ads7846_probe()
1332 * touchscreen-swapped-x-y in ads7846_probe()
1334 if (!ts->core_prop.swap_x_y && pdata->swap_xy) { in ads7846_probe()
1335 swap(input_dev->absinfo[ABS_X], input_dev->absinfo[ABS_Y]); in ads7846_probe()
1336 ts->core_prop.swap_x_y = true; in ads7846_probe()
1341 ts->reg = devm_regulator_get(dev, "vcc"); in ads7846_probe()
1342 if (IS_ERR(ts->reg)) { in ads7846_probe()
1343 err = PTR_ERR(ts->reg); in ads7846_probe()
1344 dev_err(dev, "unable to get regulator: %d\n", err); in ads7846_probe()
1348 err = regulator_enable(ts->reg); in ads7846_probe()
1350 dev_err(dev, "unable to enable regulator: %d\n", err); in ads7846_probe()
1354 err = devm_add_action_or_reset(dev, ads7846_regulator_disable, ts->reg); in ads7846_probe()
1358 irq_flags = pdata->irq_flags ? : IRQF_TRIGGER_FALLING; in ads7846_probe()
1361 err = devm_request_threaded_irq(dev, spi->irq, in ads7846_probe()
1363 irq_flags, dev->driver->name, ts); in ads7846_probe()
1364 if (err && err != -EPROBE_DEFER && !pdata->irq_flags) { in ads7846_probe()
1366 "trying pin change workaround on irq %d\n", spi->irq); in ads7846_probe()
1368 err = devm_request_threaded_irq(dev, spi->irq, in ads7846_probe()
1370 irq_flags, dev->driver->name, in ads7846_probe()
1375 dev_dbg(dev, "irq %d busy?\n", spi->irq); in ads7846_probe()
1383 dev_info(dev, "touchscreen, irq %d\n", spi->irq); in ads7846_probe()
1386 * Take a first sample, leaving nPENIRQ active and vREF off; avoid in ads7846_probe()
1389 if (ts->model == 7845) in ads7846_probe()
1402 device_init_wakeup(dev, pdata->wakeup); in ads7846_probe()