31 #include <linux/module.h>
33 #include <linux/slab.h>
35 #include <linux/i2c.h>
43 static const unsigned short normal_i2c[] = { 0x4c,
I2C_CLIENT_END };
51 #define TMP401_STATUS 0x02
52 #define TMP401_CONFIG_READ 0x03
53 #define TMP401_CONFIG_WRITE 0x09
54 #define TMP401_CONVERSION_RATE_READ 0x04
55 #define TMP401_CONVERSION_RATE_WRITE 0x0A
56 #define TMP401_TEMP_CRIT_HYST 0x21
57 #define TMP401_CONSECUTIVE_ALERT 0x22
58 #define TMP401_MANUFACTURER_ID_REG 0xFE
59 #define TMP401_DEVICE_ID_REG 0xFF
60 #define TMP411_N_FACTOR_REG 0x18
62 static const u8 TMP401_TEMP_MSB[2] = { 0x00, 0x01 };
63 static const u8 TMP401_TEMP_LSB[2] = { 0x15, 0x10 };
64 static const u8 TMP401_TEMP_LOW_LIMIT_MSB_READ[2] = { 0x06, 0x08 };
65 static const u8 TMP401_TEMP_LOW_LIMIT_MSB_WRITE[2] = { 0x0C, 0x0E };
66 static const u8 TMP401_TEMP_LOW_LIMIT_LSB[2] = { 0x17, 0x14 };
67 static const u8 TMP401_TEMP_HIGH_LIMIT_MSB_READ[2] = { 0x05, 0x07 };
68 static const u8 TMP401_TEMP_HIGH_LIMIT_MSB_WRITE[2] = { 0x0B, 0x0D };
69 static const u8 TMP401_TEMP_HIGH_LIMIT_LSB[2] = { 0x16, 0x13 };
71 static const u8 TMP401_TEMP_CRIT_LIMIT[2] = { 0x20, 0x19 };
73 static const u8 TMP411_TEMP_LOWEST_MSB[2] = { 0x30, 0x34 };
74 static const u8 TMP411_TEMP_LOWEST_LSB[2] = { 0x31, 0x35 };
75 static const u8 TMP411_TEMP_HIGHEST_MSB[2] = { 0x32, 0x36 };
76 static const u8 TMP411_TEMP_HIGHEST_LSB[2] = { 0x33, 0x37 };
79 #define TMP401_CONFIG_RANGE 0x04
80 #define TMP401_CONFIG_SHUTDOWN 0x40
81 #define TMP401_STATUS_LOCAL_CRIT 0x01
82 #define TMP401_STATUS_REMOTE_CRIT 0x02
83 #define TMP401_STATUS_REMOTE_OPEN 0x04
84 #define TMP401_STATUS_REMOTE_LOW 0x08
85 #define TMP401_STATUS_REMOTE_HIGH 0x10
86 #define TMP401_STATUS_LOCAL_LOW 0x20
87 #define TMP401_STATUS_LOCAL_HIGH 0x40
90 #define TMP401_MANUFACTURER_ID 0x55
91 #define TMP401_DEVICE_ID 0x11
92 #define TMP411_DEVICE_ID 0x12
139 return (temp * 625 + 80) / 160;
145 temp = SENSORS_LIMIT(temp, -64000, 191000);
148 temp = SENSORS_LIMIT(temp, 0, 127000);
150 return (temp * 160 + 312) / 625;
153 static int tmp401_crit_register_to_temp(
u8 reg,
u8 config)
157 if (config & TMP401_CONFIG_RANGE)
163 static u8 tmp401_crit_temp_to_register(
long temp,
u8 config)
165 if (config & TMP401_CONFIG_RANGE) {
166 temp = SENSORS_LIMIT(temp, -64000, 191000);
169 temp = SENSORS_LIMIT(temp, 0, 127000);
171 return (temp + 500) / 1000;
174 static struct tmp401_data *tmp401_update_device_reg16(
179 for (i = 0; i < 2; i++) {
185 TMP401_TEMP_MSB[i]) << 8;
189 TMP401_TEMP_LOW_LIMIT_MSB_READ[i]) << 8;
191 TMP401_TEMP_LOW_LIMIT_LSB[i]);
193 TMP401_TEMP_HIGH_LIMIT_MSB_READ[i]) << 8;
195 TMP401_TEMP_HIGH_LIMIT_LSB[i]);
197 TMP401_TEMP_CRIT_LIMIT[i]);
201 TMP411_TEMP_LOWEST_MSB[i]) << 8;
203 client, TMP411_TEMP_LOWEST_LSB[i]);
206 client, TMP411_TEMP_HIGHEST_MSB[i]) << 8;
208 client, TMP411_TEMP_HIGHEST_LSB[i]);
217 struct tmp401_data *data = i2c_get_clientdata(client);
225 tmp401_update_device_reg16(client, data);
243 struct tmp401_data *data = tmp401_update_device(dev);
246 tmp401_register_to_temp(data->
temp[index], data->
config));
253 struct tmp401_data *data = tmp401_update_device(dev);
263 struct tmp401_data *data = tmp401_update_device(dev);
273 struct tmp401_data *data = tmp401_update_device(dev);
276 tmp401_crit_register_to_temp(data->
temp_crit[index],
284 struct tmp401_data *data = tmp401_update_device(dev);
287 temp = tmp401_crit_register_to_temp(data->
temp_crit[index],
292 return sprintf(buf,
"%d\n", temp);
299 struct tmp401_data *data = tmp401_update_device(dev);
310 struct tmp401_data *data = tmp401_update_device(dev);
321 struct tmp401_data *data = tmp401_update_device(dev);
330 *devattr,
const char *buf,
size_t count)
333 struct tmp401_data *data = tmp401_update_device(dev);
337 if (kstrtol(buf, 10, &val))
340 reg = tmp401_temp_to_register(val, data->
config);
345 TMP401_TEMP_LOW_LIMIT_MSB_WRITE[index], reg >> 8);
347 TMP401_TEMP_LOW_LIMIT_LSB[index], reg & 0xFF);
357 *devattr,
const char *buf,
size_t count)
360 struct tmp401_data *data = tmp401_update_device(dev);
364 if (kstrtol(buf, 10, &val))
367 reg = tmp401_temp_to_register(val, data->
config);
372 TMP401_TEMP_HIGH_LIMIT_MSB_WRITE[index], reg >> 8);
374 TMP401_TEMP_HIGH_LIMIT_LSB[index], reg & 0xFF);
384 *devattr,
const char *buf,
size_t count)
387 struct tmp401_data *data = tmp401_update_device(dev);
391 if (kstrtol(buf, 10, &val))
394 reg = tmp401_crit_temp_to_register(val, data->
config);
399 TMP401_TEMP_CRIT_LIMIT[index], reg);
409 *devattr,
const char *buf,
size_t count)
412 struct tmp401_data *data = tmp401_update_device(dev);
416 if (kstrtol(buf, 10, &val))
419 if (data->
config & TMP401_CONFIG_RANGE)
420 val = SENSORS_LIMIT(val, -64000, 191000);
422 val = SENSORS_LIMIT(val, 0, 127000);
425 temp = tmp401_crit_register_to_temp(data->
temp_crit[index],
427 val = SENSORS_LIMIT(val, temp - 255000, temp);
428 reg = ((temp -
val) + 500) / 1000;
450 if (kstrtol(buf, 10, &val))
454 dev_err(dev,
"temp_reset_history value %ld not"
455 " supported. Use 1 to reset the history!\n", val);
459 TMP411_TEMP_LOWEST_MSB[0], val);
473 store_temp_crit_hyst, 0),
517 static void tmp401_init_client(
struct i2c_client *client)
527 dev_warn(&client->
dev,
"Initialization failed!\n");
534 if (config != config_orig)
538 static int tmp401_detect(
struct i2c_client *client,
580 static int tmp401_remove(
struct i2c_client *client)
582 struct tmp401_data *data = i2c_get_clientdata(client);
600 static int tmp401_probe(
struct i2c_client *client,
605 const char *names[] = {
"TMP401",
"TMP411" };
612 i2c_set_clientdata(client, data);
614 data->
kind =
id->driver_data;
617 tmp401_init_client(client);
620 for (i = 0; i <
ARRAY_SIZE(tmp401_attr); i++) {
629 for (i = 0; i <
ARRAY_SIZE(tmp411_attr); i++) {
649 tmp401_remove(client);
658 .probe = tmp401_probe,
659 .remove = tmp401_remove,
660 .id_table = tmp401_id,
661 .detect = tmp401_detect,
662 .address_list = normal_i2c,