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