Input: ad7877 - use attribute group to control visibility of attributes
Instead of manually creating one set of attributes or another set up is_visible method in attribute group structure to control whether aux3 or gpio3 attribute is presented to userspace. Acked-by: Michael Hennerich <michael.hennerich@analog.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
This commit is contained in:
parent
fc58d12be4
commit
2fd18abad1
@ -206,8 +206,8 @@ struct ad7877 {
|
|||||||
u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned;
|
u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int gpio3;
|
static bool gpio3;
|
||||||
module_param(gpio3, int, 0);
|
module_param(gpio3, bool, 0);
|
||||||
MODULE_PARM_DESC(gpio3, "If gpio3 is set to 1 AUX3 acts as GPIO3");
|
MODULE_PARM_DESC(gpio3, "If gpio3 is set to 1 AUX3 acts as GPIO3");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -471,7 +471,7 @@ static void ad7877_enable(struct ad7877 *ts)
|
|||||||
#define SHOW(name) static ssize_t \
|
#define SHOW(name) static ssize_t \
|
||||||
name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
|
name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
|
||||||
{ \
|
{ \
|
||||||
struct ad7877 *ts = dev_get_drvdata(dev); \
|
struct ad7877 *ts = dev_get_drvdata(dev); \
|
||||||
ssize_t v = ad7877_read_adc(ts->spi, \
|
ssize_t v = ad7877_read_adc(ts->spi, \
|
||||||
AD7877_READ_CHAN(name)); \
|
AD7877_READ_CHAN(name)); \
|
||||||
if (v < 0) \
|
if (v < 0) \
|
||||||
@ -491,7 +491,7 @@ SHOW(temp2)
|
|||||||
static ssize_t ad7877_disable_show(struct device *dev,
|
static ssize_t ad7877_disable_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct ad7877 *ts = dev_get_drvdata(dev);
|
struct ad7877 *ts = dev_get_drvdata(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", ts->disabled);
|
return sprintf(buf, "%u\n", ts->disabled);
|
||||||
}
|
}
|
||||||
@ -521,7 +521,7 @@ static DEVICE_ATTR(disable, 0664, ad7877_disable_show, ad7877_disable_store);
|
|||||||
static ssize_t ad7877_dac_show(struct device *dev,
|
static ssize_t ad7877_dac_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct ad7877 *ts = dev_get_drvdata(dev);
|
struct ad7877 *ts = dev_get_drvdata(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", ts->dac);
|
return sprintf(buf, "%u\n", ts->dac);
|
||||||
}
|
}
|
||||||
@ -551,7 +551,7 @@ static DEVICE_ATTR(dac, 0664, ad7877_dac_show, ad7877_dac_store);
|
|||||||
static ssize_t ad7877_gpio3_show(struct device *dev,
|
static ssize_t ad7877_gpio3_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct ad7877 *ts = dev_get_drvdata(dev);
|
struct ad7877 *ts = dev_get_drvdata(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", ts->gpio3);
|
return sprintf(buf, "%u\n", ts->gpio3);
|
||||||
}
|
}
|
||||||
@ -582,7 +582,7 @@ static DEVICE_ATTR(gpio3, 0664, ad7877_gpio3_show, ad7877_gpio3_store);
|
|||||||
static ssize_t ad7877_gpio4_show(struct device *dev,
|
static ssize_t ad7877_gpio4_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct ad7877 *ts = dev_get_drvdata(dev);
|
struct ad7877 *ts = dev_get_drvdata(dev);
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", ts->gpio4);
|
return sprintf(buf, "%u\n", ts->gpio4);
|
||||||
}
|
}
|
||||||
@ -615,16 +615,35 @@ static struct attribute *ad7877_attributes[] = {
|
|||||||
&dev_attr_temp2.attr,
|
&dev_attr_temp2.attr,
|
||||||
&dev_attr_aux1.attr,
|
&dev_attr_aux1.attr,
|
||||||
&dev_attr_aux2.attr,
|
&dev_attr_aux2.attr,
|
||||||
|
&dev_attr_aux3.attr,
|
||||||
&dev_attr_bat1.attr,
|
&dev_attr_bat1.attr,
|
||||||
&dev_attr_bat2.attr,
|
&dev_attr_bat2.attr,
|
||||||
&dev_attr_disable.attr,
|
&dev_attr_disable.attr,
|
||||||
&dev_attr_dac.attr,
|
&dev_attr_dac.attr,
|
||||||
|
&dev_attr_gpio3.attr,
|
||||||
&dev_attr_gpio4.attr,
|
&dev_attr_gpio4.attr,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static mode_t ad7877_attr_is_visible(struct kobject *kobj,
|
||||||
|
struct attribute *attr, int n)
|
||||||
|
{
|
||||||
|
mode_t mode = attr->mode;
|
||||||
|
|
||||||
|
if (attr == &dev_attr_aux3.attr) {
|
||||||
|
if (gpio3)
|
||||||
|
mode = 0;
|
||||||
|
} else if (attr == &dev_attr_gpio3.attr) {
|
||||||
|
if (!gpio3)
|
||||||
|
mode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
static const struct attribute_group ad7877_attr_group = {
|
static const struct attribute_group ad7877_attr_group = {
|
||||||
.attrs = ad7877_attributes,
|
.is_visible = ad7877_attr_is_visible,
|
||||||
|
.attrs = ad7877_attributes,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts)
|
static void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts)
|
||||||
@ -787,20 +806,12 @@ static int __devinit ad7877_probe(struct spi_device *spi)
|
|||||||
if (err)
|
if (err)
|
||||||
goto err_free_irq;
|
goto err_free_irq;
|
||||||
|
|
||||||
err = device_create_file(&spi->dev,
|
err = input_register_device(input_dev);
|
||||||
gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3);
|
|
||||||
if (err)
|
if (err)
|
||||||
goto err_remove_attr_group;
|
goto err_remove_attr_group;
|
||||||
|
|
||||||
err = input_register_device(input_dev);
|
|
||||||
if (err)
|
|
||||||
goto err_remove_attr;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_remove_attr:
|
|
||||||
device_remove_file(&spi->dev,
|
|
||||||
gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3);
|
|
||||||
err_remove_attr_group:
|
err_remove_attr_group:
|
||||||
sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
|
sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
|
||||||
err_free_irq:
|
err_free_irq:
|
||||||
@ -814,11 +825,9 @@ err_free_mem:
|
|||||||
|
|
||||||
static int __devexit ad7877_remove(struct spi_device *spi)
|
static int __devexit ad7877_remove(struct spi_device *spi)
|
||||||
{
|
{
|
||||||
struct ad7877 *ts = dev_get_drvdata(&spi->dev);
|
struct ad7877 *ts = dev_get_drvdata(&spi->dev);
|
||||||
|
|
||||||
sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
|
sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group);
|
||||||
device_remove_file(&spi->dev,
|
|
||||||
gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3);
|
|
||||||
|
|
||||||
ad7877_disable(ts);
|
ad7877_disable(ts);
|
||||||
free_irq(ts->spi->irq, ts);
|
free_irq(ts->spi->irq, ts);
|
||||||
|
Loading…
Reference in New Issue
Block a user