Commit 04738b2b2f37c13bbe37b7695fec6c1c60d79c7a

Authored by Guenter Roeck
Committed by Jean Delvare
1 parent 94e55df48a

hwmon: (lm63) Add support for update_interval sysfs attribute

The update interval is configurable on LM63 and compatibles. Add
support for it.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>

Showing 2 changed files with 93 additions and 5 deletions Inline Diff

Documentation/hwmon/lm63
1 Kernel driver lm63 1 Kernel driver lm63
2 ================== 2 ==================
3 3
4 Supported chips: 4 Supported chips:
5 * National Semiconductor LM63 5 * National Semiconductor LM63
6 Prefix: 'lm63' 6 Prefix: 'lm63'
7 Addresses scanned: I2C 0x4c 7 Addresses scanned: I2C 0x4c
8 Datasheet: Publicly available at the National Semiconductor website 8 Datasheet: Publicly available at the National Semiconductor website
9 http://www.national.com/pf/LM/LM63.html 9 http://www.national.com/pf/LM/LM63.html
10 * National Semiconductor LM64 10 * National Semiconductor LM64
11 Prefix: 'lm64' 11 Prefix: 'lm64'
12 Addresses scanned: I2C 0x18 and 0x4e 12 Addresses scanned: I2C 0x18 and 0x4e
13 Datasheet: Publicly available at the National Semiconductor website 13 Datasheet: Publicly available at the National Semiconductor website
14 http://www.national.com/pf/LM/LM64.html 14 http://www.national.com/pf/LM/LM64.html
15 * National Semiconductor LM96163 15 * National Semiconductor LM96163
16 Prefix: 'lm96163' 16 Prefix: 'lm96163'
17 Addresses scanned: I2C 0x4c 17 Addresses scanned: I2C 0x4c
18 Datasheet: Publicly available at the National Semiconductor website 18 Datasheet: Publicly available at the National Semiconductor website
19 http://www.national.com/pf/LM/LM96163.html 19 http://www.national.com/pf/LM/LM96163.html
20 20
21 Author: Jean Delvare <khali@linux-fr.org> 21 Author: Jean Delvare <khali@linux-fr.org>
22 22
23 Thanks go to Tyan and especially Alex Buckingham for setting up a remote 23 Thanks go to Tyan and especially Alex Buckingham for setting up a remote
24 access to their S4882 test platform for this driver. 24 access to their S4882 test platform for this driver.
25 http://www.tyan.com/ 25 http://www.tyan.com/
26 26
27 Description 27 Description
28 ----------- 28 -----------
29 29
30 The LM63 is a digital temperature sensor with integrated fan monitoring 30 The LM63 is a digital temperature sensor with integrated fan monitoring
31 and control. 31 and control.
32 32
33 The LM63 is basically an LM86 with fan speed monitoring and control 33 The LM63 is basically an LM86 with fan speed monitoring and control
34 capabilities added. It misses some of the LM86 features though: 34 capabilities added. It misses some of the LM86 features though:
35 - No low limit for local temperature. 35 - No low limit for local temperature.
36 - No critical limit for local temperature. 36 - No critical limit for local temperature.
37 - Critical limit for remote temperature can be changed only once. We 37 - Critical limit for remote temperature can be changed only once. We
38 will consider that the critical limit is read-only. 38 will consider that the critical limit is read-only.
39 39
40 The datasheet isn't very clear about what the tachometer reading is. 40 The datasheet isn't very clear about what the tachometer reading is.
41 41
42 An explanation from National Semiconductor: The two lower bits of the read 42 An explanation from National Semiconductor: The two lower bits of the read
43 value have to be masked out. The value is still 16 bit in width. 43 value have to be masked out. The value is still 16 bit in width.
44 44
45 All temperature values are given in degrees Celsius. Resolution is 1.0 45 All temperature values are given in degrees Celsius. Resolution is 1.0
46 degree for the local temperature, 0.125 degree for the remote temperature. 46 degree for the local temperature, 0.125 degree for the remote temperature.
47 47
48 The fan speed is measured using a tachometer. Contrary to most chips which 48 The fan speed is measured using a tachometer. Contrary to most chips which
49 store the value in an 8-bit register and have a selectable clock divider 49 store the value in an 8-bit register and have a selectable clock divider
50 to make sure that the result will fit in the register, the LM63 uses 16-bit 50 to make sure that the result will fit in the register, the LM63 uses 16-bit
51 value for measuring the speed of the fan. It can measure fan speeds down to 51 value for measuring the speed of the fan. It can measure fan speeds down to
52 83 RPM, at least in theory. 52 83 RPM, at least in theory.
53 53
54 Note that the pin used for fan monitoring is shared with an alert out 54 Note that the pin used for fan monitoring is shared with an alert out
55 function. Depending on how the board designer wanted to use the chip, fan 55 function. Depending on how the board designer wanted to use the chip, fan
56 speed monitoring will or will not be possible. The proper chip configuration 56 speed monitoring will or will not be possible. The proper chip configuration
57 is left to the BIOS, and the driver will blindly trust it. 57 is left to the BIOS, and the driver will blindly trust it.
58 58
59 A PWM output can be used to control the speed of the fan. The LM63 has two 59 A PWM output can be used to control the speed of the fan. The LM63 has two
60 PWM modes: manual and automatic. Automatic mode is not fully implemented yet 60 PWM modes: manual and automatic. Automatic mode is not fully implemented yet
61 (you cannot define your custom PWM/temperature curve), and mode change isn't 61 (you cannot define your custom PWM/temperature curve), and mode change isn't
62 supported either. 62 supported either.
63 63
64 The lm63 driver will not update its values more frequently than every 64 The lm63 driver will not update its values more frequently than configured with
65 second; reading them more often will do no harm, but will return 'old' 65 the update_interval sysfs attribute; reading them more often will do no harm,
66 values. 66 but will return 'old' values.
67 67
68 The LM64 is effectively an LM63 with GPIO lines. The driver does not 68 The LM64 is effectively an LM63 with GPIO lines. The driver does not
69 support these GPIO lines at present. 69 support these GPIO lines at present.
70 70
71 The LM96163 is an enhanced version of LM63 with improved temperature accuracy 71 The LM96163 is an enhanced version of LM63 with improved temperature accuracy
72 and better PWM resolution. 72 and better PWM resolution.
73 73
drivers/hwmon/lm63.c
1 /* 1 /*
2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor 2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 * with integrated fan control 3 * with integrated fan control
4 * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2004-2008 Jean Delvare <khali@linux-fr.org>
5 * Based on the lm90 driver. 5 * Based on the lm90 driver.
6 * 6 *
7 * The LM63 is a sensor chip made by National Semiconductor. It measures 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 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 9 * fan, those speed it can additionally control. Complete datasheet can be
10 * obtained from National's website at: 10 * obtained from National's website at:
11 * http://www.national.com/pf/LM/LM63.html 11 * http://www.national.com/pf/LM/LM63.html
12 * 12 *
13 * The LM63 is basically an LM86 with fan speed monitoring and control 13 * The LM63 is basically an LM86 with fan speed monitoring and control
14 * capabilities added. It misses some of the LM86 features though: 14 * capabilities added. It misses some of the LM86 features though:
15 * - No low limit for local temperature. 15 * - No low limit for local temperature.
16 * - No critical limit for local temperature. 16 * - No critical limit for local temperature.
17 * - Critical limit for remote temperature can be changed only once. We 17 * - Critical limit for remote temperature can be changed only once. We
18 * will consider that the critical limit is read-only. 18 * will consider that the critical limit is read-only.
19 * 19 *
20 * The datasheet isn't very clear about what the tachometer reading is. 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 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 22 * bits of the read value have to be masked out. The value is still 16 bit
23 * in width. 23 * in width.
24 * 24 *
25 * This program is free software; you can redistribute it and/or modify 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 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 27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version. 28 * (at your option) any later version.
29 * 29 *
30 * This program is distributed in the hope that it will be useful, 30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details. 33 * GNU General Public License for more details.
34 * 34 *
35 * You should have received a copy of the GNU General Public License 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 36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 */ 38 */
39 39
40 #include <linux/module.h> 40 #include <linux/module.h>
41 #include <linux/init.h> 41 #include <linux/init.h>
42 #include <linux/slab.h> 42 #include <linux/slab.h>
43 #include <linux/jiffies.h> 43 #include <linux/jiffies.h>
44 #include <linux/i2c.h> 44 #include <linux/i2c.h>
45 #include <linux/hwmon-sysfs.h> 45 #include <linux/hwmon-sysfs.h>
46 #include <linux/hwmon.h> 46 #include <linux/hwmon.h>
47 #include <linux/err.h> 47 #include <linux/err.h>
48 #include <linux/mutex.h> 48 #include <linux/mutex.h>
49 #include <linux/sysfs.h> 49 #include <linux/sysfs.h>
50 #include <linux/types.h> 50 #include <linux/types.h>
51 51
52 /* 52 /*
53 * Addresses to scan 53 * Addresses to scan
54 * Address is fully defined internally and cannot be changed. 54 * Address is fully defined internally and cannot be changed.
55 */ 55 */
56 56
57 static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END }; 57 static const unsigned short normal_i2c[] = { 0x18, 0x4c, 0x4e, I2C_CLIENT_END };
58 58
59 /* 59 /*
60 * The LM63 registers 60 * The LM63 registers
61 */ 61 */
62 62
63 #define LM63_REG_CONFIG1 0x03 63 #define LM63_REG_CONFIG1 0x03
64 #define LM63_REG_CONVRATE 0x04
64 #define LM63_REG_CONFIG2 0xBF 65 #define LM63_REG_CONFIG2 0xBF
65 #define LM63_REG_CONFIG_FAN 0x4A 66 #define LM63_REG_CONFIG_FAN 0x4A
66 67
67 #define LM63_REG_TACH_COUNT_MSB 0x47 68 #define LM63_REG_TACH_COUNT_MSB 0x47
68 #define LM63_REG_TACH_COUNT_LSB 0x46 69 #define LM63_REG_TACH_COUNT_LSB 0x46
69 #define LM63_REG_TACH_LIMIT_MSB 0x49 70 #define LM63_REG_TACH_LIMIT_MSB 0x49
70 #define LM63_REG_TACH_LIMIT_LSB 0x48 71 #define LM63_REG_TACH_LIMIT_LSB 0x48
71 72
72 #define LM63_REG_PWM_VALUE 0x4C 73 #define LM63_REG_PWM_VALUE 0x4C
73 #define LM63_REG_PWM_FREQ 0x4D 74 #define LM63_REG_PWM_FREQ 0x4D
74 75
75 #define LM63_REG_LOCAL_TEMP 0x00 76 #define LM63_REG_LOCAL_TEMP 0x00
76 #define LM63_REG_LOCAL_HIGH 0x05 77 #define LM63_REG_LOCAL_HIGH 0x05
77 78
78 #define LM63_REG_REMOTE_TEMP_MSB 0x01 79 #define LM63_REG_REMOTE_TEMP_MSB 0x01
79 #define LM63_REG_REMOTE_TEMP_LSB 0x10 80 #define LM63_REG_REMOTE_TEMP_LSB 0x10
80 #define LM63_REG_REMOTE_OFFSET_MSB 0x11 81 #define LM63_REG_REMOTE_OFFSET_MSB 0x11
81 #define LM63_REG_REMOTE_OFFSET_LSB 0x12 82 #define LM63_REG_REMOTE_OFFSET_LSB 0x12
82 #define LM63_REG_REMOTE_HIGH_MSB 0x07 83 #define LM63_REG_REMOTE_HIGH_MSB 0x07
83 #define LM63_REG_REMOTE_HIGH_LSB 0x13 84 #define LM63_REG_REMOTE_HIGH_LSB 0x13
84 #define LM63_REG_REMOTE_LOW_MSB 0x08 85 #define LM63_REG_REMOTE_LOW_MSB 0x08
85 #define LM63_REG_REMOTE_LOW_LSB 0x14 86 #define LM63_REG_REMOTE_LOW_LSB 0x14
86 #define LM63_REG_REMOTE_TCRIT 0x19 87 #define LM63_REG_REMOTE_TCRIT 0x19
87 #define LM63_REG_REMOTE_TCRIT_HYST 0x21 88 #define LM63_REG_REMOTE_TCRIT_HYST 0x21
88 89
89 #define LM63_REG_ALERT_STATUS 0x02 90 #define LM63_REG_ALERT_STATUS 0x02
90 #define LM63_REG_ALERT_MASK 0x16 91 #define LM63_REG_ALERT_MASK 0x16
91 92
92 #define LM63_REG_MAN_ID 0xFE 93 #define LM63_REG_MAN_ID 0xFE
93 #define LM63_REG_CHIP_ID 0xFF 94 #define LM63_REG_CHIP_ID 0xFF
94 95
95 #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31 96 #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31
96 #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32 97 #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32
97 #define LM96163_REG_CONFIG_ENHANCED 0x45 98 #define LM96163_REG_CONFIG_ENHANCED 0x45
98 99
100 #define LM63_MAX_CONVRATE 9
101
102 #define LM63_MAX_CONVRATE_HZ 32
103 #define LM96163_MAX_CONVRATE_HZ 26
104
99 /* 105 /*
100 * Conversions and various macros 106 * Conversions and various macros
101 * For tachometer counts, the LM63 uses 16-bit values. 107 * For tachometer counts, the LM63 uses 16-bit values.
102 * For local temperature and high limit, remote critical limit and hysteresis 108 * For local temperature and high limit, remote critical limit and hysteresis
103 * value, it uses signed 8-bit values with LSB = 1 degree Celsius. 109 * value, it uses signed 8-bit values with LSB = 1 degree Celsius.
104 * For remote temperature, low and high limits, it uses signed 11-bit values 110 * For remote temperature, low and high limits, it uses signed 11-bit values
105 * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers. 111 * with LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
106 * For LM64 the actual remote diode temperature is 16 degree Celsius higher 112 * For LM64 the actual remote diode temperature is 16 degree Celsius higher
107 * than the register reading. Remote temperature setpoints have to be 113 * than the register reading. Remote temperature setpoints have to be
108 * adapted accordingly. 114 * adapted accordingly.
109 */ 115 */
110 116
111 #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ 117 #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \
112 5400000 / (reg)) 118 5400000 / (reg))
113 #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ 119 #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \
114 (5400000 / (val)) & 0xFFFC) 120 (5400000 / (val)) & 0xFFFC)
115 #define TEMP8_FROM_REG(reg) ((reg) * 1000) 121 #define TEMP8_FROM_REG(reg) ((reg) * 1000)
116 #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ 122 #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \
117 (val) >= 127000 ? 127 : \ 123 (val) >= 127000 ? 127 : \
118 (val) < 0 ? ((val) - 500) / 1000 : \ 124 (val) < 0 ? ((val) - 500) / 1000 : \
119 ((val) + 500) / 1000) 125 ((val) + 500) / 1000)
120 #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \ 126 #define TEMP8U_TO_REG(val) ((val) <= 0 ? 0 : \
121 (val) >= 255000 ? 255 : \ 127 (val) >= 255000 ? 255 : \
122 ((val) + 500) / 1000) 128 ((val) + 500) / 1000)
123 #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) 129 #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
124 #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ 130 #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
125 (val) >= 127875 ? 0x7FE0 : \ 131 (val) >= 127875 ? 0x7FE0 : \
126 (val) < 0 ? ((val) - 62) / 125 * 32 : \ 132 (val) < 0 ? ((val) - 62) / 125 * 32 : \
127 ((val) + 62) / 125 * 32) 133 ((val) + 62) / 125 * 32)
128 #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ 134 #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \
129 (val) >= 255875 ? 0xFFE0 : \ 135 (val) >= 255875 ? 0xFFE0 : \
130 ((val) + 62) / 125 * 32) 136 ((val) + 62) / 125 * 32)
131 #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ 137 #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \
132 (val) >= 127000 ? 127 : \ 138 (val) >= 127000 ? 127 : \
133 ((val) + 500) / 1000) 139 ((val) + 500) / 1000)
134 140
141 #define UPDATE_INTERVAL(max, rate) \
142 ((1000 << (LM63_MAX_CONVRATE - (rate))) / (max))
143
135 /* 144 /*
136 * Functions declaration 145 * Functions declaration
137 */ 146 */
138 147
139 static int lm63_probe(struct i2c_client *client, 148 static int lm63_probe(struct i2c_client *client,
140 const struct i2c_device_id *id); 149 const struct i2c_device_id *id);
141 static int lm63_remove(struct i2c_client *client); 150 static int lm63_remove(struct i2c_client *client);
142 151
143 static struct lm63_data *lm63_update_device(struct device *dev); 152 static struct lm63_data *lm63_update_device(struct device *dev);
144 153
145 static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); 154 static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info);
146 static void lm63_init_client(struct i2c_client *client); 155 static void lm63_init_client(struct i2c_client *client);
147 156
148 enum chips { lm63, lm64, lm96163 }; 157 enum chips { lm63, lm64, lm96163 };
149 158
150 /* 159 /*
151 * Driver data (common to all clients) 160 * Driver data (common to all clients)
152 */ 161 */
153 162
154 static const struct i2c_device_id lm63_id[] = { 163 static const struct i2c_device_id lm63_id[] = {
155 { "lm63", lm63 }, 164 { "lm63", lm63 },
156 { "lm64", lm64 }, 165 { "lm64", lm64 },
157 { "lm96163", lm96163 }, 166 { "lm96163", lm96163 },
158 { } 167 { }
159 }; 168 };
160 MODULE_DEVICE_TABLE(i2c, lm63_id); 169 MODULE_DEVICE_TABLE(i2c, lm63_id);
161 170
162 static struct i2c_driver lm63_driver = { 171 static struct i2c_driver lm63_driver = {
163 .class = I2C_CLASS_HWMON, 172 .class = I2C_CLASS_HWMON,
164 .driver = { 173 .driver = {
165 .name = "lm63", 174 .name = "lm63",
166 }, 175 },
167 .probe = lm63_probe, 176 .probe = lm63_probe,
168 .remove = lm63_remove, 177 .remove = lm63_remove,
169 .id_table = lm63_id, 178 .id_table = lm63_id,
170 .detect = lm63_detect, 179 .detect = lm63_detect,
171 .address_list = normal_i2c, 180 .address_list = normal_i2c,
172 }; 181 };
173 182
174 /* 183 /*
175 * Client data (each client gets its own) 184 * Client data (each client gets its own)
176 */ 185 */
177 186
178 struct lm63_data { 187 struct lm63_data {
179 struct device *hwmon_dev; 188 struct device *hwmon_dev;
180 struct mutex update_lock; 189 struct mutex update_lock;
181 char valid; /* zero until following fields are valid */ 190 char valid; /* zero until following fields are valid */
182 unsigned long last_updated; /* in jiffies */ 191 unsigned long last_updated; /* in jiffies */
183 int kind; 192 enum chips kind;
184 int temp2_offset; 193 int temp2_offset;
185 194
195 int update_interval; /* in milliseconds */
196 int max_convrate_hz;
197
186 /* registers values */ 198 /* registers values */
187 u8 config, config_fan; 199 u8 config, config_fan;
188 u16 fan[2]; /* 0: input 200 u16 fan[2]; /* 0: input
189 1: low limit */ 201 1: low limit */
190 u8 pwm1_freq; 202 u8 pwm1_freq;
191 u8 pwm1_value; 203 u8 pwm1_value;
192 s8 temp8[3]; /* 0: local input 204 s8 temp8[3]; /* 0: local input
193 1: local high limit 205 1: local high limit
194 2: remote critical limit */ 206 2: remote critical limit */
195 s16 temp11[4]; /* 0: remote input 207 s16 temp11[4]; /* 0: remote input
196 1: remote low limit 208 1: remote low limit
197 2: remote high limit 209 2: remote high limit
198 3: remote offset */ 210 3: remote offset */
199 u16 temp11u; /* remote input (unsigned) */ 211 u16 temp11u; /* remote input (unsigned) */
200 u8 temp2_crit_hyst; 212 u8 temp2_crit_hyst;
201 u8 alarms; 213 u8 alarms;
202 bool pwm_highres; 214 bool pwm_highres;
203 bool remote_unsigned; /* true if unsigned remote upper limits */ 215 bool remote_unsigned; /* true if unsigned remote upper limits */
204 }; 216 };
205 217
206 static inline int temp8_from_reg(struct lm63_data *data, int nr) 218 static inline int temp8_from_reg(struct lm63_data *data, int nr)
207 { 219 {
208 if (data->remote_unsigned) 220 if (data->remote_unsigned)
209 return TEMP8_FROM_REG((u8)data->temp8[nr]); 221 return TEMP8_FROM_REG((u8)data->temp8[nr]);
210 return TEMP8_FROM_REG(data->temp8[nr]); 222 return TEMP8_FROM_REG(data->temp8[nr]);
211 } 223 }
212 224
213 /* 225 /*
214 * Sysfs callback functions and files 226 * Sysfs callback functions and files
215 */ 227 */
216 228
217 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, 229 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
218 char *buf) 230 char *buf)
219 { 231 {
220 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 232 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
221 struct lm63_data *data = lm63_update_device(dev); 233 struct lm63_data *data = lm63_update_device(dev);
222 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); 234 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index]));
223 } 235 }
224 236
225 static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, 237 static ssize_t set_fan(struct device *dev, struct device_attribute *dummy,
226 const char *buf, size_t count) 238 const char *buf, size_t count)
227 { 239 {
228 struct i2c_client *client = to_i2c_client(dev); 240 struct i2c_client *client = to_i2c_client(dev);
229 struct lm63_data *data = i2c_get_clientdata(client); 241 struct lm63_data *data = i2c_get_clientdata(client);
230 unsigned long val; 242 unsigned long val;
231 int err; 243 int err;
232 244
233 err = kstrtoul(buf, 10, &val); 245 err = kstrtoul(buf, 10, &val);
234 if (err) 246 if (err)
235 return err; 247 return err;
236 248
237 mutex_lock(&data->update_lock); 249 mutex_lock(&data->update_lock);
238 data->fan[1] = FAN_TO_REG(val); 250 data->fan[1] = FAN_TO_REG(val);
239 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, 251 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
240 data->fan[1] & 0xFF); 252 data->fan[1] & 0xFF);
241 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, 253 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
242 data->fan[1] >> 8); 254 data->fan[1] >> 8);
243 mutex_unlock(&data->update_lock); 255 mutex_unlock(&data->update_lock);
244 return count; 256 return count;
245 } 257 }
246 258
247 static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy, 259 static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy,
248 char *buf) 260 char *buf)
249 { 261 {
250 struct lm63_data *data = lm63_update_device(dev); 262 struct lm63_data *data = lm63_update_device(dev);
251 int pwm; 263 int pwm;
252 264
253 if (data->pwm_highres) 265 if (data->pwm_highres)
254 pwm = data->pwm1_value; 266 pwm = data->pwm1_value;
255 else 267 else
256 pwm = data->pwm1_value >= 2 * data->pwm1_freq ? 268 pwm = data->pwm1_value >= 2 * data->pwm1_freq ?
257 255 : (data->pwm1_value * 255 + data->pwm1_freq) / 269 255 : (data->pwm1_value * 255 + data->pwm1_freq) /
258 (2 * data->pwm1_freq); 270 (2 * data->pwm1_freq);
259 271
260 return sprintf(buf, "%d\n", pwm); 272 return sprintf(buf, "%d\n", pwm);
261 } 273 }
262 274
263 static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, 275 static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy,
264 const char *buf, size_t count) 276 const char *buf, size_t count)
265 { 277 {
266 struct i2c_client *client = to_i2c_client(dev); 278 struct i2c_client *client = to_i2c_client(dev);
267 struct lm63_data *data = i2c_get_clientdata(client); 279 struct lm63_data *data = i2c_get_clientdata(client);
268 unsigned long val; 280 unsigned long val;
269 int err; 281 int err;
270 282
271 if (!(data->config_fan & 0x20)) /* register is read-only */ 283 if (!(data->config_fan & 0x20)) /* register is read-only */
272 return -EPERM; 284 return -EPERM;
273 285
274 err = kstrtoul(buf, 10, &val); 286 err = kstrtoul(buf, 10, &val);
275 if (err) 287 if (err)
276 return err; 288 return err;
277 289
278 val = SENSORS_LIMIT(val, 0, 255); 290 val = SENSORS_LIMIT(val, 0, 255);
279 mutex_lock(&data->update_lock); 291 mutex_lock(&data->update_lock);
280 data->pwm1_value = data->pwm_highres ? val : 292 data->pwm1_value = data->pwm_highres ? val :
281 (val * data->pwm1_freq * 2 + 127) / 255; 293 (val * data->pwm1_freq * 2 + 127) / 255;
282 i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value); 294 i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value);
283 mutex_unlock(&data->update_lock); 295 mutex_unlock(&data->update_lock);
284 return count; 296 return count;
285 } 297 }
286 298
287 static ssize_t show_pwm1_enable(struct device *dev, 299 static ssize_t show_pwm1_enable(struct device *dev,
288 struct device_attribute *dummy, char *buf) 300 struct device_attribute *dummy, char *buf)
289 { 301 {
290 struct lm63_data *data = lm63_update_device(dev); 302 struct lm63_data *data = lm63_update_device(dev);
291 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); 303 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2);
292 } 304 }
293 305
294 /* 306 /*
295 * There are 8bit registers for both local(temp1) and remote(temp2) sensor. 307 * There are 8bit registers for both local(temp1) and remote(temp2) sensor.
296 * For remote sensor registers temp2_offset has to be considered, 308 * For remote sensor registers temp2_offset has to be considered,
297 * for local sensor it must not. 309 * for local sensor it must not.
298 * So we need separate 8bit accessors for local and remote sensor. 310 * So we need separate 8bit accessors for local and remote sensor.
299 */ 311 */
300 static ssize_t show_local_temp8(struct device *dev, 312 static ssize_t show_local_temp8(struct device *dev,
301 struct device_attribute *devattr, 313 struct device_attribute *devattr,
302 char *buf) 314 char *buf)
303 { 315 {
304 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 316 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
305 struct lm63_data *data = lm63_update_device(dev); 317 struct lm63_data *data = lm63_update_device(dev);
306 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); 318 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index]));
307 } 319 }
308 320
309 static ssize_t show_remote_temp8(struct device *dev, 321 static ssize_t show_remote_temp8(struct device *dev,
310 struct device_attribute *devattr, 322 struct device_attribute *devattr,
311 char *buf) 323 char *buf)
312 { 324 {
313 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 325 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
314 struct lm63_data *data = lm63_update_device(dev); 326 struct lm63_data *data = lm63_update_device(dev);
315 return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index) 327 return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index)
316 + data->temp2_offset); 328 + data->temp2_offset);
317 } 329 }
318 330
319 static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, 331 static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
320 const char *buf, size_t count) 332 const char *buf, size_t count)
321 { 333 {
322 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 334 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
323 struct i2c_client *client = to_i2c_client(dev); 335 struct i2c_client *client = to_i2c_client(dev);
324 struct lm63_data *data = i2c_get_clientdata(client); 336 struct lm63_data *data = i2c_get_clientdata(client);
325 int nr = attr->index; 337 int nr = attr->index;
326 int reg = nr == 2 ? LM63_REG_REMOTE_TCRIT : LM63_REG_LOCAL_HIGH; 338 int reg = nr == 2 ? LM63_REG_REMOTE_TCRIT : LM63_REG_LOCAL_HIGH;
327 long val; 339 long val;
328 int err; 340 int err;
329 int temp; 341 int temp;
330 342
331 err = kstrtol(buf, 10, &val); 343 err = kstrtol(buf, 10, &val);
332 if (err) 344 if (err)
333 return err; 345 return err;
334 346
335 mutex_lock(&data->update_lock); 347 mutex_lock(&data->update_lock);
336 if (nr == 2) { 348 if (nr == 2) {
337 if (data->remote_unsigned) 349 if (data->remote_unsigned)
338 temp = TEMP8U_TO_REG(val - data->temp2_offset); 350 temp = TEMP8U_TO_REG(val - data->temp2_offset);
339 else 351 else
340 temp = TEMP8_TO_REG(val - data->temp2_offset); 352 temp = TEMP8_TO_REG(val - data->temp2_offset);
341 } else { 353 } else {
342 temp = TEMP8_TO_REG(val); 354 temp = TEMP8_TO_REG(val);
343 } 355 }
344 data->temp8[nr] = temp; 356 data->temp8[nr] = temp;
345 i2c_smbus_write_byte_data(client, reg, temp); 357 i2c_smbus_write_byte_data(client, reg, temp);
346 mutex_unlock(&data->update_lock); 358 mutex_unlock(&data->update_lock);
347 return count; 359 return count;
348 } 360 }
349 361
350 static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, 362 static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
351 char *buf) 363 char *buf)
352 { 364 {
353 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 365 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
354 struct lm63_data *data = lm63_update_device(dev); 366 struct lm63_data *data = lm63_update_device(dev);
355 int nr = attr->index; 367 int nr = attr->index;
356 int temp; 368 int temp;
357 369
358 if (!nr) { 370 if (!nr) {
359 /* 371 /*
360 * Use unsigned temperature unless its value is zero. 372 * Use unsigned temperature unless its value is zero.
361 * If it is zero, use signed temperature. 373 * If it is zero, use signed temperature.
362 */ 374 */
363 if (data->temp11u) 375 if (data->temp11u)
364 temp = TEMP11_FROM_REG(data->temp11u); 376 temp = TEMP11_FROM_REG(data->temp11u);
365 else 377 else
366 temp = TEMP11_FROM_REG(data->temp11[nr]); 378 temp = TEMP11_FROM_REG(data->temp11[nr]);
367 } else { 379 } else {
368 if (data->remote_unsigned && nr == 2) 380 if (data->remote_unsigned && nr == 2)
369 temp = TEMP11_FROM_REG((u16)data->temp11[nr]); 381 temp = TEMP11_FROM_REG((u16)data->temp11[nr]);
370 else 382 else
371 temp = TEMP11_FROM_REG(data->temp11[nr]); 383 temp = TEMP11_FROM_REG(data->temp11[nr]);
372 } 384 }
373 return sprintf(buf, "%d\n", temp + data->temp2_offset); 385 return sprintf(buf, "%d\n", temp + data->temp2_offset);
374 } 386 }
375 387
376 static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, 388 static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
377 const char *buf, size_t count) 389 const char *buf, size_t count)
378 { 390 {
379 static const u8 reg[6] = { 391 static const u8 reg[6] = {
380 LM63_REG_REMOTE_LOW_MSB, 392 LM63_REG_REMOTE_LOW_MSB,
381 LM63_REG_REMOTE_LOW_LSB, 393 LM63_REG_REMOTE_LOW_LSB,
382 LM63_REG_REMOTE_HIGH_MSB, 394 LM63_REG_REMOTE_HIGH_MSB,
383 LM63_REG_REMOTE_HIGH_LSB, 395 LM63_REG_REMOTE_HIGH_LSB,
384 LM63_REG_REMOTE_OFFSET_MSB, 396 LM63_REG_REMOTE_OFFSET_MSB,
385 LM63_REG_REMOTE_OFFSET_LSB, 397 LM63_REG_REMOTE_OFFSET_LSB,
386 }; 398 };
387 399
388 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 400 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
389 struct i2c_client *client = to_i2c_client(dev); 401 struct i2c_client *client = to_i2c_client(dev);
390 struct lm63_data *data = i2c_get_clientdata(client); 402 struct lm63_data *data = i2c_get_clientdata(client);
391 long val; 403 long val;
392 int err; 404 int err;
393 int nr = attr->index; 405 int nr = attr->index;
394 406
395 err = kstrtol(buf, 10, &val); 407 err = kstrtol(buf, 10, &val);
396 if (err) 408 if (err)
397 return err; 409 return err;
398 410
399 mutex_lock(&data->update_lock); 411 mutex_lock(&data->update_lock);
400 if (data->remote_unsigned && nr == 2) 412 if (data->remote_unsigned && nr == 2)
401 data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset); 413 data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset);
402 else 414 else
403 data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); 415 data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset);
404 416
405 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], 417 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
406 data->temp11[nr] >> 8); 418 data->temp11[nr] >> 8);
407 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], 419 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
408 data->temp11[nr] & 0xff); 420 data->temp11[nr] & 0xff);
409 mutex_unlock(&data->update_lock); 421 mutex_unlock(&data->update_lock);
410 return count; 422 return count;
411 } 423 }
412 424
413 /* 425 /*
414 * Hysteresis register holds a relative value, while we want to present 426 * Hysteresis register holds a relative value, while we want to present
415 * an absolute to user-space 427 * an absolute to user-space
416 */ 428 */
417 static ssize_t show_temp2_crit_hyst(struct device *dev, 429 static ssize_t show_temp2_crit_hyst(struct device *dev,
418 struct device_attribute *dummy, char *buf) 430 struct device_attribute *dummy, char *buf)
419 { 431 {
420 struct lm63_data *data = lm63_update_device(dev); 432 struct lm63_data *data = lm63_update_device(dev);
421 return sprintf(buf, "%d\n", temp8_from_reg(data, 2) 433 return sprintf(buf, "%d\n", temp8_from_reg(data, 2)
422 + data->temp2_offset 434 + data->temp2_offset
423 - TEMP8_FROM_REG(data->temp2_crit_hyst)); 435 - TEMP8_FROM_REG(data->temp2_crit_hyst));
424 } 436 }
425 437
426 /* 438 /*
427 * And now the other way around, user-space provides an absolute 439 * And now the other way around, user-space provides an absolute
428 * hysteresis value and we have to store a relative one 440 * hysteresis value and we have to store a relative one
429 */ 441 */
430 static ssize_t set_temp2_crit_hyst(struct device *dev, 442 static ssize_t set_temp2_crit_hyst(struct device *dev,
431 struct device_attribute *dummy, 443 struct device_attribute *dummy,
432 const char *buf, size_t count) 444 const char *buf, size_t count)
433 { 445 {
434 struct i2c_client *client = to_i2c_client(dev); 446 struct i2c_client *client = to_i2c_client(dev);
435 struct lm63_data *data = i2c_get_clientdata(client); 447 struct lm63_data *data = i2c_get_clientdata(client);
436 long val; 448 long val;
437 int err; 449 int err;
438 long hyst; 450 long hyst;
439 451
440 err = kstrtol(buf, 10, &val); 452 err = kstrtol(buf, 10, &val);
441 if (err) 453 if (err)
442 return err; 454 return err;
443 455
444 mutex_lock(&data->update_lock); 456 mutex_lock(&data->update_lock);
445 hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; 457 hyst = temp8_from_reg(data, 2) + data->temp2_offset - val;
446 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, 458 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
447 HYST_TO_REG(hyst)); 459 HYST_TO_REG(hyst));
448 mutex_unlock(&data->update_lock); 460 mutex_unlock(&data->update_lock);
449 return count; 461 return count;
450 } 462 }
451 463
464 /*
465 * Set conversion rate.
466 * client->update_lock must be held when calling this function.
467 */
468 static void lm63_set_convrate(struct i2c_client *client, struct lm63_data *data,
469 unsigned int interval)
470 {
471 int i;
472 unsigned int update_interval;
473
474 /* Shift calculations to avoid rounding errors */
475 interval <<= 6;
476
477 /* find the nearest update rate */
478 update_interval = (1 << (LM63_MAX_CONVRATE + 6)) * 1000
479 / data->max_convrate_hz;
480 for (i = 0; i < LM63_MAX_CONVRATE; i++, update_interval >>= 1)
481 if (interval >= update_interval * 3 / 4)
482 break;
483
484 i2c_smbus_write_byte_data(client, LM63_REG_CONVRATE, i);
485 data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz, i);
486 }
487
488 static ssize_t show_update_interval(struct device *dev,
489 struct device_attribute *attr, char *buf)
490 {
491 struct lm63_data *data = dev_get_drvdata(dev);
492
493 return sprintf(buf, "%u\n", data->update_interval);
494 }
495
496 static ssize_t set_update_interval(struct device *dev,
497 struct device_attribute *attr,
498 const char *buf, size_t count)
499 {
500 struct i2c_client *client = to_i2c_client(dev);
501 struct lm63_data *data = i2c_get_clientdata(client);
502 unsigned long val;
503 int err;
504
505 err = kstrtoul(buf, 10, &val);
506 if (err)
507 return err;
508
509 mutex_lock(&data->update_lock);
510 lm63_set_convrate(client, data, SENSORS_LIMIT(val, 0, 100000));
511 mutex_unlock(&data->update_lock);
512
513 return count;
514 }
515
452 static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, 516 static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
453 char *buf) 517 char *buf)
454 { 518 {
455 struct lm63_data *data = lm63_update_device(dev); 519 struct lm63_data *data = lm63_update_device(dev);
456 return sprintf(buf, "%u\n", data->alarms); 520 return sprintf(buf, "%u\n", data->alarms);
457 } 521 }
458 522
459 static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, 523 static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr,
460 char *buf) 524 char *buf)
461 { 525 {
462 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 526 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
463 struct lm63_data *data = lm63_update_device(dev); 527 struct lm63_data *data = lm63_update_device(dev);
464 int bitnr = attr->index; 528 int bitnr = attr->index;
465 529
466 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); 530 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
467 } 531 }
468 532
469 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); 533 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
470 static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, 534 static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan,
471 set_fan, 1); 535 set_fan, 1);
472 536
473 static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1); 537 static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1);
474 static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); 538 static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL);
475 539
476 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); 540 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0);
477 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, 541 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8,
478 set_temp8, 1); 542 set_temp8, 1);
479 543
480 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); 544 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
481 static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, 545 static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
482 set_temp11, 1); 546 set_temp11, 1);
483 static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, 547 static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
484 set_temp11, 2); 548 set_temp11, 2);
485 static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, 549 static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
486 set_temp11, 3); 550 set_temp11, 3);
487 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, 551 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8,
488 set_temp8, 2); 552 set_temp8, 2);
489 static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, 553 static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
490 set_temp2_crit_hyst); 554 set_temp2_crit_hyst);
491 555
492 /* Individual alarm files */ 556 /* Individual alarm files */
493 static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); 557 static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
494 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); 558 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
495 static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); 559 static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
496 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); 560 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
497 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); 561 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
498 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); 562 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
499 /* Raw alarm file for compatibility */ 563 /* Raw alarm file for compatibility */
500 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 564 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
501 565
566 static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval,
567 set_update_interval);
568
502 static struct attribute *lm63_attributes[] = { 569 static struct attribute *lm63_attributes[] = {
503 &dev_attr_pwm1.attr, 570 &dev_attr_pwm1.attr,
504 &dev_attr_pwm1_enable.attr, 571 &dev_attr_pwm1_enable.attr,
505 &sensor_dev_attr_temp1_input.dev_attr.attr, 572 &sensor_dev_attr_temp1_input.dev_attr.attr,
506 &sensor_dev_attr_temp2_input.dev_attr.attr, 573 &sensor_dev_attr_temp2_input.dev_attr.attr,
507 &sensor_dev_attr_temp2_min.dev_attr.attr, 574 &sensor_dev_attr_temp2_min.dev_attr.attr,
508 &sensor_dev_attr_temp1_max.dev_attr.attr, 575 &sensor_dev_attr_temp1_max.dev_attr.attr,
509 &sensor_dev_attr_temp2_max.dev_attr.attr, 576 &sensor_dev_attr_temp2_max.dev_attr.attr,
510 &sensor_dev_attr_temp2_offset.dev_attr.attr, 577 &sensor_dev_attr_temp2_offset.dev_attr.attr,
511 &sensor_dev_attr_temp2_crit.dev_attr.attr, 578 &sensor_dev_attr_temp2_crit.dev_attr.attr,
512 &dev_attr_temp2_crit_hyst.attr, 579 &dev_attr_temp2_crit_hyst.attr,
513 580
514 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, 581 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
515 &sensor_dev_attr_temp2_fault.dev_attr.attr, 582 &sensor_dev_attr_temp2_fault.dev_attr.attr,
516 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, 583 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
517 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 584 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
518 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 585 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
519 &dev_attr_alarms.attr, 586 &dev_attr_alarms.attr,
587 &dev_attr_update_interval.attr,
520 NULL 588 NULL
521 }; 589 };
522 590
523 /* 591 /*
524 * On LM63, temp2_crit can be set only once, which should be job 592 * On LM63, temp2_crit can be set only once, which should be job
525 * of the bootloader. 593 * of the bootloader.
526 * On LM64, temp2_crit can always be set. 594 * On LM64, temp2_crit can always be set.
527 * On LM96163, temp2_crit can be set if bit 1 of the configuration 595 * On LM96163, temp2_crit can be set if bit 1 of the configuration
528 * register is true. 596 * register is true.
529 */ 597 */
530 static umode_t lm63_attribute_mode(struct kobject *kobj, 598 static umode_t lm63_attribute_mode(struct kobject *kobj,
531 struct attribute *attr, int index) 599 struct attribute *attr, int index)
532 { 600 {
533 struct device *dev = container_of(kobj, struct device, kobj); 601 struct device *dev = container_of(kobj, struct device, kobj);
534 struct i2c_client *client = to_i2c_client(dev); 602 struct i2c_client *client = to_i2c_client(dev);
535 struct lm63_data *data = i2c_get_clientdata(client); 603 struct lm63_data *data = i2c_get_clientdata(client);
536 604
537 if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr 605 if (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr
538 && (data->kind == lm64 || 606 && (data->kind == lm64 ||
539 (data->kind == lm96163 && (data->config & 0x02)))) 607 (data->kind == lm96163 && (data->config & 0x02))))
540 return attr->mode | S_IWUSR; 608 return attr->mode | S_IWUSR;
541 609
542 return attr->mode; 610 return attr->mode;
543 } 611 }
544 612
545 static const struct attribute_group lm63_group = { 613 static const struct attribute_group lm63_group = {
546 .is_visible = lm63_attribute_mode, 614 .is_visible = lm63_attribute_mode,
547 .attrs = lm63_attributes, 615 .attrs = lm63_attributes,
548 }; 616 };
549 617
550 static struct attribute *lm63_attributes_fan1[] = { 618 static struct attribute *lm63_attributes_fan1[] = {
551 &sensor_dev_attr_fan1_input.dev_attr.attr, 619 &sensor_dev_attr_fan1_input.dev_attr.attr,
552 &sensor_dev_attr_fan1_min.dev_attr.attr, 620 &sensor_dev_attr_fan1_min.dev_attr.attr,
553 621
554 &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, 622 &sensor_dev_attr_fan1_min_alarm.dev_attr.attr,
555 NULL 623 NULL
556 }; 624 };
557 625
558 static const struct attribute_group lm63_group_fan1 = { 626 static const struct attribute_group lm63_group_fan1 = {
559 .attrs = lm63_attributes_fan1, 627 .attrs = lm63_attributes_fan1,
560 }; 628 };
561 629
562 /* 630 /*
563 * Real code 631 * Real code
564 */ 632 */
565 633
566 /* Return 0 if detection is successful, -ENODEV otherwise */ 634 /* Return 0 if detection is successful, -ENODEV otherwise */
567 static int lm63_detect(struct i2c_client *new_client, 635 static int lm63_detect(struct i2c_client *new_client,
568 struct i2c_board_info *info) 636 struct i2c_board_info *info)
569 { 637 {
570 struct i2c_adapter *adapter = new_client->adapter; 638 struct i2c_adapter *adapter = new_client->adapter;
571 u8 man_id, chip_id, reg_config1, reg_config2; 639 u8 man_id, chip_id, reg_config1, reg_config2;
572 u8 reg_alert_status, reg_alert_mask; 640 u8 reg_alert_status, reg_alert_mask;
573 int address = new_client->addr; 641 int address = new_client->addr;
574 642
575 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 643 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
576 return -ENODEV; 644 return -ENODEV;
577 645
578 man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); 646 man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID);
579 chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); 647 chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID);
580 648
581 reg_config1 = i2c_smbus_read_byte_data(new_client, 649 reg_config1 = i2c_smbus_read_byte_data(new_client,
582 LM63_REG_CONFIG1); 650 LM63_REG_CONFIG1);
583 reg_config2 = i2c_smbus_read_byte_data(new_client, 651 reg_config2 = i2c_smbus_read_byte_data(new_client,
584 LM63_REG_CONFIG2); 652 LM63_REG_CONFIG2);
585 reg_alert_status = i2c_smbus_read_byte_data(new_client, 653 reg_alert_status = i2c_smbus_read_byte_data(new_client,
586 LM63_REG_ALERT_STATUS); 654 LM63_REG_ALERT_STATUS);
587 reg_alert_mask = i2c_smbus_read_byte_data(new_client, 655 reg_alert_mask = i2c_smbus_read_byte_data(new_client,
588 LM63_REG_ALERT_MASK); 656 LM63_REG_ALERT_MASK);
589 657
590 if (man_id != 0x01 /* National Semiconductor */ 658 if (man_id != 0x01 /* National Semiconductor */
591 || (reg_config1 & 0x18) != 0x00 659 || (reg_config1 & 0x18) != 0x00
592 || (reg_config2 & 0xF8) != 0x00 660 || (reg_config2 & 0xF8) != 0x00
593 || (reg_alert_status & 0x20) != 0x00 661 || (reg_alert_status & 0x20) != 0x00
594 || (reg_alert_mask & 0xA4) != 0xA4) { 662 || (reg_alert_mask & 0xA4) != 0xA4) {
595 dev_dbg(&adapter->dev, 663 dev_dbg(&adapter->dev,
596 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", 664 "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
597 man_id, chip_id); 665 man_id, chip_id);
598 return -ENODEV; 666 return -ENODEV;
599 } 667 }
600 668
601 if (chip_id == 0x41 && address == 0x4c) 669 if (chip_id == 0x41 && address == 0x4c)
602 strlcpy(info->type, "lm63", I2C_NAME_SIZE); 670 strlcpy(info->type, "lm63", I2C_NAME_SIZE);
603 else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) 671 else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e))
604 strlcpy(info->type, "lm64", I2C_NAME_SIZE); 672 strlcpy(info->type, "lm64", I2C_NAME_SIZE);
605 else if (chip_id == 0x49 && address == 0x4c) 673 else if (chip_id == 0x49 && address == 0x4c)
606 strlcpy(info->type, "lm96163", I2C_NAME_SIZE); 674 strlcpy(info->type, "lm96163", I2C_NAME_SIZE);
607 else 675 else
608 return -ENODEV; 676 return -ENODEV;
609 677
610 return 0; 678 return 0;
611 } 679 }
612 680
613 static int lm63_probe(struct i2c_client *new_client, 681 static int lm63_probe(struct i2c_client *new_client,
614 const struct i2c_device_id *id) 682 const struct i2c_device_id *id)
615 { 683 {
616 struct lm63_data *data; 684 struct lm63_data *data;
617 int err; 685 int err;
618 686
619 data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); 687 data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL);
620 if (!data) { 688 if (!data) {
621 err = -ENOMEM; 689 err = -ENOMEM;
622 goto exit; 690 goto exit;
623 } 691 }
624 692
625 i2c_set_clientdata(new_client, data); 693 i2c_set_clientdata(new_client, data);
626 data->valid = 0; 694 data->valid = 0;
627 mutex_init(&data->update_lock); 695 mutex_init(&data->update_lock);
628 696
629 /* Set the device type */ 697 /* Set the device type */
630 data->kind = id->driver_data; 698 data->kind = id->driver_data;
631 if (data->kind == lm64) 699 if (data->kind == lm64)
632 data->temp2_offset = 16000; 700 data->temp2_offset = 16000;
633 701
634 /* Initialize chip */ 702 /* Initialize chip */
635 lm63_init_client(new_client); 703 lm63_init_client(new_client);
636 704
637 /* Register sysfs hooks */ 705 /* Register sysfs hooks */
638 err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); 706 err = sysfs_create_group(&new_client->dev.kobj, &lm63_group);
639 if (err) 707 if (err)
640 goto exit_free; 708 goto exit_free;
641 if (data->config & 0x04) { /* tachometer enabled */ 709 if (data->config & 0x04) { /* tachometer enabled */
642 err = sysfs_create_group(&new_client->dev.kobj, 710 err = sysfs_create_group(&new_client->dev.kobj,
643 &lm63_group_fan1); 711 &lm63_group_fan1);
644 if (err) 712 if (err)
645 goto exit_remove_files; 713 goto exit_remove_files;
646 } 714 }
647 715
648 data->hwmon_dev = hwmon_device_register(&new_client->dev); 716 data->hwmon_dev = hwmon_device_register(&new_client->dev);
649 if (IS_ERR(data->hwmon_dev)) { 717 if (IS_ERR(data->hwmon_dev)) {
650 err = PTR_ERR(data->hwmon_dev); 718 err = PTR_ERR(data->hwmon_dev);
651 goto exit_remove_files; 719 goto exit_remove_files;
652 } 720 }
653 721
654 return 0; 722 return 0;
655 723
656 exit_remove_files: 724 exit_remove_files:
657 sysfs_remove_group(&new_client->dev.kobj, &lm63_group); 725 sysfs_remove_group(&new_client->dev.kobj, &lm63_group);
658 sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); 726 sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1);
659 exit_free: 727 exit_free:
660 kfree(data); 728 kfree(data);
661 exit: 729 exit:
662 return err; 730 return err;
663 } 731 }
664 732
665 /* 733 /*
666 * Ideally we shouldn't have to initialize anything, since the BIOS 734 * Ideally we shouldn't have to initialize anything, since the BIOS
667 * should have taken care of everything 735 * should have taken care of everything
668 */ 736 */
669 static void lm63_init_client(struct i2c_client *client) 737 static void lm63_init_client(struct i2c_client *client)
670 { 738 {
671 struct lm63_data *data = i2c_get_clientdata(client); 739 struct lm63_data *data = i2c_get_clientdata(client);
740 u8 convrate;
672 741
673 data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); 742 data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1);
674 data->config_fan = i2c_smbus_read_byte_data(client, 743 data->config_fan = i2c_smbus_read_byte_data(client,
675 LM63_REG_CONFIG_FAN); 744 LM63_REG_CONFIG_FAN);
676 745
677 /* Start converting if needed */ 746 /* Start converting if needed */
678 if (data->config & 0x40) { /* standby */ 747 if (data->config & 0x40) { /* standby */
679 dev_dbg(&client->dev, "Switching to operational mode\n"); 748 dev_dbg(&client->dev, "Switching to operational mode\n");
680 data->config &= 0xA7; 749 data->config &= 0xA7;
681 i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, 750 i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1,
682 data->config); 751 data->config);
683 } 752 }
684 753
685 /* We may need pwm1_freq before ever updating the client data */ 754 /* We may need pwm1_freq before ever updating the client data */
686 data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); 755 data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ);
687 if (data->pwm1_freq == 0) 756 if (data->pwm1_freq == 0)
688 data->pwm1_freq = 1; 757 data->pwm1_freq = 1;
689 758
759 switch (data->kind) {
760 case lm63:
761 case lm64:
762 data->max_convrate_hz = LM63_MAX_CONVRATE_HZ;
763 break;
764 case lm96163:
765 data->max_convrate_hz = LM96163_MAX_CONVRATE_HZ;
766 break;
767 }
768 convrate = i2c_smbus_read_byte_data(client, LM63_REG_CONVRATE);
769 if (unlikely(convrate > LM63_MAX_CONVRATE))
770 convrate = LM63_MAX_CONVRATE;
771 data->update_interval = UPDATE_INTERVAL(data->max_convrate_hz,
772 convrate);
773
690 /* 774 /*
691 * For LM96163, check if high resolution PWM 775 * For LM96163, check if high resolution PWM
692 * and unsigned temperature format is enabled. 776 * and unsigned temperature format is enabled.
693 */ 777 */
694 if (data->kind == lm96163) { 778 if (data->kind == lm96163) {
695 u8 config_enhanced 779 u8 config_enhanced
696 = i2c_smbus_read_byte_data(client, 780 = i2c_smbus_read_byte_data(client,
697 LM96163_REG_CONFIG_ENHANCED); 781 LM96163_REG_CONFIG_ENHANCED);
698 if ((config_enhanced & 0x10) 782 if ((config_enhanced & 0x10)
699 && !(data->config_fan & 0x08) && data->pwm1_freq == 8) 783 && !(data->config_fan & 0x08) && data->pwm1_freq == 8)
700 data->pwm_highres = true; 784 data->pwm_highres = true;
701 if (config_enhanced & 0x08) 785 if (config_enhanced & 0x08)
702 data->remote_unsigned = true; 786 data->remote_unsigned = true;
703 } 787 }
704 788
705 /* Show some debug info about the LM63 configuration */ 789 /* Show some debug info about the LM63 configuration */
706 dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", 790 dev_dbg(&client->dev, "Alert/tach pin configured for %s\n",
707 (data->config & 0x04) ? "tachometer input" : 791 (data->config & 0x04) ? "tachometer input" :
708 "alert output"); 792 "alert output");
709 dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", 793 dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n",
710 (data->config_fan & 0x08) ? "1.4" : "360", 794 (data->config_fan & 0x08) ? "1.4" : "360",
711 ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); 795 ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq);
712 dev_dbg(&client->dev, "PWM output active %s, %s mode\n", 796 dev_dbg(&client->dev, "PWM output active %s, %s mode\n",
713 (data->config_fan & 0x10) ? "low" : "high", 797 (data->config_fan & 0x10) ? "low" : "high",
714 (data->config_fan & 0x20) ? "manual" : "auto"); 798 (data->config_fan & 0x20) ? "manual" : "auto");
715 } 799 }
716 800
717 static int lm63_remove(struct i2c_client *client) 801 static int lm63_remove(struct i2c_client *client)
718 { 802 {
719 struct lm63_data *data = i2c_get_clientdata(client); 803 struct lm63_data *data = i2c_get_clientdata(client);
720 804
721 hwmon_device_unregister(data->hwmon_dev); 805 hwmon_device_unregister(data->hwmon_dev);
722 sysfs_remove_group(&client->dev.kobj, &lm63_group); 806 sysfs_remove_group(&client->dev.kobj, &lm63_group);
723 sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); 807 sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
724 808
725 kfree(data); 809 kfree(data);
726 return 0; 810 return 0;
727 } 811 }
728 812
729 static struct lm63_data *lm63_update_device(struct device *dev) 813 static struct lm63_data *lm63_update_device(struct device *dev)
730 { 814 {
731 struct i2c_client *client = to_i2c_client(dev); 815 struct i2c_client *client = to_i2c_client(dev);
732 struct lm63_data *data = i2c_get_clientdata(client); 816 struct lm63_data *data = i2c_get_clientdata(client);
817 unsigned long next_update;
733 818
734 mutex_lock(&data->update_lock); 819 mutex_lock(&data->update_lock);
735 820
736 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 821 next_update = data->last_updated
822 + msecs_to_jiffies(data->update_interval) + 1;
823
824 if (time_after(jiffies, next_update) || !data->valid) {
737 if (data->config & 0x04) { /* tachometer enabled */ 825 if (data->config & 0x04) { /* tachometer enabled */
738 /* order matters for fan1_input */ 826 /* order matters for fan1_input */
739 data->fan[0] = i2c_smbus_read_byte_data(client, 827 data->fan[0] = i2c_smbus_read_byte_data(client,
740 LM63_REG_TACH_COUNT_LSB) & 0xFC; 828 LM63_REG_TACH_COUNT_LSB) & 0xFC;
741 data->fan[0] |= i2c_smbus_read_byte_data(client, 829 data->fan[0] |= i2c_smbus_read_byte_data(client,
742 LM63_REG_TACH_COUNT_MSB) << 8; 830 LM63_REG_TACH_COUNT_MSB) << 8;
743 data->fan[1] = (i2c_smbus_read_byte_data(client, 831 data->fan[1] = (i2c_smbus_read_byte_data(client,
744 LM63_REG_TACH_LIMIT_LSB) & 0xFC) 832 LM63_REG_TACH_LIMIT_LSB) & 0xFC)
745 | (i2c_smbus_read_byte_data(client, 833 | (i2c_smbus_read_byte_data(client,
746 LM63_REG_TACH_LIMIT_MSB) << 8); 834 LM63_REG_TACH_LIMIT_MSB) << 8);
747 } 835 }
748 836
749 data->pwm1_freq = i2c_smbus_read_byte_data(client, 837 data->pwm1_freq = i2c_smbus_read_byte_data(client,
750 LM63_REG_PWM_FREQ); 838 LM63_REG_PWM_FREQ);
751 if (data->pwm1_freq == 0) 839 if (data->pwm1_freq == 0)
752 data->pwm1_freq = 1; 840 data->pwm1_freq = 1;
753 data->pwm1_value = i2c_smbus_read_byte_data(client, 841 data->pwm1_value = i2c_smbus_read_byte_data(client,
754 LM63_REG_PWM_VALUE); 842 LM63_REG_PWM_VALUE);
755 843
756 data->temp8[0] = i2c_smbus_read_byte_data(client, 844 data->temp8[0] = i2c_smbus_read_byte_data(client,
757 LM63_REG_LOCAL_TEMP); 845 LM63_REG_LOCAL_TEMP);
758 data->temp8[1] = i2c_smbus_read_byte_data(client, 846 data->temp8[1] = i2c_smbus_read_byte_data(client,
759 LM63_REG_LOCAL_HIGH); 847 LM63_REG_LOCAL_HIGH);
760 848
761 /* order matters for temp2_input */ 849 /* order matters for temp2_input */
762 data->temp11[0] = i2c_smbus_read_byte_data(client, 850 data->temp11[0] = i2c_smbus_read_byte_data(client,
763 LM63_REG_REMOTE_TEMP_MSB) << 8; 851 LM63_REG_REMOTE_TEMP_MSB) << 8;
764 data->temp11[0] |= i2c_smbus_read_byte_data(client, 852 data->temp11[0] |= i2c_smbus_read_byte_data(client,
765 LM63_REG_REMOTE_TEMP_LSB); 853 LM63_REG_REMOTE_TEMP_LSB);
766 data->temp11[1] = (i2c_smbus_read_byte_data(client, 854 data->temp11[1] = (i2c_smbus_read_byte_data(client,
767 LM63_REG_REMOTE_LOW_MSB) << 8) 855 LM63_REG_REMOTE_LOW_MSB) << 8)
768 | i2c_smbus_read_byte_data(client, 856 | i2c_smbus_read_byte_data(client,
769 LM63_REG_REMOTE_LOW_LSB); 857 LM63_REG_REMOTE_LOW_LSB);
770 data->temp11[2] = (i2c_smbus_read_byte_data(client, 858 data->temp11[2] = (i2c_smbus_read_byte_data(client,
771 LM63_REG_REMOTE_HIGH_MSB) << 8) 859 LM63_REG_REMOTE_HIGH_MSB) << 8)
772 | i2c_smbus_read_byte_data(client, 860 | i2c_smbus_read_byte_data(client,
773 LM63_REG_REMOTE_HIGH_LSB); 861 LM63_REG_REMOTE_HIGH_LSB);
774 data->temp11[3] = (i2c_smbus_read_byte_data(client, 862 data->temp11[3] = (i2c_smbus_read_byte_data(client,
775 LM63_REG_REMOTE_OFFSET_MSB) << 8) 863 LM63_REG_REMOTE_OFFSET_MSB) << 8)
776 | i2c_smbus_read_byte_data(client, 864 | i2c_smbus_read_byte_data(client,
777 LM63_REG_REMOTE_OFFSET_LSB); 865 LM63_REG_REMOTE_OFFSET_LSB);
778 866
779 if (data->kind == lm96163) 867 if (data->kind == lm96163)
780 data->temp11u = (i2c_smbus_read_byte_data(client, 868 data->temp11u = (i2c_smbus_read_byte_data(client,
781 LM96163_REG_REMOTE_TEMP_U_MSB) << 8) 869 LM96163_REG_REMOTE_TEMP_U_MSB) << 8)
782 | i2c_smbus_read_byte_data(client, 870 | i2c_smbus_read_byte_data(client,
783 LM96163_REG_REMOTE_TEMP_U_LSB); 871 LM96163_REG_REMOTE_TEMP_U_LSB);
784 872
785 data->temp8[2] = i2c_smbus_read_byte_data(client, 873 data->temp8[2] = i2c_smbus_read_byte_data(client,
786 LM63_REG_REMOTE_TCRIT); 874 LM63_REG_REMOTE_TCRIT);
787 data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, 875 data->temp2_crit_hyst = i2c_smbus_read_byte_data(client,
788 LM63_REG_REMOTE_TCRIT_HYST); 876 LM63_REG_REMOTE_TCRIT_HYST);
789 877
790 data->alarms = i2c_smbus_read_byte_data(client, 878 data->alarms = i2c_smbus_read_byte_data(client,
791 LM63_REG_ALERT_STATUS) & 0x7F; 879 LM63_REG_ALERT_STATUS) & 0x7F;
792 880
793 data->last_updated = jiffies; 881 data->last_updated = jiffies;
794 data->valid = 1; 882 data->valid = 1;
795 } 883 }
796 884
797 mutex_unlock(&data->update_lock); 885 mutex_unlock(&data->update_lock);
798 886
799 return data; 887 return data;
800 } 888 }
801 889
802 static int __init sensors_lm63_init(void) 890 static int __init sensors_lm63_init(void)
803 { 891 {
804 return i2c_add_driver(&lm63_driver); 892 return i2c_add_driver(&lm63_driver);
805 } 893 }
806 894
807 static void __exit sensors_lm63_exit(void) 895 static void __exit sensors_lm63_exit(void)
808 { 896 {
809 i2c_del_driver(&lm63_driver); 897 i2c_del_driver(&lm63_driver);
810 } 898 }
811 899
812 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 900 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
813 MODULE_DESCRIPTION("LM63 driver"); 901 MODULE_DESCRIPTION("LM63 driver");
814 MODULE_LICENSE("GPL"); 902 MODULE_LICENSE("GPL");
815 903
816 module_init(sensors_lm63_init); 904 module_init(sensors_lm63_init);
817 module_exit(sensors_lm63_exit); 905 module_exit(sensors_lm63_exit);
818 906