diff options
Diffstat (limited to 'drivers/hwmon/w83l785ts.c')
-rw-r--r-- | drivers/hwmon/w83l785ts.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c index 133e34ab1d0a..f495b6378668 100644 --- a/drivers/hwmon/w83l785ts.c +++ b/drivers/hwmon/w83l785ts.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/jiffies.h> | 37 | #include <linux/jiffies.h> |
38 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
39 | #include <linux/hwmon.h> | 39 | #include <linux/hwmon.h> |
40 | #include <linux/hwmon-sysfs.h> | ||
40 | #include <linux/err.h> | 41 | #include <linux/err.h> |
41 | 42 | ||
42 | /* How many retries on register read error */ | 43 | /* How many retries on register read error */ |
@@ -73,7 +74,7 @@ I2C_CLIENT_INSMOD_1(w83l785ts); | |||
73 | * The W83L785TS-S uses signed 8-bit values. | 74 | * The W83L785TS-S uses signed 8-bit values. |
74 | */ | 75 | */ |
75 | 76 | ||
76 | #define TEMP_FROM_REG(val) ((val & 0x80 ? val-0x100 : val) * 1000) | 77 | #define TEMP_FROM_REG(val) ((val) * 1000) |
77 | 78 | ||
78 | /* | 79 | /* |
79 | * Functions declaration | 80 | * Functions declaration |
@@ -111,27 +112,24 @@ struct w83l785ts_data { | |||
111 | unsigned long last_updated; /* in jiffies */ | 112 | unsigned long last_updated; /* in jiffies */ |
112 | 113 | ||
113 | /* registers values */ | 114 | /* registers values */ |
114 | u8 temp, temp_over; | 115 | s8 temp[2]; /* 0: input |
116 | 1: critical limit */ | ||
115 | }; | 117 | }; |
116 | 118 | ||
117 | /* | 119 | /* |
118 | * Sysfs stuff | 120 | * Sysfs stuff |
119 | */ | 121 | */ |
120 | 122 | ||
121 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) | 123 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
124 | char *buf) | ||
122 | { | 125 | { |
126 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
123 | struct w83l785ts_data *data = w83l785ts_update_device(dev); | 127 | struct w83l785ts_data *data = w83l785ts_update_device(dev); |
124 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); | 128 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index])); |
125 | } | 129 | } |
126 | 130 | ||
127 | static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, char *buf) | 131 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); |
128 | { | 132 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, 1); |
129 | struct w83l785ts_data *data = w83l785ts_update_device(dev); | ||
130 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); | ||
131 | } | ||
132 | |||
133 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL); | ||
134 | static DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_over, NULL); | ||
135 | 133 | ||
136 | /* | 134 | /* |
137 | * Real code | 135 | * Real code |
@@ -158,12 +156,10 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
158 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 156 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
159 | goto exit; | 157 | goto exit; |
160 | 158 | ||
161 | if (!(data = kmalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) { | 159 | if (!(data = kzalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) { |
162 | err = -ENOMEM; | 160 | err = -ENOMEM; |
163 | goto exit; | 161 | goto exit; |
164 | } | 162 | } |
165 | memset(data, 0, sizeof(struct w83l785ts_data)); | ||
166 | |||
167 | 163 | ||
168 | /* The common I2C client data is placed right before the | 164 | /* The common I2C client data is placed right before the |
169 | * W83L785TS-specific data. */ | 165 | * W83L785TS-specific data. */ |
@@ -228,7 +224,7 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
228 | init_MUTEX(&data->update_lock); | 224 | init_MUTEX(&data->update_lock); |
229 | 225 | ||
230 | /* Default values in case the first read fails (unlikely). */ | 226 | /* Default values in case the first read fails (unlikely). */ |
231 | data->temp_over = data->temp = 0; | 227 | data->temp[1] = data->temp[0] = 0; |
232 | 228 | ||
233 | /* Tell the I2C layer a new client has arrived. */ | 229 | /* Tell the I2C layer a new client has arrived. */ |
234 | if ((err = i2c_attach_client(new_client))) | 230 | if ((err = i2c_attach_client(new_client))) |
@@ -246,8 +242,10 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind) | |||
246 | goto exit_detach; | 242 | goto exit_detach; |
247 | } | 243 | } |
248 | 244 | ||
249 | device_create_file(&new_client->dev, &dev_attr_temp1_input); | 245 | device_create_file(&new_client->dev, |
250 | device_create_file(&new_client->dev, &dev_attr_temp1_max); | 246 | &sensor_dev_attr_temp1_input.dev_attr); |
247 | device_create_file(&new_client->dev, | ||
248 | &sensor_dev_attr_temp1_max.dev_attr); | ||
251 | 249 | ||
252 | return 0; | 250 | return 0; |
253 | 251 | ||
@@ -305,10 +303,10 @@ static struct w83l785ts_data *w83l785ts_update_device(struct device *dev) | |||
305 | 303 | ||
306 | if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) { | 304 | if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) { |
307 | dev_dbg(&client->dev, "Updating w83l785ts data.\n"); | 305 | dev_dbg(&client->dev, "Updating w83l785ts data.\n"); |
308 | data->temp = w83l785ts_read_value(client, | 306 | data->temp[0] = w83l785ts_read_value(client, |
309 | W83L785TS_REG_TEMP, data->temp); | 307 | W83L785TS_REG_TEMP, data->temp[0]); |
310 | data->temp_over = w83l785ts_read_value(client, | 308 | data->temp[1] = w83l785ts_read_value(client, |
311 | W83L785TS_REG_TEMP_OVER, data->temp_over); | 309 | W83L785TS_REG_TEMP_OVER, data->temp[1]); |
312 | 310 | ||
313 | data->last_updated = jiffies; | 311 | data->last_updated = jiffies; |
314 | data->valid = 1; | 312 | data->valid = 1; |