2 * Support for the FTS Systemmonitoring Chip "Teutates"
4 * Copyright (C) 2016 Fujitsu Technology Solutions GmbH,
5 * Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/err.h>
20 #include <linux/hwmon.h>
21 #include <linux/hwmon-sysfs.h>
22 #include <linux/i2c.h>
23 #include <linux/init.h>
24 #include <linux/jiffies.h>
25 #include <linux/module.h>
26 #include <linux/mutex.h>
27 #include <linux/slab.h>
28 #include <linux/sysfs.h>
29 #include <linux/uaccess.h>
30 #include <linux/watchdog.h>
32 #define FTS_DEVICE_ID_REG 0x0000
33 #define FTS_DEVICE_REVISION_REG 0x0001
34 #define FTS_DEVICE_STATUS_REG 0x0004
35 #define FTS_SATELLITE_STATUS_REG 0x0005
36 #define FTS_EVENT_STATUS_REG 0x0006
37 #define FTS_GLOBAL_CONTROL_REG 0x0007
39 #define FTS_SENSOR_EVENT_REG 0x0010
41 #define FTS_FAN_EVENT_REG 0x0014
42 #define FTS_FAN_PRESENT_REG 0x0015
44 #define FTS_POWER_ON_TIME_COUNTER_A 0x007A
45 #define FTS_POWER_ON_TIME_COUNTER_B 0x007B
46 #define FTS_POWER_ON_TIME_COUNTER_C 0x007C
48 #define FTS_PAGE_SELECT_REG 0x007F
50 #define FTS_WATCHDOG_TIME_PRESET 0x000B
51 #define FTS_WATCHDOG_CONTROL 0x5081
53 #define FTS_NO_FAN_SENSORS 0x08
54 #define FTS_NO_TEMP_SENSORS 0x10
55 #define FTS_NO_VOLT_SENSORS 0x04
57 static struct i2c_device_id fts_id
[] = {
61 MODULE_DEVICE_TABLE(i2c
, fts_id
);
63 enum WATCHDOG_RESOLUTION
{
69 struct i2c_client
*client
;
70 /* update sensor data lock */
71 struct mutex update_lock
;
72 /* read/write register lock */
73 struct mutex access_lock
;
74 unsigned long last_updated
; /* in jiffies */
75 struct watchdog_device wdd
;
76 enum WATCHDOG_RESOLUTION resolution
;
77 bool valid
; /* false until following fields are valid */
79 u8 volt
[FTS_NO_VOLT_SENSORS
];
81 u8 temp_input
[FTS_NO_TEMP_SENSORS
];
85 u8 fan_input
[FTS_NO_FAN_SENSORS
]; /* in rps */
86 u8 fan_source
[FTS_NO_FAN_SENSORS
];
90 #define FTS_REG_FAN_INPUT(idx) ((idx) + 0x20)
91 #define FTS_REG_FAN_SOURCE(idx) ((idx) + 0x30)
92 #define FTS_REG_FAN_CONTROL(idx) (((idx) << 16) + 0x4881)
94 #define FTS_REG_TEMP_INPUT(idx) ((idx) + 0x40)
95 #define FTS_REG_TEMP_CONTROL(idx) (((idx) << 16) + 0x0681)
97 #define FTS_REG_VOLT(idx) ((idx) + 0x18)
99 /*****************************************************************************/
100 /* I2C Helper functions */
101 /*****************************************************************************/
102 static int fts_read_byte(struct i2c_client
*client
, unsigned short reg
)
105 unsigned char page
= reg
>> 8;
106 struct fts_data
*data
= dev_get_drvdata(&client
->dev
);
108 mutex_lock(&data
->access_lock
);
110 dev_dbg(&client
->dev
, "page select - page: 0x%.02x\n", page
);
111 ret
= i2c_smbus_write_byte_data(client
, FTS_PAGE_SELECT_REG
, page
);
116 ret
= i2c_smbus_read_byte_data(client
, reg
);
117 dev_dbg(&client
->dev
, "read - reg: 0x%.02x: val: 0x%.02x\n", reg
, ret
);
120 mutex_unlock(&data
->access_lock
);
124 static int fts_write_byte(struct i2c_client
*client
, unsigned short reg
,
128 unsigned char page
= reg
>> 8;
129 struct fts_data
*data
= dev_get_drvdata(&client
->dev
);
131 mutex_lock(&data
->access_lock
);
133 dev_dbg(&client
->dev
, "page select - page: 0x%.02x\n", page
);
134 ret
= i2c_smbus_write_byte_data(client
, FTS_PAGE_SELECT_REG
, page
);
139 dev_dbg(&client
->dev
,
140 "write - reg: 0x%.02x: val: 0x%.02x\n", reg
, value
);
141 ret
= i2c_smbus_write_byte_data(client
, reg
, value
);
144 mutex_unlock(&data
->access_lock
);
148 /*****************************************************************************/
149 /* Data Updater Helper function */
150 /*****************************************************************************/
151 static int fts_update_device(struct fts_data
*data
)
156 mutex_lock(&data
->update_lock
);
157 if (!time_after(jiffies
, data
->last_updated
+ 2 * HZ
) && data
->valid
)
160 err
= fts_read_byte(data
->client
, FTS_DEVICE_STATUS_REG
);
164 data
->valid
= !!(err
& 0x02); /* Data not ready yet */
165 if (unlikely(!data
->valid
)) {
170 err
= fts_read_byte(data
->client
, FTS_FAN_PRESENT_REG
);
173 data
->fan_present
= err
;
175 err
= fts_read_byte(data
->client
, FTS_FAN_EVENT_REG
);
178 data
->fan_alarm
= err
;
180 for (i
= 0; i
< FTS_NO_FAN_SENSORS
; i
++) {
181 if (data
->fan_present
& BIT(i
)) {
182 err
= fts_read_byte(data
->client
, FTS_REG_FAN_INPUT(i
));
185 data
->fan_input
[i
] = err
;
187 err
= fts_read_byte(data
->client
,
188 FTS_REG_FAN_SOURCE(i
));
191 data
->fan_source
[i
] = err
;
193 data
->fan_input
[i
] = 0;
194 data
->fan_source
[i
] = 0;
198 err
= fts_read_byte(data
->client
, FTS_SENSOR_EVENT_REG
);
201 data
->temp_alarm
= err
;
203 for (i
= 0; i
< FTS_NO_TEMP_SENSORS
; i
++) {
204 err
= fts_read_byte(data
->client
, FTS_REG_TEMP_INPUT(i
));
207 data
->temp_input
[i
] = err
;
210 for (i
= 0; i
< FTS_NO_VOLT_SENSORS
; i
++) {
211 err
= fts_read_byte(data
->client
, FTS_REG_VOLT(i
));
216 data
->last_updated
= jiffies
;
219 mutex_unlock(&data
->update_lock
);
223 /*****************************************************************************/
224 /* Watchdog functions */
225 /*****************************************************************************/
226 static int fts_wd_set_resolution(struct fts_data
*data
,
227 enum WATCHDOG_RESOLUTION resolution
)
231 if (data
->resolution
== resolution
)
234 ret
= fts_read_byte(data
->client
, FTS_WATCHDOG_CONTROL
);
238 if ((resolution
== seconds
&& ret
& BIT(1)) ||
239 (resolution
== minutes
&& (ret
& BIT(1)) == 0)) {
240 data
->resolution
= resolution
;
244 if (resolution
== seconds
)
249 ret
= fts_write_byte(data
->client
, FTS_WATCHDOG_CONTROL
, ret
);
253 data
->resolution
= resolution
;
257 static int fts_wd_set_timeout(struct watchdog_device
*wdd
, unsigned int timeout
)
259 struct fts_data
*data
;
260 enum WATCHDOG_RESOLUTION resolution
= seconds
;
263 data
= watchdog_get_drvdata(wdd
);
264 /* switch watchdog resolution to minutes if timeout does not fit
267 if (timeout
> 0xFF) {
268 timeout
= DIV_ROUND_UP(timeout
, 60) * 60;
269 resolution
= minutes
;
272 ret
= fts_wd_set_resolution(data
, resolution
);
276 wdd
->timeout
= timeout
;
280 static int fts_wd_start(struct watchdog_device
*wdd
)
282 struct fts_data
*data
= watchdog_get_drvdata(wdd
);
284 return fts_write_byte(data
->client
, FTS_WATCHDOG_TIME_PRESET
,
285 wdd
->timeout
/ (u8
)data
->resolution
);
288 static int fts_wd_stop(struct watchdog_device
*wdd
)
290 struct fts_data
*data
;
292 data
= watchdog_get_drvdata(wdd
);
293 return fts_write_byte(data
->client
, FTS_WATCHDOG_TIME_PRESET
, 0);
296 static const struct watchdog_info fts_wd_info
= {
297 .options
= WDIOF_SETTIMEOUT
| WDIOF_KEEPALIVEPING
| WDIOF_MAGICCLOSE
,
298 .identity
= "FTS Teutates Hardware Watchdog",
301 static const struct watchdog_ops fts_wd_ops
= {
302 .owner
= THIS_MODULE
,
303 .start
= fts_wd_start
,
305 .set_timeout
= fts_wd_set_timeout
,
308 static int fts_watchdog_init(struct fts_data
*data
)
312 watchdog_set_drvdata(&data
->wdd
, data
);
314 timeout
= fts_read_byte(data
->client
, FTS_WATCHDOG_TIME_PRESET
);
318 /* watchdog not running, set timeout to a default of 60 sec. */
320 ret
= fts_wd_set_resolution(data
, seconds
);
323 data
->wdd
.timeout
= 60;
325 ret
= fts_read_byte(data
->client
, FTS_WATCHDOG_CONTROL
);
329 data
->resolution
= ret
& BIT(1) ? seconds
: minutes
;
330 data
->wdd
.timeout
= timeout
* (u8
)data
->resolution
;
331 set_bit(WDOG_HW_RUNNING
, &data
->wdd
.status
);
334 /* Register our watchdog part */
335 data
->wdd
.info
= &fts_wd_info
;
336 data
->wdd
.ops
= &fts_wd_ops
;
337 data
->wdd
.parent
= &data
->client
->dev
;
338 data
->wdd
.min_timeout
= 1;
340 /* max timeout 255 minutes. */
341 data
->wdd
.max_hw_heartbeat_ms
= 0xFF * 60 * MSEC_PER_SEC
;
343 return watchdog_register_device(&data
->wdd
);
346 /*****************************************************************************/
347 /* SysFS handler functions */
348 /*****************************************************************************/
349 static ssize_t
show_in_value(struct device
*dev
,
350 struct device_attribute
*devattr
, char *buf
)
352 struct fts_data
*data
= dev_get_drvdata(dev
);
353 int index
= to_sensor_dev_attr(devattr
)->index
;
356 err
= fts_update_device(data
);
360 return sprintf(buf
, "%u\n", data
->volt
[index
]);
363 static ssize_t
show_temp_value(struct device
*dev
,
364 struct device_attribute
*devattr
, char *buf
)
366 struct fts_data
*data
= dev_get_drvdata(dev
);
367 int index
= to_sensor_dev_attr(devattr
)->index
;
370 err
= fts_update_device(data
);
374 return sprintf(buf
, "%u\n", data
->temp_input
[index
]);
377 static ssize_t
show_temp_fault(struct device
*dev
,
378 struct device_attribute
*devattr
, char *buf
)
380 struct fts_data
*data
= dev_get_drvdata(dev
);
381 int index
= to_sensor_dev_attr(devattr
)->index
;
384 err
= fts_update_device(data
);
388 /* 00h Temperature = Sensor Error */
389 return sprintf(buf
, "%d\n", data
->temp_input
[index
] == 0);
392 static ssize_t
show_temp_alarm(struct device
*dev
,
393 struct device_attribute
*devattr
, char *buf
)
395 struct fts_data
*data
= dev_get_drvdata(dev
);
396 int index
= to_sensor_dev_attr(devattr
)->index
;
399 err
= fts_update_device(data
);
403 return sprintf(buf
, "%u\n", !!(data
->temp_alarm
& BIT(index
)));
407 clear_temp_alarm(struct device
*dev
, struct device_attribute
*devattr
,
408 const char *buf
, size_t count
)
410 struct fts_data
*data
= dev_get_drvdata(dev
);
411 int index
= to_sensor_dev_attr(devattr
)->index
;
414 ret
= fts_update_device(data
);
418 if (kstrtoul(buf
, 10, &ret
) || ret
!= 0)
421 mutex_lock(&data
->update_lock
);
422 ret
= fts_read_byte(data
->client
, FTS_REG_TEMP_CONTROL(index
));
426 ret
= fts_write_byte(data
->client
, FTS_REG_TEMP_CONTROL(index
),
433 mutex_unlock(&data
->update_lock
);
437 static ssize_t
show_fan_value(struct device
*dev
,
438 struct device_attribute
*devattr
, char *buf
)
440 struct fts_data
*data
= dev_get_drvdata(dev
);
441 int index
= to_sensor_dev_attr(devattr
)->index
;
444 err
= fts_update_device(data
);
448 return sprintf(buf
, "%u\n", data
->fan_input
[index
]);
451 static ssize_t
show_fan_source(struct device
*dev
,
452 struct device_attribute
*devattr
, char *buf
)
454 struct fts_data
*data
= dev_get_drvdata(dev
);
455 int index
= to_sensor_dev_attr(devattr
)->index
;
458 err
= fts_update_device(data
);
462 return sprintf(buf
, "%u\n", data
->fan_source
[index
]);
465 static ssize_t
show_fan_alarm(struct device
*dev
,
466 struct device_attribute
*devattr
, char *buf
)
468 struct fts_data
*data
= dev_get_drvdata(dev
);
469 int index
= to_sensor_dev_attr(devattr
)->index
;
472 err
= fts_update_device(data
);
476 return sprintf(buf
, "%d\n", !!(data
->fan_alarm
& BIT(index
)));
480 clear_fan_alarm(struct device
*dev
, struct device_attribute
*devattr
,
481 const char *buf
, size_t count
)
483 struct fts_data
*data
= dev_get_drvdata(dev
);
484 int index
= to_sensor_dev_attr(devattr
)->index
;
487 ret
= fts_update_device(data
);
491 if (kstrtoul(buf
, 10, &ret
) || ret
!= 0)
494 mutex_lock(&data
->update_lock
);
495 ret
= fts_read_byte(data
->client
, FTS_REG_FAN_CONTROL(index
));
499 ret
= fts_write_byte(data
->client
, FTS_REG_FAN_CONTROL(index
),
506 mutex_unlock(&data
->update_lock
);
510 /*****************************************************************************/
512 /*****************************************************************************/
514 /* Temprature sensors */
515 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp_value
, NULL
, 0);
516 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp_value
, NULL
, 1);
517 static SENSOR_DEVICE_ATTR(temp3_input
, S_IRUGO
, show_temp_value
, NULL
, 2);
518 static SENSOR_DEVICE_ATTR(temp4_input
, S_IRUGO
, show_temp_value
, NULL
, 3);
519 static SENSOR_DEVICE_ATTR(temp5_input
, S_IRUGO
, show_temp_value
, NULL
, 4);
520 static SENSOR_DEVICE_ATTR(temp6_input
, S_IRUGO
, show_temp_value
, NULL
, 5);
521 static SENSOR_DEVICE_ATTR(temp7_input
, S_IRUGO
, show_temp_value
, NULL
, 6);
522 static SENSOR_DEVICE_ATTR(temp8_input
, S_IRUGO
, show_temp_value
, NULL
, 7);
523 static SENSOR_DEVICE_ATTR(temp9_input
, S_IRUGO
, show_temp_value
, NULL
, 8);
524 static SENSOR_DEVICE_ATTR(temp10_input
, S_IRUGO
, show_temp_value
, NULL
, 9);
525 static SENSOR_DEVICE_ATTR(temp11_input
, S_IRUGO
, show_temp_value
, NULL
, 10);
526 static SENSOR_DEVICE_ATTR(temp12_input
, S_IRUGO
, show_temp_value
, NULL
, 11);
527 static SENSOR_DEVICE_ATTR(temp13_input
, S_IRUGO
, show_temp_value
, NULL
, 12);
528 static SENSOR_DEVICE_ATTR(temp14_input
, S_IRUGO
, show_temp_value
, NULL
, 13);
529 static SENSOR_DEVICE_ATTR(temp15_input
, S_IRUGO
, show_temp_value
, NULL
, 14);
530 static SENSOR_DEVICE_ATTR(temp16_input
, S_IRUGO
, show_temp_value
, NULL
, 15);
532 static SENSOR_DEVICE_ATTR(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0);
533 static SENSOR_DEVICE_ATTR(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 1);
534 static SENSOR_DEVICE_ATTR(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 2);
535 static SENSOR_DEVICE_ATTR(temp4_fault
, S_IRUGO
, show_temp_fault
, NULL
, 3);
536 static SENSOR_DEVICE_ATTR(temp5_fault
, S_IRUGO
, show_temp_fault
, NULL
, 4);
537 static SENSOR_DEVICE_ATTR(temp6_fault
, S_IRUGO
, show_temp_fault
, NULL
, 5);
538 static SENSOR_DEVICE_ATTR(temp7_fault
, S_IRUGO
, show_temp_fault
, NULL
, 6);
539 static SENSOR_DEVICE_ATTR(temp8_fault
, S_IRUGO
, show_temp_fault
, NULL
, 7);
540 static SENSOR_DEVICE_ATTR(temp9_fault
, S_IRUGO
, show_temp_fault
, NULL
, 8);
541 static SENSOR_DEVICE_ATTR(temp10_fault
, S_IRUGO
, show_temp_fault
, NULL
, 9);
542 static SENSOR_DEVICE_ATTR(temp11_fault
, S_IRUGO
, show_temp_fault
, NULL
, 10);
543 static SENSOR_DEVICE_ATTR(temp12_fault
, S_IRUGO
, show_temp_fault
, NULL
, 11);
544 static SENSOR_DEVICE_ATTR(temp13_fault
, S_IRUGO
, show_temp_fault
, NULL
, 12);
545 static SENSOR_DEVICE_ATTR(temp14_fault
, S_IRUGO
, show_temp_fault
, NULL
, 13);
546 static SENSOR_DEVICE_ATTR(temp15_fault
, S_IRUGO
, show_temp_fault
, NULL
, 14);
547 static SENSOR_DEVICE_ATTR(temp16_fault
, S_IRUGO
, show_temp_fault
, NULL
, 15);
549 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
550 clear_temp_alarm
, 0);
551 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
552 clear_temp_alarm
, 1);
553 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
554 clear_temp_alarm
, 2);
555 static SENSOR_DEVICE_ATTR(temp4_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
556 clear_temp_alarm
, 3);
557 static SENSOR_DEVICE_ATTR(temp5_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
558 clear_temp_alarm
, 4);
559 static SENSOR_DEVICE_ATTR(temp6_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
560 clear_temp_alarm
, 5);
561 static SENSOR_DEVICE_ATTR(temp7_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
562 clear_temp_alarm
, 6);
563 static SENSOR_DEVICE_ATTR(temp8_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
564 clear_temp_alarm
, 7);
565 static SENSOR_DEVICE_ATTR(temp9_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
566 clear_temp_alarm
, 8);
567 static SENSOR_DEVICE_ATTR(temp10_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
568 clear_temp_alarm
, 9);
569 static SENSOR_DEVICE_ATTR(temp11_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
570 clear_temp_alarm
, 10);
571 static SENSOR_DEVICE_ATTR(temp12_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
572 clear_temp_alarm
, 11);
573 static SENSOR_DEVICE_ATTR(temp13_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
574 clear_temp_alarm
, 12);
575 static SENSOR_DEVICE_ATTR(temp14_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
576 clear_temp_alarm
, 13);
577 static SENSOR_DEVICE_ATTR(temp15_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
578 clear_temp_alarm
, 14);
579 static SENSOR_DEVICE_ATTR(temp16_alarm
, S_IRUGO
| S_IWUSR
, show_temp_alarm
,
580 clear_temp_alarm
, 15);
582 static struct attribute
*fts_temp_attrs
[] = {
583 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
584 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
585 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
586 &sensor_dev_attr_temp4_input
.dev_attr
.attr
,
587 &sensor_dev_attr_temp5_input
.dev_attr
.attr
,
588 &sensor_dev_attr_temp6_input
.dev_attr
.attr
,
589 &sensor_dev_attr_temp7_input
.dev_attr
.attr
,
590 &sensor_dev_attr_temp8_input
.dev_attr
.attr
,
591 &sensor_dev_attr_temp9_input
.dev_attr
.attr
,
592 &sensor_dev_attr_temp10_input
.dev_attr
.attr
,
593 &sensor_dev_attr_temp11_input
.dev_attr
.attr
,
594 &sensor_dev_attr_temp12_input
.dev_attr
.attr
,
595 &sensor_dev_attr_temp13_input
.dev_attr
.attr
,
596 &sensor_dev_attr_temp14_input
.dev_attr
.attr
,
597 &sensor_dev_attr_temp15_input
.dev_attr
.attr
,
598 &sensor_dev_attr_temp16_input
.dev_attr
.attr
,
600 &sensor_dev_attr_temp1_fault
.dev_attr
.attr
,
601 &sensor_dev_attr_temp2_fault
.dev_attr
.attr
,
602 &sensor_dev_attr_temp3_fault
.dev_attr
.attr
,
603 &sensor_dev_attr_temp4_fault
.dev_attr
.attr
,
604 &sensor_dev_attr_temp5_fault
.dev_attr
.attr
,
605 &sensor_dev_attr_temp6_fault
.dev_attr
.attr
,
606 &sensor_dev_attr_temp7_fault
.dev_attr
.attr
,
607 &sensor_dev_attr_temp8_fault
.dev_attr
.attr
,
608 &sensor_dev_attr_temp9_fault
.dev_attr
.attr
,
609 &sensor_dev_attr_temp10_fault
.dev_attr
.attr
,
610 &sensor_dev_attr_temp11_fault
.dev_attr
.attr
,
611 &sensor_dev_attr_temp12_fault
.dev_attr
.attr
,
612 &sensor_dev_attr_temp13_fault
.dev_attr
.attr
,
613 &sensor_dev_attr_temp14_fault
.dev_attr
.attr
,
614 &sensor_dev_attr_temp15_fault
.dev_attr
.attr
,
615 &sensor_dev_attr_temp16_fault
.dev_attr
.attr
,
617 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
618 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
619 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
620 &sensor_dev_attr_temp4_alarm
.dev_attr
.attr
,
621 &sensor_dev_attr_temp5_alarm
.dev_attr
.attr
,
622 &sensor_dev_attr_temp6_alarm
.dev_attr
.attr
,
623 &sensor_dev_attr_temp7_alarm
.dev_attr
.attr
,
624 &sensor_dev_attr_temp8_alarm
.dev_attr
.attr
,
625 &sensor_dev_attr_temp9_alarm
.dev_attr
.attr
,
626 &sensor_dev_attr_temp10_alarm
.dev_attr
.attr
,
627 &sensor_dev_attr_temp11_alarm
.dev_attr
.attr
,
628 &sensor_dev_attr_temp12_alarm
.dev_attr
.attr
,
629 &sensor_dev_attr_temp13_alarm
.dev_attr
.attr
,
630 &sensor_dev_attr_temp14_alarm
.dev_attr
.attr
,
631 &sensor_dev_attr_temp15_alarm
.dev_attr
.attr
,
632 &sensor_dev_attr_temp16_alarm
.dev_attr
.attr
,
637 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan_value
, NULL
, 0);
638 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan_value
, NULL
, 1);
639 static SENSOR_DEVICE_ATTR(fan3_input
, S_IRUGO
, show_fan_value
, NULL
, 2);
640 static SENSOR_DEVICE_ATTR(fan4_input
, S_IRUGO
, show_fan_value
, NULL
, 3);
641 static SENSOR_DEVICE_ATTR(fan5_input
, S_IRUGO
, show_fan_value
, NULL
, 4);
642 static SENSOR_DEVICE_ATTR(fan6_input
, S_IRUGO
, show_fan_value
, NULL
, 5);
643 static SENSOR_DEVICE_ATTR(fan7_input
, S_IRUGO
, show_fan_value
, NULL
, 6);
644 static SENSOR_DEVICE_ATTR(fan8_input
, S_IRUGO
, show_fan_value
, NULL
, 7);
646 static SENSOR_DEVICE_ATTR(fan1_source
, S_IRUGO
, show_fan_source
, NULL
, 0);
647 static SENSOR_DEVICE_ATTR(fan2_source
, S_IRUGO
, show_fan_source
, NULL
, 1);
648 static SENSOR_DEVICE_ATTR(fan3_source
, S_IRUGO
, show_fan_source
, NULL
, 2);
649 static SENSOR_DEVICE_ATTR(fan4_source
, S_IRUGO
, show_fan_source
, NULL
, 3);
650 static SENSOR_DEVICE_ATTR(fan5_source
, S_IRUGO
, show_fan_source
, NULL
, 4);
651 static SENSOR_DEVICE_ATTR(fan6_source
, S_IRUGO
, show_fan_source
, NULL
, 5);
652 static SENSOR_DEVICE_ATTR(fan7_source
, S_IRUGO
, show_fan_source
, NULL
, 6);
653 static SENSOR_DEVICE_ATTR(fan8_source
, S_IRUGO
, show_fan_source
, NULL
, 7);
655 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
| S_IWUSR
,
656 show_fan_alarm
, clear_fan_alarm
, 0);
657 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
| S_IWUSR
,
658 show_fan_alarm
, clear_fan_alarm
, 1);
659 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
| S_IWUSR
,
660 show_fan_alarm
, clear_fan_alarm
, 2);
661 static SENSOR_DEVICE_ATTR(fan4_alarm
, S_IRUGO
| S_IWUSR
,
662 show_fan_alarm
, clear_fan_alarm
, 3);
663 static SENSOR_DEVICE_ATTR(fan5_alarm
, S_IRUGO
| S_IWUSR
,
664 show_fan_alarm
, clear_fan_alarm
, 4);
665 static SENSOR_DEVICE_ATTR(fan6_alarm
, S_IRUGO
| S_IWUSR
,
666 show_fan_alarm
, clear_fan_alarm
, 5);
667 static SENSOR_DEVICE_ATTR(fan7_alarm
, S_IRUGO
| S_IWUSR
,
668 show_fan_alarm
, clear_fan_alarm
, 6);
669 static SENSOR_DEVICE_ATTR(fan8_alarm
, S_IRUGO
| S_IWUSR
,
670 show_fan_alarm
, clear_fan_alarm
, 7);
672 static struct attribute
*fts_fan_attrs
[] = {
673 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
674 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
675 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
676 &sensor_dev_attr_fan4_input
.dev_attr
.attr
,
677 &sensor_dev_attr_fan5_input
.dev_attr
.attr
,
678 &sensor_dev_attr_fan6_input
.dev_attr
.attr
,
679 &sensor_dev_attr_fan7_input
.dev_attr
.attr
,
680 &sensor_dev_attr_fan8_input
.dev_attr
.attr
,
682 &sensor_dev_attr_fan1_source
.dev_attr
.attr
,
683 &sensor_dev_attr_fan2_source
.dev_attr
.attr
,
684 &sensor_dev_attr_fan3_source
.dev_attr
.attr
,
685 &sensor_dev_attr_fan4_source
.dev_attr
.attr
,
686 &sensor_dev_attr_fan5_source
.dev_attr
.attr
,
687 &sensor_dev_attr_fan6_source
.dev_attr
.attr
,
688 &sensor_dev_attr_fan7_source
.dev_attr
.attr
,
689 &sensor_dev_attr_fan8_source
.dev_attr
.attr
,
691 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
692 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
693 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
694 &sensor_dev_attr_fan4_alarm
.dev_attr
.attr
,
695 &sensor_dev_attr_fan5_alarm
.dev_attr
.attr
,
696 &sensor_dev_attr_fan6_alarm
.dev_attr
.attr
,
697 &sensor_dev_attr_fan7_alarm
.dev_attr
.attr
,
698 &sensor_dev_attr_fan8_alarm
.dev_attr
.attr
,
703 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in_value
, NULL
, 0);
704 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in_value
, NULL
, 1);
705 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in_value
, NULL
, 2);
706 static SENSOR_DEVICE_ATTR(in4_input
, S_IRUGO
, show_in_value
, NULL
, 3);
707 static struct attribute
*fts_voltage_attrs
[] = {
708 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
709 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
710 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
711 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
715 static const struct attribute_group fts_voltage_attr_group
= {
716 .attrs
= fts_voltage_attrs
719 static const struct attribute_group fts_temp_attr_group
= {
720 .attrs
= fts_temp_attrs
723 static const struct attribute_group fts_fan_attr_group
= {
724 .attrs
= fts_fan_attrs
727 static const struct attribute_group
*fts_attr_groups
[] = {
728 &fts_voltage_attr_group
,
729 &fts_temp_attr_group
,
734 /*****************************************************************************/
735 /* Module initialization / remove functions */
736 /*****************************************************************************/
737 static int fts_remove(struct i2c_client
*client
)
739 struct fts_data
*data
= dev_get_drvdata(&client
->dev
);
741 watchdog_unregister_device(&data
->wdd
);
745 static int fts_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
748 struct fts_data
*data
;
751 struct device
*hwmon_dev
;
753 if (client
->addr
!= 0x73)
756 /* Baseboard Management Controller check */
757 deviceid
= i2c_smbus_read_byte_data(client
, FTS_DEVICE_ID_REG
);
758 if (deviceid
> 0 && (deviceid
& 0xF0) == 0x10) {
759 switch (deviceid
& 0x0F) {
763 dev_dbg(&client
->dev
,
764 "No Baseboard Management Controller\n");
768 dev_dbg(&client
->dev
, "No fujitsu board\n");
772 data
= devm_kzalloc(&client
->dev
, sizeof(struct fts_data
),
777 mutex_init(&data
->update_lock
);
778 mutex_init(&data
->access_lock
);
779 data
->client
= client
;
780 dev_set_drvdata(&client
->dev
, data
);
782 err
= i2c_smbus_read_byte_data(client
, FTS_DEVICE_REVISION_REG
);
787 hwmon_dev
= devm_hwmon_device_register_with_groups(&client
->dev
,
791 if (IS_ERR(hwmon_dev
))
792 return PTR_ERR(hwmon_dev
);
794 err
= fts_watchdog_init(data
);
798 dev_info(&client
->dev
, "Detected FTS Teutates chip, revision: %d.%d\n",
799 (revision
& 0xF0) >> 4, revision
& 0x0F);
803 /*****************************************************************************/
805 /*****************************************************************************/
806 static struct i2c_driver fts_driver
= {
808 .name
= "ftsteutates",
812 .remove
= fts_remove
,
815 module_i2c_driver(fts_driver
);
817 MODULE_AUTHOR("Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com>");
818 MODULE_DESCRIPTION("FTS Teutates driver");
819 MODULE_LICENSE("GPL");