]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
43da3d12 GR |
2 | * gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring | |
4 | * Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>, | |
5 | * Kyösti Mälkki <kmalkki@cc.hut.fi> | |
6 | * Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | * | |
22 | */ | |
1da177e4 LT |
23 | |
24 | #include <linux/module.h> | |
25 | #include <linux/init.h> | |
26 | #include <linux/slab.h> | |
0cacdf29 | 27 | #include <linux/jiffies.h> |
1da177e4 | 28 | #include <linux/i2c.h> |
943b0830 | 29 | #include <linux/hwmon.h> |
86d47f12 | 30 | #include <linux/hwmon-sysfs.h> |
303760b4 | 31 | #include <linux/hwmon-vid.h> |
943b0830 | 32 | #include <linux/err.h> |
9a61bf63 | 33 | #include <linux/mutex.h> |
87808be4 | 34 | #include <linux/sysfs.h> |
1da177e4 LT |
35 | |
36 | /* Type of the extra sensor */ | |
37 | static unsigned short extra_sensor_type; | |
38 | module_param(extra_sensor_type, ushort, 0); | |
39 | MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=temperature, 2=voltage)"); | |
40 | ||
41 | /* Addresses to scan */ | |
25e9c86d | 42 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; |
1da177e4 | 43 | |
43da3d12 GR |
44 | /* |
45 | * Many GL520 constants specified below | |
46 | * One of the inputs can be configured as either temp or voltage. | |
47 | * That's why _TEMP2 and _IN4 access the same register | |
48 | */ | |
1da177e4 LT |
49 | |
50 | /* The GL520 registers */ | |
51 | #define GL520_REG_CHIP_ID 0x00 | |
52 | #define GL520_REG_REVISION 0x01 | |
53 | #define GL520_REG_CONF 0x03 | |
54 | #define GL520_REG_MASK 0x11 | |
55 | ||
56 | #define GL520_REG_VID_INPUT 0x02 | |
57 | ||
8b4b0ab4 JD |
58 | static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e }; |
59 | static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b }; | |
60 | static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 }; | |
61 | static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 }; | |
62 | ||
63 | static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e }; | |
64 | static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 }; | |
65 | static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 }; | |
1da177e4 LT |
66 | |
67 | #define GL520_REG_FAN_INPUT 0x07 | |
68 | #define GL520_REG_FAN_MIN 0x08 | |
69 | #define GL520_REG_FAN_DIV 0x0f | |
70 | #define GL520_REG_FAN_OFF GL520_REG_FAN_DIV | |
71 | ||
72 | #define GL520_REG_ALARMS 0x12 | |
73 | #define GL520_REG_BEEP_MASK 0x10 | |
74 | #define GL520_REG_BEEP_ENABLE GL520_REG_CONF | |
75 | ||
1da177e4 LT |
76 | /* Client data */ |
77 | struct gl520_data { | |
d1b9c3f5 AL |
78 | struct i2c_client *client; |
79 | const struct attribute_group *groups[3]; | |
9a61bf63 | 80 | struct mutex update_lock; |
1da177e4 LT |
81 | char valid; /* zero until the following fields are valid */ |
82 | unsigned long last_updated; /* in jiffies */ | |
83 | ||
84 | u8 vid; | |
85 | u8 vrm; | |
86 | u8 in_input[5]; /* [0] = VVD */ | |
87 | u8 in_min[5]; /* [0] = VDD */ | |
88 | u8 in_max[5]; /* [0] = VDD */ | |
89 | u8 fan_input[2]; | |
90 | u8 fan_min[2]; | |
91 | u8 fan_div[2]; | |
92 | u8 fan_off; | |
93 | u8 temp_input[2]; | |
94 | u8 temp_max[2]; | |
95 | u8 temp_max_hyst[2]; | |
96 | u8 alarms; | |
97 | u8 beep_enable; | |
98 | u8 beep_mask; | |
99 | u8 alarm_mask; | |
100 | u8 two_temps; | |
101 | }; | |
102 | ||
df51f2d7 AL |
103 | /* |
104 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized | |
105 | * GL520 uses a high-byte first convention | |
106 | */ | |
107 | static int gl520_read_value(struct i2c_client *client, u8 reg) | |
108 | { | |
109 | if ((reg >= 0x07) && (reg <= 0x0c)) | |
110 | return i2c_smbus_read_word_swapped(client, reg); | |
111 | else | |
112 | return i2c_smbus_read_byte_data(client, reg); | |
113 | } | |
114 | ||
115 | static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) | |
116 | { | |
117 | if ((reg >= 0x07) && (reg <= 0x0c)) | |
118 | return i2c_smbus_write_word_swapped(client, reg, value); | |
119 | else | |
120 | return i2c_smbus_write_byte_data(client, reg, value); | |
121 | } | |
122 | ||
123 | static struct gl520_data *gl520_update_device(struct device *dev) | |
124 | { | |
d1b9c3f5 AL |
125 | struct gl520_data *data = dev_get_drvdata(dev); |
126 | struct i2c_client *client = data->client; | |
df51f2d7 AL |
127 | int val, i; |
128 | ||
129 | mutex_lock(&data->update_lock); | |
130 | ||
131 | if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { | |
132 | ||
133 | dev_dbg(&client->dev, "Starting gl520sm update\n"); | |
134 | ||
135 | data->alarms = gl520_read_value(client, GL520_REG_ALARMS); | |
136 | data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); | |
137 | data->vid = gl520_read_value(client, | |
138 | GL520_REG_VID_INPUT) & 0x1f; | |
139 | ||
140 | for (i = 0; i < 4; i++) { | |
141 | data->in_input[i] = gl520_read_value(client, | |
142 | GL520_REG_IN_INPUT[i]); | |
143 | val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]); | |
144 | data->in_min[i] = val & 0xff; | |
145 | data->in_max[i] = (val >> 8) & 0xff; | |
146 | } | |
147 | ||
148 | val = gl520_read_value(client, GL520_REG_FAN_INPUT); | |
149 | data->fan_input[0] = (val >> 8) & 0xff; | |
150 | data->fan_input[1] = val & 0xff; | |
151 | ||
152 | val = gl520_read_value(client, GL520_REG_FAN_MIN); | |
153 | data->fan_min[0] = (val >> 8) & 0xff; | |
154 | data->fan_min[1] = val & 0xff; | |
155 | ||
156 | data->temp_input[0] = gl520_read_value(client, | |
157 | GL520_REG_TEMP_INPUT[0]); | |
158 | data->temp_max[0] = gl520_read_value(client, | |
159 | GL520_REG_TEMP_MAX[0]); | |
160 | data->temp_max_hyst[0] = gl520_read_value(client, | |
161 | GL520_REG_TEMP_MAX_HYST[0]); | |
162 | ||
163 | val = gl520_read_value(client, GL520_REG_FAN_DIV); | |
164 | data->fan_div[0] = (val >> 6) & 0x03; | |
165 | data->fan_div[1] = (val >> 4) & 0x03; | |
166 | data->fan_off = (val >> 2) & 0x01; | |
167 | ||
168 | data->alarms &= data->alarm_mask; | |
169 | ||
170 | val = gl520_read_value(client, GL520_REG_CONF); | |
171 | data->beep_enable = !((val >> 2) & 1); | |
172 | ||
173 | /* Temp1 and Vin4 are the same input */ | |
174 | if (data->two_temps) { | |
175 | data->temp_input[1] = gl520_read_value(client, | |
176 | GL520_REG_TEMP_INPUT[1]); | |
177 | data->temp_max[1] = gl520_read_value(client, | |
178 | GL520_REG_TEMP_MAX[1]); | |
179 | data->temp_max_hyst[1] = gl520_read_value(client, | |
180 | GL520_REG_TEMP_MAX_HYST[1]); | |
181 | } else { | |
182 | data->in_input[4] = gl520_read_value(client, | |
183 | GL520_REG_IN_INPUT[4]); | |
184 | data->in_min[4] = gl520_read_value(client, | |
185 | GL520_REG_IN_MIN[4]); | |
186 | data->in_max[4] = gl520_read_value(client, | |
187 | GL520_REG_IN_MAX[4]); | |
188 | } | |
189 | ||
190 | data->last_updated = jiffies; | |
191 | data->valid = 1; | |
192 | } | |
193 | ||
194 | mutex_unlock(&data->update_lock); | |
195 | ||
196 | return data; | |
197 | } | |
198 | ||
1da177e4 LT |
199 | /* |
200 | * Sysfs stuff | |
201 | */ | |
202 | ||
2579b7ff JL |
203 | static ssize_t cpu0_vid_show(struct device *dev, |
204 | struct device_attribute *attr, char *buf) | |
1da177e4 | 205 | { |
86d47f12 | 206 | struct gl520_data *data = gl520_update_device(dev); |
1da177e4 LT |
207 | return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); |
208 | } | |
2579b7ff | 209 | static DEVICE_ATTR_RO(cpu0_vid); |
1da177e4 | 210 | |
87cdfa9d GR |
211 | #define VDD_FROM_REG(val) DIV_ROUND_CLOSEST((val) * 95, 4) |
212 | #define VDD_CLAMP(val) clamp_val(val, 0, 255 * 95 / 4) | |
213 | #define VDD_TO_REG(val) DIV_ROUND_CLOSEST(VDD_CLAMP(val) * 4, 95) | |
1da177e4 | 214 | |
87cdfa9d GR |
215 | #define IN_FROM_REG(val) ((val) * 19) |
216 | #define IN_CLAMP(val) clamp_val(val, 0, 255 * 19) | |
217 | #define IN_TO_REG(val) DIV_ROUND_CLOSEST(IN_CLAMP(val), 19) | |
1da177e4 | 218 | |
17de1a88 GR |
219 | static ssize_t in_input_show(struct device *dev, |
220 | struct device_attribute *attr, char *buf) | |
1da177e4 | 221 | { |
86d47f12 JD |
222 | int n = to_sensor_dev_attr(attr)->index; |
223 | struct gl520_data *data = gl520_update_device(dev); | |
1da177e4 LT |
224 | u8 r = data->in_input[n]; |
225 | ||
226 | if (n == 0) | |
227 | return sprintf(buf, "%d\n", VDD_FROM_REG(r)); | |
228 | else | |
229 | return sprintf(buf, "%d\n", IN_FROM_REG(r)); | |
230 | } | |
231 | ||
17de1a88 GR |
232 | static ssize_t in_min_show(struct device *dev, struct device_attribute *attr, |
233 | char *buf) | |
1da177e4 | 234 | { |
86d47f12 JD |
235 | int n = to_sensor_dev_attr(attr)->index; |
236 | struct gl520_data *data = gl520_update_device(dev); | |
1da177e4 LT |
237 | u8 r = data->in_min[n]; |
238 | ||
239 | if (n == 0) | |
240 | return sprintf(buf, "%d\n", VDD_FROM_REG(r)); | |
241 | else | |
242 | return sprintf(buf, "%d\n", IN_FROM_REG(r)); | |
243 | } | |
244 | ||
17de1a88 GR |
245 | static ssize_t in_max_show(struct device *dev, struct device_attribute *attr, |
246 | char *buf) | |
1da177e4 | 247 | { |
86d47f12 JD |
248 | int n = to_sensor_dev_attr(attr)->index; |
249 | struct gl520_data *data = gl520_update_device(dev); | |
1da177e4 LT |
250 | u8 r = data->in_max[n]; |
251 | ||
252 | if (n == 0) | |
253 | return sprintf(buf, "%d\n", VDD_FROM_REG(r)); | |
254 | else | |
255 | return sprintf(buf, "%d\n", IN_FROM_REG(r)); | |
256 | } | |
257 | ||
17de1a88 GR |
258 | static ssize_t in_min_store(struct device *dev, struct device_attribute *attr, |
259 | const char *buf, size_t count) | |
1da177e4 | 260 | { |
d1b9c3f5 AL |
261 | struct gl520_data *data = dev_get_drvdata(dev); |
262 | struct i2c_client *client = data->client; | |
86d47f12 | 263 | int n = to_sensor_dev_attr(attr)->index; |
1da177e4 | 264 | u8 r; |
43da3d12 GR |
265 | long v; |
266 | int err; | |
267 | ||
268 | err = kstrtol(buf, 10, &v); | |
269 | if (err) | |
270 | return err; | |
1da177e4 | 271 | |
9a61bf63 | 272 | mutex_lock(&data->update_lock); |
1da177e4 LT |
273 | |
274 | if (n == 0) | |
275 | r = VDD_TO_REG(v); | |
276 | else | |
277 | r = IN_TO_REG(v); | |
278 | ||
279 | data->in_min[n] = r; | |
280 | ||
281 | if (n < 4) | |
86d47f12 JD |
282 | gl520_write_value(client, GL520_REG_IN_MIN[n], |
283 | (gl520_read_value(client, GL520_REG_IN_MIN[n]) | |
284 | & ~0xff) | r); | |
1da177e4 | 285 | else |
86d47f12 | 286 | gl520_write_value(client, GL520_REG_IN_MIN[n], r); |
1da177e4 | 287 | |
9a61bf63 | 288 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
289 | return count; |
290 | } | |
291 | ||
17de1a88 GR |
292 | static ssize_t in_max_store(struct device *dev, struct device_attribute *attr, |
293 | const char *buf, size_t count) | |
1da177e4 | 294 | { |
d1b9c3f5 AL |
295 | struct gl520_data *data = dev_get_drvdata(dev); |
296 | struct i2c_client *client = data->client; | |
86d47f12 | 297 | int n = to_sensor_dev_attr(attr)->index; |
1da177e4 | 298 | u8 r; |
43da3d12 GR |
299 | long v; |
300 | int err; | |
301 | ||
302 | err = kstrtol(buf, 10, &v); | |
303 | if (err) | |
304 | return err; | |
1da177e4 LT |
305 | |
306 | if (n == 0) | |
307 | r = VDD_TO_REG(v); | |
308 | else | |
309 | r = IN_TO_REG(v); | |
310 | ||
9a61bf63 | 311 | mutex_lock(&data->update_lock); |
1da177e4 LT |
312 | |
313 | data->in_max[n] = r; | |
314 | ||
315 | if (n < 4) | |
86d47f12 JD |
316 | gl520_write_value(client, GL520_REG_IN_MAX[n], |
317 | (gl520_read_value(client, GL520_REG_IN_MAX[n]) | |
318 | & ~0xff00) | (r << 8)); | |
1da177e4 | 319 | else |
86d47f12 | 320 | gl520_write_value(client, GL520_REG_IN_MAX[n], r); |
1da177e4 | 321 | |
9a61bf63 | 322 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
323 | return count; |
324 | } | |
325 | ||
17de1a88 GR |
326 | static SENSOR_DEVICE_ATTR_RO(in0_input, in_input, 0); |
327 | static SENSOR_DEVICE_ATTR_RO(in1_input, in_input, 1); | |
328 | static SENSOR_DEVICE_ATTR_RO(in2_input, in_input, 2); | |
329 | static SENSOR_DEVICE_ATTR_RO(in3_input, in_input, 3); | |
330 | static SENSOR_DEVICE_ATTR_RO(in4_input, in_input, 4); | |
331 | static SENSOR_DEVICE_ATTR_RW(in0_min, in_min, 0); | |
332 | static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); | |
333 | static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); | |
334 | static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); | |
335 | static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); | |
336 | static SENSOR_DEVICE_ATTR_RW(in0_max, in_max, 0); | |
337 | static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); | |
338 | static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); | |
339 | static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); | |
340 | static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); | |
86d47f12 | 341 | |
1da177e4 | 342 | #define DIV_FROM_REG(val) (1 << (val)) |
43da3d12 | 343 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : (480000 / ((val) << (div)))) |
87cdfa9d GR |
344 | |
345 | #define FAN_BASE(div) (480000 >> (div)) | |
346 | #define FAN_CLAMP(val, div) clamp_val(val, FAN_BASE(div) / 255, \ | |
347 | FAN_BASE(div)) | |
348 | #define FAN_TO_REG(val, div) ((val) == 0 ? 0 : \ | |
349 | DIV_ROUND_CLOSEST(480000, \ | |
350 | FAN_CLAMP(val, div) << (div))) | |
1da177e4 | 351 | |
17de1a88 GR |
352 | static ssize_t fan_input_show(struct device *dev, |
353 | struct device_attribute *attr, char *buf) | |
1da177e4 | 354 | { |
86d47f12 JD |
355 | int n = to_sensor_dev_attr(attr)->index; |
356 | struct gl520_data *data = gl520_update_device(dev); | |
357 | ||
358 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n], | |
359 | data->fan_div[n])); | |
1da177e4 LT |
360 | } |
361 | ||
17de1a88 GR |
362 | static ssize_t fan_min_show(struct device *dev, struct device_attribute *attr, |
363 | char *buf) | |
1da177e4 | 364 | { |
86d47f12 JD |
365 | int n = to_sensor_dev_attr(attr)->index; |
366 | struct gl520_data *data = gl520_update_device(dev); | |
367 | ||
368 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n], | |
369 | data->fan_div[n])); | |
1da177e4 LT |
370 | } |
371 | ||
17de1a88 GR |
372 | static ssize_t fan_div_show(struct device *dev, struct device_attribute *attr, |
373 | char *buf) | |
1da177e4 | 374 | { |
86d47f12 JD |
375 | int n = to_sensor_dev_attr(attr)->index; |
376 | struct gl520_data *data = gl520_update_device(dev); | |
377 | ||
378 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n])); | |
1da177e4 LT |
379 | } |
380 | ||
2579b7ff JL |
381 | static ssize_t fan1_off_show(struct device *dev, |
382 | struct device_attribute *attr, char *buf) | |
1da177e4 | 383 | { |
86d47f12 | 384 | struct gl520_data *data = gl520_update_device(dev); |
1da177e4 LT |
385 | return sprintf(buf, "%d\n", data->fan_off); |
386 | } | |
387 | ||
17de1a88 GR |
388 | static ssize_t fan_min_store(struct device *dev, |
389 | struct device_attribute *attr, const char *buf, | |
390 | size_t count) | |
1da177e4 | 391 | { |
d1b9c3f5 AL |
392 | struct gl520_data *data = dev_get_drvdata(dev); |
393 | struct i2c_client *client = data->client; | |
86d47f12 | 394 | int n = to_sensor_dev_attr(attr)->index; |
1da177e4 | 395 | u8 r; |
43da3d12 GR |
396 | unsigned long v; |
397 | int err; | |
398 | ||
399 | err = kstrtoul(buf, 10, &v); | |
400 | if (err) | |
401 | return err; | |
1da177e4 | 402 | |
9a61bf63 | 403 | mutex_lock(&data->update_lock); |
86d47f12 JD |
404 | r = FAN_TO_REG(v, data->fan_div[n]); |
405 | data->fan_min[n] = r; | |
1da177e4 | 406 | |
86d47f12 JD |
407 | if (n == 0) |
408 | gl520_write_value(client, GL520_REG_FAN_MIN, | |
409 | (gl520_read_value(client, GL520_REG_FAN_MIN) | |
410 | & ~0xff00) | (r << 8)); | |
1da177e4 | 411 | else |
86d47f12 JD |
412 | gl520_write_value(client, GL520_REG_FAN_MIN, |
413 | (gl520_read_value(client, GL520_REG_FAN_MIN) | |
414 | & ~0xff) | r); | |
1da177e4 LT |
415 | |
416 | data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); | |
86d47f12 JD |
417 | if (data->fan_min[n] == 0) |
418 | data->alarm_mask &= (n == 0) ? ~0x20 : ~0x40; | |
1da177e4 | 419 | else |
86d47f12 | 420 | data->alarm_mask |= (n == 0) ? 0x20 : 0x40; |
1da177e4 LT |
421 | data->beep_mask &= data->alarm_mask; |
422 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); | |
423 | ||
9a61bf63 | 424 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
425 | return count; |
426 | } | |
427 | ||
17de1a88 GR |
428 | static ssize_t fan_div_store(struct device *dev, |
429 | struct device_attribute *attr, const char *buf, | |
430 | size_t count) | |
1da177e4 | 431 | { |
d1b9c3f5 AL |
432 | struct gl520_data *data = dev_get_drvdata(dev); |
433 | struct i2c_client *client = data->client; | |
86d47f12 | 434 | int n = to_sensor_dev_attr(attr)->index; |
1da177e4 | 435 | u8 r; |
43da3d12 GR |
436 | unsigned long v; |
437 | int err; | |
438 | ||
439 | err = kstrtoul(buf, 10, &v); | |
440 | if (err) | |
441 | return err; | |
1da177e4 LT |
442 | |
443 | switch (v) { | |
43da3d12 GR |
444 | case 1: |
445 | r = 0; | |
446 | break; | |
447 | case 2: | |
448 | r = 1; | |
449 | break; | |
450 | case 4: | |
451 | r = 2; | |
452 | break; | |
453 | case 8: | |
454 | r = 3; | |
455 | break; | |
1da177e4 | 456 | default: |
43da3d12 GR |
457 | dev_err(&client->dev, |
458 | "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v); | |
1da177e4 LT |
459 | return -EINVAL; |
460 | } | |
461 | ||
9a61bf63 | 462 | mutex_lock(&data->update_lock); |
86d47f12 | 463 | data->fan_div[n] = r; |
1da177e4 | 464 | |
86d47f12 JD |
465 | if (n == 0) |
466 | gl520_write_value(client, GL520_REG_FAN_DIV, | |
467 | (gl520_read_value(client, GL520_REG_FAN_DIV) | |
468 | & ~0xc0) | (r << 6)); | |
1da177e4 | 469 | else |
86d47f12 JD |
470 | gl520_write_value(client, GL520_REG_FAN_DIV, |
471 | (gl520_read_value(client, GL520_REG_FAN_DIV) | |
472 | & ~0x30) | (r << 4)); | |
1da177e4 | 473 | |
9a61bf63 | 474 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
475 | return count; |
476 | } | |
477 | ||
2579b7ff JL |
478 | static ssize_t fan1_off_store(struct device *dev, |
479 | struct device_attribute *attr, const char *buf, | |
480 | size_t count) | |
1da177e4 | 481 | { |
d1b9c3f5 AL |
482 | struct gl520_data *data = dev_get_drvdata(dev); |
483 | struct i2c_client *client = data->client; | |
43da3d12 GR |
484 | u8 r; |
485 | unsigned long v; | |
486 | int err; | |
487 | ||
488 | err = kstrtoul(buf, 10, &v); | |
489 | if (err) | |
490 | return err; | |
491 | ||
492 | r = (v ? 1 : 0); | |
1da177e4 | 493 | |
9a61bf63 | 494 | mutex_lock(&data->update_lock); |
1da177e4 | 495 | data->fan_off = r; |
86d47f12 JD |
496 | gl520_write_value(client, GL520_REG_FAN_OFF, |
497 | (gl520_read_value(client, GL520_REG_FAN_OFF) | |
498 | & ~0x0c) | (r << 2)); | |
9a61bf63 | 499 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
500 | return count; |
501 | } | |
502 | ||
17de1a88 GR |
503 | static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0); |
504 | static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1); | |
505 | static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); | |
506 | static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); | |
507 | static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); | |
508 | static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); | |
2579b7ff | 509 | static DEVICE_ATTR_RW(fan1_off); |
86d47f12 | 510 | |
87cdfa9d GR |
511 | #define TEMP_FROM_REG(val) (((val) - 130) * 1000) |
512 | #define TEMP_CLAMP(val) clamp_val(val, -130000, 125000) | |
513 | #define TEMP_TO_REG(val) (DIV_ROUND_CLOSEST(TEMP_CLAMP(val), 1000) + 130) | |
1da177e4 | 514 | |
17de1a88 GR |
515 | static ssize_t temp_input_show(struct device *dev, |
516 | struct device_attribute *attr, char *buf) | |
1da177e4 | 517 | { |
86d47f12 JD |
518 | int n = to_sensor_dev_attr(attr)->index; |
519 | struct gl520_data *data = gl520_update_device(dev); | |
520 | ||
521 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n])); | |
1da177e4 LT |
522 | } |
523 | ||
17de1a88 GR |
524 | static ssize_t temp_max_show(struct device *dev, |
525 | struct device_attribute *attr, char *buf) | |
1da177e4 | 526 | { |
86d47f12 JD |
527 | int n = to_sensor_dev_attr(attr)->index; |
528 | struct gl520_data *data = gl520_update_device(dev); | |
529 | ||
530 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n])); | |
1da177e4 LT |
531 | } |
532 | ||
17de1a88 GR |
533 | static ssize_t temp_max_hyst_show(struct device *dev, |
534 | struct device_attribute *attr, char *buf) | |
1da177e4 | 535 | { |
86d47f12 JD |
536 | int n = to_sensor_dev_attr(attr)->index; |
537 | struct gl520_data *data = gl520_update_device(dev); | |
538 | ||
539 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n])); | |
1da177e4 LT |
540 | } |
541 | ||
17de1a88 GR |
542 | static ssize_t temp_max_store(struct device *dev, |
543 | struct device_attribute *attr, const char *buf, | |
544 | size_t count) | |
1da177e4 | 545 | { |
d1b9c3f5 AL |
546 | struct gl520_data *data = dev_get_drvdata(dev); |
547 | struct i2c_client *client = data->client; | |
86d47f12 | 548 | int n = to_sensor_dev_attr(attr)->index; |
43da3d12 GR |
549 | long v; |
550 | int err; | |
551 | ||
552 | err = kstrtol(buf, 10, &v); | |
553 | if (err) | |
554 | return err; | |
1da177e4 | 555 | |
9a61bf63 | 556 | mutex_lock(&data->update_lock); |
86d47f12 JD |
557 | data->temp_max[n] = TEMP_TO_REG(v); |
558 | gl520_write_value(client, GL520_REG_TEMP_MAX[n], data->temp_max[n]); | |
9a61bf63 | 559 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
560 | return count; |
561 | } | |
562 | ||
17de1a88 GR |
563 | static ssize_t temp_max_hyst_store(struct device *dev, |
564 | struct device_attribute *attr, | |
565 | const char *buf, size_t count) | |
1da177e4 | 566 | { |
d1b9c3f5 AL |
567 | struct gl520_data *data = dev_get_drvdata(dev); |
568 | struct i2c_client *client = data->client; | |
86d47f12 | 569 | int n = to_sensor_dev_attr(attr)->index; |
43da3d12 GR |
570 | long v; |
571 | int err; | |
572 | ||
573 | err = kstrtol(buf, 10, &v); | |
574 | if (err) | |
575 | return err; | |
1da177e4 | 576 | |
9a61bf63 | 577 | mutex_lock(&data->update_lock); |
86d47f12 JD |
578 | data->temp_max_hyst[n] = TEMP_TO_REG(v); |
579 | gl520_write_value(client, GL520_REG_TEMP_MAX_HYST[n], | |
580 | data->temp_max_hyst[n]); | |
9a61bf63 | 581 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
582 | return count; |
583 | } | |
584 | ||
17de1a88 GR |
585 | static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0); |
586 | static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1); | |
587 | static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0); | |
588 | static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1); | |
589 | static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp_max_hyst, 0); | |
590 | static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_max_hyst, 1); | |
86d47f12 | 591 | |
2579b7ff JL |
592 | static ssize_t alarms_show(struct device *dev, struct device_attribute *attr, |
593 | char *buf) | |
1da177e4 | 594 | { |
86d47f12 | 595 | struct gl520_data *data = gl520_update_device(dev); |
1da177e4 LT |
596 | return sprintf(buf, "%d\n", data->alarms); |
597 | } | |
598 | ||
2579b7ff JL |
599 | static ssize_t beep_enable_show(struct device *dev, |
600 | struct device_attribute *attr, char *buf) | |
1da177e4 | 601 | { |
86d47f12 | 602 | struct gl520_data *data = gl520_update_device(dev); |
1da177e4 LT |
603 | return sprintf(buf, "%d\n", data->beep_enable); |
604 | } | |
605 | ||
2579b7ff JL |
606 | static ssize_t beep_mask_show(struct device *dev, |
607 | struct device_attribute *attr, char *buf) | |
1da177e4 | 608 | { |
86d47f12 | 609 | struct gl520_data *data = gl520_update_device(dev); |
1da177e4 LT |
610 | return sprintf(buf, "%d\n", data->beep_mask); |
611 | } | |
612 | ||
2579b7ff JL |
613 | static ssize_t beep_enable_store(struct device *dev, |
614 | struct device_attribute *attr, | |
615 | const char *buf, size_t count) | |
1da177e4 | 616 | { |
d1b9c3f5 AL |
617 | struct gl520_data *data = dev_get_drvdata(dev); |
618 | struct i2c_client *client = data->client; | |
43da3d12 GR |
619 | u8 r; |
620 | unsigned long v; | |
621 | int err; | |
622 | ||
623 | err = kstrtoul(buf, 10, &v); | |
624 | if (err) | |
625 | return err; | |
626 | ||
627 | r = (v ? 0 : 1); | |
1da177e4 | 628 | |
9a61bf63 | 629 | mutex_lock(&data->update_lock); |
1da177e4 | 630 | data->beep_enable = !r; |
86d47f12 JD |
631 | gl520_write_value(client, GL520_REG_BEEP_ENABLE, |
632 | (gl520_read_value(client, GL520_REG_BEEP_ENABLE) | |
633 | & ~0x04) | (r << 2)); | |
9a61bf63 | 634 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
635 | return count; |
636 | } | |
637 | ||
2579b7ff JL |
638 | static ssize_t beep_mask_store(struct device *dev, |
639 | struct device_attribute *attr, const char *buf, | |
640 | size_t count) | |
1da177e4 | 641 | { |
d1b9c3f5 AL |
642 | struct gl520_data *data = dev_get_drvdata(dev); |
643 | struct i2c_client *client = data->client; | |
43da3d12 GR |
644 | unsigned long r; |
645 | int err; | |
646 | ||
647 | err = kstrtoul(buf, 10, &r); | |
648 | if (err) | |
649 | return err; | |
f28dc2f7 | 650 | |
9a61bf63 | 651 | mutex_lock(&data->update_lock); |
1da177e4 LT |
652 | r &= data->alarm_mask; |
653 | data->beep_mask = r; | |
86d47f12 | 654 | gl520_write_value(client, GL520_REG_BEEP_MASK, r); |
9a61bf63 | 655 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
656 | return count; |
657 | } | |
658 | ||
2579b7ff JL |
659 | static DEVICE_ATTR_RO(alarms); |
660 | static DEVICE_ATTR_RW(beep_enable); | |
661 | static DEVICE_ATTR_RW(beep_mask); | |
86d47f12 | 662 | |
17de1a88 GR |
663 | static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, |
664 | char *buf) | |
e86a7760 JD |
665 | { |
666 | int bit_nr = to_sensor_dev_attr(attr)->index; | |
667 | struct gl520_data *data = gl520_update_device(dev); | |
668 | ||
669 | return sprintf(buf, "%d\n", (data->alarms >> bit_nr) & 1); | |
670 | } | |
671 | ||
17de1a88 GR |
672 | static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
673 | static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); | |
674 | static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); | |
675 | static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); | |
676 | static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4); | |
677 | static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 5); | |
678 | static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 6); | |
679 | static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 7); | |
680 | static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 7); | |
681 | ||
682 | static ssize_t beep_show(struct device *dev, struct device_attribute *attr, | |
683 | char *buf) | |
e86a7760 JD |
684 | { |
685 | int bitnr = to_sensor_dev_attr(attr)->index; | |
686 | struct gl520_data *data = gl520_update_device(dev); | |
687 | ||
688 | return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1); | |
689 | } | |
690 | ||
17de1a88 GR |
691 | static ssize_t beep_store(struct device *dev, struct device_attribute *attr, |
692 | const char *buf, size_t count) | |
e86a7760 | 693 | { |
d1b9c3f5 AL |
694 | struct gl520_data *data = dev_get_drvdata(dev); |
695 | struct i2c_client *client = data->client; | |
e86a7760 JD |
696 | int bitnr = to_sensor_dev_attr(attr)->index; |
697 | unsigned long bit; | |
698 | ||
43da3d12 GR |
699 | int err; |
700 | ||
701 | err = kstrtoul(buf, 10, &bit); | |
702 | if (err) | |
703 | return err; | |
e86a7760 JD |
704 | if (bit & ~1) |
705 | return -EINVAL; | |
706 | ||
707 | mutex_lock(&data->update_lock); | |
708 | data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); | |
709 | if (bit) | |
710 | data->beep_mask |= (1 << bitnr); | |
711 | else | |
712 | data->beep_mask &= ~(1 << bitnr); | |
713 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); | |
714 | mutex_unlock(&data->update_lock); | |
715 | return count; | |
716 | } | |
717 | ||
17de1a88 GR |
718 | static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0); |
719 | static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1); | |
720 | static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2); | |
721 | static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3); | |
722 | static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4); | |
723 | static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 5); | |
724 | static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 6); | |
725 | static SENSOR_DEVICE_ATTR_RW(temp2_beep, beep, 7); | |
726 | static SENSOR_DEVICE_ATTR_RW(in4_beep, beep, 7); | |
e86a7760 | 727 | |
87808be4 JD |
728 | static struct attribute *gl520_attributes[] = { |
729 | &dev_attr_cpu0_vid.attr, | |
730 | ||
86d47f12 JD |
731 | &sensor_dev_attr_in0_input.dev_attr.attr, |
732 | &sensor_dev_attr_in0_min.dev_attr.attr, | |
733 | &sensor_dev_attr_in0_max.dev_attr.attr, | |
e86a7760 JD |
734 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
735 | &sensor_dev_attr_in0_beep.dev_attr.attr, | |
86d47f12 JD |
736 | &sensor_dev_attr_in1_input.dev_attr.attr, |
737 | &sensor_dev_attr_in1_min.dev_attr.attr, | |
738 | &sensor_dev_attr_in1_max.dev_attr.attr, | |
e86a7760 JD |
739 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
740 | &sensor_dev_attr_in1_beep.dev_attr.attr, | |
86d47f12 JD |
741 | &sensor_dev_attr_in2_input.dev_attr.attr, |
742 | &sensor_dev_attr_in2_min.dev_attr.attr, | |
743 | &sensor_dev_attr_in2_max.dev_attr.attr, | |
e86a7760 JD |
744 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
745 | &sensor_dev_attr_in2_beep.dev_attr.attr, | |
86d47f12 JD |
746 | &sensor_dev_attr_in3_input.dev_attr.attr, |
747 | &sensor_dev_attr_in3_min.dev_attr.attr, | |
748 | &sensor_dev_attr_in3_max.dev_attr.attr, | |
e86a7760 JD |
749 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
750 | &sensor_dev_attr_in3_beep.dev_attr.attr, | |
86d47f12 JD |
751 | |
752 | &sensor_dev_attr_fan1_input.dev_attr.attr, | |
753 | &sensor_dev_attr_fan1_min.dev_attr.attr, | |
754 | &sensor_dev_attr_fan1_div.dev_attr.attr, | |
e86a7760 JD |
755 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
756 | &sensor_dev_attr_fan1_beep.dev_attr.attr, | |
87808be4 | 757 | &dev_attr_fan1_off.attr, |
86d47f12 JD |
758 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
759 | &sensor_dev_attr_fan2_min.dev_attr.attr, | |
760 | &sensor_dev_attr_fan2_div.dev_attr.attr, | |
e86a7760 JD |
761 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
762 | &sensor_dev_attr_fan2_beep.dev_attr.attr, | |
87808be4 | 763 | |
86d47f12 JD |
764 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
765 | &sensor_dev_attr_temp1_max.dev_attr.attr, | |
766 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, | |
e86a7760 JD |
767 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
768 | &sensor_dev_attr_temp1_beep.dev_attr.attr, | |
87808be4 JD |
769 | |
770 | &dev_attr_alarms.attr, | |
771 | &dev_attr_beep_enable.attr, | |
772 | &dev_attr_beep_mask.attr, | |
773 | NULL | |
774 | }; | |
775 | ||
776 | static const struct attribute_group gl520_group = { | |
777 | .attrs = gl520_attributes, | |
778 | }; | |
779 | ||
f445a9af | 780 | static struct attribute *gl520_attributes_in4[] = { |
86d47f12 JD |
781 | &sensor_dev_attr_in4_input.dev_attr.attr, |
782 | &sensor_dev_attr_in4_min.dev_attr.attr, | |
783 | &sensor_dev_attr_in4_max.dev_attr.attr, | |
e86a7760 JD |
784 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
785 | &sensor_dev_attr_in4_beep.dev_attr.attr, | |
f445a9af GR |
786 | NULL |
787 | }; | |
87808be4 | 788 | |
f445a9af | 789 | static struct attribute *gl520_attributes_temp2[] = { |
86d47f12 JD |
790 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
791 | &sensor_dev_attr_temp2_max.dev_attr.attr, | |
792 | &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, | |
e86a7760 JD |
793 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
794 | &sensor_dev_attr_temp2_beep.dev_attr.attr, | |
87808be4 JD |
795 | NULL |
796 | }; | |
797 | ||
f445a9af GR |
798 | static const struct attribute_group gl520_group_in4 = { |
799 | .attrs = gl520_attributes_in4, | |
800 | }; | |
801 | ||
802 | static const struct attribute_group gl520_group_temp2 = { | |
803 | .attrs = gl520_attributes_temp2, | |
87808be4 JD |
804 | }; |
805 | ||
1da177e4 LT |
806 | |
807 | /* | |
808 | * Real code | |
809 | */ | |
810 | ||
a23a9fe1 | 811 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
310ec792 | 812 | static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info) |
1da177e4 | 813 | { |
a23a9fe1 | 814 | struct i2c_adapter *adapter = client->adapter; |
1da177e4 LT |
815 | |
816 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | |
817 | I2C_FUNC_SMBUS_WORD_DATA)) | |
a23a9fe1 | 818 | return -ENODEV; |
1da177e4 LT |
819 | |
820 | /* Determine the chip type. */ | |
52df6440 JD |
821 | if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) || |
822 | ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) || | |
823 | ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) { | |
824 | dev_dbg(&client->dev, "Unknown chip type, skipping\n"); | |
825 | return -ENODEV; | |
1da177e4 LT |
826 | } |
827 | ||
a23a9fe1 | 828 | strlcpy(info->type, "gl520sm", I2C_NAME_SIZE); |
1da177e4 | 829 | |
a23a9fe1 JD |
830 | return 0; |
831 | } | |
832 | ||
df51f2d7 AL |
833 | /* Called when we have found a new GL520SM. */ |
834 | static void gl520_init_client(struct i2c_client *client) | |
835 | { | |
836 | struct gl520_data *data = i2c_get_clientdata(client); | |
837 | u8 oldconf, conf; | |
838 | ||
839 | conf = oldconf = gl520_read_value(client, GL520_REG_CONF); | |
840 | ||
841 | data->alarm_mask = 0xff; | |
842 | data->vrm = vid_which_vrm(); | |
843 | ||
844 | if (extra_sensor_type == 1) | |
845 | conf &= ~0x10; | |
846 | else if (extra_sensor_type == 2) | |
847 | conf |= 0x10; | |
848 | data->two_temps = !(conf & 0x10); | |
849 | ||
850 | /* If IRQ# is disabled, we can safely force comparator mode */ | |
851 | if (!(conf & 0x20)) | |
852 | conf &= 0xf7; | |
853 | ||
854 | /* Enable monitoring if needed */ | |
855 | conf |= 0x40; | |
856 | ||
857 | if (conf != oldconf) | |
858 | gl520_write_value(client, GL520_REG_CONF, conf); | |
859 | ||
860 | gl520_update_device(&(client->dev)); | |
861 | ||
862 | if (data->fan_min[0] == 0) | |
863 | data->alarm_mask &= ~0x20; | |
864 | if (data->fan_min[1] == 0) | |
865 | data->alarm_mask &= ~0x40; | |
866 | ||
867 | data->beep_mask &= data->alarm_mask; | |
868 | gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask); | |
869 | } | |
870 | ||
a23a9fe1 JD |
871 | static int gl520_probe(struct i2c_client *client, |
872 | const struct i2c_device_id *id) | |
873 | { | |
d1b9c3f5 AL |
874 | struct device *dev = &client->dev; |
875 | struct device *hwmon_dev; | |
a23a9fe1 | 876 | struct gl520_data *data; |
a23a9fe1 | 877 | |
d1b9c3f5 | 878 | data = devm_kzalloc(dev, sizeof(struct gl520_data), GFP_KERNEL); |
647ff514 GR |
879 | if (!data) |
880 | return -ENOMEM; | |
a23a9fe1 JD |
881 | |
882 | i2c_set_clientdata(client, data); | |
883 | mutex_init(&data->update_lock); | |
d1b9c3f5 | 884 | data->client = client; |
1da177e4 LT |
885 | |
886 | /* Initialize the GL520SM chip */ | |
f28dc2f7 | 887 | gl520_init_client(client); |
1da177e4 | 888 | |
d1b9c3f5 AL |
889 | /* sysfs hooks */ |
890 | data->groups[0] = &gl520_group; | |
1da177e4 | 891 | |
f445a9af | 892 | if (data->two_temps) |
d1b9c3f5 | 893 | data->groups[1] = &gl520_group_temp2; |
f445a9af | 894 | else |
d1b9c3f5 | 895 | data->groups[1] = &gl520_group_in4; |
1da177e4 | 896 | |
d1b9c3f5 AL |
897 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
898 | data, data->groups); | |
899 | return PTR_ERR_OR_ZERO(hwmon_dev); | |
1da177e4 LT |
900 | } |
901 | ||
df51f2d7 AL |
902 | static const struct i2c_device_id gl520_id[] = { |
903 | { "gl520sm", 0 }, | |
904 | { } | |
905 | }; | |
906 | MODULE_DEVICE_TABLE(i2c, gl520_id); | |
1da177e4 | 907 | |
df51f2d7 AL |
908 | static struct i2c_driver gl520_driver = { |
909 | .class = I2C_CLASS_HWMON, | |
910 | .driver = { | |
911 | .name = "gl520sm", | |
912 | }, | |
913 | .probe = gl520_probe, | |
df51f2d7 AL |
914 | .id_table = gl520_id, |
915 | .detect = gl520_detect, | |
916 | .address_list = normal_i2c, | |
917 | }; | |
1da177e4 | 918 | |
f0967eea | 919 | module_i2c_driver(gl520_driver); |
1da177e4 LT |
920 | |
921 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " | |
96de0e25 | 922 | "Kyösti Mälkki <kmalkki@cc.hut.fi>, " |
1da177e4 LT |
923 | "Maarten Deprez <maartendeprez@users.sourceforge.net>"); |
924 | MODULE_DESCRIPTION("GL520SM driver"); | |
925 | MODULE_LICENSE("GPL"); |