aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorMichael Hennerich <michael.hennerich@analog.com>2010-01-19 03:27:58 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2010-01-19 03:31:51 -0500
commitec51b7f538c440bfa5a4d538133c659071c02155 (patch)
tree0c3fb518adb6852440a58887e9ea90ccd212b9a9 /drivers/input/touchscreen
parentc332e9fcc5289698350d39d4d22c3ed5257d7a80 (diff)
Input: ad7879 - support auxiliary GPIOs via gpiolib
Drop the simple fancy sysfs hooks for the aux GPIOs and expose these via the gpiolib interface so that other drivers can use them. Signed-off-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/ad7879.c197
1 files changed, 141 insertions, 56 deletions
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index c21e6d3a8844..794d070c6900 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -47,6 +47,7 @@
47#include <linux/workqueue.h> 47#include <linux/workqueue.h>
48#include <linux/spi/spi.h> 48#include <linux/spi/spi.h>
49#include <linux/i2c.h> 49#include <linux/i2c.h>
50#include <linux/gpio.h>
50 51
51#include <linux/spi/ad7879.h> 52#include <linux/spi/ad7879.h>
52 53
@@ -132,7 +133,9 @@ struct ad7879 {
132 struct input_dev *input; 133 struct input_dev *input;
133 struct work_struct work; 134 struct work_struct work;
134 struct timer_list timer; 135 struct timer_list timer;
135 136#ifdef CONFIG_GPIOLIB
137 struct gpio_chip gc;
138#endif
136 struct mutex mutex; 139 struct mutex mutex;
137 unsigned disabled:1; /* P: mutex */ 140 unsigned disabled:1; /* P: mutex */
138 141
@@ -150,11 +153,9 @@ struct ad7879 {
150 u8 median; 153 u8 median;
151 u16 x_plate_ohms; 154 u16 x_plate_ohms;
152 u16 pressure_max; 155 u16 pressure_max;
153 u16 gpio_init;
154 u16 cmd_crtl1; 156 u16 cmd_crtl1;
155 u16 cmd_crtl2; 157 u16 cmd_crtl2;
156 u16 cmd_crtl3; 158 u16 cmd_crtl3;
157 unsigned gpio:1;
158}; 159};
159 160
160static int ad7879_read(bus_device *, u8); 161static int ad7879_read(bus_device *, u8);
@@ -237,24 +238,6 @@ static irqreturn_t ad7879_irq(int irq, void *handle)
237 238
238static void ad7879_setup(struct ad7879 *ts) 239static void ad7879_setup(struct ad7879 *ts)
239{ 240{
240 ts->cmd_crtl3 = AD7879_YPLUS_BIT |
241 AD7879_XPLUS_BIT |
242 AD7879_Z2_BIT |
243 AD7879_Z1_BIT |
244 AD7879_TEMPMASK_BIT |
245 AD7879_AUXVBATMASK_BIT |
246 AD7879_GPIOALERTMASK_BIT;
247
248 ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR |
249 AD7879_AVG(ts->averaging) |
250 AD7879_MFS(ts->median) |
251 AD7879_FCD(ts->first_conversion_delay) |
252 ts->gpio_init;
253
254 ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 |
255 AD7879_ACQ(ts->acquisition_time) |
256 AD7879_TMR(ts->pen_down_acc_interval);
257
258 ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2); 241 ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2);
259 ad7879_write(ts->bus, AD7879_REG_CTRL3, ts->cmd_crtl3); 242 ad7879_write(ts->bus, AD7879_REG_CTRL3, ts->cmd_crtl3);
260 ad7879_write(ts->bus, AD7879_REG_CTRL1, ts->cmd_crtl1); 243 ad7879_write(ts->bus, AD7879_REG_CTRL1, ts->cmd_crtl1);
@@ -324,48 +307,132 @@ static ssize_t ad7879_disable_store(struct device *dev,
324 307
325static DEVICE_ATTR(disable, 0664, ad7879_disable_show, ad7879_disable_store); 308static DEVICE_ATTR(disable, 0664, ad7879_disable_show, ad7879_disable_store);
326 309
327static ssize_t ad7879_gpio_show(struct device *dev, 310static struct attribute *ad7879_attributes[] = {
328 struct device_attribute *attr, char *buf) 311 &dev_attr_disable.attr,
312 NULL
313};
314
315static const struct attribute_group ad7879_attr_group = {
316 .attrs = ad7879_attributes,
317};
318
319#ifdef CONFIG_GPIOLIB
320static int ad7879_gpio_direction_input(struct gpio_chip *chip,
321 unsigned gpio)
329{ 322{
330 struct ad7879 *ts = dev_get_drvdata(dev); 323 struct ad7879 *ts = container_of(chip, struct ad7879, gc);
324 int err;
331 325
332 return sprintf(buf, "%u\n", ts->gpio); 326 mutex_lock(&ts->mutex);
327 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIODIR | AD7879_GPIOPOL;
328 err = ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2);
329 mutex_unlock(&ts->mutex);
330
331 return err;
333} 332}
334 333
335static ssize_t ad7879_gpio_store(struct device *dev, 334static int ad7879_gpio_direction_output(struct gpio_chip *chip,
336 struct device_attribute *attr, 335 unsigned gpio, int level)
337 const char *buf, size_t count)
338{ 336{
339 struct ad7879 *ts = dev_get_drvdata(dev); 337 struct ad7879 *ts = container_of(chip, struct ad7879, gc);
340 unsigned long val; 338 int err;
341 int error;
342 339
343 error = strict_strtoul(buf, 10, &val); 340 mutex_lock(&ts->mutex);
344 if (error) 341 ts->cmd_crtl2 &= ~AD7879_GPIODIR;
345 return error; 342 ts->cmd_crtl2 |= AD7879_GPIO_EN | AD7879_GPIOPOL;
343 if (level)
344 ts->cmd_crtl2 |= AD7879_GPIO_DATA;
345 else
346 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA;
347
348 err = ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2);
349 mutex_unlock(&ts->mutex);
350
351 return err;
352}
353
354static int ad7879_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
355{
356 struct ad7879 *ts = container_of(chip, struct ad7879, gc);
357 u16 val;
346 358
347 mutex_lock(&ts->mutex); 359 mutex_lock(&ts->mutex);
348 ts->gpio = !!val; 360 val = ad7879_read(ts->bus, AD7879_REG_CTRL2);
349 error = ad7879_write(ts->bus, AD7879_REG_CTRL2,
350 ts->gpio ?
351 ts->cmd_crtl2 & ~AD7879_GPIO_DATA :
352 ts->cmd_crtl2 | AD7879_GPIO_DATA);
353 mutex_unlock(&ts->mutex); 361 mutex_unlock(&ts->mutex);
354 362
355 return error ? : count; 363 return !!(val & AD7879_GPIO_DATA);
356} 364}
357 365
358static DEVICE_ATTR(gpio, 0664, ad7879_gpio_show, ad7879_gpio_store); 366static void ad7879_gpio_set_value(struct gpio_chip *chip,
367 unsigned gpio, int value)
368{
369 struct ad7879 *ts = container_of(chip, struct ad7879, gc);
359 370
360static struct attribute *ad7879_attributes[] = { 371 mutex_lock(&ts->mutex);
361 &dev_attr_disable.attr, 372 if (value)
362 &dev_attr_gpio.attr, 373 ts->cmd_crtl2 |= AD7879_GPIO_DATA;
363 NULL 374 else
364}; 375 ts->cmd_crtl2 &= ~AD7879_GPIO_DATA;
365 376
366static const struct attribute_group ad7879_attr_group = { 377 ad7879_write(ts->bus, AD7879_REG_CTRL2, ts->cmd_crtl2);
367 .attrs = ad7879_attributes, 378 mutex_unlock(&ts->mutex);
368}; 379}
380
381static int __devinit ad7879_gpio_add(struct device *dev)
382{
383 struct ad7879 *ts = dev_get_drvdata(dev);
384 struct ad7879_platform_data *pdata = dev->platform_data;
385 int ret = 0;
386
387 if (pdata->gpio_export) {
388 ts->gc.direction_input = ad7879_gpio_direction_input;
389 ts->gc.direction_output = ad7879_gpio_direction_output;
390 ts->gc.get = ad7879_gpio_get_value;
391 ts->gc.set = ad7879_gpio_set_value;
392 ts->gc.can_sleep = 1;
393 ts->gc.base = pdata->gpio_base;
394 ts->gc.ngpio = 1;
395 ts->gc.label = "AD7879-GPIO";
396 ts->gc.owner = THIS_MODULE;
397 ts->gc.dev = dev;
398
399 ret = gpiochip_add(&ts->gc);
400 if (ret)
401 dev_err(dev, "failed to register gpio %d\n",
402 ts->gc.base);
403 }
404
405 return ret;
406}
407
408/*
409 * We mark ad7879_gpio_remove inline so there is a chance the code
410 * gets discarded when not needed. We can't do __devinit/__devexit
411 * markup since it is used in both probe and remove methods.
412 */
413static inline void ad7879_gpio_remove(struct device *dev)
414{
415 struct ad7879 *ts = dev_get_drvdata(dev);
416 struct ad7879_platform_data *pdata = dev->platform_data;
417 int ret;
418
419 if (pdata->gpio_export) {
420 ret = gpiochip_remove(&ts->gc);
421 if (ret)
422 dev_err(dev, "failed to remove gpio %d\n",
423 ts->gc.base);
424 }
425}
426#else
427static inline int ad7879_gpio_add(struct device *dev)
428{
429 return 0;
430}
431
432static inline void ad7879_gpio_remove(struct device *dev)
433{
434}
435#endif
369 436
370static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts) 437static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
371{ 438{
@@ -403,12 +470,6 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
403 ts->pen_down_acc_interval = pdata->pen_down_acc_interval; 470 ts->pen_down_acc_interval = pdata->pen_down_acc_interval;
404 ts->median = pdata->median; 471 ts->median = pdata->median;
405 472
406 if (pdata->gpio_output)
407 ts->gpio_init = AD7879_GPIO_EN |
408 (pdata->gpio_default ? 0 : AD7879_GPIO_DATA);
409 else
410 ts->gpio_init = AD7879_GPIO_EN | AD7879_GPIODIR;
411
412 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&bus->dev)); 473 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&bus->dev));
413 474
414 input_dev->name = "AD7879 Touchscreen"; 475 input_dev->name = "AD7879 Touchscreen";
@@ -446,6 +507,23 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
446 goto err_free_mem; 507 goto err_free_mem;
447 } 508 }
448 509
510 ts->cmd_crtl3 = AD7879_YPLUS_BIT |
511 AD7879_XPLUS_BIT |
512 AD7879_Z2_BIT |
513 AD7879_Z1_BIT |
514 AD7879_TEMPMASK_BIT |
515 AD7879_AUXVBATMASK_BIT |
516 AD7879_GPIOALERTMASK_BIT;
517
518 ts->cmd_crtl2 = AD7879_PM(AD7879_PM_DYN) | AD7879_DFR |
519 AD7879_AVG(ts->averaging) |
520 AD7879_MFS(ts->median) |
521 AD7879_FCD(ts->first_conversion_delay);
522
523 ts->cmd_crtl1 = AD7879_MODE_INT | AD7879_MODE_SEQ1 |
524 AD7879_ACQ(ts->acquisition_time) |
525 AD7879_TMR(ts->pen_down_acc_interval);
526
449 ad7879_setup(ts); 527 ad7879_setup(ts);
450 528
451 err = request_irq(bus->irq, ad7879_irq, 529 err = request_irq(bus->irq, ad7879_irq,
@@ -460,15 +538,21 @@ static int __devinit ad7879_construct(bus_device *bus, struct ad7879 *ts)
460 if (err) 538 if (err)
461 goto err_free_irq; 539 goto err_free_irq;
462 540
463 err = input_register_device(input_dev); 541 err = ad7879_gpio_add(&bus->dev);
464 if (err) 542 if (err)
465 goto err_remove_attr; 543 goto err_remove_attr;
466 544
545 err = input_register_device(input_dev);
546 if (err)
547 goto err_remove_gpio;
548
467 dev_info(&bus->dev, "Rev.%d touchscreen, irq %d\n", 549 dev_info(&bus->dev, "Rev.%d touchscreen, irq %d\n",
468 revid >> 8, bus->irq); 550 revid >> 8, bus->irq);
469 551
470 return 0; 552 return 0;
471 553
554err_remove_gpio:
555 ad7879_gpio_remove(&bus->dev);
472err_remove_attr: 556err_remove_attr:
473 sysfs_remove_group(&bus->dev.kobj, &ad7879_attr_group); 557 sysfs_remove_group(&bus->dev.kobj, &ad7879_attr_group);
474err_free_irq: 558err_free_irq:
@@ -481,6 +565,7 @@ err_free_mem:
481 565
482static int __devexit ad7879_destroy(bus_device *bus, struct ad7879 *ts) 566static int __devexit ad7879_destroy(bus_device *bus, struct ad7879 *ts)
483{ 567{
568 ad7879_gpio_remove(&bus->dev);
484 ad7879_disable(ts); 569 ad7879_disable(ts);
485 sysfs_remove_group(&ts->bus->dev.kobj, &ad7879_attr_group); 570 sysfs_remove_group(&ts->bus->dev.kobj, &ad7879_attr_group);
486 free_irq(ts->bus->irq, ts); 571 free_irq(ts->bus->irq, ts);