1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2007 - 2009 Hans de Goede <hdegoede@redhat.com>
9 * Merged Fujitsu Siemens hwmon driver, supporting the Poseidon, Hermes,
10 * Scylla, Heracles, Heimdall, Hades and Syleus chips
12 * Based on the original 2.4 fscscy, 2.6 fscpos, 2.6 fscher and 2.6
13 * (candidate) fschmd drivers:
14 * Copyright (C) 2006 Thilo Cestonaro
15 * <thilo.cestonaro.external@fujitsu-siemens.com>
16 * Copyright (C) 2004, 2005 Stefan Ott <stefan@desire.ch>
17 * Copyright (C) 2003, 2004 Reinhard Nissl <rnissl@gmx.de>
18 * Copyright (c) 2001 Martin Knoblauch <mkn@teraport.de, knobi@knobisoft.de>
19 * Copyright (C) 2000 Hermann Jung <hej@odn.de>
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/jiffies.h>
26 #include <linux/i2c.h>
27 #include <linux/hwmon.h>
28 #include <linux/hwmon-sysfs.h>
29 #include <linux/err.h>
30 #include <linux/mutex.h>
31 #include <linux/sysfs.h>
32 #include <linux/dmi.h>
34 #include <linux/watchdog.h>
35 #include <linux/miscdevice.h>
36 #include <linux/uaccess.h>
37 #include <linux/kref.h>
39 /* Addresses to scan */
40 static const unsigned short normal_i2c
[] = { 0x73, I2C_CLIENT_END
};
42 /* Insmod parameters */
43 static bool nowayout
= WATCHDOG_NOWAYOUT
;
44 module_param(nowayout
, bool, 0);
45 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started (default="
46 __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
48 enum chips
{ fscpos
, fscher
, fscscy
, fschrc
, fschmd
, fschds
, fscsyl
};
51 * The FSCHMD registers and other defines
54 /* chip identification */
55 #define FSCHMD_REG_IDENT_0 0x00
56 #define FSCHMD_REG_IDENT_1 0x01
57 #define FSCHMD_REG_IDENT_2 0x02
58 #define FSCHMD_REG_REVISION 0x03
60 /* global control and status */
61 #define FSCHMD_REG_EVENT_STATE 0x04
62 #define FSCHMD_REG_CONTROL 0x05
64 #define FSCHMD_CONTROL_ALERT_LED 0x01
67 static const u8 FSCHMD_REG_WDOG_CONTROL
[7] = {
68 0x21, 0x21, 0x21, 0x21, 0x21, 0x28, 0x28 };
69 static const u8 FSCHMD_REG_WDOG_STATE
[7] = {
70 0x23, 0x23, 0x23, 0x23, 0x23, 0x29, 0x29 };
71 static const u8 FSCHMD_REG_WDOG_PRESET
[7] = {
72 0x28, 0x28, 0x28, 0x28, 0x28, 0x2a, 0x2a };
74 #define FSCHMD_WDOG_CONTROL_TRIGGER 0x10
75 #define FSCHMD_WDOG_CONTROL_STARTED 0x10 /* the same as trigger */
76 #define FSCHMD_WDOG_CONTROL_STOP 0x20
77 #define FSCHMD_WDOG_CONTROL_RESOLUTION 0x40
79 #define FSCHMD_WDOG_STATE_CARDRESET 0x02
81 /* voltages, weird order is to keep the same order as the old drivers */
82 static const u8 FSCHMD_REG_VOLT
[7][6] = {
83 { 0x45, 0x42, 0x48 }, /* pos */
84 { 0x45, 0x42, 0x48 }, /* her */
85 { 0x45, 0x42, 0x48 }, /* scy */
86 { 0x45, 0x42, 0x48 }, /* hrc */
87 { 0x45, 0x42, 0x48 }, /* hmd */
88 { 0x21, 0x20, 0x22 }, /* hds */
89 { 0x21, 0x20, 0x22, 0x23, 0x24, 0x25 }, /* syl */
92 static const int FSCHMD_NO_VOLT_SENSORS
[7] = { 3, 3, 3, 3, 3, 3, 6 };
95 * minimum pwm at which the fan is driven (pwm can be increased depending on
96 * the temp. Notice that for the scy some fans share there minimum speed.
97 * Also notice that with the scy the sensor order is different than with the
98 * other chips, this order was in the 2.4 driver and kept for consistency.
100 static const u8 FSCHMD_REG_FAN_MIN
[7][7] = {
101 { 0x55, 0x65 }, /* pos */
102 { 0x55, 0x65, 0xb5 }, /* her */
103 { 0x65, 0x65, 0x55, 0xa5, 0x55, 0xa5 }, /* scy */
104 { 0x55, 0x65, 0xa5, 0xb5 }, /* hrc */
105 { 0x55, 0x65, 0xa5, 0xb5, 0xc5 }, /* hmd */
106 { 0x55, 0x65, 0xa5, 0xb5, 0xc5 }, /* hds */
107 { 0x54, 0x64, 0x74, 0x84, 0x94, 0xa4, 0xb4 }, /* syl */
110 /* actual fan speed */
111 static const u8 FSCHMD_REG_FAN_ACT
[7][7] = {
112 { 0x0e, 0x6b, 0xab }, /* pos */
113 { 0x0e, 0x6b, 0xbb }, /* her */
114 { 0x6b, 0x6c, 0x0e, 0xab, 0x5c, 0xbb }, /* scy */
115 { 0x0e, 0x6b, 0xab, 0xbb }, /* hrc */
116 { 0x5b, 0x6b, 0xab, 0xbb, 0xcb }, /* hmd */
117 { 0x5b, 0x6b, 0xab, 0xbb, 0xcb }, /* hds */
118 { 0x57, 0x67, 0x77, 0x87, 0x97, 0xa7, 0xb7 }, /* syl */
121 /* fan status registers */
122 static const u8 FSCHMD_REG_FAN_STATE
[7][7] = {
123 { 0x0d, 0x62, 0xa2 }, /* pos */
124 { 0x0d, 0x62, 0xb2 }, /* her */
125 { 0x62, 0x61, 0x0d, 0xa2, 0x52, 0xb2 }, /* scy */
126 { 0x0d, 0x62, 0xa2, 0xb2 }, /* hrc */
127 { 0x52, 0x62, 0xa2, 0xb2, 0xc2 }, /* hmd */
128 { 0x52, 0x62, 0xa2, 0xb2, 0xc2 }, /* hds */
129 { 0x50, 0x60, 0x70, 0x80, 0x90, 0xa0, 0xb0 }, /* syl */
132 /* fan ripple / divider registers */
133 static const u8 FSCHMD_REG_FAN_RIPPLE
[7][7] = {
134 { 0x0f, 0x6f, 0xaf }, /* pos */
135 { 0x0f, 0x6f, 0xbf }, /* her */
136 { 0x6f, 0x6f, 0x0f, 0xaf, 0x0f, 0xbf }, /* scy */
137 { 0x0f, 0x6f, 0xaf, 0xbf }, /* hrc */
138 { 0x5f, 0x6f, 0xaf, 0xbf, 0xcf }, /* hmd */
139 { 0x5f, 0x6f, 0xaf, 0xbf, 0xcf }, /* hds */
140 { 0x56, 0x66, 0x76, 0x86, 0x96, 0xa6, 0xb6 }, /* syl */
143 static const int FSCHMD_NO_FAN_SENSORS
[7] = { 3, 3, 6, 4, 5, 5, 7 };
145 /* Fan status register bitmasks */
146 #define FSCHMD_FAN_ALARM 0x04 /* called fault by FSC! */
147 #define FSCHMD_FAN_NOT_PRESENT 0x08
148 #define FSCHMD_FAN_DISABLED 0x80
151 /* actual temperature registers */
152 static const u8 FSCHMD_REG_TEMP_ACT
[7][11] = {
153 { 0x64, 0x32, 0x35 }, /* pos */
154 { 0x64, 0x32, 0x35 }, /* her */
155 { 0x64, 0xD0, 0x32, 0x35 }, /* scy */
156 { 0x64, 0x32, 0x35 }, /* hrc */
157 { 0x70, 0x80, 0x90, 0xd0, 0xe0 }, /* hmd */
158 { 0x70, 0x80, 0x90, 0xd0, 0xe0 }, /* hds */
159 { 0x58, 0x68, 0x78, 0x88, 0x98, 0xa8, /* syl */
160 0xb8, 0xc8, 0xd8, 0xe8, 0xf8 },
163 /* temperature state registers */
164 static const u8 FSCHMD_REG_TEMP_STATE
[7][11] = {
165 { 0x71, 0x81, 0x91 }, /* pos */
166 { 0x71, 0x81, 0x91 }, /* her */
167 { 0x71, 0xd1, 0x81, 0x91 }, /* scy */
168 { 0x71, 0x81, 0x91 }, /* hrc */
169 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hmd */
170 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hds */
171 { 0x59, 0x69, 0x79, 0x89, 0x99, 0xa9, /* syl */
172 0xb9, 0xc9, 0xd9, 0xe9, 0xf9 },
176 * temperature high limit registers, FSC does not document these. Proven to be
177 * there with field testing on the fscher and fschrc, already supported / used
178 * in the fscscy 2.4 driver. FSC has confirmed that the fschmd has registers
179 * at these addresses, but doesn't want to confirm they are the same as with
182 static const u8 FSCHMD_REG_TEMP_LIMIT
[7][11] = {
183 { 0, 0, 0 }, /* pos */
184 { 0x76, 0x86, 0x96 }, /* her */
185 { 0x76, 0xd6, 0x86, 0x96 }, /* scy */
186 { 0x76, 0x86, 0x96 }, /* hrc */
187 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hmd */
188 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hds */
189 { 0x5a, 0x6a, 0x7a, 0x8a, 0x9a, 0xaa, /* syl */
190 0xba, 0xca, 0xda, 0xea, 0xfa },
194 * These were found through experimenting with an fscher, currently they are
195 * not used, but we keep them around for future reference.
196 * On the fscsyl AUTOP1 lives at 0x#c (so 0x5c for fan1, 0x6c for fan2, etc),
197 * AUTOP2 lives at 0x#e, and 0x#1 is a bitmask defining which temps influence
199 * static const u8 FSCHER_REG_TEMP_AUTOP1[] = { 0x73, 0x83, 0x93 };
200 * static const u8 FSCHER_REG_TEMP_AUTOP2[] = { 0x75, 0x85, 0x95 };
203 static const int FSCHMD_NO_TEMP_SENSORS
[7] = { 3, 3, 4, 3, 5, 5, 11 };
205 /* temp status register bitmasks */
206 #define FSCHMD_TEMP_WORKING 0x01
207 #define FSCHMD_TEMP_ALERT 0x02
208 #define FSCHMD_TEMP_DISABLED 0x80
209 /* there only really is an alarm if the sensor is working and alert == 1 */
210 #define FSCHMD_TEMP_ALARM_MASK \
211 (FSCHMD_TEMP_WORKING | FSCHMD_TEMP_ALERT)
214 * Functions declarations
217 static int fschmd_probe(struct i2c_client
*client
,
218 const struct i2c_device_id
*id
);
219 static int fschmd_detect(struct i2c_client
*client
,
220 struct i2c_board_info
*info
);
221 static int fschmd_remove(struct i2c_client
*client
);
222 static struct fschmd_data
*fschmd_update_device(struct device
*dev
);
225 * Driver data (common to all clients)
228 static const struct i2c_device_id fschmd_id
[] = {
229 { "fscpos", fscpos
},
230 { "fscher", fscher
},
231 { "fscscy", fscscy
},
232 { "fschrc", fschrc
},
233 { "fschmd", fschmd
},
234 { "fschds", fschds
},
235 { "fscsyl", fscsyl
},
238 MODULE_DEVICE_TABLE(i2c
, fschmd_id
);
240 static struct i2c_driver fschmd_driver
= {
241 .class = I2C_CLASS_HWMON
,
245 .probe
= fschmd_probe
,
246 .remove
= fschmd_remove
,
247 .id_table
= fschmd_id
,
248 .detect
= fschmd_detect
,
249 .address_list
= normal_i2c
,
253 * Client data (each client gets its own)
257 struct i2c_client
*client
;
258 struct device
*hwmon_dev
;
259 struct mutex update_lock
;
260 struct mutex watchdog_lock
;
261 struct list_head list
; /* member of the watchdog_data_list */
263 struct miscdevice watchdog_miscdev
;
265 unsigned long watchdog_is_open
;
266 char watchdog_expect_close
;
267 char watchdog_name
[10]; /* must be unique to avoid sysfs conflict */
268 char valid
; /* zero until following fields are valid */
269 unsigned long last_updated
; /* in jiffies */
271 /* register values */
272 u8 revision
; /* chip revision */
273 u8 global_control
; /* global control register */
274 u8 watchdog_control
; /* watchdog control register */
275 u8 watchdog_state
; /* watchdog status register */
276 u8 watchdog_preset
; /* watchdog counter preset on trigger val */
277 u8 volt
[6]; /* voltage */
278 u8 temp_act
[11]; /* temperature */
279 u8 temp_status
[11]; /* status of sensor */
280 u8 temp_max
[11]; /* high temp limit, notice: undocumented! */
281 u8 fan_act
[7]; /* fans revolutions per second */
282 u8 fan_status
[7]; /* fan status */
283 u8 fan_min
[7]; /* fan min value for rps */
284 u8 fan_ripple
[7]; /* divider for rps */
288 * Global variables to hold information read from special DMI tables, which are
289 * available on FSC machines with an fscher or later chip. There is no need to
290 * protect these with a lock as they are only modified from our attach function
291 * which always gets called with the i2c-core lock held and never accessed
292 * before the attach function is done with them.
294 static int dmi_mult
[6] = { 490, 200, 100, 100, 200, 100 };
295 static int dmi_offset
[6] = { 0, 0, 0, 0, 0, 0 };
296 static int dmi_vref
= -1;
299 * Somewhat ugly :( global data pointer list with all fschmd devices, so that
300 * we can find our device data as when using misc_register there is no other
301 * method to get to ones device data from the open fop.
303 static LIST_HEAD(watchdog_data_list
);
304 /* Note this lock not only protect list access, but also data.kref access */
305 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
311 static void fschmd_release_resources(struct kref
*ref
)
313 struct fschmd_data
*data
= container_of(ref
, struct fschmd_data
, kref
);
318 * Sysfs attr show / store functions
321 static ssize_t
in_value_show(struct device
*dev
,
322 struct device_attribute
*devattr
, char *buf
)
324 const int max_reading
[3] = { 14200, 6600, 3300 };
325 int index
= to_sensor_dev_attr(devattr
)->index
;
326 struct fschmd_data
*data
= fschmd_update_device(dev
);
328 if (data
->kind
== fscher
|| data
->kind
>= fschrc
)
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
temp_value_show(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
temp_max_show(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
temp_max_store(struct device
*dev
,
358 struct device_attribute
*devattr
,
359 const char *buf
, size_t count
)
361 int index
= to_sensor_dev_attr(devattr
)->index
;
362 struct fschmd_data
*data
= dev_get_drvdata(dev
);
366 err
= kstrtol(buf
, 10, &v
);
370 v
= clamp_val(v
/ 1000, -128, 127) + 128;
372 mutex_lock(&data
->update_lock
);
373 i2c_smbus_write_byte_data(to_i2c_client(dev
),
374 FSCHMD_REG_TEMP_LIMIT
[data
->kind
][index
], v
);
375 data
->temp_max
[index
] = v
;
376 mutex_unlock(&data
->update_lock
);
381 static ssize_t
temp_fault_show(struct device
*dev
,
382 struct device_attribute
*devattr
, char *buf
)
384 int index
= to_sensor_dev_attr(devattr
)->index
;
385 struct fschmd_data
*data
= fschmd_update_device(dev
);
387 /* bit 0 set means sensor working ok, so no fault! */
388 if (data
->temp_status
[index
] & FSCHMD_TEMP_WORKING
)
389 return sprintf(buf
, "0\n");
391 return sprintf(buf
, "1\n");
394 static ssize_t
temp_alarm_show(struct device
*dev
,
395 struct device_attribute
*devattr
, char *buf
)
397 int index
= to_sensor_dev_attr(devattr
)->index
;
398 struct fschmd_data
*data
= fschmd_update_device(dev
);
400 if ((data
->temp_status
[index
] & FSCHMD_TEMP_ALARM_MASK
) ==
401 FSCHMD_TEMP_ALARM_MASK
)
402 return sprintf(buf
, "1\n");
404 return sprintf(buf
, "0\n");
408 #define RPM_FROM_REG(val) ((val) * 60)
410 static ssize_t
fan_value_show(struct device
*dev
,
411 struct device_attribute
*devattr
, char *buf
)
413 int index
= to_sensor_dev_attr(devattr
)->index
;
414 struct fschmd_data
*data
= fschmd_update_device(dev
);
416 return sprintf(buf
, "%u\n", RPM_FROM_REG(data
->fan_act
[index
]));
419 static ssize_t
fan_div_show(struct device
*dev
,
420 struct device_attribute
*devattr
, char *buf
)
422 int index
= to_sensor_dev_attr(devattr
)->index
;
423 struct fschmd_data
*data
= fschmd_update_device(dev
);
425 /* bits 2..7 reserved => mask with 3 */
426 return sprintf(buf
, "%d\n", 1 << (data
->fan_ripple
[index
] & 3));
429 static ssize_t
fan_div_store(struct device
*dev
,
430 struct device_attribute
*devattr
,
431 const char *buf
, size_t count
)
434 int index
= to_sensor_dev_attr(devattr
)->index
;
435 struct fschmd_data
*data
= dev_get_drvdata(dev
);
436 /* supported values: 2, 4, 8 */
440 err
= kstrtoul(buf
, 10, &v
);
456 "fan_div value %lu not supported. Choose one of 2, 4 or 8!\n",
461 mutex_lock(&data
->update_lock
);
463 reg
= i2c_smbus_read_byte_data(to_i2c_client(dev
),
464 FSCHMD_REG_FAN_RIPPLE
[data
->kind
][index
]);
466 /* bits 2..7 reserved => mask with 0x03 */
470 i2c_smbus_write_byte_data(to_i2c_client(dev
),
471 FSCHMD_REG_FAN_RIPPLE
[data
->kind
][index
], reg
);
473 data
->fan_ripple
[index
] = reg
;
475 mutex_unlock(&data
->update_lock
);
480 static ssize_t
fan_alarm_show(struct device
*dev
,
481 struct device_attribute
*devattr
, char *buf
)
483 int index
= to_sensor_dev_attr(devattr
)->index
;
484 struct fschmd_data
*data
= fschmd_update_device(dev
);
486 if (data
->fan_status
[index
] & FSCHMD_FAN_ALARM
)
487 return sprintf(buf
, "1\n");
489 return sprintf(buf
, "0\n");
492 static ssize_t
fan_fault_show(struct device
*dev
,
493 struct device_attribute
*devattr
, char *buf
)
495 int index
= to_sensor_dev_attr(devattr
)->index
;
496 struct fschmd_data
*data
= fschmd_update_device(dev
);
498 if (data
->fan_status
[index
] & FSCHMD_FAN_NOT_PRESENT
)
499 return sprintf(buf
, "1\n");
501 return sprintf(buf
, "0\n");
505 static ssize_t
pwm_auto_point1_pwm_show(struct device
*dev
,
506 struct device_attribute
*devattr
,
509 int index
= to_sensor_dev_attr(devattr
)->index
;
510 struct fschmd_data
*data
= fschmd_update_device(dev
);
511 int val
= data
->fan_min
[index
];
513 /* 0 = allow turning off (except on the syl), 1-255 = 50-100% */
514 if (val
|| data
->kind
== fscsyl
)
517 return sprintf(buf
, "%d\n", val
);
520 static ssize_t
pwm_auto_point1_pwm_store(struct device
*dev
,
521 struct device_attribute
*devattr
,
522 const char *buf
, size_t count
)
524 int index
= to_sensor_dev_attr(devattr
)->index
;
525 struct fschmd_data
*data
= dev_get_drvdata(dev
);
529 err
= kstrtoul(buf
, 10, &v
);
533 /* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */
534 if (v
|| data
->kind
== fscsyl
) {
535 v
= clamp_val(v
, 128, 255);
536 v
= (v
- 128) * 2 + 1;
539 mutex_lock(&data
->update_lock
);
541 i2c_smbus_write_byte_data(to_i2c_client(dev
),
542 FSCHMD_REG_FAN_MIN
[data
->kind
][index
], v
);
543 data
->fan_min
[index
] = v
;
545 mutex_unlock(&data
->update_lock
);
552 * The FSC hwmon family has the ability to force an attached alert led to flash
553 * from software, we export this as an alert_led sysfs attr
555 static ssize_t
alert_led_show(struct device
*dev
,
556 struct device_attribute
*devattr
, char *buf
)
558 struct fschmd_data
*data
= fschmd_update_device(dev
);
560 if (data
->global_control
& FSCHMD_CONTROL_ALERT_LED
)
561 return sprintf(buf
, "1\n");
563 return sprintf(buf
, "0\n");
566 static ssize_t
alert_led_store(struct device
*dev
,
567 struct device_attribute
*devattr
, const char *buf
, size_t count
)
570 struct fschmd_data
*data
= dev_get_drvdata(dev
);
574 err
= kstrtoul(buf
, 10, &v
);
578 mutex_lock(&data
->update_lock
);
580 reg
= i2c_smbus_read_byte_data(to_i2c_client(dev
), FSCHMD_REG_CONTROL
);
583 reg
|= FSCHMD_CONTROL_ALERT_LED
;
585 reg
&= ~FSCHMD_CONTROL_ALERT_LED
;
587 i2c_smbus_write_byte_data(to_i2c_client(dev
), FSCHMD_REG_CONTROL
, reg
);
589 data
->global_control
= reg
;
591 mutex_unlock(&data
->update_lock
);
596 static DEVICE_ATTR_RW(alert_led
);
598 static struct sensor_device_attribute fschmd_attr
[] = {
599 SENSOR_ATTR_RO(in0_input
, in_value
, 0),
600 SENSOR_ATTR_RO(in1_input
, in_value
, 1),
601 SENSOR_ATTR_RO(in2_input
, in_value
, 2),
602 SENSOR_ATTR_RO(in3_input
, in_value
, 3),
603 SENSOR_ATTR_RO(in4_input
, in_value
, 4),
604 SENSOR_ATTR_RO(in5_input
, in_value
, 5),
607 static struct sensor_device_attribute fschmd_temp_attr
[] = {
608 SENSOR_ATTR_RO(temp1_input
, temp_value
, 0),
609 SENSOR_ATTR_RW(temp1_max
, temp_max
, 0),
610 SENSOR_ATTR_RO(temp1_fault
, temp_fault
, 0),
611 SENSOR_ATTR_RO(temp1_alarm
, temp_alarm
, 0),
612 SENSOR_ATTR_RO(temp2_input
, temp_value
, 1),
613 SENSOR_ATTR_RW(temp2_max
, temp_max
, 1),
614 SENSOR_ATTR_RO(temp2_fault
, temp_fault
, 1),
615 SENSOR_ATTR_RO(temp2_alarm
, temp_alarm
, 1),
616 SENSOR_ATTR_RO(temp3_input
, temp_value
, 2),
617 SENSOR_ATTR_RW(temp3_max
, temp_max
, 2),
618 SENSOR_ATTR_RO(temp3_fault
, temp_fault
, 2),
619 SENSOR_ATTR_RO(temp3_alarm
, temp_alarm
, 2),
620 SENSOR_ATTR_RO(temp4_input
, temp_value
, 3),
621 SENSOR_ATTR_RW(temp4_max
, temp_max
, 3),
622 SENSOR_ATTR_RO(temp4_fault
, temp_fault
, 3),
623 SENSOR_ATTR_RO(temp4_alarm
, temp_alarm
, 3),
624 SENSOR_ATTR_RO(temp5_input
, temp_value
, 4),
625 SENSOR_ATTR_RW(temp5_max
, temp_max
, 4),
626 SENSOR_ATTR_RO(temp5_fault
, temp_fault
, 4),
627 SENSOR_ATTR_RO(temp5_alarm
, temp_alarm
, 4),
628 SENSOR_ATTR_RO(temp6_input
, temp_value
, 5),
629 SENSOR_ATTR_RW(temp6_max
, temp_max
, 5),
630 SENSOR_ATTR_RO(temp6_fault
, temp_fault
, 5),
631 SENSOR_ATTR_RO(temp6_alarm
, temp_alarm
, 5),
632 SENSOR_ATTR_RO(temp7_input
, temp_value
, 6),
633 SENSOR_ATTR_RW(temp7_max
, temp_max
, 6),
634 SENSOR_ATTR_RO(temp7_fault
, temp_fault
, 6),
635 SENSOR_ATTR_RO(temp7_alarm
, temp_alarm
, 6),
636 SENSOR_ATTR_RO(temp8_input
, temp_value
, 7),
637 SENSOR_ATTR_RW(temp8_max
, temp_max
, 7),
638 SENSOR_ATTR_RO(temp8_fault
, temp_fault
, 7),
639 SENSOR_ATTR_RO(temp8_alarm
, temp_alarm
, 7),
640 SENSOR_ATTR_RO(temp9_input
, temp_value
, 8),
641 SENSOR_ATTR_RW(temp9_max
, temp_max
, 8),
642 SENSOR_ATTR_RO(temp9_fault
, temp_fault
, 8),
643 SENSOR_ATTR_RO(temp9_alarm
, temp_alarm
, 8),
644 SENSOR_ATTR_RO(temp10_input
, temp_value
, 9),
645 SENSOR_ATTR_RW(temp10_max
, temp_max
, 9),
646 SENSOR_ATTR_RO(temp10_fault
, temp_fault
, 9),
647 SENSOR_ATTR_RO(temp10_alarm
, temp_alarm
, 9),
648 SENSOR_ATTR_RO(temp11_input
, temp_value
, 10),
649 SENSOR_ATTR_RW(temp11_max
, temp_max
, 10),
650 SENSOR_ATTR_RO(temp11_fault
, temp_fault
, 10),
651 SENSOR_ATTR_RO(temp11_alarm
, temp_alarm
, 10),
654 static struct sensor_device_attribute fschmd_fan_attr
[] = {
655 SENSOR_ATTR_RO(fan1_input
, fan_value
, 0),
656 SENSOR_ATTR_RW(fan1_div
, fan_div
, 0),
657 SENSOR_ATTR_RO(fan1_alarm
, fan_alarm
, 0),
658 SENSOR_ATTR_RO(fan1_fault
, fan_fault
, 0),
659 SENSOR_ATTR_RW(pwm1_auto_point1_pwm
, pwm_auto_point1_pwm
, 0),
660 SENSOR_ATTR_RO(fan2_input
, fan_value
, 1),
661 SENSOR_ATTR_RW(fan2_div
, fan_div
, 1),
662 SENSOR_ATTR_RO(fan2_alarm
, fan_alarm
, 1),
663 SENSOR_ATTR_RO(fan2_fault
, fan_fault
, 1),
664 SENSOR_ATTR_RW(pwm2_auto_point1_pwm
, pwm_auto_point1_pwm
, 1),
665 SENSOR_ATTR_RO(fan3_input
, fan_value
, 2),
666 SENSOR_ATTR_RW(fan3_div
, fan_div
, 2),
667 SENSOR_ATTR_RO(fan3_alarm
, fan_alarm
, 2),
668 SENSOR_ATTR_RO(fan3_fault
, fan_fault
, 2),
669 SENSOR_ATTR_RW(pwm3_auto_point1_pwm
, pwm_auto_point1_pwm
, 2),
670 SENSOR_ATTR_RO(fan4_input
, fan_value
, 3),
671 SENSOR_ATTR_RW(fan4_div
, fan_div
, 3),
672 SENSOR_ATTR_RO(fan4_alarm
, fan_alarm
, 3),
673 SENSOR_ATTR_RO(fan4_fault
, fan_fault
, 3),
674 SENSOR_ATTR_RW(pwm4_auto_point1_pwm
, pwm_auto_point1_pwm
, 3),
675 SENSOR_ATTR_RO(fan5_input
, fan_value
, 4),
676 SENSOR_ATTR_RW(fan5_div
, fan_div
, 4),
677 SENSOR_ATTR_RO(fan5_alarm
, fan_alarm
, 4),
678 SENSOR_ATTR_RO(fan5_fault
, fan_fault
, 4),
679 SENSOR_ATTR_RW(pwm5_auto_point1_pwm
, pwm_auto_point1_pwm
, 4),
680 SENSOR_ATTR_RO(fan6_input
, fan_value
, 5),
681 SENSOR_ATTR_RW(fan6_div
, fan_div
, 5),
682 SENSOR_ATTR_RO(fan6_alarm
, fan_alarm
, 5),
683 SENSOR_ATTR_RO(fan6_fault
, fan_fault
, 5),
684 SENSOR_ATTR_RW(pwm6_auto_point1_pwm
, pwm_auto_point1_pwm
, 5),
685 SENSOR_ATTR_RO(fan7_input
, fan_value
, 6),
686 SENSOR_ATTR_RW(fan7_div
, fan_div
, 6),
687 SENSOR_ATTR_RO(fan7_alarm
, fan_alarm
, 6),
688 SENSOR_ATTR_RO(fan7_fault
, fan_fault
, 6),
689 SENSOR_ATTR_RW(pwm7_auto_point1_pwm
, pwm_auto_point1_pwm
, 6),
697 static int watchdog_set_timeout(struct fschmd_data
*data
, int timeout
)
700 int kind
= data
->kind
+ 1; /* 0-x array index -> 1-x module param */
702 /* 2 second or 60 second resolution? */
703 if (timeout
<= 510 || kind
== fscpos
|| kind
== fscscy
)
708 if (timeout
< resolution
|| timeout
> (resolution
* 255))
711 mutex_lock(&data
->watchdog_lock
);
718 data
->watchdog_control
&= ~FSCHMD_WDOG_CONTROL_RESOLUTION
;
720 data
->watchdog_control
|= FSCHMD_WDOG_CONTROL_RESOLUTION
;
722 data
->watchdog_preset
= DIV_ROUND_UP(timeout
, resolution
);
724 /* Write new timeout value */
725 i2c_smbus_write_byte_data(data
->client
,
726 FSCHMD_REG_WDOG_PRESET
[data
->kind
], data
->watchdog_preset
);
727 /* Write new control register, do not trigger! */
728 i2c_smbus_write_byte_data(data
->client
,
729 FSCHMD_REG_WDOG_CONTROL
[data
->kind
],
730 data
->watchdog_control
& ~FSCHMD_WDOG_CONTROL_TRIGGER
);
732 ret
= data
->watchdog_preset
* resolution
;
735 mutex_unlock(&data
->watchdog_lock
);
739 static int watchdog_get_timeout(struct fschmd_data
*data
)
743 mutex_lock(&data
->watchdog_lock
);
744 if (data
->watchdog_control
& FSCHMD_WDOG_CONTROL_RESOLUTION
)
745 timeout
= data
->watchdog_preset
* 60;
747 timeout
= data
->watchdog_preset
* 2;
748 mutex_unlock(&data
->watchdog_lock
);
753 static int watchdog_trigger(struct fschmd_data
*data
)
757 mutex_lock(&data
->watchdog_lock
);
763 data
->watchdog_control
|= FSCHMD_WDOG_CONTROL_TRIGGER
;
764 i2c_smbus_write_byte_data(data
->client
,
765 FSCHMD_REG_WDOG_CONTROL
[data
->kind
],
766 data
->watchdog_control
);
768 mutex_unlock(&data
->watchdog_lock
);
772 static int watchdog_stop(struct fschmd_data
*data
)
776 mutex_lock(&data
->watchdog_lock
);
782 data
->watchdog_control
&= ~FSCHMD_WDOG_CONTROL_STARTED
;
784 * Don't store the stop flag in our watchdog control register copy, as
785 * its a write only bit (read always returns 0)
787 i2c_smbus_write_byte_data(data
->client
,
788 FSCHMD_REG_WDOG_CONTROL
[data
->kind
],
789 data
->watchdog_control
| FSCHMD_WDOG_CONTROL_STOP
);
791 mutex_unlock(&data
->watchdog_lock
);
795 static int watchdog_open(struct inode
*inode
, struct file
*filp
)
797 struct fschmd_data
*pos
, *data
= NULL
;
798 int watchdog_is_open
;
801 * We get called from drivers/char/misc.c with misc_mtx hold, and we
802 * call misc_register() from fschmd_probe() with watchdog_data_mutex
803 * hold, as misc_register() takes the misc_mtx lock, this is a possible
804 * deadlock, so we use mutex_trylock here.
806 if (!mutex_trylock(&watchdog_data_mutex
))
808 list_for_each_entry(pos
, &watchdog_data_list
, list
) {
809 if (pos
->watchdog_miscdev
.minor
== iminor(inode
)) {
814 /* Note we can never not have found data, so we don't check for this */
815 watchdog_is_open
= test_and_set_bit(0, &data
->watchdog_is_open
);
816 if (!watchdog_is_open
)
817 kref_get(&data
->kref
);
818 mutex_unlock(&watchdog_data_mutex
);
820 if (watchdog_is_open
)
823 /* Start the watchdog */
824 watchdog_trigger(data
);
825 filp
->private_data
= data
;
827 return stream_open(inode
, filp
);
830 static int watchdog_release(struct inode
*inode
, struct file
*filp
)
832 struct fschmd_data
*data
= filp
->private_data
;
834 if (data
->watchdog_expect_close
) {
836 data
->watchdog_expect_close
= 0;
838 watchdog_trigger(data
);
839 dev_crit(&data
->client
->dev
,
840 "unexpected close, not stopping watchdog!\n");
843 clear_bit(0, &data
->watchdog_is_open
);
845 mutex_lock(&watchdog_data_mutex
);
846 kref_put(&data
->kref
, fschmd_release_resources
);
847 mutex_unlock(&watchdog_data_mutex
);
852 static ssize_t
watchdog_write(struct file
*filp
, const char __user
*buf
,
853 size_t count
, loff_t
*offset
)
856 struct fschmd_data
*data
= filp
->private_data
;
862 /* Clear it in case it was set with a previous write */
863 data
->watchdog_expect_close
= 0;
865 for (i
= 0; i
!= count
; i
++) {
867 if (get_user(c
, buf
+ i
))
870 data
->watchdog_expect_close
= 1;
873 ret
= watchdog_trigger(data
);
880 static long watchdog_ioctl(struct file
*filp
, unsigned int cmd
,
883 struct watchdog_info ident
= {
884 .options
= WDIOF_KEEPALIVEPING
| WDIOF_SETTIMEOUT
|
886 .identity
= "FSC watchdog"
889 struct fschmd_data
*data
= filp
->private_data
;
892 case WDIOC_GETSUPPORT
:
893 ident
.firmware_version
= data
->revision
;
895 ident
.options
|= WDIOF_MAGICCLOSE
;
896 if (copy_to_user((void __user
*)arg
, &ident
, sizeof(ident
)))
900 case WDIOC_GETSTATUS
:
901 ret
= put_user(0, (int __user
*)arg
);
904 case WDIOC_GETBOOTSTATUS
:
905 if (data
->watchdog_state
& FSCHMD_WDOG_STATE_CARDRESET
)
906 ret
= put_user(WDIOF_CARDRESET
, (int __user
*)arg
);
908 ret
= put_user(0, (int __user
*)arg
);
911 case WDIOC_KEEPALIVE
:
912 ret
= watchdog_trigger(data
);
915 case WDIOC_GETTIMEOUT
:
916 i
= watchdog_get_timeout(data
);
917 ret
= put_user(i
, (int __user
*)arg
);
920 case WDIOC_SETTIMEOUT
:
921 if (get_user(i
, (int __user
*)arg
)) {
925 ret
= watchdog_set_timeout(data
, i
);
927 ret
= put_user(ret
, (int __user
*)arg
);
930 case WDIOC_SETOPTIONS
:
931 if (get_user(i
, (int __user
*)arg
)) {
936 if (i
& WDIOS_DISABLECARD
)
937 ret
= watchdog_stop(data
);
938 else if (i
& WDIOS_ENABLECARD
)
939 ret
= watchdog_trigger(data
);
950 static const struct file_operations watchdog_fops
= {
951 .owner
= THIS_MODULE
,
953 .open
= watchdog_open
,
954 .release
= watchdog_release
,
955 .write
= watchdog_write
,
956 .unlocked_ioctl
= watchdog_ioctl
,
957 .compat_ioctl
= compat_ptr_ioctl
,
962 * Detect, register, unregister and update device functions
966 * DMI decode routine to read voltage scaling factors from special DMI tables,
967 * which are available on FSC machines with an fscher or later chip.
969 static void fschmd_dmi_decode(const struct dmi_header
*header
, void *dummy
)
971 int i
, mult
[3] = { 0 }, offset
[3] = { 0 }, vref
= 0, found
= 0;
974 * dmi code ugliness, we get passed the address of the contents of
975 * a complete DMI record, but in the form of a dmi_header pointer, in
976 * reality this address holds header->length bytes of which the header
977 * are the first 4 bytes
979 u8
*dmi_data
= (u8
*)header
;
981 /* We are looking for OEM-specific type 185 */
982 if (header
->type
!= 185)
986 * we are looking for what Siemens calls "subtype" 19, the subtype
987 * is stored in byte 5 of the dmi block
989 if (header
->length
< 5 || dmi_data
[4] != 19)
993 * After the subtype comes 1 unknown byte and then blocks of 5 bytes,
994 * consisting of what Siemens calls an "Entity" number, followed by
995 * 2 16-bit words in LSB first order
997 for (i
= 6; (i
+ 4) < header
->length
; i
+= 5) {
998 /* entity 1 - 3: voltage multiplier and offset */
999 if (dmi_data
[i
] >= 1 && dmi_data
[i
] <= 3) {
1000 /* Our in sensors order and the DMI order differ */
1001 const int shuffle
[3] = { 1, 0, 2 };
1002 int in
= shuffle
[dmi_data
[i
] - 1];
1004 /* Check for twice the same entity */
1005 if (found
& (1 << in
))
1008 mult
[in
] = dmi_data
[i
+ 1] | (dmi_data
[i
+ 2] << 8);
1009 offset
[in
] = dmi_data
[i
+ 3] | (dmi_data
[i
+ 4] << 8);
1014 /* entity 7: reference voltage */
1015 if (dmi_data
[i
] == 7) {
1016 /* Check for twice the same entity */
1020 vref
= dmi_data
[i
+ 1] | (dmi_data
[i
+ 2] << 8);
1026 if (found
== 0x0F) {
1027 for (i
= 0; i
< 3; i
++) {
1028 dmi_mult
[i
] = mult
[i
] * 10;
1029 dmi_offset
[i
] = offset
[i
] * 10;
1032 * According to the docs there should be separate dmi entries
1033 * for the mult's and offsets of in3-5 of the syl, but on
1034 * my test machine these are not present
1036 dmi_mult
[3] = dmi_mult
[2];
1037 dmi_mult
[4] = dmi_mult
[1];
1038 dmi_mult
[5] = dmi_mult
[2];
1039 dmi_offset
[3] = dmi_offset
[2];
1040 dmi_offset
[4] = dmi_offset
[1];
1041 dmi_offset
[5] = dmi_offset
[2];
1046 static int fschmd_detect(struct i2c_client
*client
,
1047 struct i2c_board_info
*info
)
1050 struct i2c_adapter
*adapter
= client
->adapter
;
1053 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
1056 /* Detect & Identify the chip */
1057 id
[0] = i2c_smbus_read_byte_data(client
, FSCHMD_REG_IDENT_0
);
1058 id
[1] = i2c_smbus_read_byte_data(client
, FSCHMD_REG_IDENT_1
);
1059 id
[2] = i2c_smbus_read_byte_data(client
, FSCHMD_REG_IDENT_2
);
1062 if (!strcmp(id
, "PEG"))
1064 else if (!strcmp(id
, "HER"))
1066 else if (!strcmp(id
, "SCY"))
1068 else if (!strcmp(id
, "HRC"))
1070 else if (!strcmp(id
, "HMD"))
1072 else if (!strcmp(id
, "HDS"))
1074 else if (!strcmp(id
, "SYL"))
1079 strlcpy(info
->type
, fschmd_id
[kind
].name
, I2C_NAME_SIZE
);
1084 static int fschmd_probe(struct i2c_client
*client
,
1085 const struct i2c_device_id
*id
)
1087 struct fschmd_data
*data
;
1088 const char * const names
[7] = { "Poseidon", "Hermes", "Scylla",
1089 "Heracles", "Heimdall", "Hades", "Syleus" };
1090 const int watchdog_minors
[] = { WATCHDOG_MINOR
, 212, 213, 214, 215 };
1092 enum chips kind
= id
->driver_data
;
1094 data
= kzalloc(sizeof(struct fschmd_data
), GFP_KERNEL
);
1098 i2c_set_clientdata(client
, data
);
1099 mutex_init(&data
->update_lock
);
1100 mutex_init(&data
->watchdog_lock
);
1101 INIT_LIST_HEAD(&data
->list
);
1102 kref_init(&data
->kref
);
1104 * Store client pointer in our data struct for watchdog usage
1105 * (where the client is found through a data ptr instead of the
1108 data
->client
= client
;
1111 if (kind
== fscpos
) {
1113 * The Poseidon has hardwired temp limits, fill these
1114 * in for the alarm resetting code
1116 data
->temp_max
[0] = 70 + 128;
1117 data
->temp_max
[1] = 50 + 128;
1118 data
->temp_max
[2] = 50 + 128;
1121 /* Read the special DMI table for fscher and newer chips */
1122 if ((kind
== fscher
|| kind
>= fschrc
) && dmi_vref
== -1) {
1123 dmi_walk(fschmd_dmi_decode
, NULL
);
1124 if (dmi_vref
== -1) {
1125 dev_warn(&client
->dev
,
1126 "Couldn't get voltage scaling factors from "
1127 "BIOS DMI table, using builtin defaults\n");
1132 /* Read in some never changing registers */
1133 data
->revision
= i2c_smbus_read_byte_data(client
, FSCHMD_REG_REVISION
);
1134 data
->global_control
= i2c_smbus_read_byte_data(client
,
1135 FSCHMD_REG_CONTROL
);
1136 data
->watchdog_control
= i2c_smbus_read_byte_data(client
,
1137 FSCHMD_REG_WDOG_CONTROL
[data
->kind
]);
1138 data
->watchdog_state
= i2c_smbus_read_byte_data(client
,
1139 FSCHMD_REG_WDOG_STATE
[data
->kind
]);
1140 data
->watchdog_preset
= i2c_smbus_read_byte_data(client
,
1141 FSCHMD_REG_WDOG_PRESET
[data
->kind
]);
1143 err
= device_create_file(&client
->dev
, &dev_attr_alert_led
);
1147 for (i
= 0; i
< FSCHMD_NO_VOLT_SENSORS
[data
->kind
]; i
++) {
1148 err
= device_create_file(&client
->dev
,
1149 &fschmd_attr
[i
].dev_attr
);
1154 for (i
= 0; i
< (FSCHMD_NO_TEMP_SENSORS
[data
->kind
] * 4); i
++) {
1155 /* Poseidon doesn't have TEMP_LIMIT registers */
1156 if (kind
== fscpos
&& fschmd_temp_attr
[i
].dev_attr
.show
==
1160 if (kind
== fscsyl
) {
1162 data
->temp_status
[i
/ 4] =
1163 i2c_smbus_read_byte_data(client
,
1164 FSCHMD_REG_TEMP_STATE
1165 [data
->kind
][i
/ 4]);
1166 if (data
->temp_status
[i
/ 4] & FSCHMD_TEMP_DISABLED
)
1170 err
= device_create_file(&client
->dev
,
1171 &fschmd_temp_attr
[i
].dev_attr
);
1176 for (i
= 0; i
< (FSCHMD_NO_FAN_SENSORS
[data
->kind
] * 5); i
++) {
1177 /* Poseidon doesn't have a FAN_MIN register for its 3rd fan */
1178 if (kind
== fscpos
&&
1179 !strcmp(fschmd_fan_attr
[i
].dev_attr
.attr
.name
,
1180 "pwm3_auto_point1_pwm"))
1183 if (kind
== fscsyl
) {
1185 data
->fan_status
[i
/ 5] =
1186 i2c_smbus_read_byte_data(client
,
1187 FSCHMD_REG_FAN_STATE
1188 [data
->kind
][i
/ 5]);
1189 if (data
->fan_status
[i
/ 5] & FSCHMD_FAN_DISABLED
)
1193 err
= device_create_file(&client
->dev
,
1194 &fschmd_fan_attr
[i
].dev_attr
);
1199 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
1200 if (IS_ERR(data
->hwmon_dev
)) {
1201 err
= PTR_ERR(data
->hwmon_dev
);
1202 data
->hwmon_dev
= NULL
;
1207 * We take the data_mutex lock early so that watchdog_open() cannot
1208 * run when misc_register() has completed, but we've not yet added
1209 * our data to the watchdog_data_list (and set the default timeout)
1211 mutex_lock(&watchdog_data_mutex
);
1212 for (i
= 0; i
< ARRAY_SIZE(watchdog_minors
); i
++) {
1213 /* Register our watchdog part */
1214 snprintf(data
->watchdog_name
, sizeof(data
->watchdog_name
),
1215 "watchdog%c", (i
== 0) ? '\0' : ('0' + i
));
1216 data
->watchdog_miscdev
.name
= data
->watchdog_name
;
1217 data
->watchdog_miscdev
.fops
= &watchdog_fops
;
1218 data
->watchdog_miscdev
.minor
= watchdog_minors
[i
];
1219 err
= misc_register(&data
->watchdog_miscdev
);
1223 data
->watchdog_miscdev
.minor
= 0;
1224 dev_err(&client
->dev
,
1225 "Registering watchdog chardev: %d\n", err
);
1229 list_add(&data
->list
, &watchdog_data_list
);
1230 watchdog_set_timeout(data
, 60);
1231 dev_info(&client
->dev
,
1232 "Registered watchdog chardev major 10, minor: %d\n",
1233 watchdog_minors
[i
]);
1236 if (i
== ARRAY_SIZE(watchdog_minors
)) {
1237 data
->watchdog_miscdev
.minor
= 0;
1238 dev_warn(&client
->dev
,
1239 "Couldn't register watchdog chardev (due to no free minor)\n");
1241 mutex_unlock(&watchdog_data_mutex
);
1243 dev_info(&client
->dev
, "Detected FSC %s chip, revision: %d\n",
1244 names
[data
->kind
], (int) data
->revision
);
1249 fschmd_remove(client
); /* will also free data for us */
1253 static int fschmd_remove(struct i2c_client
*client
)
1255 struct fschmd_data
*data
= i2c_get_clientdata(client
);
1258 /* Unregister the watchdog (if registered) */
1259 if (data
->watchdog_miscdev
.minor
) {
1260 misc_deregister(&data
->watchdog_miscdev
);
1261 if (data
->watchdog_is_open
) {
1262 dev_warn(&client
->dev
,
1263 "i2c client detached with watchdog open! "
1264 "Stopping watchdog.\n");
1265 watchdog_stop(data
);
1267 mutex_lock(&watchdog_data_mutex
);
1268 list_del(&data
->list
);
1269 mutex_unlock(&watchdog_data_mutex
);
1270 /* Tell the watchdog code the client is gone */
1271 mutex_lock(&data
->watchdog_lock
);
1272 data
->client
= NULL
;
1273 mutex_unlock(&data
->watchdog_lock
);
1277 * Check if registered in case we're called from fschmd_detect
1278 * to cleanup after an error
1280 if (data
->hwmon_dev
)
1281 hwmon_device_unregister(data
->hwmon_dev
);
1283 device_remove_file(&client
->dev
, &dev_attr_alert_led
);
1284 for (i
= 0; i
< (FSCHMD_NO_VOLT_SENSORS
[data
->kind
]); i
++)
1285 device_remove_file(&client
->dev
, &fschmd_attr
[i
].dev_attr
);
1286 for (i
= 0; i
< (FSCHMD_NO_TEMP_SENSORS
[data
->kind
] * 4); i
++)
1287 device_remove_file(&client
->dev
,
1288 &fschmd_temp_attr
[i
].dev_attr
);
1289 for (i
= 0; i
< (FSCHMD_NO_FAN_SENSORS
[data
->kind
] * 5); i
++)
1290 device_remove_file(&client
->dev
,
1291 &fschmd_fan_attr
[i
].dev_attr
);
1293 mutex_lock(&watchdog_data_mutex
);
1294 kref_put(&data
->kref
, fschmd_release_resources
);
1295 mutex_unlock(&watchdog_data_mutex
);
1300 static struct fschmd_data
*fschmd_update_device(struct device
*dev
)
1302 struct i2c_client
*client
= to_i2c_client(dev
);
1303 struct fschmd_data
*data
= i2c_get_clientdata(client
);
1306 mutex_lock(&data
->update_lock
);
1308 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
) || !data
->valid
) {
1310 for (i
= 0; i
< FSCHMD_NO_TEMP_SENSORS
[data
->kind
]; i
++) {
1311 data
->temp_act
[i
] = i2c_smbus_read_byte_data(client
,
1312 FSCHMD_REG_TEMP_ACT
[data
->kind
][i
]);
1313 data
->temp_status
[i
] = i2c_smbus_read_byte_data(client
,
1314 FSCHMD_REG_TEMP_STATE
[data
->kind
][i
]);
1316 /* The fscpos doesn't have TEMP_LIMIT registers */
1317 if (FSCHMD_REG_TEMP_LIMIT
[data
->kind
][i
])
1318 data
->temp_max
[i
] = i2c_smbus_read_byte_data(
1320 FSCHMD_REG_TEMP_LIMIT
[data
->kind
][i
]);
1323 * reset alarm if the alarm condition is gone,
1324 * the chip doesn't do this itself
1326 if ((data
->temp_status
[i
] & FSCHMD_TEMP_ALARM_MASK
) ==
1327 FSCHMD_TEMP_ALARM_MASK
&&
1328 data
->temp_act
[i
] < data
->temp_max
[i
])
1329 i2c_smbus_write_byte_data(client
,
1330 FSCHMD_REG_TEMP_STATE
[data
->kind
][i
],
1331 data
->temp_status
[i
]);
1334 for (i
= 0; i
< FSCHMD_NO_FAN_SENSORS
[data
->kind
]; i
++) {
1335 data
->fan_act
[i
] = i2c_smbus_read_byte_data(client
,
1336 FSCHMD_REG_FAN_ACT
[data
->kind
][i
]);
1337 data
->fan_status
[i
] = i2c_smbus_read_byte_data(client
,
1338 FSCHMD_REG_FAN_STATE
[data
->kind
][i
]);
1339 data
->fan_ripple
[i
] = i2c_smbus_read_byte_data(client
,
1340 FSCHMD_REG_FAN_RIPPLE
[data
->kind
][i
]);
1342 /* The fscpos third fan doesn't have a fan_min */
1343 if (FSCHMD_REG_FAN_MIN
[data
->kind
][i
])
1344 data
->fan_min
[i
] = i2c_smbus_read_byte_data(
1346 FSCHMD_REG_FAN_MIN
[data
->kind
][i
]);
1348 /* reset fan status if speed is back to > 0 */
1349 if ((data
->fan_status
[i
] & FSCHMD_FAN_ALARM
) &&
1351 i2c_smbus_write_byte_data(client
,
1352 FSCHMD_REG_FAN_STATE
[data
->kind
][i
],
1353 data
->fan_status
[i
]);
1356 for (i
= 0; i
< FSCHMD_NO_VOLT_SENSORS
[data
->kind
]; i
++)
1357 data
->volt
[i
] = i2c_smbus_read_byte_data(client
,
1358 FSCHMD_REG_VOLT
[data
->kind
][i
]);
1360 data
->last_updated
= jiffies
;
1364 mutex_unlock(&data
->update_lock
);
1369 module_i2c_driver(fschmd_driver
);
1371 MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
1372 MODULE_DESCRIPTION("FSC Poseidon, Hermes, Scylla, Heracles, Heimdall, Hades "
1373 "and Syleus driver");
1374 MODULE_LICENSE("GPL");