1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2007,2008 Hans de Goede <hdegoede@redhat.com>
5 * Preliminary tmp411 support by:
6 * Gabriel Konat, Sander Leget, Wouter Willems
7 * Copyright (C) 2009 Andre Prendel <andre.prendel@gmx.de>
9 * Cleanup and support for TMP431 and TMP432 by Guenter Roeck
10 * Copyright (c) 2013 Guenter Roeck <linux@roeck-us.net>
14 * Driver for the Texas Instruments TMP401 SMBUS temperature sensor IC.
16 * Note this IC is in some aspect similar to the LM90, but it has quite a
17 * few differences too, for example the local temp has a higher resolution
18 * and thus has 16 bits registers for its value and limit instead of 8 bits.
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/bitops.h>
24 #include <linux/slab.h>
25 #include <linux/jiffies.h>
26 #include <linux/i2c.h>
27 #include <linux/hwmon.h>
28 #include <linux/hwmon-sysfs.h>
29 #include <linux/err.h>
30 #include <linux/mutex.h>
31 #include <linux/sysfs.h>
33 /* Addresses to scan */
34 static const unsigned short normal_i2c
[] = { 0x48, 0x49, 0x4a, 0x4c, 0x4d,
35 0x4e, 0x4f, I2C_CLIENT_END
};
37 enum chips
{ tmp401
, tmp411
, tmp431
, tmp432
, tmp435
, tmp461
};
40 * The TMP401 registers, note some registers have different addresses for
43 #define TMP401_STATUS 0x02
44 #define TMP401_CONFIG_READ 0x03
45 #define TMP401_CONFIG_WRITE 0x09
46 #define TMP401_CONVERSION_RATE_READ 0x04
47 #define TMP401_CONVERSION_RATE_WRITE 0x0A
48 #define TMP401_TEMP_CRIT_HYST 0x21
49 #define TMP401_MANUFACTURER_ID_REG 0xFE
50 #define TMP401_DEVICE_ID_REG 0xFF
52 static const u8 TMP401_TEMP_MSB_READ
[7][2] = {
53 { 0x00, 0x01 }, /* temp */
54 { 0x06, 0x08 }, /* low limit */
55 { 0x05, 0x07 }, /* high limit */
56 { 0x20, 0x19 }, /* therm (crit) limit */
57 { 0x30, 0x34 }, /* lowest */
58 { 0x32, 0x36 }, /* highest */
59 { 0, 0x11 }, /* offset */
62 static const u8 TMP401_TEMP_MSB_WRITE
[7][2] = {
63 { 0, 0 }, /* temp (unused) */
64 { 0x0C, 0x0E }, /* low limit */
65 { 0x0B, 0x0D }, /* high limit */
66 { 0x20, 0x19 }, /* therm (crit) limit */
67 { 0x30, 0x34 }, /* lowest */
68 { 0x32, 0x36 }, /* highest */
69 { 0, 0x11 }, /* offset */
72 static const u8 TMP432_TEMP_MSB_READ
[4][3] = {
73 { 0x00, 0x01, 0x23 }, /* temp */
74 { 0x06, 0x08, 0x16 }, /* low limit */
75 { 0x05, 0x07, 0x15 }, /* high limit */
76 { 0x20, 0x19, 0x1A }, /* therm (crit) limit */
79 static const u8 TMP432_TEMP_MSB_WRITE
[4][3] = {
80 { 0, 0, 0 }, /* temp - unused */
81 { 0x0C, 0x0E, 0x16 }, /* low limit */
82 { 0x0B, 0x0D, 0x15 }, /* high limit */
83 { 0x20, 0x19, 0x1A }, /* therm (crit) limit */
86 /* [0] = fault, [1] = low, [2] = high, [3] = therm/crit */
87 static const u8 TMP432_STATUS_REG
[] = {
88 0x1b, 0x36, 0x35, 0x37 };
91 #define TMP401_CONFIG_RANGE BIT(2)
92 #define TMP401_CONFIG_SHUTDOWN BIT(6)
93 #define TMP401_STATUS_LOCAL_CRIT BIT(0)
94 #define TMP401_STATUS_REMOTE_CRIT BIT(1)
95 #define TMP401_STATUS_REMOTE_OPEN BIT(2)
96 #define TMP401_STATUS_REMOTE_LOW BIT(3)
97 #define TMP401_STATUS_REMOTE_HIGH BIT(4)
98 #define TMP401_STATUS_LOCAL_LOW BIT(5)
99 #define TMP401_STATUS_LOCAL_HIGH BIT(6)
101 /* On TMP432, each status has its own register */
102 #define TMP432_STATUS_LOCAL BIT(0)
103 #define TMP432_STATUS_REMOTE1 BIT(1)
104 #define TMP432_STATUS_REMOTE2 BIT(2)
106 /* Manufacturer / Device ID's */
107 #define TMP401_MANUFACTURER_ID 0x55
108 #define TMP401_DEVICE_ID 0x11
109 #define TMP411A_DEVICE_ID 0x12
110 #define TMP411B_DEVICE_ID 0x13
111 #define TMP411C_DEVICE_ID 0x10
112 #define TMP431_DEVICE_ID 0x31
113 #define TMP432_DEVICE_ID 0x32
114 #define TMP435_DEVICE_ID 0x35
117 * Driver data (common to all clients)
120 static const struct i2c_device_id tmp401_id
[] = {
121 { "tmp401", tmp401
},
122 { "tmp411", tmp411
},
123 { "tmp431", tmp431
},
124 { "tmp432", tmp432
},
125 { "tmp435", tmp435
},
126 { "tmp461", tmp461
},
129 MODULE_DEVICE_TABLE(i2c
, tmp401_id
);
132 * Client data (each client gets its own)
136 struct i2c_client
*client
;
137 const struct attribute_group
*groups
[3];
138 struct mutex update_lock
;
139 char valid
; /* zero until following fields are valid */
140 unsigned long last_updated
; /* in jiffies */
143 unsigned int update_interval
; /* in milliseconds */
145 /* register values */
153 * Sysfs attr show / store functions
156 static int tmp401_register_to_temp(u16 reg
, u8 config
)
160 if (config
& TMP401_CONFIG_RANGE
)
163 return DIV_ROUND_CLOSEST(temp
* 125, 32);
166 static u16
tmp401_temp_to_register(long temp
, u8 config
, int zbits
)
168 if (config
& TMP401_CONFIG_RANGE
) {
169 temp
= clamp_val(temp
, -64000, 191000);
172 temp
= clamp_val(temp
, 0, 127000);
174 return DIV_ROUND_CLOSEST(temp
* (1 << (8 - zbits
)), 1000) << zbits
;
177 static int tmp401_update_device_reg16(struct i2c_client
*client
,
178 struct tmp401_data
*data
)
181 int num_regs
= data
->kind
== tmp411
? 6 : 4;
182 int num_sensors
= data
->kind
== tmp432
? 3 : 2;
184 for (i
= 0; i
< num_sensors
; i
++) { /* local / r1 / r2 */
185 for (j
= 0; j
< num_regs
; j
++) { /* temp / low / ... */
188 regaddr
= data
->kind
== tmp432
?
189 TMP432_TEMP_MSB_READ
[j
][i
] :
190 TMP401_TEMP_MSB_READ
[j
][i
];
191 if (j
== 3) { /* crit is msb only */
192 val
= i2c_smbus_read_byte_data(client
, regaddr
);
194 val
= i2c_smbus_read_word_swapped(client
,
200 data
->temp
[j
][i
] = j
== 3 ? val
<< 8 : val
;
206 static struct tmp401_data
*tmp401_update_device(struct device
*dev
)
208 struct tmp401_data
*data
= dev_get_drvdata(dev
);
209 struct i2c_client
*client
= data
->client
;
210 struct tmp401_data
*ret
= data
;
212 unsigned long next_update
;
214 mutex_lock(&data
->update_lock
);
216 next_update
= data
->last_updated
+
217 msecs_to_jiffies(data
->update_interval
);
218 if (time_after(jiffies
, next_update
) || !data
->valid
) {
219 if (data
->kind
!= tmp432
) {
221 * The driver uses the TMP432 status format internally.
222 * Convert status to TMP432 format for other chips.
224 val
= i2c_smbus_read_byte_data(client
, TMP401_STATUS
);
230 (val
& TMP401_STATUS_REMOTE_OPEN
) >> 1;
232 ((val
& TMP401_STATUS_REMOTE_LOW
) >> 2) |
233 ((val
& TMP401_STATUS_LOCAL_LOW
) >> 5);
235 ((val
& TMP401_STATUS_REMOTE_HIGH
) >> 3) |
236 ((val
& TMP401_STATUS_LOCAL_HIGH
) >> 6);
237 data
->status
[3] = val
& (TMP401_STATUS_LOCAL_CRIT
238 | TMP401_STATUS_REMOTE_CRIT
);
240 for (i
= 0; i
< ARRAY_SIZE(data
->status
); i
++) {
241 val
= i2c_smbus_read_byte_data(client
,
242 TMP432_STATUS_REG
[i
]);
247 data
->status
[i
] = val
;
251 val
= i2c_smbus_read_byte_data(client
, TMP401_CONFIG_READ
);
257 val
= tmp401_update_device_reg16(client
, data
);
262 val
= i2c_smbus_read_byte_data(client
, TMP401_TEMP_CRIT_HYST
);
267 data
->temp_crit_hyst
= val
;
269 data
->last_updated
= jiffies
;
274 mutex_unlock(&data
->update_lock
);
278 static ssize_t
temp_show(struct device
*dev
, struct device_attribute
*devattr
,
281 int nr
= to_sensor_dev_attr_2(devattr
)->nr
;
282 int index
= to_sensor_dev_attr_2(devattr
)->index
;
283 struct tmp401_data
*data
= tmp401_update_device(dev
);
286 return PTR_ERR(data
);
288 return sprintf(buf
, "%d\n",
289 tmp401_register_to_temp(data
->temp
[nr
][index
], data
->config
));
292 static ssize_t
temp_crit_hyst_show(struct device
*dev
,
293 struct device_attribute
*devattr
,
296 int temp
, index
= to_sensor_dev_attr(devattr
)->index
;
297 struct tmp401_data
*data
= tmp401_update_device(dev
);
300 return PTR_ERR(data
);
302 mutex_lock(&data
->update_lock
);
303 temp
= tmp401_register_to_temp(data
->temp
[3][index
], data
->config
);
304 temp
-= data
->temp_crit_hyst
* 1000;
305 mutex_unlock(&data
->update_lock
);
307 return sprintf(buf
, "%d\n", temp
);
310 static ssize_t
status_show(struct device
*dev
,
311 struct device_attribute
*devattr
, char *buf
)
313 int nr
= to_sensor_dev_attr_2(devattr
)->nr
;
314 int mask
= to_sensor_dev_attr_2(devattr
)->index
;
315 struct tmp401_data
*data
= tmp401_update_device(dev
);
318 return PTR_ERR(data
);
320 return sprintf(buf
, "%d\n", !!(data
->status
[nr
] & mask
));
323 static ssize_t
temp_store(struct device
*dev
,
324 struct device_attribute
*devattr
, const char *buf
,
327 int nr
= to_sensor_dev_attr_2(devattr
)->nr
;
328 int index
= to_sensor_dev_attr_2(devattr
)->index
;
329 struct tmp401_data
*data
= dev_get_drvdata(dev
);
330 struct i2c_client
*client
= data
->client
;
335 if (kstrtol(buf
, 10, &val
))
338 reg
= tmp401_temp_to_register(val
, data
->config
, nr
== 3 ? 8 : 4);
340 mutex_lock(&data
->update_lock
);
342 regaddr
= data
->kind
== tmp432
? TMP432_TEMP_MSB_WRITE
[nr
][index
]
343 : TMP401_TEMP_MSB_WRITE
[nr
][index
];
344 if (nr
== 3) { /* crit is msb only */
345 i2c_smbus_write_byte_data(client
, regaddr
, reg
>> 8);
347 /* Hardware expects big endian data --> use _swapped */
348 i2c_smbus_write_word_swapped(client
, regaddr
, reg
);
350 data
->temp
[nr
][index
] = reg
;
352 mutex_unlock(&data
->update_lock
);
357 static ssize_t
temp_crit_hyst_store(struct device
*dev
,
358 struct device_attribute
*devattr
,
359 const char *buf
, size_t count
)
361 int temp
, index
= to_sensor_dev_attr(devattr
)->index
;
362 struct tmp401_data
*data
= tmp401_update_device(dev
);
367 return PTR_ERR(data
);
369 if (kstrtol(buf
, 10, &val
))
372 if (data
->config
& TMP401_CONFIG_RANGE
)
373 val
= clamp_val(val
, -64000, 191000);
375 val
= clamp_val(val
, 0, 127000);
377 mutex_lock(&data
->update_lock
);
378 temp
= tmp401_register_to_temp(data
->temp
[3][index
], data
->config
);
379 val
= clamp_val(val
, temp
- 255000, temp
);
380 reg
= ((temp
- val
) + 500) / 1000;
382 i2c_smbus_write_byte_data(data
->client
, TMP401_TEMP_CRIT_HYST
,
385 data
->temp_crit_hyst
= reg
;
387 mutex_unlock(&data
->update_lock
);
393 * Resets the historical measurements of minimum and maximum temperatures.
394 * This is done by writing any value to any of the minimum/maximum registers
397 static ssize_t
reset_temp_history_store(struct device
*dev
,
398 struct device_attribute
*devattr
,
399 const char *buf
, size_t count
)
401 struct tmp401_data
*data
= dev_get_drvdata(dev
);
402 struct i2c_client
*client
= data
->client
;
405 if (kstrtol(buf
, 10, &val
))
410 "temp_reset_history value %ld not supported. Use 1 to reset the history!\n",
414 mutex_lock(&data
->update_lock
);
415 i2c_smbus_write_byte_data(client
, TMP401_TEMP_MSB_WRITE
[5][0], val
);
417 mutex_unlock(&data
->update_lock
);
422 static ssize_t
update_interval_show(struct device
*dev
,
423 struct device_attribute
*attr
, char *buf
)
425 struct tmp401_data
*data
= dev_get_drvdata(dev
);
427 return sprintf(buf
, "%u\n", data
->update_interval
);
430 static ssize_t
update_interval_store(struct device
*dev
,
431 struct device_attribute
*attr
,
432 const char *buf
, size_t count
)
434 struct tmp401_data
*data
= dev_get_drvdata(dev
);
435 struct i2c_client
*client
= data
->client
;
439 err
= kstrtoul(buf
, 10, &val
);
444 * For valid rates, interval can be calculated as
445 * interval = (1 << (7 - rate)) * 125;
446 * Rounded rate is therefore
447 * rate = 7 - __fls(interval * 4 / (125 * 3));
448 * Use clamp_val() to avoid overflows, and to ensure valid input
451 val
= clamp_val(val
, 125, 16000);
452 rate
= 7 - __fls(val
* 4 / (125 * 3));
453 mutex_lock(&data
->update_lock
);
454 i2c_smbus_write_byte_data(client
, TMP401_CONVERSION_RATE_WRITE
, rate
);
455 data
->update_interval
= (1 << (7 - rate
)) * 125;
456 mutex_unlock(&data
->update_lock
);
461 static SENSOR_DEVICE_ATTR_2_RO(temp1_input
, temp
, 0, 0);
462 static SENSOR_DEVICE_ATTR_2_RW(temp1_min
, temp
, 1, 0);
463 static SENSOR_DEVICE_ATTR_2_RW(temp1_max
, temp
, 2, 0);
464 static SENSOR_DEVICE_ATTR_2_RW(temp1_crit
, temp
, 3, 0);
465 static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst
, temp_crit_hyst
, 0);
466 static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm
, status
, 1,
467 TMP432_STATUS_LOCAL
);
468 static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm
, status
, 2,
469 TMP432_STATUS_LOCAL
);
470 static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm
, status
, 3,
471 TMP432_STATUS_LOCAL
);
472 static SENSOR_DEVICE_ATTR_2_RO(temp2_input
, temp
, 0, 1);
473 static SENSOR_DEVICE_ATTR_2_RW(temp2_min
, temp
, 1, 1);
474 static SENSOR_DEVICE_ATTR_2_RW(temp2_max
, temp
, 2, 1);
475 static SENSOR_DEVICE_ATTR_2_RW(temp2_crit
, temp
, 3, 1);
476 static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst
, temp_crit_hyst
, 1);
477 static SENSOR_DEVICE_ATTR_2_RO(temp2_fault
, status
, 0, TMP432_STATUS_REMOTE1
);
478 static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm
, status
, 1,
479 TMP432_STATUS_REMOTE1
);
480 static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm
, status
, 2,
481 TMP432_STATUS_REMOTE1
);
482 static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm
, status
, 3,
483 TMP432_STATUS_REMOTE1
);
485 static DEVICE_ATTR_RW(update_interval
);
487 static struct attribute
*tmp401_attributes
[] = {
488 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
489 &sensor_dev_attr_temp1_min
.dev_attr
.attr
,
490 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
491 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
492 &sensor_dev_attr_temp1_crit_hyst
.dev_attr
.attr
,
493 &sensor_dev_attr_temp1_max_alarm
.dev_attr
.attr
,
494 &sensor_dev_attr_temp1_min_alarm
.dev_attr
.attr
,
495 &sensor_dev_attr_temp1_crit_alarm
.dev_attr
.attr
,
497 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
498 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
499 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
500 &sensor_dev_attr_temp2_crit
.dev_attr
.attr
,
501 &sensor_dev_attr_temp2_crit_hyst
.dev_attr
.attr
,
502 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
503 &sensor_dev_attr_temp2_max_alarm
.dev_attr
.attr
,
504 &sensor_dev_attr_temp2_min_alarm
.dev_attr
.attr
,
505 &sensor_dev_attr_temp2_crit_alarm
.dev_attr
.attr
,
507 &dev_attr_update_interval
.attr
,
512 static const struct attribute_group tmp401_group
= {
513 .attrs
= tmp401_attributes
,
517 * Additional features of the TMP411 chip.
518 * The TMP411 stores the minimum and maximum
519 * temperature measured since power-on, chip-reset, or
520 * minimum and maximum register reset for both the local
521 * and remote channels.
523 static SENSOR_DEVICE_ATTR_2_RO(temp1_lowest
, temp
, 4, 0);
524 static SENSOR_DEVICE_ATTR_2_RO(temp1_highest
, temp
, 5, 0);
525 static SENSOR_DEVICE_ATTR_2_RO(temp2_lowest
, temp
, 4, 1);
526 static SENSOR_DEVICE_ATTR_2_RO(temp2_highest
, temp
, 5, 1);
527 static SENSOR_DEVICE_ATTR_WO(temp_reset_history
, reset_temp_history
, 0);
529 static struct attribute
*tmp411_attributes
[] = {
530 &sensor_dev_attr_temp1_highest
.dev_attr
.attr
,
531 &sensor_dev_attr_temp1_lowest
.dev_attr
.attr
,
532 &sensor_dev_attr_temp2_highest
.dev_attr
.attr
,
533 &sensor_dev_attr_temp2_lowest
.dev_attr
.attr
,
534 &sensor_dev_attr_temp_reset_history
.dev_attr
.attr
,
538 static const struct attribute_group tmp411_group
= {
539 .attrs
= tmp411_attributes
,
542 static SENSOR_DEVICE_ATTR_2_RO(temp3_input
, temp
, 0, 2);
543 static SENSOR_DEVICE_ATTR_2_RW(temp3_min
, temp
, 1, 2);
544 static SENSOR_DEVICE_ATTR_2_RW(temp3_max
, temp
, 2, 2);
545 static SENSOR_DEVICE_ATTR_2_RW(temp3_crit
, temp
, 3, 2);
546 static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst
, temp_crit_hyst
, 2);
547 static SENSOR_DEVICE_ATTR_2_RO(temp3_fault
, status
, 0, TMP432_STATUS_REMOTE2
);
548 static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm
, status
, 1,
549 TMP432_STATUS_REMOTE2
);
550 static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm
, status
, 2,
551 TMP432_STATUS_REMOTE2
);
552 static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm
, status
, 3,
553 TMP432_STATUS_REMOTE2
);
555 static struct attribute
*tmp432_attributes
[] = {
556 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
557 &sensor_dev_attr_temp3_min
.dev_attr
.attr
,
558 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
559 &sensor_dev_attr_temp3_crit
.dev_attr
.attr
,
560 &sensor_dev_attr_temp3_crit_hyst
.dev_attr
.attr
,
561 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
562 &sensor_dev_attr_temp3_max_alarm
.dev_attr
.attr
,
563 &sensor_dev_attr_temp3_min_alarm
.dev_attr
.attr
,
564 &sensor_dev_attr_temp3_crit_alarm
.dev_attr
.attr
,
569 static const struct attribute_group tmp432_group
= {
570 .attrs
= tmp432_attributes
,
574 * Additional features of the TMP461 chip.
575 * The TMP461 temperature offset for the remote channel.
577 static SENSOR_DEVICE_ATTR_2_RW(temp2_offset
, temp
, 6, 1);
579 static struct attribute
*tmp461_attributes
[] = {
580 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
584 static const struct attribute_group tmp461_group
= {
585 .attrs
= tmp461_attributes
,
589 * Begin non sysfs callback code (aka Real code)
592 static int tmp401_init_client(struct tmp401_data
*data
,
593 struct i2c_client
*client
)
595 int config
, config_orig
, status
= 0;
597 /* Set the conversion rate to 2 Hz */
598 i2c_smbus_write_byte_data(client
, TMP401_CONVERSION_RATE_WRITE
, 5);
599 data
->update_interval
= 500;
601 /* Start conversions (disable shutdown if necessary) */
602 config
= i2c_smbus_read_byte_data(client
, TMP401_CONFIG_READ
);
606 config_orig
= config
;
607 config
&= ~TMP401_CONFIG_SHUTDOWN
;
609 if (config
!= config_orig
)
610 status
= i2c_smbus_write_byte_data(client
,
617 static int tmp401_detect(struct i2c_client
*client
,
618 struct i2c_board_info
*info
)
621 struct i2c_adapter
*adapter
= client
->adapter
;
624 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
627 /* Detect and identify the chip */
628 reg
= i2c_smbus_read_byte_data(client
, TMP401_MANUFACTURER_ID_REG
);
629 if (reg
!= TMP401_MANUFACTURER_ID
)
632 reg
= i2c_smbus_read_byte_data(client
, TMP401_DEVICE_ID_REG
);
635 case TMP401_DEVICE_ID
:
636 if (client
->addr
!= 0x4c)
640 case TMP411A_DEVICE_ID
:
641 if (client
->addr
!= 0x4c)
645 case TMP411B_DEVICE_ID
:
646 if (client
->addr
!= 0x4d)
650 case TMP411C_DEVICE_ID
:
651 if (client
->addr
!= 0x4e)
655 case TMP431_DEVICE_ID
:
656 if (client
->addr
!= 0x4c && client
->addr
!= 0x4d)
660 case TMP432_DEVICE_ID
:
661 if (client
->addr
!= 0x4c && client
->addr
!= 0x4d)
665 case TMP435_DEVICE_ID
:
672 reg
= i2c_smbus_read_byte_data(client
, TMP401_CONFIG_READ
);
676 reg
= i2c_smbus_read_byte_data(client
, TMP401_CONVERSION_RATE_READ
);
677 /* Datasheet says: 0x1-0x6 */
681 strlcpy(info
->type
, tmp401_id
[kind
].name
, I2C_NAME_SIZE
);
686 static int tmp401_probe(struct i2c_client
*client
,
687 const struct i2c_device_id
*id
)
689 static const char * const names
[] = {
690 "TMP401", "TMP411", "TMP431", "TMP432", "TMP435", "TMP461"
692 struct device
*dev
= &client
->dev
;
693 struct device
*hwmon_dev
;
694 struct tmp401_data
*data
;
695 int groups
= 0, status
;
697 data
= devm_kzalloc(dev
, sizeof(struct tmp401_data
), GFP_KERNEL
);
701 data
->client
= client
;
702 mutex_init(&data
->update_lock
);
703 data
->kind
= id
->driver_data
;
705 /* Initialize the TMP401 chip */
706 status
= tmp401_init_client(data
, client
);
710 /* Register sysfs hooks */
711 data
->groups
[groups
++] = &tmp401_group
;
713 /* Register additional tmp411 sysfs hooks */
714 if (data
->kind
== tmp411
)
715 data
->groups
[groups
++] = &tmp411_group
;
717 /* Register additional tmp432 sysfs hooks */
718 if (data
->kind
== tmp432
)
719 data
->groups
[groups
++] = &tmp432_group
;
721 if (data
->kind
== tmp461
)
722 data
->groups
[groups
++] = &tmp461_group
;
724 hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, client
->name
,
726 if (IS_ERR(hwmon_dev
))
727 return PTR_ERR(hwmon_dev
);
729 dev_info(dev
, "Detected TI %s chip\n", names
[data
->kind
]);
734 static struct i2c_driver tmp401_driver
= {
735 .class = I2C_CLASS_HWMON
,
739 .probe
= tmp401_probe
,
740 .id_table
= tmp401_id
,
741 .detect
= tmp401_detect
,
742 .address_list
= normal_i2c
,
745 module_i2c_driver(tmp401_driver
);
747 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
748 MODULE_DESCRIPTION("Texas Instruments TMP401 temperature sensor driver");
749 MODULE_LICENSE("GPL");