Lines Matching refs:ts
138 static int ad7879_read(struct ad7879 *ts, u8 reg) in ad7879_read() argument
140 return ts->bops->read(ts->dev, reg); in ad7879_read()
143 static int ad7879_multi_read(struct ad7879 *ts, u8 first_reg, u8 count, u16 *buf) in ad7879_multi_read() argument
145 return ts->bops->multi_read(ts->dev, first_reg, count, buf); in ad7879_multi_read()
148 static int ad7879_write(struct ad7879 *ts, u8 reg, u16 val) in ad7879_write() argument
150 return ts->bops->write(ts->dev, reg, val); in ad7879_write()
153 static int ad7879_report(struct ad7879 *ts) in ad7879_report() argument
155 struct input_dev *input_dev = ts->input; in ad7879_report()
159 x = ts->conversion_data[AD7879_SEQ_XPOS] & MAX_12BIT; in ad7879_report()
160 y = ts->conversion_data[AD7879_SEQ_YPOS] & MAX_12BIT; in ad7879_report()
161 z1 = ts->conversion_data[AD7879_SEQ_Z1] & MAX_12BIT; in ad7879_report()
162 z2 = ts->conversion_data[AD7879_SEQ_Z2] & MAX_12BIT; in ad7879_report()
164 if (ts->swap_xy) in ad7879_report()
181 Rt = (z2 - z1) * x * ts->x_plate_ohms; in ad7879_report()
189 if (Rt > ts->pressure_max) in ad7879_report()
198 if (timer_pending(&ts->timer)) { in ad7879_report()
201 input_report_abs(input_dev, ABS_X, ts->x); in ad7879_report()
202 input_report_abs(input_dev, ABS_Y, ts->y); in ad7879_report()
203 input_report_abs(input_dev, ABS_PRESSURE, ts->Rt); in ad7879_report()
207 ts->x = x; in ad7879_report()
208 ts->y = y; in ad7879_report()
209 ts->Rt = Rt; in ad7879_report()
217 static void ad7879_ts_event_release(struct ad7879 *ts) in ad7879_ts_event_release() argument
219 struct input_dev *input_dev = ts->input; in ad7879_ts_event_release()
228 struct ad7879 *ts = (void *)handle; in ad7879_timer() local
230 ad7879_ts_event_release(ts); in ad7879_timer()
235 struct ad7879 *ts = handle; in ad7879_irq() local
237 ad7879_multi_read(ts, AD7879_REG_XPLUS, AD7879_NR_SENSE, ts->conversion_data); in ad7879_irq()
239 if (!ad7879_report(ts)) in ad7879_irq()
240 mod_timer(&ts->timer, jiffies + TS_PEN_UP_TIMEOUT); in ad7879_irq()
245 static void __ad7879_enable(struct ad7879 *ts) in __ad7879_enable() argument
247 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in __ad7879_enable()
248 ad7879_write(ts, AD7879_REG_CTRL3, ts->cmd_crtl3); in __ad7879_enable()
249 ad7879_write(ts, AD7879_REG_CTRL1, ts->cmd_crtl1); in __ad7879_enable()
251 enable_irq(ts->irq); in __ad7879_enable()
254 static void __ad7879_disable(struct ad7879 *ts) in __ad7879_disable() argument
256 u16 reg = (ts->cmd_crtl2 & ~AD7879_PM(-1)) | in __ad7879_disable()
258 disable_irq(ts->irq); in __ad7879_disable()
260 if (del_timer_sync(&ts->timer)) in __ad7879_disable()
261 ad7879_ts_event_release(ts); in __ad7879_disable()
263 ad7879_write(ts, AD7879_REG_CTRL2, reg); in __ad7879_disable()
269 struct ad7879 *ts = input_get_drvdata(input); in ad7879_open() local
272 if (!ts->disabled && !ts->suspended) in ad7879_open()
273 __ad7879_enable(ts); in ad7879_open()
280 struct ad7879 *ts = input_get_drvdata(input); in ad7879_close() local
283 if (!ts->disabled && !ts->suspended) in ad7879_close()
284 __ad7879_disable(ts); in ad7879_close()
289 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_suspend() local
291 mutex_lock(&ts->input->mutex); in ad7879_suspend()
293 if (!ts->suspended && !ts->disabled && ts->input->users) in ad7879_suspend()
294 __ad7879_disable(ts); in ad7879_suspend()
296 ts->suspended = true; in ad7879_suspend()
298 mutex_unlock(&ts->input->mutex); in ad7879_suspend()
305 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_resume() local
307 mutex_lock(&ts->input->mutex); in ad7879_resume()
309 if (ts->suspended && !ts->disabled && ts->input->users) in ad7879_resume()
310 __ad7879_enable(ts); in ad7879_resume()
312 ts->suspended = false; in ad7879_resume()
314 mutex_unlock(&ts->input->mutex); in ad7879_resume()
322 static void ad7879_toggle(struct ad7879 *ts, bool disable) in ad7879_toggle() argument
324 mutex_lock(&ts->input->mutex); in ad7879_toggle()
326 if (!ts->suspended && ts->input->users != 0) { in ad7879_toggle()
329 if (ts->disabled) in ad7879_toggle()
330 __ad7879_enable(ts); in ad7879_toggle()
332 if (!ts->disabled) in ad7879_toggle()
333 __ad7879_disable(ts); in ad7879_toggle()
337 ts->disabled = disable; in ad7879_toggle()
339 mutex_unlock(&ts->input->mutex); in ad7879_toggle()
345 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_disable_show() local
347 return sprintf(buf, "%u\n", ts->disabled); in ad7879_disable_show()
354 struct ad7879 *ts = dev_get_drvdata(dev); in ad7879_disable_store() local
362 ad7879_toggle(ts, val); in ad7879_disable_store()
382 struct ad7879 *ts = container_of(chip, struct ad7879, gc); in ad7879_gpio_direction_input() local
385 mutex_lock(&ts->mutex); in ad7879_gpio_direction_input()
386 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL; in ad7879_gpio_direction_input()
387 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_input()
388 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_input()
396 struct ad7879 *ts = container_of(chip, struct ad7879, gc); in ad7879_gpio_direction_output() local
399 mutex_lock(&ts->mutex); in ad7879_gpio_direction_output()
400 ts->cmd_crtl2 &= ~AD7879_GPIODIR; in ad7879_gpio_direction_output()
401 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL; in ad7879_gpio_direction_output()
403 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
405 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_direction_output()
407 err = ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_direction_output()
408 mutex_unlock(&ts->mutex); in ad7879_gpio_direction_output()
415 struct ad7879 *ts = container_of(chip, struct ad7879, gc); in ad7879_gpio_get_value() local
418 mutex_lock(&ts->mutex); in ad7879_gpio_get_value()
419 val = ad7879_read(ts, AD7879_REG_CTRL2); in ad7879_gpio_get_value()
420 mutex_unlock(&ts->mutex); in ad7879_gpio_get_value()
428 struct ad7879 *ts = container_of(chip, struct ad7879, gc); in ad7879_gpio_set_value() local
430 mutex_lock(&ts->mutex); in ad7879_gpio_set_value()
432 ts->cmd_crtl2 |= AD7879_GPIO_DATA; in ad7879_gpio_set_value()
434 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA; in ad7879_gpio_set_value()
436 ad7879_write(ts, AD7879_REG_CTRL2, ts->cmd_crtl2); in ad7879_gpio_set_value()
437 mutex_unlock(&ts->mutex); in ad7879_gpio_set_value()
440 static int ad7879_gpio_add(struct ad7879 *ts, in ad7879_gpio_add() argument
445 mutex_init(&ts->mutex); in ad7879_gpio_add()
448 ts->gc.direction_input = ad7879_gpio_direction_input; in ad7879_gpio_add()
449 ts->gc.direction_output = ad7879_gpio_direction_output; in ad7879_gpio_add()
450 ts->gc.get = ad7879_gpio_get_value; in ad7879_gpio_add()
451 ts->gc.set = ad7879_gpio_set_value; in ad7879_gpio_add()
452 ts->gc.can_sleep = 1; in ad7879_gpio_add()
453 ts->gc.base = pdata->gpio_base; in ad7879_gpio_add()
454 ts->gc.ngpio = 1; in ad7879_gpio_add()
455 ts->gc.label = "AD7879-GPIO"; in ad7879_gpio_add()
456 ts->gc.owner = THIS_MODULE; in ad7879_gpio_add()
457 ts->gc.dev = ts->dev; in ad7879_gpio_add()
459 ret = gpiochip_add(&ts->gc); in ad7879_gpio_add()
461 dev_err(ts->dev, "failed to register gpio %d\n", in ad7879_gpio_add()
462 ts->gc.base); in ad7879_gpio_add()
468 static void ad7879_gpio_remove(struct ad7879 *ts) in ad7879_gpio_remove() argument
470 const struct ad7879_platform_data *pdata = dev_get_platdata(ts->dev); in ad7879_gpio_remove()
473 gpiochip_remove(&ts->gc); in ad7879_gpio_remove()
477 static inline int ad7879_gpio_add(struct ad7879 *ts, in ad7879_gpio_add() argument
483 static inline void ad7879_gpio_remove(struct ad7879 *ts) in ad7879_gpio_remove() argument
492 struct ad7879 *ts; in ad7879_probe() local
509 ts = kzalloc(sizeof(*ts), GFP_KERNEL); in ad7879_probe()
511 if (!ts || !input_dev) { in ad7879_probe()
516 ts->bops = bops; in ad7879_probe()
517 ts->dev = dev; in ad7879_probe()
518 ts->input = input_dev; in ad7879_probe()
519 ts->irq = irq; in ad7879_probe()
520 ts->swap_xy = pdata->swap_xy; in ad7879_probe()
522 setup_timer(&ts->timer, ad7879_timer, (unsigned long) ts); in ad7879_probe()
524 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; in ad7879_probe()
525 ts->pressure_max = pdata->pressure_max ? : ~0; in ad7879_probe()
527 ts->first_conversion_delay = pdata->first_conversion_delay; in ad7879_probe()
528 ts->acquisition_time = pdata->acquisition_time; in ad7879_probe()
529 ts->averaging = pdata->averaging; in ad7879_probe()
530 ts->pen_down_acc_interval = pdata->pen_down_acc_interval; in ad7879_probe()
531 ts->median = pdata->median; in ad7879_probe()
533 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(dev)); in ad7879_probe()
536 input_dev->phys = ts->phys; in ad7879_probe()
543 input_set_drvdata(input_dev, ts); in ad7879_probe()
564 err = ad7879_write(ts, AD7879_REG_CTRL2, AD7879_RESET); in ad7879_probe()
570 revid = ad7879_read(ts, AD7879_REG_REVID); in ad7879_probe()
580 ts->cmd_crtl3 = AD7879_YPLUS_BIT | in ad7879_probe()
588 ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR | in ad7879_probe()
589 AD7879_AVG(ts->averaging) | in ad7879_probe()
590 AD7879_MFS(ts->median) | in ad7879_probe()
591 AD7879_FCD(ts->first_conversion_delay); in ad7879_probe()
593 ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 | in ad7879_probe()
594 AD7879_ACQ(ts->acquisition_time) | in ad7879_probe()
595 AD7879_TMR(ts->pen_down_acc_interval); in ad7879_probe()
597 err = request_threaded_irq(ts->irq, NULL, ad7879_irq, in ad7879_probe()
599 dev_name(dev), ts); in ad7879_probe()
601 dev_err(dev, "irq %d busy?\n", ts->irq); in ad7879_probe()
605 __ad7879_disable(ts); in ad7879_probe()
611 err = ad7879_gpio_add(ts, pdata); in ad7879_probe()
619 return ts; in ad7879_probe()
622 ad7879_gpio_remove(ts); in ad7879_probe()
626 free_irq(ts->irq, ts); in ad7879_probe()
629 kfree(ts); in ad7879_probe()
635 void ad7879_remove(struct ad7879 *ts) in ad7879_remove() argument
637 ad7879_gpio_remove(ts); in ad7879_remove()
638 sysfs_remove_group(&ts->dev->kobj, &ad7879_attr_group); in ad7879_remove()
639 free_irq(ts->irq, ts); in ad7879_remove()
640 input_unregister_device(ts->input); in ad7879_remove()
641 kfree(ts); in ad7879_remove()