diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-17 16:15:55 -0500 |
commit | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch) | |
tree | a8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/hwmon/k8temp.c | |
parent | 406089d01562f1e2bf9f089fd7637009ebaad589 (diff) |
Patched in Tegra support.
Diffstat (limited to 'drivers/hwmon/k8temp.c')
-rw-r--r-- | drivers/hwmon/k8temp.c | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c index 9f3c0aeacdb..b923bc2307a 100644 --- a/drivers/hwmon/k8temp.c +++ b/drivers/hwmon/k8temp.c | |||
@@ -22,6 +22,7 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/module.h> | 24 | #include <linux/module.h> |
25 | #include <linux/delay.h> | ||
25 | #include <linux/init.h> | 26 | #include <linux/init.h> |
26 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
27 | #include <linux/jiffies.h> | 28 | #include <linux/jiffies.h> |
@@ -45,7 +46,7 @@ struct k8temp_data { | |||
45 | unsigned long last_updated; /* in jiffies */ | 46 | unsigned long last_updated; /* in jiffies */ |
46 | 47 | ||
47 | /* registers values */ | 48 | /* registers values */ |
48 | u8 sensorsp; /* sensor presence bits - SEL_CORE, SEL_PLACE */ | 49 | u8 sensorsp; /* sensor presence bits - SEL_CORE & SEL_PLACE */ |
49 | u32 temp[2][2]; /* core, place */ | 50 | u32 temp[2][2]; /* core, place */ |
50 | u8 swap_core_select; /* meaning of SEL_CORE is inverted */ | 51 | u8 swap_core_select; /* meaning of SEL_CORE is inverted */ |
51 | u32 temp_offset; | 52 | u32 temp_offset; |
@@ -62,7 +63,7 @@ static struct k8temp_data *k8temp_update_device(struct device *dev) | |||
62 | if (!data->valid | 63 | if (!data->valid |
63 | || time_after(jiffies, data->last_updated + HZ)) { | 64 | || time_after(jiffies, data->last_updated + HZ)) { |
64 | pci_read_config_byte(pdev, REG_TEMP, &tmp); | 65 | pci_read_config_byte(pdev, REG_TEMP, &tmp); |
65 | tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ | 66 | tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ |
66 | pci_write_config_byte(pdev, REG_TEMP, tmp); | 67 | pci_write_config_byte(pdev, REG_TEMP, tmp); |
67 | pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]); | 68 | pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]); |
68 | 69 | ||
@@ -81,7 +82,7 @@ static struct k8temp_data *k8temp_update_device(struct device *dev) | |||
81 | &data->temp[1][0]); | 82 | &data->temp[1][0]); |
82 | 83 | ||
83 | if (data->sensorsp & SEL_PLACE) { | 84 | if (data->sensorsp & SEL_PLACE) { |
84 | tmp |= SEL_PLACE; /* Select sensor 1, core1 */ | 85 | tmp |= SEL_PLACE; /* Select sensor 1, core1 */ |
85 | pci_write_config_byte(pdev, REG_TEMP, tmp); | 86 | pci_write_config_byte(pdev, REG_TEMP, tmp); |
86 | pci_read_config_dword(pdev, REG_TEMP, | 87 | pci_read_config_dword(pdev, REG_TEMP, |
87 | &data->temp[1][1]); | 88 | &data->temp[1][1]); |
@@ -135,14 +136,14 @@ static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 1, 0); | |||
135 | static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 1, 1); | 136 | static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 1, 1); |
136 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | 137 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
137 | 138 | ||
138 | static DEFINE_PCI_DEVICE_TABLE(k8temp_ids) = { | 139 | static const struct pci_device_id k8temp_ids[] = { |
139 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) }, | 140 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) }, |
140 | { 0 }, | 141 | { 0 }, |
141 | }; | 142 | }; |
142 | 143 | ||
143 | MODULE_DEVICE_TABLE(pci, k8temp_ids); | 144 | MODULE_DEVICE_TABLE(pci, k8temp_ids); |
144 | 145 | ||
145 | static int is_rev_g_desktop(u8 model) | 146 | static int __devinit is_rev_g_desktop(u8 model) |
146 | { | 147 | { |
147 | u32 brandidx; | 148 | u32 brandidx; |
148 | 149 | ||
@@ -173,7 +174,7 @@ static int is_rev_g_desktop(u8 model) | |||
173 | return 1; | 174 | return 1; |
174 | } | 175 | } |
175 | 176 | ||
176 | static int k8temp_probe(struct pci_dev *pdev, | 177 | static int __devinit k8temp_probe(struct pci_dev *pdev, |
177 | const struct pci_device_id *id) | 178 | const struct pci_device_id *id) |
178 | { | 179 | { |
179 | int err; | 180 | int err; |
@@ -182,17 +183,20 @@ static int k8temp_probe(struct pci_dev *pdev, | |||
182 | u8 model, stepping; | 183 | u8 model, stepping; |
183 | struct k8temp_data *data; | 184 | struct k8temp_data *data; |
184 | 185 | ||
185 | data = devm_kzalloc(&pdev->dev, sizeof(struct k8temp_data), GFP_KERNEL); | 186 | if (!(data = kzalloc(sizeof(struct k8temp_data), GFP_KERNEL))) { |
186 | if (!data) | 187 | err = -ENOMEM; |
187 | return -ENOMEM; | 188 | goto exit; |
189 | } | ||
188 | 190 | ||
189 | model = boot_cpu_data.x86_model; | 191 | model = boot_cpu_data.x86_model; |
190 | stepping = boot_cpu_data.x86_mask; | 192 | stepping = boot_cpu_data.x86_mask; |
191 | 193 | ||
192 | /* feature available since SH-C0, exclude older revisions */ | 194 | /* feature available since SH-C0, exclude older revisions */ |
193 | if ((model == 4 && stepping == 0) || | 195 | if (((model == 4) && (stepping == 0)) || |
194 | (model == 5 && stepping <= 1)) | 196 | ((model == 5) && (stepping <= 1))) { |
195 | return -ENODEV; | 197 | err = -ENODEV; |
198 | goto exit_free; | ||
199 | } | ||
196 | 200 | ||
197 | /* | 201 | /* |
198 | * AMD NPT family 0fh, i.e. RevF and RevG: | 202 | * AMD NPT family 0fh, i.e. RevF and RevG: |
@@ -213,13 +217,14 @@ static int k8temp_probe(struct pci_dev *pdev, | |||
213 | data->temp_offset = 21000; | 217 | data->temp_offset = 21000; |
214 | 218 | ||
215 | pci_read_config_byte(pdev, REG_TEMP, &scfg); | 219 | pci_read_config_byte(pdev, REG_TEMP, &scfg); |
216 | scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ | 220 | scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */ |
217 | pci_write_config_byte(pdev, REG_TEMP, scfg); | 221 | pci_write_config_byte(pdev, REG_TEMP, scfg); |
218 | pci_read_config_byte(pdev, REG_TEMP, &scfg); | 222 | pci_read_config_byte(pdev, REG_TEMP, &scfg); |
219 | 223 | ||
220 | if (scfg & (SEL_PLACE | SEL_CORE)) { | 224 | if (scfg & (SEL_PLACE | SEL_CORE)) { |
221 | dev_err(&pdev->dev, "Configuration bit(s) stuck at 1!\n"); | 225 | dev_err(&pdev->dev, "Configuration bit(s) stuck at 1!\n"); |
222 | return -ENODEV; | 226 | err = -ENODEV; |
227 | goto exit_free; | ||
223 | } | 228 | } |
224 | 229 | ||
225 | scfg |= (SEL_PLACE | SEL_CORE); | 230 | scfg |= (SEL_PLACE | SEL_CORE); |
@@ -233,7 +238,7 @@ static int k8temp_probe(struct pci_dev *pdev, | |||
233 | pci_write_config_byte(pdev, REG_TEMP, scfg); | 238 | pci_write_config_byte(pdev, REG_TEMP, scfg); |
234 | pci_read_config_dword(pdev, REG_TEMP, &temp); | 239 | pci_read_config_dword(pdev, REG_TEMP, &temp); |
235 | scfg |= SEL_CORE; /* prepare for next selection */ | 240 | scfg |= SEL_CORE; /* prepare for next selection */ |
236 | if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is unlikely */ | 241 | if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */ |
237 | data->sensorsp &= ~SEL_PLACE; | 242 | data->sensorsp &= ~SEL_PLACE; |
238 | } | 243 | } |
239 | 244 | ||
@@ -241,7 +246,7 @@ static int k8temp_probe(struct pci_dev *pdev, | |||
241 | scfg &= ~SEL_PLACE; /* Select sensor 0, core1 */ | 246 | scfg &= ~SEL_PLACE; /* Select sensor 0, core1 */ |
242 | pci_write_config_byte(pdev, REG_TEMP, scfg); | 247 | pci_write_config_byte(pdev, REG_TEMP, scfg); |
243 | pci_read_config_dword(pdev, REG_TEMP, &temp); | 248 | pci_read_config_dword(pdev, REG_TEMP, &temp); |
244 | if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is unlikely */ | 249 | if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */ |
245 | data->sensorsp &= ~SEL_CORE; | 250 | data->sensorsp &= ~SEL_CORE; |
246 | } | 251 | } |
247 | 252 | ||
@@ -301,10 +306,14 @@ exit_remove: | |||
301 | device_remove_file(&pdev->dev, | 306 | device_remove_file(&pdev->dev, |
302 | &sensor_dev_attr_temp4_input.dev_attr); | 307 | &sensor_dev_attr_temp4_input.dev_attr); |
303 | device_remove_file(&pdev->dev, &dev_attr_name); | 308 | device_remove_file(&pdev->dev, &dev_attr_name); |
309 | exit_free: | ||
310 | pci_set_drvdata(pdev, NULL); | ||
311 | kfree(data); | ||
312 | exit: | ||
304 | return err; | 313 | return err; |
305 | } | 314 | } |
306 | 315 | ||
307 | static void k8temp_remove(struct pci_dev *pdev) | 316 | static void __devexit k8temp_remove(struct pci_dev *pdev) |
308 | { | 317 | { |
309 | struct k8temp_data *data = pci_get_drvdata(pdev); | 318 | struct k8temp_data *data = pci_get_drvdata(pdev); |
310 | 319 | ||
@@ -318,17 +327,30 @@ static void k8temp_remove(struct pci_dev *pdev) | |||
318 | device_remove_file(&pdev->dev, | 327 | device_remove_file(&pdev->dev, |
319 | &sensor_dev_attr_temp4_input.dev_attr); | 328 | &sensor_dev_attr_temp4_input.dev_attr); |
320 | device_remove_file(&pdev->dev, &dev_attr_name); | 329 | device_remove_file(&pdev->dev, &dev_attr_name); |
330 | pci_set_drvdata(pdev, NULL); | ||
331 | kfree(data); | ||
321 | } | 332 | } |
322 | 333 | ||
323 | static struct pci_driver k8temp_driver = { | 334 | static struct pci_driver k8temp_driver = { |
324 | .name = "k8temp", | 335 | .name = "k8temp", |
325 | .id_table = k8temp_ids, | 336 | .id_table = k8temp_ids, |
326 | .probe = k8temp_probe, | 337 | .probe = k8temp_probe, |
327 | .remove = k8temp_remove, | 338 | .remove = __devexit_p(k8temp_remove), |
328 | }; | 339 | }; |
329 | 340 | ||
330 | module_pci_driver(k8temp_driver); | 341 | static int __init k8temp_init(void) |
342 | { | ||
343 | return pci_register_driver(&k8temp_driver); | ||
344 | } | ||
345 | |||
346 | static void __exit k8temp_exit(void) | ||
347 | { | ||
348 | pci_unregister_driver(&k8temp_driver); | ||
349 | } | ||
331 | 350 | ||
332 | MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); | 351 | MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); |
333 | MODULE_DESCRIPTION("AMD K8 core temperature monitor"); | 352 | MODULE_DESCRIPTION("AMD K8 core temperature monitor"); |
334 | MODULE_LICENSE("GPL"); | 353 | MODULE_LICENSE("GPL"); |
354 | |||
355 | module_init(k8temp_init) | ||
356 | module_exit(k8temp_exit) | ||