aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/ads7846.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2006-11-02 23:34:09 -0500
committerDmitry Torokhov <dtor@insightbb.com>2006-11-02 23:34:09 -0500
commit8dd51650baf0861b0a73acb2c08bb944aa45bc61 (patch)
treebb65d2a4db270e70961dfcee40d4105f4b8357ee /drivers/input/touchscreen/ads7846.c
parentf4e3c711b31cea401b03ce39d4b5f1a30279094c (diff)
Input: ads7846 - handle errors from sysfs
Add sysfs error handling and switch to using attribute groups to simplify it. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/touchscreen/ads7846.c')
-rw-r--r--drivers/input/touchscreen/ads7846.c95
1 files changed, 61 insertions, 34 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index f56d6a0f0624..8f56af8cd7a0 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -76,6 +76,7 @@ struct ads7846 {
76 char phys[32]; 76 char phys[32];
77 77
78 struct spi_device *spi; 78 struct spi_device *spi;
79 struct attribute_group *attr_group;
79 u16 model; 80 u16 model;
80 u16 vref_delay_usecs; 81 u16 vref_delay_usecs;
81 u16 x_plate_ohms; 82 u16 x_plate_ohms;
@@ -317,6 +318,48 @@ static ssize_t ads7846_disable_store(struct device *dev,
317 318
318static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); 319static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
319 320
321static struct attribute *ads7846_attributes[] = {
322 &dev_attr_temp0.attr,
323 &dev_attr_temp1.attr,
324 &dev_attr_vbatt.attr,
325 &dev_attr_vaux.attr,
326 &dev_attr_pen_down.attr,
327 &dev_attr_disable.attr,
328 NULL,
329};
330
331static struct attribute_group ads7846_attr_group = {
332 .attrs = ads7846_attributes,
333};
334
335/*
336 * ads7843/7845 don't have temperature sensors, and
337 * use the other sensors a bit differently too
338 */
339
340static struct attribute *ads7843_attributes[] = {
341 &dev_attr_vbatt.attr,
342 &dev_attr_vaux.attr,
343 &dev_attr_pen_down.attr,
344 &dev_attr_disable.attr,
345 NULL,
346};
347
348static struct attribute_group ads7843_attr_group = {
349 .attrs = ads7843_attributes,
350};
351
352static struct attribute *ads7845_attributes[] = {
353 &dev_attr_vaux.attr,
354 &dev_attr_pen_down.attr,
355 &dev_attr_disable.attr,
356 NULL,
357};
358
359static struct attribute_group ads7845_attr_group = {
360 .attrs = ads7845_attributes,
361};
362
320/*--------------------------------------------------------------------------*/ 363/*--------------------------------------------------------------------------*/
321 364
322/* 365/*
@@ -788,38 +831,30 @@ static int __devinit ads7846_probe(struct spi_device *spi)
788 (void) ads7846_read12_ser(&spi->dev, 831 (void) ads7846_read12_ser(&spi->dev,
789 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); 832 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
790 833
791 /* ads7843/7845 don't have temperature sensors, and 834 switch (ts->model) {
792 * use the other sensors a bit differently too 835 case 7846:
793 */ 836 ts->attr_group = &ads7846_attr_group;
794 if (ts->model == 7846) { 837 break;
795 device_create_file(&spi->dev, &dev_attr_temp0); 838 case 7845:
796 device_create_file(&spi->dev, &dev_attr_temp1); 839 ts->attr_group = &ads7845_attr_group;
840 break;
841 default:
842 ts->attr_group = &ads7843_attr_group;
843 break;
797 } 844 }
798 if (ts->model != 7845) 845 err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
799 device_create_file(&spi->dev, &dev_attr_vbatt); 846 if (err)
800 device_create_file(&spi->dev, &dev_attr_vaux); 847 goto err_free_irq;
801
802 device_create_file(&spi->dev, &dev_attr_pen_down);
803
804 device_create_file(&spi->dev, &dev_attr_disable);
805 848
806 err = input_register_device(input_dev); 849 err = input_register_device(input_dev);
807 if (err) 850 if (err)
808 goto err_remove_attr; 851 goto err_remove_attr_group;
809 852
810 return 0; 853 return 0;
811 854
812 err_remove_attr: 855 err_remove_attr_group:
813 device_remove_file(&spi->dev, &dev_attr_disable); 856 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
814 device_remove_file(&spi->dev, &dev_attr_pen_down); 857 err_free_irq:
815 if (ts->model == 7846) {
816 device_remove_file(&spi->dev, &dev_attr_temp1);
817 device_remove_file(&spi->dev, &dev_attr_temp0);
818 }
819 if (ts->model != 7845)
820 device_remove_file(&spi->dev, &dev_attr_vbatt);
821 device_remove_file(&spi->dev, &dev_attr_vaux);
822
823 free_irq(spi->irq, ts); 858 free_irq(spi->irq, ts);
824 err_free_mem: 859 err_free_mem:
825 input_free_device(input_dev); 860 input_free_device(input_dev);
@@ -835,15 +870,7 @@ static int __devexit ads7846_remove(struct spi_device *spi)
835 870
836 ads7846_suspend(spi, PMSG_SUSPEND); 871 ads7846_suspend(spi, PMSG_SUSPEND);
837 872
838 device_remove_file(&spi->dev, &dev_attr_disable); 873 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
839 device_remove_file(&spi->dev, &dev_attr_pen_down);
840 if (ts->model == 7846) {
841 device_remove_file(&spi->dev, &dev_attr_temp1);
842 device_remove_file(&spi->dev, &dev_attr_temp0);
843 }
844 if (ts->model != 7845)
845 device_remove_file(&spi->dev, &dev_attr_vbatt);
846 device_remove_file(&spi->dev, &dev_attr_vaux);
847 874
848 free_irq(ts->spi->irq, ts); 875 free_irq(ts->spi->irq, ts);
849 /* suspend left the IRQ disabled */ 876 /* suspend left the IRQ disabled */