diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-10-18 12:22:38 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2010-10-18 12:35:09 -0400 |
commit | 2fd18abad179b11cbd881f2bd271b193ababfb65 (patch) | |
tree | 547ac1f98babf973c1d091fc7a8890306b82bfdc /drivers/input | |
parent | fc58d12be416eb51932eec594667ca3181903b9e (diff) |
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>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/touchscreen/ad7877.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c index b7de78e82737..326d7336a372 100644 --- a/drivers/input/touchscreen/ad7877.c +++ b/drivers/input/touchscreen/ad7877.c | |||
@@ -206,8 +206,8 @@ struct ad7877 { | |||
206 | u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned; | 206 | u16 conversion_data[AD7877_NR_SENSE] ____cacheline_aligned; |
207 | }; | 207 | }; |
208 | 208 | ||
209 | static int gpio3; | 209 | static bool gpio3; |
210 | module_param(gpio3, int, 0); | 210 | module_param(gpio3, bool, 0); |
211 | MODULE_PARM_DESC(gpio3, "If gpio3 is set to 1 AUX3 acts as GPIO3"); | 211 | MODULE_PARM_DESC(gpio3, "If gpio3 is set to 1 AUX3 acts as GPIO3"); |
212 | 212 | ||
213 | /* | 213 | /* |
@@ -471,7 +471,7 @@ static void ad7877_enable(struct ad7877 *ts) | |||
471 | #define SHOW(name) static ssize_t \ | 471 | #define SHOW(name) static ssize_t \ |
472 | name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ | 472 | name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ |
473 | { \ | 473 | { \ |
474 | struct ad7877 *ts = dev_get_drvdata(dev); \ | 474 | struct ad7877 *ts = dev_get_drvdata(dev); \ |
475 | ssize_t v = ad7877_read_adc(ts->spi, \ | 475 | ssize_t v = ad7877_read_adc(ts->spi, \ |
476 | AD7877_READ_CHAN(name)); \ | 476 | AD7877_READ_CHAN(name)); \ |
477 | if (v < 0) \ | 477 | if (v < 0) \ |
@@ -491,7 +491,7 @@ SHOW(temp2) | |||
491 | static ssize_t ad7877_disable_show(struct device *dev, | 491 | static ssize_t ad7877_disable_show(struct device *dev, |
492 | struct device_attribute *attr, char *buf) | 492 | struct device_attribute *attr, char *buf) |
493 | { | 493 | { |
494 | struct ad7877 *ts = dev_get_drvdata(dev); | 494 | struct ad7877 *ts = dev_get_drvdata(dev); |
495 | 495 | ||
496 | return sprintf(buf, "%u\n", ts->disabled); | 496 | return sprintf(buf, "%u\n", ts->disabled); |
497 | } | 497 | } |
@@ -521,7 +521,7 @@ static DEVICE_ATTR(disable, 0664, ad7877_disable_show, ad7877_disable_store); | |||
521 | static ssize_t ad7877_dac_show(struct device *dev, | 521 | static ssize_t ad7877_dac_show(struct device *dev, |
522 | struct device_attribute *attr, char *buf) | 522 | struct device_attribute *attr, char *buf) |
523 | { | 523 | { |
524 | struct ad7877 *ts = dev_get_drvdata(dev); | 524 | struct ad7877 *ts = dev_get_drvdata(dev); |
525 | 525 | ||
526 | return sprintf(buf, "%u\n", ts->dac); | 526 | return sprintf(buf, "%u\n", ts->dac); |
527 | } | 527 | } |
@@ -551,7 +551,7 @@ static DEVICE_ATTR(dac, 0664, ad7877_dac_show, ad7877_dac_store); | |||
551 | static ssize_t ad7877_gpio3_show(struct device *dev, | 551 | static ssize_t ad7877_gpio3_show(struct device *dev, |
552 | struct device_attribute *attr, char *buf) | 552 | struct device_attribute *attr, char *buf) |
553 | { | 553 | { |
554 | struct ad7877 *ts = dev_get_drvdata(dev); | 554 | struct ad7877 *ts = dev_get_drvdata(dev); |
555 | 555 | ||
556 | return sprintf(buf, "%u\n", ts->gpio3); | 556 | return sprintf(buf, "%u\n", ts->gpio3); |
557 | } | 557 | } |
@@ -582,7 +582,7 @@ static DEVICE_ATTR(gpio3, 0664, ad7877_gpio3_show, ad7877_gpio3_store); | |||
582 | static ssize_t ad7877_gpio4_show(struct device *dev, | 582 | static ssize_t ad7877_gpio4_show(struct device *dev, |
583 | struct device_attribute *attr, char *buf) | 583 | struct device_attribute *attr, char *buf) |
584 | { | 584 | { |
585 | struct ad7877 *ts = dev_get_drvdata(dev); | 585 | struct ad7877 *ts = dev_get_drvdata(dev); |
586 | 586 | ||
587 | return sprintf(buf, "%u\n", ts->gpio4); | 587 | return sprintf(buf, "%u\n", ts->gpio4); |
588 | } | 588 | } |
@@ -615,16 +615,35 @@ static struct attribute *ad7877_attributes[] = { | |||
615 | &dev_attr_temp2.attr, | 615 | &dev_attr_temp2.attr, |
616 | &dev_attr_aux1.attr, | 616 | &dev_attr_aux1.attr, |
617 | &dev_attr_aux2.attr, | 617 | &dev_attr_aux2.attr, |
618 | &dev_attr_aux3.attr, | ||
618 | &dev_attr_bat1.attr, | 619 | &dev_attr_bat1.attr, |
619 | &dev_attr_bat2.attr, | 620 | &dev_attr_bat2.attr, |
620 | &dev_attr_disable.attr, | 621 | &dev_attr_disable.attr, |
621 | &dev_attr_dac.attr, | 622 | &dev_attr_dac.attr, |
623 | &dev_attr_gpio3.attr, | ||
622 | &dev_attr_gpio4.attr, | 624 | &dev_attr_gpio4.attr, |
623 | NULL | 625 | NULL |
624 | }; | 626 | }; |
625 | 627 | ||
628 | static mode_t ad7877_attr_is_visible(struct kobject *kobj, | ||
629 | struct attribute *attr, int n) | ||
630 | { | ||
631 | mode_t mode = attr->mode; | ||
632 | |||
633 | if (attr == &dev_attr_aux3.attr) { | ||
634 | if (gpio3) | ||
635 | mode = 0; | ||
636 | } else if (attr == &dev_attr_gpio3.attr) { | ||
637 | if (!gpio3) | ||
638 | mode = 0; | ||
639 | } | ||
640 | |||
641 | return mode; | ||
642 | } | ||
643 | |||
626 | static const struct attribute_group ad7877_attr_group = { | 644 | static const struct attribute_group ad7877_attr_group = { |
627 | .attrs = ad7877_attributes, | 645 | .is_visible = ad7877_attr_is_visible, |
646 | .attrs = ad7877_attributes, | ||
628 | }; | 647 | }; |
629 | 648 | ||
630 | static void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts) | 649 | 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) | |||
787 | if (err) | 806 | if (err) |
788 | goto err_free_irq; | 807 | goto err_free_irq; |
789 | 808 | ||
790 | err = device_create_file(&spi->dev, | ||
791 | gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); | ||
792 | if (err) | ||
793 | goto err_remove_attr_group; | ||
794 | |||
795 | err = input_register_device(input_dev); | 809 | err = input_register_device(input_dev); |
796 | if (err) | 810 | if (err) |
797 | goto err_remove_attr; | 811 | goto err_remove_attr_group; |
798 | 812 | ||
799 | return 0; | 813 | return 0; |
800 | 814 | ||
801 | err_remove_attr: | ||
802 | device_remove_file(&spi->dev, | ||
803 | gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); | ||
804 | err_remove_attr_group: | 815 | err_remove_attr_group: |
805 | sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); | 816 | sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); |
806 | err_free_irq: | 817 | err_free_irq: |
@@ -814,11 +825,9 @@ err_free_mem: | |||
814 | 825 | ||
815 | static int __devexit ad7877_remove(struct spi_device *spi) | 826 | static int __devexit ad7877_remove(struct spi_device *spi) |
816 | { | 827 | { |
817 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | 828 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); |
818 | 829 | ||
819 | sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); | 830 | sysfs_remove_group(&spi->dev.kobj, &ad7877_attr_group); |
820 | device_remove_file(&spi->dev, | ||
821 | gpio3 ? &dev_attr_gpio3 : &dev_attr_aux3); | ||
822 | 831 | ||
823 | ad7877_disable(ts); | 832 | ad7877_disable(ts); |
824 | free_irq(ts->spi->irq, ts); | 833 | free_irq(ts->spi->irq, ts); |