Skip to contentSkip to conversation

hwmon: added kernel module for FTS BMC chip "Teutates"

PATCH Guenter Roeck 2 participants 2 messages Jul 4, 2016 – Jul 5, 2016 Hardware monitoring

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw
Quoted 48 lines · Thilo Cestonaro

From: Thilo Cestonaro <[email protected]>

This driver implements support for the FTS BMC Chip "Teutates".

---
 Documentation/hwmon/ftsteutates |  23 ++
 drivers/hwmon/Kconfig           |  11 +
 drivers/hwmon/Makefile          |   1 +
 drivers/hwmon/ftsteutates.c     | 834 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 869 insertions(+)
 create mode 100644 Documentation/hwmon/ftsteutates
 create mode 100644 drivers/hwmon/ftsteutates.c
Documentation/hwmon/ftsteutates new file +23 -0
new file mode 100644
index 0000000..2a1bf69
@@ -0,0 +1,23 @@
+Kernel driver ftsteutates
+=====================
+
+Supported chips:
+  * FTS Teutates
+    Prefix: 'ftsteutates'
+    Addresses scanned: I2C 0x73 (7-Bit)
+
+Author: Thilo Cestonaro <[email protected]>
+
+
+Description
+-----------
+The BMC Teutates is the Eleventh generation of Superior System
+monitoring and thermal management solution. It is builds on the basic
+functionality of the BMC Theseus and contains several new features and
+enhancements. It can monitor up to 4 voltages, 16 temperatures and
+8 fans. It also contains an integrated watchdog which is currently
+implemented in this driver.
+
+Specification of the chip can be found here:
+ftp:///pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/BMC-Teutates_Specification_V1.21.pdf
+ftp:///pub/Mainboard-OEM-Sales/Services/Software&Tools/Linux_SystemMonitoring&Watchdog&GPIO/Fujitsu_mainboards-1-Sensors_HowTo-en-US.pdf
drivers/hwmon/Kconfig +0 -0
index ff94007..8f5d30d 100644

drivers/hwmon/Kconfig config SENSORS_FSCHMD · line 495

Quoted 10 lines
drivers/hwmon/Kconfig +7 -0
@@ -486,6 +486,17 @@ config SENSORS_FSCHMD
 	  This driver can also be built as a module.  If so, the module
 	  will be called fschmd.
 
+config SENSORS_FTSTEUTATES
+	tristate "Fujitsu Technology Solutions sensor chip Teutates"
+	depends on I2C
+	help
+	  If you say yes here you get support for the Fujitsu Technology
+      Solutions (FTS) sensor chip "Teutates" including support for
+      the integrated watchdog.

Did you try to enable this ? Probably not, because if I apply your patch and try to run "make allmodconfig" I get

drivers/hwmon/Kconfig:495: syntax error drivers/hwmon/Kconfig:494: unknown option "Solutions" drivers/hwmon/Kconfig:495: unknown option "the" drivers/hwmon/Kconfig:498: syntax error

Quoted 83 lines
drivers/hwmon/Kconfig +4 -0
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ftsteutates.
+
 config SENSORS_GL518SM
 	tristate "Genesys Logic GL518SM"
 	depends on I2C
drivers/hwmon/Makefile +1 -0
index 2ef5b7c..dcad5f7 100644
@@ -62,6 +62,7 @@ obj-$(CONFIG_SENSORS_F71882FG)	+= f71882fg.o
 obj-$(CONFIG_SENSORS_F75375S)	+= f75375s.o
 obj-$(CONFIG_SENSORS_FAM15H_POWER) += fam15h_power.o
 obj-$(CONFIG_SENSORS_FSCHMD)	+= fschmd.o
+obj-$(CONFIG_SENSORS_FTSTEUTATES) += ftsteutates.o
 obj-$(CONFIG_SENSORS_G760A)	+= g760a.o
 obj-$(CONFIG_SENSORS_G762)	+= g762.o
 obj-$(CONFIG_SENSORS_GL518SM)	+= gl518sm.o
drivers/hwmon/ftsteutates.c new file +58 -0
new file mode 100644
index 0000000..19e0906
@@ -0,0 +1,834 @@
+/*
+ * fts.c, Support for the FTS Systemmonitoring Chip "Teutates"
+ *
+ * Copyright (C) 2016 Fujitsu Technology Solutions GmbH,
+ *		  Thilo Cestonaro <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+#include <linux/uaccess.h>
+#include <linux/watchdog.h>
+
+#define FTS_DEVICE_ID_REG		0x0000
+#define FTS_DEVICE_REVISION_REG		0x0001
+#define FTS_DEVICE_STATUS_REG		0x0004
+#define FTS_SATELLITE_STATUS_REG	0x0005
+#define FTS_EVENT_STATUS_REG		0x0006
+#define FTS_GLOBAL_CONTROL_REG		0x0007
+
+#define FTS_SENSOR_EVENT_REG		0x0010
+
+#define FTS_FAN_EVENT_REG		0x0014
+#define FTS_FAN_PRESENT_REG		0x0015
+
+#define FTS_POWER_ON_TIME_COUNTER_A	0x007A
+#define FTS_POWER_ON_TIME_COUNTER_B	0x007B
+#define FTS_POWER_ON_TIME_COUNTER_C	0x007C
+
+#define FTS_PAGE_SELECT_REG		0x007F
+
+#define FTS_WATCHDOG_TIME_PRESET	0x000B
+#define FTS_WATCHDOG_CONTROL		0x5081
+
+#define FTS_NO_FAN_SENSORS		0x08
+#define FTS_NO_TEMP_SENSORS		0x10
+#define FTS_NO_VOLT_SENSORS		0x04
+
+/* possible addresses */
+static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };

