2 * Driver for Texas Instruments / National Semiconductor LM95234
4 * Copyright (c) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
6 * Derived from lm95241.c
7 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/jiffies.h>
24 #include <linux/i2c.h>
25 #include <linux/hwmon.h>
26 #include <linux/hwmon-sysfs.h>
27 #include <linux/err.h>
28 #include <linux/mutex.h>
29 #include <linux/sysfs.h>
31 #define DRVNAME "lm95234"
33 enum chips
{ lm95233
, lm95234
};
35 static const unsigned short normal_i2c
[] = {
36 0x18, 0x2a, 0x2b, 0x4d, 0x4e, I2C_CLIENT_END
};
38 /* LM95234 registers */
39 #define LM95234_REG_MAN_ID 0xFE
40 #define LM95234_REG_CHIP_ID 0xFF
41 #define LM95234_REG_STATUS 0x02
42 #define LM95234_REG_CONFIG 0x03
43 #define LM95234_REG_CONVRATE 0x04
44 #define LM95234_REG_STS_FAULT 0x07
45 #define LM95234_REG_STS_TCRIT1 0x08
46 #define LM95234_REG_STS_TCRIT2 0x09
47 #define LM95234_REG_TEMPH(x) ((x) + 0x10)
48 #define LM95234_REG_TEMPL(x) ((x) + 0x20)
49 #define LM95234_REG_UTEMPH(x) ((x) + 0x19) /* Remote only */
50 #define LM95234_REG_UTEMPL(x) ((x) + 0x29)
51 #define LM95234_REG_REM_MODEL 0x30
52 #define LM95234_REG_REM_MODEL_STS 0x38
53 #define LM95234_REG_OFFSET(x) ((x) + 0x31) /* Remote only */
54 #define LM95234_REG_TCRIT1(x) ((x) + 0x40)
55 #define LM95234_REG_TCRIT2(x) ((x) + 0x49) /* Remote channel 1,2 */
56 #define LM95234_REG_TCRIT_HYST 0x5a
58 #define NATSEMI_MAN_ID 0x01
59 #define LM95233_CHIP_ID 0x89
60 #define LM95234_CHIP_ID 0x79
62 /* Client data (each client gets its own) */
64 struct i2c_client
*client
;
65 const struct attribute_group
*groups
[3];
66 struct mutex update_lock
;
67 unsigned long last_updated
, interval
; /* in jiffies */
68 bool valid
; /* false until following fields are valid */
69 /* registers values */
70 int temp
[5]; /* temperature (signed) */
71 u32 status
; /* fault/alarm status */
72 u8 tcrit1
[5]; /* critical temperature limit */
73 u8 tcrit2
[2]; /* high temperature limit */
74 s8 toffset
[4]; /* remote temperature offset */
75 u8 thyst
; /* common hysteresis */
77 u8 sensor_type
; /* temperature sensor type */
80 static int lm95234_read_temp(struct i2c_client
*client
, int index
, int *t
)
86 val
= i2c_smbus_read_byte_data(client
,
87 LM95234_REG_UTEMPH(index
- 1));
91 val
= i2c_smbus_read_byte_data(client
,
92 LM95234_REG_UTEMPL(index
- 1));
99 * Read signed temperature if unsigned temperature is 0,
100 * or if this is the local sensor.
103 val
= i2c_smbus_read_byte_data(client
,
104 LM95234_REG_TEMPH(index
));
108 val
= i2c_smbus_read_byte_data(client
,
109 LM95234_REG_TEMPL(index
));
118 static u16 update_intervals
[] = { 143, 364, 1000, 2500 };
120 /* Fill value cache. Must be called with update lock held. */
122 static int lm95234_fill_cache(struct lm95234_data
*data
,
123 struct i2c_client
*client
)
127 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONVRATE
);
131 data
->interval
= msecs_to_jiffies(update_intervals
[ret
& 0x03]);
133 for (i
= 0; i
< ARRAY_SIZE(data
->tcrit1
); i
++) {
134 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_TCRIT1(i
));
137 data
->tcrit1
[i
] = ret
;
139 for (i
= 0; i
< ARRAY_SIZE(data
->tcrit2
); i
++) {
140 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_TCRIT2(i
));
143 data
->tcrit2
[i
] = ret
;
145 for (i
= 0; i
< ARRAY_SIZE(data
->toffset
); i
++) {
146 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_OFFSET(i
));
149 data
->toffset
[i
] = ret
;
152 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_TCRIT_HYST
);
157 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL
);
160 data
->sensor_type
= ret
;
165 static int lm95234_update_device(struct lm95234_data
*data
)
167 struct i2c_client
*client
= data
->client
;
170 mutex_lock(&data
->update_lock
);
172 if (time_after(jiffies
, data
->last_updated
+ data
->interval
) ||
177 ret
= lm95234_fill_cache(data
, client
);
183 for (i
= 0; i
< ARRAY_SIZE(data
->temp
); i
++) {
184 ret
= lm95234_read_temp(client
, i
, &data
->temp
[i
]);
189 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_STS_FAULT
);
194 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_STS_TCRIT1
);
197 data
->status
|= ret
<< 8;
199 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_STS_TCRIT2
);
202 data
->status
|= ret
<< 16;
204 data
->last_updated
= jiffies
;
209 mutex_unlock(&data
->update_lock
);
214 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
217 struct lm95234_data
*data
= dev_get_drvdata(dev
);
218 int index
= to_sensor_dev_attr(attr
)->index
;
219 int ret
= lm95234_update_device(data
);
224 return sprintf(buf
, "%d\n",
225 DIV_ROUND_CLOSEST(data
->temp
[index
] * 125, 32));
228 static ssize_t
show_alarm(struct device
*dev
,
229 struct device_attribute
*attr
, char *buf
)
231 struct lm95234_data
*data
= dev_get_drvdata(dev
);
232 u32 mask
= to_sensor_dev_attr(attr
)->index
;
233 int ret
= lm95234_update_device(data
);
238 return sprintf(buf
, "%u", !!(data
->status
& mask
));
241 static ssize_t
show_type(struct device
*dev
, struct device_attribute
*attr
,
244 struct lm95234_data
*data
= dev_get_drvdata(dev
);
245 u8 mask
= to_sensor_dev_attr(attr
)->index
;
246 int ret
= lm95234_update_device(data
);
251 return sprintf(buf
, data
->sensor_type
& mask
? "1\n" : "2\n");
254 static ssize_t
set_type(struct device
*dev
, struct device_attribute
*attr
,
255 const char *buf
, size_t count
)
257 struct lm95234_data
*data
= dev_get_drvdata(dev
);
259 u8 mask
= to_sensor_dev_attr(attr
)->index
;
260 int ret
= lm95234_update_device(data
);
265 ret
= kstrtoul(buf
, 10, &val
);
269 if (val
!= 1 && val
!= 2)
272 mutex_lock(&data
->update_lock
);
274 data
->sensor_type
|= mask
;
276 data
->sensor_type
&= ~mask
;
278 i2c_smbus_write_byte_data(data
->client
, LM95234_REG_REM_MODEL
,
280 mutex_unlock(&data
->update_lock
);
285 static ssize_t
show_tcrit2(struct device
*dev
, struct device_attribute
*attr
,
288 struct lm95234_data
*data
= dev_get_drvdata(dev
);
289 int index
= to_sensor_dev_attr(attr
)->index
;
290 int ret
= lm95234_update_device(data
);
295 return sprintf(buf
, "%u", data
->tcrit2
[index
] * 1000);
298 static ssize_t
set_tcrit2(struct device
*dev
, struct device_attribute
*attr
,
299 const char *buf
, size_t count
)
301 struct lm95234_data
*data
= dev_get_drvdata(dev
);
302 int index
= to_sensor_dev_attr(attr
)->index
;
304 int ret
= lm95234_update_device(data
);
309 ret
= kstrtol(buf
, 10, &val
);
313 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0, index
? 255 : 127);
315 mutex_lock(&data
->update_lock
);
316 data
->tcrit2
[index
] = val
;
317 i2c_smbus_write_byte_data(data
->client
, LM95234_REG_TCRIT2(index
), val
);
318 mutex_unlock(&data
->update_lock
);
323 static ssize_t
show_tcrit2_hyst(struct device
*dev
,
324 struct device_attribute
*attr
, char *buf
)
326 struct lm95234_data
*data
= dev_get_drvdata(dev
);
327 int index
= to_sensor_dev_attr(attr
)->index
;
328 int ret
= lm95234_update_device(data
);
333 /* Result can be negative, so be careful with unsigned operands */
334 return sprintf(buf
, "%d",
335 ((int)data
->tcrit2
[index
] - (int)data
->thyst
) * 1000);
338 static ssize_t
show_tcrit1(struct device
*dev
, struct device_attribute
*attr
,
341 struct lm95234_data
*data
= dev_get_drvdata(dev
);
342 int index
= to_sensor_dev_attr(attr
)->index
;
344 return sprintf(buf
, "%u", data
->tcrit1
[index
] * 1000);
347 static ssize_t
set_tcrit1(struct device
*dev
, struct device_attribute
*attr
,
348 const char *buf
, size_t count
)
350 struct lm95234_data
*data
= dev_get_drvdata(dev
);
351 int index
= to_sensor_dev_attr(attr
)->index
;
352 int ret
= lm95234_update_device(data
);
358 ret
= kstrtol(buf
, 10, &val
);
362 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0, 255);
364 mutex_lock(&data
->update_lock
);
365 data
->tcrit1
[index
] = val
;
366 i2c_smbus_write_byte_data(data
->client
, LM95234_REG_TCRIT1(index
), val
);
367 mutex_unlock(&data
->update_lock
);
372 static ssize_t
show_tcrit1_hyst(struct device
*dev
,
373 struct device_attribute
*attr
, char *buf
)
375 struct lm95234_data
*data
= dev_get_drvdata(dev
);
376 int index
= to_sensor_dev_attr(attr
)->index
;
377 int ret
= lm95234_update_device(data
);
382 /* Result can be negative, so be careful with unsigned operands */
383 return sprintf(buf
, "%d",
384 ((int)data
->tcrit1
[index
] - (int)data
->thyst
) * 1000);
387 static ssize_t
set_tcrit1_hyst(struct device
*dev
,
388 struct device_attribute
*attr
,
389 const char *buf
, size_t count
)
391 struct lm95234_data
*data
= dev_get_drvdata(dev
);
392 int index
= to_sensor_dev_attr(attr
)->index
;
393 int ret
= lm95234_update_device(data
);
399 ret
= kstrtol(buf
, 10, &val
);
403 val
= DIV_ROUND_CLOSEST(val
, 1000);
404 val
= clamp_val((int)data
->tcrit1
[index
] - val
, 0, 31);
406 mutex_lock(&data
->update_lock
);
408 i2c_smbus_write_byte_data(data
->client
, LM95234_REG_TCRIT_HYST
, val
);
409 mutex_unlock(&data
->update_lock
);
414 static ssize_t
show_offset(struct device
*dev
, struct device_attribute
*attr
,
417 struct lm95234_data
*data
= dev_get_drvdata(dev
);
418 int index
= to_sensor_dev_attr(attr
)->index
;
419 int ret
= lm95234_update_device(data
);
424 return sprintf(buf
, "%d", data
->toffset
[index
] * 500);
427 static ssize_t
set_offset(struct device
*dev
, struct device_attribute
*attr
,
428 const char *buf
, size_t count
)
430 struct lm95234_data
*data
= dev_get_drvdata(dev
);
431 int index
= to_sensor_dev_attr(attr
)->index
;
432 int ret
= lm95234_update_device(data
);
438 ret
= kstrtol(buf
, 10, &val
);
442 /* Accuracy is 1/2 degrees C */
443 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 500), -128, 127);
445 mutex_lock(&data
->update_lock
);
446 data
->toffset
[index
] = val
;
447 i2c_smbus_write_byte_data(data
->client
, LM95234_REG_OFFSET(index
), val
);
448 mutex_unlock(&data
->update_lock
);
453 static ssize_t
update_interval_show(struct device
*dev
,
454 struct device_attribute
*attr
, char *buf
)
456 struct lm95234_data
*data
= dev_get_drvdata(dev
);
457 int ret
= lm95234_update_device(data
);
462 return sprintf(buf
, "%lu\n",
463 DIV_ROUND_CLOSEST(data
->interval
* 1000, HZ
));
466 static ssize_t
update_interval_store(struct device
*dev
,
467 struct device_attribute
*attr
,
468 const char *buf
, size_t count
)
470 struct lm95234_data
*data
= dev_get_drvdata(dev
);
471 int ret
= lm95234_update_device(data
);
478 ret
= kstrtoul(buf
, 10, &val
);
482 for (regval
= 0; regval
< 3; regval
++) {
483 if (val
<= update_intervals
[regval
])
487 mutex_lock(&data
->update_lock
);
488 data
->interval
= msecs_to_jiffies(update_intervals
[regval
]);
489 i2c_smbus_write_byte_data(data
->client
, LM95234_REG_CONVRATE
, regval
);
490 mutex_unlock(&data
->update_lock
);
495 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
496 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
497 static SENSOR_DEVICE_ATTR(temp3_input
, S_IRUGO
, show_temp
, NULL
, 2);
498 static SENSOR_DEVICE_ATTR(temp4_input
, S_IRUGO
, show_temp
, NULL
, 3);
499 static SENSOR_DEVICE_ATTR(temp5_input
, S_IRUGO
, show_temp
, NULL
, 4);
501 static SENSOR_DEVICE_ATTR(temp2_fault
, S_IRUGO
, show_alarm
, NULL
,
503 static SENSOR_DEVICE_ATTR(temp3_fault
, S_IRUGO
, show_alarm
, NULL
,
505 static SENSOR_DEVICE_ATTR(temp4_fault
, S_IRUGO
, show_alarm
, NULL
,
507 static SENSOR_DEVICE_ATTR(temp5_fault
, S_IRUGO
, show_alarm
, NULL
,
510 static SENSOR_DEVICE_ATTR(temp2_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
512 static SENSOR_DEVICE_ATTR(temp3_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
514 static SENSOR_DEVICE_ATTR(temp4_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
516 static SENSOR_DEVICE_ATTR(temp5_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
519 static SENSOR_DEVICE_ATTR(temp1_max
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
521 static SENSOR_DEVICE_ATTR(temp2_max
, S_IWUSR
| S_IRUGO
, show_tcrit2
,
523 static SENSOR_DEVICE_ATTR(temp3_max
, S_IWUSR
| S_IRUGO
, show_tcrit2
,
525 static SENSOR_DEVICE_ATTR(temp4_max
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
527 static SENSOR_DEVICE_ATTR(temp5_max
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
530 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IWUSR
| S_IRUGO
, show_tcrit1_hyst
,
532 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
, show_tcrit2_hyst
, NULL
, 0);
533 static SENSOR_DEVICE_ATTR(temp3_max_hyst
, S_IRUGO
, show_tcrit2_hyst
, NULL
, 1);
534 static SENSOR_DEVICE_ATTR(temp4_max_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 3);
535 static SENSOR_DEVICE_ATTR(temp5_max_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 4);
537 static SENSOR_DEVICE_ATTR(temp1_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
539 static SENSOR_DEVICE_ATTR(temp2_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
541 static SENSOR_DEVICE_ATTR(temp3_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
543 static SENSOR_DEVICE_ATTR(temp4_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
545 static SENSOR_DEVICE_ATTR(temp5_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
548 static SENSOR_DEVICE_ATTR(temp2_crit
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
550 static SENSOR_DEVICE_ATTR(temp3_crit
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
553 static SENSOR_DEVICE_ATTR(temp2_crit_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 1);
554 static SENSOR_DEVICE_ATTR(temp3_crit_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 2);
556 static SENSOR_DEVICE_ATTR(temp2_crit_alarm
, S_IRUGO
, show_alarm
, NULL
,
558 static SENSOR_DEVICE_ATTR(temp3_crit_alarm
, S_IRUGO
, show_alarm
, NULL
,
561 static SENSOR_DEVICE_ATTR(temp2_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
563 static SENSOR_DEVICE_ATTR(temp3_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
565 static SENSOR_DEVICE_ATTR(temp4_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
567 static SENSOR_DEVICE_ATTR(temp5_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
570 static DEVICE_ATTR_RW(update_interval
);
572 static struct attribute
*lm95234_common_attrs
[] = {
573 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
574 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
575 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
576 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
577 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
578 &sensor_dev_attr_temp2_type
.dev_attr
.attr
,
579 &sensor_dev_attr_temp3_type
.dev_attr
.attr
,
580 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
581 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
582 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
583 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
584 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
585 &sensor_dev_attr_temp3_max_hyst
.dev_attr
.attr
,
586 &sensor_dev_attr_temp1_max_alarm
.dev_attr
.attr
,
587 &sensor_dev_attr_temp2_max_alarm
.dev_attr
.attr
,
588 &sensor_dev_attr_temp3_max_alarm
.dev_attr
.attr
,
589 &sensor_dev_attr_temp2_crit
.dev_attr
.attr
,
590 &sensor_dev_attr_temp3_crit
.dev_attr
.attr
,
591 &sensor_dev_attr_temp2_crit_hyst
.dev_attr
.attr
,
592 &sensor_dev_attr_temp3_crit_hyst
.dev_attr
.attr
,
593 &sensor_dev_attr_temp2_crit_alarm
.dev_attr
.attr
,
594 &sensor_dev_attr_temp3_crit_alarm
.dev_attr
.attr
,
595 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
596 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
597 &dev_attr_update_interval
.attr
,
601 static const struct attribute_group lm95234_common_group
= {
602 .attrs
= lm95234_common_attrs
,
605 static struct attribute
*lm95234_attrs
[] = {
606 &sensor_dev_attr_temp4_input
.dev_attr
.attr
,
607 &sensor_dev_attr_temp5_input
.dev_attr
.attr
,
608 &sensor_dev_attr_temp4_fault
.dev_attr
.attr
,
609 &sensor_dev_attr_temp5_fault
.dev_attr
.attr
,
610 &sensor_dev_attr_temp4_type
.dev_attr
.attr
,
611 &sensor_dev_attr_temp5_type
.dev_attr
.attr
,
612 &sensor_dev_attr_temp4_max
.dev_attr
.attr
,
613 &sensor_dev_attr_temp5_max
.dev_attr
.attr
,
614 &sensor_dev_attr_temp4_max_hyst
.dev_attr
.attr
,
615 &sensor_dev_attr_temp5_max_hyst
.dev_attr
.attr
,
616 &sensor_dev_attr_temp4_max_alarm
.dev_attr
.attr
,
617 &sensor_dev_attr_temp5_max_alarm
.dev_attr
.attr
,
618 &sensor_dev_attr_temp4_offset
.dev_attr
.attr
,
619 &sensor_dev_attr_temp5_offset
.dev_attr
.attr
,
623 static const struct attribute_group lm95234_group
= {
624 .attrs
= lm95234_attrs
,
627 static int lm95234_detect(struct i2c_client
*client
,
628 struct i2c_board_info
*info
)
630 struct i2c_adapter
*adapter
= client
->adapter
;
631 int address
= client
->addr
;
632 u8 config_mask
, model_mask
;
633 int mfg_id
, chip_id
, val
;
636 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
639 mfg_id
= i2c_smbus_read_byte_data(client
, LM95234_REG_MAN_ID
);
640 if (mfg_id
!= NATSEMI_MAN_ID
)
643 chip_id
= i2c_smbus_read_byte_data(client
, LM95234_REG_CHIP_ID
);
645 case LM95233_CHIP_ID
:
646 if (address
!= 0x18 && address
!= 0x2a && address
!= 0x2b)
652 case LM95234_CHIP_ID
:
653 if (address
!= 0x18 && address
!= 0x4d && address
!= 0x4e)
663 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_STATUS
);
667 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONFIG
);
668 if (val
& config_mask
)
671 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONVRATE
);
675 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL
);
676 if (val
& model_mask
)
679 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL_STS
);
680 if (val
& model_mask
)
683 strlcpy(info
->type
, name
, I2C_NAME_SIZE
);
687 static int lm95234_init_client(struct i2c_client
*client
)
691 /* start conversion if necessary */
692 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONFIG
);
696 i2c_smbus_write_byte_data(client
, LM95234_REG_CONFIG
,
699 /* If diode type status reports an error, try to fix it */
700 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL_STS
);
703 model
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL
);
707 dev_notice(&client
->dev
,
708 "Fixing remote diode type misconfiguration (0x%x)\n",
710 i2c_smbus_write_byte_data(client
, LM95234_REG_REM_MODEL
,
716 static int lm95234_probe(struct i2c_client
*client
,
717 const struct i2c_device_id
*id
)
719 struct device
*dev
= &client
->dev
;
720 struct lm95234_data
*data
;
721 struct device
*hwmon_dev
;
724 data
= devm_kzalloc(dev
, sizeof(struct lm95234_data
), GFP_KERNEL
);
728 data
->client
= client
;
729 mutex_init(&data
->update_lock
);
731 /* Initialize the LM95234 chip */
732 err
= lm95234_init_client(client
);
736 data
->groups
[0] = &lm95234_common_group
;
737 if (id
->driver_data
== lm95234
)
738 data
->groups
[1] = &lm95234_group
;
740 hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, client
->name
,
742 return PTR_ERR_OR_ZERO(hwmon_dev
);
745 /* Driver data (common to all clients) */
746 static const struct i2c_device_id lm95234_id
[] = {
747 { "lm95233", lm95233
},
748 { "lm95234", lm95234
},
751 MODULE_DEVICE_TABLE(i2c
, lm95234_id
);
753 static struct i2c_driver lm95234_driver
= {
754 .class = I2C_CLASS_HWMON
,
758 .probe
= lm95234_probe
,
759 .id_table
= lm95234_id
,
760 .detect
= lm95234_detect
,
761 .address_list
= normal_i2c
,
764 module_i2c_driver(lm95234_driver
);
766 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
767 MODULE_DESCRIPTION("LM95233/LM95234 sensor driver");
768 MODULE_LICENSE("GPL");