Lines Matching +full:x +full:- +full:plate

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2008-2010 Michael Hennerich, Analog Devices Inc.
13 * - corgi_ts.c
14 * Copyright (C) 2004-2005 Richard Purdie
15 * - omap_ts.[hc], ads7846.h, ts_osk.c
19 * - ad7877.c
20 * Copyright (C) 2006-2008 Analog Devices Inc.
54 #define AD7879_TMR(x) ((x & 0xFF) << 0) argument
55 #define AD7879_ACQ(x) ((x & 0x3) << 8) argument
63 #define AD7879_FCD(x) ((x & 0x3) << 0) argument
65 #define AD7879_MFS(x) ((x & 0x3) << 5) argument
66 #define AD7879_AVG(x) ((x & 0x3) << 7) argument
67 #define AD7879_SER (1 << 9) /* non-differential */
73 #define AD7879_PM(x) ((x & 0x3) << 14) argument
103 #define MAX_12BIT ((1<<12)-1)
116 bool disabled; /* P: input->mutex */
117 bool suspended; /* P: input->mutex */
130 int x; member
140 error = regmap_read(ts->regmap, reg, &val); in ad7879_read()
142 dev_err(ts->dev, "failed to read register %#02x: %d\n", in ad7879_read()
154 error = regmap_write(ts->regmap, reg, val); in ad7879_write()
156 dev_err(ts->dev, in ad7879_write()
157 "failed to write %#04x to register %#02x: %d\n", in ad7879_write()
167 struct input_dev *input_dev = ts->input; in ad7879_report()
169 u16 x, y, z1, z2; in ad7879_report() local
171 x = ts->conversion_data[AD7879_SEQ_XPOS] & MAX_12BIT; in ad7879_report()
172 y = ts->conversion_data[AD7879_SEQ_YPOS] & MAX_12BIT; in ad7879_report()
173 z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT; in ad7879_report()
174 z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT; in ad7879_report()
176 if (ts->swap_xy) in ad7879_report()
177 swap(x, y); in ad7879_report()
186 * Other user-programmable conversion controls include variable in ad7879_report()
191 if (likely(x && z1)) { in ad7879_report()
193 Rt = (z2 - z1) * x * ts->x_plate_ohms; in ad7879_report()
202 return -EINVAL; in ad7879_report()
210 if (timer_pending(&ts->timer)) { in ad7879_report()
213 input_report_abs(input_dev, ABS_X, ts->x); in ad7879_report()
214 input_report_abs(input_dev, ABS_Y, ts->y); in ad7879_report()
215 input_report_abs(input_dev, ABS_PRESSURE, ts->Rt); in ad7879_report()
219 ts->x = x; in ad7879_report()
220 ts->y = y; in ad7879_report()
221 ts->Rt = Rt; in ad7879_report()
226 return -EINVAL; in ad7879_report()
231 struct input_dev *input_dev = ts->input; in ad7879_ts_event_release()
250 error = regmap_bulk_read(ts->regmap, AD7879_REG_XPLUS, in ad7879_irq()
251 ts->conversion_data, AD7879_NR_SENSE); in ad7879_irq()
253 dev_err_ratelimited(ts->dev, "failed to read %#02x: %d\n", in ad7879_irq()
256 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); in ad7879_irq()
263 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in __ad7879_enable()
264 ad7879_write(ts, AD7879_REG_CTRL3, ts->cmd_crtl3); in __ad7879_enable()
265 ad7879_write(ts, AD7879_REG_CTRL1, ts->cmd_crtl1); in __ad7879_enable()
267 enable_irq(ts->irq); in __ad7879_enable()
272 u16 reg = (ts->cmd_crtl2 & ~AD7879_PM(-1)) | in __ad7879_disable()
274 disable_irq(ts->irq); in __ad7879_disable()
276 if (del_timer_sync(&ts->timer)) in __ad7879_disable()
287 /* protected by input->mutex */ in ad7879_open()
288 if (!ts->disabled && !ts->suspended) in ad7879_open()
298 /* protected by input->mutex */ in ad7879_close()
299 if (!ts->disabled && !ts->suspended) in ad7879_close()
307 mutex_lock(&ts->input->mutex); in ad7879_suspend()
309 if (!ts->suspended && !ts->disabled && input_device_enabled(ts->input)) in ad7879_suspend()
312 ts->suspended = true; in ad7879_suspend()
314 mutex_unlock(&ts->input->mutex); in ad7879_suspend()
323 mutex_lock(&ts->input->mutex); in ad7879_resume()
325 if (ts->suspended && !ts->disabled && input_device_enabled(ts->input)) in ad7879_resume()
328 ts->suspended = false; in ad7879_resume()
330 mutex_unlock(&ts->input->mutex); in ad7879_resume()
340 mutex_lock(&ts->input->mutex); in ad7879_toggle()
342 if (!ts->suspended && input_device_enabled(ts->input)) { in ad7879_toggle()
345 if (ts->disabled) in ad7879_toggle()
348 if (!ts->disabled) in ad7879_toggle()
353 ts->disabled = disable; in ad7879_toggle()
355 mutex_unlock(&ts->input->mutex); in ad7879_toggle()
363 return sprintf(buf, "%u\n", ts->disabled); in ad7879_disable_show()
407 mutex_lock(&ts->mutex); in ad7879_gpio_direction_input()
408 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; in ad7879_gpio_direction_input()
409 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_input()
410 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_input()
421 mutex_lock(&ts->mutex); in ad7879_gpio_direction_output()
422 ts->cmd_crtl2 &= ~AD7879_GPIODIR; in ad7879_gpio_direction_output()
423 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL; in ad7879_gpio_direction_output()
425 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
427 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
429 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_output()
430 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_output()
440 mutex_lock(&ts->mutex); in ad7879_gpio_get_value()
442 mutex_unlock(&ts->mutex); in ad7879_gpio_get_value()
452 mutex_lock(&ts->mutex); in ad7879_gpio_set_value()
454 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_set_value()
456 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_set_value()
458 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_set_value()
459 mutex_unlock(&ts->mutex); in ad7879_gpio_set_value()
466 mutex_init(&ts->mutex); in ad7879_gpio_add()
469 if (!device_property_read_bool(ts->dev, "gpio-controller")) in ad7879_gpio_add()
472 ts->gc.direction_input = ad7879_gpio_direction_input; in ad7879_gpio_add()
473 ts->gc.direction_output = ad7879_gpio_direction_output; in ad7879_gpio_add()
474 ts->gc.get = ad7879_gpio_get_value; in ad7879_gpio_add()
475 ts->gc.set = ad7879_gpio_set_value; in ad7879_gpio_add()
476 ts->gc.can_sleep = 1; in ad7879_gpio_add()
477 ts->gc.base = -1; in ad7879_gpio_add()
478 ts->gc.ngpio = 1; in ad7879_gpio_add()
479 ts->gc.label = "AD7879-GPIO"; in ad7879_gpio_add()
480 ts->gc.owner = THIS_MODULE; in ad7879_gpio_add()
481 ts->gc.parent = ts->dev; in ad7879_gpio_add()
483 ret = devm_gpiochip_add_data(ts->dev, &ts->gc, ts); in ad7879_gpio_add()
485 dev_err(ts->dev, "failed to register gpio %d\n", in ad7879_gpio_add()
486 ts->gc.base); in ad7879_gpio_add()
502 err = device_property_read_u32(dev, "adi,resistance-plate-x", &tmp); in ad7879_parse_dt()
504 dev_err(dev, "failed to get resistance-plate-x property\n"); in ad7879_parse_dt()
507 ts->x_plate_ohms = (u16)tmp; in ad7879_parse_dt()
509 device_property_read_u8(dev, "adi,first-conversion-delay", in ad7879_parse_dt()
510 &ts->first_conversion_delay); in ad7879_parse_dt()
511 device_property_read_u8(dev, "adi,acquisition-time", in ad7879_parse_dt()
512 &ts->acquisition_time); in ad7879_parse_dt()
513 device_property_read_u8(dev, "adi,median-filter-size", &ts->median); in ad7879_parse_dt()
514 device_property_read_u8(dev, "adi,averaging", &ts->averaging); in ad7879_parse_dt()
515 device_property_read_u8(dev, "adi,conversion-interval", in ad7879_parse_dt()
516 &ts->pen_down_acc_interval); in ad7879_parse_dt()
518 ts->swap_xy = device_property_read_bool(dev, "touchscreen-swapped-x-y"); in ad7879_parse_dt()
533 return -EINVAL; in ad7879_probe()
538 return -ENOMEM; in ad7879_probe()
547 return -ENOMEM; in ad7879_probe()
550 ts->dev = dev; in ad7879_probe()
551 ts->input = input_dev; in ad7879_probe()
552 ts->irq = irq; in ad7879_probe()
553 ts->regmap = regmap; in ad7879_probe()
555 timer_setup(&ts->timer, ad7879_timer, 0); in ad7879_probe()
556 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ad7879_probe()
558 input_dev->name = "AD7879 Touchscreen"; in ad7879_probe()
559 input_dev->phys = ts->phys; in ad7879_probe()
560 input_dev->dev.parent = dev; in ad7879_probe()
561 input_dev->id.bustype = bustype; in ad7879_probe()
563 input_dev->open = ad7879_open; in ad7879_probe()
564 input_dev->close = ad7879_close; in ad7879_probe()
576 return -EINVAL; in ad7879_probe()
581 dev_err(dev, "Failed to write %s\n", input_dev->name); in ad7879_probe()
586 input_dev->id.product = (revid & 0xff); in ad7879_probe()
587 input_dev->id.version = revid >> 8; in ad7879_probe()
588 if (input_dev->id.product != devid) { in ad7879_probe()
589 dev_err(dev, "Failed to probe %s (%x vs %x)\n", in ad7879_probe()
590 input_dev->name, devid, revid); in ad7879_probe()
591 return -ENODEV; in ad7879_probe()
594 ts->cmd_crtl3 = AD7879_YPLUS_BIT | in ad7879_probe()
602 ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR | in ad7879_probe()
603 AD7879_AVG(ts->averaging) | in ad7879_probe()
604 AD7879_MFS(ts->median) | in ad7879_probe()
605 AD7879_FCD(ts->first_conversion_delay); in ad7879_probe()
607 ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 | in ad7879_probe()
608 AD7879_ACQ(ts->acquisition_time) | in ad7879_probe()
609 AD7879_TMR(ts->pen_down_acc_interval); in ad7879_probe()
611 err = devm_request_threaded_irq(dev, ts->irq, NULL, ad7879_irq, in ad7879_probe()
636 MODULE_DESCRIPTION("AD7879(-1) touchscreen Driver");