drivers/hwmon/ftsteutates.c line 68

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+
+static struct i2c_device_id fts_id[] = {
+	{ "ftsteutates", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, fts_id);
+
+struct fts_data {
+	struct i2c_client *client;
+	struct device *hwmon_dev;

This variable is not used outside the probe function and thus not needed in the data structure.

drivers/hwmon/ftsteutates.c line 70

Quoted 2 lines
drivers/hwmon/ftsteutates.c new file +2 -0
+	struct mutex update_lock;
+	bool valid; /* zero until following fields are valid */

false

drivers/hwmon/ftsteutates.c line 78

Quoted 8 lines
drivers/hwmon/ftsteutates.c new file +8 -0
+	unsigned long last_updated; /* in jiffies */
+	struct mutex access_lock;
+	u8 watchdog_resolution;
+
+	/* voltage */
+	u8 volt[FTS_NO_VOLT_SENSORS];
+
+	/* temprature */

temperature

That seems obvious from the variable names, though.

drivers/hwmon/ftsteutates.c line 86

Quoted 8 lines
drivers/hwmon/ftsteutates.c new file +8 -0
+	u8 temp_input[FTS_NO_TEMP_SENSORS]; /* value */
+	u8 temp_alarm; /* alarm */
+
+	/* fan */
+	u8 fan_present; /* presence */
+	u8 fan_input[FTS_NO_FAN_SENSORS]; /* revolutions per second */
+	u8 fan_source[FTS_NO_FAN_SENSORS]; /* sensor source */
+	u8 fan_alarm; /* alarm */

Those comments add no value (it appears obvious that fan_alarm refers to an alarm).

drivers/hwmon/ftsteutates.c line 91

Quoted 5 lines
drivers/hwmon/ftsteutates.c new file +5 -0
+};
+
+#define FTS_REG_FAN_INPUT(idx) (idx + 0x20)
+#define FTS_REG_FAN_SOURCE(idx) (idx + 0x30)
+#define FTS_REG_FAN_CONTROL(idx) ((idx<<16) + 0x4881)

Space before and after operators, please

drivers/hwmon/ftsteutates.c line 95

Quoted 4 lines
drivers/hwmon/ftsteutates.c new file +4 -0
+
+#define FTS_REG_TEMP_INPUT(idx) (idx + 0x40)
+#define FTS_REG_TEMP_CONTROL(idx) ((idx<<16) + 0x0681)
+

All macro parameters should be in ( ), such as

#define FTS_REG_TEMP_CONTROL(idx) (((idx) << 16) + 0x0681)

drivers/hwmon/ftsteutates.c line 104

Quoted 9 lines
drivers/hwmon/ftsteutates.c new file +9 -0
+/* voltage registers */
+static const u16 FTS_REG_VOLT[FTS_NO_VOLT_SENSORS] = {
+	  0x001A, 0x0018, 0x0019, 0x001B
+};
+
+/*****************************************************************************/
+/* I2C Helper functions							     */
+/*****************************************************************************/
+int fts_read_byte(struct i2c_client *client, unsigned short reg)

static

drivers/hwmon/ftsteutates.c line 106

Quoted 2 lines
drivers/hwmon/ftsteutates.c new file +2 -0
+{
+	int ret = -1;

Unnecessary initialization.

drivers/hwmon/ftsteutates.c line 107

Quoted 1 line
drivers/hwmon/ftsteutates.c new file +1 -0
+	unsigned char page = reg>>8;
				reg << 8

checkpatch --strict helps finding such places.

drivers/hwmon/ftsteutates.c line 114

Quoted 7 lines
drivers/hwmon/ftsteutates.c new file +7 -0
+	struct fts_data *data = dev_get_drvdata(&client->dev);
+
+	mutex_lock(&data->access_lock);
+
+	dev_dbg(&client->dev, "page select - page: 0x%.02x\n", page);
+	ret = i2c_smbus_write_byte_data(client, FTS_PAGE_SELECT_REG, page);
+

Please no empty line between functions and return value checks.

Quoted 4 lines
drivers/hwmon/ftsteutates.c new file +4 -0
+	if (ret < 0)
+		goto error;
+
+	reg &= 0xFF;

drivers/hwmon/ftsteutates.c line 128

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	ret = i2c_smbus_read_byte_data(client, reg);
+	dev_dbg(&client->dev, "read - reg: 0x%.02x: val: 0x%.02x\n", reg, ret);
+
+error:
+	mutex_unlock(&data->access_lock);
+	return ret;
+}
+
+int fts_write_byte(struct i2c_client *client, unsigned short reg,
+						   unsigned char value)

static

Please align continuation lines with '('.

drivers/hwmon/ftsteutates.c line 139

Quoted 11 lines
drivers/hwmon/ftsteutates.c new file +11 -0
+{
+	int ret;
+	unsigned char page = reg>>8;
+	struct fts_data *data = dev_get_drvdata(&client->dev);
+
+	mutex_lock(&data->access_lock);
+
+	dev_dbg(&client->dev, "page select - page: 0x%.02x\n", page);
+	ret = i2c_smbus_write_byte_data(client, FTS_PAGE_SELECT_REG,
+				page);
+

Please no empty line here.

Quoted 37 lines
drivers/hwmon/ftsteutates.c new file +37 -0
+	if (ret < 0)
+		goto error;
+
+	reg &= 0xFF;
+	dev_dbg(&client->dev,
+		"write - reg: 0x%.02x: val: 0x%.02x\n", reg, value);
+	ret = i2c_smbus_write_byte_data(client, reg, value);
+
+error:
+	mutex_unlock(&data->access_lock);
+	return ret;
+}
+
+/*****************************************************************************/
+/* Data Updater Helper function						     */
+/*****************************************************************************/
+static int fts_update_device(struct fts_data *data)
+{
+	int i;
+	int err = 0;
+
+	mutex_lock(&data->update_lock);
+	if (!time_after(jiffies, data->last_updated + 2 * HZ) && data->valid)
+		goto exit;
+
+	err = fts_read_byte(data->client, FTS_DEVICE_STATUS_REG);
+	if (err < 0)
+		goto exit;
+
+	data->valid = !!(err & 0x02); /* Data not ready yet */
+	if (unlikely(!data->valid)) {
+		err = -EAGAIN;
+		goto exit;
+	}
+
+	err = fts_read_byte(data->client, FTS_FAN_PRESENT_REG);
+	if (err < 0)

drivers/hwmon/ftsteutates.c line 186

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+		goto exit;
+	data->fan_present = err;
+
+	err = fts_read_byte(data->client, FTS_FAN_EVENT_REG);
+	if (err < 0)
+		goto exit;
+	data->fan_alarm = err;
+
+	for (i = 0; i < FTS_NO_FAN_SENSORS; i++) {
+		if (!!(data->fan_present & BIT(i))) {

Unnecessary !!

Quoted 36 lines
drivers/hwmon/ftsteutates.c new file +36 -0
+			err = fts_read_byte(data->client, FTS_REG_FAN_INPUT(i));
+			if (err < 0)
+				goto exit;
+			data->fan_input[i] = err;
+
+			err = fts_read_byte(data->client,
+					    FTS_REG_FAN_SOURCE(i));
+			if (err < 0)
+				goto exit;
+			data->fan_source[i] = err;
+		} else {
+			data->fan_input[i] = 0;
+			data->fan_source[i] = 0;
+		}
+	}
+
+	err = fts_read_byte(data->client, FTS_SENSOR_EVENT_REG);
+	if (err < 0)
+		goto exit;
+	data->temp_alarm = err;
+
+	for (i = 0; i < FTS_NO_TEMP_SENSORS; i++) {
+		err = fts_read_byte(data->client, FTS_REG_TEMP_INPUT(i));
+		if (err < 0)
+			goto exit;
+		data->temp_input[i] = err;
+	}
+
+	for (i = 0; i < FTS_NO_VOLT_SENSORS; i++) {
+		err = fts_read_byte(data->client, FTS_REG_VOLT[i]);
+		if (err < 0)
+			goto exit;
+		data->volt[i] = err;
+	}
+	data->last_updated = jiffies;
+	err = 0;

drivers/hwmon/ftsteutates.c line 232

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+exit:
+	mutex_unlock(&data->update_lock);
+	return err;
+}
+
+/*****************************************************************************/
+/* Watchdog functions							     */
+/*****************************************************************************/
+static int fts_wdt_set_resolution(struct watchdog_device *wdd, int resolution)
+{

You might as well pass struct fts_data * to this function.

drivers/hwmon/ftsteutates.c line 238

Quoted 6 lines
drivers/hwmon/ftsteutates.c new file +6 -0
+	struct fts_data *data;
+	int ret;
+
+	if (resolution != 1 && resolution != 60)
+		return -EINVAL;
+

The resolution variable passed to this function is always 1, so this check and ...

drivers/hwmon/ftsteutates.c line 245

Quoted 7 lines
drivers/hwmon/ftsteutates.c new file +7 -0
+	data = watchdog_get_drvdata(wdd);
+	ret = fts_read_byte(data->client, FTS_WATCHDOG_CONTROL);
+	if (ret < 0)
+		return ret;
+
+	ret = fts_write_byte(data->client, FTS_WATCHDOG_CONTROL,
+			     resolution == 1 ? ret | BIT(1) : ret & ~BIT(1));

... the resolution == 1 check here are unnecessary.

drivers/hwmon/ftsteutates.c line 249

Quoted 4 lines
drivers/hwmon/ftsteutates.c new file +4 -0
+	if (ret < 0)
+		return ret;
+
+	data->watchdog_resolution = resolution;

The calling code already sets data->watchdog_resolution.

Besides, data->watchdog_resolution is not used anywhere. What is the point of keeping it ?

drivers/hwmon/ftsteutates.c line 250

Quoted 1 line
drivers/hwmon/ftsteutates.c new file +1 -0
+	return ret;
	return 0;
Quoted 36 lines
drivers/hwmon/ftsteutates.c new file +36 -0
+}
+
+static int fts_wdt_start(struct watchdog_device *wdd)
+{
+	struct fts_data *data;
+
+	data = watchdog_get_drvdata(wdd);
+	return fts_write_byte(data->client, FTS_WATCHDOG_TIME_PRESET,
+			      wdd->timeout);
+}
+
+static int fts_wdt_stop(struct watchdog_device *wdd)
+{
+	struct fts_data *data;
+
+	data = watchdog_get_drvdata(wdd);
+	return fts_write_byte(data->client, FTS_WATCHDOG_TIME_PRESET, 0);
+}
+
+static const struct watchdog_info fts_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = "FTS Teutates Hardware Watchdog",
+};
+
+static const struct watchdog_ops fts_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = fts_wdt_start,
+	.stop = fts_wdt_stop,
+};
+
+static struct watchdog_device fts_wdt = {
+	.info = &fts_wdt_info,
+	.ops = &fts_wdt_ops,
+};
+
+static int fts_watchdog_init(struct fts_data *data)

