24 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include <linux/i2c.h>
35 #define DEVNAME "lm95241"
37 static const unsigned short normal_i2c[] = {
41 #define LM95241_REG_R_MAN_ID 0xFE
42 #define LM95241_REG_R_CHIP_ID 0xFF
43 #define LM95241_REG_R_STATUS 0x02
44 #define LM95241_REG_RW_CONFIG 0x03
45 #define LM95241_REG_RW_REM_FILTER 0x06
46 #define LM95241_REG_RW_TRUTHERM 0x07
47 #define LM95241_REG_W_ONE_SHOT 0x0F
48 #define LM95241_REG_R_LOCAL_TEMPH 0x10
49 #define LM95241_REG_R_REMOTE1_TEMPH 0x11
50 #define LM95241_REG_R_REMOTE2_TEMPH 0x12
51 #define LM95241_REG_R_LOCAL_TEMPL 0x20
52 #define LM95241_REG_R_REMOTE1_TEMPL 0x21
53 #define LM95241_REG_R_REMOTE2_TEMPL 0x22
54 #define LM95241_REG_RW_REMOTE_MODEL 0x30
58 #define CFG_CR0076 0x00
59 #define CFG_CR0182 0x10
60 #define CFG_CR1000 0x20
61 #define CFG_CR2700 0x30
64 #define R1MS_MASK (0x01 << (R1MS_SHIFT))
65 #define R2MS_MASK (0x01 << (R2MS_SHIFT))
68 #define R1DF_MASK (0x01 << (R1DF_SHIFT))
69 #define R2DF_MASK (0x01 << (R2DF_SHIFT))
70 #define R1FE_MASK 0x01
71 #define R2FE_MASK 0x05
77 #define NATSEMI_MAN_ID 0x01
78 #define LM95231_CHIP_ID 0xA1
79 #define LM95241_CHIP_ID 0xA4
81 static const u8 lm95241_reg_address[] = {
102 static int temp_from_reg_signed(
u8 val_h,
u8 val_l)
104 s16 val_hl = (val_h << 8) | val_l;
105 return val_hl * 1000 / 256;
108 static int temp_from_reg_unsigned(
u8 val_h,
u8 val_l)
110 u16 val_hl = (val_h << 8) | val_l;
111 return val_hl * 1000 / 256;
125 dev_dbg(&client->
dev,
"Updating lm95241 data.\n");
126 for (i = 0; i <
ARRAY_SIZE(lm95241_reg_address); i++)
129 lm95241_reg_address[i]);
147 index == 0 || (data->
config & (1 << (index / 2))) ?
148 temp_from_reg_signed(data->
temp[index], data->
temp[index + 1]) :
149 temp_from_reg_unsigned(data->
temp[index],
150 data->
temp[index + 1]));
164 const char *buf,
size_t count)
172 if (kstrtoul(buf, 10, &val) < 0)
174 if (val != 1 && val != 2)
186 data->
model &= ~mask;
209 "-127000\n" :
"0\n");
213 const char *buf,
size_t count)
219 if (kstrtol(buf, 10, &val) < 0)
247 "127000\n" :
"255000\n");
251 const char *buf,
size_t count)
257 if (kstrtol(buf, 10, &val) < 0)
287 const char *buf,
size_t count)
293 if (kstrtoul(buf, 10, &val) < 0)
319 static struct attribute *lm95241_attributes[] = {
320 &sensor_dev_attr_temp1_input.dev_attr.attr,
321 &sensor_dev_attr_temp2_input.dev_attr.attr,
322 &sensor_dev_attr_temp3_input.dev_attr.attr,
323 &sensor_dev_attr_temp2_type.dev_attr.attr,
324 &sensor_dev_attr_temp3_type.dev_attr.attr,
325 &sensor_dev_attr_temp2_min.dev_attr.attr,
326 &sensor_dev_attr_temp3_min.dev_attr.attr,
327 &sensor_dev_attr_temp2_max.dev_attr.attr,
328 &sensor_dev_attr_temp3_max.dev_attr.attr,
329 &dev_attr_update_interval.attr,
334 .attrs = lm95241_attributes,
338 static int lm95241_detect(
struct i2c_client *new_client,
369 static void lm95241_init_client(
struct i2c_client *client)
388 static int lm95241_probe(
struct i2c_client *new_client,
399 i2c_set_clientdata(new_client, data);
403 lm95241_init_client(new_client);
413 goto exit_remove_files;
423 static int lm95241_remove(
struct i2c_client *client)
446 .probe = lm95241_probe,
447 .remove = lm95241_remove,
448 .id_table = lm95241_id,
449 .detect = lm95241_detect,
450 .address_list = normal_i2c,