1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for the FTS Systemmonitoring Chip "Teutates"
5 * Copyright (C) 2016 Fujitsu Technology Solutions GmbH,
6 * Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com>
10 #include <linux/hwmon.h>
11 #include <linux/hwmon-sysfs.h>
12 #include <linux/i2c.h>
13 #include <linux/init.h>
14 #include <linux/jiffies.h>
15 #include <linux/module.h>
16 #include <linux/mutex.h>
17 #include <linux/slab.h>
18 #include <linux/sysfs.h>
19 #include <linux/uaccess.h>
20 #include <linux/watchdog.h>
22 #define FTS_DEVICE_ID_REG 0x0000
23 #define FTS_DEVICE_REVISION_REG 0x0001
24 #define FTS_DEVICE_STATUS_REG 0x0004
25 #define FTS_SATELLITE_STATUS_REG 0x0005
26 #define FTS_EVENT_STATUS_REG 0x0006
27 #define FTS_GLOBAL_CONTROL_REG 0x0007
29 #define FTS_DEVICE_DETECT_REG_1 0x0C
30 #define FTS_DEVICE_DETECT_REG_2 0x0D
31 #define FTS_DEVICE_DETECT_REG_3 0x0E
33 #define FTS_SENSOR_EVENT_REG 0x0010
35 #define FTS_FAN_EVENT_REG 0x0014
36 #define FTS_FAN_PRESENT_REG 0x0015
38 #define FTS_POWER_ON_TIME_COUNTER_A 0x007A
39 #define FTS_POWER_ON_TIME_COUNTER_B 0x007B
40 #define FTS_POWER_ON_TIME_COUNTER_C 0x007C
42 #define FTS_PAGE_SELECT_REG 0x007F
44 #define FTS_WATCHDOG_TIME_PRESET 0x000B
45 #define FTS_WATCHDOG_CONTROL 0x5081
47 #define FTS_NO_FAN_SENSORS 0x08
48 #define FTS_NO_TEMP_SENSORS 0x10
49 #define FTS_NO_VOLT_SENSORS 0x04
51 static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
53 static const struct i2c_device_id fts_id[] = {
57 MODULE_DEVICE_TABLE(i2c, fts_id);
59 enum WATCHDOG_RESOLUTION {
65 struct i2c_client *client;
66 /* update sensor data lock */
67 struct mutex update_lock;
68 /* read/write register lock */
69 struct mutex access_lock;
70 unsigned long last_updated; /* in jiffies */
71 struct watchdog_device wdd;
72 enum WATCHDOG_RESOLUTION resolution;
73 bool valid; /* false until following fields are valid */
75 u8 volt[FTS_NO_VOLT_SENSORS];
77 u8 temp_input[FTS_NO_TEMP_SENSORS];
81 u8 fan_input[FTS_NO_FAN_SENSORS]; /* in rps */
82 u8 fan_source[FTS_NO_FAN_SENSORS];
86 #define FTS_REG_FAN_INPUT(idx) ((idx) + 0x20)
87 #define FTS_REG_FAN_SOURCE(idx) ((idx) + 0x30)
88 #define FTS_REG_FAN_CONTROL(idx) (((idx) << 16) + 0x4881)
90 #define FTS_REG_TEMP_INPUT(idx) ((idx) + 0x40)
91 #define FTS_REG_TEMP_CONTROL(idx) (((idx) << 16) + 0x0681)
93 #define FTS_REG_VOLT(idx) ((idx) + 0x18)
95 /*****************************************************************************/
96 /* I2C Helper functions */
97 /*****************************************************************************/
98 static int fts_read_byte(struct i2c_client *client, unsigned short reg)
101 unsigned char page = reg >> 8;
102 struct fts_data *data = dev_get_drvdata(&client->dev);
104 mutex_lock(&data->access_lock);
106 dev_dbg(&client->dev, "page select - page: 0x%.02x\n", page);
107 ret = i2c_smbus_write_byte_data(client, FTS_PAGE_SELECT_REG, page);
112 ret = i2c_smbus_read_byte_data(client, reg);
113 dev_dbg(&client->dev, "read - reg: 0x%.02x: val: 0x%.02x\n", reg, ret);
116 mutex_unlock(&data->access_lock);
120 static int fts_write_byte(struct i2c_client *client, unsigned short reg,
124 unsigned char page = reg >> 8;
125 struct fts_data *data = dev_get_drvdata(&client->dev);
127 mutex_lock(&data->access_lock);
129 dev_dbg(&client->dev, "page select - page: 0x%.02x\n", page);
130 ret = i2c_smbus_write_byte_data(client, FTS_PAGE_SELECT_REG, page);
135 dev_dbg(&client->dev,
136 "write - reg: 0x%.02x: val: 0x%.02x\n", reg, value);
137 ret = i2c_smbus_write_byte_data(client, reg, value);
140 mutex_unlock(&data->access_lock);
144 /*****************************************************************************/
145 /* Data Updater Helper function */
146 /*****************************************************************************/
147 static int fts_update_device(struct fts_data *data)
152 mutex_lock(&data->update_lock);
153 if (!time_after(jiffies, data->last_updated + 2 * HZ) && data->valid)
156 err = fts_read_byte(data->client, FTS_DEVICE_STATUS_REG);
160 data->valid = !!(err & 0x02); /* Data not ready yet */
161 if (unlikely(!data->valid)) {
166 err = fts_read_byte(data->client, FTS_FAN_PRESENT_REG);
169 data->fan_present = err;
171 err = fts_read_byte(data->client, FTS_FAN_EVENT_REG);
174 data->fan_alarm = err;
176 for (i = 0; i < FTS_NO_FAN_SENSORS; i++) {
177 if (data->fan_present & BIT(i)) {
178 err = fts_read_byte(data->client, FTS_REG_FAN_INPUT(i));
181 data->fan_input[i] = err;
183 err = fts_read_byte(data->client,
184 FTS_REG_FAN_SOURCE(i));
187 data->fan_source[i] = err;
189 data->fan_input[i] = 0;
190 data->fan_source[i] = 0;
194 err = fts_read_byte(data->client, FTS_SENSOR_EVENT_REG);
197 data->temp_alarm = err;
199 for (i = 0; i < FTS_NO_TEMP_SENSORS; i++) {
200 err = fts_read_byte(data->client, FTS_REG_TEMP_INPUT(i));
203 data->temp_input[i] = err;
206 for (i = 0; i < FTS_NO_VOLT_SENSORS; i++) {
207 err = fts_read_byte(data->client, FTS_REG_VOLT(i));
212 data->last_updated = jiffies;
215 mutex_unlock(&data->update_lock);
219 /*****************************************************************************/
220 /* Watchdog functions */
221 /*****************************************************************************/
222 static int fts_wd_set_resolution(struct fts_data *data,
223 enum WATCHDOG_RESOLUTION resolution)
227 if (data->resolution == resolution)
230 ret = fts_read_byte(data->client, FTS_WATCHDOG_CONTROL);
234 if ((resolution == seconds && ret & BIT(1)) ||
235 (resolution == minutes && (ret & BIT(1)) == 0)) {
236 data->resolution = resolution;
240 if (resolution == seconds)
245 ret = fts_write_byte(data->client, FTS_WATCHDOG_CONTROL, ret);
249 data->resolution = resolution;
253 static int fts_wd_set_timeout(struct watchdog_device *wdd, unsigned int timeout)
255 struct fts_data *data;
256 enum WATCHDOG_RESOLUTION resolution = seconds;
259 data = watchdog_get_drvdata(wdd);
260 /* switch watchdog resolution to minutes if timeout does not fit
263 if (timeout > 0xFF) {
264 timeout = DIV_ROUND_UP(timeout, 60) * 60;
265 resolution = minutes;
268 ret = fts_wd_set_resolution(data, resolution);
272 wdd->timeout = timeout;
276 static int fts_wd_start(struct watchdog_device *wdd)
278 struct fts_data *data = watchdog_get_drvdata(wdd);
280 return fts_write_byte(data->client, FTS_WATCHDOG_TIME_PRESET,
281 wdd->timeout / (u8)data->resolution);
284 static int fts_wd_stop(struct watchdog_device *wdd)
286 struct fts_data *data;
288 data = watchdog_get_drvdata(wdd);
289 return fts_write_byte(data->client, FTS_WATCHDOG_TIME_PRESET, 0);
292 static const struct watchdog_info fts_wd_info = {
293 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
294 .identity = "FTS Teutates Hardware Watchdog",
297 static const struct watchdog_ops fts_wd_ops = {
298 .owner = THIS_MODULE,
299 .start = fts_wd_start,
301 .set_timeout = fts_wd_set_timeout,
304 static int fts_watchdog_init(struct fts_data *data)
308 watchdog_set_drvdata(&data->wdd, data);
310 timeout = fts_read_byte(data->client, FTS_WATCHDOG_TIME_PRESET);
314 /* watchdog not running, set timeout to a default of 60 sec. */
316 ret = fts_wd_set_resolution(data, seconds);
319 data->wdd.timeout = 60;
321 ret = fts_read_byte(data->client, FTS_WATCHDOG_CONTROL);
325 data->resolution = ret & BIT(1) ? seconds : minutes;
326 data->wdd.timeout = timeout * (u8)data->resolution;
327 set_bit(WDOG_HW_RUNNING, &data->wdd.status);
330 /* Register our watchdog part */
331 data->wdd.info = &fts_wd_info;
332 data->wdd.ops = &fts_wd_ops;
333 data->wdd.parent = &data->client->dev;
334 data->wdd.min_timeout = 1;
336 /* max timeout 255 minutes. */
337 data->wdd.max_hw_heartbeat_ms = 0xFF * 60 * MSEC_PER_SEC;
339 return watchdog_register_device(&data->wdd);
342 /*****************************************************************************/
343 /* SysFS handler functions */
344 /*****************************************************************************/
345 static ssize_t in_value_show(struct device *dev,
346 struct device_attribute *devattr, char *buf)
348 struct fts_data *data = dev_get_drvdata(dev);
349 int index = to_sensor_dev_attr(devattr)->index;
352 err = fts_update_device(data);
356 return sprintf(buf, "%u\n", data->volt[index]);
359 static ssize_t temp_value_show(struct device *dev,
360 struct device_attribute *devattr, char *buf)
362 struct fts_data *data = dev_get_drvdata(dev);
363 int index = to_sensor_dev_attr(devattr)->index;
366 err = fts_update_device(data);
370 return sprintf(buf, "%u\n", data->temp_input[index]);
373 static ssize_t temp_fault_show(struct device *dev,
374 struct device_attribute *devattr, char *buf)
376 struct fts_data *data = dev_get_drvdata(dev);
377 int index = to_sensor_dev_attr(devattr)->index;
380 err = fts_update_device(data);
384 /* 00h Temperature = Sensor Error */
385 return sprintf(buf, "%d\n", data->temp_input[index] == 0);
388 static ssize_t temp_alarm_show(struct device *dev,
389 struct device_attribute *devattr, char *buf)
391 struct fts_data *data = dev_get_drvdata(dev);
392 int index = to_sensor_dev_attr(devattr)->index;
395 err = fts_update_device(data);
399 return sprintf(buf, "%u\n", !!(data->temp_alarm & BIT(index)));
403 temp_alarm_store(struct device *dev, struct device_attribute *devattr,
404 const char *buf, size_t count)
406 struct fts_data *data = dev_get_drvdata(dev);
407 int index = to_sensor_dev_attr(devattr)->index;
410 ret = fts_update_device(data);
414 if (kstrtoul(buf, 10, &ret) || ret != 0)
417 mutex_lock(&data->update_lock);
418 ret = fts_read_byte(data->client, FTS_REG_TEMP_CONTROL(index));
422 ret = fts_write_byte(data->client, FTS_REG_TEMP_CONTROL(index),
430 mutex_unlock(&data->update_lock);
434 static ssize_t fan_value_show(struct device *dev,
435 struct device_attribute *devattr, char *buf)
437 struct fts_data *data = dev_get_drvdata(dev);
438 int index = to_sensor_dev_attr(devattr)->index;
441 err = fts_update_device(data);
445 return sprintf(buf, "%u\n", data->fan_input[index]);
448 static ssize_t fan_source_show(struct device *dev,
449 struct device_attribute *devattr, char *buf)
451 struct fts_data *data = dev_get_drvdata(dev);
452 int index = to_sensor_dev_attr(devattr)->index;
455 err = fts_update_device(data);
459 return sprintf(buf, "%u\n", data->fan_source[index]);
462 static ssize_t fan_alarm_show(struct device *dev,
463 struct device_attribute *devattr, char *buf)
465 struct fts_data *data = dev_get_drvdata(dev);
466 int index = to_sensor_dev_attr(devattr)->index;
469 err = fts_update_device(data);
473 return sprintf(buf, "%d\n", !!(data->fan_alarm & BIT(index)));
477 fan_alarm_store(struct device *dev, struct device_attribute *devattr,
478 const char *buf, size_t count)
480 struct fts_data *data = dev_get_drvdata(dev);
481 int index = to_sensor_dev_attr(devattr)->index;
484 ret = fts_update_device(data);
488 if (kstrtoul(buf, 10, &ret) || ret != 0)
491 mutex_lock(&data->update_lock);
492 ret = fts_read_byte(data->client, FTS_REG_FAN_CONTROL(index));
496 ret = fts_write_byte(data->client, FTS_REG_FAN_CONTROL(index),
504 mutex_unlock(&data->update_lock);
508 /*****************************************************************************/
510 /*****************************************************************************/
512 /* Temperature sensors */
513 static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_value, 0);
514 static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_value, 1);
515 static SENSOR_DEVICE_ATTR_RO(temp3_input, temp_value, 2);
516 static SENSOR_DEVICE_ATTR_RO(temp4_input, temp_value, 3);
517 static SENSOR_DEVICE_ATTR_RO(temp5_input, temp_value, 4);
518 static SENSOR_DEVICE_ATTR_RO(temp6_input, temp_value, 5);
519 static SENSOR_DEVICE_ATTR_RO(temp7_input, temp_value, 6);
520 static SENSOR_DEVICE_ATTR_RO(temp8_input, temp_value, 7);
521 static SENSOR_DEVICE_ATTR_RO(temp9_input, temp_value, 8);
522 static SENSOR_DEVICE_ATTR_RO(temp10_input, temp_value, 9);
523 static SENSOR_DEVICE_ATTR_RO(temp11_input, temp_value, 10);
524 static SENSOR_DEVICE_ATTR_RO(temp12_input, temp_value, 11);
525 static SENSOR_DEVICE_ATTR_RO(temp13_input, temp_value, 12);
526 static SENSOR_DEVICE_ATTR_RO(temp14_input, temp_value, 13);
527 static SENSOR_DEVICE_ATTR_RO(temp15_input, temp_value, 14);
528 static SENSOR_DEVICE_ATTR_RO(temp16_input, temp_value, 15);
530 static SENSOR_DEVICE_ATTR_RO(temp1_fault, temp_fault, 0);
531 static SENSOR_DEVICE_ATTR_RO(temp2_fault, temp_fault, 1);
532 static SENSOR_DEVICE_ATTR_RO(temp3_fault, temp_fault, 2);
533 static SENSOR_DEVICE_ATTR_RO(temp4_fault, temp_fault, 3);
534 static SENSOR_DEVICE_ATTR_RO(temp5_fault, temp_fault, 4);
535 static SENSOR_DEVICE_ATTR_RO(temp6_fault, temp_fault, 5);
536 static SENSOR_DEVICE_ATTR_RO(temp7_fault, temp_fault, 6);
537 static SENSOR_DEVICE_ATTR_RO(temp8_fault, temp_fault, 7);
538 static SENSOR_DEVICE_ATTR_RO(temp9_fault, temp_fault, 8);
539 static SENSOR_DEVICE_ATTR_RO(temp10_fault, temp_fault, 9);
540 static SENSOR_DEVICE_ATTR_RO(temp11_fault, temp_fault, 10);
541 static SENSOR_DEVICE_ATTR_RO(temp12_fault, temp_fault, 11);
542 static SENSOR_DEVICE_ATTR_RO(temp13_fault, temp_fault, 12);
543 static SENSOR_DEVICE_ATTR_RO(temp14_fault, temp_fault, 13);
544 static SENSOR_DEVICE_ATTR_RO(temp15_fault, temp_fault, 14);
545 static SENSOR_DEVICE_ATTR_RO(temp16_fault, temp_fault, 15);
547 static SENSOR_DEVICE_ATTR_RW(temp1_alarm, temp_alarm, 0);
548 static SENSOR_DEVICE_ATTR_RW(temp2_alarm, temp_alarm, 1);
549 static SENSOR_DEVICE_ATTR_RW(temp3_alarm, temp_alarm, 2);
550 static SENSOR_DEVICE_ATTR_RW(temp4_alarm, temp_alarm, 3);
551 static SENSOR_DEVICE_ATTR_RW(temp5_alarm, temp_alarm, 4);
552 static SENSOR_DEVICE_ATTR_RW(temp6_alarm, temp_alarm, 5);
553 static SENSOR_DEVICE_ATTR_RW(temp7_alarm, temp_alarm, 6);
554 static SENSOR_DEVICE_ATTR_RW(temp8_alarm, temp_alarm, 7);
555 static SENSOR_DEVICE_ATTR_RW(temp9_alarm, temp_alarm, 8);
556 static SENSOR_DEVICE_ATTR_RW(temp10_alarm, temp_alarm, 9);
557 static SENSOR_DEVICE_ATTR_RW(temp11_alarm, temp_alarm, 10);
558 static SENSOR_DEVICE_ATTR_RW(temp12_alarm, temp_alarm, 11);
559 static SENSOR_DEVICE_ATTR_RW(temp13_alarm, temp_alarm, 12);
560 static SENSOR_DEVICE_ATTR_RW(temp14_alarm, temp_alarm, 13);
561 static SENSOR_DEVICE_ATTR_RW(temp15_alarm, temp_alarm, 14);
562 static SENSOR_DEVICE_ATTR_RW(temp16_alarm, temp_alarm, 15);
564 static struct attribute *fts_temp_attrs[] = {
565 &sensor_dev_attr_temp1_input.dev_attr.attr,
566 &sensor_dev_attr_temp2_input.dev_attr.attr,
567 &sensor_dev_attr_temp3_input.dev_attr.attr,
568 &sensor_dev_attr_temp4_input.dev_attr.attr,
569 &sensor_dev_attr_temp5_input.dev_attr.attr,
570 &sensor_dev_attr_temp6_input.dev_attr.attr,
571 &sensor_dev_attr_temp7_input.dev_attr.attr,
572 &sensor_dev_attr_temp8_input.dev_attr.attr,
573 &sensor_dev_attr_temp9_input.dev_attr.attr,
574 &sensor_dev_attr_temp10_input.dev_attr.attr,
575 &sensor_dev_attr_temp11_input.dev_attr.attr,
576 &sensor_dev_attr_temp12_input.dev_attr.attr,
577 &sensor_dev_attr_temp13_input.dev_attr.attr,
578 &sensor_dev_attr_temp14_input.dev_attr.attr,
579 &sensor_dev_attr_temp15_input.dev_attr.attr,
580 &sensor_dev_attr_temp16_input.dev_attr.attr,
582 &sensor_dev_attr_temp1_fault.dev_attr.attr,
583 &sensor_dev_attr_temp2_fault.dev_attr.attr,
584 &sensor_dev_attr_temp3_fault.dev_attr.attr,
585 &sensor_dev_attr_temp4_fault.dev_attr.attr,
586 &sensor_dev_attr_temp5_fault.dev_attr.attr,
587 &sensor_dev_attr_temp6_fault.dev_attr.attr,
588 &sensor_dev_attr_temp7_fault.dev_attr.attr,
589 &sensor_dev_attr_temp8_fault.dev_attr.attr,
590 &sensor_dev_attr_temp9_fault.dev_attr.attr,
591 &sensor_dev_attr_temp10_fault.dev_attr.attr,
592 &sensor_dev_attr_temp11_fault.dev_attr.attr,
593 &sensor_dev_attr_temp12_fault.dev_attr.attr,
594 &sensor_dev_attr_temp13_fault.dev_attr.attr,
595 &sensor_dev_attr_temp14_fault.dev_attr.attr,
596 &sensor_dev_attr_temp15_fault.dev_attr.attr,
597 &sensor_dev_attr_temp16_fault.dev_attr.attr,
599 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
600 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
601 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
602 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
603 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
604 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
605 &sensor_dev_attr_temp7_alarm.dev_attr.attr,
606 &sensor_dev_attr_temp8_alarm.dev_attr.attr,
607 &sensor_dev_attr_temp9_alarm.dev_attr.attr,
608 &sensor_dev_attr_temp10_alarm.dev_attr.attr,
609 &sensor_dev_attr_temp11_alarm.dev_attr.attr,
610 &sensor_dev_attr_temp12_alarm.dev_attr.attr,
611 &sensor_dev_attr_temp13_alarm.dev_attr.attr,
612 &sensor_dev_attr_temp14_alarm.dev_attr.attr,
613 &sensor_dev_attr_temp15_alarm.dev_attr.attr,
614 &sensor_dev_attr_temp16_alarm.dev_attr.attr,
619 static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_value, 0);
620 static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_value, 1);
621 static SENSOR_DEVICE_ATTR_RO(fan3_input, fan_value, 2);
622 static SENSOR_DEVICE_ATTR_RO(fan4_input, fan_value, 3);
623 static SENSOR_DEVICE_ATTR_RO(fan5_input, fan_value, 4);
624 static SENSOR_DEVICE_ATTR_RO(fan6_input, fan_value, 5);
625 static SENSOR_DEVICE_ATTR_RO(fan7_input, fan_value, 6);
626 static SENSOR_DEVICE_ATTR_RO(fan8_input, fan_value, 7);
628 static SENSOR_DEVICE_ATTR_RO(fan1_source, fan_source, 0);
629 static SENSOR_DEVICE_ATTR_RO(fan2_source, fan_source, 1);
630 static SENSOR_DEVICE_ATTR_RO(fan3_source, fan_source, 2);
631 static SENSOR_DEVICE_ATTR_RO(fan4_source, fan_source, 3);
632 static SENSOR_DEVICE_ATTR_RO(fan5_source, fan_source, 4);
633 static SENSOR_DEVICE_ATTR_RO(fan6_source, fan_source, 5);
634 static SENSOR_DEVICE_ATTR_RO(fan7_source, fan_source, 6);
635 static SENSOR_DEVICE_ATTR_RO(fan8_source, fan_source, 7);
637 static SENSOR_DEVICE_ATTR_RW(fan1_alarm, fan_alarm, 0);
638 static SENSOR_DEVICE_ATTR_RW(fan2_alarm, fan_alarm, 1);
639 static SENSOR_DEVICE_ATTR_RW(fan3_alarm, fan_alarm, 2);
640 static SENSOR_DEVICE_ATTR_RW(fan4_alarm, fan_alarm, 3);
641 static SENSOR_DEVICE_ATTR_RW(fan5_alarm, fan_alarm, 4);
642 static SENSOR_DEVICE_ATTR_RW(fan6_alarm, fan_alarm, 5);
643 static SENSOR_DEVICE_ATTR_RW(fan7_alarm, fan_alarm, 6);
644 static SENSOR_DEVICE_ATTR_RW(fan8_alarm, fan_alarm, 7);
646 static struct attribute *fts_fan_attrs[] = {
647 &sensor_dev_attr_fan1_input.dev_attr.attr,
648 &sensor_dev_attr_fan2_input.dev_attr.attr,
649 &sensor_dev_attr_fan3_input.dev_attr.attr,
650 &sensor_dev_attr_fan4_input.dev_attr.attr,
651 &sensor_dev_attr_fan5_input.dev_attr.attr,
652 &sensor_dev_attr_fan6_input.dev_attr.attr,
653 &sensor_dev_attr_fan7_input.dev_attr.attr,
654 &sensor_dev_attr_fan8_input.dev_attr.attr,
656 &sensor_dev_attr_fan1_source.dev_attr.attr,
657 &sensor_dev_attr_fan2_source.dev_attr.attr,
658 &sensor_dev_attr_fan3_source.dev_attr.attr,
659 &sensor_dev_attr_fan4_source.dev_attr.attr,
660 &sensor_dev_attr_fan5_source.dev_attr.attr,
661 &sensor_dev_attr_fan6_source.dev_attr.attr,
662 &sensor_dev_attr_fan7_source.dev_attr.attr,
663 &sensor_dev_attr_fan8_source.dev_attr.attr,
665 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
666 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
667 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
668 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
669 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
670 &sensor_dev_attr_fan6_alarm.dev_attr.attr,
671 &sensor_dev_attr_fan7_alarm.dev_attr.attr,
672 &sensor_dev_attr_fan8_alarm.dev_attr.attr,
677 static SENSOR_DEVICE_ATTR_RO(in1_input, in_value, 0);
678 static SENSOR_DEVICE_ATTR_RO(in2_input, in_value, 1);
679 static SENSOR_DEVICE_ATTR_RO(in3_input, in_value, 2);
680 static SENSOR_DEVICE_ATTR_RO(in4_input, in_value, 3);
681 static struct attribute *fts_voltage_attrs[] = {
682 &sensor_dev_attr_in1_input.dev_attr.attr,
683 &sensor_dev_attr_in2_input.dev_attr.attr,
684 &sensor_dev_attr_in3_input.dev_attr.attr,
685 &sensor_dev_attr_in4_input.dev_attr.attr,
689 static const struct attribute_group fts_voltage_attr_group = {
690 .attrs = fts_voltage_attrs
693 static const struct attribute_group fts_temp_attr_group = {
694 .attrs = fts_temp_attrs
697 static const struct attribute_group fts_fan_attr_group = {
698 .attrs = fts_fan_attrs
701 static const struct attribute_group *fts_attr_groups[] = {
702 &fts_voltage_attr_group,
703 &fts_temp_attr_group,
708 /*****************************************************************************/
709 /* Module initialization / remove functions */
710 /*****************************************************************************/
711 static int fts_detect(struct i2c_client *client,
712 struct i2c_board_info *info)
716 /* detection works with revision greater or equal to 0x2b */
717 val = i2c_smbus_read_byte_data(client, FTS_DEVICE_REVISION_REG);
721 /* Device Detect Regs must have 0x17 0x34 and 0x54 */
722 val = i2c_smbus_read_byte_data(client, FTS_DEVICE_DETECT_REG_1);
726 val = i2c_smbus_read_byte_data(client, FTS_DEVICE_DETECT_REG_2);
730 val = i2c_smbus_read_byte_data(client, FTS_DEVICE_DETECT_REG_3);
735 * 0x10 == Baseboard Management Controller, 0x01 == Teutates
736 * Device ID Reg needs to be 0x11
738 val = i2c_smbus_read_byte_data(client, FTS_DEVICE_ID_REG);
742 strlcpy(info->type, fts_id[0].name, I2C_NAME_SIZE);
747 static int fts_remove(struct i2c_client *client)
749 struct fts_data *data = dev_get_drvdata(&client->dev);
751 watchdog_unregister_device(&data->wdd);
755 static int fts_probe(struct i2c_client *client)
758 struct fts_data *data;
761 struct device *hwmon_dev;
763 if (client->addr != 0x73)
766 /* Baseboard Management Controller check */
767 deviceid = i2c_smbus_read_byte_data(client, FTS_DEVICE_ID_REG);
768 if (deviceid > 0 && (deviceid & 0xF0) == 0x10) {
769 switch (deviceid & 0x0F) {
773 dev_dbg(&client->dev,
774 "No Baseboard Management Controller\n");
778 dev_dbg(&client->dev, "No fujitsu board\n");
782 data = devm_kzalloc(&client->dev, sizeof(struct fts_data),
787 mutex_init(&data->update_lock);
788 mutex_init(&data->access_lock);
789 data->client = client;
790 dev_set_drvdata(&client->dev, data);
792 err = i2c_smbus_read_byte_data(client, FTS_DEVICE_REVISION_REG);
797 hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
801 if (IS_ERR(hwmon_dev))
802 return PTR_ERR(hwmon_dev);
804 err = fts_watchdog_init(data);
808 dev_info(&client->dev, "Detected FTS Teutates chip, revision: %d.%d\n",
809 (revision & 0xF0) >> 4, revision & 0x0F);
813 /*****************************************************************************/
815 /*****************************************************************************/
816 static struct i2c_driver fts_driver = {
817 .class = I2C_CLASS_HWMON,
819 .name = "ftsteutates",
822 .probe_new = fts_probe,
823 .remove = fts_remove,
824 .detect = fts_detect,
825 .address_list = normal_i2c,
828 module_i2c_driver(fts_driver);
830 MODULE_AUTHOR("Thilo Cestonaro <thilo.cestonaro@ts.fujitsu.com>");
831 MODULE_DESCRIPTION("FTS Teutates driver");
832 MODULE_LICENSE("GPL");