drivers/hwmon/ftsteutates.c line 296

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+{
+	int ret, timeout;
+
+	watchdog_set_drvdata(&fts_wdt, data);
+
+	ret = fts_read_byte(data->client, FTS_WATCHDOG_TIME_PRESET);
+	if (ret < 0)
+		return ret;
+	timeout = ret;
+

Just assign to timeout directly. No need to use 'ret' as interim variable.

drivers/hwmon/ftsteutates.c line 305

Quoted 9 lines
drivers/hwmon/ftsteutates.c new file +9 -0
+	/* watchdog not running, set timeout to a default of 60 sec. */
+	if (timeout == 0) {
+		data->watchdog_resolution = 1;
+		ret = fts_wdt_set_resolution(&fts_wdt,
+					     data->watchdog_resolution);
+		if (ret < 0)
+			return ret;
+		fts_wdt.timeout = 60;
+

Unecessary empty line.

drivers/hwmon/ftsteutates.c line 310

Quoted 5 lines
drivers/hwmon/ftsteutates.c new file +5 -0
+	} else {
+		ret = fts_read_byte(data->client, FTS_WATCHDOG_CONTROL);
+		if (ret < 0)
+			return ret;
+		data->watchdog_resolution = !!(ret & BIT(1)) ? 1 : 60;

Unnecessary !!

drivers/hwmon/ftsteutates.c line 312

Quoted 2 lines
drivers/hwmon/ftsteutates.c new file +2 -0
+		fts_wdt.timeout = data->watchdog_resolution * timeout;
+		fts_wdt.status |= BIT(WDOG_ACTIVE);

WDOG_ACTIVE indicates that the watchdog device is opened. You need to set WDOG_HW_RUNNING instead.

drivers/hwmon/ftsteutates.c line 318

Quoted 6 lines
drivers/hwmon/ftsteutates.c new file +6 -0
+	}
+
+	/* Register our watchdog part */
+	fts_wdt.parent = &data->client->dev;
+	fts_wdt.min_timeout = 1;
+	fts_wdt.max_timeout = 0xFF;

max_timeout is not necessarly correct, isn't it ? If the watchdog is already running, and the resolution is set to 60 seconds, that should be 60 * 255 seconds.

The static nature of fts_wdt is problematic. If the driver is instantiated on multiple addresses, if a chip is there, and if the code above does not detect that the chip isn't really the chip it is supposed to be (it could be an eeprom or nvram with the right values in its registers), everything will be messed up.

You'll either need to add more checks (such as checking the i2c address, and possibly a flag to indicate if the driver is already instantiated), or keep all variables local, ie allocated with struct fts_data.

Quoted 53 lines
drivers/hwmon/ftsteutates.c new file +53 -0
+	ret = watchdog_register_device(&fts_wdt);
+	return ret;
+}
+
+/*****************************************************************************/
+/* SysFS handler functions						     */
+/*****************************************************************************/
+static ssize_t show_in_value(struct device *dev,
+			     struct device_attribute *devattr, char *buf)
+{
+	/* got from the systemboard specification */
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+	return sprintf(buf, "%u\n", data->volt[index]);
+}
+
+static ssize_t show_temp_value(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+	return sprintf(buf, "%u\n", data->temp_input[index]);
+}
+
+static ssize_t show_temp_fault(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+	/* 00h Temperature = Sensor Error */
+	return sprintf(buf, "%d\n", data->temp_input[index] == 0);
+}
+
+static ssize_t show_temp_alarm(struct device *dev,
+			       struct device_attribute *devattr, char *buf)

