aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/i5500_temp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/i5500_temp.c')
-rw-r--r--drivers/hwmon/i5500_temp.c73
1 files changed, 15 insertions, 58 deletions
diff --git a/drivers/hwmon/i5500_temp.c b/drivers/hwmon/i5500_temp.c
index cbc822dec942..fdcfa9fcf5c4 100644
--- a/drivers/hwmon/i5500_temp.c
+++ b/drivers/hwmon/i5500_temp.c
@@ -18,6 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/jiffies.h> 20#include <linux/jiffies.h>
21#include <linux/device.h>
21#include <linux/pci.h> 22#include <linux/pci.h>
22#include <linux/hwmon.h> 23#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h> 24#include <linux/hwmon-sysfs.h>
@@ -37,11 +38,6 @@
37#define REG_CTCTRL 0xF7 38#define REG_CTCTRL 0xF7
38#define REG_TSTIMER 0xF8 39#define REG_TSTIMER 0xF8
39 40
40struct i5500_temp_data {
41 struct device *hwmon_dev;
42 const char *name;
43};
44
45/* 41/*
46 * Sysfs stuff 42 * Sysfs stuff
47 */ 43 */
@@ -50,7 +46,7 @@ struct i5500_temp_data {
50static ssize_t show_temp(struct device *dev, 46static ssize_t show_temp(struct device *dev,
51 struct device_attribute *devattr, char *buf) 47 struct device_attribute *devattr, char *buf)
52{ 48{
53 struct pci_dev *pdev = to_pci_dev(dev); 49 struct pci_dev *pdev = to_pci_dev(dev->parent);
54 long temp; 50 long temp;
55 u16 tsthrhi; 51 u16 tsthrhi;
56 s8 tsfsc; 52 s8 tsfsc;
@@ -65,7 +61,7 @@ static ssize_t show_temp(struct device *dev,
65static ssize_t show_thresh(struct device *dev, 61static ssize_t show_thresh(struct device *dev,
66 struct device_attribute *devattr, char *buf) 62 struct device_attribute *devattr, char *buf)
67{ 63{
68 struct pci_dev *pdev = to_pci_dev(dev); 64 struct pci_dev *pdev = to_pci_dev(dev->parent);
69 int reg = to_sensor_dev_attr(devattr)->index; 65 int reg = to_sensor_dev_attr(devattr)->index;
70 long temp; 66 long temp;
71 u16 tsthr; 67 u16 tsthr;
@@ -79,7 +75,7 @@ static ssize_t show_thresh(struct device *dev,
79static ssize_t show_alarm(struct device *dev, 75static ssize_t show_alarm(struct device *dev,
80 struct device_attribute *devattr, char *buf) 76 struct device_attribute *devattr, char *buf)
81{ 77{
82 struct pci_dev *pdev = to_pci_dev(dev); 78 struct pci_dev *pdev = to_pci_dev(dev->parent);
83 int nr = to_sensor_dev_attr(devattr)->index; 79 int nr = to_sensor_dev_attr(devattr)->index;
84 u8 ctsts; 80 u8 ctsts;
85 81
@@ -87,21 +83,12 @@ static ssize_t show_alarm(struct device *dev,
87 return sprintf(buf, "%u\n", (unsigned int)ctsts & (1 << nr)); 83 return sprintf(buf, "%u\n", (unsigned int)ctsts & (1 << nr));
88} 84}
89 85
90static ssize_t show_name(struct device *dev, struct device_attribute
91 *devattr, char *buf)
92{
93 struct i5500_temp_data *data = dev_get_drvdata(dev);
94
95 return sprintf(buf, "%s\n", data->name);
96}
97
98static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); 86static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
99static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_thresh, NULL, 0xE2); 87static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_thresh, NULL, 0xE2);
100static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_thresh, NULL, 0xEC); 88static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_thresh, NULL, 0xEC);
101static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_thresh, NULL, 0xEE); 89static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_thresh, NULL, 0xEE);
102static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); 90static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
103static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1); 91static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
104static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
105 92
106static struct attribute *i5500_temp_attributes[] = { 93static struct attribute *i5500_temp_attributes[] = {
107 &dev_attr_temp1_input.attr, 94 &dev_attr_temp1_input.attr,
@@ -110,7 +97,6 @@ static struct attribute *i5500_temp_attributes[] = {
110 &sensor_dev_attr_temp1_max.dev_attr.attr, 97 &sensor_dev_attr_temp1_max.dev_attr.attr,
111 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, 98 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
112 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 99 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
113 &dev_attr_name.attr,
114 NULL 100 NULL
115}; 101};
116 102
@@ -118,6 +104,11 @@ static const struct attribute_group i5500_temp_group = {
118 .attrs = i5500_temp_attributes, 104 .attrs = i5500_temp_attributes,
119}; 105};
120 106
107static const struct attribute_group *i5500_temp_groups[] = {
108 &i5500_temp_group,
109 NULL
110};
111
121static const struct pci_device_id i5500_temp_ids[] = { 112static const struct pci_device_id i5500_temp_ids[] = {
122 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3438) }, 113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x3438) },
123 { 0 }, 114 { 0 },
@@ -129,58 +120,24 @@ static int i5500_temp_probe(struct pci_dev *pdev,
129 const struct pci_device_id *id) 120 const struct pci_device_id *id)
130{ 121{
131 int err; 122 int err;
132 struct i5500_temp_data *data; 123 struct device *hwmon_dev;
133
134 data = kzalloc(sizeof(struct i5500_temp_data), GFP_KERNEL);
135 if (!data) {
136 err = -ENOMEM;
137 goto exit;
138 }
139
140 data->name = "intel5500";
141 dev_set_drvdata(&pdev->dev, data);
142 124
143 err = pci_enable_device(pdev); 125 err = pci_enable_device(pdev);
144 if (err) { 126 if (err) {
145 dev_err(&pdev->dev, "Failed to enable device\n"); 127 dev_err(&pdev->dev, "Failed to enable device\n");
146 goto exit_free; 128 return err;
147 }
148
149 /* Register sysfs hooks */
150 err = sysfs_create_group(&pdev->dev.kobj, &i5500_temp_group);
151 if (err)
152 goto exit_free;
153
154 data->hwmon_dev = hwmon_device_register(&pdev->dev);
155 if (IS_ERR(data->hwmon_dev)) {
156 err = PTR_ERR(data->hwmon_dev);
157 goto exit_remove;
158 } 129 }
159 130
160 return 0; 131 hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev,
161 132 "intel5500", NULL,
162 exit_remove: 133 i5500_temp_groups);
163 sysfs_remove_group(&pdev->dev.kobj, &i5500_temp_group); 134 return PTR_ERR_OR_ZERO(hwmon_dev);
164 exit_free:
165 kfree(data);
166 exit:
167 return err;
168}
169
170static void i5500_temp_remove(struct pci_dev *pdev)
171{
172 struct i5500_temp_data *data = dev_get_drvdata(&pdev->dev);
173
174 hwmon_device_unregister(data->hwmon_dev);
175 sysfs_remove_group(&pdev->dev.kobj, &i5500_temp_group);
176 kfree(data);
177} 135}
178 136
179static struct pci_driver i5500_temp_driver = { 137static struct pci_driver i5500_temp_driver = {
180 .name = "i5500_temp", 138 .name = "i5500_temp",
181 .id_table = i5500_temp_ids, 139 .id_table = i5500_temp_ids,
182 .probe = i5500_temp_probe, 140 .probe = i5500_temp_probe,
183 .remove = i5500_temp_remove,
184}; 141};
185 142
186static int __init i5500_temp_init(void) 143static int __init i5500_temp_init(void)