48 #include <linux/module.h>
50 #include <linux/slab.h>
52 #include <linux/i2c.h>
65 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e,
I2C_CLIENT_END };
73 #define ADM1025_REG_MAN_ID 0x3E
74 #define ADM1025_REG_CHIP_ID 0x3F
75 #define ADM1025_REG_CONFIG 0x40
76 #define ADM1025_REG_STATUS1 0x41
77 #define ADM1025_REG_STATUS2 0x42
78 #define ADM1025_REG_IN(nr) (0x20 + (nr))
79 #define ADM1025_REG_IN_MAX(nr) (0x2B + (nr) * 2)
80 #define ADM1025_REG_IN_MIN(nr) (0x2C + (nr) * 2)
81 #define ADM1025_REG_TEMP(nr) (0x26 + (nr))
82 #define ADM1025_REG_TEMP_HIGH(nr) (0x37 + (nr) * 2)
83 #define ADM1025_REG_TEMP_LOW(nr) (0x38 + (nr) * 2)
84 #define ADM1025_REG_VID 0x47
85 #define ADM1025_REG_VID4 0x49
92 static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
94 #define IN_FROM_REG(reg, scale) (((reg) * (scale) + 96) / 192)
95 #define IN_TO_REG(val, scale) ((val) <= 0 ? 0 : \
96 (val) * 192 >= (scale) * 255 ? 255 : \
97 ((val) * 192 + (scale) / 2) / (scale))
99 #define TEMP_FROM_REG(reg) ((reg) * 1000)
100 #define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
101 (val) >= 126500 ? 127 : \
102 (((val) < 0 ? (val) - 500 : \
103 (val) + 500) / 1000))
133 .probe = adm1025_probe,
134 .remove = adm1025_remove,
135 .id_table = adm1025_id,
136 .detect = adm1025_detect,
137 .address_list = normal_i2c,
217 const char *buf,
size_t count)
225 err = kstrtol(buf, 10, &val);
238 const char *buf,
size_t count)
246 err = kstrtol(buf, 10, &val);
258 #define set_in(offset) \
259 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
260 show_in, NULL, offset); \
261 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
262 show_in_min, set_in_min, offset); \
263 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
264 show_in_max, set_in_max, offset)
273 const char *buf,
size_t count)
281 err = kstrtol(buf, 10, &val);
294 const char *buf,
size_t count)
302 err = kstrtol(buf, 10, &val);
314 #define set_temp(offset) \
315 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
316 show_temp, NULL, offset - 1); \
317 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
318 show_temp_min, set_temp_min, offset - 1); \
319 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
320 show_temp_max, set_temp_max, offset - 1)
364 const char *buf,
size_t count)
370 err = kstrtoul(buf, 10, &val);
383 static struct attribute *adm1025_attributes[] = {
384 &sensor_dev_attr_in0_input.dev_attr.attr,
385 &sensor_dev_attr_in1_input.dev_attr.attr,
386 &sensor_dev_attr_in2_input.dev_attr.attr,
387 &sensor_dev_attr_in3_input.dev_attr.attr,
388 &sensor_dev_attr_in5_input.dev_attr.attr,
389 &sensor_dev_attr_in0_min.dev_attr.attr,
390 &sensor_dev_attr_in1_min.dev_attr.attr,
391 &sensor_dev_attr_in2_min.dev_attr.attr,
392 &sensor_dev_attr_in3_min.dev_attr.attr,
393 &sensor_dev_attr_in5_min.dev_attr.attr,
394 &sensor_dev_attr_in0_max.dev_attr.attr,
395 &sensor_dev_attr_in1_max.dev_attr.attr,
396 &sensor_dev_attr_in2_max.dev_attr.attr,
397 &sensor_dev_attr_in3_max.dev_attr.attr,
398 &sensor_dev_attr_in5_max.dev_attr.attr,
399 &sensor_dev_attr_in0_alarm.dev_attr.attr,
400 &sensor_dev_attr_in1_alarm.dev_attr.attr,
401 &sensor_dev_attr_in2_alarm.dev_attr.attr,
402 &sensor_dev_attr_in3_alarm.dev_attr.attr,
403 &sensor_dev_attr_in5_alarm.dev_attr.attr,
404 &sensor_dev_attr_temp1_input.dev_attr.attr,
405 &sensor_dev_attr_temp2_input.dev_attr.attr,
406 &sensor_dev_attr_temp1_min.dev_attr.attr,
407 &sensor_dev_attr_temp2_min.dev_attr.attr,
408 &sensor_dev_attr_temp1_max.dev_attr.attr,
409 &sensor_dev_attr_temp2_max.dev_attr.attr,
410 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
411 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
412 &sensor_dev_attr_temp1_fault.dev_attr.attr,
413 &dev_attr_alarms.attr,
414 &dev_attr_cpu0_vid.attr,
420 .attrs = adm1025_attributes,
423 static struct attribute *adm1025_attributes_in4[] = {
424 &sensor_dev_attr_in4_input.dev_attr.attr,
425 &sensor_dev_attr_in4_min.dev_attr.attr,
426 &sensor_dev_attr_in4_max.dev_attr.attr,
427 &sensor_dev_attr_in4_alarm.dev_attr.attr,
432 .attrs = adm1025_attributes_in4,
436 static int adm1025_detect(
struct i2c_client *client,
450 dev_dbg(&adapter->
dev,
"ADM1025 detection failed at 0x%02x\n",
457 if ((chip_id & 0xF0) != 0x20)
463 else if (man_id == 0xA1 && client->
addr != 0x2E)
473 static int adm1025_probe(
struct i2c_client *client,
485 i2c_set_clientdata(client, data);
489 adm1025_init_client(client);
498 if (!(config & 0x20)) {
518 static void adm1025_init_client(
struct i2c_client *client)
534 for (i = 0; i < 6; i++) {
542 for (i = 0; i < 2; i++) {
560 static int adm1025_remove(
struct i2c_client *client)
582 for (i = 0; i < 6; i++) {
590 for (i = 0; i < 2; i++) {