45 #include <linux/module.h>
46 #include <linux/slab.h>
47 #include <linux/i2c.h>
56 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
62 #define ADM9240_REG_MAN_ID 0x3e
63 #define ADM9240_REG_DIE_REV 0x3f
64 #define ADM9240_REG_CONFIG 0x40
66 #define ADM9240_REG_IN(nr) (0x20 + (nr))
67 #define ADM9240_REG_IN_MAX(nr) (0x2b + (nr) * 2)
68 #define ADM9240_REG_IN_MIN(nr) (0x2c + (nr) * 2)
69 #define ADM9240_REG_FAN(nr) (0x28 + (nr))
70 #define ADM9240_REG_FAN_MIN(nr) (0x3b + (nr))
71 #define ADM9240_REG_INT(nr) (0x41 + (nr))
72 #define ADM9240_REG_INT_MASK(nr) (0x43 + (nr))
73 #define ADM9240_REG_TEMP 0x27
74 #define ADM9240_REG_TEMP_MAX(nr) (0x39 + (nr))
75 #define ADM9240_REG_ANALOG_OUT 0x19
76 #define ADM9240_REG_CHASSIS_CLEAR 0x46
77 #define ADM9240_REG_VID_FAN_DIV 0x47
78 #define ADM9240_REG_I2C_ADDR 0x48
79 #define ADM9240_REG_VID4 0x49
80 #define ADM9240_REG_TEMP_CONF 0x4b
86 return (val * mul - div / 2) /
div;
88 return (val * mul + div / 2) /
div;
92 static const u16 nom_mv[] = { 2500, 2700, 3300, 5000, 12000, 2700 };
96 return SCALE(reg, nom_mv[n], 192);
101 return SENSORS_LIMIT(
SCALE(val, 192, nom_mv[n]), 0, 255);
107 return SENSORS_LIMIT(
SCALE(val, 1, 1000), -40, 127);
119 return SCALE(1350000, 1, reg * div);
125 return SENSORS_LIMIT(
SCALE(val, 255, 1250), 0, 255);
130 return SCALE(reg, 1250, 255);
155 .probe = adm9240_probe,
156 .remove = adm9240_remove,
157 .id_table = adm9240_id,
158 .detect = adm9240_detect,
159 .address_list = normal_i2c,
211 err = kstrtol(buf, 10, &val);
225 show_max, set_max, 0);
227 show_max, set_max, 1);
259 const char *buf,
size_t count)
267 err = kstrtoul(buf, 10, &val);
281 const char *buf,
size_t count)
289 err = kstrtoul(buf, 10, &val);
302 static SENSOR_DEVICE_ATTR(in##nr##_input, S_IRUGO, \
303 show_in, NULL, nr); \
304 static SENSOR_DEVICE_ATTR(in##nr##_min, S_IRUGO | S_IWUSR, \
305 show_in_min, set_in_min, nr); \
306 static SENSOR_DEVICE_ATTR(in##nr##_max, S_IRUGO | S_IWUSR, \
307 show_in_max, set_in_max, nr);
344 static void adm9240_write_fan_div(
struct i2c_client *client,
int nr,
347 u8 reg, old, shift = (nr + 2) * 2;
350 old = (reg >> shift) & 3;
351 reg &= ~(3 << shift);
352 reg |= (fan_div << shift);
354 dev_dbg(&client->
dev,
"fan%d clock divider changed from %u "
355 "to %u\n", nr + 1, 1 << old, 1 << fan_div);
371 const char *buf,
size_t count)
381 err = kstrtoul(buf, 10, &val);
391 dev_dbg(&client->
dev,
"fan%u low limit set disabled\n",
394 }
else if (val < 1350000 / (8 * 254)) {
398 dev_dbg(&client->
dev,
"fan%u low limit set minimum %u\n",
402 unsigned int new_min = 1350000 /
val;
405 while (new_min > 192 && new_div < 3) {
414 dev_dbg(&client->
dev,
"fan%u low limit set fan speed %u\n",
418 if (new_div != data->
fan_div[nr]) {
420 adm9240_write_fan_div(client, nr, new_div);
430 static SENSOR_DEVICE_ATTR(fan##nr##_input, S_IRUGO, \
431 show_fan, NULL, nr - 1); \
432 static SENSOR_DEVICE_ATTR(fan##nr##_div, S_IRUGO, \
433 show_fan_div, NULL, nr - 1); \
434 static SENSOR_DEVICE_ATTR(fan##nr##_min, S_IRUGO | S_IWUSR, \
435 show_fan_min, set_fan_min, nr - 1);
485 const char *buf,
size_t count)
492 err = kstrtol(buf, 10, &val);
506 const char *buf,
size_t count)
512 if (kstrtoul(buf, 10, &val) || val != 0)
519 dev_dbg(&client->
dev,
"chassis intrusion latch cleared\n");
526 static struct attribute *adm9240_attributes[] = {
527 &sensor_dev_attr_in0_input.dev_attr.attr,
528 &sensor_dev_attr_in0_min.dev_attr.attr,
529 &sensor_dev_attr_in0_max.dev_attr.attr,
530 &sensor_dev_attr_in0_alarm.dev_attr.attr,
531 &sensor_dev_attr_in1_input.dev_attr.attr,
532 &sensor_dev_attr_in1_min.dev_attr.attr,
533 &sensor_dev_attr_in1_max.dev_attr.attr,
534 &sensor_dev_attr_in1_alarm.dev_attr.attr,
535 &sensor_dev_attr_in2_input.dev_attr.attr,
536 &sensor_dev_attr_in2_min.dev_attr.attr,
537 &sensor_dev_attr_in2_max.dev_attr.attr,
538 &sensor_dev_attr_in2_alarm.dev_attr.attr,
539 &sensor_dev_attr_in3_input.dev_attr.attr,
540 &sensor_dev_attr_in3_min.dev_attr.attr,
541 &sensor_dev_attr_in3_max.dev_attr.attr,
542 &sensor_dev_attr_in3_alarm.dev_attr.attr,
543 &sensor_dev_attr_in4_input.dev_attr.attr,
544 &sensor_dev_attr_in4_min.dev_attr.attr,
545 &sensor_dev_attr_in4_max.dev_attr.attr,
546 &sensor_dev_attr_in4_alarm.dev_attr.attr,
547 &sensor_dev_attr_in5_input.dev_attr.attr,
548 &sensor_dev_attr_in5_min.dev_attr.attr,
549 &sensor_dev_attr_in5_max.dev_attr.attr,
550 &sensor_dev_attr_in5_alarm.dev_attr.attr,
551 &dev_attr_temp1_input.attr,
552 &sensor_dev_attr_temp1_max.dev_attr.attr,
553 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
554 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
555 &sensor_dev_attr_fan1_input.dev_attr.attr,
556 &sensor_dev_attr_fan1_div.dev_attr.attr,
557 &sensor_dev_attr_fan1_min.dev_attr.attr,
558 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
559 &sensor_dev_attr_fan2_input.dev_attr.attr,
560 &sensor_dev_attr_fan2_div.dev_attr.attr,
561 &sensor_dev_attr_fan2_min.dev_attr.attr,
562 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
563 &dev_attr_alarms.attr,
564 &dev_attr_aout_output.attr,
565 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
566 &dev_attr_cpu0_vid.attr,
571 .attrs = adm9240_attributes,
578 static int adm9240_detect(
struct i2c_client *new_client,
582 const char *
name =
"";
592 dev_err(&adapter->
dev,
"detect fail: address match, 0x%02x\n",
599 if (man_id == 0x23) {
601 }
else if (man_id == 0xda) {
603 }
else if (man_id == 0x01) {
606 dev_err(&adapter->
dev,
"detect fail: unknown manuf, 0x%02x\n",
614 man_id == 0x23 ?
"ADM9240" :
615 man_id == 0xda ?
"DS1780" :
"LM81", die_rev);
622 static int adm9240_probe(
struct i2c_client *new_client,
632 i2c_set_clientdata(new_client, data);
635 adm9240_init_client(new_client);
655 static int adm9240_remove(
struct i2c_client *client)
665 static void adm9240_init_client(
struct i2c_client *client)
678 dev_info(&client->
dev,
"status: config 0x%02x mode %u\n",
684 for (i = 0; i < 6; i++) {
702 dev_info(&client->
dev,
"cold start: config was 0x%02x "
703 "mode %u\n", conf, mode);
719 for (i = 0; i < 6; i++) {
738 for (i = 0; i < 2; i++) {
743 if (data->
valid && data->
fan[i] == 255 &&
746 adm9240_write_fan_div(client, i,
762 for (i = 0; i < 6; i++) {
768 for (i = 0; i < 2; i++) {
779 data->
fan_div[0] = (i >> 4) & 3;
780 data->
fan_div[1] = (i >> 6) & 3;
781 data->
vid = i & 0x0f;