27 #include <linux/module.h>
29 #include <linux/slab.h>
31 #include <linux/i2c.h>
39 static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f,
45 #define TMP421_CONFIG_REG_1 0x09
46 #define TMP421_CONVERSION_RATE_REG 0x0B
47 #define TMP421_MANUFACTURER_ID_REG 0xFE
48 #define TMP421_DEVICE_ID_REG 0xFF
50 static const u8 TMP421_TEMP_MSB[4] = { 0x00, 0x01, 0x02, 0x03 };
51 static const u8 TMP421_TEMP_LSB[4] = { 0x10, 0x11, 0x12, 0x13 };
54 #define TMP421_CONFIG_SHUTDOWN 0x40
55 #define TMP421_CONFIG_RANGE 0x04
58 #define TMP421_MANUFACTURER_ID 0x55
59 #define TMP421_DEVICE_ID 0x21
60 #define TMP422_DEVICE_ID 0x22
61 #define TMP423_DEVICE_ID 0x23
81 static int temp_from_s16(
s16 reg)
84 int temp = reg & ~0xf;
86 return (temp * 1000 + 128) / 256;
89 static int temp_from_u16(
u16 reg)
92 int temp = reg & ~0xf;
97 return (temp * 1000 + 128) / 256;
112 for (i = 0; i < data->
channels; i++) {
114 TMP421_TEMP_MSB[i]) << 8;
131 struct tmp421_data *data = tmp421_update_device(dev);
136 temp = temp_from_u16(data->
temp[index]);
138 temp = temp_from_s16(data->
temp[index]);
141 return sprintf(buf,
"%d\n", temp);
148 struct tmp421_data *data = tmp421_update_device(dev);
154 if (data->
temp[index] & 0x01)
185 static struct attribute *tmp421_attr[] = {
186 &sensor_dev_attr_temp1_input.dev_attr.attr,
187 &sensor_dev_attr_temp2_input.dev_attr.attr,
188 &sensor_dev_attr_temp2_fault.dev_attr.attr,
189 &sensor_dev_attr_temp3_input.dev_attr.attr,
190 &sensor_dev_attr_temp3_fault.dev_attr.attr,
191 &sensor_dev_attr_temp4_input.dev_attr.attr,
192 &sensor_dev_attr_temp4_fault.dev_attr.attr,
197 .attrs = tmp421_attr,
198 .is_visible = tmp421_is_visible,
201 static int tmp421_init_client(
struct i2c_client *client)
211 dev_err(&client->
dev,
"Could not read configuration"
212 " register (%d)\n", config);
219 if (config != config_orig) {
220 dev_info(&client->
dev,
"Enable monitoring chip\n");
227 static int tmp421_detect(
struct i2c_client *client,
232 const char *names[] = {
"TMP421",
"TMP422",
"TMP423" };
258 dev_info(&adapter->
dev,
"Detected TI %s chip at 0x%02x\n",
259 names[kind], client->
addr);
264 static int tmp421_probe(
struct i2c_client *client,
275 i2c_set_clientdata(client, data);
279 err = tmp421_init_client(client);
300 static int tmp421_remove(
struct i2c_client *client)
302 struct tmp421_data *data = i2c_get_clientdata(client);
315 .probe = tmp421_probe,
316 .remove = tmp421_remove,
317 .id_table = tmp421_id,
318 .detect = tmp421_detect,
319 .address_list = normal_i2c,