drivers/hwmon/ftsteutates.c line 381

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+{
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+

Please no double empty lines.

Quoted 7 lines
drivers/hwmon/ftsteutates.c new file +7 -0
+	return sprintf(buf, "%u\n", !!(data->temp_alarm & BIT(index)));
+}
+
+static ssize_t
+clear_temp_alarm(struct device *dev, struct device_attribute *devattr,
+				 const char *buf, size_t count)
+{

drivers/hwmon/ftsteutates.c line 398

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	unsigned long val;
+	unsigned char reg;
+	int err;
+
+	if (!data) {
+		dev_err(dev, "no dev drvdata available");
+		return -EINVAL;
+	}

This won't happen. Please no unnecessary error checks.

drivers/hwmon/ftsteutates.c line 408

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+
+	err = fts_update_device(data);
+	if (err < 0) {
+		count = err;
+		return err;
+	}
+
+	if (kstrtoul(buf, 10, &val) || val != 0) {
+		count = -EINVAL;
+		return count;
		return -EINVAL;

accomplishes exactly the same without assigning a negative value to an unsigned variable.

drivers/hwmon/ftsteutates.c line 412

Quoted 4 lines
drivers/hwmon/ftsteutates.c new file +4 -0
+	}
+
+	mutex_lock(&data->update_lock);
+	reg = fts_read_byte(data->client, FTS_REG_TEMP_CONTROL(index));

reg is declared as unsigned char, and thus will never be < 0.

drivers/hwmon/ftsteutates.c line 420

Quoted 8 lines
drivers/hwmon/ftsteutates.c new file +8 -0
+	if (reg < 0) {
+		count = reg;
+		goto error;
+	}
+
+	val = fts_write_byte(data->client, FTS_REG_TEMP_CONTROL(index),
+			     reg | 0x1);
+	if (val < 0) {

val is declared as unsigned long.

drivers/hwmon/ftsteutates.c line 421

Quoted 1 line
drivers/hwmon/ftsteutates.c new file +1 -0
+		count = val;

count is size_t which is unsigned long. Granted, the return value is ssize_t and it will thus be converted back to signed, but it is still a bad idea to rely on that.

Quoted 55 lines
drivers/hwmon/ftsteutates.c new file +55 -0
+		goto error;
+	}
+	data->valid = false;
+
+error:
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+static ssize_t show_fan_value(struct device *dev,
+			      struct device_attribute *devattr, char *buf)
+{
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+	return sprintf(buf, "%u\n", data->fan_input[index]);
+}
+
+static ssize_t show_fan_source(struct device *dev,
+			       struct device_attribute *devattr, char *buf)
+{
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+	return sprintf(buf, "%u\n", data->fan_source[index]);
+}
+
+static ssize_t show_fan_alarm(struct device *dev,
+			      struct device_attribute *devattr, char *buf)
+{
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	int err;
+
+	err = fts_update_device(data);
+	if (err < 0)
+		return err;
+
+	return sprintf(buf, "%d\n", !!(data->fan_alarm & BIT(index)));
+}
+
+static ssize_t
+clear_fan_alarm(struct device *dev, struct device_attribute *devattr,
+				const char *buf, size_t count)
+{

drivers/hwmon/ftsteutates.c line 486

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	struct fts_data *data = dev_get_drvdata(dev);
+	int index = to_sensor_dev_attr(devattr)->index;
+	unsigned long val;
+	unsigned char reg;
+	int err;
+
+	if (!data) {
+		dev_err(dev, "no dev drvdata available");
+		return -EINVAL;
+	}

Please no unnecessary error checks.

drivers/hwmon/ftsteutates.c line 490

Quoted 4 lines
drivers/hwmon/ftsteutates.c new file +4 -0
+
+	err = fts_update_device(data);
+	if (err < 0) {
+		count = err;

count is size_t (unsigned long).

drivers/hwmon/ftsteutates.c line 496

Quoted 6 lines
drivers/hwmon/ftsteutates.c new file +6 -0
+		return err;
+	}
+
+	if (kstrtoul(buf, 10, &val) || val != 0) {
+		count = -EINVAL;
+		return count;
		return -EINVAL;

drivers/hwmon/ftsteutates.c line 501

Quoted 5 lines
drivers/hwmon/ftsteutates.c new file +5 -0
+	}
+
+	mutex_lock(&data->update_lock);
+	reg = fts_read_byte(data->client, FTS_REG_FAN_CONTROL(index));
+	if (reg < 0) {

reg is declared as unsigned char.

drivers/hwmon/ftsteutates.c line 508

Quoted 7 lines
drivers/hwmon/ftsteutates.c new file +7 -0
+		count = reg;
+		goto error;
+	}
+
+	val = fts_write_byte(data->client, FTS_REG_FAN_CONTROL(index),
+			     reg | 0x1);
+	if (val < 0) {

val is unsigned long. Why not use ret here ?

Please build your code with W=1 to see (and hopefully eliminate) all those errors.

Quoted 230 lines
drivers/hwmon/ftsteutates.c new file +230 -0
+		count = val;
+		goto error;
+	}
+	data->valid = false;
+
+error:
+	mutex_unlock(&data->update_lock);
+	return count;
+}
+
+/*****************************************************************************/
+/* SysFS structs							     */
+/*****************************************************************************/
+
+/* Temprature sensors */
+static SENSOR_DEVICE_ATTR(temp1_input,  S_IRUGO, show_temp_value, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp2_input,  S_IRUGO, show_temp_value, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp3_input,  S_IRUGO, show_temp_value, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp4_input,  S_IRUGO, show_temp_value, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp5_input,  S_IRUGO, show_temp_value, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp6_input,  S_IRUGO, show_temp_value, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp7_input,  S_IRUGO, show_temp_value, NULL, 6);
+static SENSOR_DEVICE_ATTR(temp8_input,  S_IRUGO, show_temp_value, NULL, 7);
+static SENSOR_DEVICE_ATTR(temp9_input,  S_IRUGO, show_temp_value, NULL, 8);
+static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp_value, NULL, 9);
+static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO, show_temp_value, NULL, 10);
+static SENSOR_DEVICE_ATTR(temp12_input, S_IRUGO, show_temp_value, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp13_input, S_IRUGO, show_temp_value, NULL, 12);
+static SENSOR_DEVICE_ATTR(temp14_input, S_IRUGO, show_temp_value, NULL, 13);
+static SENSOR_DEVICE_ATTR(temp15_input, S_IRUGO, show_temp_value, NULL, 14);
+static SENSOR_DEVICE_ATTR(temp16_input, S_IRUGO, show_temp_value, NULL, 15);
+
+static SENSOR_DEVICE_ATTR(temp1_fault,  S_IRUGO, show_temp_fault, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp2_fault,  S_IRUGO, show_temp_fault, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp3_fault,  S_IRUGO, show_temp_fault, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp4_fault,  S_IRUGO, show_temp_fault, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp5_fault,  S_IRUGO, show_temp_fault, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp6_fault,  S_IRUGO, show_temp_fault, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp7_fault,  S_IRUGO, show_temp_fault, NULL, 6);
+static SENSOR_DEVICE_ATTR(temp8_fault,  S_IRUGO, show_temp_fault, NULL, 7);
+static SENSOR_DEVICE_ATTR(temp9_fault,  S_IRUGO, show_temp_fault, NULL, 8);
+static SENSOR_DEVICE_ATTR(temp10_fault, S_IRUGO, show_temp_fault, NULL, 9);
+static SENSOR_DEVICE_ATTR(temp11_fault, S_IRUGO, show_temp_fault, NULL, 10);
+static SENSOR_DEVICE_ATTR(temp12_fault, S_IRUGO, show_temp_fault, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp13_fault, S_IRUGO, show_temp_fault, NULL, 12);
+static SENSOR_DEVICE_ATTR(temp14_fault, S_IRUGO, show_temp_fault, NULL, 13);
+static SENSOR_DEVICE_ATTR(temp15_fault, S_IRUGO, show_temp_fault, NULL, 14);
+static SENSOR_DEVICE_ATTR(temp16_fault, S_IRUGO, show_temp_fault, NULL, 15);
+
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 0);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 1);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 2);
+static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 3);
+static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 4);
+static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 5);
+static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 6);
+static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 7);
+static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 8);
+static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 9);
+static SENSOR_DEVICE_ATTR(temp11_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 10);
+static SENSOR_DEVICE_ATTR(temp12_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 11);
+static SENSOR_DEVICE_ATTR(temp13_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 12);
+static SENSOR_DEVICE_ATTR(temp14_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 13);
+static SENSOR_DEVICE_ATTR(temp15_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 14);
+static SENSOR_DEVICE_ATTR(temp16_alarm, S_IRUGO | S_IWUSR, show_temp_alarm,
+			  clear_temp_alarm, 15);
+
+static struct attribute *fts_temp_attrs[] = {
+	&sensor_dev_attr_temp1_input.dev_attr.attr,
+	&sensor_dev_attr_temp2_input.dev_attr.attr,
+	&sensor_dev_attr_temp3_input.dev_attr.attr,
+	&sensor_dev_attr_temp4_input.dev_attr.attr,
+	&sensor_dev_attr_temp5_input.dev_attr.attr,
+	&sensor_dev_attr_temp6_input.dev_attr.attr,
+	&sensor_dev_attr_temp7_input.dev_attr.attr,
+	&sensor_dev_attr_temp8_input.dev_attr.attr,
+	&sensor_dev_attr_temp9_input.dev_attr.attr,
+	&sensor_dev_attr_temp10_input.dev_attr.attr,
+	&sensor_dev_attr_temp11_input.dev_attr.attr,
+	&sensor_dev_attr_temp12_input.dev_attr.attr,
+	&sensor_dev_attr_temp13_input.dev_attr.attr,
+	&sensor_dev_attr_temp14_input.dev_attr.attr,
+	&sensor_dev_attr_temp15_input.dev_attr.attr,
+	&sensor_dev_attr_temp16_input.dev_attr.attr,
+
+	&sensor_dev_attr_temp1_fault.dev_attr.attr,
+	&sensor_dev_attr_temp2_fault.dev_attr.attr,
+	&sensor_dev_attr_temp3_fault.dev_attr.attr,
+	&sensor_dev_attr_temp4_fault.dev_attr.attr,
+	&sensor_dev_attr_temp5_fault.dev_attr.attr,
+	&sensor_dev_attr_temp6_fault.dev_attr.attr,
+	&sensor_dev_attr_temp7_fault.dev_attr.attr,
+	&sensor_dev_attr_temp8_fault.dev_attr.attr,
+	&sensor_dev_attr_temp9_fault.dev_attr.attr,
+	&sensor_dev_attr_temp10_fault.dev_attr.attr,
+	&sensor_dev_attr_temp11_fault.dev_attr.attr,
+	&sensor_dev_attr_temp12_fault.dev_attr.attr,
+	&sensor_dev_attr_temp13_fault.dev_attr.attr,
+	&sensor_dev_attr_temp14_fault.dev_attr.attr,
+	&sensor_dev_attr_temp15_fault.dev_attr.attr,
+	&sensor_dev_attr_temp16_fault.dev_attr.attr,
+
+	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp3_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp4_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp5_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp6_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp7_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp8_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp9_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp10_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp11_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp12_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp13_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp14_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp15_alarm.dev_attr.attr,
+	&sensor_dev_attr_temp16_alarm.dev_attr.attr,
+	NULL
+};
+
+/* Fans */
+static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_value, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_value, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_value, NULL, 2);
+static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_value, NULL, 3);
+static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan_value, NULL, 4);
+static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan_value, NULL, 5);
+static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan_value, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan_value, NULL, 7);
+
+static SENSOR_DEVICE_ATTR(fan1_source, S_IRUGO, show_fan_source, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_source, S_IRUGO, show_fan_source, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan3_source, S_IRUGO, show_fan_source, NULL, 2);
+static SENSOR_DEVICE_ATTR(fan4_source, S_IRUGO, show_fan_source, NULL, 3);
+static SENSOR_DEVICE_ATTR(fan5_source, S_IRUGO, show_fan_source, NULL, 4);
+static SENSOR_DEVICE_ATTR(fan6_source, S_IRUGO, show_fan_source, NULL, 5);
+static SENSOR_DEVICE_ATTR(fan7_source, S_IRUGO, show_fan_source, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan8_source, S_IRUGO, show_fan_source, NULL, 7);
+
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 0);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 1);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 2);
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 3);
+static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 4);
+static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 5);
+static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 6);
+static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO | S_IWUSR,
+			 show_fan_alarm, clear_fan_alarm, 7);
+
+static struct attribute *fts_fan_attrs[] = {
+	&sensor_dev_attr_fan1_input.dev_attr.attr,
+	&sensor_dev_attr_fan2_input.dev_attr.attr,
+	&sensor_dev_attr_fan3_input.dev_attr.attr,
+	&sensor_dev_attr_fan4_input.dev_attr.attr,
+	&sensor_dev_attr_fan5_input.dev_attr.attr,
+	&sensor_dev_attr_fan6_input.dev_attr.attr,
+	&sensor_dev_attr_fan7_input.dev_attr.attr,
+	&sensor_dev_attr_fan8_input.dev_attr.attr,
+
+	&sensor_dev_attr_fan1_source.dev_attr.attr,
+	&sensor_dev_attr_fan2_source.dev_attr.attr,
+	&sensor_dev_attr_fan3_source.dev_attr.attr,
+	&sensor_dev_attr_fan4_source.dev_attr.attr,
+	&sensor_dev_attr_fan5_source.dev_attr.attr,
+	&sensor_dev_attr_fan6_source.dev_attr.attr,
+	&sensor_dev_attr_fan7_source.dev_attr.attr,
+	&sensor_dev_attr_fan8_source.dev_attr.attr,
+
+	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan4_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan5_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan6_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan7_alarm.dev_attr.attr,
+	&sensor_dev_attr_fan8_alarm.dev_attr.attr,
+	NULL
+};
+
+/* Voltages */
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_value, NULL, 0);
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_value, NULL, 1);
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_value, NULL, 2);
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_value, NULL, 3);
+static struct attribute *fts_voltage_attrs[] = {
+	&sensor_dev_attr_in1_input.dev_attr.attr,
+	&sensor_dev_attr_in2_input.dev_attr.attr,
+	&sensor_dev_attr_in3_input.dev_attr.attr,
+	&sensor_dev_attr_in4_input.dev_attr.attr,
+	NULL
+};
+
+static const struct attribute_group fts_voltage_attr_group = {
+	.attrs = fts_voltage_attrs
+};
+
+static const struct attribute_group fts_temp_attr_group = {
+	.attrs = fts_temp_attrs
+};
+
+static const struct attribute_group fts_fan_attr_group = {
+	.attrs = fts_fan_attrs
+};
+
+static const struct attribute_group *fts_attr_groups[] = {
+	&fts_voltage_attr_group,
+	&fts_temp_attr_group,

drivers/hwmon/ftsteutates.c line 748

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	&fts_fan_attr_group,
+	NULL
+};
+
+/*****************************************************************************/
+/* Module initialization / remove functions				     */
+/*****************************************************************************/
+static int fts_remove(struct i2c_client *client)
+{
+	fts_wdt_stop(&fts_wdt);

If the watchdog is running, the watchdog core should prevent the driver from being unloaded, so this should not be necessary.

drivers/hwmon/ftsteutates.c line 758

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	watchdog_unregister_device(&fts_wdt);
+	return 0;
+}
+
+static int fts_probe(struct i2c_client *client,
+			     const struct i2c_device_id *id)
+{
+	u8 revision;
+	struct fts_data *data;
+	long err;

Why long and not int ?

drivers/hwmon/ftsteutates.c line 768

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	s8 deviceid;
+
+	/* Baseboard Management Controller check */
+	deviceid = i2c_smbus_read_byte_data(client, FTS_DEVICE_ID_REG);
+	if (deviceid > 0 && (deviceid & 0xF0) == 0x10) {
+		switch (deviceid & 0x0F) {
+		case 0x01:
+			break;
+		default:
+			dev_dbg(&client->dev, "No aseboard Management Controller\n");

Baseboard

Quoted 23 lines
drivers/hwmon/ftsteutates.c new file +23 -0
+			return -ENODEV;
+		}
+	} else {
+		dev_dbg(&client->dev, "No fujitsu board\n");
+		return -ENODEV;
+	}
+
+	data = devm_kzalloc(&client->dev, sizeof(struct fts_data),
+			    GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	mutex_init(&data->update_lock);
+	mutex_init(&data->access_lock);
+	data->client = client;
+	dev_set_drvdata(&client->dev, data);
+
+	err = i2c_smbus_read_byte_data(client, FTS_DEVICE_REVISION_REG);
+	if (err < 0) {
+		dev_err(&client->dev,
+			"couldn't read device revision register\n");
+		return err;
+	}

drivers/hwmon/ftsteutates.c line 801

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+	revision = err;
+
+	data->hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
+								 "ftsteutates",
+								 data,
+								 fts_attr_groups
+								 );
+	if (IS_ERR(data->hwmon_dev)) {
+		err = PTR_ERR(data->hwmon_dev);
+		goto exit_detach;

Those gotos (and the cleanup) are not necessary.
There is no data to be freed, and the watchdog device is not registered. The only possible effect is that the watchdog is stopped if it happened to be running, but one could argue that it should continue to run in this case. Obviously, something must be badly wrong if this happens, and reacting by stopping the watchdog seems to be the wrong solution.

Quoted 16 lines
drivers/hwmon/ftsteutates.c new file +16 -0
+	}
+
+	err = fts_watchdog_init(data);
+	if (err)
+		goto exit_detach;
+
+	dev_info(&client->dev, "Detected FTS Teutates chip, revision: %d.%d\n",
+		 (revision & 0xF0)>>4, revision & 0x0F);
+	return 0;
+
+exit_detach:
+	fts_remove(client); /* will also free data for us */
+	return err;
+}
+
+/*****************************************************************************/

