3 * Copyright (C) 2007 - 2009 Hans de Goede <hdegoede@redhat.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Merged Fujitsu Siemens hwmon driver, supporting the Poseidon, Hermes,
22 * Scylla, Heracles, Heimdall, Hades and Syleus chips
24 * Based on the original 2.4 fscscy, 2.6 fscpos, 2.6 fscher and 2.6
25 * (candidate) fschmd drivers:
26 * Copyright (C) 2006 Thilo Cestonaro
27 * <thilo.cestonaro.external@fujitsu-siemens.com>
28 * Copyright (C) 2004, 2005 Stefan Ott <stefan@desire.ch>
29 * Copyright (C) 2003, 2004 Reinhard Nissl <rnissl@gmx.de>
30 * Copyright (c) 2001 Martin Knoblauch <mkn@teraport.de, knobi@knobisoft.de>
31 * Copyright (C) 2000 Hermann Jung <hej@odn.de>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/slab.h>
37 #include <linux/jiffies.h>
38 #include <linux/i2c.h>
39 #include <linux/hwmon.h>
40 #include <linux/hwmon-sysfs.h>
41 #include <linux/err.h>
42 #include <linux/mutex.h>
43 #include <linux/sysfs.h>
44 #include <linux/dmi.h>
46 #include <linux/watchdog.h>
47 #include <linux/miscdevice.h>
48 #include <linux/uaccess.h>
49 #include <linux/kref.h>
51 /* Addresses to scan */
52 static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
54 /* Insmod parameters */
55 static int nowayout = WATCHDOG_NOWAYOUT;
56 module_param(nowayout, int, 0);
57 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
58 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
59 I2C_CLIENT_INSMOD_7(fscpos, fscher, fscscy, fschrc, fschmd, fschds, fscsyl);
62 * The FSCHMD registers and other defines
65 /* chip identification */
66 #define FSCHMD_REG_IDENT_0 0x00
67 #define FSCHMD_REG_IDENT_1 0x01
68 #define FSCHMD_REG_IDENT_2 0x02
69 #define FSCHMD_REG_REVISION 0x03
71 /* global control and status */
72 #define FSCHMD_REG_EVENT_STATE 0x04
73 #define FSCHMD_REG_CONTROL 0x05
75 #define FSCHMD_CONTROL_ALERT_LED 0x01
78 static const u8 FSCHMD_REG_WDOG_CONTROL[7] =
79 { 0x21, 0x21, 0x21, 0x21, 0x21, 0x28, 0x28 };
80 static const u8 FSCHMD_REG_WDOG_STATE[7] =
81 { 0x23, 0x23, 0x23, 0x23, 0x23, 0x29, 0x29 };
82 static const u8 FSCHMD_REG_WDOG_PRESET[7] =
83 { 0x28, 0x28, 0x28, 0x28, 0x28, 0x2a, 0x2a };
85 #define FSCHMD_WDOG_CONTROL_TRIGGER 0x10
86 #define FSCHMD_WDOG_CONTROL_STARTED 0x10 /* the same as trigger */
87 #define FSCHMD_WDOG_CONTROL_STOP 0x20
88 #define FSCHMD_WDOG_CONTROL_RESOLUTION 0x40
90 #define FSCHMD_WDOG_STATE_CARDRESET 0x02
92 /* voltages, weird order is to keep the same order as the old drivers */
93 static const u8 FSCHMD_REG_VOLT[7][6] = {
94 { 0x45, 0x42, 0x48 }, /* pos */
95 { 0x45, 0x42, 0x48 }, /* her */
96 { 0x45, 0x42, 0x48 }, /* scy */
97 { 0x45, 0x42, 0x48 }, /* hrc */
98 { 0x45, 0x42, 0x48 }, /* hmd */
99 { 0x21, 0x20, 0x22 }, /* hds */
100 { 0x21, 0x20, 0x22, 0x23, 0x24, 0x25 }, /* syl */
103 static const int FSCHMD_NO_VOLT_SENSORS[7] = { 3, 3, 3, 3, 3, 3, 6 };
105 /* minimum pwm at which the fan is driven (pwm can by increased depending on
106 the temp. Notice that for the scy some fans share there minimum speed.
107 Also notice that with the scy the sensor order is different than with the
108 other chips, this order was in the 2.4 driver and kept for consistency. */
109 static const u8 FSCHMD_REG_FAN_MIN[7][7] = {
110 { 0x55, 0x65 }, /* pos */
111 { 0x55, 0x65, 0xb5 }, /* her */
112 { 0x65, 0x65, 0x55, 0xa5, 0x55, 0xa5 }, /* scy */
113 { 0x55, 0x65, 0xa5, 0xb5 }, /* hrc */
114 { 0x55, 0x65, 0xa5, 0xb5, 0xc5 }, /* hmd */
115 { 0x55, 0x65, 0xa5, 0xb5, 0xc5 }, /* hds */
116 { 0x54, 0x64, 0x74, 0x84, 0x94, 0xa4, 0xb4 }, /* syl */
119 /* actual fan speed */
120 static const u8 FSCHMD_REG_FAN_ACT[7][7] = {
121 { 0x0e, 0x6b, 0xab }, /* pos */
122 { 0x0e, 0x6b, 0xbb }, /* her */
123 { 0x6b, 0x6c, 0x0e, 0xab, 0x5c, 0xbb }, /* scy */
124 { 0x0e, 0x6b, 0xab, 0xbb }, /* hrc */
125 { 0x5b, 0x6b, 0xab, 0xbb, 0xcb }, /* hmd */
126 { 0x5b, 0x6b, 0xab, 0xbb, 0xcb }, /* hds */
127 { 0x57, 0x67, 0x77, 0x87, 0x97, 0xa7, 0xb7 }, /* syl */
130 /* fan status registers */
131 static const u8 FSCHMD_REG_FAN_STATE[7][7] = {
132 { 0x0d, 0x62, 0xa2 }, /* pos */
133 { 0x0d, 0x62, 0xb2 }, /* her */
134 { 0x62, 0x61, 0x0d, 0xa2, 0x52, 0xb2 }, /* scy */
135 { 0x0d, 0x62, 0xa2, 0xb2 }, /* hrc */
136 { 0x52, 0x62, 0xa2, 0xb2, 0xc2 }, /* hmd */
137 { 0x52, 0x62, 0xa2, 0xb2, 0xc2 }, /* hds */
138 { 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0 }, /* syl */
141 /* fan ripple / divider registers */
142 static const u8 FSCHMD_REG_FAN_RIPPLE[7][7] = {
143 { 0x0f, 0x6f, 0xaf }, /* pos */
144 { 0x0f, 0x6f, 0xbf }, /* her */
145 { 0x6f, 0x6f, 0x0f, 0xaf, 0x0f, 0xbf }, /* scy */
146 { 0x0f, 0x6f, 0xaf, 0xbf }, /* hrc */
147 { 0x5f, 0x6f, 0xaf, 0xbf, 0xcf }, /* hmd */
148 { 0x5f, 0x6f, 0xaf, 0xbf, 0xcf }, /* hds */
149 { 0x56, 0x66, 0x76, 0x86, 0x96, 0xa6, 0xb6 }, /* syl */
152 static const int FSCHMD_NO_FAN_SENSORS[7] = { 3, 3, 6, 4, 5, 5, 7 };
154 /* Fan status register bitmasks */
155 #define FSCHMD_FAN_ALARM 0x04 /* called fault by FSC! */
156 #define FSCHMD_FAN_NOT_PRESENT 0x08
157 #define FSCHMD_FAN_DISABLED 0x80
160 /* actual temperature registers */
161 static const u8 FSCHMD_REG_TEMP_ACT[7][11] = {
162 { 0x64, 0x32, 0x35 }, /* pos */
163 { 0x64, 0x32, 0x35 }, /* her */
164 { 0x64, 0xD0, 0x32, 0x35 }, /* scy */
165 { 0x64, 0x32, 0x35 }, /* hrc */
166 { 0x70, 0x80, 0x90, 0xd0, 0xe0 }, /* hmd */
167 { 0x70, 0x80, 0x90, 0xd0, 0xe0 }, /* hds */
168 { 0x58, 0x68, 0x78, 0x88, 0x98, 0xa8, /* syl */
169 0xb8, 0xc8, 0xd8, 0xe8, 0xf8 },
172 /* temperature state registers */
173 static const u8 FSCHMD_REG_TEMP_STATE[7][11] = {
174 { 0x71, 0x81, 0x91 }, /* pos */
175 { 0x71, 0x81, 0x91 }, /* her */
176 { 0x71, 0xd1, 0x81, 0x91 }, /* scy */
177 { 0x71, 0x81, 0x91 }, /* hrc */
178 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hmd */
179 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hds */
180 { 0x59, 0x69, 0x79, 0x89, 0x99, 0xa9, /* syl */
181 0xb9, 0xc9, 0xd9, 0xe9, 0xf9 },
184 /* temperature high limit registers, FSC does not document these. Proven to be
185 there with field testing on the fscher and fschrc, already supported / used
186 in the fscscy 2.4 driver. FSC has confirmed that the fschmd has registers
187 at these addresses, but doesn't want to confirm they are the same as with
189 static const u8 FSCHMD_REG_TEMP_LIMIT[7][11] = {
190 { 0, 0, 0 }, /* pos */
191 { 0x76, 0x86, 0x96 }, /* her */
192 { 0x76, 0xd6, 0x86, 0x96 }, /* scy */
193 { 0x76, 0x86, 0x96 }, /* hrc */
194 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hmd */
195 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hds */
196 { 0x5a, 0x6a, 0x7a, 0x8a, 0x9a, 0xaa, /* syl */
197 0xba, 0xca, 0xda, 0xea, 0xfa },
200 /* These were found through experimenting with an fscher, currently they are
201 not used, but we keep them around for future reference.
202 On the fscsyl AUTOP1 lives at 0x#c (so 0x5c for fan1, 0x6c for fan2, etc),
203 AUTOP2 lives at 0x#e, and 0x#1 is a bitmask defining which temps influence
205 static const u8 FSCHER_REG_TEMP_AUTOP1[] = { 0x73, 0x83, 0x93 };
206 static const u8 FSCHER_REG_TEMP_AUTOP2[] = { 0x75, 0x85, 0x95 }; */
208 static const int FSCHMD_NO_TEMP_SENSORS[7] = { 3, 3, 4, 3, 5, 5, 11 };
210 /* temp status register bitmasks */
211 #define FSCHMD_TEMP_WORKING 0x01
212 #define FSCHMD_TEMP_ALERT 0x02
213 #define FSCHMD_TEMP_DISABLED 0x80
214 /* there only really is an alarm if the sensor is working and alert == 1 */
215 #define FSCHMD_TEMP_ALARM_MASK \
216 (FSCHMD_TEMP_WORKING | FSCHMD_TEMP_ALERT)
219 * Functions declarations
222 static int fschmd_probe(struct i2c_client *client,
223 const struct i2c_device_id *id);
224 static int fschmd_detect(struct i2c_client *client, int kind,
225 struct i2c_board_info *info);
226 static int fschmd_remove(struct i2c_client *client);
227 static struct fschmd_data *fschmd_update_device(struct device *dev);
230 * Driver data (common to all clients)
233 static const struct i2c_device_id fschmd_id[] = {
234 { "fscpos", fscpos },
235 { "fscher", fscher },
236 { "fscscy", fscscy },
237 { "fschrc", fschrc },
238 { "fschmd", fschmd },
239 { "fschds", fschds },
240 { "fscsyl", fscsyl },
243 MODULE_DEVICE_TABLE(i2c, fschmd_id);
245 static struct i2c_driver fschmd_driver = {
246 .class = I2C_CLASS_HWMON,
250 .probe = fschmd_probe,
251 .remove = fschmd_remove,
252 .id_table = fschmd_id,
253 .detect = fschmd_detect,
254 .address_data = &addr_data,
258 * Client data (each client gets its own)
262 struct i2c_client *client;
263 struct device *hwmon_dev;
264 struct mutex update_lock;
265 struct mutex watchdog_lock;
266 struct list_head list; /* member of the watchdog_data_list */
268 struct miscdevice watchdog_miscdev;
270 unsigned long watchdog_is_open;
271 char watchdog_expect_close;
272 char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
273 char valid; /* zero until following fields are valid */
274 unsigned long last_updated; /* in jiffies */
276 /* register values */
277 u8 revision; /* chip revision */
278 u8 global_control; /* global control register */
279 u8 watchdog_control; /* watchdog control register */
280 u8 watchdog_state; /* watchdog status register */
281 u8 watchdog_preset; /* watchdog counter preset on trigger val */
282 u8 volt[6]; /* voltage */
283 u8 temp_act[11]; /* temperature */
284 u8 temp_status[11]; /* status of sensor */
285 u8 temp_max[11]; /* high temp limit, notice: undocumented! */
286 u8 fan_act[7]; /* fans revolutions per second */
287 u8 fan_status[7]; /* fan status */
288 u8 fan_min[7]; /* fan min value for rps */
289 u8 fan_ripple[7]; /* divider for rps */
292 /* Global variables to hold information read from special DMI tables, which are
293 available on FSC machines with an fscher or later chip. There is no need to
294 protect these with a lock as they are only modified from our attach function
295 which always gets called with the i2c-core lock held and never accessed
296 before the attach function is done with them. */
297 static int dmi_mult[6] = { 490, 200, 100, 100, 200, 100 };
298 static int dmi_offset[6] = { 0, 0, 0, 0, 0, 0 };
299 static int dmi_vref = -1;
301 /* Somewhat ugly :( global data pointer list with all fschmd devices, so that
302 we can find our device data as when using misc_register there is no other
303 method to get to ones device data from the open fop. */
304 static LIST_HEAD(watchdog_data_list);
305 /* Note this lock not only protect list access, but also data.kref access */
306 static DEFINE_MUTEX(watchdog_data_mutex);
308 /* Release our data struct when we're detached from the i2c client *and* all
309 references to our watchdog device are released */
310 static void fschmd_release_resources(struct kref *ref)
312 struct fschmd_data *data = container_of(ref, struct fschmd_data, kref);
317 * Sysfs attr show / store functions
320 static ssize_t show_in_value(struct device *dev,
321 struct device_attribute *devattr, char *buf)
323 const int max_reading[3] = { 14200, 6600, 3300 };
324 int index = to_sensor_dev_attr(devattr)->index;
325 struct fschmd_data *data = fschmd_update_device(dev);
327 /* fscher / fschrc - 1 as data->kind is an array index, not a chips */
328 if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
329 return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
330 dmi_mult[index]) / 255 + dmi_offset[index]);
332 return sprintf(buf, "%d\n", (data->volt[index] *
333 max_reading[index] + 128) / 255);
337 #define TEMP_FROM_REG(val) (((val) - 128) * 1000)
339 static ssize_t show_temp_value(struct device *dev,
340 struct device_attribute *devattr, char *buf)
342 int index = to_sensor_dev_attr(devattr)->index;
343 struct fschmd_data *data = fschmd_update_device(dev);
345 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_act[index]));
348 static ssize_t show_temp_max(struct device *dev,
349 struct device_attribute *devattr, char *buf)
351 int index = to_sensor_dev_attr(devattr)->index;
352 struct fschmd_data *data = fschmd_update_device(dev);
354 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
357 static ssize_t store_temp_max(struct device *dev, struct device_attribute
358 *devattr, const char *buf, size_t count)
360 int index = to_sensor_dev_attr(devattr)->index;
361 struct fschmd_data *data = dev_get_drvdata(dev);
362 long v = simple_strtol(buf, NULL, 10) / 1000;
364 v = SENSORS_LIMIT(v, -128, 127) + 128;
366 mutex_lock(&data->update_lock);
367 i2c_smbus_write_byte_data(to_i2c_client(dev),
368 FSCHMD_REG_TEMP_LIMIT[data->kind][index], v);
369 data->temp_max[index] = v;
370 mutex_unlock(&data->update_lock);
375 static ssize_t show_temp_fault(struct device *dev,
376 struct device_attribute *devattr, char *buf)
378 int index = to_sensor_dev_attr(devattr)->index;
379 struct fschmd_data *data = fschmd_update_device(dev);
381 /* bit 0 set means sensor working ok, so no fault! */
382 if (data->temp_status[index] & FSCHMD_TEMP_WORKING)
383 return sprintf(buf, "0\n");
385 return sprintf(buf, "1\n");
388 static ssize_t show_temp_alarm(struct device *dev,
389 struct device_attribute *devattr, char *buf)
391 int index = to_sensor_dev_attr(devattr)->index;
392 struct fschmd_data *data = fschmd_update_device(dev);
394 if ((data->temp_status[index] & FSCHMD_TEMP_ALARM_MASK) ==
395 FSCHMD_TEMP_ALARM_MASK)
396 return sprintf(buf, "1\n");
398 return sprintf(buf, "0\n");
402 #define RPM_FROM_REG(val) ((val) * 60)
404 static ssize_t show_fan_value(struct device *dev,
405 struct device_attribute *devattr, char *buf)
407 int index = to_sensor_dev_attr(devattr)->index;
408 struct fschmd_data *data = fschmd_update_device(dev);
410 return sprintf(buf, "%u\n", RPM_FROM_REG(data->fan_act[index]));
413 static ssize_t show_fan_div(struct device *dev,
414 struct device_attribute *devattr, char *buf)
416 int index = to_sensor_dev_attr(devattr)->index;
417 struct fschmd_data *data = fschmd_update_device(dev);
419 /* bits 2..7 reserved => mask with 3 */
420 return sprintf(buf, "%d\n", 1 << (data->fan_ripple[index] & 3));
423 static ssize_t store_fan_div(struct device *dev, struct device_attribute
424 *devattr, const char *buf, size_t count)
427 int index = to_sensor_dev_attr(devattr)->index;
428 struct fschmd_data *data = dev_get_drvdata(dev);
429 /* supported values: 2, 4, 8 */
430 unsigned long v = simple_strtoul(buf, NULL, 10);
433 case 2: v = 1; break;
434 case 4: v = 2; break;
435 case 8: v = 3; break;
437 dev_err(dev, "fan_div value %lu not supported. "
438 "Choose one of 2, 4 or 8!\n", v);
442 mutex_lock(&data->update_lock);
444 reg = i2c_smbus_read_byte_data(to_i2c_client(dev),
445 FSCHMD_REG_FAN_RIPPLE[data->kind][index]);
447 /* bits 2..7 reserved => mask with 0x03 */
451 i2c_smbus_write_byte_data(to_i2c_client(dev),
452 FSCHMD_REG_FAN_RIPPLE[data->kind][index], reg);
454 data->fan_ripple[index] = reg;
456 mutex_unlock(&data->update_lock);
461 static ssize_t show_fan_alarm(struct device *dev,
462 struct device_attribute *devattr, char *buf)
464 int index = to_sensor_dev_attr(devattr)->index;
465 struct fschmd_data *data = fschmd_update_device(dev);
467 if (data->fan_status[index] & FSCHMD_FAN_ALARM)
468 return sprintf(buf, "1\n");
470 return sprintf(buf, "0\n");
473 static ssize_t show_fan_fault(struct device *dev,
474 struct device_attribute *devattr, char *buf)
476 int index = to_sensor_dev_attr(devattr)->index;
477 struct fschmd_data *data = fschmd_update_device(dev);
479 if (data->fan_status[index] & FSCHMD_FAN_NOT_PRESENT)
480 return sprintf(buf, "1\n");
482 return sprintf(buf, "0\n");
486 static ssize_t show_pwm_auto_point1_pwm(struct device *dev,
487 struct device_attribute *devattr, char *buf)
489 int index = to_sensor_dev_attr(devattr)->index;
490 struct fschmd_data *data = fschmd_update_device(dev);
491 int val = data->fan_min[index];
493 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */
494 if (val || data->kind == fscsyl - 1)
497 return sprintf(buf, "%d\n", val);
500 static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
501 struct device_attribute *devattr, const char *buf, size_t count)
503 int index = to_sensor_dev_attr(devattr)->index;
504 struct fschmd_data *data = dev_get_drvdata(dev);
505 unsigned long v = simple_strtoul(buf, NULL, 10);
507 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */
508 if (v || data->kind == fscsyl - 1) {
509 v = SENSORS_LIMIT(v, 128, 255);
510 v = (v - 128) * 2 + 1;
513 mutex_lock(&data->update_lock);
515 i2c_smbus_write_byte_data(to_i2c_client(dev),
516 FSCHMD_REG_FAN_MIN[data->kind][index], v);
517 data->fan_min[index] = v;
519 mutex_unlock(&data->update_lock);
525 /* The FSC hwmon family has the ability to force an attached alert led to flash
526 from software, we export this as an alert_led sysfs attr */
527 static ssize_t show_alert_led(struct device *dev,
528 struct device_attribute *devattr, char *buf)
530 struct fschmd_data *data = fschmd_update_device(dev);
532 if (data->global_control & FSCHMD_CONTROL_ALERT_LED)
533 return sprintf(buf, "1\n");
535 return sprintf(buf, "0\n");
538 static ssize_t store_alert_led(struct device *dev,
539 struct device_attribute *devattr, const char *buf, size_t count)
542 struct fschmd_data *data = dev_get_drvdata(dev);
543 unsigned long v = simple_strtoul(buf, NULL, 10);
545 mutex_lock(&data->update_lock);
547 reg = i2c_smbus_read_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL);
550 reg |= FSCHMD_CONTROL_ALERT_LED;
552 reg &= ~FSCHMD_CONTROL_ALERT_LED;
554 i2c_smbus_write_byte_data(to_i2c_client(dev), FSCHMD_REG_CONTROL, reg);
556 data->global_control = reg;
558 mutex_unlock(&data->update_lock);
563 static DEVICE_ATTR(alert_led, 0644, show_alert_led, store_alert_led);
565 static struct sensor_device_attribute fschmd_attr[] = {
566 SENSOR_ATTR(in0_input, 0444, show_in_value, NULL, 0),
567 SENSOR_ATTR(in1_input, 0444, show_in_value, NULL, 1),
568 SENSOR_ATTR(in2_input, 0444, show_in_value, NULL, 2),
569 SENSOR_ATTR(in3_input, 0444, show_in_value, NULL, 3),
570 SENSOR_ATTR(in4_input, 0444, show_in_value, NULL, 4),
571 SENSOR_ATTR(in5_input, 0444, show_in_value, NULL, 5),
574 static struct sensor_device_attribute fschmd_temp_attr[] = {
575 SENSOR_ATTR(temp1_input, 0444, show_temp_value, NULL, 0),
576 SENSOR_ATTR(temp1_max, 0644, show_temp_max, store_temp_max, 0),
577 SENSOR_ATTR(temp1_fault, 0444, show_temp_fault, NULL, 0),
578 SENSOR_ATTR(temp1_alarm, 0444, show_temp_alarm, NULL, 0),
579 SENSOR_ATTR(temp2_input, 0444, show_temp_value, NULL, 1),
580 SENSOR_ATTR(temp2_max, 0644, show_temp_max, store_temp_max, 1),
581 SENSOR_ATTR(temp2_fault, 0444, show_temp_fault, NULL, 1),
582 SENSOR_ATTR(temp2_alarm, 0444, show_temp_alarm, NULL, 1),
583 SENSOR_ATTR(temp3_input, 0444, show_temp_value, NULL, 2),
584 SENSOR_ATTR(temp3_max, 0644, show_temp_max, store_temp_max, 2),
585 SENSOR_ATTR(temp3_fault, 0444, show_temp_fault, NULL, 2),
586 SENSOR_ATTR(temp3_alarm, 0444, show_temp_alarm, NULL, 2),
587 SENSOR_ATTR(temp4_input, 0444, show_temp_value, NULL, 3),
588 SENSOR_ATTR(temp4_max, 0644, show_temp_max, store_temp_max, 3),
589 SENSOR_ATTR(temp4_fault, 0444, show_temp_fault, NULL, 3),
590 SENSOR_ATTR(temp4_alarm, 0444, show_temp_alarm, NULL, 3),
591 SENSOR_ATTR(temp5_input, 0444, show_temp_value, NULL, 4),
592 SENSOR_ATTR(temp5_max, 0644, show_temp_max, store_temp_max, 4),
593 SENSOR_ATTR(temp5_fault, 0444, show_temp_fault, NULL, 4),
594 SENSOR_ATTR(temp5_alarm, 0444, show_temp_alarm, NULL, 4),
595 SENSOR_ATTR(temp6_input, 0444, show_temp_value, NULL, 5),
596 SENSOR_ATTR(temp6_max, 0644, show_temp_max, store_temp_max, 5),
597 SENSOR_ATTR(temp6_fault, 0444, show_temp_fault, NULL, 5),
598 SENSOR_ATTR(temp6_alarm, 0444, show_temp_alarm, NULL, 5),
599 SENSOR_ATTR(temp7_input, 0444, show_temp_value, NULL, 6),
600 SENSOR_ATTR(temp7_max, 0644, show_temp_max, store_temp_max, 6),
601 SENSOR_ATTR(temp7_fault, 0444, show_temp_fault, NULL, 6),
602 SENSOR_ATTR(temp7_alarm, 0444, show_temp_alarm, NULL, 6),
603 SENSOR_ATTR(temp8_input, 0444, show_temp_value, NULL, 7),
604 SENSOR_ATTR(temp8_max, 0644, show_temp_max, store_temp_max, 7),
605 SENSOR_ATTR(temp8_fault, 0444, show_temp_fault, NULL, 7),
606 SENSOR_ATTR(temp8_alarm, 0444, show_temp_alarm, NULL, 7),
607 SENSOR_ATTR(temp9_input, 0444, show_temp_value, NULL, 8),
608 SENSOR_ATTR(temp9_max, 0644, show_temp_max, store_temp_max, 8),
609 SENSOR_ATTR(temp9_fault, 0444, show_temp_fault, NULL, 8),
610 SENSOR_ATTR(temp9_alarm, 0444, show_temp_alarm, NULL, 8),
611 SENSOR_ATTR(temp10_input, 0444, show_temp_value, NULL, 9),
612 SENSOR_ATTR(temp10_max, 0644, show_temp_max, store_temp_max, 9),
613 SENSOR_ATTR(temp10_fault, 0444, show_temp_fault, NULL, 9),
614 SENSOR_ATTR(temp10_alarm, 0444, show_temp_alarm, NULL, 9),
615 SENSOR_ATTR(temp11_input, 0444, show_temp_value, NULL, 10),
616 SENSOR_ATTR(temp11_max, 0644, show_temp_max, store_temp_max, 10),
617 SENSOR_ATTR(temp11_fault, 0444, show_temp_fault, NULL, 10),
618 SENSOR_ATTR(temp11_alarm, 0444, show_temp_alarm, NULL, 10),
621 static struct sensor_device_attribute fschmd_fan_attr[] = {
622 SENSOR_ATTR(fan1_input, 0444, show_fan_value, NULL, 0),
623 SENSOR_ATTR(fan1_div, 0644, show_fan_div, store_fan_div, 0),
624 SENSOR_ATTR(fan1_alarm, 0444, show_fan_alarm, NULL, 0),
625 SENSOR_ATTR(fan1_fault, 0444, show_fan_fault, NULL, 0),
626 SENSOR_ATTR(pwm1_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
627 store_pwm_auto_point1_pwm, 0),
628 SENSOR_ATTR(fan2_input, 0444, show_fan_value, NULL, 1),
629 SENSOR_ATTR(fan2_div, 0644, show_fan_div, store_fan_div, 1),
630 SENSOR_ATTR(fan2_alarm, 0444, show_fan_alarm, NULL, 1),
631 SENSOR_ATTR(fan2_fault, 0444, show_fan_fault, NULL, 1),
632 SENSOR_ATTR(pwm2_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
633 store_pwm_auto_point1_pwm, 1),
634 SENSOR_ATTR(fan3_input, 0444, show_fan_value, NULL, 2),
635 SENSOR_ATTR(fan3_div, 0644, show_fan_div, store_fan_div, 2),
636 SENSOR_ATTR(fan3_alarm, 0444, show_fan_alarm, NULL, 2),
637 SENSOR_ATTR(fan3_fault, 0444, show_fan_fault, NULL, 2),
638 SENSOR_ATTR(pwm3_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
639 store_pwm_auto_point1_pwm, 2),
640 SENSOR_ATTR(fan4_input, 0444, show_fan_value, NULL, 3),
641 SENSOR_ATTR(fan4_div, 0644, show_fan_div, store_fan_div, 3),
642 SENSOR_ATTR(fan4_alarm, 0444, show_fan_alarm, NULL, 3),
643 SENSOR_ATTR(fan4_fault, 0444, show_fan_fault, NULL, 3),
644 SENSOR_ATTR(pwm4_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
645 store_pwm_auto_point1_pwm, 3),
646 SENSOR_ATTR(fan5_input, 0444, show_fan_value, NULL, 4),
647 SENSOR_ATTR(fan5_div, 0644, show_fan_div, store_fan_div, 4),
648 SENSOR_ATTR(fan5_alarm, 0444, show_fan_alarm, NULL, 4),
649 SENSOR_ATTR(fan5_fault, 0444, show_fan_fault, NULL, 4),
650 SENSOR_ATTR(pwm5_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
651 store_pwm_auto_point1_pwm, 4),
652 SENSOR_ATTR(fan6_input, 0444, show_fan_value, NULL, 5),
653 SENSOR_ATTR(fan6_div, 0644, show_fan_div, store_fan_div, 5),
654 SENSOR_ATTR(fan6_alarm, 0444, show_fan_alarm, NULL, 5),
655 SENSOR_ATTR(fan6_fault, 0444, show_fan_fault, NULL, 5),
656 SENSOR_ATTR(pwm6_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
657 store_pwm_auto_point1_pwm, 5),
658 SENSOR_ATTR(fan7_input, 0444, show_fan_value, NULL, 6),
659 SENSOR_ATTR(fan7_div, 0644, show_fan_div, store_fan_div, 6),
660 SENSOR_ATTR(fan7_alarm, 0444, show_fan_alarm, NULL, 6),
661 SENSOR_ATTR(fan7_fault, 0444, show_fan_fault, NULL, 6),
662 SENSOR_ATTR(pwm7_auto_point1_pwm, 0644, show_pwm_auto_point1_pwm,
663 store_pwm_auto_point1_pwm, 6),
671 static int watchdog_set_timeout(struct fschmd_data *data, int timeout)
674 int kind = data->kind + 1; /* 0-x array index -> 1-x module param */
676 /* 2 second or 60 second resolution? */
677 if (timeout <= 510 || kind == fscpos || kind == fscscy)
682 if (timeout < resolution || timeout > (resolution * 255))
685 mutex_lock(&data->watchdog_lock);
692 data->watchdog_control &= ~FSCHMD_WDOG_CONTROL_RESOLUTION;
694 data->watchdog_control |= FSCHMD_WDOG_CONTROL_RESOLUTION;
696 data->watchdog_preset = DIV_ROUND_UP(timeout, resolution);
698 /* Write new timeout value */
699 i2c_smbus_write_byte_data(data->client,
700 FSCHMD_REG_WDOG_PRESET[data->kind], data->watchdog_preset);
701 /* Write new control register, do not trigger! */
702 i2c_smbus_write_byte_data(data->client,
703 FSCHMD_REG_WDOG_CONTROL[data->kind],
704 data->watchdog_control & ~FSCHMD_WDOG_CONTROL_TRIGGER);
706 ret = data->watchdog_preset * resolution;
709 mutex_unlock(&data->watchdog_lock);
713 static int watchdog_get_timeout(struct fschmd_data *data)
717 mutex_lock(&data->watchdog_lock);
718 if (data->watchdog_control & FSCHMD_WDOG_CONTROL_RESOLUTION)
719 timeout = data->watchdog_preset * 60;
721 timeout = data->watchdog_preset * 2;
722 mutex_unlock(&data->watchdog_lock);
727 static int watchdog_trigger(struct fschmd_data *data)
731 mutex_lock(&data->watchdog_lock);
737 data->watchdog_control |= FSCHMD_WDOG_CONTROL_TRIGGER;
738 i2c_smbus_write_byte_data(data->client,
739 FSCHMD_REG_WDOG_CONTROL[data->kind],
740 data->watchdog_control);
742 mutex_unlock(&data->watchdog_lock);
746 static int watchdog_stop(struct fschmd_data *data)
750 mutex_lock(&data->watchdog_lock);
756 data->watchdog_control &= ~FSCHMD_WDOG_CONTROL_STARTED;
757 /* Don't store the stop flag in our watchdog control register copy, as
758 its a write only bit (read always returns 0) */
759 i2c_smbus_write_byte_data(data->client,
760 FSCHMD_REG_WDOG_CONTROL[data->kind],
761 data->watchdog_control | FSCHMD_WDOG_CONTROL_STOP);
763 mutex_unlock(&data->watchdog_lock);
767 static int watchdog_open(struct inode *inode, struct file *filp)
769 struct fschmd_data *pos, *data = NULL;
771 /* We get called from drivers/char/misc.c with misc_mtx hold, and we
772 call misc_register() from fschmd_probe() with watchdog_data_mutex
773 hold, as misc_register() takes the misc_mtx lock, this is a possible
774 deadlock, so we use mutex_trylock here. */
775 if (!mutex_trylock(&watchdog_data_mutex))
777 list_for_each_entry(pos, &watchdog_data_list, list) {
778 if (pos->watchdog_miscdev.minor == iminor(inode)) {
783 /* Note we can never not have found data, so we don't check for this */
784 kref_get(&data->kref);
785 mutex_unlock(&watchdog_data_mutex);
787 if (test_and_set_bit(0, &data->watchdog_is_open))
790 /* Start the watchdog */
791 watchdog_trigger(data);
792 filp->private_data = data;
794 return nonseekable_open(inode, filp);
797 static int watchdog_release(struct inode *inode, struct file *filp)
799 struct fschmd_data *data = filp->private_data;
801 if (data->watchdog_expect_close) {
803 data->watchdog_expect_close = 0;
805 watchdog_trigger(data);
806 dev_crit(&data->client->dev,
807 "unexpected close, not stopping watchdog!\n");
810 clear_bit(0, &data->watchdog_is_open);
812 mutex_lock(&watchdog_data_mutex);
813 kref_put(&data->kref, fschmd_release_resources);
814 mutex_unlock(&watchdog_data_mutex);
819 static ssize_t watchdog_write(struct file *filp, const char __user *buf,
820 size_t count, loff_t *offset)
823 struct fschmd_data *data = filp->private_data;
829 /* Clear it in case it was set with a previous write */
830 data->watchdog_expect_close = 0;
832 for (i = 0; i != count; i++) {
834 if (get_user(c, buf + i))
837 data->watchdog_expect_close = 1;
840 ret = watchdog_trigger(data);
847 static int watchdog_ioctl(struct inode *inode, struct file *filp,
848 unsigned int cmd, unsigned long arg)
850 static struct watchdog_info ident = {
851 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
853 .identity = "FSC watchdog"
856 struct fschmd_data *data = filp->private_data;
859 case WDIOC_GETSUPPORT:
860 ident.firmware_version = data->revision;
862 ident.options |= WDIOF_MAGICCLOSE;
863 if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
867 case WDIOC_GETSTATUS:
868 ret = put_user(0, (int __user *)arg);
871 case WDIOC_GETBOOTSTATUS:
872 if (data->watchdog_state & FSCHMD_WDOG_STATE_CARDRESET)
873 ret = put_user(WDIOF_CARDRESET, (int __user *)arg);
875 ret = put_user(0, (int __user *)arg);
878 case WDIOC_KEEPALIVE:
879 ret = watchdog_trigger(data);
882 case WDIOC_GETTIMEOUT:
883 i = watchdog_get_timeout(data);
884 ret = put_user(i, (int __user *)arg);
887 case WDIOC_SETTIMEOUT:
888 if (get_user(i, (int __user *)arg)) {
892 ret = watchdog_set_timeout(data, i);
894 ret = put_user(ret, (int __user *)arg);
897 case WDIOC_SETOPTIONS:
898 if (get_user(i, (int __user *)arg)) {
903 if (i & WDIOS_DISABLECARD)
904 ret = watchdog_stop(data);
905 else if (i & WDIOS_ENABLECARD)
906 ret = watchdog_trigger(data);
918 static struct file_operations watchdog_fops = {
919 .owner = THIS_MODULE,
921 .open = watchdog_open,
922 .release = watchdog_release,
923 .write = watchdog_write,
924 .ioctl = watchdog_ioctl,
929 * Detect, register, unregister and update device functions
932 /* DMI decode routine to read voltage scaling factors from special DMI tables,
933 which are available on FSC machines with an fscher or later chip. */
934 static void fschmd_dmi_decode(const struct dmi_header *header, void *dummy)
936 int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
938 /* dmi code ugliness, we get passed the address of the contents of
939 a complete DMI record, but in the form of a dmi_header pointer, in
940 reality this address holds header->length bytes of which the header
941 are the first 4 bytes */
942 u8 *dmi_data = (u8 *)header;
944 /* We are looking for OEM-specific type 185 */
945 if (header->type != 185)
948 /* we are looking for what Siemens calls "subtype" 19, the subtype
949 is stored in byte 5 of the dmi block */
950 if (header->length < 5 || dmi_data[4] != 19)
953 /* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
954 consisting of what Siemens calls an "Entity" number, followed by
955 2 16-bit words in LSB first order */
956 for (i = 6; (i + 4) < header->length; i += 5) {
957 /* entity 1 - 3: voltage multiplier and offset */
958 if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
959 /* Our in sensors order and the DMI order differ */
960 const int shuffle[3] = { 1, 0, 2 };
961 int in = shuffle[dmi_data[i] - 1];
963 /* Check for twice the same entity */
964 if (found & (1 << in))
967 mult[in] = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
968 offset[in] = dmi_data[i + 3] | (dmi_data[i + 4] << 8);
973 /* entity 7: reference voltage */
974 if (dmi_data[i] == 7) {
975 /* Check for twice the same entity */
979 vref = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
986 for (i = 0; i < 3; i++) {
987 dmi_mult[i] = mult[i] * 10;
988 dmi_offset[i] = offset[i] * 10;
990 /* According to the docs there should be separate dmi entries
991 for the mult's and offsets of in3-5 of the syl, but on
992 my test machine these are not present */
993 dmi_mult[3] = dmi_mult[2];
994 dmi_mult[4] = dmi_mult[1];
995 dmi_mult[5] = dmi_mult[2];
996 dmi_offset[3] = dmi_offset[2];
997 dmi_offset[4] = dmi_offset[1];
998 dmi_offset[5] = dmi_offset[2];
1003 static int fschmd_detect(struct i2c_client *client, int kind,
1004 struct i2c_board_info *info)
1006 struct i2c_adapter *adapter = client->adapter;
1008 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1011 /* Detect & Identify the chip */
1015 id[0] = i2c_smbus_read_byte_data(client,
1016 FSCHMD_REG_IDENT_0);
1017 id[1] = i2c_smbus_read_byte_data(client,
1018 FSCHMD_REG_IDENT_1);
1019 id[2] = i2c_smbus_read_byte_data(client,
1020 FSCHMD_REG_IDENT_2);
1023 if (!strcmp(id, "PEG"))
1025 else if (!strcmp(id, "HER"))
1027 else if (!strcmp(id, "SCY"))
1029 else if (!strcmp(id, "HRC"))
1031 else if (!strcmp(id, "HMD"))
1033 else if (!strcmp(id, "HDS"))
1035 else if (!strcmp(id, "SYL"))
1041 strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE);
1046 static int fschmd_probe(struct i2c_client *client,
1047 const struct i2c_device_id *id)
1049 struct fschmd_data *data;
1050 const char * const names[7] = { "Poseidon", "Hermes", "Scylla",
1051 "Heracles", "Heimdall", "Hades", "Syleus" };
1052 const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 };
1054 enum chips kind = id->driver_data;
1056 data = kzalloc(sizeof(struct fschmd_data), GFP_KERNEL);
1060 i2c_set_clientdata(client, data);
1061 mutex_init(&data->update_lock);
1062 mutex_init(&data->watchdog_lock);
1063 INIT_LIST_HEAD(&data->list);
1064 kref_init(&data->kref);
1065 /* Store client pointer in our data struct for watchdog usage
1066 (where the client is found through a data ptr instead of the
1068 data->client = client;
1070 if (kind == fscpos) {
1071 /* The Poseidon has hardwired temp limits, fill these
1072 in for the alarm resetting code */
1073 data->temp_max[0] = 70 + 128;
1074 data->temp_max[1] = 50 + 128;
1075 data->temp_max[2] = 50 + 128;
1078 /* Read the special DMI table for fscher and newer chips */
1079 if ((kind == fscher || kind >= fschrc) && dmi_vref == -1) {
1080 dmi_walk(fschmd_dmi_decode, NULL);
1081 if (dmi_vref == -1) {
1082 dev_warn(&client->dev,
1083 "Couldn't get voltage scaling factors from "
1084 "BIOS DMI table, using builtin defaults\n");
1089 /* i2c kind goes from 1-6, we want from 0-5 to address arrays */
1090 data->kind = kind - 1;
1092 /* Read in some never changing registers */
1093 data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
1094 data->global_control = i2c_smbus_read_byte_data(client,
1095 FSCHMD_REG_CONTROL);
1096 data->watchdog_control = i2c_smbus_read_byte_data(client,
1097 FSCHMD_REG_WDOG_CONTROL[data->kind]);
1098 data->watchdog_state = i2c_smbus_read_byte_data(client,
1099 FSCHMD_REG_WDOG_STATE[data->kind]);
1100 data->watchdog_preset = i2c_smbus_read_byte_data(client,
1101 FSCHMD_REG_WDOG_PRESET[data->kind]);
1103 err = device_create_file(&client->dev, &dev_attr_alert_led);
1107 for (i = 0; i < FSCHMD_NO_VOLT_SENSORS[data->kind]; i++) {
1108 err = device_create_file(&client->dev,
1109 &fschmd_attr[i].dev_attr);
1114 for (i = 0; i < (FSCHMD_NO_TEMP_SENSORS[data->kind] * 4); i++) {
1115 /* Poseidon doesn't have TEMP_LIMIT registers */
1116 if (kind == fscpos && fschmd_temp_attr[i].dev_attr.show ==
1120 if (kind == fscsyl) {
1122 data->temp_status[i / 4] =
1123 i2c_smbus_read_byte_data(client,
1124 FSCHMD_REG_TEMP_STATE
1125 [data->kind][i / 4]);
1126 if (data->temp_status[i / 4] & FSCHMD_TEMP_DISABLED)
1130 err = device_create_file(&client->dev,
1131 &fschmd_temp_attr[i].dev_attr);
1136 for (i = 0; i < (FSCHMD_NO_FAN_SENSORS[data->kind] * 5); i++) {
1137 /* Poseidon doesn't have a FAN_MIN register for its 3rd fan */
1138 if (kind == fscpos &&
1139 !strcmp(fschmd_fan_attr[i].dev_attr.attr.name,
1140 "pwm3_auto_point1_pwm"))
1143 if (kind == fscsyl) {
1145 data->fan_status[i / 5] =
1146 i2c_smbus_read_byte_data(client,
1147 FSCHMD_REG_FAN_STATE
1148 [data->kind][i / 5]);
1149 if (data->fan_status[i / 5] & FSCHMD_FAN_DISABLED)
1153 err = device_create_file(&client->dev,
1154 &fschmd_fan_attr[i].dev_attr);
1159 data->hwmon_dev = hwmon_device_register(&client->dev);
1160 if (IS_ERR(data->hwmon_dev)) {
1161 err = PTR_ERR(data->hwmon_dev);
1162 data->hwmon_dev = NULL;
1166 /* We take the data_mutex lock early so that watchdog_open() cannot
1167 run when misc_register() has completed, but we've not yet added
1168 our data to the watchdog_data_list (and set the default timeout) */
1169 mutex_lock(&watchdog_data_mutex);
1170 for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
1171 /* Register our watchdog part */
1172 snprintf(data->watchdog_name, sizeof(data->watchdog_name),
1173 "watchdog%c", (i == 0) ? '\0' : ('0' + i));
1174 data->watchdog_miscdev.name = data->watchdog_name;
1175 data->watchdog_miscdev.fops = &watchdog_fops;
1176 data->watchdog_miscdev.minor = watchdog_minors[i];
1177 err = misc_register(&data->watchdog_miscdev);
1181 data->watchdog_miscdev.minor = 0;
1182 dev_err(&client->dev,
1183 "Registering watchdog chardev: %d\n", err);
1187 list_add(&data->list, &watchdog_data_list);
1188 watchdog_set_timeout(data, 60);
1189 dev_info(&client->dev,
1190 "Registered watchdog chardev major 10, minor: %d\n",
1191 watchdog_minors[i]);
1194 if (i == ARRAY_SIZE(watchdog_minors)) {
1195 data->watchdog_miscdev.minor = 0;
1196 dev_warn(&client->dev, "Couldn't register watchdog chardev "
1197 "(due to no free minor)\n");
1199 mutex_unlock(&watchdog_data_mutex);
1201 dev_info(&client->dev, "Detected FSC %s chip, revision: %d\n",
1202 names[data->kind], (int) data->revision);
1207 fschmd_remove(client); /* will also free data for us */
1211 static int fschmd_remove(struct i2c_client *client)
1213 struct fschmd_data *data = i2c_get_clientdata(client);
1216 /* Unregister the watchdog (if registered) */
1217 if (data->watchdog_miscdev.minor) {
1218 misc_deregister(&data->watchdog_miscdev);
1219 if (data->watchdog_is_open) {
1220 dev_warn(&client->dev,
1221 "i2c client detached with watchdog open! "
1222 "Stopping watchdog.\n");
1223 watchdog_stop(data);
1225 mutex_lock(&watchdog_data_mutex);
1226 list_del(&data->list);
1227 mutex_unlock(&watchdog_data_mutex);
1228 /* Tell the watchdog code the client is gone */
1229 mutex_lock(&data->watchdog_lock);
1230 data->client = NULL;
1231 mutex_unlock(&data->watchdog_lock);
1234 /* Check if registered in case we're called from fschmd_detect
1235 to cleanup after an error */
1236 if (data->hwmon_dev)
1237 hwmon_device_unregister(data->hwmon_dev);
1239 device_remove_file(&client->dev, &dev_attr_alert_led);
1240 for (i = 0; i < (FSCHMD_NO_VOLT_SENSORS[data->kind]); i++)
1241 device_remove_file(&client->dev, &fschmd_attr[i].dev_attr);
1242 for (i = 0; i < (FSCHMD_NO_TEMP_SENSORS[data->kind] * 4); i++)
1243 device_remove_file(&client->dev,
1244 &fschmd_temp_attr[i].dev_attr);
1245 for (i = 0; i < (FSCHMD_NO_FAN_SENSORS[data->kind] * 5); i++)
1246 device_remove_file(&client->dev,
1247 &fschmd_fan_attr[i].dev_attr);
1249 mutex_lock(&watchdog_data_mutex);
1250 kref_put(&data->kref, fschmd_release_resources);
1251 mutex_unlock(&watchdog_data_mutex);
1256 static struct fschmd_data *fschmd_update_device(struct device *dev)
1258 struct i2c_client *client = to_i2c_client(dev);
1259 struct fschmd_data *data = i2c_get_clientdata(client);
1262 mutex_lock(&data->update_lock);
1264 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
1266 for (i = 0; i < FSCHMD_NO_TEMP_SENSORS[data->kind]; i++) {
1267 data->temp_act[i] = i2c_smbus_read_byte_data(client,
1268 FSCHMD_REG_TEMP_ACT[data->kind][i]);
1269 data->temp_status[i] = i2c_smbus_read_byte_data(client,
1270 FSCHMD_REG_TEMP_STATE[data->kind][i]);
1272 /* The fscpos doesn't have TEMP_LIMIT registers */
1273 if (FSCHMD_REG_TEMP_LIMIT[data->kind][i])
1274 data->temp_max[i] = i2c_smbus_read_byte_data(
1276 FSCHMD_REG_TEMP_LIMIT[data->kind][i]);
1278 /* reset alarm if the alarm condition is gone,
1279 the chip doesn't do this itself */
1280 if ((data->temp_status[i] & FSCHMD_TEMP_ALARM_MASK) ==
1281 FSCHMD_TEMP_ALARM_MASK &&
1282 data->temp_act[i] < data->temp_max[i])
1283 i2c_smbus_write_byte_data(client,
1284 FSCHMD_REG_TEMP_STATE[data->kind][i],
1285 data->temp_status[i]);
1288 for (i = 0; i < FSCHMD_NO_FAN_SENSORS[data->kind]; i++) {
1289 data->fan_act[i] = i2c_smbus_read_byte_data(client,
1290 FSCHMD_REG_FAN_ACT[data->kind][i]);
1291 data->fan_status[i] = i2c_smbus_read_byte_data(client,
1292 FSCHMD_REG_FAN_STATE[data->kind][i]);
1293 data->fan_ripple[i] = i2c_smbus_read_byte_data(client,
1294 FSCHMD_REG_FAN_RIPPLE[data->kind][i]);
1296 /* The fscpos third fan doesn't have a fan_min */
1297 if (FSCHMD_REG_FAN_MIN[data->kind][i])
1298 data->fan_min[i] = i2c_smbus_read_byte_data(
1300 FSCHMD_REG_FAN_MIN[data->kind][i]);
1302 /* reset fan status if speed is back to > 0 */
1303 if ((data->fan_status[i] & FSCHMD_FAN_ALARM) &&
1305 i2c_smbus_write_byte_data(client,
1306 FSCHMD_REG_FAN_STATE[data->kind][i],
1307 data->fan_status[i]);
1310 for (i = 0; i < FSCHMD_NO_VOLT_SENSORS[data->kind]; i++)
1311 data->volt[i] = i2c_smbus_read_byte_data(client,
1312 FSCHMD_REG_VOLT[data->kind][i]);
1314 data->last_updated = jiffies;
1318 mutex_unlock(&data->update_lock);
1323 static int __init fschmd_init(void)
1325 return i2c_add_driver(&fschmd_driver);
1328 static void __exit fschmd_exit(void)
1330 i2c_del_driver(&fschmd_driver);
1333 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
1334 MODULE_DESCRIPTION("FSC Poseidon, Hermes, Scylla, Heracles, Heimdall, Hades "
1335 "and Syleus driver");
1336 MODULE_LICENSE("GPL");
1338 module_init(fschmd_init);
1339 module_exit(fschmd_exit);