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>
This commit is contained in:
Родитель
f4e3c711b3
Коммит
8dd51650ba
|
@ -76,6 +76,7 @@ struct ads7846 {
|
||||||
char phys[32];
|
char phys[32];
|
||||||
|
|
||||||
struct spi_device *spi;
|
struct spi_device *spi;
|
||||||
|
struct attribute_group *attr_group;
|
||||||
u16 model;
|
u16 model;
|
||||||
u16 vref_delay_usecs;
|
u16 vref_delay_usecs;
|
||||||
u16 x_plate_ohms;
|
u16 x_plate_ohms;
|
||||||
|
@ -317,6 +318,48 @@ static ssize_t ads7846_disable_store(struct device *dev,
|
||||||
|
|
||||||
static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
|
static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
|
||||||
|
|
||||||
|
static struct attribute *ads7846_attributes[] = {
|
||||||
|
&dev_attr_temp0.attr,
|
||||||
|
&dev_attr_temp1.attr,
|
||||||
|
&dev_attr_vbatt.attr,
|
||||||
|
&dev_attr_vaux.attr,
|
||||||
|
&dev_attr_pen_down.attr,
|
||||||
|
&dev_attr_disable.attr,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct attribute_group ads7846_attr_group = {
|
||||||
|
.attrs = ads7846_attributes,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ads7843/7845 don't have temperature sensors, and
|
||||||
|
* use the other sensors a bit differently too
|
||||||
|
*/
|
||||||
|
|
||||||
|
static struct attribute *ads7843_attributes[] = {
|
||||||
|
&dev_attr_vbatt.attr,
|
||||||
|
&dev_attr_vaux.attr,
|
||||||
|
&dev_attr_pen_down.attr,
|
||||||
|
&dev_attr_disable.attr,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct attribute_group ads7843_attr_group = {
|
||||||
|
.attrs = ads7843_attributes,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct attribute *ads7845_attributes[] = {
|
||||||
|
&dev_attr_vaux.attr,
|
||||||
|
&dev_attr_pen_down.attr,
|
||||||
|
&dev_attr_disable.attr,
|
||||||
|
NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct attribute_group ads7845_attr_group = {
|
||||||
|
.attrs = ads7845_attributes,
|
||||||
|
};
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -788,38 +831,30 @@ static int __devinit ads7846_probe(struct spi_device *spi)
|
||||||
(void) ads7846_read12_ser(&spi->dev,
|
(void) ads7846_read12_ser(&spi->dev,
|
||||||
READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
|
READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
|
||||||
|
|
||||||
/* ads7843/7845 don't have temperature sensors, and
|
switch (ts->model) {
|
||||||
* use the other sensors a bit differently too
|
case 7846:
|
||||||
*/
|
ts->attr_group = &ads7846_attr_group;
|
||||||
if (ts->model == 7846) {
|
break;
|
||||||
device_create_file(&spi->dev, &dev_attr_temp0);
|
case 7845:
|
||||||
device_create_file(&spi->dev, &dev_attr_temp1);
|
ts->attr_group = &ads7845_attr_group;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ts->attr_group = &ads7843_attr_group;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (ts->model != 7845)
|
err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
|
||||||
device_create_file(&spi->dev, &dev_attr_vbatt);
|
if (err)
|
||||||
device_create_file(&spi->dev, &dev_attr_vaux);
|
goto err_free_irq;
|
||||||
|
|
||||||
device_create_file(&spi->dev, &dev_attr_pen_down);
|
|
||||||
|
|
||||||
device_create_file(&spi->dev, &dev_attr_disable);
|
|
||||||
|
|
||||||
err = input_register_device(input_dev);
|
err = input_register_device(input_dev);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_remove_attr;
|
goto err_remove_attr_group;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_remove_attr:
|
err_remove_attr_group:
|
||||||
device_remove_file(&spi->dev, &dev_attr_disable);
|
sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
|
||||||
device_remove_file(&spi->dev, &dev_attr_pen_down);
|
err_free_irq:
|
||||||
if (ts->model == 7846) {
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_temp1);
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_temp0);
|
|
||||||
}
|
|
||||||
if (ts->model != 7845)
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_vbatt);
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_vaux);
|
|
||||||
|
|
||||||
free_irq(spi->irq, ts);
|
free_irq(spi->irq, ts);
|
||||||
err_free_mem:
|
err_free_mem:
|
||||||
input_free_device(input_dev);
|
input_free_device(input_dev);
|
||||||
|
@ -835,15 +870,7 @@ static int __devexit ads7846_remove(struct spi_device *spi)
|
||||||
|
|
||||||
ads7846_suspend(spi, PMSG_SUSPEND);
|
ads7846_suspend(spi, PMSG_SUSPEND);
|
||||||
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_disable);
|
sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
|
||||||
device_remove_file(&spi->dev, &dev_attr_pen_down);
|
|
||||||
if (ts->model == 7846) {
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_temp1);
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_temp0);
|
|
||||||
}
|
|
||||||
if (ts->model != 7845)
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_vbatt);
|
|
||||||
device_remove_file(&spi->dev, &dev_attr_vaux);
|
|
||||||
|
|
||||||
free_irq(ts->spi->irq, ts);
|
free_irq(ts->spi->irq, ts);
|
||||||
/* suspend left the IRQ disabled */
|
/* suspend left the IRQ disabled */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче