aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen/ads7846.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/touchscreen/ads7846.c')
-rw-r--r--drivers/input/touchscreen/ads7846.c86
1 files changed, 27 insertions, 59 deletions
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index ea195360747e..45a06e495ed2 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -19,7 +19,6 @@
19 */ 19 */
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/hwmon.h> 21#include <linux/hwmon.h>
22#include <linux/init.h>
23#include <linux/err.h> 22#include <linux/err.h>
24#include <linux/sched.h> 23#include <linux/sched.h>
25#include <linux/delay.h> 24#include <linux/delay.h>
@@ -101,8 +100,7 @@ struct ads7846 {
101 struct spi_device *spi; 100 struct spi_device *spi;
102 struct regulator *reg; 101 struct regulator *reg;
103 102
104#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) 103#if IS_ENABLED(CONFIG_HWMON)
105 struct attribute_group *attr_group;
106 struct device *hwmon; 104 struct device *hwmon;
107#endif 105#endif
108 106
@@ -421,7 +419,7 @@ static int ads7845_read12_ser(struct device *dev, unsigned command)
421 return status; 419 return status;
422} 420}
423 421
424#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) 422#if IS_ENABLED(CONFIG_HWMON)
425 423
426#define SHOW(name, var, adjust) static ssize_t \ 424#define SHOW(name, var, adjust) static ssize_t \
427name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ 425name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
@@ -479,42 +477,36 @@ static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v)
479SHOW(in0_input, vaux, vaux_adjust) 477SHOW(in0_input, vaux, vaux_adjust)
480SHOW(in1_input, vbatt, vbatt_adjust) 478SHOW(in1_input, vbatt, vbatt_adjust)
481 479
482static struct attribute *ads7846_attributes[] = { 480static umode_t ads7846_is_visible(struct kobject *kobj, struct attribute *attr,
483 &dev_attr_temp0.attr, 481 int index)
484 &dev_attr_temp1.attr, 482{
485 &dev_attr_in0_input.attr, 483 struct device *dev = container_of(kobj, struct device, kobj);
486 &dev_attr_in1_input.attr, 484 struct ads7846 *ts = dev_get_drvdata(dev);
487 NULL,
488};
489
490static struct attribute_group ads7846_attr_group = {
491 .attrs = ads7846_attributes,
492};
493 485
494static struct attribute *ads7843_attributes[] = { 486 if (ts->model == 7843 && index < 2) /* in0, in1 */
495 &dev_attr_in0_input.attr, 487 return 0;
496 &dev_attr_in1_input.attr, 488 if (ts->model == 7845 && index != 2) /* in0 */
497 NULL, 489 return 0;
498};
499 490
500static struct attribute_group ads7843_attr_group = { 491 return attr->mode;
501 .attrs = ads7843_attributes, 492}
502};
503 493
504static struct attribute *ads7845_attributes[] = { 494static struct attribute *ads7846_attributes[] = {
505 &dev_attr_in0_input.attr, 495 &dev_attr_temp0.attr, /* 0 */
496 &dev_attr_temp1.attr, /* 1 */
497 &dev_attr_in0_input.attr, /* 2 */
498 &dev_attr_in1_input.attr, /* 3 */
506 NULL, 499 NULL,
507}; 500};
508 501
509static struct attribute_group ads7845_attr_group = { 502static struct attribute_group ads7846_attr_group = {
510 .attrs = ads7845_attributes, 503 .attrs = ads7846_attributes,
504 .is_visible = ads7846_is_visible,
511}; 505};
506__ATTRIBUTE_GROUPS(ads7846_attr);
512 507
513static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) 508static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
514{ 509{
515 struct device *hwmon;
516 int err;
517
518 /* hwmon sensors need a reference voltage */ 510 /* hwmon sensors need a reference voltage */
519 switch (ts->model) { 511 switch (ts->model) {
520 case 7846: 512 case 7846:
@@ -535,43 +527,19 @@ static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
535 break; 527 break;
536 } 528 }
537 529
538 /* different chips have different sensor groups */ 530 ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias,
539 switch (ts->model) { 531 ts, ads7846_attr_groups);
540 case 7846: 532 if (IS_ERR(ts->hwmon))
541 ts->attr_group = &ads7846_attr_group; 533 return PTR_ERR(ts->hwmon);
542 break;
543 case 7845:
544 ts->attr_group = &ads7845_attr_group;
545 break;
546 case 7843:
547 ts->attr_group = &ads7843_attr_group;
548 break;
549 default:
550 dev_dbg(&spi->dev, "ADS%d not recognized\n", ts->model);
551 return 0;
552 }
553
554 err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
555 if (err)
556 return err;
557
558 hwmon = hwmon_device_register(&spi->dev);
559 if (IS_ERR(hwmon)) {
560 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
561 return PTR_ERR(hwmon);
562 }
563 534
564 ts->hwmon = hwmon;
565 return 0; 535 return 0;
566} 536}
567 537
568static void ads784x_hwmon_unregister(struct spi_device *spi, 538static void ads784x_hwmon_unregister(struct spi_device *spi,
569 struct ads7846 *ts) 539 struct ads7846 *ts)
570{ 540{
571 if (ts->hwmon) { 541 if (ts->hwmon)
572 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
573 hwmon_device_unregister(ts->hwmon); 542 hwmon_device_unregister(ts->hwmon);
574 }
575} 543}
576 544
577#else 545#else