Lines Matching refs:ts
135 static int ad7879_read(struct ad7879 *ts, u8 reg) in ad7879_read() argument
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()
150 static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val) in ad7879_write() argument
154 error = regmap_write(ts->regmap, reg, val); in ad7879_write()
156 dev_err(ts->dev, in ad7879_write()
165 static int ad7879_report(struct ad7879 *ts) in ad7879_report() argument
167 struct input_dev *input_dev = ts->input; in ad7879_report()
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()
193 Rt = (z2 - z1) * x * ts->x_plate_ohms; 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()
229 static void ad7879_ts_event_release(struct ad7879 *ts) in ad7879_ts_event_release() argument
231 struct input_dev *input_dev = ts->input; in ad7879_ts_event_release()
240 struct ad7879 *ts = from_timer(ts, t, timer); in ad7879_timer() local
242 ad7879_ts_event_release(ts); in ad7879_timer()
247 struct ad7879 *ts = handle; in ad7879_irq() local
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()
255 else if (!ad7879_report(ts)) in ad7879_irq()
256 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); in ad7879_irq()
261 static void __ad7879_enable(struct ad7879 *ts) in __ad7879_enable() argument
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()
270 static void __ad7879_disable(struct ad7879 *ts) in __ad7879_disable() argument
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()
277 ad7879_ts_event_release(ts); in __ad7879_disable()
279 ad7879_write(ts, AD7879_REG_CTRL2, reg); in __ad7879_disable()
285 struct ad7879 *ts = input_get_drvdata(input); in ad7879_open() local
288 if (!ts->disabled && !ts->suspended) in ad7879_open()
289 __ad7879_enable(ts); in ad7879_open()
296 struct ad7879 *ts = input_get_drvdata(input); in ad7879_close() local
299 if (!ts->disabled && !ts->suspended) in ad7879_close()
300 __ad7879_disable(ts); in ad7879_close()
305 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_suspend() local
307 mutex_lock(&ts->input->mutex); in ad7879_suspend()
309 if (!ts->suspended && !ts->disabled && input_device_enabled(ts->input)) in ad7879_suspend()
310 __ad7879_disable(ts); in ad7879_suspend()
312 ts->suspended = true; in ad7879_suspend()
314 mutex_unlock(&ts->input->mutex); in ad7879_suspend()
321 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_resume() local
323 mutex_lock(&ts->input->mutex); in ad7879_resume()
325 if (ts->suspended && !ts->disabled && input_device_enabled(ts->input)) in ad7879_resume()
326 __ad7879_enable(ts); in ad7879_resume()
328 ts->suspended = false; in ad7879_resume()
330 mutex_unlock(&ts->input->mutex); in ad7879_resume()
338 static void ad7879_toggle(struct ad7879 *ts, bool disable) in ad7879_toggle() argument
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()
346 __ad7879_enable(ts); in ad7879_toggle()
348 if (!ts->disabled) in ad7879_toggle()
349 __ad7879_disable(ts); in ad7879_toggle()
353 ts->disabled = disable; in ad7879_toggle()
355 mutex_unlock(&ts->input->mutex); in ad7879_toggle()
361 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_disable_show() local
363 return sprintf(buf, "%u\n", ts->disabled); in ad7879_disable_show()
370 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_disable_store() local
378 ad7879_toggle(ts, val); in ad7879_disable_store()
398 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_direction_input() local
401 mutex_lock(&ts->mutex); in ad7879_gpio_direction_input()
402 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; in ad7879_gpio_direction_input()
403 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_input()
404 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_input()
412 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_direction_output() local
415 mutex_lock(&ts->mutex); in ad7879_gpio_direction_output()
416 ts->cmd_crtl2 &= ~AD7879_GPIODIR; in ad7879_gpio_direction_output()
417 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL; in ad7879_gpio_direction_output()
419 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
421 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
423 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_output()
424 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_output()
431 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_get_value() local
434 mutex_lock(&ts->mutex); in ad7879_gpio_get_value()
435 val = ad7879_read(ts, AD7879_REG_CTRL2); in ad7879_gpio_get_value()
436 mutex_unlock(&ts->mutex); in ad7879_gpio_get_value()
444 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_set_value() local
446 mutex_lock(&ts->mutex); in ad7879_gpio_set_value()
448 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_set_value()
450 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_set_value()
452 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_set_value()
453 mutex_unlock(&ts->mutex); in ad7879_gpio_set_value()
456 static int ad7879_gpio_add(struct ad7879 *ts) in ad7879_gpio_add() argument
460 mutex_init(&ts->mutex); in ad7879_gpio_add()
463 if (!device_property_read_bool(ts->dev, "gpio-controller")) in ad7879_gpio_add()
466 ts->gc.direction_input = ad7879_gpio_direction_input; in ad7879_gpio_add()
467 ts->gc.direction_output = ad7879_gpio_direction_output; in ad7879_gpio_add()
468 ts->gc.get = ad7879_gpio_get_value; in ad7879_gpio_add()
469 ts->gc.set = ad7879_gpio_set_value; in ad7879_gpio_add()
470 ts->gc.can_sleep = 1; in ad7879_gpio_add()
471 ts->gc.base = -1; in ad7879_gpio_add()
472 ts->gc.ngpio = 1; in ad7879_gpio_add()
473 ts->gc.label = "AD7879-GPIO"; in ad7879_gpio_add()
474 ts->gc.owner = THIS_MODULE; in ad7879_gpio_add()
475 ts->gc.parent = ts->dev; in ad7879_gpio_add()
477 ret = devm_gpiochip_add_data(ts->dev, &ts->gc, ts); in ad7879_gpio_add()
479 dev_err(ts->dev, "failed to register gpio %d\n", in ad7879_gpio_add()
480 ts->gc.base); in ad7879_gpio_add()
485 static int ad7879_gpio_add(struct ad7879 *ts) in ad7879_gpio_add() argument
491 static int ad7879_parse_dt(struct device *dev, struct ad7879 *ts) in ad7879_parse_dt() argument
501 ts->x_plate_ohms = (u16)tmp; in ad7879_parse_dt()
504 &ts->first_conversion_delay); in ad7879_parse_dt()
506 &ts->acquisition_time); in ad7879_parse_dt()
507 device_property_read_u8(dev, "adi,median-filter-size", &ts->median); in ad7879_parse_dt()
508 device_property_read_u8(dev, "adi,averaging", &ts->averaging); in ad7879_parse_dt()
510 &ts->pen_down_acc_interval); in ad7879_parse_dt()
512 ts->swap_xy = device_property_read_bool(dev, "touchscreen-swapped-x-y"); in ad7879_parse_dt()
520 struct ad7879 *ts; in ad7879_probe() local
530 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in ad7879_probe()
531 if (!ts) in ad7879_probe()
534 err = ad7879_parse_dt(dev, ts); in ad7879_probe()
544 ts->dev = dev; in ad7879_probe()
545 ts->input = input_dev; in ad7879_probe()
546 ts->irq = irq; in ad7879_probe()
547 ts->regmap = regmap; in ad7879_probe()
549 timer_setup(&ts->timer, ad7879_timer, 0); in ad7879_probe()
550 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ad7879_probe()
553 input_dev->phys = ts->phys; in ad7879_probe()
560 input_set_drvdata(input_dev, ts); in ad7879_probe()
573 err = ad7879_write(ts, AD7879_REG_CTRL2, AD7879_RESET); in ad7879_probe()
579 revid = ad7879_read(ts, AD7879_REG_REVID); in ad7879_probe()
588 ts->cmd_crtl3 = AD7879_YPLUS_BIT | in ad7879_probe()
596 ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR | in ad7879_probe()
597 AD7879_AVG(ts->averaging) | in ad7879_probe()
598 AD7879_MFS(ts->median) | in ad7879_probe()
599 AD7879_FCD(ts->first_conversion_delay); in ad7879_probe()
601 ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 | in ad7879_probe()
602 AD7879_ACQ(ts->acquisition_time) | in ad7879_probe()
603 AD7879_TMR(ts->pen_down_acc_interval); in ad7879_probe()
605 err = devm_request_threaded_irq(dev, ts->irq, NULL, ad7879_irq, in ad7879_probe()
607 dev_name(dev), ts); in ad7879_probe()
613 __ad7879_disable(ts); in ad7879_probe()
619 err = ad7879_gpio_add(ts); in ad7879_probe()
627 dev_set_drvdata(dev, ts); in ad7879_probe()