--- zzzz-none-000/linux-3.10.107/drivers/hwmon/da9052-hwmon.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/da9052-hwmon.c 2021-02-04 17:41:59.000000000 +0000 @@ -26,7 +26,6 @@ struct da9052_hwmon { struct da9052 *da9052; - struct device *class_device; struct mutex hwmon_lock; }; @@ -45,7 +44,7 @@ /* Conversion function for VDDOUT and VBAT */ static inline int volt_reg_to_mv(int value) { - return DIV_ROUND_CLOSEST(value * 1000, 512) + 2500; + return DIV_ROUND_CLOSEST(value * 2000, 1023) + 2500; } /* Conversion function for ADC channels 4, 5 and 6 */ @@ -57,7 +56,7 @@ /* Conversion function for VBBAT */ static inline int vbbat_reg_to_mv(int value) { - return DIV_ROUND_CLOSEST(value * 2500, 512); + return DIV_ROUND_CLOSEST(value * 5000, 1023); } static inline int da9052_enable_vddout_channel(struct da9052 *da9052) @@ -190,13 +189,6 @@ return sprintf(buf, "%d\n", vbbat_reg_to_mv(ret)); } -static ssize_t da9052_hwmon_show_name(struct device *dev, - struct device_attribute *devattr, - char *buf) -{ - return sprintf(buf, "da9052\n"); -} - static ssize_t show_label(struct device *dev, struct device_attribute *devattr, char *buf) { @@ -243,10 +235,7 @@ static SENSOR_DEVICE_ATTR(temp8_label, S_IRUGO, show_label, NULL, DA9052_ADC_TJUNC); -static DEVICE_ATTR(name, S_IRUGO, da9052_hwmon_show_name, NULL); - -static struct attribute *da9052_attr[] = { - &dev_attr_name.attr, +static struct attribute *da9052_attrs[] = { &sensor_dev_attr_in0_input.dev_attr.attr, &sensor_dev_attr_in0_label.dev_attr.attr, &sensor_dev_attr_in3_input.dev_attr.attr, @@ -268,57 +257,31 @@ NULL }; -static const struct attribute_group da9052_attr_group = {.attrs = da9052_attr}; +ATTRIBUTE_GROUPS(da9052); static int da9052_hwmon_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; struct da9052_hwmon *hwmon; - int ret; + struct device *hwmon_dev; - hwmon = devm_kzalloc(&pdev->dev, sizeof(struct da9052_hwmon), - GFP_KERNEL); + hwmon = devm_kzalloc(dev, sizeof(struct da9052_hwmon), GFP_KERNEL); if (!hwmon) return -ENOMEM; mutex_init(&hwmon->hwmon_lock); hwmon->da9052 = dev_get_drvdata(pdev->dev.parent); - platform_set_drvdata(pdev, hwmon); - - ret = sysfs_create_group(&pdev->dev.kobj, &da9052_attr_group); - if (ret) - goto err_mem; - - hwmon->class_device = hwmon_device_register(&pdev->dev); - if (IS_ERR(hwmon->class_device)) { - ret = PTR_ERR(hwmon->class_device); - goto err_sysfs; - } - - return 0; - -err_sysfs: - sysfs_remove_group(&pdev->dev.kobj, &da9052_attr_group); -err_mem: - return ret; -} - -static int da9052_hwmon_remove(struct platform_device *pdev) -{ - struct da9052_hwmon *hwmon = platform_get_drvdata(pdev); - - hwmon_device_unregister(hwmon->class_device); - sysfs_remove_group(&pdev->dev.kobj, &da9052_attr_group); - - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, "da9052", + hwmon, + da9052_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } static struct platform_driver da9052_hwmon_driver = { .probe = da9052_hwmon_probe, - .remove = da9052_hwmon_remove, .driver = { .name = "da9052-hwmon", - .owner = THIS_MODULE, }, };