Lines Matching refs:ts

220 static int get_pendown_state(struct ads7846 *ts)
222 if (ts->get_pendown_state)
223 return ts->get_pendown_state();
225 return !gpio_get_value(ts->gpio_pendown);
228 static void ads7846_report_pen_up(struct ads7846 *ts)
230 struct input_dev *input = ts->input;
236 ts->pendown = false;
237 dev_vdbg(&ts->spi->dev, "UP\n");
240 /* Must be called with ts->lock held */
241 static void ads7846_stop(struct ads7846 *ts)
243 if (!ts->disabled && !ts->suspended) {
245 ts->stopped = true;
247 wake_up(&ts->wait);
248 disable_irq(ts->spi->irq);
252 /* Must be called with ts->lock held */
253 static void ads7846_restart(struct ads7846 *ts)
255 if (!ts->disabled && !ts->suspended) {
257 if (ts->pendown && !get_pendown_state(ts))
258 ads7846_report_pen_up(ts);
261 ts->stopped = false;
263 enable_irq(ts->spi->irq);
267 /* Must be called with ts->lock held */
268 static void __ads7846_disable(struct ads7846 *ts)
270 ads7846_stop(ts);
271 regulator_disable(ts->reg);
279 /* Must be called with ts->lock held */
280 static void __ads7846_enable(struct ads7846 *ts)
284 error = regulator_enable(ts->reg);
286 dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error);
288 ads7846_restart(ts);
291 static void ads7846_disable(struct ads7846 *ts)
293 mutex_lock(&ts->lock);
295 if (!ts->disabled) {
297 if (!ts->suspended)
298 __ads7846_disable(ts);
300 ts->disabled = true;
303 mutex_unlock(&ts->lock);
306 static void ads7846_enable(struct ads7846 *ts)
308 mutex_lock(&ts->lock);
310 if (ts->disabled) {
312 ts->disabled = false;
314 if (!ts->suspended)
315 __ads7846_enable(ts);
318 mutex_unlock(&ts->lock);
357 struct ads7846 *ts = dev_get_drvdata(dev);
368 if (ts->use_internal) {
378 req->xfer[1].delay.value = ts->vref_delay_usecs;
412 mutex_lock(&ts->lock);
413 ads7846_stop(ts);
415 ads7846_restart(ts);
416 mutex_unlock(&ts->lock);
432 struct ads7846 *ts = dev_get_drvdata(dev);
448 mutex_lock(&ts->lock);
449 ads7846_stop(ts);
451 ads7846_restart(ts);
452 mutex_unlock(&ts->lock);
470 struct ads7846 *ts = dev_get_drvdata(dev); \
471 ssize_t v = ads7846_read12_ser(&ts->spi->dev, \
475 return sprintf(buf, "%u\n", adjust(ts, v)); \
485 static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v)
498 static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
503 retval *= ts->vref_mv;
509 static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v)
511 unsigned retval = vaux_adjust(ts, v);
514 if (ts->model == 7846)
527 struct ads7846 *ts = dev_get_drvdata(dev);
529 if (ts->model == 7843 && index < 2) /* in0, in1 */
531 if (ts->model == 7845 && index != 2) /* in0 */
551 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
554 switch (ts->model) {
556 if (!ts->vref_mv) {
558 ts->vref_mv = 2500;
559 ts->use_internal = true;
564 if (!ts->vref_mv) {
567 ts->model);
573 ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias,
574 ts, ads7846_attr_groups);
576 return PTR_ERR_OR_ZERO(ts->hwmon);
580 struct ads7846 *ts)
582 if (ts->hwmon)
583 hwmon_device_unregister(ts->hwmon);
588 struct ads7846 *ts)
594 struct ads7846 *ts)
602 struct ads7846 *ts = dev_get_drvdata(dev);
604 return sprintf(buf, "%u\n", ts->pendown);
612 struct ads7846 *ts = dev_get_drvdata(dev);
614 return sprintf(buf, "%u\n", ts->disabled);
621 struct ads7846 *ts = dev_get_drvdata(dev);
630 ads7846_disable(ts);
632 ads7846_enable(ts);
657 struct ads7846 *ts = ads;
659 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) {
661 ts->read_rep = 0;
666 if (ts->read_cnt < ts->debounce_max) {
667 ts->last_read = *val;
668 ts->read_cnt++;
677 ts->read_cnt = 0;
681 if (++ts->read_rep > ts->debounce_rep) {
686 ts->read_cnt = 0;
687 ts->read_rep = 0;
691 ts->read_cnt++;
712 static void ads7846_set_cmd_val(struct ads7846 *ts, enum ads7846_cmds cmd_idx,
715 struct ads7846_packet *packet = ts->packet;
774 static int ads7846_filter(struct ads7846 *ts)
776 struct ads7846_packet *packet = ts->packet;
790 action = ts->filter(ts->filter_data, cmd_idx, &val);
795 ads7846_set_cmd_val(ts, cmd_idx, val);
807 static void ads7846_read_state(struct ads7846 *ts)
809 struct ads7846_packet *packet = ts->packet;
817 ts->wait_for_sync();
819 m = &ts->msg[msg_idx];
820 error = spi_sync(ts->spi, m);
822 dev_err(&ts->spi->dev, "spi_sync --> %d\n", error);
827 error = ads7846_filter(ts);
835 static void ads7846_report_state(struct ads7846 *ts)
837 struct ads7846_packet *packet = ts->packet;
843 if (ts->model == 7845) {
855 if (ts->model == 7843 || ts->model == 7845) {
856 Rt = ts->pressure_max / 2;
861 Rt *= ts->x_plate_ohms;
875 if (packet->ignore || Rt > ts->pressure_max) {
876 dev_vdbg(&ts->spi->dev, "ignored %d pressure %d\n",
885 if (ts->penirq_recheck_delay_usecs) {
886 udelay(ts->penirq_recheck_delay_usecs);
887 if (!get_pendown_state(ts))
901 struct input_dev *input = ts->input;
903 if (!ts->pendown) {
905 ts->pendown = true;
906 dev_vdbg(&ts->spi->dev, "DOWN\n");
909 touchscreen_report_pos(input, &ts->core_prop, x, y, false);
910 input_report_abs(input, ABS_PRESSURE, ts->pressure_max - Rt);
913 dev_vdbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt);
919 struct ads7846 *ts = handle;
921 return get_pendown_state(ts) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
927 struct ads7846 *ts = handle;
932 while (!ts->stopped && get_pendown_state(ts)) {
935 ads7846_read_state(ts);
937 if (!ts->stopped)
938 ads7846_report_state(ts);
940 wait_event_timeout(ts->wait, ts->stopped,
944 if (ts->pendown && !ts->stopped)
945 ads7846_report_pen_up(ts);
952 struct ads7846 *ts = dev_get_drvdata(dev);
954 mutex_lock(&ts->lock);
956 if (!ts->suspended) {
958 if (!ts->disabled)
959 __ads7846_disable(ts);
961 if (device_may_wakeup(&ts->spi->dev))
962 enable_irq_wake(ts->spi->irq);
964 ts->suspended = true;
967 mutex_unlock(&ts->lock);
974 struct ads7846 *ts = dev_get_drvdata(dev);
976 mutex_lock(&ts->lock);
978 if (ts->suspended) {
980 ts->suspended = false;
982 if (device_may_wakeup(&ts->spi->dev))
983 disable_irq_wake(ts->spi->irq);
985 if (!ts->disabled)
986 __ads7846_enable(ts);
989 mutex_unlock(&ts->lock);
997 struct ads7846 *ts,
1009 ts->get_pendown_state = pdata->get_pendown_state;
1021 ts->gpio_pendown = pdata->gpio_pendown;
1038 static int ads7846_setup_spi_msg(struct ads7846 *ts,
1041 struct spi_message *m = &ts->msg[0];
1042 struct spi_transfer *x = ts->xfer;
1043 struct ads7846_packet *packet = ts->packet;
1051 time = NSEC_PER_SEC / ts->spi->max_speed_hz;
1056 if (ts->debounce_max && ts->debounce_rep)
1057 /* ads7846_debounce_filter() is making ts->debounce_rep + 2
1059 packet->count = ts->debounce_rep + 2;
1063 if (ts->model == 7846)
1087 packet->tx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL);
1091 packet->rx = devm_kzalloc(&ts->spi->dev, size, GFP_KERNEL);
1095 if (ts->model == 7873) {
1101 ts->model = 7846;
1105 ts->msg_count = 1;
1107 m->context = ts;
1221 struct ads7846 *ts;
1250 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
1253 if (!ts || !packet || !input_dev) {
1258 spi_set_drvdata(spi, ts);
1260 ts->packet = packet;
1261 ts->spi = spi;
1262 ts->input = input_dev;
1264 mutex_init(&ts->lock);
1265 init_waitqueue_head(&ts->wait);
1276 ts->model = pdata->model ? : 7846;
1277 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
1278 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
1279 ts->vref_mv = pdata->vref_mv;
1283 err = pdata->filter_init(pdata, &ts->filter_data);
1287 ts->filter = pdata->filter;
1288 ts->filter_cleanup = pdata->filter_cleanup;
1290 ts->debounce_max = pdata->debounce_max;
1291 if (ts->debounce_max < 2)
1292 ts->debounce_max = 2;
1293 ts->debounce_tol = pdata->debounce_tol;
1294 ts->debounce_rep = pdata->debounce_rep;
1295 ts->filter = ads7846_debounce_filter;
1296 ts->filter_data = ts;
1298 ts->filter = ads7846_no_filter;
1301 err = ads7846_setup_pendown(spi, ts, pdata);
1306 ts->penirq_recheck_delay_usecs =
1309 ts->wait_for_sync = pdata->wait_for_sync ? : null_wait_for_sync;
1311 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&spi->dev));
1312 snprintf(ts->name, sizeof(ts->name), "ADS%d Touchscreen", ts->model);
1314 input_dev->name = ts->name;
1315 input_dev->phys = ts->phys;
1328 if (ts->model != 7845)
1337 touchscreen_parse_properties(ts->input, false, &ts->core_prop);
1338 ts->pressure_max = input_abs_get_max(input_dev, ABS_PRESSURE) ? : ~0;
1344 if (!ts->core_prop.swap_x_y && pdata->swap_xy) {
1346 ts->core_prop.swap_x_y = true;
1349 ads7846_setup_spi_msg(ts, pdata);
1351 ts->reg = regulator_get(&spi->dev, "vcc");
1352 if (IS_ERR(ts->reg)) {
1353 err = PTR_ERR(ts->reg);
1358 err = regulator_enable(ts->reg);
1368 irq_flags, spi->dev.driver->name, ts);
1375 irq_flags, spi->dev.driver->name, ts);
1383 err = ads784x_hwmon_register(spi, ts);
1393 if (ts->model == 7845)
1420 ads784x_hwmon_unregister(spi, ts);
1422 free_irq(spi->irq, ts);
1424 regulator_disable(ts->reg);
1426 regulator_put(ts->reg);
1428 if (!ts->get_pendown_state)
1429 gpio_free(ts->gpio_pendown);
1431 if (ts->filter_cleanup)
1432 ts->filter_cleanup(ts->filter_data);
1436 kfree(ts);
1442 struct ads7846 *ts = spi_get_drvdata(spi);
1446 ads7846_disable(ts);
1447 free_irq(ts->spi->irq, ts);
1449 input_unregister_device(ts->input);
1451 ads784x_hwmon_unregister(spi, ts);
1453 regulator_put(ts->reg);
1455 if (!ts->get_pendown_state) {
1460 gpio_free(ts->gpio_pendown);
1463 if (ts->filter_cleanup)
1464 ts->filter_cleanup(ts->filter_data);
1466 kfree(ts->packet);
1467 kfree(ts);