82 #include <linux/module.h>
84 #include <linux/slab.h>
86 #include <linux/i2c.h>
108 static const unsigned short normal_i2c[] = {
109 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x48, 0x49, 0x4a, 0x4b, 0x4c,
119 #define LM90_REG_R_MAN_ID 0xFE
120 #define LM90_REG_R_CHIP_ID 0xFF
121 #define LM90_REG_R_CONFIG1 0x03
122 #define LM90_REG_W_CONFIG1 0x09
123 #define LM90_REG_R_CONFIG2 0xBF
124 #define LM90_REG_W_CONFIG2 0xBF
125 #define LM90_REG_R_CONVRATE 0x04
126 #define LM90_REG_W_CONVRATE 0x0A
127 #define LM90_REG_R_STATUS 0x02
128 #define LM90_REG_R_LOCAL_TEMP 0x00
129 #define LM90_REG_R_LOCAL_HIGH 0x05
130 #define LM90_REG_W_LOCAL_HIGH 0x0B
131 #define LM90_REG_R_LOCAL_LOW 0x06
132 #define LM90_REG_W_LOCAL_LOW 0x0C
133 #define LM90_REG_R_LOCAL_CRIT 0x20
134 #define LM90_REG_W_LOCAL_CRIT 0x20
135 #define LM90_REG_R_REMOTE_TEMPH 0x01
136 #define LM90_REG_R_REMOTE_TEMPL 0x10
137 #define LM90_REG_R_REMOTE_OFFSH 0x11
138 #define LM90_REG_W_REMOTE_OFFSH 0x11
139 #define LM90_REG_R_REMOTE_OFFSL 0x12
140 #define LM90_REG_W_REMOTE_OFFSL 0x12
141 #define LM90_REG_R_REMOTE_HIGHH 0x07
142 #define LM90_REG_W_REMOTE_HIGHH 0x0D
143 #define LM90_REG_R_REMOTE_HIGHL 0x13
144 #define LM90_REG_W_REMOTE_HIGHL 0x13
145 #define LM90_REG_R_REMOTE_LOWH 0x08
146 #define LM90_REG_W_REMOTE_LOWH 0x0E
147 #define LM90_REG_R_REMOTE_LOWL 0x14
148 #define LM90_REG_W_REMOTE_LOWL 0x14
149 #define LM90_REG_R_REMOTE_CRIT 0x19
150 #define LM90_REG_W_REMOTE_CRIT 0x19
151 #define LM90_REG_R_TCRIT_HYST 0x21
152 #define LM90_REG_W_TCRIT_HYST 0x21
156 #define MAX6657_REG_R_LOCAL_TEMPL 0x11
157 #define MAX6696_REG_R_STATUS2 0x12
158 #define MAX6659_REG_R_REMOTE_EMERG 0x16
159 #define MAX6659_REG_W_REMOTE_EMERG 0x16
160 #define MAX6659_REG_R_LOCAL_EMERG 0x17
161 #define MAX6659_REG_W_LOCAL_EMERG 0x17
165 #define SA56004_REG_R_LOCAL_TEMPL 0x22
167 #define LM90_DEF_CONVRATE_RVAL 6
168 #define LM90_MAX_CONVRATE_MS 16000
173 #define LM90_FLAG_ADT7461_EXT (1 << 0)
175 #define LM90_HAVE_OFFSET (1 << 1)
176 #define LM90_HAVE_REM_LIMIT_EXT (1 << 3)
177 #define LM90_HAVE_EMERGENCY (1 << 4)
178 #define LM90_HAVE_EMERGENCY_ALARM (1 << 5)
179 #define LM90_HAVE_TEMP3 (1 << 6)
180 #define LM90_HAVE_BROKEN_ALERT (1 << 7)
227 .alert_alarms = 0x7c,
233 .alert_alarms = 0x7c,
239 .alert_alarms = 0x7c,
244 .alert_alarms = 0x7b,
249 .alert_alarms = 0x7b,
254 .alert_alarms = 0x7b,
258 .alert_alarms = 0x7c,
263 .alert_alarms = 0x7c,
269 .alert_alarms = 0x7c,
275 .alert_alarms = 0x7c,
281 .alert_alarms = 0x187c,
287 .alert_alarms = 0x7c,
292 .alert_alarms = 0x7b,
369 err = adm1032_write_byte(client, reg);
376 dev_warn(&client->
dev,
"Register %#02x read failed (%d)\n",
403 if ((err = lm90_read_reg(client, regh, &oldh))
404 || (err = lm90_read_reg(client, regl, &l))
405 || (err = lm90_read_reg(client, regh, &newh)))
408 err = lm90_read_reg(client, regl, &l);
412 *value = (newh << 8) | l;
425 static inline void lm90_select_remote_channel(
struct i2c_client *client,
458 if (interval >= update_interval * 3 / 4)
468 struct lm90_data *data = i2c_get_clientdata(client);
469 unsigned long next_update;
479 dev_dbg(&client->
dev,
"Updating lm90 data.\n");
518 data->
temp11[3] = (h << 8) | l;
530 lm90_select_remote_channel(client, data, 1);
541 lm90_select_remote_channel(client, data, 0);
545 data->
alarms |= alarms << 8;
558 dev_dbg(&client->
dev,
"Re-enabling ALERT#\n");
583 static inline int temp_from_s8(
s8 val)
588 static inline int temp_from_u8(
u8 val)
593 static inline int temp_from_s16(
s16 val)
595 return val / 32 * 125;
598 static inline int temp_from_u16(
u16 val)
600 return val / 32 * 125;
603 static s8 temp_to_s8(
long val)
610 return (val - 500) / 1000;
611 return (val + 500) / 1000;
614 static u8 temp_to_u8(
long val)
620 return (val + 500) / 1000;
623 static s16 temp_to_s16(
long val)
630 return (val - 62) / 125 * 32;
631 return (val + 62) / 125 * 32;
634 static u8 hyst_to_reg(
long val)
640 return (val + 500) / 1000;
651 static inline int temp_from_u8_adt7461(
struct lm90_data *data,
u8 val)
654 return (val - 64) * 1000;
656 return temp_from_s8(val);
659 static inline int temp_from_u16_adt7461(
struct lm90_data *data,
u16 val)
662 return (val - 0x4000) / 64 * 250;
664 return temp_from_s16(val);
667 static u8 temp_to_u8_adt7461(
struct lm90_data *data,
long val)
674 return (val + 500 + 64000) / 1000;
680 return (val + 500) / 1000;
684 static u16 temp_to_u16_adt7461(
struct lm90_data *data,
long val)
691 return (val + 64000 + 125) / 250 * 64;
697 return (val + 125) / 250 * 64;
709 struct lm90_data *data = lm90_update_device(dev);
713 temp = temp_from_u8_adt7461(data, data->
temp8[attr->
index]);
715 temp = temp_from_u8(data->
temp8[attr->
index]);
717 temp = temp_from_s8(data->
temp8[attr->
index]);
723 return sprintf(buf,
"%d\n", temp);
727 const char *buf,
size_t count)
729 static const u8 reg[8] = {
742 struct lm90_data *data = i2c_get_clientdata(client);
747 err = kstrtol(buf, 10, &val);
757 data->
temp8[
nr] = temp_to_u8_adt7461(data, val);
759 data->
temp8[
nr] = temp_to_u8(val);
761 data->
temp8[
nr] = temp_to_s8(val);
763 lm90_select_remote_channel(client, data, nr >= 6);
765 lm90_select_remote_channel(client, data, 0);
775 struct lm90_data *data = lm90_update_device(dev);
779 temp = temp_from_u16_adt7461(data, data->
temp11[attr->
index]);
789 return sprintf(buf,
"%d\n", temp);
793 const char *buf,
size_t count)
809 struct lm90_data *data = i2c_get_clientdata(client);
815 err = kstrtol(buf, 10, &val);
820 if (data->
kind ==
lm99 && index <= 2)
825 data->
temp11[
index] = temp_to_u16_adt7461(data, val);
833 lm90_select_remote_channel(client, data, reg[nr].channel);
835 data->
temp11[index] >> 8);
838 data->
temp11[index] & 0xff);
839 lm90_select_remote_channel(client, data, 0);
850 struct lm90_data *data = lm90_update_device(dev);
854 temp = temp_from_u8_adt7461(data, data->
temp8[attr->
index]);
856 temp = temp_from_u8(data->
temp8[attr->
index]);
858 temp = temp_from_s8(data->
temp8[attr->
index]);
868 const char *buf,
size_t count)
871 struct lm90_data *data = i2c_get_clientdata(client);
876 err = kstrtol(buf, 10, &val);
882 temp = temp_from_u8_adt7461(data, data->
temp8[2]);
884 temp = temp_from_u8(data->
temp8[2]);
886 temp = temp_from_s8(data->
temp8[2]);
888 data->
temp_hyst = hyst_to_reg(temp - val);
898 struct lm90_data *data = lm90_update_device(dev);
906 struct lm90_data *data = lm90_update_device(dev);
907 int bitnr = attr->
index;
922 const char *buf,
size_t count)
925 struct lm90_data *data = i2c_get_clientdata(client);
929 err = kstrtoul(buf, 10, &val);
934 lm90_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000));
972 set_update_interval);
974 static struct attribute *lm90_attributes[] = {
975 &sensor_dev_attr_temp1_input.dev_attr.attr,
976 &sensor_dev_attr_temp2_input.dev_attr.attr,
977 &sensor_dev_attr_temp1_min.dev_attr.attr,
978 &sensor_dev_attr_temp2_min.dev_attr.attr,
979 &sensor_dev_attr_temp1_max.dev_attr.attr,
980 &sensor_dev_attr_temp2_max.dev_attr.attr,
981 &sensor_dev_attr_temp1_crit.dev_attr.attr,
982 &sensor_dev_attr_temp2_crit.dev_attr.attr,
983 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
984 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
986 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
987 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
988 &sensor_dev_attr_temp2_fault.dev_attr.attr,
989 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
990 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
991 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
992 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
993 &dev_attr_alarms.attr,
994 &dev_attr_update_interval.attr,
999 .attrs = lm90_attributes,
1014 static struct attribute *lm90_emergency_attributes[] = {
1015 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
1016 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
1017 &sensor_dev_attr_temp1_emergency_hyst.dev_attr.attr,
1018 &sensor_dev_attr_temp2_emergency_hyst.dev_attr.attr,
1023 .attrs = lm90_emergency_attributes,
1029 static struct attribute *lm90_emergency_alarm_attributes[] = {
1030 &sensor_dev_attr_temp1_emergency_alarm.dev_attr.attr,
1031 &sensor_dev_attr_temp2_emergency_alarm.dev_attr.attr,
1036 .attrs = lm90_emergency_alarm_attributes,
1061 static struct attribute *lm90_temp3_attributes[] = {
1062 &sensor_dev_attr_temp3_input.dev_attr.attr,
1063 &sensor_dev_attr_temp3_min.dev_attr.attr,
1064 &sensor_dev_attr_temp3_max.dev_attr.attr,
1065 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1066 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
1067 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
1068 &sensor_dev_attr_temp3_emergency_hyst.dev_attr.attr,
1070 &sensor_dev_attr_temp3_fault.dev_attr.attr,
1071 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
1072 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
1073 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
1074 &sensor_dev_attr_temp3_emergency_alarm.dev_attr.attr,
1079 .attrs = lm90_temp3_attributes,
1091 const char *buf,
size_t count)
1097 err = kstrtol(buf, 10, &val);
1122 static int lm90_detect(
struct i2c_client *client,
1128 int man_id,
chip_id, config1, config2, convrate;
1138 if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0)
1141 if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) {
1148 if ((address == 0x4C || address == 0x4D)
1149 && man_id == 0x01) {
1150 if ((config1 & 0x2A) == 0x00
1151 && (config2 & 0xF8) == 0x00
1152 && convrate <= 0x09) {
1154 && (chip_id & 0xF0) == 0x20) {
1157 if ((chip_id & 0xF0) == 0x30) {
1160 "Assuming LM99 chip at 0x%02x\n",
1163 "If it is an LM89, instantiate it "
1164 "with the new_device sysfs "
1168 && (chip_id & 0xF0) == 0x10) {
1173 if ((address == 0x4C || address == 0x4D)
1174 && man_id == 0x41) {
1175 if ((chip_id & 0xF0) == 0x40
1176 && (config1 & 0x3F) == 0x00
1177 && convrate <= 0x0A) {
1183 if (i2c_check_functionality(adapter,
1188 && (config1 & 0x1B) == 0x00
1189 && convrate <= 0x0A) {
1193 && (config1 & 0x1B) == 0x00
1194 && convrate <= 0x0A) {
1198 if (man_id == 0x4D) {
1215 if (emerg < 0 || man_id < 0 || emerg2 < 0 || status2 < 0)
1231 if (chip_id == man_id
1232 && (address == 0x4C || address == 0x4D || address == 0x4E)
1233 && (config1 & 0x1F) == (man_id & 0x0F)
1234 && convrate <= 0x09) {
1235 if (address == 0x4C)
1252 && (config1 & 0x10) == 0x00
1253 && (status2 & 0x01) == 0x00
1255 && convrate <= 0x07) {
1265 && (config1 & 0x03) == 0x00
1266 && convrate <= 0x07) {
1275 && (config1 & 0x3f) == 0x00
1276 && convrate <= 0x07) {
1281 && man_id == 0x5C) {
1282 if ((config1 & 0x2A) == 0x00
1283 && (config2 & 0xF8) == 0x00) {
1285 && convrate <= 0x09) {
1288 if ((chip_id & 0xFE) == 0x10
1289 && convrate <= 0x08) {
1294 if (address >= 0x48 && address <= 0x4F
1295 && man_id == 0xA1) {
1297 && (config1 & 0x2A) == 0x00
1298 && (config2 & 0xFE) == 0x00
1299 && convrate <= 0x09) {
1303 if ((address == 0x4C || address == 0x4D)
1304 && man_id == 0x47) {
1306 && (config1 & 0x3F) == 0x00
1307 && convrate <= 0x08)
1313 "Unsupported chip at 0x%02x (man_id=0x%02X, "
1314 "chip_id=0x%02X)\n", address, man_id, chip_id);
1348 static void lm90_init_client(
struct i2c_client *client)
1351 struct lm90_data *data = i2c_get_clientdata(client);
1354 dev_warn(&client->
dev,
"Failed to read convrate register!\n");
1362 lm90_set_convrate(client, data, 500);
1364 dev_warn(&client->
dev,
"Initialization failed!\n");
1394 static int lm90_probe(
struct i2c_client *client,
1406 i2c_set_clientdata(client, data);
1410 data->
kind =
id->driver_data;
1430 lm90_init_client(client);
1439 goto exit_remove_files;
1443 &sensor_dev_attr_temp2_offset.dev_attr);
1445 goto exit_remove_files;
1450 goto exit_remove_files;
1454 &lm90_emergency_alarm_group);
1456 goto exit_remove_files;
1461 goto exit_remove_files;
1467 goto exit_remove_files;
1473 lm90_remove_files(client, data);
1475 lm90_restore_conf(client, data);
1479 static int lm90_remove(
struct i2c_client *client)
1481 struct lm90_data *data = i2c_get_clientdata(client);
1484 lm90_remove_files(client, data);
1485 lm90_restore_conf(client, data);
1490 static void lm90_alert(
struct i2c_client *client,
unsigned int flag)
1492 struct lm90_data *data = i2c_get_clientdata(client);
1500 if ((alarms & 0x7f) == 0 && (alarms2 & 0xfe) == 0) {
1505 "temp%d out of range, please check!\n", 1);
1508 "temp%d out of range, please check!\n", 2);
1511 "temp%d diode open, please check!\n", 2);
1515 "temp%d out of range, please check!\n", 3);
1537 .probe = lm90_probe,
1538 .remove = lm90_remove,
1539 .alert = lm90_alert,
1540 .id_table = lm90_id,
1541 .detect = lm90_detect,
1542 .address_list = normal_i2c,