Commit e872c91e726e7f7f74817cf9a81a138bf0d0a583
Committed by
Jean Delvare
1 parent
210961c436
Exists in
master
and in
6 other branches
hwmon: (lm63) Add support for unsigned upper temperature limits
LM96163 supports unsigned upper limits for the external temperature sensor. Add support for it. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Showing 1 changed file with 51 additions and 11 deletions Inline Diff
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_CONFIG2 0xBF | 64 | #define LM63_REG_CONFIG2 0xBF |
65 | #define LM63_REG_CONFIG_FAN 0x4A | 65 | #define LM63_REG_CONFIG_FAN 0x4A |
66 | 66 | ||
67 | #define LM63_REG_TACH_COUNT_MSB 0x47 | 67 | #define LM63_REG_TACH_COUNT_MSB 0x47 |
68 | #define LM63_REG_TACH_COUNT_LSB 0x46 | 68 | #define LM63_REG_TACH_COUNT_LSB 0x46 |
69 | #define LM63_REG_TACH_LIMIT_MSB 0x49 | 69 | #define LM63_REG_TACH_LIMIT_MSB 0x49 |
70 | #define LM63_REG_TACH_LIMIT_LSB 0x48 | 70 | #define LM63_REG_TACH_LIMIT_LSB 0x48 |
71 | 71 | ||
72 | #define LM63_REG_PWM_VALUE 0x4C | 72 | #define LM63_REG_PWM_VALUE 0x4C |
73 | #define LM63_REG_PWM_FREQ 0x4D | 73 | #define LM63_REG_PWM_FREQ 0x4D |
74 | 74 | ||
75 | #define LM63_REG_LOCAL_TEMP 0x00 | 75 | #define LM63_REG_LOCAL_TEMP 0x00 |
76 | #define LM63_REG_LOCAL_HIGH 0x05 | 76 | #define LM63_REG_LOCAL_HIGH 0x05 |
77 | 77 | ||
78 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 | 78 | #define LM63_REG_REMOTE_TEMP_MSB 0x01 |
79 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 | 79 | #define LM63_REG_REMOTE_TEMP_LSB 0x10 |
80 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 | 80 | #define LM63_REG_REMOTE_OFFSET_MSB 0x11 |
81 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 | 81 | #define LM63_REG_REMOTE_OFFSET_LSB 0x12 |
82 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 | 82 | #define LM63_REG_REMOTE_HIGH_MSB 0x07 |
83 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 | 83 | #define LM63_REG_REMOTE_HIGH_LSB 0x13 |
84 | #define LM63_REG_REMOTE_LOW_MSB 0x08 | 84 | #define LM63_REG_REMOTE_LOW_MSB 0x08 |
85 | #define LM63_REG_REMOTE_LOW_LSB 0x14 | 85 | #define LM63_REG_REMOTE_LOW_LSB 0x14 |
86 | #define LM63_REG_REMOTE_TCRIT 0x19 | 86 | #define LM63_REG_REMOTE_TCRIT 0x19 |
87 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 | 87 | #define LM63_REG_REMOTE_TCRIT_HYST 0x21 |
88 | 88 | ||
89 | #define LM63_REG_ALERT_STATUS 0x02 | 89 | #define LM63_REG_ALERT_STATUS 0x02 |
90 | #define LM63_REG_ALERT_MASK 0x16 | 90 | #define LM63_REG_ALERT_MASK 0x16 |
91 | 91 | ||
92 | #define LM63_REG_MAN_ID 0xFE | 92 | #define LM63_REG_MAN_ID 0xFE |
93 | #define LM63_REG_CHIP_ID 0xFF | 93 | #define LM63_REG_CHIP_ID 0xFF |
94 | 94 | ||
95 | #define LM96163_REG_REMOTE_TEMP_U_MSB 0x31 | ||
96 | #define LM96163_REG_REMOTE_TEMP_U_LSB 0x32 | ||
95 | #define LM96163_REG_CONFIG_ENHANCED 0x45 | 97 | #define LM96163_REG_CONFIG_ENHANCED 0x45 |
96 | 98 | ||
97 | /* | 99 | /* |
98 | * Conversions and various macros | 100 | * Conversions and various macros |
99 | * For tachometer counts, the LM63 uses 16-bit values. | 101 | * For tachometer counts, the LM63 uses 16-bit values. |
100 | * For local temperature and high limit, remote critical limit and hysteresis | 102 | * For local temperature and high limit, remote critical limit and hysteresis |
101 | * value, it uses signed 8-bit values with LSB = 1 degree Celsius. | 103 | * 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 | 104 | * 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. | 105 | * 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 | 106 | * For LM64 the actual remote diode temperature is 16 degree Celsius higher |
105 | * than the register reading. Remote temperature setpoints have to be | 107 | * than the register reading. Remote temperature setpoints have to be |
106 | * adapted accordingly. | 108 | * adapted accordingly. |
107 | */ | 109 | */ |
108 | 110 | ||
109 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ | 111 | #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \ |
110 | 5400000 / (reg)) | 112 | 5400000 / (reg)) |
111 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ | 113 | #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \ |
112 | (5400000 / (val)) & 0xFFFC) | 114 | (5400000 / (val)) & 0xFFFC) |
113 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) | 115 | #define TEMP8_FROM_REG(reg) ((reg) * 1000) |
114 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ | 116 | #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \ |
115 | (val) >= 127000 ? 127 : \ | 117 | (val) >= 127000 ? 127 : \ |
116 | (val) < 0 ? ((val) - 500) / 1000 : \ | 118 | (val) < 0 ? ((val) - 500) / 1000 : \ |
117 | ((val) + 500) / 1000) | 119 | ((val) + 500) / 1000) |
118 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) | 120 | #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125) |
119 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ | 121 | #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \ |
120 | (val) >= 127875 ? 0x7FE0 : \ | 122 | (val) >= 127875 ? 0x7FE0 : \ |
121 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ | 123 | (val) < 0 ? ((val) - 62) / 125 * 32 : \ |
122 | ((val) + 62) / 125 * 32) | 124 | ((val) + 62) / 125 * 32) |
125 | #define TEMP11U_TO_REG(val) ((val) <= 0 ? 0 : \ | ||
126 | (val) >= 255875 ? 0xFFE0 : \ | ||
127 | ((val) + 62) / 125 * 32) | ||
123 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ | 128 | #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ |
124 | (val) >= 127000 ? 127 : \ | 129 | (val) >= 127000 ? 127 : \ |
125 | ((val) + 500) / 1000) | 130 | ((val) + 500) / 1000) |
126 | 131 | ||
127 | /* | 132 | /* |
128 | * Functions declaration | 133 | * Functions declaration |
129 | */ | 134 | */ |
130 | 135 | ||
131 | static int lm63_probe(struct i2c_client *client, | 136 | static int lm63_probe(struct i2c_client *client, |
132 | const struct i2c_device_id *id); | 137 | const struct i2c_device_id *id); |
133 | static int lm63_remove(struct i2c_client *client); | 138 | static int lm63_remove(struct i2c_client *client); |
134 | 139 | ||
135 | static struct lm63_data *lm63_update_device(struct device *dev); | 140 | static struct lm63_data *lm63_update_device(struct device *dev); |
136 | 141 | ||
137 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); | 142 | static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info); |
138 | static void lm63_init_client(struct i2c_client *client); | 143 | static void lm63_init_client(struct i2c_client *client); |
139 | 144 | ||
140 | enum chips { lm63, lm64, lm96163 }; | 145 | enum chips { lm63, lm64, lm96163 }; |
141 | 146 | ||
142 | /* | 147 | /* |
143 | * Driver data (common to all clients) | 148 | * Driver data (common to all clients) |
144 | */ | 149 | */ |
145 | 150 | ||
146 | static const struct i2c_device_id lm63_id[] = { | 151 | static const struct i2c_device_id lm63_id[] = { |
147 | { "lm63", lm63 }, | 152 | { "lm63", lm63 }, |
148 | { "lm64", lm64 }, | 153 | { "lm64", lm64 }, |
149 | { "lm96163", lm96163 }, | 154 | { "lm96163", lm96163 }, |
150 | { } | 155 | { } |
151 | }; | 156 | }; |
152 | MODULE_DEVICE_TABLE(i2c, lm63_id); | 157 | MODULE_DEVICE_TABLE(i2c, lm63_id); |
153 | 158 | ||
154 | static struct i2c_driver lm63_driver = { | 159 | static struct i2c_driver lm63_driver = { |
155 | .class = I2C_CLASS_HWMON, | 160 | .class = I2C_CLASS_HWMON, |
156 | .driver = { | 161 | .driver = { |
157 | .name = "lm63", | 162 | .name = "lm63", |
158 | }, | 163 | }, |
159 | .probe = lm63_probe, | 164 | .probe = lm63_probe, |
160 | .remove = lm63_remove, | 165 | .remove = lm63_remove, |
161 | .id_table = lm63_id, | 166 | .id_table = lm63_id, |
162 | .detect = lm63_detect, | 167 | .detect = lm63_detect, |
163 | .address_list = normal_i2c, | 168 | .address_list = normal_i2c, |
164 | }; | 169 | }; |
165 | 170 | ||
166 | /* | 171 | /* |
167 | * Client data (each client gets its own) | 172 | * Client data (each client gets its own) |
168 | */ | 173 | */ |
169 | 174 | ||
170 | struct lm63_data { | 175 | struct lm63_data { |
171 | struct device *hwmon_dev; | 176 | struct device *hwmon_dev; |
172 | struct mutex update_lock; | 177 | struct mutex update_lock; |
173 | char valid; /* zero until following fields are valid */ | 178 | char valid; /* zero until following fields are valid */ |
174 | unsigned long last_updated; /* in jiffies */ | 179 | unsigned long last_updated; /* in jiffies */ |
175 | int kind; | 180 | int kind; |
176 | int temp2_offset; | 181 | int temp2_offset; |
177 | 182 | ||
178 | /* registers values */ | 183 | /* registers values */ |
179 | u8 config, config_fan; | 184 | u8 config, config_fan; |
180 | u16 fan[2]; /* 0: input | 185 | u16 fan[2]; /* 0: input |
181 | 1: low limit */ | 186 | 1: low limit */ |
182 | u8 pwm1_freq; | 187 | u8 pwm1_freq; |
183 | u8 pwm1_value; | 188 | u8 pwm1_value; |
184 | s8 temp8[3]; /* 0: local input | 189 | s8 temp8[3]; /* 0: local input |
185 | 1: local high limit | 190 | 1: local high limit |
186 | 2: remote critical limit */ | 191 | 2: remote critical limit */ |
187 | s16 temp11[4]; /* 0: remote input | 192 | s16 temp11[4]; /* 0: remote input |
188 | 1: remote low limit | 193 | 1: remote low limit |
189 | 2: remote high limit | 194 | 2: remote high limit |
190 | 3: remote offset */ | 195 | 3: remote offset */ |
196 | u16 temp11u; /* remote input (unsigned) */ | ||
191 | u8 temp2_crit_hyst; | 197 | u8 temp2_crit_hyst; |
192 | u8 alarms; | 198 | u8 alarms; |
193 | bool pwm_highres; | 199 | bool pwm_highres; |
200 | bool remote_unsigned; /* true if unsigned remote upper limits */ | ||
194 | }; | 201 | }; |
195 | 202 | ||
203 | static inline int temp8_from_reg(struct lm63_data *data, int nr) | ||
204 | { | ||
205 | if (data->remote_unsigned) | ||
206 | return TEMP8_FROM_REG((u8)data->temp8[nr]); | ||
207 | return TEMP8_FROM_REG(data->temp8[nr]); | ||
208 | } | ||
209 | |||
196 | /* | 210 | /* |
197 | * Sysfs callback functions and files | 211 | * Sysfs callback functions and files |
198 | */ | 212 | */ |
199 | 213 | ||
200 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | 214 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
201 | char *buf) | 215 | char *buf) |
202 | { | 216 | { |
203 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 217 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
204 | struct lm63_data *data = lm63_update_device(dev); | 218 | struct lm63_data *data = lm63_update_device(dev); |
205 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); | 219 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index])); |
206 | } | 220 | } |
207 | 221 | ||
208 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, | 222 | static ssize_t set_fan(struct device *dev, struct device_attribute *dummy, |
209 | const char *buf, size_t count) | 223 | const char *buf, size_t count) |
210 | { | 224 | { |
211 | struct i2c_client *client = to_i2c_client(dev); | 225 | struct i2c_client *client = to_i2c_client(dev); |
212 | struct lm63_data *data = i2c_get_clientdata(client); | 226 | struct lm63_data *data = i2c_get_clientdata(client); |
213 | unsigned long val; | 227 | unsigned long val; |
214 | int err; | 228 | int err; |
215 | 229 | ||
216 | err = kstrtoul(buf, 10, &val); | 230 | err = kstrtoul(buf, 10, &val); |
217 | if (err) | 231 | if (err) |
218 | return err; | 232 | return err; |
219 | 233 | ||
220 | mutex_lock(&data->update_lock); | 234 | mutex_lock(&data->update_lock); |
221 | data->fan[1] = FAN_TO_REG(val); | 235 | data->fan[1] = FAN_TO_REG(val); |
222 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, | 236 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB, |
223 | data->fan[1] & 0xFF); | 237 | data->fan[1] & 0xFF); |
224 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, | 238 | i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB, |
225 | data->fan[1] >> 8); | 239 | data->fan[1] >> 8); |
226 | mutex_unlock(&data->update_lock); | 240 | mutex_unlock(&data->update_lock); |
227 | return count; | 241 | return count; |
228 | } | 242 | } |
229 | 243 | ||
230 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy, | 244 | static ssize_t show_pwm1(struct device *dev, struct device_attribute *dummy, |
231 | char *buf) | 245 | char *buf) |
232 | { | 246 | { |
233 | struct lm63_data *data = lm63_update_device(dev); | 247 | struct lm63_data *data = lm63_update_device(dev); |
234 | int pwm; | 248 | int pwm; |
235 | 249 | ||
236 | if (data->pwm_highres) | 250 | if (data->pwm_highres) |
237 | pwm = data->pwm1_value; | 251 | pwm = data->pwm1_value; |
238 | else | 252 | else |
239 | pwm = data->pwm1_value >= 2 * data->pwm1_freq ? | 253 | pwm = data->pwm1_value >= 2 * data->pwm1_freq ? |
240 | 255 : (data->pwm1_value * 255 + data->pwm1_freq) / | 254 | 255 : (data->pwm1_value * 255 + data->pwm1_freq) / |
241 | (2 * data->pwm1_freq); | 255 | (2 * data->pwm1_freq); |
242 | 256 | ||
243 | return sprintf(buf, "%d\n", pwm); | 257 | return sprintf(buf, "%d\n", pwm); |
244 | } | 258 | } |
245 | 259 | ||
246 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, | 260 | static ssize_t set_pwm1(struct device *dev, struct device_attribute *dummy, |
247 | const char *buf, size_t count) | 261 | const char *buf, size_t count) |
248 | { | 262 | { |
249 | struct i2c_client *client = to_i2c_client(dev); | 263 | struct i2c_client *client = to_i2c_client(dev); |
250 | struct lm63_data *data = i2c_get_clientdata(client); | 264 | struct lm63_data *data = i2c_get_clientdata(client); |
251 | unsigned long val; | 265 | unsigned long val; |
252 | int err; | 266 | int err; |
253 | 267 | ||
254 | if (!(data->config_fan & 0x20)) /* register is read-only */ | 268 | if (!(data->config_fan & 0x20)) /* register is read-only */ |
255 | return -EPERM; | 269 | return -EPERM; |
256 | 270 | ||
257 | err = kstrtoul(buf, 10, &val); | 271 | err = kstrtoul(buf, 10, &val); |
258 | if (err) | 272 | if (err) |
259 | return err; | 273 | return err; |
260 | 274 | ||
261 | val = SENSORS_LIMIT(val, 0, 255); | 275 | val = SENSORS_LIMIT(val, 0, 255); |
262 | mutex_lock(&data->update_lock); | 276 | mutex_lock(&data->update_lock); |
263 | data->pwm1_value = data->pwm_highres ? val : | 277 | data->pwm1_value = data->pwm_highres ? val : |
264 | (val * data->pwm1_freq * 2 + 127) / 255; | 278 | (val * data->pwm1_freq * 2 + 127) / 255; |
265 | i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value); | 279 | i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value); |
266 | mutex_unlock(&data->update_lock); | 280 | mutex_unlock(&data->update_lock); |
267 | return count; | 281 | return count; |
268 | } | 282 | } |
269 | 283 | ||
270 | static ssize_t show_pwm1_enable(struct device *dev, | 284 | static ssize_t show_pwm1_enable(struct device *dev, |
271 | struct device_attribute *dummy, char *buf) | 285 | struct device_attribute *dummy, char *buf) |
272 | { | 286 | { |
273 | struct lm63_data *data = lm63_update_device(dev); | 287 | struct lm63_data *data = lm63_update_device(dev); |
274 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); | 288 | return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2); |
275 | } | 289 | } |
276 | 290 | ||
277 | /* | 291 | /* |
278 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. | 292 | * There are 8bit registers for both local(temp1) and remote(temp2) sensor. |
279 | * For remote sensor registers temp2_offset has to be considered, | 293 | * For remote sensor registers temp2_offset has to be considered, |
280 | * for local sensor it must not. | 294 | * for local sensor it must not. |
281 | * So we need separate 8bit accessors for local and remote sensor. | 295 | * So we need separate 8bit accessors for local and remote sensor. |
282 | */ | 296 | */ |
283 | static ssize_t show_local_temp8(struct device *dev, | 297 | static ssize_t show_local_temp8(struct device *dev, |
284 | struct device_attribute *devattr, | 298 | struct device_attribute *devattr, |
285 | char *buf) | 299 | char *buf) |
286 | { | 300 | { |
287 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 301 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
288 | struct lm63_data *data = lm63_update_device(dev); | 302 | struct lm63_data *data = lm63_update_device(dev); |
289 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); | 303 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index])); |
290 | } | 304 | } |
291 | 305 | ||
292 | static ssize_t show_remote_temp8(struct device *dev, | 306 | static ssize_t show_remote_temp8(struct device *dev, |
293 | struct device_attribute *devattr, | 307 | struct device_attribute *devattr, |
294 | char *buf) | 308 | char *buf) |
295 | { | 309 | { |
296 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 310 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
297 | struct lm63_data *data = lm63_update_device(dev); | 311 | struct lm63_data *data = lm63_update_device(dev); |
298 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[attr->index]) | 312 | return sprintf(buf, "%d\n", temp8_from_reg(data, attr->index) |
299 | + data->temp2_offset); | 313 | + data->temp2_offset); |
300 | } | 314 | } |
301 | 315 | ||
302 | static ssize_t set_local_temp8(struct device *dev, | 316 | static ssize_t set_local_temp8(struct device *dev, |
303 | struct device_attribute *dummy, | 317 | struct device_attribute *dummy, |
304 | const char *buf, size_t count) | 318 | const char *buf, size_t count) |
305 | { | 319 | { |
306 | struct i2c_client *client = to_i2c_client(dev); | 320 | struct i2c_client *client = to_i2c_client(dev); |
307 | struct lm63_data *data = i2c_get_clientdata(client); | 321 | struct lm63_data *data = i2c_get_clientdata(client); |
308 | long val; | 322 | long val; |
309 | int err; | 323 | int err; |
310 | 324 | ||
311 | err = kstrtol(buf, 10, &val); | 325 | err = kstrtol(buf, 10, &val); |
312 | if (err) | 326 | if (err) |
313 | return err; | 327 | return err; |
314 | 328 | ||
315 | mutex_lock(&data->update_lock); | 329 | mutex_lock(&data->update_lock); |
316 | data->temp8[1] = TEMP8_TO_REG(val); | 330 | data->temp8[1] = TEMP8_TO_REG(val); |
317 | i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]); | 331 | i2c_smbus_write_byte_data(client, LM63_REG_LOCAL_HIGH, data->temp8[1]); |
318 | mutex_unlock(&data->update_lock); | 332 | mutex_unlock(&data->update_lock); |
319 | return count; | 333 | return count; |
320 | } | 334 | } |
321 | 335 | ||
322 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, | 336 | static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr, |
323 | char *buf) | 337 | char *buf) |
324 | { | 338 | { |
325 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 339 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
326 | struct lm63_data *data = lm63_update_device(dev); | 340 | struct lm63_data *data = lm63_update_device(dev); |
327 | return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->temp11[attr->index]) | 341 | int nr = attr->index; |
328 | + data->temp2_offset); | 342 | int temp; |
343 | |||
344 | if (!nr) { | ||
345 | /* | ||
346 | * Use unsigned temperature unless its value is zero. | ||
347 | * If it is zero, use signed temperature. | ||
348 | */ | ||
349 | if (data->temp11u) | ||
350 | temp = TEMP11_FROM_REG(data->temp11u); | ||
351 | else | ||
352 | temp = TEMP11_FROM_REG(data->temp11[nr]); | ||
353 | } else { | ||
354 | if (data->remote_unsigned && nr == 2) | ||
355 | temp = TEMP11_FROM_REG((u16)data->temp11[nr]); | ||
356 | else | ||
357 | temp = TEMP11_FROM_REG(data->temp11[nr]); | ||
358 | } | ||
359 | return sprintf(buf, "%d\n", temp + data->temp2_offset); | ||
329 | } | 360 | } |
330 | 361 | ||
331 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, | 362 | static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, |
332 | const char *buf, size_t count) | 363 | const char *buf, size_t count) |
333 | { | 364 | { |
334 | static const u8 reg[6] = { | 365 | static const u8 reg[6] = { |
335 | LM63_REG_REMOTE_LOW_MSB, | 366 | LM63_REG_REMOTE_LOW_MSB, |
336 | LM63_REG_REMOTE_LOW_LSB, | 367 | LM63_REG_REMOTE_LOW_LSB, |
337 | LM63_REG_REMOTE_HIGH_MSB, | 368 | LM63_REG_REMOTE_HIGH_MSB, |
338 | LM63_REG_REMOTE_HIGH_LSB, | 369 | LM63_REG_REMOTE_HIGH_LSB, |
339 | LM63_REG_REMOTE_OFFSET_MSB, | 370 | LM63_REG_REMOTE_OFFSET_MSB, |
340 | LM63_REG_REMOTE_OFFSET_LSB, | 371 | LM63_REG_REMOTE_OFFSET_LSB, |
341 | }; | 372 | }; |
342 | 373 | ||
343 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 374 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
344 | struct i2c_client *client = to_i2c_client(dev); | 375 | struct i2c_client *client = to_i2c_client(dev); |
345 | struct lm63_data *data = i2c_get_clientdata(client); | 376 | struct lm63_data *data = i2c_get_clientdata(client); |
346 | long val; | 377 | long val; |
347 | int err; | 378 | int err; |
348 | int nr = attr->index; | 379 | int nr = attr->index; |
349 | 380 | ||
350 | err = kstrtol(buf, 10, &val); | 381 | err = kstrtol(buf, 10, &val); |
351 | if (err) | 382 | if (err) |
352 | return err; | 383 | return err; |
353 | 384 | ||
354 | mutex_lock(&data->update_lock); | 385 | mutex_lock(&data->update_lock); |
355 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); | 386 | if (data->remote_unsigned && nr == 2) |
387 | data->temp11[nr] = TEMP11U_TO_REG(val - data->temp2_offset); | ||
388 | else | ||
389 | data->temp11[nr] = TEMP11_TO_REG(val - data->temp2_offset); | ||
390 | |||
356 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], | 391 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], |
357 | data->temp11[nr] >> 8); | 392 | data->temp11[nr] >> 8); |
358 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], | 393 | i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], |
359 | data->temp11[nr] & 0xff); | 394 | data->temp11[nr] & 0xff); |
360 | mutex_unlock(&data->update_lock); | 395 | mutex_unlock(&data->update_lock); |
361 | return count; | 396 | return count; |
362 | } | 397 | } |
363 | 398 | ||
364 | /* | 399 | /* |
365 | * Hysteresis register holds a relative value, while we want to present | 400 | * Hysteresis register holds a relative value, while we want to present |
366 | * an absolute to user-space | 401 | * an absolute to user-space |
367 | */ | 402 | */ |
368 | static ssize_t show_temp2_crit_hyst(struct device *dev, | 403 | static ssize_t show_temp2_crit_hyst(struct device *dev, |
369 | struct device_attribute *dummy, char *buf) | 404 | struct device_attribute *dummy, char *buf) |
370 | { | 405 | { |
371 | struct lm63_data *data = lm63_update_device(dev); | 406 | struct lm63_data *data = lm63_update_device(dev); |
372 | return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp8[2]) | 407 | return sprintf(buf, "%d\n", temp8_from_reg(data, 2) |
373 | + data->temp2_offset | 408 | + data->temp2_offset |
374 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); | 409 | - TEMP8_FROM_REG(data->temp2_crit_hyst)); |
375 | } | 410 | } |
376 | 411 | ||
377 | /* | 412 | /* |
378 | * And now the other way around, user-space provides an absolute | 413 | * And now the other way around, user-space provides an absolute |
379 | * hysteresis value and we have to store a relative one | 414 | * hysteresis value and we have to store a relative one |
380 | */ | 415 | */ |
381 | static ssize_t set_temp2_crit_hyst(struct device *dev, | 416 | static ssize_t set_temp2_crit_hyst(struct device *dev, |
382 | struct device_attribute *dummy, | 417 | struct device_attribute *dummy, |
383 | const char *buf, size_t count) | 418 | const char *buf, size_t count) |
384 | { | 419 | { |
385 | struct i2c_client *client = to_i2c_client(dev); | 420 | struct i2c_client *client = to_i2c_client(dev); |
386 | struct lm63_data *data = i2c_get_clientdata(client); | 421 | struct lm63_data *data = i2c_get_clientdata(client); |
387 | long val; | 422 | long val; |
388 | int err; | 423 | int err; |
389 | long hyst; | 424 | long hyst; |
390 | 425 | ||
391 | err = kstrtol(buf, 10, &val); | 426 | err = kstrtol(buf, 10, &val); |
392 | if (err) | 427 | if (err) |
393 | return err; | 428 | return err; |
394 | 429 | ||
395 | mutex_lock(&data->update_lock); | 430 | mutex_lock(&data->update_lock); |
396 | hyst = TEMP8_FROM_REG(data->temp8[2]) + data->temp2_offset - val; | 431 | hyst = temp8_from_reg(data, 2) + data->temp2_offset - val; |
397 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, | 432 | i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST, |
398 | HYST_TO_REG(hyst)); | 433 | HYST_TO_REG(hyst)); |
399 | mutex_unlock(&data->update_lock); | 434 | mutex_unlock(&data->update_lock); |
400 | return count; | 435 | return count; |
401 | } | 436 | } |
402 | 437 | ||
403 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, | 438 | static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy, |
404 | char *buf) | 439 | char *buf) |
405 | { | 440 | { |
406 | struct lm63_data *data = lm63_update_device(dev); | 441 | struct lm63_data *data = lm63_update_device(dev); |
407 | return sprintf(buf, "%u\n", data->alarms); | 442 | return sprintf(buf, "%u\n", data->alarms); |
408 | } | 443 | } |
409 | 444 | ||
410 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, | 445 | static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr, |
411 | char *buf) | 446 | char *buf) |
412 | { | 447 | { |
413 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 448 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
414 | struct lm63_data *data = lm63_update_device(dev); | 449 | struct lm63_data *data = lm63_update_device(dev); |
415 | int bitnr = attr->index; | 450 | int bitnr = attr->index; |
416 | 451 | ||
417 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | 452 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
418 | } | 453 | } |
419 | 454 | ||
420 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); | 455 | 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, | 456 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, |
422 | set_fan, 1); | 457 | set_fan, 1); |
423 | 458 | ||
424 | static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1); | 459 | static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1); |
425 | static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); | 460 | static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL); |
426 | 461 | ||
427 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_local_temp8, NULL, 0); | 462 | 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, | 463 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_local_temp8, |
429 | set_local_temp8, 1); | 464 | set_local_temp8, 1); |
430 | 465 | ||
431 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); | 466 | 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, | 467 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, |
433 | set_temp11, 1); | 468 | set_temp11, 1); |
434 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, | 469 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, |
435 | set_temp11, 2); | 470 | set_temp11, 2); |
436 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, | 471 | static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, |
437 | set_temp11, 3); | 472 | set_temp11, 3); |
438 | /* | 473 | /* |
439 | * On LM63, temp2_crit can be set only once, which should be job | 474 | * On LM63, temp2_crit can be set only once, which should be job |
440 | * of the bootloader. | 475 | * of the bootloader. |
441 | */ | 476 | */ |
442 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, | 477 | static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_remote_temp8, |
443 | NULL, 2); | 478 | NULL, 2); |
444 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, | 479 | static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, |
445 | set_temp2_crit_hyst); | 480 | set_temp2_crit_hyst); |
446 | 481 | ||
447 | /* Individual alarm files */ | 482 | /* Individual alarm files */ |
448 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); | 483 | 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); | 484 | 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); | 485 | 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); | 486 | 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); | 487 | 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); | 488 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
454 | /* Raw alarm file for compatibility */ | 489 | /* Raw alarm file for compatibility */ |
455 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 490 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
456 | 491 | ||
457 | static struct attribute *lm63_attributes[] = { | 492 | static struct attribute *lm63_attributes[] = { |
458 | &dev_attr_pwm1.attr, | 493 | &dev_attr_pwm1.attr, |
459 | &dev_attr_pwm1_enable.attr, | 494 | &dev_attr_pwm1_enable.attr, |
460 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 495 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
461 | &sensor_dev_attr_temp2_input.dev_attr.attr, | 496 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
462 | &sensor_dev_attr_temp2_min.dev_attr.attr, | 497 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
463 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 498 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
464 | &sensor_dev_attr_temp2_max.dev_attr.attr, | 499 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
465 | &sensor_dev_attr_temp2_offset.dev_attr.attr, | 500 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
466 | &sensor_dev_attr_temp2_crit.dev_attr.attr, | 501 | &sensor_dev_attr_temp2_crit.dev_attr.attr, |
467 | &dev_attr_temp2_crit_hyst.attr, | 502 | &dev_attr_temp2_crit_hyst.attr, |
468 | 503 | ||
469 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | 504 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
470 | &sensor_dev_attr_temp2_fault.dev_attr.attr, | 505 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
471 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, | 506 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
472 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 507 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
473 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 508 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
474 | &dev_attr_alarms.attr, | 509 | &dev_attr_alarms.attr, |
475 | NULL | 510 | NULL |
476 | }; | 511 | }; |
477 | 512 | ||
478 | static const struct attribute_group lm63_group = { | 513 | static const struct attribute_group lm63_group = { |
479 | .attrs = lm63_attributes, | 514 | .attrs = lm63_attributes, |
480 | }; | 515 | }; |
481 | 516 | ||
482 | static struct attribute *lm63_attributes_fan1[] = { | 517 | static struct attribute *lm63_attributes_fan1[] = { |
483 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 518 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
484 | &sensor_dev_attr_fan1_min.dev_attr.attr, | 519 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
485 | 520 | ||
486 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, | 521 | &sensor_dev_attr_fan1_min_alarm.dev_attr.attr, |
487 | NULL | 522 | NULL |
488 | }; | 523 | }; |
489 | 524 | ||
490 | static const struct attribute_group lm63_group_fan1 = { | 525 | static const struct attribute_group lm63_group_fan1 = { |
491 | .attrs = lm63_attributes_fan1, | 526 | .attrs = lm63_attributes_fan1, |
492 | }; | 527 | }; |
493 | 528 | ||
494 | /* | 529 | /* |
495 | * Real code | 530 | * Real code |
496 | */ | 531 | */ |
497 | 532 | ||
498 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 533 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
499 | static int lm63_detect(struct i2c_client *new_client, | 534 | static int lm63_detect(struct i2c_client *new_client, |
500 | struct i2c_board_info *info) | 535 | struct i2c_board_info *info) |
501 | { | 536 | { |
502 | struct i2c_adapter *adapter = new_client->adapter; | 537 | struct i2c_adapter *adapter = new_client->adapter; |
503 | u8 man_id, chip_id, reg_config1, reg_config2; | 538 | u8 man_id, chip_id, reg_config1, reg_config2; |
504 | u8 reg_alert_status, reg_alert_mask; | 539 | u8 reg_alert_status, reg_alert_mask; |
505 | int address = new_client->addr; | 540 | int address = new_client->addr; |
506 | 541 | ||
507 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 542 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
508 | return -ENODEV; | 543 | return -ENODEV; |
509 | 544 | ||
510 | man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID); | 545 | 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); | 546 | chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID); |
512 | 547 | ||
513 | reg_config1 = i2c_smbus_read_byte_data(new_client, | 548 | reg_config1 = i2c_smbus_read_byte_data(new_client, |
514 | LM63_REG_CONFIG1); | 549 | LM63_REG_CONFIG1); |
515 | reg_config2 = i2c_smbus_read_byte_data(new_client, | 550 | reg_config2 = i2c_smbus_read_byte_data(new_client, |
516 | LM63_REG_CONFIG2); | 551 | LM63_REG_CONFIG2); |
517 | reg_alert_status = i2c_smbus_read_byte_data(new_client, | 552 | reg_alert_status = i2c_smbus_read_byte_data(new_client, |
518 | LM63_REG_ALERT_STATUS); | 553 | LM63_REG_ALERT_STATUS); |
519 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, | 554 | reg_alert_mask = i2c_smbus_read_byte_data(new_client, |
520 | LM63_REG_ALERT_MASK); | 555 | LM63_REG_ALERT_MASK); |
521 | 556 | ||
522 | if (man_id != 0x01 /* National Semiconductor */ | 557 | if (man_id != 0x01 /* National Semiconductor */ |
523 | || (reg_config1 & 0x18) != 0x00 | 558 | || (reg_config1 & 0x18) != 0x00 |
524 | || (reg_config2 & 0xF8) != 0x00 | 559 | || (reg_config2 & 0xF8) != 0x00 |
525 | || (reg_alert_status & 0x20) != 0x00 | 560 | || (reg_alert_status & 0x20) != 0x00 |
526 | || (reg_alert_mask & 0xA4) != 0xA4) { | 561 | || (reg_alert_mask & 0xA4) != 0xA4) { |
527 | dev_dbg(&adapter->dev, | 562 | dev_dbg(&adapter->dev, |
528 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", | 563 | "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n", |
529 | man_id, chip_id); | 564 | man_id, chip_id); |
530 | return -ENODEV; | 565 | return -ENODEV; |
531 | } | 566 | } |
532 | 567 | ||
533 | if (chip_id == 0x41 && address == 0x4c) | 568 | if (chip_id == 0x41 && address == 0x4c) |
534 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); | 569 | strlcpy(info->type, "lm63", I2C_NAME_SIZE); |
535 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) | 570 | else if (chip_id == 0x51 && (address == 0x18 || address == 0x4e)) |
536 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); | 571 | strlcpy(info->type, "lm64", I2C_NAME_SIZE); |
537 | else if (chip_id == 0x49 && address == 0x4c) | 572 | else if (chip_id == 0x49 && address == 0x4c) |
538 | strlcpy(info->type, "lm96163", I2C_NAME_SIZE); | 573 | strlcpy(info->type, "lm96163", I2C_NAME_SIZE); |
539 | else | 574 | else |
540 | return -ENODEV; | 575 | return -ENODEV; |
541 | 576 | ||
542 | return 0; | 577 | return 0; |
543 | } | 578 | } |
544 | 579 | ||
545 | static int lm63_probe(struct i2c_client *new_client, | 580 | static int lm63_probe(struct i2c_client *new_client, |
546 | const struct i2c_device_id *id) | 581 | const struct i2c_device_id *id) |
547 | { | 582 | { |
548 | struct lm63_data *data; | 583 | struct lm63_data *data; |
549 | int err; | 584 | int err; |
550 | 585 | ||
551 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); | 586 | data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL); |
552 | if (!data) { | 587 | if (!data) { |
553 | err = -ENOMEM; | 588 | err = -ENOMEM; |
554 | goto exit; | 589 | goto exit; |
555 | } | 590 | } |
556 | 591 | ||
557 | i2c_set_clientdata(new_client, data); | 592 | i2c_set_clientdata(new_client, data); |
558 | data->valid = 0; | 593 | data->valid = 0; |
559 | mutex_init(&data->update_lock); | 594 | mutex_init(&data->update_lock); |
560 | 595 | ||
561 | /* Set the device type */ | 596 | /* Set the device type */ |
562 | data->kind = id->driver_data; | 597 | data->kind = id->driver_data; |
563 | if (data->kind == lm64) | 598 | if (data->kind == lm64) |
564 | data->temp2_offset = 16000; | 599 | data->temp2_offset = 16000; |
565 | 600 | ||
566 | /* Initialize chip */ | 601 | /* Initialize chip */ |
567 | lm63_init_client(new_client); | 602 | lm63_init_client(new_client); |
568 | 603 | ||
569 | /* Register sysfs hooks */ | 604 | /* Register sysfs hooks */ |
570 | err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); | 605 | err = sysfs_create_group(&new_client->dev.kobj, &lm63_group); |
571 | if (err) | 606 | if (err) |
572 | goto exit_free; | 607 | goto exit_free; |
573 | if (data->config & 0x04) { /* tachometer enabled */ | 608 | if (data->config & 0x04) { /* tachometer enabled */ |
574 | err = sysfs_create_group(&new_client->dev.kobj, | 609 | err = sysfs_create_group(&new_client->dev.kobj, |
575 | &lm63_group_fan1); | 610 | &lm63_group_fan1); |
576 | if (err) | 611 | if (err) |
577 | goto exit_remove_files; | 612 | goto exit_remove_files; |
578 | } | 613 | } |
579 | 614 | ||
580 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 615 | data->hwmon_dev = hwmon_device_register(&new_client->dev); |
581 | if (IS_ERR(data->hwmon_dev)) { | 616 | if (IS_ERR(data->hwmon_dev)) { |
582 | err = PTR_ERR(data->hwmon_dev); | 617 | err = PTR_ERR(data->hwmon_dev); |
583 | goto exit_remove_files; | 618 | goto exit_remove_files; |
584 | } | 619 | } |
585 | 620 | ||
586 | return 0; | 621 | return 0; |
587 | 622 | ||
588 | exit_remove_files: | 623 | exit_remove_files: |
589 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); | 624 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group); |
590 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); | 625 | sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1); |
591 | exit_free: | 626 | exit_free: |
592 | kfree(data); | 627 | kfree(data); |
593 | exit: | 628 | exit: |
594 | return err; | 629 | return err; |
595 | } | 630 | } |
596 | 631 | ||
597 | /* | 632 | /* |
598 | * Ideally we shouldn't have to initialize anything, since the BIOS | 633 | * Ideally we shouldn't have to initialize anything, since the BIOS |
599 | * should have taken care of everything | 634 | * should have taken care of everything |
600 | */ | 635 | */ |
601 | static void lm63_init_client(struct i2c_client *client) | 636 | static void lm63_init_client(struct i2c_client *client) |
602 | { | 637 | { |
603 | struct lm63_data *data = i2c_get_clientdata(client); | 638 | struct lm63_data *data = i2c_get_clientdata(client); |
604 | 639 | ||
605 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); | 640 | data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1); |
606 | data->config_fan = i2c_smbus_read_byte_data(client, | 641 | data->config_fan = i2c_smbus_read_byte_data(client, |
607 | LM63_REG_CONFIG_FAN); | 642 | LM63_REG_CONFIG_FAN); |
608 | 643 | ||
609 | /* Start converting if needed */ | 644 | /* Start converting if needed */ |
610 | if (data->config & 0x40) { /* standby */ | 645 | if (data->config & 0x40) { /* standby */ |
611 | dev_dbg(&client->dev, "Switching to operational mode\n"); | 646 | dev_dbg(&client->dev, "Switching to operational mode\n"); |
612 | data->config &= 0xA7; | 647 | data->config &= 0xA7; |
613 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, | 648 | i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1, |
614 | data->config); | 649 | data->config); |
615 | } | 650 | } |
616 | 651 | ||
617 | /* We may need pwm1_freq before ever updating the client data */ | 652 | /* 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); | 653 | data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ); |
619 | if (data->pwm1_freq == 0) | 654 | if (data->pwm1_freq == 0) |
620 | data->pwm1_freq = 1; | 655 | data->pwm1_freq = 1; |
621 | 656 | ||
622 | /* | 657 | /* |
623 | * For LM96163, check if high resolution PWM is enabled. | 658 | * For LM96163, check if high resolution PWM |
624 | * Also, check if unsigned temperature format is enabled | 659 | * and unsigned temperature format is enabled. |
625 | * and display a warning message if it is. | ||
626 | */ | 660 | */ |
627 | if (data->kind == lm96163) { | 661 | if (data->kind == lm96163) { |
628 | u8 config_enhanced | 662 | u8 config_enhanced |
629 | = i2c_smbus_read_byte_data(client, | 663 | = i2c_smbus_read_byte_data(client, |
630 | LM96163_REG_CONFIG_ENHANCED); | 664 | LM96163_REG_CONFIG_ENHANCED); |
631 | if ((config_enhanced & 0x10) | 665 | if ((config_enhanced & 0x10) |
632 | && !(data->config_fan & 0x08) && data->pwm1_freq == 8) | 666 | && !(data->config_fan & 0x08) && data->pwm1_freq == 8) |
633 | data->pwm_highres = true; | 667 | data->pwm_highres = true; |
634 | if (config_enhanced & 0x08) | 668 | if (config_enhanced & 0x08) |
635 | dev_warn(&client->dev, | 669 | data->remote_unsigned = true; |
636 | "Unsigned format for High and Crit setpoints enabled but not supported by driver\n"); | ||
637 | } | 670 | } |
638 | 671 | ||
639 | /* Show some debug info about the LM63 configuration */ | 672 | /* Show some debug info about the LM63 configuration */ |
640 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", | 673 | dev_dbg(&client->dev, "Alert/tach pin configured for %s\n", |
641 | (data->config & 0x04) ? "tachometer input" : | 674 | (data->config & 0x04) ? "tachometer input" : |
642 | "alert output"); | 675 | "alert output"); |
643 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", | 676 | dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n", |
644 | (data->config_fan & 0x08) ? "1.4" : "360", | 677 | (data->config_fan & 0x08) ? "1.4" : "360", |
645 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); | 678 | ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq); |
646 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", | 679 | dev_dbg(&client->dev, "PWM output active %s, %s mode\n", |
647 | (data->config_fan & 0x10) ? "low" : "high", | 680 | (data->config_fan & 0x10) ? "low" : "high", |
648 | (data->config_fan & 0x20) ? "manual" : "auto"); | 681 | (data->config_fan & 0x20) ? "manual" : "auto"); |
649 | } | 682 | } |
650 | 683 | ||
651 | static int lm63_remove(struct i2c_client *client) | 684 | static int lm63_remove(struct i2c_client *client) |
652 | { | 685 | { |
653 | struct lm63_data *data = i2c_get_clientdata(client); | 686 | struct lm63_data *data = i2c_get_clientdata(client); |
654 | 687 | ||
655 | hwmon_device_unregister(data->hwmon_dev); | 688 | hwmon_device_unregister(data->hwmon_dev); |
656 | sysfs_remove_group(&client->dev.kobj, &lm63_group); | 689 | sysfs_remove_group(&client->dev.kobj, &lm63_group); |
657 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); | 690 | sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1); |
658 | 691 | ||
659 | kfree(data); | 692 | kfree(data); |
660 | return 0; | 693 | return 0; |
661 | } | 694 | } |
662 | 695 | ||
663 | static struct lm63_data *lm63_update_device(struct device *dev) | 696 | static struct lm63_data *lm63_update_device(struct device *dev) |
664 | { | 697 | { |
665 | struct i2c_client *client = to_i2c_client(dev); | 698 | struct i2c_client *client = to_i2c_client(dev); |
666 | struct lm63_data *data = i2c_get_clientdata(client); | 699 | struct lm63_data *data = i2c_get_clientdata(client); |
667 | 700 | ||
668 | mutex_lock(&data->update_lock); | 701 | mutex_lock(&data->update_lock); |
669 | 702 | ||
670 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 703 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
671 | if (data->config & 0x04) { /* tachometer enabled */ | 704 | if (data->config & 0x04) { /* tachometer enabled */ |
672 | /* order matters for fan1_input */ | 705 | /* order matters for fan1_input */ |
673 | data->fan[0] = i2c_smbus_read_byte_data(client, | 706 | data->fan[0] = i2c_smbus_read_byte_data(client, |
674 | LM63_REG_TACH_COUNT_LSB) & 0xFC; | 707 | LM63_REG_TACH_COUNT_LSB) & 0xFC; |
675 | data->fan[0] |= i2c_smbus_read_byte_data(client, | 708 | data->fan[0] |= i2c_smbus_read_byte_data(client, |
676 | LM63_REG_TACH_COUNT_MSB) << 8; | 709 | LM63_REG_TACH_COUNT_MSB) << 8; |
677 | data->fan[1] = (i2c_smbus_read_byte_data(client, | 710 | data->fan[1] = (i2c_smbus_read_byte_data(client, |
678 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) | 711 | LM63_REG_TACH_LIMIT_LSB) & 0xFC) |
679 | | (i2c_smbus_read_byte_data(client, | 712 | | (i2c_smbus_read_byte_data(client, |
680 | LM63_REG_TACH_LIMIT_MSB) << 8); | 713 | LM63_REG_TACH_LIMIT_MSB) << 8); |
681 | } | 714 | } |
682 | 715 | ||
683 | data->pwm1_freq = i2c_smbus_read_byte_data(client, | 716 | data->pwm1_freq = i2c_smbus_read_byte_data(client, |
684 | LM63_REG_PWM_FREQ); | 717 | LM63_REG_PWM_FREQ); |
685 | if (data->pwm1_freq == 0) | 718 | if (data->pwm1_freq == 0) |
686 | data->pwm1_freq = 1; | 719 | data->pwm1_freq = 1; |
687 | data->pwm1_value = i2c_smbus_read_byte_data(client, | 720 | data->pwm1_value = i2c_smbus_read_byte_data(client, |
688 | LM63_REG_PWM_VALUE); | 721 | LM63_REG_PWM_VALUE); |
689 | 722 | ||
690 | data->temp8[0] = i2c_smbus_read_byte_data(client, | 723 | data->temp8[0] = i2c_smbus_read_byte_data(client, |
691 | LM63_REG_LOCAL_TEMP); | 724 | LM63_REG_LOCAL_TEMP); |
692 | data->temp8[1] = i2c_smbus_read_byte_data(client, | 725 | data->temp8[1] = i2c_smbus_read_byte_data(client, |
693 | LM63_REG_LOCAL_HIGH); | 726 | LM63_REG_LOCAL_HIGH); |
694 | 727 | ||
695 | /* order matters for temp2_input */ | 728 | /* order matters for temp2_input */ |
696 | data->temp11[0] = i2c_smbus_read_byte_data(client, | 729 | data->temp11[0] = i2c_smbus_read_byte_data(client, |
697 | LM63_REG_REMOTE_TEMP_MSB) << 8; | 730 | LM63_REG_REMOTE_TEMP_MSB) << 8; |
698 | data->temp11[0] |= i2c_smbus_read_byte_data(client, | 731 | data->temp11[0] |= i2c_smbus_read_byte_data(client, |
699 | LM63_REG_REMOTE_TEMP_LSB); | 732 | LM63_REG_REMOTE_TEMP_LSB); |
700 | data->temp11[1] = (i2c_smbus_read_byte_data(client, | 733 | data->temp11[1] = (i2c_smbus_read_byte_data(client, |
701 | LM63_REG_REMOTE_LOW_MSB) << 8) | 734 | LM63_REG_REMOTE_LOW_MSB) << 8) |
702 | | i2c_smbus_read_byte_data(client, | 735 | | i2c_smbus_read_byte_data(client, |
703 | LM63_REG_REMOTE_LOW_LSB); | 736 | LM63_REG_REMOTE_LOW_LSB); |
704 | data->temp11[2] = (i2c_smbus_read_byte_data(client, | 737 | data->temp11[2] = (i2c_smbus_read_byte_data(client, |
705 | LM63_REG_REMOTE_HIGH_MSB) << 8) | 738 | LM63_REG_REMOTE_HIGH_MSB) << 8) |
706 | | i2c_smbus_read_byte_data(client, | 739 | | i2c_smbus_read_byte_data(client, |
707 | LM63_REG_REMOTE_HIGH_LSB); | 740 | LM63_REG_REMOTE_HIGH_LSB); |
708 | data->temp11[3] = (i2c_smbus_read_byte_data(client, | 741 | data->temp11[3] = (i2c_smbus_read_byte_data(client, |
709 | LM63_REG_REMOTE_OFFSET_MSB) << 8) | 742 | LM63_REG_REMOTE_OFFSET_MSB) << 8) |
710 | | i2c_smbus_read_byte_data(client, | 743 | | i2c_smbus_read_byte_data(client, |
711 | LM63_REG_REMOTE_OFFSET_LSB); | 744 | LM63_REG_REMOTE_OFFSET_LSB); |
745 | |||
746 | if (data->kind == lm96163) | ||
747 | data->temp11u = (i2c_smbus_read_byte_data(client, | ||
748 | LM96163_REG_REMOTE_TEMP_U_MSB) << 8) | ||
749 | | i2c_smbus_read_byte_data(client, | ||
750 | LM96163_REG_REMOTE_TEMP_U_LSB); | ||
751 | |||
712 | data->temp8[2] = i2c_smbus_read_byte_data(client, | 752 | data->temp8[2] = i2c_smbus_read_byte_data(client, |
713 | LM63_REG_REMOTE_TCRIT); | 753 | LM63_REG_REMOTE_TCRIT); |
714 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, | 754 | data->temp2_crit_hyst = i2c_smbus_read_byte_data(client, |
715 | LM63_REG_REMOTE_TCRIT_HYST); | 755 | LM63_REG_REMOTE_TCRIT_HYST); |
716 | 756 | ||
717 | data->alarms = i2c_smbus_read_byte_data(client, | 757 | data->alarms = i2c_smbus_read_byte_data(client, |
718 | LM63_REG_ALERT_STATUS) & 0x7F; | 758 | LM63_REG_ALERT_STATUS) & 0x7F; |
719 | 759 | ||
720 | data->last_updated = jiffies; | 760 | data->last_updated = jiffies; |
721 | data->valid = 1; | 761 | data->valid = 1; |
722 | } | 762 | } |
723 | 763 | ||
724 | mutex_unlock(&data->update_lock); | 764 | mutex_unlock(&data->update_lock); |
725 | 765 | ||
726 | return data; | 766 | return data; |
727 | } | 767 | } |
728 | 768 | ||
729 | static int __init sensors_lm63_init(void) | 769 | static int __init sensors_lm63_init(void) |
730 | { | 770 | { |
731 | return i2c_add_driver(&lm63_driver); | 771 | return i2c_add_driver(&lm63_driver); |
732 | } | 772 | } |
733 | 773 | ||
734 | static void __exit sensors_lm63_exit(void) | 774 | static void __exit sensors_lm63_exit(void) |
735 | { | 775 | { |
736 | i2c_del_driver(&lm63_driver); | 776 | i2c_del_driver(&lm63_driver); |
737 | } | 777 | } |
738 | 778 | ||
739 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 779 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
740 | MODULE_DESCRIPTION("LM63 driver"); | 780 | MODULE_DESCRIPTION("LM63 driver"); |
741 | MODULE_LICENSE("GPL"); | 781 | MODULE_LICENSE("GPL"); |
742 | 782 | ||
743 | module_init(sensors_lm63_init); | 783 | module_init(sensors_lm63_init); |