2 * Driver for Texas Instruments / National Semiconductor LM95234
4 * Copyright (c) 2013 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 static const unsigned short normal_i2c
[] = { 0x18, 0x4d, 0x4e, I2C_CLIENT_END
};
35 /* LM95234 registers */
36 #define LM95234_REG_MAN_ID 0xFE
37 #define LM95234_REG_CHIP_ID 0xFF
38 #define LM95234_REG_STATUS 0x02
39 #define LM95234_REG_CONFIG 0x03
40 #define LM95234_REG_CONVRATE 0x04
41 #define LM95234_REG_STS_FAULT 0x07
42 #define LM95234_REG_STS_TCRIT1 0x08
43 #define LM95234_REG_STS_TCRIT2 0x09
44 #define LM95234_REG_TEMPH(x) ((x) + 0x10)
45 #define LM95234_REG_TEMPL(x) ((x) + 0x20)
46 #define LM95234_REG_UTEMPH(x) ((x) + 0x19) /* Remote only */
47 #define LM95234_REG_UTEMPL(x) ((x) + 0x29)
48 #define LM95234_REG_REM_MODEL 0x30
49 #define LM95234_REG_REM_MODEL_STS 0x38
50 #define LM95234_REG_OFFSET(x) ((x) + 0x31) /* Remote only */
51 #define LM95234_REG_TCRIT1(x) ((x) + 0x40)
52 #define LM95234_REG_TCRIT2(x) ((x) + 0x49) /* Remote channel 1,2 */
53 #define LM95234_REG_TCRIT_HYST 0x5a
55 #define NATSEMI_MAN_ID 0x01
56 #define LM95234_CHIP_ID 0x79
58 /* Client data (each client gets its own) */
60 struct device
*hwmon_dev
;
61 struct mutex update_lock
;
62 unsigned long last_updated
, interval
; /* in jiffies */
63 bool valid
; /* false until following fields are valid */
64 /* registers values */
65 int temp
[5]; /* temperature (signed) */
66 u32 status
; /* fault/alarm status */
67 u8 tcrit1
[5]; /* critical temperature limit */
68 u8 tcrit2
[2]; /* high temperature limit */
69 s8 toffset
[4]; /* remote temperature offset */
70 u8 thyst
; /* common hysteresis */
72 u8 sensor_type
; /* temperature sensor type */
75 static int lm95234_read_temp(struct i2c_client
*client
, int index
, int *t
)
81 val
= i2c_smbus_read_byte_data(client
,
82 LM95234_REG_UTEMPH(index
- 1));
86 val
= i2c_smbus_read_byte_data(client
,
87 LM95234_REG_UTEMPL(index
- 1));
94 * Read signed temperature if unsigned temperature is 0,
95 * or if this is the local sensor.
98 val
= i2c_smbus_read_byte_data(client
,
99 LM95234_REG_TEMPH(index
));
103 val
= i2c_smbus_read_byte_data(client
,
104 LM95234_REG_TEMPL(index
));
113 static u16 update_intervals
[] = { 143, 364, 1000, 2500 };
115 /* Fill value cache. Must be called with update lock held. */
117 static int lm95234_fill_cache(struct i2c_client
*client
)
119 struct lm95234_data
*data
= i2c_get_clientdata(client
);
122 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONVRATE
);
126 data
->interval
= msecs_to_jiffies(update_intervals
[ret
& 0x03]);
128 for (i
= 0; i
< ARRAY_SIZE(data
->tcrit1
); i
++) {
129 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_TCRIT1(i
));
132 data
->tcrit1
[i
] = ret
;
134 for (i
= 0; i
< ARRAY_SIZE(data
->tcrit2
); i
++) {
135 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_TCRIT2(i
));
138 data
->tcrit2
[i
] = ret
;
140 for (i
= 0; i
< ARRAY_SIZE(data
->toffset
); i
++) {
141 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_OFFSET(i
));
144 data
->toffset
[i
] = ret
;
147 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_TCRIT_HYST
);
152 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL
);
155 data
->sensor_type
= ret
;
160 static int lm95234_update_device(struct i2c_client
*client
,
161 struct lm95234_data
*data
)
165 mutex_lock(&data
->update_lock
);
167 if (time_after(jiffies
, data
->last_updated
+ data
->interval
) ||
172 ret
= lm95234_fill_cache(client
);
178 for (i
= 0; i
< ARRAY_SIZE(data
->temp
); i
++) {
179 ret
= lm95234_read_temp(client
, i
, &data
->temp
[i
]);
184 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_STS_FAULT
);
189 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_STS_TCRIT1
);
192 data
->status
|= ret
<< 8;
194 ret
= i2c_smbus_read_byte_data(client
, LM95234_REG_STS_TCRIT2
);
197 data
->status
|= ret
<< 16;
199 data
->last_updated
= jiffies
;
204 mutex_unlock(&data
->update_lock
);
209 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
212 struct i2c_client
*client
= to_i2c_client(dev
);
213 struct lm95234_data
*data
= i2c_get_clientdata(client
);
214 int index
= to_sensor_dev_attr(attr
)->index
;
215 int ret
= lm95234_update_device(client
, data
);
220 return sprintf(buf
, "%d\n",
221 DIV_ROUND_CLOSEST(data
->temp
[index
] * 125, 32));
224 static ssize_t
show_alarm(struct device
*dev
,
225 struct device_attribute
*attr
, char *buf
)
227 struct i2c_client
*client
= to_i2c_client(dev
);
228 struct lm95234_data
*data
= i2c_get_clientdata(client
);
229 u32 mask
= to_sensor_dev_attr(attr
)->index
;
230 int ret
= lm95234_update_device(client
, data
);
235 return sprintf(buf
, "%u", !!(data
->status
& mask
));
238 static ssize_t
show_type(struct device
*dev
, struct device_attribute
*attr
,
241 struct i2c_client
*client
= to_i2c_client(dev
);
242 struct lm95234_data
*data
= i2c_get_clientdata(client
);
243 u8 mask
= to_sensor_dev_attr(attr
)->index
;
244 int ret
= lm95234_update_device(client
, data
);
249 return sprintf(buf
, data
->sensor_type
& mask
? "1\n" : "2\n");
252 static ssize_t
set_type(struct device
*dev
, struct device_attribute
*attr
,
253 const char *buf
, size_t count
)
255 struct i2c_client
*client
= to_i2c_client(dev
);
256 struct lm95234_data
*data
= i2c_get_clientdata(client
);
258 u8 mask
= to_sensor_dev_attr(attr
)->index
;
259 int ret
= lm95234_update_device(client
, data
);
264 ret
= kstrtoul(buf
, 10, &val
);
268 if (val
!= 1 && val
!= 2)
271 mutex_lock(&data
->update_lock
);
273 data
->sensor_type
|= mask
;
275 data
->sensor_type
&= ~mask
;
277 i2c_smbus_write_byte_data(client
, LM95234_REG_REM_MODEL
,
279 mutex_unlock(&data
->update_lock
);
284 static ssize_t
show_tcrit2(struct device
*dev
, struct device_attribute
*attr
,
287 struct i2c_client
*client
= to_i2c_client(dev
);
288 struct lm95234_data
*data
= i2c_get_clientdata(client
);
289 int index
= to_sensor_dev_attr(attr
)->index
;
290 int ret
= lm95234_update_device(client
, 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 i2c_client
*client
= to_i2c_client(dev
);
302 struct lm95234_data
*data
= i2c_get_clientdata(client
);
303 int index
= to_sensor_dev_attr(attr
)->index
;
305 int ret
= lm95234_update_device(client
, data
);
310 ret
= kstrtol(buf
, 10, &val
);
314 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0, index
? 255 : 127);
316 mutex_lock(&data
->update_lock
);
317 data
->tcrit2
[index
] = val
;
318 i2c_smbus_write_byte_data(client
, LM95234_REG_TCRIT2(index
), val
);
319 mutex_unlock(&data
->update_lock
);
324 static ssize_t
show_tcrit2_hyst(struct device
*dev
,
325 struct device_attribute
*attr
, char *buf
)
327 struct i2c_client
*client
= to_i2c_client(dev
);
328 struct lm95234_data
*data
= i2c_get_clientdata(client
);
329 int index
= to_sensor_dev_attr(attr
)->index
;
330 int ret
= lm95234_update_device(client
, data
);
335 /* Result can be negative, so be careful with unsigned operands */
336 return sprintf(buf
, "%d",
337 ((int)data
->tcrit2
[index
] - (int)data
->thyst
) * 1000);
340 static ssize_t
show_tcrit1(struct device
*dev
, struct device_attribute
*attr
,
343 struct i2c_client
*client
= to_i2c_client(dev
);
344 struct lm95234_data
*data
= i2c_get_clientdata(client
);
345 int index
= to_sensor_dev_attr(attr
)->index
;
347 return sprintf(buf
, "%u", data
->tcrit1
[index
] * 1000);
350 static ssize_t
set_tcrit1(struct device
*dev
, struct device_attribute
*attr
,
351 const char *buf
, size_t count
)
353 struct i2c_client
*client
= to_i2c_client(dev
);
354 struct lm95234_data
*data
= i2c_get_clientdata(client
);
355 int index
= to_sensor_dev_attr(attr
)->index
;
357 int ret
= lm95234_update_device(client
, data
);
362 ret
= kstrtol(buf
, 10, &val
);
366 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0, 255);
368 mutex_lock(&data
->update_lock
);
369 data
->tcrit1
[index
] = val
;
370 i2c_smbus_write_byte_data(client
, LM95234_REG_TCRIT1(index
), val
);
371 mutex_unlock(&data
->update_lock
);
376 static ssize_t
show_tcrit1_hyst(struct device
*dev
,
377 struct device_attribute
*attr
, char *buf
)
379 struct i2c_client
*client
= to_i2c_client(dev
);
380 struct lm95234_data
*data
= i2c_get_clientdata(client
);
381 int index
= to_sensor_dev_attr(attr
)->index
;
382 int ret
= lm95234_update_device(client
, data
);
387 /* Result can be negative, so be careful with unsigned operands */
388 return sprintf(buf
, "%d",
389 ((int)data
->tcrit1
[index
] - (int)data
->thyst
) * 1000);
392 static ssize_t
set_tcrit1_hyst(struct device
*dev
,
393 struct device_attribute
*attr
,
394 const char *buf
, size_t count
)
396 struct i2c_client
*client
= to_i2c_client(dev
);
397 struct lm95234_data
*data
= i2c_get_clientdata(client
);
398 int index
= to_sensor_dev_attr(attr
)->index
;
400 int ret
= lm95234_update_device(client
, data
);
405 ret
= kstrtol(buf
, 10, &val
);
409 val
= DIV_ROUND_CLOSEST(val
, 1000);
410 val
= clamp_val((int)data
->tcrit1
[index
] - val
, 0, 31);
412 mutex_lock(&data
->update_lock
);
414 i2c_smbus_write_byte_data(client
, LM95234_REG_TCRIT_HYST
, val
);
415 mutex_unlock(&data
->update_lock
);
420 static ssize_t
show_offset(struct device
*dev
, struct device_attribute
*attr
,
423 struct i2c_client
*client
= to_i2c_client(dev
);
424 struct lm95234_data
*data
= i2c_get_clientdata(client
);
425 int index
= to_sensor_dev_attr(attr
)->index
;
426 int ret
= lm95234_update_device(client
, data
);
431 return sprintf(buf
, "%d", data
->toffset
[index
] * 500);
434 static ssize_t
set_offset(struct device
*dev
, struct device_attribute
*attr
,
435 const char *buf
, size_t count
)
437 struct i2c_client
*client
= to_i2c_client(dev
);
438 struct lm95234_data
*data
= i2c_get_clientdata(client
);
439 int index
= to_sensor_dev_attr(attr
)->index
;
441 int ret
= lm95234_update_device(client
, data
);
446 ret
= kstrtol(buf
, 10, &val
);
450 /* Accuracy is 1/2 degrees C */
451 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 500), -128, 127);
453 mutex_lock(&data
->update_lock
);
454 data
->toffset
[index
] = val
;
455 i2c_smbus_write_byte_data(client
, LM95234_REG_OFFSET(index
), val
);
456 mutex_unlock(&data
->update_lock
);
461 static ssize_t
show_interval(struct device
*dev
, struct device_attribute
*attr
,
464 struct i2c_client
*client
= to_i2c_client(dev
);
465 struct lm95234_data
*data
= i2c_get_clientdata(client
);
466 int ret
= lm95234_update_device(client
, data
);
471 return sprintf(buf
, "%lu\n",
472 DIV_ROUND_CLOSEST(data
->interval
* 1000, HZ
));
475 static ssize_t
set_interval(struct device
*dev
, struct device_attribute
*attr
,
476 const char *buf
, size_t count
)
478 struct i2c_client
*client
= to_i2c_client(dev
);
479 struct lm95234_data
*data
= i2c_get_clientdata(client
);
482 int ret
= lm95234_update_device(client
, data
);
487 ret
= kstrtoul(buf
, 10, &val
);
491 for (regval
= 0; regval
< 3; regval
++) {
492 if (val
<= update_intervals
[regval
])
496 mutex_lock(&data
->update_lock
);
497 data
->interval
= msecs_to_jiffies(update_intervals
[regval
]);
498 i2c_smbus_write_byte_data(client
, LM95234_REG_CONVRATE
, regval
);
499 mutex_unlock(&data
->update_lock
);
504 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
505 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
506 static SENSOR_DEVICE_ATTR(temp3_input
, S_IRUGO
, show_temp
, NULL
, 2);
507 static SENSOR_DEVICE_ATTR(temp4_input
, S_IRUGO
, show_temp
, NULL
, 3);
508 static SENSOR_DEVICE_ATTR(temp5_input
, S_IRUGO
, show_temp
, NULL
, 4);
510 static SENSOR_DEVICE_ATTR(temp2_fault
, S_IRUGO
, show_alarm
, NULL
,
512 static SENSOR_DEVICE_ATTR(temp3_fault
, S_IRUGO
, show_alarm
, NULL
,
514 static SENSOR_DEVICE_ATTR(temp4_fault
, S_IRUGO
, show_alarm
, NULL
,
516 static SENSOR_DEVICE_ATTR(temp5_fault
, S_IRUGO
, show_alarm
, NULL
,
519 static SENSOR_DEVICE_ATTR(temp2_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
521 static SENSOR_DEVICE_ATTR(temp3_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
523 static SENSOR_DEVICE_ATTR(temp4_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
525 static SENSOR_DEVICE_ATTR(temp5_type
, S_IWUSR
| S_IRUGO
, show_type
, set_type
,
528 static SENSOR_DEVICE_ATTR(temp1_max
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
530 static SENSOR_DEVICE_ATTR(temp2_max
, S_IWUSR
| S_IRUGO
, show_tcrit2
,
532 static SENSOR_DEVICE_ATTR(temp3_max
, S_IWUSR
| S_IRUGO
, show_tcrit2
,
534 static SENSOR_DEVICE_ATTR(temp4_max
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
536 static SENSOR_DEVICE_ATTR(temp5_max
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
539 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IWUSR
| S_IRUGO
, show_tcrit1_hyst
,
541 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
, show_tcrit2_hyst
, NULL
, 0);
542 static SENSOR_DEVICE_ATTR(temp3_max_hyst
, S_IRUGO
, show_tcrit2_hyst
, NULL
, 1);
543 static SENSOR_DEVICE_ATTR(temp4_max_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 3);
544 static SENSOR_DEVICE_ATTR(temp5_max_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 4);
546 static SENSOR_DEVICE_ATTR(temp1_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
548 static SENSOR_DEVICE_ATTR(temp2_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
550 static SENSOR_DEVICE_ATTR(temp3_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
552 static SENSOR_DEVICE_ATTR(temp4_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
554 static SENSOR_DEVICE_ATTR(temp5_max_alarm
, S_IRUGO
, show_alarm
, NULL
,
557 static SENSOR_DEVICE_ATTR(temp2_crit
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
559 static SENSOR_DEVICE_ATTR(temp3_crit
, S_IWUSR
| S_IRUGO
, show_tcrit1
,
562 static SENSOR_DEVICE_ATTR(temp2_crit_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 1);
563 static SENSOR_DEVICE_ATTR(temp3_crit_hyst
, S_IRUGO
, show_tcrit1_hyst
, NULL
, 2);
565 static SENSOR_DEVICE_ATTR(temp2_crit_alarm
, S_IRUGO
, show_alarm
, NULL
,
567 static SENSOR_DEVICE_ATTR(temp3_crit_alarm
, S_IRUGO
, show_alarm
, NULL
,
570 static SENSOR_DEVICE_ATTR(temp2_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
572 static SENSOR_DEVICE_ATTR(temp3_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
574 static SENSOR_DEVICE_ATTR(temp4_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
576 static SENSOR_DEVICE_ATTR(temp5_offset
, S_IWUSR
| S_IRUGO
, show_offset
,
579 static DEVICE_ATTR(update_interval
, S_IWUSR
| S_IRUGO
, show_interval
,
582 static struct attribute
*lm95234_attributes
[] = {
583 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
584 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
585 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
586 &sensor_dev_attr_temp4_input
.dev_attr
.attr
,
587 &sensor_dev_attr_temp5_input
.dev_attr
.attr
,
588 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
589 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
590 &sensor_dev_attr_temp4_fault
.dev_attr
.attr
,
591 &sensor_dev_attr_temp5_fault
.dev_attr
.attr
,
592 &sensor_dev_attr_temp2_type
.dev_attr
.attr
,
593 &sensor_dev_attr_temp3_type
.dev_attr
.attr
,
594 &sensor_dev_attr_temp4_type
.dev_attr
.attr
,
595 &sensor_dev_attr_temp5_type
.dev_attr
.attr
,
596 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
597 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
598 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
599 &sensor_dev_attr_temp4_max
.dev_attr
.attr
,
600 &sensor_dev_attr_temp5_max
.dev_attr
.attr
,
601 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
602 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
603 &sensor_dev_attr_temp3_max_hyst
.dev_attr
.attr
,
604 &sensor_dev_attr_temp4_max_hyst
.dev_attr
.attr
,
605 &sensor_dev_attr_temp5_max_hyst
.dev_attr
.attr
,
606 &sensor_dev_attr_temp1_max_alarm
.dev_attr
.attr
,
607 &sensor_dev_attr_temp2_max_alarm
.dev_attr
.attr
,
608 &sensor_dev_attr_temp3_max_alarm
.dev_attr
.attr
,
609 &sensor_dev_attr_temp4_max_alarm
.dev_attr
.attr
,
610 &sensor_dev_attr_temp5_max_alarm
.dev_attr
.attr
,
611 &sensor_dev_attr_temp2_crit
.dev_attr
.attr
,
612 &sensor_dev_attr_temp3_crit
.dev_attr
.attr
,
613 &sensor_dev_attr_temp2_crit_hyst
.dev_attr
.attr
,
614 &sensor_dev_attr_temp3_crit_hyst
.dev_attr
.attr
,
615 &sensor_dev_attr_temp2_crit_alarm
.dev_attr
.attr
,
616 &sensor_dev_attr_temp3_crit_alarm
.dev_attr
.attr
,
617 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
618 &sensor_dev_attr_temp3_offset
.dev_attr
.attr
,
619 &sensor_dev_attr_temp4_offset
.dev_attr
.attr
,
620 &sensor_dev_attr_temp5_offset
.dev_attr
.attr
,
621 &dev_attr_update_interval
.attr
,
625 static const struct attribute_group lm95234_group
= {
626 .attrs
= lm95234_attributes
,
629 static int lm95234_detect(struct i2c_client
*client
,
630 struct i2c_board_info
*info
)
632 struct i2c_adapter
*adapter
= client
->adapter
;
633 int mfg_id
, chip_id
, val
;
635 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
638 mfg_id
= i2c_smbus_read_byte_data(client
, LM95234_REG_MAN_ID
);
639 if (mfg_id
!= NATSEMI_MAN_ID
)
642 chip_id
= i2c_smbus_read_byte_data(client
, LM95234_REG_CHIP_ID
);
643 if (chip_id
!= LM95234_CHIP_ID
)
646 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_STATUS
);
650 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONFIG
);
654 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONVRATE
);
658 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL
);
662 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL_STS
);
666 strlcpy(info
->type
, "lm95234", I2C_NAME_SIZE
);
670 static int lm95234_init_client(struct i2c_client
*client
)
674 /* start conversion if necessary */
675 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_CONFIG
);
679 i2c_smbus_write_byte_data(client
, LM95234_REG_CONFIG
,
682 /* If diode type status reports an error, try to fix it */
683 val
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL_STS
);
686 model
= i2c_smbus_read_byte_data(client
, LM95234_REG_REM_MODEL
);
690 dev_notice(&client
->dev
,
691 "Fixing remote diode type misconfiguration (0x%x)\n",
693 i2c_smbus_write_byte_data(client
, LM95234_REG_REM_MODEL
,
699 static int lm95234_probe(struct i2c_client
*client
,
700 const struct i2c_device_id
*id
)
702 struct device
*dev
= &client
->dev
;
703 struct lm95234_data
*data
;
706 data
= devm_kzalloc(dev
, sizeof(struct lm95234_data
), GFP_KERNEL
);
710 i2c_set_clientdata(client
, data
);
711 mutex_init(&data
->update_lock
);
713 /* Initialize the LM95234 chip */
714 err
= lm95234_init_client(client
);
718 /* Register sysfs hooks */
719 err
= sysfs_create_group(&dev
->kobj
, &lm95234_group
);
723 data
->hwmon_dev
= hwmon_device_register(dev
);
724 if (IS_ERR(data
->hwmon_dev
)) {
725 err
= PTR_ERR(data
->hwmon_dev
);
726 goto exit_remove_files
;
732 sysfs_remove_group(&dev
->kobj
, &lm95234_group
);
736 static int lm95234_remove(struct i2c_client
*client
)
738 struct lm95234_data
*data
= i2c_get_clientdata(client
);
740 hwmon_device_unregister(data
->hwmon_dev
);
741 sysfs_remove_group(&client
->dev
.kobj
, &lm95234_group
);
746 /* Driver data (common to all clients) */
747 static const struct i2c_device_id lm95234_id
[] = {
751 MODULE_DEVICE_TABLE(i2c
, lm95234_id
);
753 static struct i2c_driver lm95234_driver
= {
754 .class = I2C_CLASS_HWMON
,
758 .probe
= lm95234_probe
,
759 .remove
= lm95234_remove
,
760 .id_table
= lm95234_id
,
761 .detect
= lm95234_detect
,
762 .address_list
= normal_i2c
,
765 module_i2c_driver(lm95234_driver
);
767 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
768 MODULE_DESCRIPTION("LM95234 sensor driver");
769 MODULE_LICENSE("GPL");