lm95241.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | lm95241.c (f48ccb26e264b112afc087d562fa2d68e2e1174b) |
---|---|
1/* 2 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com> 3 * 4 * The LM95241 is a sensor chip made by National Semiconductors. 5 * It reports up to three temperatures (its own plus up to two external ones). 6 * Complete datasheet can be obtained from National's website at: 7 * http://www.national.com/ds.cgi/LM/LM95241.pdf 8 * --- 45 unchanged lines hidden (view full) --- 54#define LM95241_REG_RW_REMOTE_MODEL 0x30 55 56/* LM95241 specific bitfields */ 57#define CFG_STOP 0x40 58#define CFG_CR0076 0x00 59#define CFG_CR0182 0x10 60#define CFG_CR1000 0x20 61#define CFG_CR2700 0x30 | 1/* 2 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com> 3 * 4 * The LM95241 is a sensor chip made by National Semiconductors. 5 * It reports up to three temperatures (its own plus up to two external ones). 6 * Complete datasheet can be obtained from National's website at: 7 * http://www.national.com/ds.cgi/LM/LM95241.pdf 8 * --- 45 unchanged lines hidden (view full) --- 54#define LM95241_REG_RW_REMOTE_MODEL 0x30 55 56/* LM95241 specific bitfields */ 57#define CFG_STOP 0x40 58#define CFG_CR0076 0x00 59#define CFG_CR0182 0x10 60#define CFG_CR1000 0x20 61#define CFG_CR2700 0x30 |
62#define CFG_CRMASK 0x30 |
|
62#define R1MS_SHIFT 0 63#define R2MS_SHIFT 2 64#define R1MS_MASK (0x01 << (R1MS_SHIFT)) 65#define R2MS_MASK (0x01 << (R2MS_SHIFT)) 66#define R1DF_SHIFT 1 67#define R2DF_SHIFT 2 68#define R1DF_MASK (0x01 << (R1DF_SHIFT)) 69#define R2DF_MASK (0x01 << (R2DF_SHIFT)) --- 16 unchanged lines hidden (view full) --- 86 LM95241_REG_R_REMOTE2_TEMPH, 87 LM95241_REG_R_REMOTE2_TEMPL 88}; 89 90/* Client data (each client gets its own) */ 91struct lm95241_data { 92 struct i2c_client *client; 93 struct mutex update_lock; | 63#define R1MS_SHIFT 0 64#define R2MS_SHIFT 2 65#define R1MS_MASK (0x01 << (R1MS_SHIFT)) 66#define R2MS_MASK (0x01 << (R2MS_SHIFT)) 67#define R1DF_SHIFT 1 68#define R2DF_SHIFT 2 69#define R1DF_MASK (0x01 << (R1DF_SHIFT)) 70#define R2DF_MASK (0x01 << (R2DF_SHIFT)) --- 16 unchanged lines hidden (view full) --- 87 LM95241_REG_R_REMOTE2_TEMPH, 88 LM95241_REG_R_REMOTE2_TEMPL 89}; 90 91/* Client data (each client gets its own) */ 92struct lm95241_data { 93 struct i2c_client *client; 94 struct mutex update_lock; |
94 unsigned long last_updated, interval; /* in jiffies */ | 95 unsigned long last_updated; /* in jiffies */ 96 unsigned long interval; /* in milli-seconds */ |
95 char valid; /* zero until following fields are valid */ 96 /* registers values */ 97 u8 temp[ARRAY_SIZE(lm95241_reg_address)]; 98 u8 config, model, trutherm; 99}; 100 101/* Conversions */ 102static int temp_from_reg_signed(u8 val_h, u8 val_l) --- 10 unchanged lines hidden (view full) --- 113 114static struct lm95241_data *lm95241_update_device(struct device *dev) 115{ 116 struct lm95241_data *data = dev_get_drvdata(dev); 117 struct i2c_client *client = data->client; 118 119 mutex_lock(&data->update_lock); 120 | 97 char valid; /* zero until following fields are valid */ 98 /* registers values */ 99 u8 temp[ARRAY_SIZE(lm95241_reg_address)]; 100 u8 config, model, trutherm; 101}; 102 103/* Conversions */ 104static int temp_from_reg_signed(u8 val_h, u8 val_l) --- 10 unchanged lines hidden (view full) --- 115 116static struct lm95241_data *lm95241_update_device(struct device *dev) 117{ 118 struct lm95241_data *data = dev_get_drvdata(dev); 119 struct i2c_client *client = data->client; 120 121 mutex_lock(&data->update_lock); 122 |
121 if (time_after(jiffies, data->last_updated + data->interval) || | 123 if (time_after(jiffies, data->last_updated 124 + msecs_to_jiffies(data->interval)) || |
122 !data->valid) { 123 int i; 124 125 dev_dbg(dev, "Updating lm95241 data.\n"); 126 for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) 127 data->temp[i] 128 = i2c_smbus_read_byte_data(client, 129 lm95241_reg_address[i]); --- 141 unchanged lines hidden (view full) --- 271 return count; 272} 273 274static ssize_t show_interval(struct device *dev, struct device_attribute *attr, 275 char *buf) 276{ 277 struct lm95241_data *data = lm95241_update_device(dev); 278 | 125 !data->valid) { 126 int i; 127 128 dev_dbg(dev, "Updating lm95241 data.\n"); 129 for (i = 0; i < ARRAY_SIZE(lm95241_reg_address); i++) 130 data->temp[i] 131 = i2c_smbus_read_byte_data(client, 132 lm95241_reg_address[i]); --- 141 unchanged lines hidden (view full) --- 274 return count; 275} 276 277static ssize_t show_interval(struct device *dev, struct device_attribute *attr, 278 char *buf) 279{ 280 struct lm95241_data *data = lm95241_update_device(dev); 281 |
279 return snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval 280 / HZ); | 282 return snprintf(buf, PAGE_SIZE - 1, "%lu\n", data->interval); |
281} 282 283static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 284 const char *buf, size_t count) 285{ 286 struct lm95241_data *data = dev_get_drvdata(dev); 287 unsigned long val; | 283} 284 285static ssize_t set_interval(struct device *dev, struct device_attribute *attr, 286 const char *buf, size_t count) 287{ 288 struct lm95241_data *data = dev_get_drvdata(dev); 289 unsigned long val; |
290 int convrate; 291 u8 config; |
|
288 289 if (kstrtoul(buf, 10, &val) < 0) 290 return -EINVAL; 291 | 292 293 if (kstrtoul(buf, 10, &val) < 0) 294 return -EINVAL; 295 |
292 data->interval = val * HZ / 1000; | 296 mutex_lock(&data->update_lock); |
293 | 297 |
298 config = data->config & ~CFG_CRMASK; 299 300 if (val < 130) { 301 convrate = 76; 302 config |= CFG_CR0076; 303 } else if (val < 590) { 304 convrate = 182; 305 config |= CFG_CR0182; 306 } else if (val < 1850) { 307 convrate = 1000; 308 config |= CFG_CR1000; 309 } else { 310 convrate = 2700; 311 config |= CFG_CR2700; 312 } 313 314 data->interval = convrate; 315 data->config = config; 316 i2c_smbus_write_byte_data(data->client, LM95241_REG_RW_CONFIG, 317 config); 318 mutex_unlock(&data->update_lock); 319 |
|
294 return count; 295} 296 297static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); 298static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); 299static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 4); 300static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type, 301 R1MS_MASK); --- 55 unchanged lines hidden (view full) --- 357 /* Fill the i2c board info */ 358 strlcpy(info->type, name, I2C_NAME_SIZE); 359 return 0; 360} 361 362static void lm95241_init_client(struct i2c_client *client, 363 struct lm95241_data *data) 364{ | 320 return count; 321} 322 323static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); 324static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); 325static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_input, NULL, 4); 326static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, set_type, 327 R1MS_MASK); --- 55 unchanged lines hidden (view full) --- 383 /* Fill the i2c board info */ 384 strlcpy(info->type, name, I2C_NAME_SIZE); 385 return 0; 386} 387 388static void lm95241_init_client(struct i2c_client *client, 389 struct lm95241_data *data) 390{ |
365 data->interval = HZ; /* 1 sec default */ 366 data->config = CFG_CR0076; | 391 data->interval = 1000; 392 data->config = CFG_CR1000; |
367 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); 368 369 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 370 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER, 371 R1FE_MASK | R2FE_MASK); 372 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, 373 data->trutherm); 374 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, --- 50 unchanged lines hidden --- | 393 data->trutherm = (TT_OFF << TT1_SHIFT) | (TT_OFF << TT2_SHIFT); 394 395 i2c_smbus_write_byte_data(client, LM95241_REG_RW_CONFIG, data->config); 396 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REM_FILTER, 397 R1FE_MASK | R2FE_MASK); 398 i2c_smbus_write_byte_data(client, LM95241_REG_RW_TRUTHERM, 399 data->trutherm); 400 i2c_smbus_write_byte_data(client, LM95241_REG_RW_REMOTE_MODEL, --- 50 unchanged lines hidden --- |