20 #include <linux/module.h>
22 #include <linux/slab.h>
24 #include <linux/i2c.h>
34 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e,
I2C_CLIENT_END };
40 #define EMC6W201_REG_IN(nr) (0x20 + (nr))
41 #define EMC6W201_REG_TEMP(nr) (0x26 + (nr))
42 #define EMC6W201_REG_FAN(nr) (0x2C + (nr) * 2)
43 #define EMC6W201_REG_COMPANY 0x3E
44 #define EMC6W201_REG_VERSTEP 0x3F
45 #define EMC6W201_REG_CONFIG 0x40
46 #define EMC6W201_REG_IN_LOW(nr) (0x4A + (nr) * 2)
47 #define EMC6W201_REG_IN_HIGH(nr) (0x4B + (nr) * 2)
48 #define EMC6W201_REG_TEMP_LOW(nr) (0x56 + (nr) * 2)
49 #define EMC6W201_REG_TEMP_HIGH(nr) (0x57 + (nr) * 2)
50 #define EMC6W201_REG_FAN_MIN(nr) (0x62 + (nr) * 2)
81 dev_err(&client->
dev,
"%d-bit %s failed at 0x%02x\n",
86 return (msb << 8) |
lsb;
101 dev_err(&client->
dev,
"%d-bit %s failed at 0x%02x\n",
114 dev_err(&client->
dev,
"%d-bit %s failed at 0x%02x\n",
123 static int emc6w201_write8(
struct i2c_client *client,
u8 reg,
u8 val)
129 dev_err(&client->
dev,
"%d-bit %s failed at 0x%02x\n",
144 for (nr = 0; nr < 6; nr++) {
146 emc6w201_read8(client,
149 emc6w201_read8(client,
152 emc6w201_read8(client,
156 for (nr = 0; nr < 6; nr++) {
158 emc6w201_read8(client,
161 emc6w201_read8(client,
164 emc6w201_read8(client,
168 for (nr = 0; nr < 5; nr++) {
170 emc6w201_read16(client,
173 emc6w201_read16(client,
190 static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
200 (
unsigned)data->
in[sf][nr] * nominal_mv[nr] / 0xC0);
204 const char *buf,
size_t count)
214 err = kstrtol(buf, 10, &val);
223 data->
in[
sf][
nr] = SENSORS_LIMIT(val, 0, 255);
224 err = emc6w201_write8(client, reg, data->
in[sf][nr]);
227 return err < 0 ? err :
count;
237 return sprintf(buf,
"%d\n", (
int)data->
temp[sf][nr] * 1000);
241 const char *buf,
size_t count)
251 err = kstrtol(buf, 10, &val);
260 data->
temp[
sf][
nr] = SENSORS_LIMIT(val, -127, 128);
261 err = emc6w201_write8(client, reg, data->
temp[sf][nr]);
264 return err < 0 ? err :
count;
275 if (data->
fan[sf][nr] == 0 || data->
fan[sf][nr] == 0xFFFF)
280 return sprintf(buf,
"%u\n", rpm);
284 const char *buf,
size_t count)
293 err = kstrtoul(buf, 10, &val);
301 val = SENSORS_LIMIT(val, 0, 0xFFFE);
310 return err < 0 ? err :
count;
391 static struct attribute *emc6w201_attributes[] = {
392 &sensor_dev_attr_in0_input.dev_attr.attr,
393 &sensor_dev_attr_in0_min.dev_attr.attr,
394 &sensor_dev_attr_in0_max.dev_attr.attr,
395 &sensor_dev_attr_in1_input.dev_attr.attr,
396 &sensor_dev_attr_in1_min.dev_attr.attr,
397 &sensor_dev_attr_in1_max.dev_attr.attr,
398 &sensor_dev_attr_in2_input.dev_attr.attr,
399 &sensor_dev_attr_in2_min.dev_attr.attr,
400 &sensor_dev_attr_in2_max.dev_attr.attr,
401 &sensor_dev_attr_in3_input.dev_attr.attr,
402 &sensor_dev_attr_in3_min.dev_attr.attr,
403 &sensor_dev_attr_in3_max.dev_attr.attr,
404 &sensor_dev_attr_in4_input.dev_attr.attr,
405 &sensor_dev_attr_in4_min.dev_attr.attr,
406 &sensor_dev_attr_in4_max.dev_attr.attr,
407 &sensor_dev_attr_in5_input.dev_attr.attr,
408 &sensor_dev_attr_in5_min.dev_attr.attr,
409 &sensor_dev_attr_in5_max.dev_attr.attr,
411 &sensor_dev_attr_temp1_input.dev_attr.attr,
412 &sensor_dev_attr_temp1_min.dev_attr.attr,
413 &sensor_dev_attr_temp1_max.dev_attr.attr,
414 &sensor_dev_attr_temp2_input.dev_attr.attr,
415 &sensor_dev_attr_temp2_min.dev_attr.attr,
416 &sensor_dev_attr_temp2_max.dev_attr.attr,
417 &sensor_dev_attr_temp3_input.dev_attr.attr,
418 &sensor_dev_attr_temp3_min.dev_attr.attr,
419 &sensor_dev_attr_temp3_max.dev_attr.attr,
420 &sensor_dev_attr_temp4_input.dev_attr.attr,
421 &sensor_dev_attr_temp4_min.dev_attr.attr,
422 &sensor_dev_attr_temp4_max.dev_attr.attr,
423 &sensor_dev_attr_temp5_input.dev_attr.attr,
424 &sensor_dev_attr_temp5_min.dev_attr.attr,
425 &sensor_dev_attr_temp5_max.dev_attr.attr,
426 &sensor_dev_attr_temp6_input.dev_attr.attr,
427 &sensor_dev_attr_temp6_min.dev_attr.attr,
428 &sensor_dev_attr_temp6_max.dev_attr.attr,
430 &sensor_dev_attr_fan1_input.dev_attr.attr,
431 &sensor_dev_attr_fan1_min.dev_attr.attr,
432 &sensor_dev_attr_fan2_input.dev_attr.attr,
433 &sensor_dev_attr_fan2_min.dev_attr.attr,
434 &sensor_dev_attr_fan3_input.dev_attr.attr,
435 &sensor_dev_attr_fan3_min.dev_attr.attr,
436 &sensor_dev_attr_fan4_input.dev_attr.attr,
437 &sensor_dev_attr_fan4_min.dev_attr.attr,
438 &sensor_dev_attr_fan5_input.dev_attr.attr,
439 &sensor_dev_attr_fan5_min.dev_attr.attr,
444 .attrs = emc6w201_attributes,
452 static int emc6w201_detect(
struct i2c_client *client,
456 int company, verstep,
config;
466 if (verstep < 0 || (verstep & 0xF0) != 0xB0)
468 if ((verstep & 0x0F) > 2) {
469 dev_dbg(&client->
dev,
"Unknwown EMC6W201 stepping %d\n",
476 if (config < 0 || (config & 0xF4) != 0x04)
478 if (!(config & 0x01)) {
479 dev_err(&client->
dev,
"Monitoring not enabled\n");
488 static int emc6w201_probe(
struct i2c_client *client,
499 i2c_set_clientdata(client, data);
521 static int emc6w201_remove(
struct i2c_client *client)
542 .probe = emc6w201_probe,
543 .remove = emc6w201_remove,
544 .id_table = emc6w201_id,
545 .detect = emc6w201_detect,
546 .address_list = normal_i2c,