Lines Matching refs:ts

137 static int ad7879_read(struct ad7879 *ts, u8 reg)  in ad7879_read()  argument
142 error = regmap_read(ts->regmap, reg, &val); in ad7879_read()
144 dev_err(ts->dev, "failed to read register %#02x: %d\n", in ad7879_read()
152 static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val) in ad7879_write() argument
156 error = regmap_write(ts->regmap, reg, val); in ad7879_write()
158 dev_err(ts->dev, in ad7879_write()
167 static int ad7879_report(struct ad7879 *ts) in ad7879_report() argument
169 struct input_dev *input_dev = ts->input; in ad7879_report()
173 x = ts->conversion_data[AD7879_SEQ_XPOS] & MAX_12BIT; in ad7879_report()
174 y = ts->conversion_data[AD7879_SEQ_YPOS] & MAX_12BIT; in ad7879_report()
175 z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT; in ad7879_report()
176 z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT; in ad7879_report()
178 if (ts->swap_xy) in ad7879_report()
195 Rt = (z2 - z1) * x * ts->x_plate_ohms; in ad7879_report()
212 if (timer_pending(&ts->timer)) { in ad7879_report()
215 input_report_abs(input_dev, ABS_X, ts->x); in ad7879_report()
216 input_report_abs(input_dev, ABS_Y, ts->y); in ad7879_report()
217 input_report_abs(input_dev, ABS_PRESSURE, ts->Rt); in ad7879_report()
221 ts->x = x; in ad7879_report()
222 ts->y = y; in ad7879_report()
223 ts->Rt = Rt; in ad7879_report()
231 static void ad7879_ts_event_release(struct ad7879 *ts) in ad7879_ts_event_release() argument
233 struct input_dev *input_dev = ts->input; in ad7879_ts_event_release()
242 struct ad7879 *ts = from_timer(ts, t, timer); in ad7879_timer() local
244 ad7879_ts_event_release(ts); in ad7879_timer()
249 struct ad7879 *ts = handle; in ad7879_irq() local
251 regmap_bulk_read(ts->regmap, AD7879_REG_XPLUS, in ad7879_irq()
252 ts->conversion_data, AD7879_NR_SENSE); in ad7879_irq()
254 if (!ad7879_report(ts)) in ad7879_irq()
255 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); in ad7879_irq()
260 static void __ad7879_enable(struct ad7879 *ts) in __ad7879_enable() argument
262 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in __ad7879_enable()
263 ad7879_write(ts, AD7879_REG_CTRL3, ts->cmd_crtl3); in __ad7879_enable()
264 ad7879_write(ts, AD7879_REG_CTRL1, ts->cmd_crtl1); in __ad7879_enable()
266 enable_irq(ts->irq); in __ad7879_enable()
269 static void __ad7879_disable(struct ad7879 *ts) in __ad7879_disable() argument
271 u16 reg = (ts->cmd_crtl2 & ~AD7879_PM(-1)) | in __ad7879_disable()
273 disable_irq(ts->irq); in __ad7879_disable()
275 if (del_timer_sync(&ts->timer)) in __ad7879_disable()
276 ad7879_ts_event_release(ts); in __ad7879_disable()
278 ad7879_write(ts, AD7879_REG_CTRL2, reg); in __ad7879_disable()
284 struct ad7879 *ts = input_get_drvdata(input); in ad7879_open() local
287 if (!ts->disabled && !ts->suspended) in ad7879_open()
288 __ad7879_enable(ts); in ad7879_open()
295 struct ad7879 *ts = input_get_drvdata(input); in ad7879_close() local
298 if (!ts->disabled && !ts->suspended) in ad7879_close()
299 __ad7879_disable(ts); in ad7879_close()
304 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_suspend() local
306 mutex_lock(&ts->input->mutex); in ad7879_suspend()
308 if (!ts->suspended && !ts->disabled && ts->input->users) in ad7879_suspend()
309 __ad7879_disable(ts); in ad7879_suspend()
311 ts->suspended = true; in ad7879_suspend()
313 mutex_unlock(&ts->input->mutex); in ad7879_suspend()
320 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_resume() local
322 mutex_lock(&ts->input->mutex); in ad7879_resume()
324 if (ts->suspended && !ts->disabled && ts->input->users) in ad7879_resume()
325 __ad7879_enable(ts); in ad7879_resume()
327 ts->suspended = false; in ad7879_resume()
329 mutex_unlock(&ts->input->mutex); in ad7879_resume()
337 static void ad7879_toggle(struct ad7879 *ts, bool disable) in ad7879_toggle() argument
339 mutex_lock(&ts->input->mutex); in ad7879_toggle()
341 if (!ts->suspended && ts->input->users != 0) { in ad7879_toggle()
344 if (ts->disabled) in ad7879_toggle()
345 __ad7879_enable(ts); in ad7879_toggle()
347 if (!ts->disabled) in ad7879_toggle()
348 __ad7879_disable(ts); in ad7879_toggle()
352 ts->disabled = disable; in ad7879_toggle()
354 mutex_unlock(&ts->input->mutex); in ad7879_toggle()
360 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_disable_show() local
362 return sprintf(buf, "%u\n", ts->disabled); in ad7879_disable_show()
369 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_disable_store() local
377 ad7879_toggle(ts, val); in ad7879_disable_store()
397 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_direction_input() local
400 mutex_lock(&ts->mutex); in ad7879_gpio_direction_input()
401 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; in ad7879_gpio_direction_input()
402 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_input()
403 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_input()
411 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_direction_output() local
414 mutex_lock(&ts->mutex); in ad7879_gpio_direction_output()
415 ts->cmd_crtl2 &= ~AD7879_GPIODIR; in ad7879_gpio_direction_output()
416 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL; in ad7879_gpio_direction_output()
418 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
420 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
422 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_output()
423 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_output()
430 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_get_value() local
433 mutex_lock(&ts->mutex); in ad7879_gpio_get_value()
434 val = ad7879_read(ts, AD7879_REG_CTRL2); in ad7879_gpio_get_value()
435 mutex_unlock(&ts->mutex); in ad7879_gpio_get_value()
443 struct ad7879 *ts = gpiochip_get_data(chip); in ad7879_gpio_set_value() local
445 mutex_lock(&ts->mutex); in ad7879_gpio_set_value()
447 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_set_value()
449 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_set_value()
451 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_set_value()
452 mutex_unlock(&ts->mutex); in ad7879_gpio_set_value()
455 static int ad7879_gpio_add(struct ad7879 *ts, in ad7879_gpio_add() argument
466 gpio_export = device_property_read_bool(ts->dev, in ad7879_gpio_add()
471 mutex_init(&ts->mutex); in ad7879_gpio_add()
474 ts->gc.direction_input = ad7879_gpio_direction_input; in ad7879_gpio_add()
475 ts->gc.direction_output = ad7879_gpio_direction_output; in ad7879_gpio_add()
476 ts->gc.get = ad7879_gpio_get_value; in ad7879_gpio_add()
477 ts->gc.set = ad7879_gpio_set_value; in ad7879_gpio_add()
478 ts->gc.can_sleep = 1; in ad7879_gpio_add()
479 ts->gc.base = gpio_base; in ad7879_gpio_add()
480 ts->gc.ngpio = 1; in ad7879_gpio_add()
481 ts->gc.label = "AD7879-GPIO"; in ad7879_gpio_add()
482 ts->gc.owner = THIS_MODULE; in ad7879_gpio_add()
483 ts->gc.parent = ts->dev; in ad7879_gpio_add()
485 ret = devm_gpiochip_add_data(ts->dev, &ts->gc, ts); in ad7879_gpio_add()
487 dev_err(ts->dev, "failed to register gpio %d\n", in ad7879_gpio_add()
488 ts->gc.base); in ad7879_gpio_add()
494 static int ad7879_gpio_add(struct ad7879 *ts, in ad7879_gpio_add() argument
501 static int ad7879_parse_dt(struct device *dev, struct ad7879 *ts) in ad7879_parse_dt() argument
511 ts->x_plate_ohms = (u16)tmp; in ad7879_parse_dt()
514 &ts->first_conversion_delay); in ad7879_parse_dt()
516 &ts->acquisition_time); in ad7879_parse_dt()
517 device_property_read_u8(dev, "adi,median-filter-size", &ts->median); in ad7879_parse_dt()
518 device_property_read_u8(dev, "adi,averaging", &ts->averaging); in ad7879_parse_dt()
520 &ts->pen_down_acc_interval); in ad7879_parse_dt()
522 ts->swap_xy = device_property_read_bool(dev, "touchscreen-swapped-x-y"); in ad7879_parse_dt()
531 struct ad7879 *ts; in ad7879_probe() local
541 ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); in ad7879_probe()
542 if (!ts) in ad7879_probe()
547 ts->swap_xy = !pdata->swap_xy; in ad7879_probe()
549 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ad7879_probe()
551 ts->first_conversion_delay = pdata->first_conversion_delay; in ad7879_probe()
552 ts->acquisition_time = pdata->acquisition_time; in ad7879_probe()
553 ts->averaging = pdata->averaging; in ad7879_probe()
554 ts->pen_down_acc_interval = pdata->pen_down_acc_interval; in ad7879_probe()
555 ts->median = pdata->median; in ad7879_probe()
557 err = ad7879_parse_dt(dev, ts); in ad7879_probe()
568 ts->dev = dev; in ad7879_probe()
569 ts->input = input_dev; in ad7879_probe()
570 ts->irq = irq; in ad7879_probe()
571 ts->regmap = regmap; in ad7879_probe()
573 timer_setup(&ts->timer, ad7879_timer, 0); in ad7879_probe()
574 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ad7879_probe()
577 input_dev->phys = ts->phys; in ad7879_probe()
584 input_set_drvdata(input_dev, ts); in ad7879_probe()
612 err = ad7879_write(ts, AD7879_REG_CTRL2, AD7879_RESET); in ad7879_probe()
618 revid = ad7879_read(ts, AD7879_REG_REVID); in ad7879_probe()
627 ts->cmd_crtl3 = AD7879_YPLUS_BIT | in ad7879_probe()
635 ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR | in ad7879_probe()
636 AD7879_AVG(ts->averaging) | in ad7879_probe()
637 AD7879_MFS(ts->median) | in ad7879_probe()
638 AD7879_FCD(ts->first_conversion_delay); in ad7879_probe()
640 ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 | in ad7879_probe()
641 AD7879_ACQ(ts->acquisition_time) | in ad7879_probe()
642 AD7879_TMR(ts->pen_down_acc_interval); in ad7879_probe()
644 err = devm_request_threaded_irq(dev, ts->irq, NULL, ad7879_irq, in ad7879_probe()
646 dev_name(dev), ts); in ad7879_probe()
652 __ad7879_disable(ts); in ad7879_probe()
658 err = ad7879_gpio_add(ts, pdata); in ad7879_probe()
666 dev_set_drvdata(dev, ts); in ad7879_probe()