26 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <linux/i2c.h>
37 #define DEVNAME "lm95245"
39 static const unsigned short normal_i2c[] = {
44 #define LM95245_REG_RW_CONFIG1 0x03
45 #define LM95245_REG_RW_CONVERS_RATE 0x04
46 #define LM95245_REG_W_ONE_SHOT 0x0F
49 #define LM95245_REG_RW_CONFIG2 0xBF
50 #define LM95245_REG_RW_REMOTE_OFFH 0x11
51 #define LM95245_REG_RW_REMOTE_OFFL 0x12
54 #define LM95245_REG_R_STATUS1 0x02
55 #define LM95245_REG_R_STATUS2 0x33
58 #define LM95245_REG_RW_REMOTE_OS_LIMIT 0x07
59 #define LM95245_REG_RW_LOCAL_OS_TCRIT_LIMIT 0x20
60 #define LM95245_REG_RW_REMOTE_TCRIT_LIMIT 0x19
61 #define LM95245_REG_RW_COMMON_HYSTERESIS 0x21
64 #define LM95245_REG_R_LOCAL_TEMPH_S 0x00
65 #define LM95245_REG_R_LOCAL_TEMPL_S 0x30
66 #define LM95245_REG_R_REMOTE_TEMPH_S 0x01
67 #define LM95245_REG_R_REMOTE_TEMPL_S 0x10
69 #define LM95245_REG_R_REMOTE_TEMPH_U 0x31
70 #define LM95245_REG_R_REMOTE_TEMPL_U 0x32
73 #define LM95245_REG_R_MAN_ID 0xFE
74 #define LM95245_REG_R_CHIP_ID 0xFF
78 #define CFG_REMOTE_TCRIT_MASK 0x10
79 #define CFG_REMOTE_OS_MASK 0x08
80 #define CFG_LOCAL_TCRIT_MASK 0x04
81 #define CFG_LOCAL_OS_MASK 0x02
83 #define CFG2_OS_A0 0x40
84 #define CFG2_DIODE_FAULT_OS 0x20
85 #define CFG2_DIODE_FAULT_TCRIT 0x10
86 #define CFG2_REMOTE_TT 0x08
87 #define CFG2_REMOTE_FILTER_DIS 0x00
88 #define CFG2_REMOTE_FILTER_EN 0x06
91 #define RATE_CR0063 0x00
92 #define RATE_CR0364 0x01
93 #define RATE_CR1000 0x02
94 #define RATE_CR2500 0x03
96 #define STATUS1_DIODE_FAULT 0x04
97 #define STATUS1_RTCRIT 0x02
98 #define STATUS1_LOC 0x01
100 #define MANUFACTURER_ID 0x01
101 #define DEFAULT_REVISION 0xB3
103 static const u8 lm95245_reg_address[] = {
129 static int temp_from_reg_unsigned(
u8 val_h,
u8 val_l)
131 return val_h * 1000 + val_l * 1000 / 256;
134 static int temp_from_reg_signed(
u8 val_h,
u8 val_l)
137 return (val_h - 0x100) * 1000;
138 return temp_from_reg_unsigned(val_h, val_l);
152 dev_dbg(&client->
dev,
"Updating lm95245 data.\n");
153 for (i = 0; i <
ARRAY_SIZE(lm95245_reg_address); i++)
156 lm95245_reg_address[i]);
166 static unsigned long lm95245_read_conversion_rate(
struct i2c_client *client)
192 static unsigned long lm95245_set_conversion_rate(
struct i2c_client *client,
193 unsigned long interval)
197 if (interval <= 63) {
200 }
else if (interval <= 364) {
203 }
else if (interval <= 1000) {
229 if (index == 0 || data->
regs[index] & 0x80)
230 temp = temp_from_reg_signed(data->
regs[index],
231 data->
regs[index + 1]);
233 temp = temp_from_reg_unsigned(data->
regs[index + 2],
234 data->
regs[index + 3]);
246 data->
regs[index] * 1000);
250 const char *buf,
size_t count)
257 if (kstrtoul(buf, 10, &val) < 0)
262 val = SENSORS_LIMIT(val, 0, (index == 6 ? 127 : 255));
276 const char *buf,
size_t count)
282 if (kstrtoul(buf, 10, &val) < 0)
287 val = SENSORS_LIMIT(val, 0, 31);
313 const char *buf,
size_t count)
319 if (kstrtoul(buf, 10, &val) < 0)
321 if (val != 1 && val != 2)
348 !!(data->
regs[9] & index));
360 const char *buf,
size_t count)
366 if (kstrtoul(buf, 10, &val) < 0)
371 data->
interval = lm95245_set_conversion_rate(client, val);
401 static struct attribute *lm95245_attributes[] = {
402 &sensor_dev_attr_temp1_input.dev_attr.attr,
403 &sensor_dev_attr_temp1_crit.dev_attr.attr,
404 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
405 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
406 &sensor_dev_attr_temp2_input.dev_attr.attr,
407 &sensor_dev_attr_temp2_crit.dev_attr.attr,
408 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
409 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
410 &sensor_dev_attr_temp2_type.dev_attr.attr,
411 &sensor_dev_attr_temp2_fault.dev_attr.attr,
412 &dev_attr_update_interval.attr,
417 .attrs = lm95245_attributes,
421 static int lm95245_detect(
struct i2c_client *new_client,
439 static void lm95245_init_client(
struct i2c_client *client)
444 data->
interval = lm95245_read_conversion_rate(client);
459 static int lm95245_probe(
struct i2c_client *new_client,
470 i2c_set_clientdata(new_client, data);
474 lm95245_init_client(new_client);
484 goto exit_remove_files;
494 static int lm95245_remove(
struct i2c_client *client)
516 .probe = lm95245_probe,
517 .remove = lm95245_remove,
518 .id_table = lm95245_id,
519 .detect = lm95245_detect,
520 .address_list = normal_i2c,