20 #include <linux/module.h>
22 #include <linux/slab.h>
24 #include <linux/i2c.h>
31 static const unsigned short normal_i2c[] = { 0x2E,
I2C_CLIENT_END };
33 static const u8 REG_TEMP[4] = { 0x00, 0x02, 0x04, 0x06 };
34 static const u8 REG_TEMP_MIN[4] = { 0x3c, 0x38, 0x39, 0x3a };
35 static const u8 REG_TEMP_MAX[4] = { 0x34, 0x30, 0x31, 0x32 };
37 #define REG_CONF1 0x20
38 #define REG_TEMP_MAX_ALARM 0x24
39 #define REG_TEMP_MIN_ALARM 0x25
40 #define REG_FAN_CONF1 0x42
41 #define REG_FAN_TARGET_LO 0x4c
42 #define REG_FAN_TARGET_HI 0x4d
43 #define REG_FAN_TACH_HI 0x4e
44 #define REG_FAN_TACH_LO 0x4f
45 #define REG_PRODUCT_ID 0xfd
46 #define REG_MFG_ID 0xfe
49 #define FAN_RPM_FACTOR 3932160
102 if (read_u8_from_i2c(client, i2c_reg, °rees) < 0)
105 if (read_u8_from_i2c(client, i2c_reg + 1, &fractional) < 0)
109 temp->
fraction = (fractional & 0xe0) >> 5;
112 static void read_fan_from_i2c(
struct i2c_client *client,
u16 *output,
113 u8 hi_addr,
u8 lo_addr)
115 u8 high_byte, lo_byte;
117 if (read_u8_from_i2c(client, hi_addr, &high_byte) < 0)
120 if (read_u8_from_i2c(client, lo_addr, &lo_byte) < 0)
123 *output = ((
u16)high_byte << 5) | (lo_byte >> 3);
126 static void write_fan_target_to_i2c(
struct i2c_client *client,
u16 new_target)
128 u8 high_byte = (new_target & 0x1fe0) >> 5;
129 u8 low_byte = (new_target & 0x001f) << 3;
134 static void read_fan_config_from_i2c(
struct i2c_client *client)
159 read_temp_from_i2c(client,
REG_TEMP[i], &data->
temp[i]);
160 read_u8_from_i2c(client, REG_TEMP_MIN[i],
162 read_u8_from_i2c(client, REG_TEMP_MAX[i],
171 read_fan_from_i2c(client, &data->
fan_tach,
175 read_fan_config_from_i2c(client);
191 int millidegrees = data->
temp[
nr].degrees * 1000
192 + data->
temp[
nr].fraction * 125;
193 return sprintf(buf,
"%d\n", millidegrees);
202 return sprintf(buf,
"%d\n", millidegrees);
211 return sprintf(buf,
"%d\n", millidegrees);
220 return sprintf(buf,
"%d\n", fault ? 1 : 0);
229 return sprintf(buf,
"%d\n", alarm ? 1 : 0);
238 return sprintf(buf,
"%d\n", alarm ? 1 : 0);
249 int result = kstrtol(buf, 10, &val);
254 if ((val < -63) || (val > 127))
266 const char *buf,
size_t count)
273 int result = kstrtol(buf, 10, &val);
278 if ((val < -63) || (val > 127))
296 return sprintf(buf,
"%d\n", rpm);
304 return sprintf(buf,
"%d\n", fan_div);
314 const char *buf,
size_t count)
321 int status = kstrtol(buf, 10, &new_div);
325 if (new_div == old_div)
355 status |= (new_range_bits << 5);
364 write_fan_target_to_i2c(client, data->
fan_target);
385 return sprintf(buf,
"%d\n", rpm);
389 const char *buf,
size_t count)
395 int result = kstrtol(buf, 10, &rpm_target);
400 if ((rpm_target < 0) || (rpm_target > 16384))
412 write_fan_target_to_i2c(client, data->
fan_target);
423 return sprintf(buf,
"%d\n", fault ? 1 : 0);
434 const char *buf,
size_t count)
441 int result = kstrtol(buf, 10, &new_value);
529 static struct attribute *emc2103_attributes[] = {
530 &sensor_dev_attr_temp1_input.dev_attr.attr,
531 &sensor_dev_attr_temp1_min.dev_attr.attr,
532 &sensor_dev_attr_temp1_max.dev_attr.attr,
533 &sensor_dev_attr_temp1_fault.dev_attr.attr,
534 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
535 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
536 &sensor_dev_attr_temp2_input.dev_attr.attr,
537 &sensor_dev_attr_temp2_min.dev_attr.attr,
538 &sensor_dev_attr_temp2_max.dev_attr.attr,
539 &sensor_dev_attr_temp2_fault.dev_attr.attr,
540 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
541 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
542 &dev_attr_fan1_input.attr,
543 &dev_attr_fan1_div.attr,
544 &dev_attr_fan1_target.attr,
545 &dev_attr_fan1_fault.attr,
546 &dev_attr_pwm1_enable.attr,
551 static struct attribute *emc2103_attributes_temp3[] = {
552 &sensor_dev_attr_temp3_input.dev_attr.attr,
553 &sensor_dev_attr_temp3_min.dev_attr.attr,
554 &sensor_dev_attr_temp3_max.dev_attr.attr,
555 &sensor_dev_attr_temp3_fault.dev_attr.attr,
556 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
557 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
562 static struct attribute *emc2103_attributes_temp4[] = {
563 &sensor_dev_attr_temp4_input.dev_attr.attr,
564 &sensor_dev_attr_temp4_min.dev_attr.attr,
565 &sensor_dev_attr_temp4_max.dev_attr.attr,
566 &sensor_dev_attr_temp4_fault.dev_attr.attr,
567 &sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
568 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
573 .attrs = emc2103_attributes,
577 .attrs = emc2103_attributes_temp3,
581 .attrs = emc2103_attributes_temp4,
598 i2c_set_clientdata(client, data);
603 if (status == 0x24) {
624 }
else if (apd == 1) {
639 &emc2103_temp3_group);
646 &emc2103_temp4_group);
648 goto exit_remove_temp3;
654 goto exit_remove_temp4;
673 static int emc2103_remove(
struct i2c_client *client)
707 if (manufacturer != 0x5D)
711 if ((product != 0x24) && (product != 0x26))
724 .probe = emc2103_probe,
725 .remove = emc2103_remove,
726 .id_table = emc2103_ids,
727 .detect = emc2103_detect,
728 .address_list = normal_i2c,