2 smsc47m192.c - Support for hardware monitoring block of
3 SMSC LPC47M192 and compatible Super I/O chips
5 Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de>
7 Derived from lm78.c and other chip drivers.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/jiffies.h>
28 #include <linux/i2c.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
31 #include <linux/hwmon-vid.h>
32 #include <linux/err.h>
33 #include <linux/sysfs.h>
34 #include <linux/mutex.h>
36 /* Addresses to scan */
37 <<<<<<< HEAD
:drivers
/hwmon
/smsc47m192
.c
38 static unsigned short normal_i2c
[] = { 0x2c, 0x2d, I2C_CLIENT_END
};
40 static const unsigned short normal_i2c
[] = { 0x2c, 0x2d, I2C_CLIENT_END
};
41 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/hwmon
/smsc47m192
.c
43 /* Insmod parameters */
44 I2C_CLIENT_INSMOD_1(smsc47m192
);
46 /* SMSC47M192 registers */
47 #define SMSC47M192_REG_IN(nr) ((nr)<6 ? (0x20 + (nr)) : \
49 #define SMSC47M192_REG_IN_MAX(nr) ((nr)<6 ? (0x2b + (nr) * 2) : \
50 (0x54 + (((nr) - 6) * 2)))
51 #define SMSC47M192_REG_IN_MIN(nr) ((nr)<6 ? (0x2c + (nr) * 2) : \
52 (0x55 + (((nr) - 6) * 2)))
53 static u8 SMSC47M192_REG_TEMP
[3] = { 0x27, 0x26, 0x52 };
54 static u8 SMSC47M192_REG_TEMP_MAX
[3] = { 0x39, 0x37, 0x58 };
55 static u8 SMSC47M192_REG_TEMP_MIN
[3] = { 0x3A, 0x38, 0x59 };
56 #define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr)==2 ? 0x1e : 0x1f)
57 #define SMSC47M192_REG_ALARM1 0x41
58 #define SMSC47M192_REG_ALARM2 0x42
59 #define SMSC47M192_REG_VID 0x47
60 #define SMSC47M192_REG_VID4 0x49
61 #define SMSC47M192_REG_CONFIG 0x40
62 #define SMSC47M192_REG_SFR 0x4f
63 #define SMSC47M192_REG_COMPANY_ID 0x3e
64 #define SMSC47M192_REG_VERSION 0x3f
66 /* generalised scaling with integer rounding */
67 static inline int SCALE(long val
, int mul
, int div
)
70 return (val
* mul
- div
/ 2) / div
;
72 return (val
* mul
+ div
/ 2) / div
;
77 /* smsc47m192 internally scales voltage measurements */
78 static const u16 nom_mv
[] = { 2500, 2250, 3300, 5000, 12000, 3300, 1500, 1800 };
80 static inline unsigned int IN_FROM_REG(u8 reg
, int n
)
82 return SCALE(reg
, nom_mv
[n
], 192);
85 static inline u8
IN_TO_REG(unsigned long val
, int n
)
87 return SENSORS_LIMIT(SCALE(val
, 192, nom_mv
[n
]), 0, 255);
90 /* TEMP: 0.001 degC units (-128C to +127C)
91 REG: 1C/bit, two's complement */
92 static inline s8
TEMP_TO_REG(int val
)
94 return SENSORS_LIMIT(SCALE(val
, 1, 1000), -128000, 127000);
97 static inline int TEMP_FROM_REG(s8 val
)
102 struct smsc47m192_data
{
103 struct i2c_client client
;
104 struct device
*hwmon_dev
;
105 struct mutex update_lock
;
106 char valid
; /* !=0 if following fields are valid */
107 unsigned long last_updated
; /* In jiffies */
109 u8 in
[8]; /* Register value */
110 u8 in_max
[8]; /* Register value */
111 u8 in_min
[8]; /* Register value */
112 s8 temp
[3]; /* Register value */
113 s8 temp_max
[3]; /* Register value */
114 s8 temp_min
[3]; /* Register value */
115 s8 temp_offset
[3]; /* Register value */
116 u16 alarms
; /* Register encoding, combined */
117 u8 vid
; /* Register encoding, combined */
121 static int smsc47m192_attach_adapter(struct i2c_adapter
*adapter
);
122 static int smsc47m192_detect(struct i2c_adapter
*adapter
, int address
,
124 static int smsc47m192_detach_client(struct i2c_client
*client
);
125 static struct smsc47m192_data
*smsc47m192_update_device(struct device
*dev
);
127 static struct i2c_driver smsc47m192_driver
= {
129 .name
= "smsc47m192",
131 .attach_adapter
= smsc47m192_attach_adapter
,
132 .detach_client
= smsc47m192_detach_client
,
136 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
139 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
140 int nr
= sensor_attr
->index
;
141 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
142 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in
[nr
], nr
));
145 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
148 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
149 int nr
= sensor_attr
->index
;
150 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
151 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_min
[nr
], nr
));
154 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
157 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
158 int nr
= sensor_attr
->index
;
159 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
160 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_max
[nr
], nr
));
163 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
164 const char *buf
, size_t count
)
166 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
167 int nr
= sensor_attr
->index
;
168 struct i2c_client
*client
= to_i2c_client(dev
);
169 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
170 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
172 mutex_lock(&data
->update_lock
);
173 data
->in_min
[nr
] = IN_TO_REG(val
, nr
);
174 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_IN_MIN(nr
),
176 mutex_unlock(&data
->update_lock
);
180 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
181 const char *buf
, size_t count
)
183 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
184 int nr
= sensor_attr
->index
;
185 struct i2c_client
*client
= to_i2c_client(dev
);
186 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
187 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
189 mutex_lock(&data
->update_lock
);
190 data
->in_max
[nr
] = IN_TO_REG(val
, nr
);
191 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_IN_MAX(nr
),
193 mutex_unlock(&data
->update_lock
);
197 #define show_in_offset(offset) \
198 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
199 show_in, NULL, offset); \
200 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
201 show_in_min, set_in_min, offset); \
202 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
203 show_in_max, set_in_max, offset);
215 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
218 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
219 int nr
= sensor_attr
->index
;
220 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
221 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
224 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*attr
,
227 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
228 int nr
= sensor_attr
->index
;
229 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
230 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_min
[nr
]));
233 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
236 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
237 int nr
= sensor_attr
->index
;
238 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
239 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max
[nr
]));
242 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*attr
,
243 const char *buf
, size_t count
)
245 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
246 int nr
= sensor_attr
->index
;
247 struct i2c_client
*client
= to_i2c_client(dev
);
248 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
249 long val
= simple_strtol(buf
, NULL
, 10);
251 mutex_lock(&data
->update_lock
);
252 data
->temp_min
[nr
] = TEMP_TO_REG(val
);
253 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_TEMP_MIN
[nr
],
255 mutex_unlock(&data
->update_lock
);
259 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
260 const char *buf
, size_t count
)
262 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
263 int nr
= sensor_attr
->index
;
264 struct i2c_client
*client
= to_i2c_client(dev
);
265 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
266 long val
= simple_strtol(buf
, NULL
, 10);
268 mutex_lock(&data
->update_lock
);
269 data
->temp_max
[nr
] = TEMP_TO_REG(val
);
270 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_TEMP_MAX
[nr
],
272 mutex_unlock(&data
->update_lock
);
276 static ssize_t
show_temp_offset(struct device
*dev
, struct device_attribute
279 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
280 int nr
= sensor_attr
->index
;
281 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
282 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_offset
[nr
]));
285 static ssize_t
set_temp_offset(struct device
*dev
, struct device_attribute
286 *attr
, const char *buf
, size_t count
)
288 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
289 int nr
= sensor_attr
->index
;
290 struct i2c_client
*client
= to_i2c_client(dev
);
291 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
292 u8 sfr
= i2c_smbus_read_byte_data(client
, SMSC47M192_REG_SFR
);
293 long val
= simple_strtol(buf
, NULL
, 10);
295 mutex_lock(&data
->update_lock
);
296 data
->temp_offset
[nr
] = TEMP_TO_REG(val
);
298 i2c_smbus_write_byte_data(client
,
299 SMSC47M192_REG_TEMP_OFFSET(nr
), data
->temp_offset
[nr
]);
300 else if (data
->temp_offset
[nr
] != 0) {
301 /* offset[0] and offset[1] share the same register,
302 SFR bit 4 activates offset[0] */
303 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_SFR
,
304 (sfr
& 0xef) | (nr
==0 ? 0x10 : 0));
305 data
->temp_offset
[1-nr
] = 0;
306 i2c_smbus_write_byte_data(client
,
307 SMSC47M192_REG_TEMP_OFFSET(nr
), data
->temp_offset
[nr
]);
308 } else if ((sfr
& 0x10) == (nr
==0 ? 0x10 : 0))
309 i2c_smbus_write_byte_data(client
,
310 SMSC47M192_REG_TEMP_OFFSET(nr
), 0);
311 mutex_unlock(&data
->update_lock
);
315 #define show_temp_index(index) \
316 static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, \
317 show_temp, NULL, index-1); \
318 static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR, \
319 show_temp_min, set_temp_min, index-1); \
320 static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR, \
321 show_temp_max, set_temp_max, index-1); \
322 static SENSOR_DEVICE_ATTR(temp##index##_offset, S_IRUGO | S_IWUSR, \
323 show_temp_offset, set_temp_offset, index-1);
330 static ssize_t
show_vid(struct device
*dev
, struct device_attribute
*attr
,
333 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
334 return sprintf(buf
, "%d\n", vid_from_reg(data
->vid
, data
->vrm
));
336 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
338 static ssize_t
show_vrm(struct device
*dev
, struct device_attribute
*attr
,
341 struct smsc47m192_data
*data
= dev_get_drvdata(dev
);
342 return sprintf(buf
, "%d\n", data
->vrm
);
345 static ssize_t
set_vrm(struct device
*dev
, struct device_attribute
*attr
,
346 const char *buf
, size_t count
)
348 struct smsc47m192_data
*data
= dev_get_drvdata(dev
);
349 data
->vrm
= simple_strtoul(buf
, NULL
, 10);
352 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm
, set_vrm
);
355 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*attr
,
358 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
359 int nr
= sensor_attr
->index
;
360 struct smsc47m192_data
*data
= smsc47m192_update_device(dev
);
361 return sprintf(buf
, "%u\n", (data
->alarms
& nr
) ? 1 : 0);
364 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0010);
365 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0020);
366 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0040);
367 static SENSOR_DEVICE_ATTR(temp2_fault
, S_IRUGO
, show_alarm
, NULL
, 0x4000);
368 static SENSOR_DEVICE_ATTR(temp3_fault
, S_IRUGO
, show_alarm
, NULL
, 0x8000);
369 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0001);
370 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0002);
371 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0004);
372 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0008);
373 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0100);
374 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0200);
375 static SENSOR_DEVICE_ATTR(in6_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0400);
376 static SENSOR_DEVICE_ATTR(in7_alarm
, S_IRUGO
, show_alarm
, NULL
, 0x0800);
378 static struct attribute
*smsc47m192_attributes
[] = {
379 &sensor_dev_attr_in0_input
.dev_attr
.attr
,
380 &sensor_dev_attr_in0_min
.dev_attr
.attr
,
381 &sensor_dev_attr_in0_max
.dev_attr
.attr
,
382 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
383 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
384 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
385 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
386 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
387 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
388 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
389 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
390 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
391 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
392 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
393 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
394 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
395 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
396 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
397 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
398 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
399 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
400 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
401 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
402 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
403 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
404 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
405 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
406 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
408 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
409 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
410 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
411 &sensor_dev_attr_temp1_offset
.dev_attr
.attr
,
412 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
413 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
414 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
415 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
416 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
417 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
418 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
419 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
420 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
421 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
422 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
423 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
424 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
426 &dev_attr_cpu0_vid
.attr
,
431 static const struct attribute_group smsc47m192_group
= {
432 .attrs
= smsc47m192_attributes
,
435 static struct attribute
*smsc47m192_attributes_in4
[] = {
436 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
437 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
438 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
439 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
443 static const struct attribute_group smsc47m192_group_in4
= {
444 .attrs
= smsc47m192_attributes_in4
,
447 /* This function is called when:
448 * smsc47m192_driver is inserted (when this module is loaded), for each
450 * when a new adapter is inserted (and smsc47m192_driver is still present) */
451 static int smsc47m192_attach_adapter(struct i2c_adapter
*adapter
)
453 if (!(adapter
->class & I2C_CLASS_HWMON
))
455 return i2c_probe(adapter
, &addr_data
, smsc47m192_detect
);
458 static void smsc47m192_init_client(struct i2c_client
*client
)
461 u8 config
= i2c_smbus_read_byte_data(client
, SMSC47M192_REG_CONFIG
);
462 u8 sfr
= i2c_smbus_read_byte_data(client
, SMSC47M192_REG_SFR
);
464 /* select cycle mode (pause 1 sec between updates) */
465 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_SFR
,
466 (sfr
& 0xfd) | 0x02);
467 if (!(config
& 0x01)) {
468 /* initialize alarm limits */
469 for (i
=0; i
<8; i
++) {
470 i2c_smbus_write_byte_data(client
,
471 SMSC47M192_REG_IN_MIN(i
), 0);
472 i2c_smbus_write_byte_data(client
,
473 SMSC47M192_REG_IN_MAX(i
), 0xff);
475 for (i
=0; i
<3; i
++) {
476 i2c_smbus_write_byte_data(client
,
477 SMSC47M192_REG_TEMP_MIN
[i
], 0x80);
478 i2c_smbus_write_byte_data(client
,
479 SMSC47M192_REG_TEMP_MAX
[i
], 0x7f);
482 /* start monitoring */
483 i2c_smbus_write_byte_data(client
, SMSC47M192_REG_CONFIG
,
484 (config
& 0xf7) | 0x01);
488 /* This function is called by i2c_probe */
489 static int smsc47m192_detect(struct i2c_adapter
*adapter
, int address
,
492 struct i2c_client
*client
;
493 struct smsc47m192_data
*data
;
497 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
500 if (!(data
= kzalloc(sizeof(struct smsc47m192_data
), GFP_KERNEL
))) {
505 client
= &data
->client
;
506 i2c_set_clientdata(client
, data
);
507 client
->addr
= address
;
508 client
->adapter
= adapter
;
509 client
->driver
= &smsc47m192_driver
;
514 /* Detection criteria from sensors_detect script */
516 if (i2c_smbus_read_byte_data(client
,
517 SMSC47M192_REG_COMPANY_ID
) == 0x55
518 && ((version
= i2c_smbus_read_byte_data(client
,
519 SMSC47M192_REG_VERSION
)) & 0xf0) == 0x20
520 && (i2c_smbus_read_byte_data(client
,
521 SMSC47M192_REG_VID
) & 0x70) == 0x00
522 && (i2c_smbus_read_byte_data(client
,
523 SMSC47M192_REG_VID4
) & 0xfe) == 0x80) {
524 dev_info(&adapter
->dev
,
525 "found SMSC47M192 or compatible, "
526 "version 2, stepping A%d\n", version
& 0x0f);
528 dev_dbg(&adapter
->dev
,
529 "SMSC47M192 detection failed at 0x%02x\n",
535 /* Fill in the remaining client fields and put into the global list */
536 strlcpy(client
->name
, "smsc47m192", I2C_NAME_SIZE
);
537 data
->vrm
= vid_which_vrm();
538 mutex_init(&data
->update_lock
);
540 /* Tell the I2C layer a new client has arrived */
541 if ((err
= i2c_attach_client(client
)))
544 /* Initialize the SMSC47M192 chip */
545 smsc47m192_init_client(client
);
547 /* Register sysfs hooks */
548 if ((err
= sysfs_create_group(&client
->dev
.kobj
, &smsc47m192_group
)))
551 /* Pin 110 is either in4 (+12V) or VID4 */
552 config
= i2c_smbus_read_byte_data(client
, SMSC47M192_REG_CONFIG
);
553 if (!(config
& 0x20)) {
554 if ((err
= sysfs_create_group(&client
->dev
.kobj
,
555 &smsc47m192_group_in4
)))
556 goto exit_remove_files
;
559 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
560 if (IS_ERR(data
->hwmon_dev
)) {
561 err
= PTR_ERR(data
->hwmon_dev
);
562 goto exit_remove_files
;
568 sysfs_remove_group(&client
->dev
.kobj
, &smsc47m192_group
);
569 sysfs_remove_group(&client
->dev
.kobj
, &smsc47m192_group_in4
);
571 i2c_detach_client(client
);
578 static int smsc47m192_detach_client(struct i2c_client
*client
)
580 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
583 hwmon_device_unregister(data
->hwmon_dev
);
584 sysfs_remove_group(&client
->dev
.kobj
, &smsc47m192_group
);
585 sysfs_remove_group(&client
->dev
.kobj
, &smsc47m192_group_in4
);
587 if ((err
= i2c_detach_client(client
)))
595 static struct smsc47m192_data
*smsc47m192_update_device(struct device
*dev
)
597 struct i2c_client
*client
= to_i2c_client(dev
);
598 struct smsc47m192_data
*data
= i2c_get_clientdata(client
);
601 mutex_lock(&data
->update_lock
);
603 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
605 u8 sfr
= i2c_smbus_read_byte_data(client
, SMSC47M192_REG_SFR
);
607 dev_dbg(&client
->dev
, "Starting smsc47m192 update\n");
609 for (i
= 0; i
<= 7; i
++) {
610 data
->in
[i
] = i2c_smbus_read_byte_data(client
,
611 SMSC47M192_REG_IN(i
));
612 data
->in_min
[i
] = i2c_smbus_read_byte_data(client
,
613 SMSC47M192_REG_IN_MIN(i
));
614 data
->in_max
[i
] = i2c_smbus_read_byte_data(client
,
615 SMSC47M192_REG_IN_MAX(i
));
617 for (i
= 0; i
< 3; i
++) {
618 data
->temp
[i
] = i2c_smbus_read_byte_data(client
,
619 SMSC47M192_REG_TEMP
[i
]);
620 data
->temp_max
[i
] = i2c_smbus_read_byte_data(client
,
621 SMSC47M192_REG_TEMP_MAX
[i
]);
622 data
->temp_min
[i
] = i2c_smbus_read_byte_data(client
,
623 SMSC47M192_REG_TEMP_MIN
[i
]);
625 for (i
= 1; i
< 3; i
++)
626 data
->temp_offset
[i
] = i2c_smbus_read_byte_data(client
,
627 SMSC47M192_REG_TEMP_OFFSET(i
));
628 /* first offset is temp_offset[0] if SFR bit 4 is set,
629 temp_offset[1] otherwise */
631 data
->temp_offset
[0] = data
->temp_offset
[1];
632 data
->temp_offset
[1] = 0;
634 data
->temp_offset
[0] = 0;
636 data
->vid
= i2c_smbus_read_byte_data(client
, SMSC47M192_REG_VID
)
638 config
= i2c_smbus_read_byte_data(client
,
639 SMSC47M192_REG_CONFIG
);
641 data
->vid
|= (i2c_smbus_read_byte_data(client
,
642 SMSC47M192_REG_VID4
) & 0x01) << 4;
643 data
->alarms
= i2c_smbus_read_byte_data(client
,
644 SMSC47M192_REG_ALARM1
) |
645 (i2c_smbus_read_byte_data(client
,
646 SMSC47M192_REG_ALARM2
) << 8);
648 data
->last_updated
= jiffies
;
652 mutex_unlock(&data
->update_lock
);
657 static int __init
smsc47m192_init(void)
659 return i2c_add_driver(&smsc47m192_driver
);
662 static void __exit
smsc47m192_exit(void)
664 i2c_del_driver(&smsc47m192_driver
);
667 MODULE_AUTHOR("Hartmut Rick <linux@rick.claranet.de>");
668 MODULE_DESCRIPTION("SMSC47M192 driver");
669 MODULE_LICENSE("GPL");
671 module_init(smsc47m192_init
);
672 module_exit(smsc47m192_exit
);