Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: ads7846 - convert to hwmon_device_register_with_groups()

Simplify the code and create mandatory 'name' attribute by using
new hwmon API.

Also use is_visible to determine visible attributes instead of creating
several different attribute groups.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Guenter Roeck and committed by
Dmitry Torokhov
e585c40b 961794a0

+25 -56
+25 -56
drivers/input/touchscreen/ads7846.c
··· 102 102 struct regulator *reg; 103 103 104 104 #if IS_ENABLED(CONFIG_HWMON) 105 - struct attribute_group *attr_group; 106 105 struct device *hwmon; 107 106 #endif 108 107 ··· 478 479 SHOW(in0_input, vaux, vaux_adjust) 479 480 SHOW(in1_input, vbatt, vbatt_adjust) 480 481 482 + static umode_t ads7846_is_visible(struct kobject *kobj, struct attribute *attr, 483 + int index) 484 + { 485 + struct device *dev = container_of(kobj, struct device, kobj); 486 + struct ads7846 *ts = dev_get_drvdata(dev); 487 + 488 + if (ts->model == 7843 && index < 2) /* in0, in1 */ 489 + return 0; 490 + if (ts->model == 7845 && index != 2) /* in0 */ 491 + return 0; 492 + 493 + return attr->mode; 494 + } 495 + 481 496 static struct attribute *ads7846_attributes[] = { 482 - &dev_attr_temp0.attr, 483 - &dev_attr_temp1.attr, 484 - &dev_attr_in0_input.attr, 485 - &dev_attr_in1_input.attr, 497 + &dev_attr_temp0.attr, /* 0 */ 498 + &dev_attr_temp1.attr, /* 1 */ 499 + &dev_attr_in0_input.attr, /* 2 */ 500 + &dev_attr_in1_input.attr, /* 3 */ 486 501 NULL, 487 502 }; 488 503 489 504 static struct attribute_group ads7846_attr_group = { 490 505 .attrs = ads7846_attributes, 506 + .is_visible = ads7846_is_visible, 491 507 }; 492 - 493 - static struct attribute *ads7843_attributes[] = { 494 - &dev_attr_in0_input.attr, 495 - &dev_attr_in1_input.attr, 496 - NULL, 497 - }; 498 - 499 - static struct attribute_group ads7843_attr_group = { 500 - .attrs = ads7843_attributes, 501 - }; 502 - 503 - static struct attribute *ads7845_attributes[] = { 504 - &dev_attr_in0_input.attr, 505 - NULL, 506 - }; 507 - 508 - static struct attribute_group ads7845_attr_group = { 509 - .attrs = ads7845_attributes, 510 - }; 508 + __ATTRIBUTE_GROUPS(ads7846_attr); 511 509 512 510 static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) 513 511 { 514 - struct device *hwmon; 515 - int err; 516 - 517 512 /* hwmon sensors need a reference voltage */ 518 513 switch (ts->model) { 519 514 case 7846: ··· 528 535 break; 529 536 } 530 537 531 - /* different chips have different sensor groups */ 532 - switch (ts->model) { 533 - case 7846: 534 - ts->attr_group = &ads7846_attr_group; 535 - break; 536 - case 7845: 537 - ts->attr_group = &ads7845_attr_group; 538 - break; 539 - case 7843: 540 - ts->attr_group = &ads7843_attr_group; 541 - break; 542 - default: 543 - dev_dbg(&spi->dev, "ADS%d not recognized\n", ts->model); 544 - return 0; 545 - } 538 + ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, 539 + ts, ads7846_attr_groups); 540 + if (IS_ERR(ts->hwmon)) 541 + return PTR_ERR(ts->hwmon); 546 542 547 - err = sysfs_create_group(&spi->dev.kobj, ts->attr_group); 548 - if (err) 549 - return err; 550 - 551 - hwmon = hwmon_device_register(&spi->dev); 552 - if (IS_ERR(hwmon)) { 553 - sysfs_remove_group(&spi->dev.kobj, ts->attr_group); 554 - return PTR_ERR(hwmon); 555 - } 556 - 557 - ts->hwmon = hwmon; 558 543 return 0; 559 544 } 560 545 561 546 static void ads784x_hwmon_unregister(struct spi_device *spi, 562 547 struct ads7846 *ts) 563 548 { 564 - if (ts->hwmon) { 565 - sysfs_remove_group(&spi->dev.kobj, ts->attr_group); 549 + if (ts->hwmon) 566 550 hwmon_device_unregister(ts->hwmon); 567 - } 568 551 } 569 552 570 553 #else