diff options
author | Davide Rizzo <elpa.rizzo@gmail.com> | 2010-11-18 10:23:00 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2011-01-08 13:55:47 -0500 |
commit | 0f1deb4b820cfacf22492abd7b17e891dafc51ae (patch) | |
tree | a31792ed3546e5dbd292301dd212d84a5e581222 /drivers/hwmon | |
parent | 2bfe814826b7266a489895f731a777f8cbe37963 (diff) |
hwmon: (lm95241) Rewrite to avoid using macros
Signed-off-by: Davide Rizzo <elpa.rizzo@gmail.com>
[guenter.roeck@ericsson.com: Formatting changes]
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm95241.c | 495 |
1 files changed, 233 insertions, 262 deletions
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c index 4546d82f024a..1a6dfb6df1e7 100644 --- a/drivers/hwmon/lm95241.c +++ b/drivers/hwmon/lm95241.c | |||
@@ -1,13 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * lm95241.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com> |
3 | * monitoring | ||
4 | * Copyright (C) 2008 Davide Rizzo <elpa-rizzo@gmail.com> | ||
5 | * | 3 | * |
6 | * Based on the max1619 driver. The LM95241 is a sensor chip made by National | 4 | * The LM95241 is a sensor chip made by National Semiconductors. |
7 | * Semiconductors. | 5 | * It reports up to three temperatures (its own plus up to two external ones). |
8 | * It reports up to three temperatures (its own plus up to | 6 | * Complete datasheet can be obtained from National's website at: |
9 | * two external ones). Complete datasheet can be | ||
10 | * obtained from National's website at: | ||
11 | * http://www.national.com/ds.cgi/LM/LM95241.pdf | 7 | * http://www.national.com/ds.cgi/LM/LM95241.pdf |
12 | * | 8 | * |
13 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
@@ -36,8 +32,10 @@ | |||
36 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
37 | #include <linux/sysfs.h> | 33 | #include <linux/sysfs.h> |
38 | 34 | ||
35 | #define DEVNAME "lm95241" | ||
36 | |||
39 | static const unsigned short normal_i2c[] = { | 37 | static const unsigned short normal_i2c[] = { |
40 | 0x19, 0x2a, 0x2b, I2C_CLIENT_END}; | 38 | 0x19, 0x2a, 0x2b, I2C_CLIENT_END }; |
41 | 39 | ||
42 | /* LM95241 registers */ | 40 | /* LM95241 registers */ |
43 | #define LM95241_REG_R_MAN_ID 0xFE | 41 | #define LM95241_REG_R_MAN_ID 0xFE |
@@ -46,7 +44,7 @@ static const unsigned short normal_i2c[] = { | |||
46 | #define LM95241_REG_RW_CONFIG 0x03 | 44 | #define LM95241_REG_RW_CONFIG 0x03 |
47 | #define LM95241_REG_RW_REM_FILTER 0x06 | 45 | #define LM95241_REG_RW_REM_FILTER 0x06 |
48 | #define LM95241_REG_RW_TRUTHERM 0x07 | 46 | #define LM95241_REG_RW_TRUTHERM 0x07 |
49 | #define LM95241_REG_W_ONE_SHOT 0x0F | 47 | #define LM95241_REG_W_ONE_SHOT 0x0F |
50 | #define LM95241_REG_R_LOCAL_TEMPH 0x10 | 48 | #define LM95241_REG_R_LOCAL_TEMPH 0x10 |
51 | #define LM95241_REG_R_REMOTE1_TEMPH 0x11 | 49 | #define LM95241_REG_R_REMOTE1_TEMPH 0x11 |
52 | #define LM95241_REG_R_REMOTE2_TEMPH 0x12 | 50 | #define LM95241_REG_R_REMOTE2_TEMPH 0x12 |
@@ -79,235 +77,246 @@ static const unsigned short normal_i2c[] = { | |||
79 | #define MANUFACTURER_ID 0x01 | 77 | #define MANUFACTURER_ID 0x01 |
80 | #define DEFAULT_REVISION 0xA4 | 78 | #define DEFAULT_REVISION 0xA4 |
81 | 79 | ||
82 | /* Conversions and various macros */ | 80 | static const u8 lm95241_reg_address[] = { |
83 | #define TEMP_FROM_REG(val_h, val_l) (((val_h) & 0x80 ? (val_h) - 0x100 : \ | 81 | LM95241_REG_R_LOCAL_TEMPH, |
84 | (val_h)) * 1000 + (val_l) * 1000 / 256) | 82 | LM95241_REG_R_LOCAL_TEMPL, |
85 | 83 | LM95241_REG_R_REMOTE1_TEMPH, | |
86 | /* Functions declaration */ | 84 | LM95241_REG_R_REMOTE1_TEMPL, |
87 | static void lm95241_init_client(struct i2c_client *client); | 85 | LM95241_REG_R_REMOTE2_TEMPH, |
88 | static struct lm95241_data *lm95241_update_device(struct device *dev); | 86 | LM95241_REG_R_REMOTE2_TEMPL |
87 | }; | ||
89 | 88 | ||
90 | /* Client data (each client gets its own) */ | 89 | /* Client data (each client gets its own) */ |
91 | struct lm95241_data { | 90 | struct lm95241_data { |
92 | struct device *hwmon_dev; | 91 | struct device *hwmon_dev; |
93 | struct mutex update_lock; | 92 | struct mutex update_lock; |
94 | unsigned long last_updated, interval; /* in jiffies */ | 93 | unsigned long last_updated, interval; /* in jiffies */ |
95 | char valid; /* zero until following fields are valid */ | 94 | char valid; /* zero until following fields are valid */ |
96 | /* registers values */ | 95 | /* registers values */ |
97 | u8 local_h, local_l; /* local */ | 96 | u8 temp[ARRAY_SIZE(lm95241_reg_address)]; |
98 | u8 remote1_h, remote1_l; /* remote1 */ | ||
99 | u8 remote2_h, remote2_l; /* remote2 */ | ||
100 | u8 config, model, trutherm; | 97 | u8 config, model, trutherm; |
101 | }; | 98 | }; |
102 | 99 | ||
100 | /* Conversions */ | ||
101 | static int TempFromReg(u8 val_h, u8 val_l) | ||
102 | { | ||
103 | if (val_h & 0x80) | ||
104 | return val_h - 0x100; | ||
105 | return val_h * 1000 + val_l * 1000 / 256; | ||
106 | } | ||
107 | |||
108 | static struct lm95241_data *lm95241_update_device(struct device *dev) | ||
109 | { | ||
110 | struct i2c_client *client = to_i2c_client(dev); | ||
111 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
112 | |||
113 | mutex_lock(&data->update_lock); | ||
114 | |||
115 | if (time_after(jiffies, data->last_updated + data->interval) || | ||
116 | !data->valid) { | ||
117 | int i; | ||
118 | |||
119 | dev_dbg(&client->dev, "Updating lm95241 data.\n"); | ||
120 | for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) | ||
121 | data->temp[i] | ||
122 | = i2c_smbus_read_byte_data(client, | ||
123 | lm95241_reg_address[i]); | ||
124 | data->last_updated = jiffies; | ||
125 | data->valid = 1; | ||
126 | } | ||
127 | |||
128 | mutex_unlock(&data->update_lock); | ||
129 | |||
130 | return data; | ||
131 | } | ||
132 | |||
103 | /* Sysfs stuff */ | 133 | /* Sysfs stuff */ |
104 | #define show_temp(value) \ | 134 | static ssize_t show_input(struct device *dev, struct device_attribute *attr, |
105 | static ssize_t show_##value(struct device *dev, \ | 135 | char *buf) |
106 | struct device_attribute *attr, char *buf) \ | 136 | { |
107 | { \ | 137 | struct lm95241_data *data = lm95241_update_device(dev); |
108 | struct lm95241_data *data = lm95241_update_device(dev); \ | 138 | |
109 | snprintf(buf, PAGE_SIZE - 1, "%d\n", \ | 139 | return snprintf(buf, PAGE_SIZE - 1, "%d\n", |
110 | TEMP_FROM_REG(data->value##_h, data->value##_l)); \ | 140 | TempFromReg(data->temp[to_sensor_dev_attr(attr)->index], |
111 | return strlen(buf); \ | 141 | data->temp[to_sensor_dev_attr(attr)->index + 1])); |
112 | } | 142 | } |
113 | show_temp(local); | ||
114 | show_temp(remote1); | ||
115 | show_temp(remote2); | ||
116 | 143 | ||
117 | static ssize_t show_interval(struct device *dev, struct device_attribute *attr, | 144 | static ssize_t show_type(struct device *dev, struct device_attribute *attr, |
118 | char *buf) | 145 | char *buf) |
119 | { | 146 | { |
120 | struct lm95241_data *data = lm95241_update_device(dev); | 147 | struct i2c_client *client = to_i2c_client(dev); |
148 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
121 | 149 | ||
122 | snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval / HZ); | 150 | return snprintf(buf, PAGE_SIZE - 1, |
123 | return strlen(buf); | 151 | data->model & to_sensor_dev_attr(attr)->index ? "1\n" : "2\n"); |
124 | } | 152 | } |
125 | 153 | ||
126 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, | 154 | static ssize_t set_type(struct device *dev, struct device_attribute *attr, |
127 | const char *buf, size_t count) | 155 | const char *buf, size_t count) |
128 | { | 156 | { |
129 | struct i2c_client *client = to_i2c_client(dev); | 157 | struct i2c_client *client = to_i2c_client(dev); |
130 | struct lm95241_data *data = i2c_get_clientdata(client); | 158 | struct lm95241_data *data = i2c_get_clientdata(client); |
131 | unsigned long val; | 159 | unsigned long val; |
160 | int shift; | ||
161 | u8 mask = to_sensor_dev_attr(attr)->index; | ||
132 | 162 | ||
133 | if (strict_strtoul(buf, 10, &val) < 0) | 163 | if (strict_strtoul(buf, 10, &val) < 0) |
134 | return -EINVAL; | 164 | return -EINVAL; |
165 | if (val != 1 && val != 2) | ||
166 | return -EINVAL; | ||
135 | 167 | ||
136 | data->interval = val * HZ / 1000; | 168 | shift = mask == R1MS_MASK ? TT1_SHIFT : TT2_SHIFT; |
169 | |||
170 | mutex_lock(&data->update_lock); | ||
171 | |||
172 | data->trutherm &= ~(TT_MASK << shift); | ||
173 | if (val == 1) { | ||
174 | data->model |= mask; | ||
175 | data->trutherm |= (TT_ON << shift); | ||
176 | } else { | ||
177 | data->model &= ~mask; | ||
178 | data->trutherm |= (TT_OFF << shift); | ||
179 | } | ||
180 | data->valid = 0; | ||
181 | |||
182 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, | ||
183 | data->model); | ||
184 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, | ||
185 | data->trutherm); | ||
186 | |||
187 | mutex_unlock(&data->update_lock); | ||
137 | 188 | ||
138 | return count; | 189 | return count; |
139 | } | 190 | } |
140 | 191 | ||
141 | #define show_type(flag) \ | 192 | static ssize_t show_min(struct device *dev, struct device_attribute *attr, |
142 | static ssize_t show_type##flag(struct device *dev, \ | 193 | char *buf) |
143 | struct device_attribute *attr, char *buf) \ | 194 | { |
144 | { \ | 195 | struct i2c_client *client = to_i2c_client(dev); |
145 | struct i2c_client *client = to_i2c_client(dev); \ | 196 | struct lm95241_data *data = i2c_get_clientdata(client); |
146 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 197 | |
147 | \ | 198 | return snprintf(buf, PAGE_SIZE - 1, |
148 | snprintf(buf, PAGE_SIZE - 1, \ | 199 | data->config & to_sensor_dev_attr(attr)->index ? |
149 | data->model & R##flag##MS_MASK ? "1\n" : "2\n"); \ | 200 | "-127000\n" : "0\n"); |
150 | return strlen(buf); \ | ||
151 | } | 201 | } |
152 | show_type(1); | 202 | |
153 | show_type(2); | 203 | static ssize_t set_min(struct device *dev, struct device_attribute *attr, |
154 | 204 | const char *buf, size_t count) | |
155 | #define show_min(flag) \ | 205 | { |
156 | static ssize_t show_min##flag(struct device *dev, \ | 206 | struct i2c_client *client = to_i2c_client(dev); |
157 | struct device_attribute *attr, char *buf) \ | 207 | struct lm95241_data *data = i2c_get_clientdata(client); |
158 | { \ | 208 | long val; |
159 | struct i2c_client *client = to_i2c_client(dev); \ | 209 | |
160 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 210 | if (strict_strtol(buf, 10, &val) < 0) |
161 | \ | 211 | return -EINVAL; |
162 | snprintf(buf, PAGE_SIZE - 1, \ | 212 | if (val < -128000) |
163 | data->config & R##flag##DF_MASK ? \ | 213 | return -EINVAL; |
164 | "-127000\n" : "0\n"); \ | 214 | |
165 | return strlen(buf); \ | 215 | mutex_lock(&data->update_lock); |
216 | |||
217 | if (val < 0) | ||
218 | data->config |= to_sensor_dev_attr(attr)->index; | ||
219 | else | ||
220 | data->config &= ~to_sensor_dev_attr(attr)->index; | ||
221 | data->valid = 0; | ||
222 | |||
223 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); | ||
224 | |||
225 | mutex_unlock(&data->update_lock); | ||
226 | |||
227 | return count; | ||
166 | } | 228 | } |
167 | show_min(1); | 229 | |
168 | show_min(2); | 230 | static ssize_t show_max(struct device *dev, struct device_attribute *attr, |
169 | 231 | char *buf) | |
170 | #define show_max(flag) \ | 232 | { |
171 | static ssize_t show_max##flag(struct device *dev, \ | 233 | struct i2c_client *client = to_i2c_client(dev); |
172 | struct device_attribute *attr, char *buf) \ | 234 | struct lm95241_data *data = i2c_get_clientdata(client); |
173 | { \ | 235 | |
174 | struct i2c_client *client = to_i2c_client(dev); \ | 236 | return snprintf(buf, PAGE_SIZE - 1, |
175 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 237 | data->config & to_sensor_dev_attr(attr)->index ? |
176 | \ | 238 | "127000\n" : "255000\n"); |
177 | snprintf(buf, PAGE_SIZE - 1, \ | ||
178 | data->config & R##flag##DF_MASK ? \ | ||
179 | "127000\n" : "255000\n"); \ | ||
180 | return strlen(buf); \ | ||
181 | } | 239 | } |
182 | show_max(1); | 240 | |
183 | show_max(2); | 241 | static ssize_t set_max(struct device *dev, struct device_attribute *attr, |
184 | 242 | const char *buf, size_t count) | |
185 | #define set_type(flag) \ | 243 | { |
186 | static ssize_t set_type##flag(struct device *dev, \ | 244 | struct i2c_client *client = to_i2c_client(dev); |
187 | struct device_attribute *attr, \ | 245 | struct lm95241_data *data = i2c_get_clientdata(client); |
188 | const char *buf, size_t count) \ | 246 | long val; |
189 | { \ | 247 | |
190 | struct i2c_client *client = to_i2c_client(dev); \ | 248 | if (strict_strtol(buf, 10, &val) < 0) |
191 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 249 | return -EINVAL; |
192 | \ | 250 | if (val >= 256000) |
193 | long val; \ | 251 | return -EINVAL; |
194 | \ | 252 | |
195 | if (strict_strtol(buf, 10, &val) < 0) \ | 253 | mutex_lock(&data->update_lock); |
196 | return -EINVAL; \ | 254 | |
197 | \ | 255 | if (val <= 127000) |
198 | if ((val == 1) || (val == 2)) { \ | 256 | data->config |= to_sensor_dev_attr(attr)->index; |
199 | \ | 257 | else |
200 | mutex_lock(&data->update_lock); \ | 258 | data->config &= ~to_sensor_dev_attr(attr)->index; |
201 | \ | 259 | data->valid = 0; |
202 | data->trutherm &= ~(TT_MASK << TT##flag##_SHIFT); \ | 260 | |
203 | if (val == 1) { \ | 261 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); |
204 | data->model |= R##flag##MS_MASK; \ | 262 | |
205 | data->trutherm |= (TT_ON << TT##flag##_SHIFT); \ | 263 | mutex_unlock(&data->update_lock); |
206 | } \ | 264 | |
207 | else { \ | 265 | return count; |
208 | data->model &= ~R##flag##MS_MASK; \ | ||
209 | data->trutherm |= (TT_OFF << TT##flag##_SHIFT); \ | ||
210 | } \ | ||
211 | \ | ||
212 | data->valid = 0; \ | ||
213 | \ | ||
214 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, \ | ||
215 | data->model); \ | ||
216 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, \ | ||
217 | data->trutherm); \ | ||
218 | \ | ||
219 | mutex_unlock(&data->update_lock); \ | ||
220 | \ | ||
221 | } \ | ||
222 | return count; \ | ||
223 | } | 266 | } |
224 | set_type(1); | 267 | |
225 | set_type(2); | 268 | static ssize_t show_interval(struct device *dev, struct device_attribute *attr, |
226 | 269 | char *buf) | |
227 | #define set_min(flag) \ | 270 | { |
228 | static ssize_t set_min##flag(struct device *dev, \ | 271 | struct lm95241_data *data = lm95241_update_device(dev); |
229 | struct device_attribute *devattr, const char *buf, size_t count) \ | 272 | |
230 | { \ | 273 | return snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval |
231 | struct i2c_client *client = to_i2c_client(dev); \ | 274 | / HZ); |
232 | struct lm95241_data *data = i2c_get_clientdata(client); \ | ||
233 | \ | ||
234 | long val; \ | ||
235 | \ | ||
236 | if (strict_strtol(buf, 10, &val) < 0) \ | ||
237 | return -EINVAL;\ | ||
238 | \ | ||
239 | mutex_lock(&data->update_lock); \ | ||
240 | \ | ||
241 | if (val < 0) \ | ||
242 | data->config |= R##flag##DF_MASK; \ | ||
243 | else \ | ||
244 | data->config &= ~R##flag##DF_MASK; \ | ||
245 | \ | ||
246 | data->valid = 0; \ | ||
247 | \ | ||
248 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \ | ||
249 | data->config); \ | ||
250 | \ | ||
251 | mutex_unlock(&data->update_lock); \ | ||
252 | \ | ||
253 | return count; \ | ||
254 | } | 275 | } |
255 | set_min(1); | 276 | |
256 | set_min(2); | 277 | static ssize_t set_interval(struct device *dev, struct device_attribute *attr, |
257 | 278 | const char *buf, size_t count) | |
258 | #define set_max(flag) \ | 279 | { |
259 | static ssize_t set_max##flag(struct device *dev, \ | 280 | struct i2c_client *client = to_i2c_client(dev); |
260 | struct device_attribute *devattr, const char *buf, size_t count) \ | 281 | struct lm95241_data *data = i2c_get_clientdata(client); |
261 | { \ | 282 | unsigned long val; |
262 | struct i2c_client *client = to_i2c_client(dev); \ | 283 | |
263 | struct lm95241_data *data = i2c_get_clientdata(client); \ | 284 | if (strict_strtoul(buf, 10, &val) < 0) |
264 | \ | 285 | return -EINVAL; |
265 | long val; \ | 286 | |
266 | \ | 287 | data->interval = val * HZ / 1000; |
267 | if (strict_strtol(buf, 10, &val) < 0) \ | 288 | |
268 | return -EINVAL; \ | 289 | return count; |
269 | \ | ||
270 | mutex_lock(&data->update_lock); \ | ||
271 | \ | ||
272 | if (val <= 127000) \ | ||
273 | data->config |= R##flag##DF_MASK; \ | ||
274 | else \ | ||
275 | data->config &= ~R##flag##DF_MASK; \ | ||
276 | \ | ||
277 | data->valid = 0; \ | ||
278 | \ | ||
279 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, \ | ||
280 | data->config); \ | ||
281 | \ | ||
282 | mutex_unlock(&data->update_lock); \ | ||
283 | \ | ||
284 | return count; \ | ||
285 | } | 290 | } |
286 | set_max(1); | 291 | |
287 | set_max(2); | 292 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); |
288 | 293 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); | |
289 | static DEVICE_ATTR(temp1_input, S_IRUGO, show_local, NULL); | 294 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 4); |
290 | static DEVICE_ATTR(temp2_input, S_IRUGO, show_remote1, NULL); | 295 | static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type, |
291 | static DEVICE_ATTR(temp3_input, S_IRUGO, show_remote2, NULL); | 296 | R1MS_MASK); |
292 | static DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type1, set_type1); | 297 | static SENSOR_DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type, set_type, |
293 | static DEVICE_ATTR(temp3_type, S_IWUSR | S_IRUGO, show_type2, set_type2); | 298 | R2MS_MASK); |
294 | static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min1, set_min1); | 299 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min, set_min, |
295 | static DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min2, set_min2); | 300 | R1DF_MASK); |
296 | static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max1, set_max1); | 301 | static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min, set_min, |
297 | static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max2, set_max2); | 302 | R2DF_MASK); |
303 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max, set_max, | ||
304 | R1DF_MASK); | ||
305 | static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max, set_max, | ||
306 | R2DF_MASK); | ||
298 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, | 307 | static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, |
299 | set_interval); | 308 | set_interval); |
300 | 309 | ||
301 | static struct attribute *lm95241_attributes[] = { | 310 | static struct attribute *lm95241_attributes[] = { |
302 | &dev_attr_temp1_input.attr, | 311 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
303 | &dev_attr_temp2_input.attr, | 312 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
304 | &dev_attr_temp3_input.attr, | 313 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
305 | &dev_attr_temp2_type.attr, | 314 | &sensor_dev_attr_temp2_type.dev_attr.attr, |
306 | &dev_attr_temp3_type.attr, | 315 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
307 | &dev_attr_temp2_min.attr, | 316 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
308 | &dev_attr_temp3_min.attr, | 317 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
309 | &dev_attr_temp2_max.attr, | 318 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
310 | &dev_attr_temp3_max.attr, | 319 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
311 | &dev_attr_update_interval.attr, | 320 | &dev_attr_update_interval.attr, |
312 | NULL | 321 | NULL |
313 | }; | 322 | }; |
@@ -329,9 +338,9 @@ static int lm95241_detect(struct i2c_client *new_client, | |||
329 | 338 | ||
330 | if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) | 339 | if ((i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID) |
331 | == MANUFACTURER_ID) | 340 | == MANUFACTURER_ID) |
332 | && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) | 341 | && (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID) |
333 | >= DEFAULT_REVISION)) { | 342 | >= DEFAULT_REVISION)) { |
334 | name = "lm95241"; | 343 | name = DEVNAME; |
335 | } else { | 344 | } else { |
336 | dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n", | 345 | dev_dbg(&adapter->dev, "LM95241 detection failed at 0x%02x\n", |
337 | address); | 346 | address); |
@@ -343,6 +352,25 @@ static int lm95241_detect(struct i2c_client *new_client, | |||
343 | return 0; | 352 | return 0; |
344 | } | 353 | } |
345 | 354 | ||
355 | static void lm95241_init_client(struct i2c_client *client) | ||
356 | { | ||
357 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
358 | |||
359 | data->interval = HZ; /* 1 sec default */ | ||
360 | data->valid = 0; | ||
361 | data->config = CFG_CR0076; | ||
362 | data->model = 0; | ||
363 | data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); | ||
364 | |||
365 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); | ||
366 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER, | ||
367 | R1FE_MASK | R2FE_MASK); | ||
368 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, | ||
369 | data->trutherm); | ||
370 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, | ||
371 | data->model); | ||
372 | } | ||
373 | |||
346 | static int lm95241_probe(struct i2c_client *new_client, | 374 | static int lm95241_probe(struct i2c_client *new_client, |
347 | const struct i2c_device_id *id) | 375 | const struct i2c_device_id *id) |
348 | { | 376 | { |
@@ -382,26 +410,6 @@ exit: | |||
382 | return err; | 410 | return err; |
383 | } | 411 | } |
384 | 412 | ||
385 | static void lm95241_init_client(struct i2c_client *client) | ||
386 | { | ||
387 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
388 | |||
389 | data->interval = HZ; /* 1 sec default */ | ||
390 | data->valid = 0; | ||
391 | data->config = CFG_CR0076; | ||
392 | data->model = 0; | ||
393 | data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); | ||
394 | |||
395 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, | ||
396 | data->config); | ||
397 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER, | ||
398 | R1FE_MASK | R2FE_MASK); | ||
399 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, | ||
400 | data->trutherm); | ||
401 | i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, | ||
402 | data->model); | ||
403 | } | ||
404 | |||
405 | static int lm95241_remove(struct i2c_client *client) | 413 | static int lm95241_remove(struct i2c_client *client) |
406 | { | 414 | { |
407 | struct lm95241_data *data = i2c_get_clientdata(client); | 415 | struct lm95241_data *data = i2c_get_clientdata(client); |
@@ -413,46 +421,9 @@ static int lm95241_remove(struct i2c_client *client) | |||
413 | return 0; | 421 | return 0; |
414 | } | 422 | } |
415 | 423 | ||
416 | static struct lm95241_data *lm95241_update_device(struct device *dev) | ||
417 | { | ||
418 | struct i2c_client *client = to_i2c_client(dev); | ||
419 | struct lm95241_data *data = i2c_get_clientdata(client); | ||
420 | |||
421 | mutex_lock(&data->update_lock); | ||
422 | |||
423 | if (time_after(jiffies, data->last_updated + data->interval) || | ||
424 | !data->valid) { | ||
425 | dev_dbg(&client->dev, "Updating lm95241 data.\n"); | ||
426 | data->local_h = | ||
427 | i2c_smbus_read_byte_data(client, | ||
428 | LM95241_REG_R_LOCAL_TEMPH); | ||
429 | data->local_l = | ||
430 | i2c_smbus_read_byte_data(client, | ||
431 | LM95241_REG_R_LOCAL_TEMPL); | ||
432 | data->remote1_h = | ||
433 | i2c_smbus_read_byte_data(client, | ||
434 | LM95241_REG_R_REMOTE1_TEMPH); | ||
435 | data->remote1_l = | ||
436 | i2c_smbus_read_byte_data(client, | ||
437 | LM95241_REG_R_REMOTE1_TEMPL); | ||
438 | data->remote2_h = | ||
439 | i2c_smbus_read_byte_data(client, | ||
440 | LM95241_REG_R_REMOTE2_TEMPH); | ||
441 | data->remote2_l = | ||
442 | i2c_smbus_read_byte_data(client, | ||
443 | LM95241_REG_R_REMOTE2_TEMPL); | ||
444 | data->last_updated = jiffies; | ||
445 | data->valid = 1; | ||
446 | } | ||
447 | |||
448 | mutex_unlock(&data->update_lock); | ||
449 | |||
450 | return data; | ||
451 | } | ||
452 | |||
453 | /* Driver data (common to all clients) */ | 424 | /* Driver data (common to all clients) */ |
454 | static const struct i2c_device_id lm95241_id[] = { | 425 | static const struct i2c_device_id lm95241_id[] = { |
455 | { "lm95241", 0 }, | 426 | { DEVNAME, 0 }, |
456 | { } | 427 | { } |
457 | }; | 428 | }; |
458 | MODULE_DEVICE_TABLE(i2c, lm95241_id); | 429 | MODULE_DEVICE_TABLE(i2c, lm95241_id); |
@@ -460,7 +431,7 @@ MODULE_DEVICE_TABLE(i2c, lm95241_id); | |||
460 | static struct i2c_driver lm95241_driver = { | 431 | static struct i2c_driver lm95241_driver = { |
461 | .class = I2C_CLASS_HWMON, | 432 | .class = I2C_CLASS_HWMON, |
462 | .driver = { | 433 | .driver = { |
463 | .name = "lm95241", | 434 | .name = DEVNAME, |
464 | }, | 435 | }, |
465 | .probe = lm95241_probe, | 436 | .probe = lm95241_probe, |
466 | .remove = lm95241_remove, | 437 | .remove = lm95241_remove, |
@@ -479,7 +450,7 @@ static void __exit sensors_lm95241_exit(void) | |||
479 | i2c_del_driver(&lm95241_driver); | 450 | i2c_del_driver(&lm95241_driver); |
480 | } | 451 | } |
481 | 452 | ||
482 | MODULE_AUTHOR("Davide Rizzo <elpa-rizzo@gmail.com>"); | 453 | MODULE_AUTHOR("Davide Rizzo <elpa.rizzo@gmail.com>"); |
483 | MODULE_DESCRIPTION("LM95241 sensor driver"); | 454 | MODULE_DESCRIPTION("LM95241 sensor driver"); |
484 | MODULE_LICENSE("GPL"); | 455 | MODULE_LICENSE("GPL"); |
485 | 456 | ||