drivers/hwmon/ftsteutates.c line 827

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +10 -0
+/* Module Details							     */
+/*****************************************************************************/
+static struct i2c_driver fts_driver = {
+	.driver = {
+		.name = "ftsteutates",
+	},
+	.id_table = fts_id,
+	.probe = fts_probe,
+	.remove = fts_remove,
+	.address_list = normal_i2c,

Unnecessary without detect function.

Quoted 10 lines
drivers/hwmon/ftsteutates.c new file +7 -0
+};
+
+module_i2c_driver(fts_driver);
+
+MODULE_AUTHOR("Thilo Cestonaro <[email protected]>");
+MODULE_DESCRIPTION("FTS Teutates driver");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.8.1
#1 lore raw

Hey Guenter!

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+config SENSORS_FTSTEUTATES
+	tristate "Fujitsu Technology Solutions sensor chip Teutates"
+	depends on I2C
+	help
+	  If you say yes here you get support for the Fujitsu Technology
+      Solutions (FTS) sensor chip "Teutates" including support for
+      the integrated watchdog.

Did you try to enable this ? Probably not, because if I apply your patch and try to run "make allmodconfig" I get

Quoted 5 lines

drivers/hwmon/Kconfig:495: syntax error drivers/hwmon/Kconfig:494: unknown option "Solutions" drivers/hwmon/Kconfig:495: unknown option "the" drivers/hwmon/Kconfig:498: syntax error

Sorry about that! Indention was wrong.

Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	unsigned char page = reg>>8;
				reg << 8

checkpatch --strict helps finding such places.

Thanks for the hint.
Next patch will be checked with --strict, promise! :)

Quoted 5 lines

Review

Quoted 2 lines

(quoted diff) +1 -0
+		fts_wdt.status |= BIT(WDOG_ACTIVE);

WDOG_ACTIVE indicates that the watchdog device is opened. You need to set WDOG_HW_RUNNING instead.

Testing with Kernel 4.4 which has no HW_RUNNING. Forgot to switch it back when creating the patch.

Quoted 10 lines

Review

Quoted 8 lines
(quoted diff) +7 -0
+		count = reg;
+		goto error;
+	}
+
+	val = fts_write_byte(data->client, FTS_REG_FAN_CONTROL(index),
+			     reg | 0x1);
+	if (val < 0) {

val is unsigned long. Why not use ret here ?

Quoted 3 lines

Please build your code with W=1 to see (and hopefully eliminate) all those errors.

Yes! Will use W=1 from now on!

Cheers,
Thilo