aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-06-19 11:29:11 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:34 -0400
commit562dc9732ac0ab1274d2ca129b5bee5a3cf778cc (patch)
treeaec4abb695fc71a5e094300dc055c5071deb3fcb
parentb3aabd6db3700dfa6ab334c96cbf16c04929b8a2 (diff)
hwmon: (fam15h_power) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to simplify the code a bit. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/fam15h_power.c51
1 files changed, 9 insertions, 42 deletions
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 6040121a405a..7e36aa93e2b3 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -45,7 +45,7 @@ MODULE_LICENSE("GPL");
45#define REG_TDP_LIMIT3 0xe8 45#define REG_TDP_LIMIT3 0xe8
46 46
47struct fam15h_power_data { 47struct fam15h_power_data {
48 struct device *hwmon_dev; 48 struct pci_dev *pdev;
49 unsigned int tdp_to_watts; 49 unsigned int tdp_to_watts;
50 unsigned int base_tdp; 50 unsigned int base_tdp;
51 unsigned int processor_pwr_watts; 51 unsigned int processor_pwr_watts;
@@ -57,8 +57,8 @@ static ssize_t show_power(struct device *dev,
57 u32 val, tdp_limit, running_avg_range; 57 u32 val, tdp_limit, running_avg_range;
58 s32 running_avg_capture; 58 s32 running_avg_capture;
59 u64 curr_pwr_watts; 59 u64 curr_pwr_watts;
60 struct pci_dev *f4 = to_pci_dev(dev);
61 struct fam15h_power_data *data = dev_get_drvdata(dev); 60 struct fam15h_power_data *data = dev_get_drvdata(dev);
61 struct pci_dev *f4 = data->pdev;
62 62
63 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5), 63 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
64 REG_TDP_RUNNING_AVERAGE, &val); 64 REG_TDP_RUNNING_AVERAGE, &val);
@@ -96,23 +96,13 @@ static ssize_t show_power_crit(struct device *dev,
96} 96}
97static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL); 97static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
98 98
99static ssize_t show_name(struct device *dev,
100 struct device_attribute *attr, char *buf)
101{
102 return sprintf(buf, "fam15h_power\n");
103}
104static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
105
106static struct attribute *fam15h_power_attrs[] = { 99static struct attribute *fam15h_power_attrs[] = {
107 &dev_attr_power1_input.attr, 100 &dev_attr_power1_input.attr,
108 &dev_attr_power1_crit.attr, 101 &dev_attr_power1_crit.attr,
109 &dev_attr_name.attr,
110 NULL 102 NULL
111}; 103};
112 104
113static const struct attribute_group fam15h_power_attr_group = { 105ATTRIBUTE_GROUPS(fam15h_power);
114 .attrs = fam15h_power_attrs,
115};
116 106
117static bool fam15h_power_is_internal_node0(struct pci_dev *f4) 107static bool fam15h_power_is_internal_node0(struct pci_dev *f4)
118{ 108{
@@ -202,7 +192,7 @@ static int fam15h_power_probe(struct pci_dev *pdev,
202{ 192{
203 struct fam15h_power_data *data; 193 struct fam15h_power_data *data;
204 struct device *dev = &pdev->dev; 194 struct device *dev = &pdev->dev;
205 int err; 195 struct device *hwmon_dev;
206 196
207 /* 197 /*
208 * though we ignore every other northbridge, we still have to 198 * though we ignore every other northbridge, we still have to
@@ -219,34 +209,12 @@ static int fam15h_power_probe(struct pci_dev *pdev,
219 return -ENOMEM; 209 return -ENOMEM;
220 210
221 fam15h_power_init_data(pdev, data); 211 fam15h_power_init_data(pdev, data);
212 data->pdev = pdev;
222 213
223 dev_set_drvdata(dev, data); 214 hwmon_dev = devm_hwmon_device_register_with_groups(dev, "fam15h_power",
224 err = sysfs_create_group(&dev->kobj, &fam15h_power_attr_group); 215 data,
225 if (err) 216 fam15h_power_groups);
226 return err; 217 return PTR_ERR_OR_ZERO(hwmon_dev);
227
228 data->hwmon_dev = hwmon_device_register(dev);
229 if (IS_ERR(data->hwmon_dev)) {
230 err = PTR_ERR(data->hwmon_dev);
231 goto exit_remove_group;
232 }
233
234 return 0;
235
236exit_remove_group:
237 sysfs_remove_group(&dev->kobj, &fam15h_power_attr_group);
238 return err;
239}
240
241static void fam15h_power_remove(struct pci_dev *pdev)
242{
243 struct device *dev;
244 struct fam15h_power_data *data;
245
246 dev = &pdev->dev;
247 data = dev_get_drvdata(dev);
248 hwmon_device_unregister(data->hwmon_dev);
249 sysfs_remove_group(&dev->kobj, &fam15h_power_attr_group);
250} 218}
251 219
252static const struct pci_device_id fam15h_power_id_table[] = { 220static const struct pci_device_id fam15h_power_id_table[] = {
@@ -260,7 +228,6 @@ static struct pci_driver fam15h_power_driver = {
260 .name = "fam15h_power", 228 .name = "fam15h_power",
261 .id_table = fam15h_power_id_table, 229 .id_table = fam15h_power_id_table,
262 .probe = fam15h_power_probe, 230 .probe = fam15h_power_probe,
263 .remove = fam15h_power_remove,
264 .resume = fam15h_power_resume, 231 .resume = fam15h_power_resume,
265}; 232};
266 233