24 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/i2c.h>
37 static const unsigned short normal_i2c[] = { 0x2c, 0x2d,
I2C_CLIENT_END };
40 #define SMSC47M192_REG_IN(nr) ((nr) < 6 ? (0x20 + (nr)) : \
42 #define SMSC47M192_REG_IN_MAX(nr) ((nr) < 6 ? (0x2b + (nr) * 2) : \
43 (0x54 + (((nr) - 6) * 2)))
44 #define SMSC47M192_REG_IN_MIN(nr) ((nr) < 6 ? (0x2c + (nr) * 2) : \
45 (0x55 + (((nr) - 6) * 2)))
46 static u8 SMSC47M192_REG_TEMP[3] = { 0x27, 0x26, 0x52 };
47 static u8 SMSC47M192_REG_TEMP_MAX[3] = { 0x39, 0x37, 0x58 };
48 static u8 SMSC47M192_REG_TEMP_MIN[3] = { 0x3A, 0x38, 0x59 };
49 #define SMSC47M192_REG_TEMP_OFFSET(nr) ((nr) == 2 ? 0x1e : 0x1f)
50 #define SMSC47M192_REG_ALARM1 0x41
51 #define SMSC47M192_REG_ALARM2 0x42
52 #define SMSC47M192_REG_VID 0x47
53 #define SMSC47M192_REG_VID4 0x49
54 #define SMSC47M192_REG_CONFIG 0x40
55 #define SMSC47M192_REG_SFR 0x4f
56 #define SMSC47M192_REG_COMPANY_ID 0x3e
57 #define SMSC47M192_REG_VERSION 0x3f
63 return (val * mul - div / 2) /
div;
65 return (val * mul + div / 2) /
div;
71 static const u16 nom_mv[] = { 2500, 2250, 3300, 5000, 12000, 3300, 1500, 1800 };
75 return SCALE(reg, nom_mv[n], 192);
80 return SENSORS_LIMIT(
SCALE(val, 192, nom_mv[n]), 0, 255);
89 return SENSORS_LIMIT(
SCALE(val, 1, 1000), -128000, 127000);
128 static struct i2c_driver smsc47m192_driver = {
131 .name =
"smsc47m192",
133 .probe = smsc47m192_probe,
134 .remove = smsc47m192_remove,
135 .id_table = smsc47m192_id,
136 .detect = smsc47m192_detect,
137 .address_list = normal_i2c,
154 int nr = sensor_attr->
index;
163 int nr = sensor_attr->
index;
169 const char *buf,
size_t count)
172 int nr = sensor_attr->
index;
178 err = kstrtoul(buf, 10, &val);
191 const char *buf,
size_t count)
194 int nr = sensor_attr->
index;
200 err = kstrtoul(buf, 10, &val);
212 #define show_in_offset(offset) \
213 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
214 show_in, NULL, offset); \
215 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
216 show_in_min, set_in_min, offset); \
217 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
218 show_in_max, set_in_max, offset);
234 int nr = sensor_attr->
index;
243 int nr = sensor_attr->
index;
252 int nr = sensor_attr->
index;
258 const char *buf,
size_t count)
261 int nr = sensor_attr->
index;
267 err = kstrtol(buf, 10, &val);
280 const char *buf,
size_t count)
283 int nr = sensor_attr->
index;
289 err = kstrtol(buf, 10, &val);
305 int nr = sensor_attr->
index;
311 *attr,
const char *buf,
size_t count)
314 int nr = sensor_attr->
index;
321 err = kstrtol(buf, 10, &val);
336 (sfr & 0xef) | (nr == 0 ? 0x10 : 0));
340 }
else if ((sfr & 0x10) == (nr == 0 ? 0x10 : 0))
347 #define show_temp_index(index) \
348 static SENSOR_DEVICE_ATTR(temp##index##_input, S_IRUGO, \
349 show_temp, NULL, index-1); \
350 static SENSOR_DEVICE_ATTR(temp##index##_min, S_IRUGO | S_IWUSR, \
351 show_temp_min, set_temp_min, index-1); \
352 static SENSOR_DEVICE_ATTR(temp##index##_max, S_IRUGO | S_IWUSR, \
353 show_temp_max, set_temp_max, index-1); \
354 static SENSOR_DEVICE_ATTR(temp##index##_offset, S_IRUGO | S_IWUSR, \
355 show_temp_offset, set_temp_offset, index-1);
378 const char *buf,
size_t count)
384 err = kstrtoul(buf, 10, &val);
398 int nr = sensor_attr->
index;
417 static struct attribute *smsc47m192_attributes[] = {
418 &sensor_dev_attr_in0_input.dev_attr.attr,
419 &sensor_dev_attr_in0_min.dev_attr.attr,
420 &sensor_dev_attr_in0_max.dev_attr.attr,
421 &sensor_dev_attr_in0_alarm.dev_attr.attr,
422 &sensor_dev_attr_in1_input.dev_attr.attr,
423 &sensor_dev_attr_in1_min.dev_attr.attr,
424 &sensor_dev_attr_in1_max.dev_attr.attr,
425 &sensor_dev_attr_in1_alarm.dev_attr.attr,
426 &sensor_dev_attr_in2_input.dev_attr.attr,
427 &sensor_dev_attr_in2_min.dev_attr.attr,
428 &sensor_dev_attr_in2_max.dev_attr.attr,
429 &sensor_dev_attr_in2_alarm.dev_attr.attr,
430 &sensor_dev_attr_in3_input.dev_attr.attr,
431 &sensor_dev_attr_in3_min.dev_attr.attr,
432 &sensor_dev_attr_in3_max.dev_attr.attr,
433 &sensor_dev_attr_in3_alarm.dev_attr.attr,
434 &sensor_dev_attr_in5_input.dev_attr.attr,
435 &sensor_dev_attr_in5_min.dev_attr.attr,
436 &sensor_dev_attr_in5_max.dev_attr.attr,
437 &sensor_dev_attr_in5_alarm.dev_attr.attr,
438 &sensor_dev_attr_in6_input.dev_attr.attr,
439 &sensor_dev_attr_in6_min.dev_attr.attr,
440 &sensor_dev_attr_in6_max.dev_attr.attr,
441 &sensor_dev_attr_in6_alarm.dev_attr.attr,
442 &sensor_dev_attr_in7_input.dev_attr.attr,
443 &sensor_dev_attr_in7_min.dev_attr.attr,
444 &sensor_dev_attr_in7_max.dev_attr.attr,
445 &sensor_dev_attr_in7_alarm.dev_attr.attr,
447 &sensor_dev_attr_temp1_input.dev_attr.attr,
448 &sensor_dev_attr_temp1_max.dev_attr.attr,
449 &sensor_dev_attr_temp1_min.dev_attr.attr,
450 &sensor_dev_attr_temp1_offset.dev_attr.attr,
451 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
452 &sensor_dev_attr_temp2_input.dev_attr.attr,
453 &sensor_dev_attr_temp2_max.dev_attr.attr,
454 &sensor_dev_attr_temp2_min.dev_attr.attr,
455 &sensor_dev_attr_temp2_offset.dev_attr.attr,
456 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
457 &sensor_dev_attr_temp2_fault.dev_attr.attr,
458 &sensor_dev_attr_temp3_input.dev_attr.attr,
459 &sensor_dev_attr_temp3_max.dev_attr.attr,
460 &sensor_dev_attr_temp3_min.dev_attr.attr,
461 &sensor_dev_attr_temp3_offset.dev_attr.attr,
462 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
463 &sensor_dev_attr_temp3_fault.dev_attr.attr,
465 &dev_attr_cpu0_vid.attr,
471 .attrs = smsc47m192_attributes,
474 static struct attribute *smsc47m192_attributes_in4[] = {
475 &sensor_dev_attr_in4_input.dev_attr.attr,
476 &sensor_dev_attr_in4_min.dev_attr.attr,
477 &sensor_dev_attr_in4_max.dev_attr.attr,
478 &sensor_dev_attr_in4_alarm.dev_attr.attr,
483 .attrs = smsc47m192_attributes_in4,
486 static void smsc47m192_init_client(
struct i2c_client *client)
494 (sfr & 0xfd) | 0x02);
495 if (!(config & 0x01)) {
497 for (i = 0; i < 8; i++) {
503 for (i = 0; i < 3; i++) {
505 SMSC47M192_REG_TEMP_MIN[i], 0x80);
507 SMSC47M192_REG_TEMP_MAX[i], 0x7f);
512 (config & 0xf7) | 0x01);
517 static int smsc47m192_detect(
struct i2c_client *client,
530 && (version & 0xf0) == 0x20
536 "found SMSC47M192 or compatible, "
537 "version 2, stepping A%d\n", version & 0x0f);
540 "SMSC47M192 detection failed at 0x%02x\n",
550 static int smsc47m192_probe(
struct i2c_client *client,
562 i2c_set_clientdata(client, data);
567 smsc47m192_init_client(client);
576 if (!(config & 0x20)) {
578 &smsc47m192_group_in4);
580 goto exit_remove_files;
586 goto exit_remove_files;
597 static int smsc47m192_remove(
struct i2c_client *client)
620 dev_dbg(&client->
dev,
"Starting smsc47m192 update\n");
622 for (i = 0; i <= 7; i++) {
630 for (i = 0; i < 3; i++) {
632 SMSC47M192_REG_TEMP[i]);
634 SMSC47M192_REG_TEMP_MAX[i]);
636 SMSC47M192_REG_TEMP_MIN[i]);
638 for (i = 1; i < 3; i++)