diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-08-15 12:27:03 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-09-22 14:14:52 -0400 |
commit | 3e3e102251a7e3a535087e0acdc6010c6acf1474 (patch) | |
tree | fbe2b98d8584815cf7e73997a84553c5a2ec8851 | |
parent | f89ce2706d8341c921b96e13a00b951a10eed308 (diff) |
hwmon: (k10temp) Convert to devm_hwmon_device_register_with_groups
Use devm_hwmon_device_register_with_groups() to simplify the code
and reduce code size.
Cc: Clemens Ladisch <clemens@ladisch.de>
Tested-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/k10temp.c | 124 |
1 files changed, 48 insertions, 76 deletions
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index 730bdf702377..1e7bdcdcb295 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c | |||
@@ -77,7 +77,7 @@ static ssize_t show_temp(struct device *dev, | |||
77 | struct device_attribute *attr, char *buf) | 77 | struct device_attribute *attr, char *buf) |
78 | { | 78 | { |
79 | u32 regval; | 79 | u32 regval; |
80 | struct pci_dev *pdev = to_pci_dev(dev); | 80 | struct pci_dev *pdev = dev_get_drvdata(dev); |
81 | 81 | ||
82 | if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model == 0x60) { | 82 | if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model == 0x60) { |
83 | amd_nb_smu_index_read(pdev, PCI_DEVFN(0, 0), | 83 | amd_nb_smu_index_read(pdev, PCI_DEVFN(0, 0), |
@@ -103,7 +103,7 @@ static ssize_t show_temp_crit(struct device *dev, | |||
103 | u32 regval; | 103 | u32 regval; |
104 | int value; | 104 | int value; |
105 | 105 | ||
106 | pci_read_config_dword(to_pci_dev(dev), | 106 | pci_read_config_dword(dev_get_drvdata(dev), |
107 | REG_HARDWARE_THERMAL_CONTROL, ®val); | 107 | REG_HARDWARE_THERMAL_CONTROL, ®val); |
108 | value = ((regval >> 16) & 0x7f) * 500 + 52000; | 108 | value = ((regval >> 16) & 0x7f) * 500 + 52000; |
109 | if (show_hyst) | 109 | if (show_hyst) |
@@ -111,17 +111,43 @@ static ssize_t show_temp_crit(struct device *dev, | |||
111 | return sprintf(buf, "%d\n", value); | 111 | return sprintf(buf, "%d\n", value); |
112 | } | 112 | } |
113 | 113 | ||
114 | static ssize_t show_name(struct device *dev, | ||
115 | struct device_attribute *attr, char *buf) | ||
116 | { | ||
117 | return sprintf(buf, "k10temp\n"); | ||
118 | } | ||
119 | |||
120 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); | 114 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); |
121 | static DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max, NULL); | 115 | static DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_max, NULL); |
122 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit, NULL, 0); | 116 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit, NULL, 0); |
123 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, show_temp_crit, NULL, 1); | 117 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, show_temp_crit, NULL, 1); |
124 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 118 | |
119 | static umode_t k10temp_is_visible(struct kobject *kobj, | ||
120 | struct attribute *attr, int index) | ||
121 | { | ||
122 | struct device *dev = container_of(kobj, struct device, kobj); | ||
123 | struct pci_dev *pdev = dev_get_drvdata(dev); | ||
124 | |||
125 | if (index >= 2) { | ||
126 | u32 reg_caps, reg_htc; | ||
127 | |||
128 | pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, | ||
129 | ®_caps); | ||
130 | pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, | ||
131 | ®_htc); | ||
132 | if (!(reg_caps & NB_CAP_HTC) || !(reg_htc & HTC_ENABLE)) | ||
133 | return 0; | ||
134 | } | ||
135 | return attr->mode; | ||
136 | } | ||
137 | |||
138 | static struct attribute *k10temp_attrs[] = { | ||
139 | &dev_attr_temp1_input.attr, | ||
140 | &dev_attr_temp1_max.attr, | ||
141 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | ||
142 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, | ||
143 | NULL | ||
144 | }; | ||
145 | |||
146 | static const struct attribute_group k10temp_group = { | ||
147 | .attrs = k10temp_attrs, | ||
148 | .is_visible = k10temp_is_visible, | ||
149 | }; | ||
150 | __ATTRIBUTE_GROUPS(k10temp); | ||
125 | 151 | ||
126 | static bool has_erratum_319(struct pci_dev *pdev) | 152 | static bool has_erratum_319(struct pci_dev *pdev) |
127 | { | 153 | { |
@@ -160,76 +186,23 @@ static bool has_erratum_319(struct pci_dev *pdev) | |||
160 | static int k10temp_probe(struct pci_dev *pdev, | 186 | static int k10temp_probe(struct pci_dev *pdev, |
161 | const struct pci_device_id *id) | 187 | const struct pci_device_id *id) |
162 | { | 188 | { |
163 | struct device *hwmon_dev; | ||
164 | u32 reg_caps, reg_htc; | ||
165 | int unreliable = has_erratum_319(pdev); | 189 | int unreliable = has_erratum_319(pdev); |
166 | int err; | 190 | struct device *dev = &pdev->dev; |
167 | 191 | struct device *hwmon_dev; | |
168 | if (unreliable && !force) { | ||
169 | dev_err(&pdev->dev, | ||
170 | "unreliable CPU thermal sensor; monitoring disabled\n"); | ||
171 | err = -ENODEV; | ||
172 | goto exit; | ||
173 | } | ||
174 | |||
175 | err = device_create_file(&pdev->dev, &dev_attr_temp1_input); | ||
176 | if (err) | ||
177 | goto exit; | ||
178 | err = device_create_file(&pdev->dev, &dev_attr_temp1_max); | ||
179 | if (err) | ||
180 | goto exit_remove; | ||
181 | |||
182 | pci_read_config_dword(pdev, REG_NORTHBRIDGE_CAPABILITIES, ®_caps); | ||
183 | pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, ®_htc); | ||
184 | if ((reg_caps & NB_CAP_HTC) && (reg_htc & HTC_ENABLE)) { | ||
185 | err = device_create_file(&pdev->dev, | ||
186 | &sensor_dev_attr_temp1_crit.dev_attr); | ||
187 | if (err) | ||
188 | goto exit_remove; | ||
189 | err = device_create_file(&pdev->dev, | ||
190 | &sensor_dev_attr_temp1_crit_hyst.dev_attr); | ||
191 | if (err) | ||
192 | goto exit_remove; | ||
193 | } | ||
194 | |||
195 | err = device_create_file(&pdev->dev, &dev_attr_name); | ||
196 | if (err) | ||
197 | goto exit_remove; | ||
198 | |||
199 | hwmon_dev = hwmon_device_register(&pdev->dev); | ||
200 | if (IS_ERR(hwmon_dev)) { | ||
201 | err = PTR_ERR(hwmon_dev); | ||
202 | goto exit_remove; | ||
203 | } | ||
204 | pci_set_drvdata(pdev, hwmon_dev); | ||
205 | 192 | ||
206 | if (unreliable && force) | 193 | if (unreliable) { |
207 | dev_warn(&pdev->dev, | 194 | if (!force) { |
195 | dev_err(dev, | ||
196 | "unreliable CPU thermal sensor; monitoring disabled\n"); | ||
197 | return -ENODEV; | ||
198 | } | ||
199 | dev_warn(dev, | ||
208 | "unreliable CPU thermal sensor; check erratum 319\n"); | 200 | "unreliable CPU thermal sensor; check erratum 319\n"); |
209 | return 0; | 201 | } |
210 | |||
211 | exit_remove: | ||
212 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
213 | device_remove_file(&pdev->dev, &dev_attr_temp1_input); | ||
214 | device_remove_file(&pdev->dev, &dev_attr_temp1_max); | ||
215 | device_remove_file(&pdev->dev, | ||
216 | &sensor_dev_attr_temp1_crit.dev_attr); | ||
217 | device_remove_file(&pdev->dev, | ||
218 | &sensor_dev_attr_temp1_crit_hyst.dev_attr); | ||
219 | exit: | ||
220 | return err; | ||
221 | } | ||
222 | 202 | ||
223 | static void k10temp_remove(struct pci_dev *pdev) | 203 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, "k10temp", pdev, |
224 | { | 204 | k10temp_groups); |
225 | hwmon_device_unregister(pci_get_drvdata(pdev)); | 205 | return PTR_ERR_OR_ZERO(hwmon_dev); |
226 | device_remove_file(&pdev->dev, &dev_attr_name); | ||
227 | device_remove_file(&pdev->dev, &dev_attr_temp1_input); | ||
228 | device_remove_file(&pdev->dev, &dev_attr_temp1_max); | ||
229 | device_remove_file(&pdev->dev, | ||
230 | &sensor_dev_attr_temp1_crit.dev_attr); | ||
231 | device_remove_file(&pdev->dev, | ||
232 | &sensor_dev_attr_temp1_crit_hyst.dev_attr); | ||
233 | } | 206 | } |
234 | 207 | ||
235 | static const struct pci_device_id k10temp_id_table[] = { | 208 | static const struct pci_device_id k10temp_id_table[] = { |
@@ -250,7 +223,6 @@ static struct pci_driver k10temp_driver = { | |||
250 | .name = "k10temp", | 223 | .name = "k10temp", |
251 | .id_table = k10temp_id_table, | 224 | .id_table = k10temp_id_table, |
252 | .probe = k10temp_probe, | 225 | .probe = k10temp_probe, |
253 | .remove = k10temp_remove, | ||
254 | }; | 226 | }; |
255 | 227 | ||
256 | module_pci_driver(k10temp_driver); | 228 | module_pci_driver(k10temp_driver); |