2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 * with integrated fan control
4 * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org>
5 * Based on the lm90 driver.
7 * The LM63 is a sensor chip made by National Semiconductor. It measures
8 * two temperatures (its own and one external one) and the speed of one
9 * fan, those speed it can additionally control. Complete datasheet can be
10 * obtained from National's website at:
11 * http://www.national.com/pf/LM/LM63.html
13 * The LM63 is basically an LM86 with fan speed monitoring and control
14 * capabilities added. It misses some of the LM86 features though:
15 * - No low limit for local temperature.
16 * - No critical limit for local temperature.
17 * - Critical limit for remote temperature can be changed only once. We
18 * will consider that the critical limit is read-only.
20 * The datasheet isn't very clear about what the tachometer reading is.
21 * I had a explanation from National Semiconductor though. The two lower
22 * bits of the read value have to be masked out. The value is still 16 bit
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/jiffies.h>
44 #include <linux/i2c.h>
45 #include <linux/hwmon-sysfs.h>
46 #include <linux/hwmon.h>
47 #include <linux/err.h>
48 #include <linux/mutex.h>
49 #include <linux/sysfs.h>
50 #include <linux/types.h>
54 * Address is fully defined internally and cannot be changed.
57 static const unsigned short normal_i2c
[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END
};
63 #define LM63_REG_CONFIG1 0x03
64 #define LM63_REG_CONFIG2 0xBF
65 #define LM63_REG_CONFIG_FAN 0x4A
67 #define LM63_REG_TACH_COUNT_MSB 0x47
68 #define LM63_REG_TACH_COUNT_LSB 0x46
69 #define LM63_REG_TACH_LIMIT_MSB 0x49
70 #define LM63_REG_TACH_LIMIT_LSB 0x48
72 #define LM63_REG_PWM_VALUE 0x4C
73 #define LM63_REG_PWM_FREQ 0x4D
75 #define LM63_REG_LOCAL_TEMP 0x00
76 #define LM63_REG_LOCAL_HIGH 0x05
78 #define LM63_REG_REMOTE_TEMP_MSB 0x01
79 #define LM63_REG_REMOTE_TEMP_LSB 0x10
80 #define LM63_REG_REMOTE_OFFSET_MSB 0x11
81 #define LM63_REG_REMOTE_OFFSET_LSB 0x12
82 #define LM63_REG_REMOTE_HIGH_MSB 0x07
83 #define LM63_REG_REMOTE_HIGH_LSB 0x13
84 #define LM63_REG_REMOTE_LOW_MSB 0x08
85 #define LM63_REG_REMOTE_LOW_LSB 0x14
86 #define LM63_REG_REMOTE_TCRIT 0x19
87 #define LM63_REG_REMOTE_TCRIT_HYST 0x21
89 #define LM63_REG_ALERT_STATUS 0x02
90 #define LM63_REG_ALERT_MASK 0x16
92 #define LM63_REG_MAN_ID 0xFE
93 #define LM63_REG_CHIP_ID 0xFF
95 #define LM96163_REG_CONFIG_ENHANCED 0x45
98 * Conversions and various macros
99 * For tachometer counts, the LM63 uses 16-bit values.
100 * For local temperature and high limit, remote critical limit and hysteresis
101 * value, it uses signed 8-bit values with LSB = 1 degree Celsius.
102 * For remote temperature, low and high limits, it uses signed 11-bit values
103 * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
104 * For LM64 the actual remote diode temperature is 16 degree Celsius higher
105 * than the register reading. Remote temperature setpoints have to be
106 * adapted accordingly.
109 #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \
111 #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \
112 (5400000 / (val)) & 0xFFFC)
113 #define TEMP8_FROM_REG(reg) ((reg) * 1000)
114 #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \
115 (val) >= 127000 ? 127 : \
116 (val) < 0 ? ((val) - 500) / 1000 : \
117 ((val) + 500) / 1000)
118 #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
119 #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
120 (val) >= 127875 ? 0x7FE0 : \
121 (val) < 0 ? ((val) - 62) / 125 * 32 : \
122 ((val) + 62) / 125 * 32)
123 #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \
124 (val) >= 127000 ? 127 : \
125 ((val) + 500) / 1000)
128 * Functions declaration
131 static int lm63_probe(struct i2c_client
*client
,
132 const struct i2c_device_id
*id
);
133 static int lm63_remove(struct i2c_client
*client
);
135 static struct lm63_data
*lm63_update_device(struct device
*dev
);
137 static int lm63_detect(struct i2c_client
*client
, struct i2c_board_info
*info
);
138 static void lm63_init_client(struct i2c_client
*client
);
140 enum chips
{ lm63
, lm64
, lm96163
};
143 * Driver data (common to all clients)
146 static const struct i2c_device_id lm63_id
[] = {
149 { "lm96163", lm96163
},
152 MODULE_DEVICE_TABLE(i2c
, lm63_id
);
154 static struct i2c_driver lm63_driver
= {
155 .class = I2C_CLASS_HWMON
,
160 .remove
= lm63_remove
,
162 .detect
= lm63_detect
,
163 .address_list
= normal_i2c
,
167 * Client data (each client gets its own)
171 struct device
*hwmon_dev
;
172 struct mutex update_lock
;
173 char valid
; /* zero until following fields are valid */
174 unsigned long last_updated
; /* in jiffies */
178 /* registers values */
179 u8 config
, config_fan
;
180 u16 fan
[2]; /* 0: input
184 s8 temp8
[3]; /* 0: local input
186 2: remote critical limit */
187 s16 temp11
[4]; /* 0: remote input
197 * Sysfs callback functions and files
200 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
203 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
204 struct lm63_data
*data
= lm63_update_device(dev
);
205 return sprintf(buf
, "%d\n", FAN_FROM_REG(data
->fan
[attr
->index
]));
208 static ssize_t
set_fan(struct device
*dev
, struct device_attribute
*dummy
,
209 const char *buf
, size_t count
)
211 struct i2c_client
*client
= to_i2c_client(dev
);
212 struct lm63_data
*data
= i2c_get_clientdata(client
);
216 err
= kstrtoul(buf
, 10, &val
);
220 mutex_lock(&data
->update_lock
);
221 data
->fan
[1] = FAN_TO_REG(val
);
222 i2c_smbus_write_byte_data(client
, LM63_REG_TACH_LIMIT_LSB
,
223 data
->fan
[1] & 0xFF);
224 i2c_smbus_write_byte_data(client
, LM63_REG_TACH_LIMIT_MSB
,
226 mutex_unlock(&data
->update_lock
);
230 static ssize_t
show_pwm1(struct device
*dev
, struct device_attribute
*dummy
,
233 struct lm63_data
*data
= lm63_update_device(dev
);
236 if (data
->pwm_highres
)
237 pwm
= data
->pwm1_value
;
239 pwm
= data
->pwm1_value
>= 2 * data
->pwm1_freq
?
240 255 : (data
->pwm1_value
* 255 + data
->pwm1_freq
) /
241 (2 * data
->pwm1_freq
);
243 return sprintf(buf
, "%d\n", pwm
);
246 static ssize_t
set_pwm1(struct device
*dev
, struct device_attribute
*dummy
,
247 const char *buf
, size_t count
)
249 struct i2c_client
*client
= to_i2c_client(dev
);
250 struct lm63_data
*data
= i2c_get_clientdata(client
);
254 if (!(data
->config_fan
& 0x20)) /* register is read-only */
257 err
= kstrtoul(buf
, 10, &val
);
261 val
= SENSORS_LIMIT(val
, 0, 255);
262 mutex_lock(&data
->update_lock
);
263 data
->pwm1_value
= data
->pwm_highres
? val
:
264 (val
* data
->pwm1_freq
* 2 + 127) / 255;
265 i2c_smbus_write_byte_data(client
, LM63_REG_PWM_VALUE
, data
->pwm1_value
);
266 mutex_unlock(&data
->update_lock
);
270 static ssize_t
show_pwm1_enable(struct device
*dev
,
271 struct device_attribute
*dummy
, char *buf
)
273 struct lm63_data
*data
= lm63_update_device(dev
);
274 return sprintf(buf
, "%d\n", data
->config_fan
& 0x20 ? 1 : 2);
278 * There are 8bit registers for both local(temp1) and remote(temp2) sensor.
279 * For remote sensor registers temp2_offset has to be considered,
280 * for local sensor it must not.
281 * So we need separate 8bit accessors for local and remote sensor.
283 static ssize_t
show_local_temp8(struct device
*dev
,
284 struct device_attribute
*devattr
,
287 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
288 struct lm63_data
*data
= lm63_update_device(dev
);
289 return sprintf(buf
, "%d\n", TEMP8_FROM_REG(data
->temp8
[attr
->index
]));
292 static ssize_t
show_remote_temp8(struct device
*dev
,
293 struct device_attribute
*devattr
,
296 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
297 struct lm63_data
*data
= lm63_update_device(dev
);
298 return sprintf(buf
, "%d\n", TEMP8_FROM_REG(data
->temp8
[attr
->index
])
299 + data
->temp2_offset
);
302 static ssize_t
set_local_temp8(struct device
*dev
,
303 struct device_attribute
*dummy
,
304 const char *buf
, size_t count
)
306 struct i2c_client
*client
= to_i2c_client(dev
);
307 struct lm63_data
*data
= i2c_get_clientdata(client
);
311 err
= kstrtol(buf
, 10, &val
);
315 mutex_lock(&data
->update_lock
);
316 data
->temp8
[1] = TEMP8_TO_REG(val
);
317 i2c_smbus_write_byte_data(client
, LM63_REG_LOCAL_HIGH
, data
->temp8
[1]);
318 mutex_unlock(&data
->update_lock
);
322 static ssize_t
show_temp11(struct device
*dev
, struct device_attribute
*devattr
,
325 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
326 struct lm63_data
*data
= lm63_update_device(dev
);
327 return sprintf(buf
, "%d\n", TEMP11_FROM_REG(data
->temp11
[attr
->index
])
328 + data
->temp2_offset
);
331 static ssize_t
set_temp11(struct device
*dev
, struct device_attribute
*devattr
,
332 const char *buf
, size_t count
)
334 static const u8 reg
[6] = {
335 LM63_REG_REMOTE_LOW_MSB
,
336 LM63_REG_REMOTE_LOW_LSB
,
337 LM63_REG_REMOTE_HIGH_MSB
,
338 LM63_REG_REMOTE_HIGH_LSB
,
339 LM63_REG_REMOTE_OFFSET_MSB
,
340 LM63_REG_REMOTE_OFFSET_LSB
,
343 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
344 struct i2c_client
*client
= to_i2c_client(dev
);
345 struct lm63_data
*data
= i2c_get_clientdata(client
);
348 int nr
= attr
->index
;
350 err
= kstrtol(buf
, 10, &val
);
354 mutex_lock(&data
->update_lock
);
355 data
->temp11
[nr
] = TEMP11_TO_REG(val
- data
->temp2_offset
);
356 i2c_smbus_write_byte_data(client
, reg
[(nr
- 1) * 2],
357 data
->temp11
[nr
] >> 8);
358 i2c_smbus_write_byte_data(client
, reg
[(nr
- 1) * 2 + 1],
359 data
->temp11
[nr
] & 0xff);
360 mutex_unlock(&data
->update_lock
);
365 * Hysteresis register holds a relative value, while we want to present
366 * an absolute to user-space
368 static ssize_t
show_temp2_crit_hyst(struct device
*dev
,
369 struct device_attribute
*dummy
, char *buf
)
371 struct lm63_data
*data
= lm63_update_device(dev
);
372 return sprintf(buf
, "%d\n", TEMP8_FROM_REG(data
->temp8
[2])
374 - TEMP8_FROM_REG(data
->temp2_crit_hyst
));
378 * And now the other way around, user-space provides an absolute
379 * hysteresis value and we have to store a relative one
381 static ssize_t
set_temp2_crit_hyst(struct device
*dev
,
382 struct device_attribute
*dummy
,
383 const char *buf
, size_t count
)
385 struct i2c_client
*client
= to_i2c_client(dev
);
386 struct lm63_data
*data
= i2c_get_clientdata(client
);
391 err
= kstrtol(buf
, 10, &val
);
395 mutex_lock(&data
->update_lock
);
396 hyst
= TEMP8_FROM_REG(data
->temp8
[2]) + data
->temp2_offset
- val
;
397 i2c_smbus_write_byte_data(client
, LM63_REG_REMOTE_TCRIT_HYST
,
399 mutex_unlock(&data
->update_lock
);
403 static ssize_t
show_alarms(struct device
*dev
, struct device_attribute
*dummy
,
406 struct lm63_data
*data
= lm63_update_device(dev
);
407 return sprintf(buf
, "%u\n", data
->alarms
);
410 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
*devattr
,
413 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
414 struct lm63_data
*data
= lm63_update_device(dev
);
415 int bitnr
= attr
->index
;
417 return sprintf(buf
, "%u\n", (data
->alarms
>> bitnr
) & 1);
420 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
421 static SENSOR_DEVICE_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan
,
424 static DEVICE_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm1
, set_pwm1
);
425 static DEVICE_ATTR(pwm1_enable
, S_IRUGO
, show_pwm1_enable
, NULL
);
427 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_local_temp8
, NULL
, 0);
428 static SENSOR_DEVICE_ATTR(temp1_max
, S_IWUSR
| S_IRUGO
, show_local_temp8
,
431 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp11
, NULL
, 0);
432 static SENSOR_DEVICE_ATTR(temp2_min
, S_IWUSR
| S_IRUGO
, show_temp11
,
434 static SENSOR_DEVICE_ATTR(temp2_max
, S_IWUSR
| S_IRUGO
, show_temp11
,
436 static SENSOR_DEVICE_ATTR(temp2_offset
, S_IWUSR
| S_IRUGO
, show_temp11
,
439 * On LM63, temp2_crit can be set only once, which should be job
442 static SENSOR_DEVICE_ATTR(temp2_crit
, S_IRUGO
, show_remote_temp8
,
444 static DEVICE_ATTR(temp2_crit_hyst
, S_IWUSR
| S_IRUGO
, show_temp2_crit_hyst
,
445 set_temp2_crit_hyst
);
447 /* Individual alarm files */
448 static SENSOR_DEVICE_ATTR(fan1_min_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
449 static SENSOR_DEVICE_ATTR(temp2_crit_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
450 static SENSOR_DEVICE_ATTR(temp2_fault
, S_IRUGO
, show_alarm
, NULL
, 2);
451 static SENSOR_DEVICE_ATTR(temp2_min_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
452 static SENSOR_DEVICE_ATTR(temp2_max_alarm
, S_IRUGO
, show_alarm
, NULL
, 4);
453 static SENSOR_DEVICE_ATTR(temp1_max_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
454 /* Raw alarm file for compatibility */
455 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
457 static struct attribute
*lm63_attributes
[] = {
459 &dev_attr_pwm1_enable
.attr
,
460 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
461 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
462 &sensor_dev_attr_temp2_min
.dev_attr
.attr
,
463 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
464 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
465 &sensor_dev_attr_temp2_offset
.dev_attr
.attr
,
466 &sensor_dev_attr_temp2_crit
.dev_attr
.attr
,
467 &dev_attr_temp2_crit_hyst
.attr
,
469 &sensor_dev_attr_temp2_crit_alarm
.dev_attr
.attr
,
470 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
471 &sensor_dev_attr_temp2_min_alarm
.dev_attr
.attr
,
472 &sensor_dev_attr_temp2_max_alarm
.dev_attr
.attr
,
473 &sensor_dev_attr_temp1_max_alarm
.dev_attr
.attr
,
474 &dev_attr_alarms
.attr
,
478 static const struct attribute_group lm63_group
= {
479 .attrs
= lm63_attributes
,
482 static struct attribute
*lm63_attributes_fan1
[] = {
483 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
484 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
486 &sensor_dev_attr_fan1_min_alarm
.dev_attr
.attr
,
490 static const struct attribute_group lm63_group_fan1
= {
491 .attrs
= lm63_attributes_fan1
,
498 /* Return 0 if detection is successful, -ENODEV otherwise */
499 static int lm63_detect(struct i2c_client
*new_client
,
500 struct i2c_board_info
*info
)
502 struct i2c_adapter
*adapter
= new_client
->adapter
;
503 u8 man_id
, chip_id
, reg_config1
, reg_config2
;
504 u8 reg_alert_status
, reg_alert_mask
;
505 int address
= new_client
->addr
;
507 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
510 man_id
= i2c_smbus_read_byte_data(new_client
, LM63_REG_MAN_ID
);
511 chip_id
= i2c_smbus_read_byte_data(new_client
, LM63_REG_CHIP_ID
);
513 reg_config1
= i2c_smbus_read_byte_data(new_client
,
515 reg_config2
= i2c_smbus_read_byte_data(new_client
,
517 reg_alert_status
= i2c_smbus_read_byte_data(new_client
,
518 LM63_REG_ALERT_STATUS
);
519 reg_alert_mask
= i2c_smbus_read_byte_data(new_client
,
520 LM63_REG_ALERT_MASK
);
522 if (man_id
!= 0x01 /* National Semiconductor */
523 || (reg_config1
& 0x18) != 0x00
524 || (reg_config2
& 0xF8) != 0x00
525 || (reg_alert_status
& 0x20) != 0x00
526 || (reg_alert_mask
& 0xA4) != 0xA4) {
527 dev_dbg(&adapter
->dev
,
528 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
533 if (chip_id
== 0x41 && address
== 0x4c)
534 strlcpy(info
->type
, "lm63", I2C_NAME_SIZE
);
535 else if (chip_id
== 0x51 && (address
== 0x18 || address
== 0x4e))
536 strlcpy(info
->type
, "lm64", I2C_NAME_SIZE
);
537 else if (chip_id
== 0x49 && address
== 0x4c)
538 strlcpy(info
->type
, "lm96163", I2C_NAME_SIZE
);
545 static int lm63_probe(struct i2c_client
*new_client
,
546 const struct i2c_device_id
*id
)
548 struct lm63_data
*data
;
551 data
= kzalloc(sizeof(struct lm63_data
), GFP_KERNEL
);
557 i2c_set_clientdata(new_client
, data
);
559 mutex_init(&data
->update_lock
);
561 /* Set the device type */
562 data
->kind
= id
->driver_data
;
563 if (data
->kind
== lm64
)
564 data
->temp2_offset
= 16000;
566 /* Initialize chip */
567 lm63_init_client(new_client
);
569 /* Register sysfs hooks */
570 err
= sysfs_create_group(&new_client
->dev
.kobj
, &lm63_group
);
573 if (data
->config
& 0x04) { /* tachometer enabled */
574 err
= sysfs_create_group(&new_client
->dev
.kobj
,
577 goto exit_remove_files
;
580 data
->hwmon_dev
= hwmon_device_register(&new_client
->dev
);
581 if (IS_ERR(data
->hwmon_dev
)) {
582 err
= PTR_ERR(data
->hwmon_dev
);
583 goto exit_remove_files
;
589 sysfs_remove_group(&new_client
->dev
.kobj
, &lm63_group
);
590 sysfs_remove_group(&new_client
->dev
.kobj
, &lm63_group_fan1
);
598 * Ideally we shouldn't have to initialize anything, since the BIOS
599 * should have taken care of everything
601 static void lm63_init_client(struct i2c_client
*client
)
603 struct lm63_data
*data
= i2c_get_clientdata(client
);
605 data
->config
= i2c_smbus_read_byte_data(client
, LM63_REG_CONFIG1
);
606 data
->config_fan
= i2c_smbus_read_byte_data(client
,
607 LM63_REG_CONFIG_FAN
);
609 /* Start converting if needed */
610 if (data
->config
& 0x40) { /* standby */
611 dev_dbg(&client
->dev
, "Switching to operational mode\n");
612 data
->config
&= 0xA7;
613 i2c_smbus_write_byte_data(client
, LM63_REG_CONFIG1
,
617 /* We may need pwm1_freq before ever updating the client data */
618 data
->pwm1_freq
= i2c_smbus_read_byte_data(client
, LM63_REG_PWM_FREQ
);
619 if (data
->pwm1_freq
== 0)
623 * For LM96163, check if high resolution PWM is enabled.
624 * Also, check if unsigned temperature format is enabled
625 * and display a warning message if it is.
627 if (data
->kind
== lm96163
) {
629 = i2c_smbus_read_byte_data(client
,
630 LM96163_REG_CONFIG_ENHANCED
);
631 if ((config_enhanced
& 0x10)
632 && !(data
->config_fan
& 0x08) && data
->pwm1_freq
== 8)
633 data
->pwm_highres
= true;
634 if (config_enhanced
& 0x08)
635 dev_warn(&client
->dev
,
636 "Unsigned format for High and Crit setpoints enabled but not supported by driver\n");
639 /* Show some debug info about the LM63 configuration */
640 dev_dbg(&client
->dev
, "Alert/tach pin configured for %s\n",
641 (data
->config
& 0x04) ? "tachometer input" :
643 dev_dbg(&client
->dev
, "PWM clock %s kHz, output frequency %u Hz\n",
644 (data
->config_fan
& 0x08) ? "1.4" : "360",
645 ((data
->config_fan
& 0x08) ? 700 : 180000) / data
->pwm1_freq
);
646 dev_dbg(&client
->dev
, "PWM output active %s, %s mode\n",
647 (data
->config_fan
& 0x10) ? "low" : "high",
648 (data
->config_fan
& 0x20) ? "manual" : "auto");
651 static int lm63_remove(struct i2c_client
*client
)
653 struct lm63_data
*data
= i2c_get_clientdata(client
);
655 hwmon_device_unregister(data
->hwmon_dev
);
656 sysfs_remove_group(&client
->dev
.kobj
, &lm63_group
);
657 sysfs_remove_group(&client
->dev
.kobj
, &lm63_group_fan1
);
663 static struct lm63_data
*lm63_update_device(struct device
*dev
)
665 struct i2c_client
*client
= to_i2c_client(dev
);
666 struct lm63_data
*data
= i2c_get_clientdata(client
);
668 mutex_lock(&data
->update_lock
);
670 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
671 if (data
->config
& 0x04) { /* tachometer enabled */
672 /* order matters for fan1_input */
673 data
->fan
[0] = i2c_smbus_read_byte_data(client
,
674 LM63_REG_TACH_COUNT_LSB
) & 0xFC;
675 data
->fan
[0] |= i2c_smbus_read_byte_data(client
,
676 LM63_REG_TACH_COUNT_MSB
) << 8;
677 data
->fan
[1] = (i2c_smbus_read_byte_data(client
,
678 LM63_REG_TACH_LIMIT_LSB
) & 0xFC)
679 | (i2c_smbus_read_byte_data(client
,
680 LM63_REG_TACH_LIMIT_MSB
) << 8);
683 data
->pwm1_freq
= i2c_smbus_read_byte_data(client
,
685 if (data
->pwm1_freq
== 0)
687 data
->pwm1_value
= i2c_smbus_read_byte_data(client
,
690 data
->temp8
[0] = i2c_smbus_read_byte_data(client
,
691 LM63_REG_LOCAL_TEMP
);
692 data
->temp8
[1] = i2c_smbus_read_byte_data(client
,
693 LM63_REG_LOCAL_HIGH
);
695 /* order matters for temp2_input */
696 data
->temp11
[0] = i2c_smbus_read_byte_data(client
,
697 LM63_REG_REMOTE_TEMP_MSB
) << 8;
698 data
->temp11
[0] |= i2c_smbus_read_byte_data(client
,
699 LM63_REG_REMOTE_TEMP_LSB
);
700 data
->temp11
[1] = (i2c_smbus_read_byte_data(client
,
701 LM63_REG_REMOTE_LOW_MSB
) << 8)
702 | i2c_smbus_read_byte_data(client
,
703 LM63_REG_REMOTE_LOW_LSB
);
704 data
->temp11
[2] = (i2c_smbus_read_byte_data(client
,
705 LM63_REG_REMOTE_HIGH_MSB
) << 8)
706 | i2c_smbus_read_byte_data(client
,
707 LM63_REG_REMOTE_HIGH_LSB
);
708 data
->temp11
[3] = (i2c_smbus_read_byte_data(client
,
709 LM63_REG_REMOTE_OFFSET_MSB
) << 8)
710 | i2c_smbus_read_byte_data(client
,
711 LM63_REG_REMOTE_OFFSET_LSB
);
712 data
->temp8
[2] = i2c_smbus_read_byte_data(client
,
713 LM63_REG_REMOTE_TCRIT
);
714 data
->temp2_crit_hyst
= i2c_smbus_read_byte_data(client
,
715 LM63_REG_REMOTE_TCRIT_HYST
);
717 data
->alarms
= i2c_smbus_read_byte_data(client
,
718 LM63_REG_ALERT_STATUS
) & 0x7F;
720 data
->last_updated
= jiffies
;
724 mutex_unlock(&data
->update_lock
);
729 static int __init
sensors_lm63_init(void)
731 return i2c_add_driver(&lm63_driver
);
734 static void __exit
sensors_lm63_exit(void)
736 i2c_del_driver(&lm63_driver
);
739 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
740 MODULE_DESCRIPTION("LM63 driver");
741 MODULE_LICENSE("GPL");
743 module_init(sensors_lm63_init
);
744 module_exit(sensors_lm63_exit
);