3 * Copyright (C) 2007 Hans de Goede <j.w.r.degoede@hhs.nl>
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 and Heimdall 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 /* Addresses to scan */
47 static unsigned short normal_i2c
[] = { 0x73, I2C_CLIENT_END
};
49 /* Insmod parameters */
50 I2C_CLIENT_INSMOD_5(fscpos
, fscher
, fscscy
, fschrc
, fschmd
);
53 * The FSCHMD registers and other defines
56 /* chip identification */
57 #define FSCHMD_REG_IDENT_0 0x00
58 #define FSCHMD_REG_IDENT_1 0x01
59 #define FSCHMD_REG_IDENT_2 0x02
60 #define FSCHMD_REG_REVISION 0x03
62 /* global control and status */
63 #define FSCHMD_REG_EVENT_STATE 0x04
64 #define FSCHMD_REG_CONTROL 0x05
66 #define FSCHMD_CONTROL_ALERT_LED_MASK 0x01
68 /* watchdog (support to be implemented) */
69 #define FSCHMD_REG_WDOG_PRESET 0x28
70 #define FSCHMD_REG_WDOG_STATE 0x23
71 #define FSCHMD_REG_WDOG_CONTROL 0x21
73 /* voltages, weird order is to keep the same order as the old drivers */
74 static const u8 FSCHMD_REG_VOLT
[3] = { 0x45, 0x42, 0x48 };
76 /* minimum pwm at which the fan is driven (pwm can by increased depending on
77 the temp. Notice that for the scy some fans share there minimum speed.
78 Also notice that with the scy the sensor order is different then with the
79 other chips, this order was in the 2.4 driver and kept for consistency. */
80 static const u8 FSCHMD_REG_FAN_MIN
[5][6] = {
81 { 0x55, 0x65 }, /* pos */
82 { 0x55, 0x65, 0xb5 }, /* her */
83 { 0x65, 0x65, 0x55, 0xa5, 0x55, 0xa5 }, /* scy */
84 { 0x55, 0x65, 0xa5, 0xb5 }, /* hrc */
85 { 0x55, 0x65, 0xa5, 0xb5, 0xc5 }, /* hmd */
88 /* actual fan speed */
89 static const u8 FSCHMD_REG_FAN_ACT
[5][6] = {
90 { 0x0e, 0x6b, 0xab }, /* pos */
91 { 0x0e, 0x6b, 0xbb }, /* her */
92 { 0x6b, 0x6c, 0x0e, 0xab, 0x5c, 0xbb }, /* scy */
93 { 0x0e, 0x6b, 0xab, 0xbb }, /* hrc */
94 { 0x5b, 0x6b, 0xab, 0xbb, 0xcb }, /* hmd */
97 /* fan status registers */
98 static const u8 FSCHMD_REG_FAN_STATE
[5][6] = {
99 { 0x0d, 0x62, 0xa2 }, /* pos */
100 { 0x0d, 0x62, 0xb2 }, /* her */
101 { 0x62, 0x61, 0x0d, 0xa2, 0x52, 0xb2 }, /* scy */
102 { 0x0d, 0x62, 0xa2, 0xb2 }, /* hrc */
103 { 0x52, 0x62, 0xa2, 0xb2, 0xc2 }, /* hmd */
106 /* fan ripple / divider registers */
107 static const u8 FSCHMD_REG_FAN_RIPPLE
[5][6] = {
108 { 0x0f, 0x6f, 0xaf }, /* pos */
109 { 0x0f, 0x6f, 0xbf }, /* her */
110 { 0x6f, 0x6f, 0x0f, 0xaf, 0x0f, 0xbf }, /* scy */
111 { 0x0f, 0x6f, 0xaf, 0xbf }, /* hrc */
112 { 0x5f, 0x6f, 0xaf, 0xbf, 0xcf }, /* hmd */
115 static const int FSCHMD_NO_FAN_SENSORS
[5] = { 3, 3, 6, 4, 5 };
117 /* Fan status register bitmasks */
118 #define FSCHMD_FAN_ALARM_MASK 0x04 /* called fault by FSC! */
119 #define FSCHMD_FAN_NOT_PRESENT_MASK 0x08 /* not documented */
122 /* actual temperature registers */
123 static const u8 FSCHMD_REG_TEMP_ACT
[5][5] = {
124 { 0x64, 0x32, 0x35 }, /* pos */
125 { 0x64, 0x32, 0x35 }, /* her */
126 { 0x64, 0xD0, 0x32, 0x35 }, /* scy */
127 { 0x64, 0x32, 0x35 }, /* hrc */
128 { 0x70, 0x80, 0x90, 0xd0, 0xe0 }, /* hmd */
131 /* temperature state registers */
132 static const u8 FSCHMD_REG_TEMP_STATE
[5][5] = {
133 { 0x71, 0x81, 0x91 }, /* pos */
134 { 0x71, 0x81, 0x91 }, /* her */
135 { 0x71, 0xd1, 0x81, 0x91 }, /* scy */
136 { 0x71, 0x81, 0x91 }, /* hrc */
137 { 0x71, 0x81, 0x91, 0xd1, 0xe1 }, /* hmd */
140 /* temperature high limit registers, FSC does not document these. Proven to be
141 there with field testing on the fscher and fschrc, already supported / used
142 in the fscscy 2.4 driver. FSC has confirmed that the fschmd has registers
143 at these addresses, but doesn't want to confirm they are the same as with
145 static const u8 FSCHMD_REG_TEMP_LIMIT
[5][5] = {
146 { 0, 0, 0 }, /* pos */
147 { 0x76, 0x86, 0x96 }, /* her */
148 { 0x76, 0xd6, 0x86, 0x96 }, /* scy */
149 { 0x76, 0x86, 0x96 }, /* hrc */
150 { 0x76, 0x86, 0x96, 0xd6, 0xe6 }, /* hmd */
153 /* These were found through experimenting with an fscher, currently they are
154 not used, but we keep them around for future reference.
155 static const u8 FSCHER_REG_TEMP_AUTOP1[] = { 0x73, 0x83, 0x93 };
156 static const u8 FSCHER_REG_TEMP_AUTOP2[] = { 0x75, 0x85, 0x95 }; */
158 static const int FSCHMD_NO_TEMP_SENSORS
[5] = { 3, 3, 4, 3, 5 };
160 /* temp status register bitmasks */
161 #define FSCHMD_TEMP_WORKING_MASK 0x01
162 #define FSCHMD_TEMP_ALERT_MASK 0x02
163 /* there only really is an alarm if the sensor is working and alert == 1 */
164 #define FSCHMD_TEMP_ALARM_MASK \
165 (FSCHMD_TEMP_WORKING_MASK | FSCHMD_TEMP_ALERT_MASK)
167 /* our driver name */
168 #define FSCHMD_NAME "fschmd"
171 * Functions declarations
174 static int fschmd_attach_adapter(struct i2c_adapter
*adapter
);
175 static int fschmd_detach_client(struct i2c_client
*client
);
176 static struct fschmd_data
*fschmd_update_device(struct device
*dev
);
179 * Driver data (common to all clients)
182 static struct i2c_driver fschmd_driver
= {
186 .attach_adapter
= fschmd_attach_adapter
,
187 .detach_client
= fschmd_detach_client
,
191 * Client data (each client gets its own)
195 struct i2c_client client
;
196 struct device
*hwmon_dev
;
197 struct mutex update_lock
;
199 char valid
; /* zero until following fields are valid */
200 unsigned long last_updated
; /* in jiffies */
202 /* register values */
203 u8 global_control
; /* global control register */
204 u8 volt
[3]; /* 12, 5, battery voltage */
205 u8 temp_act
[5]; /* temperature */
206 u8 temp_status
[5]; /* status of sensor */
207 u8 temp_max
[5]; /* high temp limit, notice: undocumented! */
208 u8 fan_act
[6]; /* fans revolutions per second */
209 u8 fan_status
[6]; /* fan status */
210 u8 fan_min
[6]; /* fan min value for rps */
211 u8 fan_ripple
[6]; /* divider for rps */
214 /* Global variables to hold information read from special DMI tables, which are
215 available on FSC machines with an fscher or later chip. */
216 static int dmi_mult
[3] = { 490, 200, 100 };
217 static int dmi_offset
[3] = { 0, 0, 0 };
218 static int dmi_vref
= -1;
222 * Sysfs attr show / store functions
225 static ssize_t
show_in_value(struct device
*dev
,
226 struct device_attribute
*devattr
, char *buf
)
228 const int max_reading
[3] = { 14200, 6600, 3300 };
229 int index
= to_sensor_dev_attr(devattr
)->index
;
230 struct fschmd_data
*data
= fschmd_update_device(dev
);
232 /* fscher / fschrc - 1 as data->kind is an array index, not a chips */
233 if (data
->kind
== (fscher
- 1) || data
->kind
>= (fschrc
- 1))
234 return sprintf(buf
, "%d\n", (data
->volt
[index
] * dmi_vref
*
235 dmi_mult
[index
]) / 255 + dmi_offset
[index
]);
237 return sprintf(buf
, "%d\n", (data
->volt
[index
] *
238 max_reading
[index
] + 128) / 255);
242 #define TEMP_FROM_REG(val) (((val) - 128) * 1000)
244 static ssize_t
show_temp_value(struct device
*dev
,
245 struct device_attribute
*devattr
, char *buf
)
247 int index
= to_sensor_dev_attr(devattr
)->index
;
248 struct fschmd_data
*data
= fschmd_update_device(dev
);
250 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_act
[index
]));
253 static ssize_t
show_temp_max(struct device
*dev
,
254 struct device_attribute
*devattr
, char *buf
)
256 int index
= to_sensor_dev_attr(devattr
)->index
;
257 struct fschmd_data
*data
= fschmd_update_device(dev
);
259 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max
[index
]));
262 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
263 *devattr
, const char *buf
, size_t count
)
265 int index
= to_sensor_dev_attr(devattr
)->index
;
266 struct fschmd_data
*data
= dev_get_drvdata(dev
);
267 long v
= simple_strtol(buf
, NULL
, 10) / 1000;
269 v
= SENSORS_LIMIT(v
, -128, 127) + 128;
271 mutex_lock(&data
->update_lock
);
272 i2c_smbus_write_byte_data(&data
->client
,
273 FSCHMD_REG_TEMP_LIMIT
[data
->kind
][index
], v
);
274 data
->temp_max
[index
] = v
;
275 mutex_unlock(&data
->update_lock
);
280 static ssize_t
show_temp_fault(struct device
*dev
,
281 struct device_attribute
*devattr
, char *buf
)
283 int index
= to_sensor_dev_attr(devattr
)->index
;
284 struct fschmd_data
*data
= fschmd_update_device(dev
);
286 /* bit 0 set means sensor working ok, so no fault! */
287 if (data
->temp_status
[index
] & FSCHMD_TEMP_WORKING_MASK
)
288 return sprintf(buf
, "0\n");
290 return sprintf(buf
, "1\n");
293 static ssize_t
show_temp_alarm(struct device
*dev
,
294 struct device_attribute
*devattr
, char *buf
)
296 int index
= to_sensor_dev_attr(devattr
)->index
;
297 struct fschmd_data
*data
= fschmd_update_device(dev
);
299 if ((data
->temp_status
[index
] & FSCHMD_TEMP_ALARM_MASK
) ==
300 FSCHMD_TEMP_ALARM_MASK
)
301 return sprintf(buf
, "1\n");
303 return sprintf(buf
, "0\n");
307 #define RPM_FROM_REG(val) ((val) * 60)
309 static ssize_t
show_fan_value(struct device
*dev
,
310 struct device_attribute
*devattr
, char *buf
)
312 int index
= to_sensor_dev_attr(devattr
)->index
;
313 struct fschmd_data
*data
= fschmd_update_device(dev
);
315 return sprintf(buf
, "%u\n", RPM_FROM_REG(data
->fan_act
[index
]));
318 static ssize_t
show_fan_div(struct device
*dev
,
319 struct device_attribute
*devattr
, char *buf
)
321 int index
= to_sensor_dev_attr(devattr
)->index
;
322 struct fschmd_data
*data
= fschmd_update_device(dev
);
324 /* bits 2..7 reserved => mask with 3 */
325 return sprintf(buf
, "%d\n", 1 << (data
->fan_ripple
[index
] & 3));
328 static ssize_t
store_fan_div(struct device
*dev
, struct device_attribute
329 *devattr
, const char *buf
, size_t count
)
332 int index
= to_sensor_dev_attr(devattr
)->index
;
333 struct fschmd_data
*data
= dev_get_drvdata(dev
);
334 /* supported values: 2, 4, 8 */
335 unsigned long v
= simple_strtoul(buf
, NULL
, 10);
338 case 2: v
= 1; break;
339 case 4: v
= 2; break;
340 case 8: v
= 3; break;
342 dev_err(dev
, "fan_div value %lu not supported. "
343 "Choose one of 2, 4 or 8!\n", v
);
347 mutex_lock(&data
->update_lock
);
349 reg
= i2c_smbus_read_byte_data(&data
->client
,
350 FSCHMD_REG_FAN_RIPPLE
[data
->kind
][index
]);
352 /* bits 2..7 reserved => mask with 0x03 */
356 i2c_smbus_write_byte_data(&data
->client
,
357 FSCHMD_REG_FAN_RIPPLE
[data
->kind
][index
], reg
);
359 data
->fan_ripple
[index
] = reg
;
361 mutex_unlock(&data
->update_lock
);
366 static ssize_t
show_fan_alarm(struct device
*dev
,
367 struct device_attribute
*devattr
, char *buf
)
369 int index
= to_sensor_dev_attr(devattr
)->index
;
370 struct fschmd_data
*data
= fschmd_update_device(dev
);
372 if (data
->fan_status
[index
] & FSCHMD_FAN_ALARM_MASK
)
373 return sprintf(buf
, "1\n");
375 return sprintf(buf
, "0\n");
378 static ssize_t
show_fan_fault(struct device
*dev
,
379 struct device_attribute
*devattr
, char *buf
)
381 int index
= to_sensor_dev_attr(devattr
)->index
;
382 struct fschmd_data
*data
= fschmd_update_device(dev
);
384 if (data
->fan_status
[index
] & FSCHMD_FAN_NOT_PRESENT_MASK
)
385 return sprintf(buf
, "1\n");
387 return sprintf(buf
, "0\n");
391 static ssize_t
show_pwm_auto_point1_pwm(struct device
*dev
,
392 struct device_attribute
*devattr
, char *buf
)
394 int index
= to_sensor_dev_attr(devattr
)->index
;
395 int val
= fschmd_update_device(dev
)->fan_min
[index
];
397 /* 0 = allow turning off, 1-255 = 50-100% */
401 return sprintf(buf
, "%d\n", val
);
404 static ssize_t
store_pwm_auto_point1_pwm(struct device
*dev
,
405 struct device_attribute
*devattr
, const char *buf
, size_t count
)
407 int index
= to_sensor_dev_attr(devattr
)->index
;
408 struct fschmd_data
*data
= dev_get_drvdata(dev
);
409 unsigned long v
= simple_strtoul(buf
, NULL
, 10);
411 /* register: 0 = allow turning off, 1-255 = 50-100% */
413 v
= SENSORS_LIMIT(v
, 128, 255);
414 v
= (v
- 128) * 2 + 1;
417 mutex_lock(&data
->update_lock
);
419 i2c_smbus_write_byte_data(&data
->client
,
420 FSCHMD_REG_FAN_MIN
[data
->kind
][index
], v
);
421 data
->fan_min
[index
] = v
;
423 mutex_unlock(&data
->update_lock
);
429 /* The FSC hwmon family has the ability to force an attached alert led to flash
430 from software, we export this as an alert_led sysfs attr */
431 static ssize_t
show_alert_led(struct device
*dev
,
432 struct device_attribute
*devattr
, char *buf
)
434 struct fschmd_data
*data
= fschmd_update_device(dev
);
436 if (data
->global_control
& FSCHMD_CONTROL_ALERT_LED_MASK
)
437 return sprintf(buf
, "1\n");
439 return sprintf(buf
, "0\n");
442 static ssize_t
store_alert_led(struct device
*dev
,
443 struct device_attribute
*devattr
, const char *buf
, size_t count
)
446 struct fschmd_data
*data
= dev_get_drvdata(dev
);
447 unsigned long v
= simple_strtoul(buf
, NULL
, 10);
449 mutex_lock(&data
->update_lock
);
451 reg
= i2c_smbus_read_byte_data(&data
->client
, FSCHMD_REG_CONTROL
);
454 reg
|= FSCHMD_CONTROL_ALERT_LED_MASK
;
456 reg
&= ~FSCHMD_CONTROL_ALERT_LED_MASK
;
458 i2c_smbus_write_byte_data(&data
->client
, FSCHMD_REG_CONTROL
, reg
);
460 data
->global_control
= reg
;
462 mutex_unlock(&data
->update_lock
);
467 static struct sensor_device_attribute fschmd_attr
[] = {
468 SENSOR_ATTR(in0_input
, 0444, show_in_value
, NULL
, 0),
469 SENSOR_ATTR(in1_input
, 0444, show_in_value
, NULL
, 1),
470 SENSOR_ATTR(in2_input
, 0444, show_in_value
, NULL
, 2),
471 SENSOR_ATTR(alert_led
, 0644, show_alert_led
, store_alert_led
, 0),
474 static struct sensor_device_attribute fschmd_temp_attr
[] = {
475 SENSOR_ATTR(temp1_input
, 0444, show_temp_value
, NULL
, 0),
476 SENSOR_ATTR(temp1_max
, 0644, show_temp_max
, store_temp_max
, 0),
477 SENSOR_ATTR(temp1_fault
, 0444, show_temp_fault
, NULL
, 0),
478 SENSOR_ATTR(temp1_alarm
, 0444, show_temp_alarm
, NULL
, 0),
479 SENSOR_ATTR(temp2_input
, 0444, show_temp_value
, NULL
, 1),
480 SENSOR_ATTR(temp2_max
, 0644, show_temp_max
, store_temp_max
, 1),
481 SENSOR_ATTR(temp2_fault
, 0444, show_temp_fault
, NULL
, 1),
482 SENSOR_ATTR(temp2_alarm
, 0444, show_temp_alarm
, NULL
, 1),
483 SENSOR_ATTR(temp3_input
, 0444, show_temp_value
, NULL
, 2),
484 SENSOR_ATTR(temp3_max
, 0644, show_temp_max
, store_temp_max
, 2),
485 SENSOR_ATTR(temp3_fault
, 0444, show_temp_fault
, NULL
, 2),
486 SENSOR_ATTR(temp3_alarm
, 0444, show_temp_alarm
, NULL
, 2),
487 SENSOR_ATTR(temp4_input
, 0444, show_temp_value
, NULL
, 3),
488 SENSOR_ATTR(temp4_max
, 0644, show_temp_max
, store_temp_max
, 3),
489 SENSOR_ATTR(temp4_fault
, 0444, show_temp_fault
, NULL
, 3),
490 SENSOR_ATTR(temp4_alarm
, 0444, show_temp_alarm
, NULL
, 3),
491 SENSOR_ATTR(temp5_input
, 0444, show_temp_value
, NULL
, 4),
492 SENSOR_ATTR(temp5_max
, 0644, show_temp_max
, store_temp_max
, 4),
493 SENSOR_ATTR(temp5_fault
, 0444, show_temp_fault
, NULL
, 4),
494 SENSOR_ATTR(temp5_alarm
, 0444, show_temp_alarm
, NULL
, 4),
497 static struct sensor_device_attribute fschmd_fan_attr
[] = {
498 SENSOR_ATTR(fan1_input
, 0444, show_fan_value
, NULL
, 0),
499 SENSOR_ATTR(fan1_div
, 0644, show_fan_div
, store_fan_div
, 0),
500 SENSOR_ATTR(fan1_alarm
, 0444, show_fan_alarm
, NULL
, 0),
501 SENSOR_ATTR(fan1_fault
, 0444, show_fan_fault
, NULL
, 0),
502 SENSOR_ATTR(pwm1_auto_point1_pwm
, 0644, show_pwm_auto_point1_pwm
,
503 store_pwm_auto_point1_pwm
, 0),
504 SENSOR_ATTR(fan2_input
, 0444, show_fan_value
, NULL
, 1),
505 SENSOR_ATTR(fan2_div
, 0644, show_fan_div
, store_fan_div
, 1),
506 SENSOR_ATTR(fan2_alarm
, 0444, show_fan_alarm
, NULL
, 1),
507 SENSOR_ATTR(fan2_fault
, 0444, show_fan_fault
, NULL
, 1),
508 SENSOR_ATTR(pwm2_auto_point1_pwm
, 0644, show_pwm_auto_point1_pwm
,
509 store_pwm_auto_point1_pwm
, 1),
510 SENSOR_ATTR(fan3_input
, 0444, show_fan_value
, NULL
, 2),
511 SENSOR_ATTR(fan3_div
, 0644, show_fan_div
, store_fan_div
, 2),
512 SENSOR_ATTR(fan3_alarm
, 0444, show_fan_alarm
, NULL
, 2),
513 SENSOR_ATTR(fan3_fault
, 0444, show_fan_fault
, NULL
, 2),
514 SENSOR_ATTR(pwm3_auto_point1_pwm
, 0644, show_pwm_auto_point1_pwm
,
515 store_pwm_auto_point1_pwm
, 2),
516 SENSOR_ATTR(fan4_input
, 0444, show_fan_value
, NULL
, 3),
517 SENSOR_ATTR(fan4_div
, 0644, show_fan_div
, store_fan_div
, 3),
518 SENSOR_ATTR(fan4_alarm
, 0444, show_fan_alarm
, NULL
, 3),
519 SENSOR_ATTR(fan4_fault
, 0444, show_fan_fault
, NULL
, 3),
520 SENSOR_ATTR(pwm4_auto_point1_pwm
, 0644, show_pwm_auto_point1_pwm
,
521 store_pwm_auto_point1_pwm
, 3),
522 SENSOR_ATTR(fan5_input
, 0444, show_fan_value
, NULL
, 4),
523 SENSOR_ATTR(fan5_div
, 0644, show_fan_div
, store_fan_div
, 4),
524 SENSOR_ATTR(fan5_alarm
, 0444, show_fan_alarm
, NULL
, 4),
525 SENSOR_ATTR(fan5_fault
, 0444, show_fan_fault
, NULL
, 4),
526 SENSOR_ATTR(pwm5_auto_point1_pwm
, 0644, show_pwm_auto_point1_pwm
,
527 store_pwm_auto_point1_pwm
, 4),
528 SENSOR_ATTR(fan6_input
, 0444, show_fan_value
, NULL
, 5),
529 SENSOR_ATTR(fan6_div
, 0644, show_fan_div
, store_fan_div
, 5),
530 SENSOR_ATTR(fan6_alarm
, 0444, show_fan_alarm
, NULL
, 5),
531 SENSOR_ATTR(fan6_fault
, 0444, show_fan_fault
, NULL
, 5),
532 SENSOR_ATTR(pwm6_auto_point1_pwm
, 0644, show_pwm_auto_point1_pwm
,
533 store_pwm_auto_point1_pwm
, 5),
541 /* DMI decode routine to read voltage scaling factors from special DMI tables,
542 which are available on FSC machines with an fscher or later chip. */
543 static void fschmd_dmi_decode(const struct dmi_header
*header
)
545 int i
, mult
[3] = { 0 }, offset
[3] = { 0 }, vref
= 0, found
= 0;
547 /* dmi code ugliness, we get passed the address of the contents of
548 a complete DMI record, but in the form of a dmi_header pointer, in
549 reality this address holds header->length bytes of which the header
550 are the first 4 bytes */
551 u8
*dmi_data
= (u8
*)header
;
553 /* We are looking for OEM-specific type 185 */
554 if (header
->type
!= 185)
557 /* we are looking for what Siemens calls "subtype" 19, the subtype
558 is stored in byte 5 of the dmi block */
559 if (header
->length
< 5 || dmi_data
[4] != 19)
562 /* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
563 consisting of what Siemens calls an "Entity" number, followed by
564 2 16-bit words in LSB first order */
565 for (i
= 6; (i
+ 4) < header
->length
; i
+= 5) {
566 /* entity 1 - 3: voltage multiplier and offset */
567 if (dmi_data
[i
] >= 1 && dmi_data
[i
] <= 3) {
568 /* Our in sensors order and the DMI order differ */
569 const int shuffle
[3] = { 1, 0, 2 };
570 int in
= shuffle
[dmi_data
[i
] - 1];
572 /* Check for twice the same entity */
573 if (found
& (1 << in
))
576 mult
[in
] = dmi_data
[i
+ 1] | (dmi_data
[i
+ 2] << 8);
577 offset
[in
] = dmi_data
[i
+ 3] | (dmi_data
[i
+ 4] << 8);
582 /* entity 7: reference voltage */
583 if (dmi_data
[i
] == 7) {
584 /* Check for twice the same entity */
588 vref
= dmi_data
[i
+ 1] | (dmi_data
[i
+ 2] << 8);
595 for (i
= 0; i
< 3; i
++) {
596 dmi_mult
[i
] = mult
[i
] * 10;
597 dmi_offset
[i
] = offset
[i
] * 10;
603 static int fschmd_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
605 struct i2c_client
*client
;
606 struct fschmd_data
*data
;
608 const char * const names
[5] = { "Poseidon", "Hermes", "Scylla",
609 "Heracles", "Heimdall" };
610 const char * const client_names
[5] = { "fscpos", "fscher", "fscscy",
611 "fschrc", "fschmd" };
614 if (!i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
617 /* OK. For now, we presume we have a valid client. We now create the
618 * client structure, even though we cannot fill it completely yet.
619 * But it allows us to access i2c_smbus_read_byte_data. */
620 if (!(data
= kzalloc(sizeof(struct fschmd_data
), GFP_KERNEL
)))
623 client
= &data
->client
;
624 i2c_set_clientdata(client
, data
);
625 client
->addr
= address
;
626 client
->adapter
= adapter
;
627 client
->driver
= &fschmd_driver
;
628 mutex_init(&data
->update_lock
);
630 /* Detect & Identify the chip */
634 id
[0] = i2c_smbus_read_byte_data(client
,
636 id
[1] = i2c_smbus_read_byte_data(client
,
638 id
[2] = i2c_smbus_read_byte_data(client
,
642 if (!strcmp(id
, "PEG"))
644 else if (!strcmp(id
, "HER"))
646 else if (!strcmp(id
, "SCY"))
648 else if (!strcmp(id
, "HRC"))
650 else if (!strcmp(id
, "HMD"))
656 if (kind
== fscpos
) {
657 /* The Poseidon has hardwired temp limits, fill these
658 in for the alarm resetting code */
659 data
->temp_max
[0] = 70 + 128;
660 data
->temp_max
[1] = 50 + 128;
661 data
->temp_max
[2] = 50 + 128;
664 /* Read the special DMI table for fscher and newer chips */
665 if (kind
== fscher
|| kind
>= fschrc
) {
666 dmi_walk(fschmd_dmi_decode
);
667 if (dmi_vref
== -1) {
668 printk(KERN_WARNING FSCHMD_NAME
669 ": Couldn't get voltage scaling factors from "
670 "BIOS DMI table, using builtin defaults\n");
675 /* i2c kind goes from 1-5, we want from 0-4 to address arrays */
676 data
->kind
= kind
- 1;
677 strlcpy(client
->name
, client_names
[data
->kind
], I2C_NAME_SIZE
);
679 /* Tell the I2C layer a new client has arrived */
680 if ((err
= i2c_attach_client(client
)))
683 for (i
= 0; i
< ARRAY_SIZE(fschmd_attr
); i
++) {
684 err
= device_create_file(&client
->dev
,
685 &fschmd_attr
[i
].dev_attr
);
690 for (i
= 0; i
< (FSCHMD_NO_TEMP_SENSORS
[data
->kind
] * 4); i
++) {
691 /* Poseidon doesn't have TEMP_LIMIT registers */
692 if (kind
== fscpos
&& fschmd_temp_attr
[i
].dev_attr
.show
==
696 err
= device_create_file(&client
->dev
,
697 &fschmd_temp_attr
[i
].dev_attr
);
702 for (i
= 0; i
< (FSCHMD_NO_FAN_SENSORS
[data
->kind
] * 5); i
++) {
703 /* Poseidon doesn't have a FAN_MIN register for its 3rd fan */
704 if (kind
== fscpos
&&
705 !strcmp(fschmd_fan_attr
[i
].dev_attr
.attr
.name
,
706 "pwm3_auto_point1_pwm"))
709 err
= device_create_file(&client
->dev
,
710 &fschmd_fan_attr
[i
].dev_attr
);
715 data
->hwmon_dev
= hwmon_device_register(&client
->dev
);
716 if (IS_ERR(data
->hwmon_dev
)) {
717 err
= PTR_ERR(data
->hwmon_dev
);
718 data
->hwmon_dev
= NULL
;
722 revision
= i2c_smbus_read_byte_data(client
, FSCHMD_REG_REVISION
);
723 printk(KERN_INFO FSCHMD_NAME
": Detected FSC %s chip, revision: %d\n",
724 names
[data
->kind
], (int) revision
);
729 fschmd_detach_client(client
); /* will also free data for us */
737 static int fschmd_attach_adapter(struct i2c_adapter
*adapter
)
739 if (!(adapter
->class & I2C_CLASS_HWMON
))
741 return i2c_probe(adapter
, &addr_data
, fschmd_detect
);
744 static int fschmd_detach_client(struct i2c_client
*client
)
746 struct fschmd_data
*data
= i2c_get_clientdata(client
);
749 /* Check if registered in case we're called from fschmd_detect
750 to cleanup after an error */
752 hwmon_device_unregister(data
->hwmon_dev
);
754 for (i
= 0; i
< ARRAY_SIZE(fschmd_attr
); i
++)
755 device_remove_file(&client
->dev
, &fschmd_attr
[i
].dev_attr
);
756 for (i
= 0; i
< (FSCHMD_NO_TEMP_SENSORS
[data
->kind
] * 4); i
++)
757 device_remove_file(&client
->dev
,
758 &fschmd_temp_attr
[i
].dev_attr
);
759 for (i
= 0; i
< (FSCHMD_NO_FAN_SENSORS
[data
->kind
] * 5); i
++)
760 device_remove_file(&client
->dev
,
761 &fschmd_fan_attr
[i
].dev_attr
);
763 if ((err
= i2c_detach_client(client
)))
770 static struct fschmd_data
*fschmd_update_device(struct device
*dev
)
772 struct i2c_client
*client
= to_i2c_client(dev
);
773 struct fschmd_data
*data
= i2c_get_clientdata(client
);
776 mutex_lock(&data
->update_lock
);
778 if (time_after(jiffies
, data
->last_updated
+ 2 * HZ
) || !data
->valid
) {
780 for (i
= 0; i
< FSCHMD_NO_TEMP_SENSORS
[data
->kind
]; i
++) {
781 data
->temp_act
[i
] = i2c_smbus_read_byte_data(client
,
782 FSCHMD_REG_TEMP_ACT
[data
->kind
][i
]);
783 data
->temp_status
[i
] = i2c_smbus_read_byte_data(client
,
784 FSCHMD_REG_TEMP_STATE
[data
->kind
][i
]);
786 /* The fscpos doesn't have TEMP_LIMIT registers */
787 if (FSCHMD_REG_TEMP_LIMIT
[data
->kind
][i
])
788 data
->temp_max
[i
] = i2c_smbus_read_byte_data(
790 FSCHMD_REG_TEMP_LIMIT
[data
->kind
][i
]);
792 /* reset alarm if the alarm condition is gone,
793 the chip doesn't do this itself */
794 if ((data
->temp_status
[i
] & FSCHMD_TEMP_ALARM_MASK
) ==
795 FSCHMD_TEMP_ALARM_MASK
&&
796 data
->temp_act
[i
] < data
->temp_max
[i
])
797 i2c_smbus_write_byte_data(client
,
798 FSCHMD_REG_TEMP_STATE
[data
->kind
][i
],
799 FSCHMD_TEMP_ALERT_MASK
);
802 for (i
= 0; i
< FSCHMD_NO_FAN_SENSORS
[data
->kind
]; i
++) {
803 data
->fan_act
[i
] = i2c_smbus_read_byte_data(client
,
804 FSCHMD_REG_FAN_ACT
[data
->kind
][i
]);
805 data
->fan_status
[i
] = i2c_smbus_read_byte_data(client
,
806 FSCHMD_REG_FAN_STATE
[data
->kind
][i
]);
807 data
->fan_ripple
[i
] = i2c_smbus_read_byte_data(client
,
808 FSCHMD_REG_FAN_RIPPLE
[data
->kind
][i
]);
810 /* The fscpos third fan doesn't have a fan_min */
811 if (FSCHMD_REG_FAN_MIN
[data
->kind
][i
])
812 data
->fan_min
[i
] = i2c_smbus_read_byte_data(
814 FSCHMD_REG_FAN_MIN
[data
->kind
][i
]);
816 /* reset fan status if speed is back to > 0 */
817 if ((data
->fan_status
[i
] & FSCHMD_FAN_ALARM_MASK
) &&
819 i2c_smbus_write_byte_data(client
,
820 FSCHMD_REG_FAN_STATE
[data
->kind
][i
],
821 FSCHMD_FAN_ALARM_MASK
);
824 for (i
= 0; i
< 3; i
++)
825 data
->volt
[i
] = i2c_smbus_read_byte_data(client
,
828 data
->global_control
= i2c_smbus_read_byte_data(client
,
831 /* To be implemented in the future
832 data->watchdog[0] = i2c_smbus_read_byte_data(client,
833 FSCHMD_REG_WDOG_PRESET);
834 data->watchdog[1] = i2c_smbus_read_byte_data(client,
835 FSCHMD_REG_WDOG_STATE);
836 data->watchdog[2] = i2c_smbus_read_byte_data(client,
837 FSCHMD_REG_WDOG_CONTROL); */
839 data
->last_updated
= jiffies
;
843 mutex_unlock(&data
->update_lock
);
848 static int __init
fschmd_init(void)
850 return i2c_add_driver(&fschmd_driver
);
853 static void __exit
fschmd_exit(void)
855 i2c_del_driver(&fschmd_driver
);
858 MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
859 MODULE_DESCRIPTION("FSC Poseidon, Hermes, Scylla, Heracles and "
861 MODULE_LICENSE("GPL");
863 module_init(fschmd_init
);
864 module_exit(fschmd_exit
);