Commit a2f4dfba authored by Guenter Roeck's avatar Guenter Roeck Committed by David S. Miller

tg3: Convert to use hwmon_device_register_with_groups

Use new hwmon API to simplify code, provide missing mandatory 'name'
sysfs attribute, and attach hwmon attributes to hwmon device instead
of pci device.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarNithin Nayak Sujir <nsujir@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fe9d04af
...@@ -10629,10 +10629,8 @@ static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir) ...@@ -10629,10 +10629,8 @@ static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir)
static ssize_t tg3_show_temp(struct device *dev, static ssize_t tg3_show_temp(struct device *dev,
struct device_attribute *devattr, char *buf) struct device_attribute *devattr, char *buf)
{ {
struct pci_dev *pdev = to_pci_dev(dev);
struct net_device *netdev = pci_get_drvdata(pdev);
struct tg3 *tp = netdev_priv(netdev);
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct tg3 *tp = dev_get_drvdata(dev);
u32 temperature; u32 temperature;
spin_lock_bh(&tp->lock); spin_lock_bh(&tp->lock);
...@@ -10650,29 +10648,25 @@ static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, tg3_show_temp, NULL, ...@@ -10650,29 +10648,25 @@ static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, tg3_show_temp, NULL,
static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, tg3_show_temp, NULL, static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, tg3_show_temp, NULL,
TG3_TEMP_MAX_OFFSET); TG3_TEMP_MAX_OFFSET);
static struct attribute *tg3_attributes[] = { static struct attribute *tg3_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_crit.dev_attr.attr, &sensor_dev_attr_temp1_crit.dev_attr.attr,
&sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp1_max.dev_attr.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(tg3);
static const struct attribute_group tg3_group = {
.attrs = tg3_attributes,
};
static void tg3_hwmon_close(struct tg3 *tp) static void tg3_hwmon_close(struct tg3 *tp)
{ {
if (tp->hwmon_dev) { if (tp->hwmon_dev) {
hwmon_device_unregister(tp->hwmon_dev); hwmon_device_unregister(tp->hwmon_dev);
tp->hwmon_dev = NULL; tp->hwmon_dev = NULL;
sysfs_remove_group(&tp->pdev->dev.kobj, &tg3_group);
} }
} }
static void tg3_hwmon_open(struct tg3 *tp) static void tg3_hwmon_open(struct tg3 *tp)
{ {
int i, err; int i;
u32 size = 0; u32 size = 0;
struct pci_dev *pdev = tp->pdev; struct pci_dev *pdev = tp->pdev;
struct tg3_ocir ocirs[TG3_SD_NUM_RECS]; struct tg3_ocir ocirs[TG3_SD_NUM_RECS];
...@@ -10690,18 +10684,11 @@ static void tg3_hwmon_open(struct tg3 *tp) ...@@ -10690,18 +10684,11 @@ static void tg3_hwmon_open(struct tg3 *tp)
if (!size) if (!size)
return; return;
/* Register hwmon sysfs hooks */ tp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, "tg3",
err = sysfs_create_group(&pdev->dev.kobj, &tg3_group); tp, tg3_groups);
if (err) {
dev_err(&pdev->dev, "Cannot create sysfs group, aborting\n");
return;
}
tp->hwmon_dev = hwmon_device_register(&pdev->dev);
if (IS_ERR(tp->hwmon_dev)) { if (IS_ERR(tp->hwmon_dev)) {
tp->hwmon_dev = NULL; tp->hwmon_dev = NULL;
dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n"); dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n");
sysfs_remove_group(&pdev->dev.kobj, &tg3_group);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment