From nobody Mon Oct 6 06:43:23 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6AD121D5AA; Wed, 23 Jul 2025 17:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753292106; cv=none; b=fI85n2Gv/rmIdiKutbtSUVUyrxclXQSmc3Vw9d7Wqve4R9DZFfkfaKPOGj2BhjWXbmhhp0EtHjGpYpzP7cnGQcP6uelep9eoX5j9OhdgMMIH8rjiYmHTYnkHXVYiaHVkWvJMRLfSuq6yk61g9d6TZW3J+OEdRaKUf6NljeSa3wE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753292106; c=relaxed/simple; bh=SSXg8ECWTIfwP0u4L4pppiz7mam/bpcy0GKszAlTwNg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tz2vAWAwMJpRmxcGWCqharcAx5yIf8T2jcgxsXN/zfTz5HXDzXdxODoCInSmGapQ3KMHwXJOmx70hRpbnFHTpYhP2kON81XZuuyKGDG/LaPx8gQsKCkrHni3tZV6phfdGpZvOI0bnBxuk7pN13w+mrKULNGNpZ5P/53UxWVkhck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lnSyv37g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lnSyv37g" Received: by smtp.kernel.org (Postfix) with ESMTPS id A0146C4CEF4; Wed, 23 Jul 2025 17:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753292106; bh=SSXg8ECWTIfwP0u4L4pppiz7mam/bpcy0GKszAlTwNg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lnSyv37gO5xEHqB8K/CQpzv8VsCYVOl5A46fWuaQ3DShpB3S9EK1/g5sx1s0AST5L 2DWJbjiG7Mnkgn9YAWwB+twyx3bC6umrddPQEk3hKNo8lPTZRJb5FTcmMW5sDsICxs w1IWe1LB1i6wEL1t9NFcsZd8iUYuATN/jb0/M49Ru7Wh0YB9cbWnC6fBmv2lygU39N uUMEYjIV22THLf2tfnwYaCv3JbM9zjittx6WHhngM+Ru1iqsfXaGCpuzI2xUqCE7Dm Y3iK67ZS06YkkRFr1q/POiUoi4RI9yZ4kV0ywEzSd0oEKor2VeamUIMSnFz54s7ekX 32lxvXm6ID9PA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F335C83F17; Wed, 23 Jul 2025 17:35:06 +0000 (UTC) From: Dimitri Fedrau via B4 Relay Date: Wed, 23 Jul 2025 19:34:56 +0200 Subject: [PATCH v5 1/2] pwm: mc33xs2410: add hwmon support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250723-mc33xs2410-hwmon-v5-1-f62aab71cd59@liebherr.com> References: <20250723-mc33xs2410-hwmon-v5-0-f62aab71cd59@liebherr.com> In-Reply-To: <20250723-mc33xs2410-hwmon-v5-0-f62aab71cd59@liebherr.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Dimitri Fedrau , Dimitri Fedrau X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753292105; l=4016; i=dimitri.fedrau@liebherr.com; s=20241202; h=from:subject:message-id; bh=7Ba6D8Nsq70XyxD+K636D3Vr+HrfmANRkuQUcbHIPpM=; b=Yaf9Q27JI8cGgE4AVwyyY7jDYQB6CmIz1eC+D5TC5XcPI8bV5vjVbWPl3DdTS++lMvSe3KSU0 Z0zxTv8nh8xDtV1acg6fIdb3PgS+A/SCS+myjLGVawzrc5yxYuySto4 X-Developer-Key: i=dimitri.fedrau@liebherr.com; a=ed25519; pk=rT653x09JSQvotxIqQl4/XiI4AOiBZrdOGvxDUbb5m8= X-Endpoint-Received: by B4 Relay for dimitri.fedrau@liebherr.com/20241202 with auth_id=290 X-Original-From: Dimitri Fedrau Reply-To: dimitri.fedrau@liebherr.com From: Dimitri Fedrau Support for hwmon is provided by a separate driver residing in hwmon subsystem which is implemented as auxiliary device. Add handling of this device. Signed-off-by: Dimitri Fedrau --- drivers/pwm/Kconfig | 1 + drivers/pwm/pwm-mc33xs2410.c | 20 ++++++++++++++++++-- include/linux/mc33xs2410.h | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 3ef1757502ebd92b30584cd10611311a0fbfc03b..64f1c86340fdc7d0ef41bf14be5= f6f0623a2bd31 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -436,6 +436,7 @@ config PWM_MC33XS2410 tristate "MC33XS2410 PWM support" depends on OF depends on SPI + select AUXILIARY_BUS help NXP MC33XS2410 high-side switch driver. The MC33XS2410 is a four channel high-side switch. The device is operational from 3.0 V diff --git a/drivers/pwm/pwm-mc33xs2410.c b/drivers/pwm/pwm-mc33xs2410.c index a1ac3445ccdb4709d92e0075d424a8abc1416eee..6d99e3ff7239891d87711d98aa4= 63ac158af70e1 100644 --- a/drivers/pwm/pwm-mc33xs2410.c +++ b/drivers/pwm/pwm-mc33xs2410.c @@ -17,11 +17,14 @@ * behavior of the output pin that is neither the old nor the new state, * rather something in between. */ +#define DEFAULT_SYMBOL_NAMESPACE "PWM_MC33XS2410" =20 +#include #include #include #include #include +#include #include #include #include @@ -120,12 +123,19 @@ static int mc33xs2410_read_reg(struct spi_device *spi= , u8 reg, u16 *val, u8 flag return mc33xs2410_read_regs(spi, ®, flag, val, 1); } =20 -static int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *v= al) +int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val) { return mc33xs2410_read_reg(spi, reg, val, MC33XS2410_FRAME_IN_DATA_RD); } +EXPORT_SYMBOL_GPL(mc33xs2410_read_reg_ctrl); =20 -static int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, = u8 val) +int mc33xs2410_read_reg_diag(struct spi_device *spi, u8 reg, u16 *val) +{ + return mc33xs2410_read_reg(spi, reg, val, 0); +} +EXPORT_SYMBOL_GPL(mc33xs2410_read_reg_diag); + +int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val) { u16 tmp; int ret; @@ -139,6 +149,7 @@ static int mc33xs2410_modify_reg(struct spi_device *spi= , u8 reg, u8 mask, u8 val =20 return mc33xs2410_write_reg(spi, reg, tmp); } +EXPORT_SYMBOL_GPL(mc33xs2410_modify_reg); =20 static u8 mc33xs2410_pwm_get_freq(u64 period) { @@ -314,6 +325,7 @@ static int mc33xs2410_reset(struct device *dev) static int mc33xs2410_probe(struct spi_device *spi) { struct device *dev =3D &spi->dev; + struct auxiliary_device *adev; struct pwm_chip *chip; int ret; =20 @@ -361,6 +373,10 @@ static int mc33xs2410_probe(struct spi_device *spi) if (ret < 0) return dev_err_probe(dev, ret, "Failed to add pwm chip\n"); =20 + adev =3D devm_auxiliary_device_create(dev, "hwmon", NULL); + if (!adev) + return dev_err_probe(dev, -ENODEV, "Failed to register hwmon device\n"); + return 0; } =20 diff --git a/include/linux/mc33xs2410.h b/include/linux/mc33xs2410.h new file mode 100644 index 0000000000000000000000000000000000000000..31c0edf10dd7370a0c3e6039472= 56577d4d40854 --- /dev/null +++ b/include/linux/mc33xs2410.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Liebherr-Electronics and Drives GmbH + */ +#ifndef _MC33XS2410_H +#define _MC33XS2410_H + +#include + +MODULE_IMPORT_NS("PWM_MC33XS2410"); + +int mc33xs2410_read_reg_ctrl(struct spi_device *spi, u8 reg, u16 *val); +int mc33xs2410_read_reg_diag(struct spi_device *spi, u8 reg, u16 *val); +int mc33xs2410_modify_reg(struct spi_device *spi, u8 reg, u8 mask, u8 val); + +#endif /* _MC33XS2410_H */ --=20 2.39.5 From nobody Mon Oct 6 06:43:23 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 382CA2222A7; Wed, 23 Jul 2025 17:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753292107; cv=none; b=VZGTwq4L/O9y2qfjn18bmHp7KMhu3OjV7WODe9rrRvMAC7/Ay7sKMMplIByP7n8sfdM+ZONX0yotXVjWNFZwZ+82BvrA1QfYEtvyCfxPzO7YPCvchITolig6v+MYXgCdleQBoDRcD1UnsxSEnr8u2YzGy31ivfCILhET9saxB2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753292107; c=relaxed/simple; bh=hBmYcaNHoIqZydKfbh8wgcy7HWw8qwr/hO73PbZOsWk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TuHf2xJNJTqpYCJofuwA0k4rdMNlQmavBWbya4Xw/P7rzFsZK3AM0fY/2Qx0LuEjMFiZEE3w3hxbc8U2tzQ8i+TWW0QUJnfFEuPsMIRCRFDJyyGqiz2yjry0ymTR1BxQA7xH4cXn7lVu66kYShvkjQahmvG0oIq9NHv+DMB8IuA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iw975G9v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Iw975G9v" Received: by smtp.kernel.org (Postfix) with ESMTPS id AF057C4CEF1; Wed, 23 Jul 2025 17:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753292106; bh=hBmYcaNHoIqZydKfbh8wgcy7HWw8qwr/hO73PbZOsWk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Iw975G9vP3k4kKCoH2XJDvsdqQM5ltnpznHImCa2KflV/9Stdmcrz675XAjXqBRPg PE6ORU2bGRr6pXBS/mVUd/wbx8yfIwTOzro7gJmlSRPxjeJRdgDeT3fdvYJrkf1yu+ 5c82MJ4WMCfuRNDTRPRZkrIr1Fom/v2IcqNqS5YRG/tzQeuFDSiSeDISiQ/Ga8NiaS GbdkP/9NHff1B5jgj+zdNG1dJRKBbpIMLQ/vkfxjtGPVfBWLlpDPRL4X08tLDPGulv qA7dEwvP7NoBYMnf+MTbv2+JBH+W/eD3e9mDWMHUc9+nSKh4+gIWvvwrHFMkBPSgde MFA5loM+tEWZw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CADBC87FC5; Wed, 23 Jul 2025 17:35:06 +0000 (UTC) From: Dimitri Fedrau via B4 Relay Date: Wed, 23 Jul 2025 19:34:57 +0200 Subject: [PATCH v5 2/2] hwmon: add support for MC33XS2410 hardware monitoring Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250723-mc33xs2410-hwmon-v5-2-f62aab71cd59@liebherr.com> References: <20250723-mc33xs2410-hwmon-v5-0-f62aab71cd59@liebherr.com> In-Reply-To: <20250723-mc33xs2410-hwmon-v5-0-f62aab71cd59@liebherr.com> To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jean Delvare , Guenter Roeck , Jonathan Corbet Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Dimitri Fedrau , Dimitri Fedrau X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753292105; l=8847; i=dimitri.fedrau@liebherr.com; s=20241202; h=from:subject:message-id; bh=YCCOttXZ9iOZy8OoouzxY5slMvI1RSmNaE/50XP8LQ8=; b=q2Q9U7owpZSCdSikq27SLgh4CUvrElB2yDXwFneDlqJUgIi8lt8r6Po+B6eTs3724EZE2U4H+ hcHPAQZ8FiQBLV2lNat1ufVeWGcO++gm6E9Qv49ENBdWSbu2s0RTIeE X-Developer-Key: i=dimitri.fedrau@liebherr.com; a=ed25519; pk=rT653x09JSQvotxIqQl4/XiI4AOiBZrdOGvxDUbb5m8= X-Endpoint-Received: by B4 Relay for dimitri.fedrau@liebherr.com/20241202 with auth_id=290 X-Original-From: Dimitri Fedrau Reply-To: dimitri.fedrau@liebherr.com From: Dimitri Fedrau The device is able to monitor temperature, voltage and current of each of the four outputs. Add basic support for monitoring the temperature of the four outputs and the die temperature. Signed-off-by: Dimitri Fedrau Acked-by: Guenter Roeck --- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/mc33xs2410_hwmon.rst | 34 ++++++ drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/mc33xs2410_hwmon.c | 178 +++++++++++++++++++++++++++= ++++ 5 files changed, 224 insertions(+) diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst index b45bfb4ebf30823094fe82726d2237f90be17642..d292a86ac5da902cad02c1965c9= 0f5de530489df 100644 --- a/Documentation/hwmon/index.rst +++ b/Documentation/hwmon/index.rst @@ -167,6 +167,7 @@ Hardware Monitoring Kernel Drivers max77705 max8688 mc13783-adc + mc33xs2410_hwmon mc34vr500 mcp3021 menf21bmc diff --git a/Documentation/hwmon/mc33xs2410_hwmon.rst b/Documentation/hwmon= /mc33xs2410_hwmon.rst new file mode 100644 index 0000000000000000000000000000000000000000..8a2136ef9139118518741796208= 15f4e74e6e5e9 --- /dev/null +++ b/Documentation/hwmon/mc33xs2410_hwmon.rst @@ -0,0 +1,34 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver mc33xs2410_hwmon +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D + +Supported devices: + + * NXPs MC33XS2410 + + Datasheet: https://www.nxp.com/docs/en/data-sheet/MC33XS2410.pdf + +Authors: + + Dimitri Fedrau + +Description +----------- + +The MC33XS2410 is a four channel self-protected high-side switch featuring +hardware monitoring functions such as temperature, current and voltages fo= r each +of the four channels. + +Sysfs entries +------------- + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D +temp1_label "Central die temperature" +temp1_input Measured temperature of central die + +temp[2-5]_label "Channel [1-4] temperature" +temp[2-5]_input Measured temperature of a single channel +temp[2-5]_alarm Temperature alarm +temp[2-5]_max Maximal temperature +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 079620dd42862ef5e026697e9e1b1fcd5b8be298..9d28fcf7cd2a6f9e2f54694a717= bd85ff4047b46 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -700,6 +700,16 @@ config SENSORS_MC13783_ADC help Support for the A/D converter on MC13783 and MC13892 PMIC. =20 +config SENSORS_MC33XS2410 + tristate "MC33XS2410 HWMON support" + depends on PWM_MC33XS2410 + help + If you say yes here you get hardware monitoring support for + MC33XS2410. + + This driver can also be built as a module. If so, the module + will be called mc33xs2410_hwmon. + config SENSORS_FSCHMD tristate "Fujitsu Siemens Computers sensor chips" depends on (X86 || COMPILE_TEST) && I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 48e5866c0c9a7677089d1001a9c5ae4adebff5d5..cd8bc4752b4dbf015c6eb461576= 26f4e8f87dfae 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -165,6 +165,7 @@ obj-$(CONFIG_SENSORS_MAX31790) +=3D max31790.o obj-$(CONFIG_MAX31827) +=3D max31827.o obj-$(CONFIG_SENSORS_MAX77705) +=3D max77705-hwmon.o obj-$(CONFIG_SENSORS_MC13783_ADC)+=3D mc13783-adc.o +obj-$(CONFIG_SENSORS_MC33XS2410) +=3D mc33xs2410_hwmon.o obj-$(CONFIG_SENSORS_MC34VR500) +=3D mc34vr500.o obj-$(CONFIG_SENSORS_MCP3021) +=3D mcp3021.o obj-$(CONFIG_SENSORS_TC654) +=3D tc654.o diff --git a/drivers/hwmon/mc33xs2410_hwmon.c b/drivers/hwmon/mc33xs2410_hw= mon.c new file mode 100644 index 0000000000000000000000000000000000000000..23eb90e337091724c5562703df7= d77a5fae6253b --- /dev/null +++ b/drivers/hwmon/mc33xs2410_hwmon.c @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2025 Liebherr-Electronics and Drives GmbH + */ + +#include +#include +#include +#include +#include +#include + +/* ctrl registers */ + +#define MC33XS2410_TEMP_WT 0x29 +#define MC33XS2410_TEMP_WT_MASK GENMASK(7, 0) + +/* diag registers */ + +/* chan in { 1 ... 4 } */ +#define MC33XS2410_OUT_STA(chan) (0x02 + (chan) - 1) +#define MC33XS2410_OUT_STA_OTW BIT(8) + +#define MC33XS2410_TS_TEMP_DIE 0x26 +#define MC33XS2410_TS_TEMP_MASK GENMASK(9, 0) + +/* chan in { 1 ... 4 } */ +#define MC33XS2410_TS_TEMP(chan) (0x2f + (chan) - 1) + +static const struct hwmon_channel_info * const mc33xs2410_hwmon_info[] =3D= { + HWMON_CHANNEL_INFO(temp, + HWMON_T_LABEL | HWMON_T_INPUT, + HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | + HWMON_T_ALARM, + HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | + HWMON_T_ALARM, + HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | + HWMON_T_ALARM, + HWMON_T_LABEL | HWMON_T_INPUT | HWMON_T_MAX | + HWMON_T_ALARM), + NULL, +}; + +static umode_t mc33xs2410_hwmon_is_visible(const void *data, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_alarm: + case hwmon_temp_label: + return 0444; + case hwmon_temp_max: + return 0644; + default: + return 0; + } +} + +static int mc33xs2410_hwmon_read(struct device *dev, + enum hwmon_sensor_types type, + u32 attr, int channel, long *val) +{ + struct spi_device *spi =3D dev_get_drvdata(dev); + u16 reg_val; + int ret; + u8 reg; + + switch (attr) { + case hwmon_temp_input: + reg =3D (channel =3D=3D 0) ? MC33XS2410_TS_TEMP_DIE : + MC33XS2410_TS_TEMP(channel); + ret =3D mc33xs2410_read_reg_diag(spi, reg, ®_val); + if (ret < 0) + return ret; + + /* LSB is 0.25 degree celsius */ + *val =3D FIELD_GET(MC33XS2410_TS_TEMP_MASK, reg_val) * 250 - 40000; + return 0; + case hwmon_temp_alarm: + ret =3D mc33xs2410_read_reg_diag(spi, MC33XS2410_OUT_STA(channel), + ®_val); + if (ret < 0) + return ret; + + *val =3D FIELD_GET(MC33XS2410_OUT_STA_OTW, reg_val); + return 0; + case hwmon_temp_max: + ret =3D mc33xs2410_read_reg_ctrl(spi, MC33XS2410_TEMP_WT, ®_val); + if (ret < 0) + return ret; + + /* LSB is 1 degree celsius */ + *val =3D FIELD_GET(MC33XS2410_TEMP_WT_MASK, reg_val) * 1000 - 40000; + return 0; + default: + return -EOPNOTSUPP; + } +} + +static int mc33xs2410_hwmon_write(struct device *dev, + enum hwmon_sensor_types type, u32 attr, + int channel, long val) +{ + struct spi_device *spi =3D dev_get_drvdata(dev); + + switch (attr) { + case hwmon_temp_max: + val =3D clamp_val(val, -40000, 215000); + + /* LSB is 1 degree celsius */ + val =3D (val / 1000) + 40; + return mc33xs2410_modify_reg(spi, MC33XS2410_TEMP_WT, + MC33XS2410_TEMP_WT_MASK, val); + default: + return -EOPNOTSUPP; + } +} + +static const char *const mc33xs2410_temp_label[] =3D { + "Central die temperature", + "Channel 1 temperature", + "Channel 2 temperature", + "Channel 3 temperature", + "Channel 4 temperature", +}; + +static int mc33xs2410_read_string(struct device *dev, + enum hwmon_sensor_types type, + u32 attr, int channel, const char **str) +{ + *str =3D mc33xs2410_temp_label[channel]; + + return 0; +} + +static const struct hwmon_ops mc33xs2410_hwmon_hwmon_ops =3D { + .is_visible =3D mc33xs2410_hwmon_is_visible, + .read =3D mc33xs2410_hwmon_read, + .read_string =3D mc33xs2410_read_string, + .write =3D mc33xs2410_hwmon_write, +}; + +static const struct hwmon_chip_info mc33xs2410_hwmon_chip_info =3D { + .ops =3D &mc33xs2410_hwmon_hwmon_ops, + .info =3D mc33xs2410_hwmon_info, +}; + +static int mc33xs2410_hwmon_probe(struct auxiliary_device *adev, + const struct auxiliary_device_id *id) +{ + struct device *dev =3D &adev->dev; + struct spi_device *spi =3D container_of(dev->parent, struct spi_device, d= ev); + struct device *hwmon; + + hwmon =3D devm_hwmon_device_register_with_info(dev, NULL, spi, + &mc33xs2410_hwmon_chip_info, + NULL); + return PTR_ERR_OR_ZERO(hwmon); +} + +static const struct auxiliary_device_id mc33xs2410_hwmon_ids[] =3D { + { + .name =3D "pwm_mc33xs2410.hwmon", + }, + { } +}; +MODULE_DEVICE_TABLE(auxiliary, mc33xs2410_hwmon_ids); + +static struct auxiliary_driver mc33xs2410_hwmon_driver =3D { + .probe =3D mc33xs2410_hwmon_probe, + .id_table =3D mc33xs2410_hwmon_ids, +}; +module_auxiliary_driver(mc33xs2410_hwmon_driver); + +MODULE_DESCRIPTION("NXP MC33XS2410 hwmon driver"); +MODULE_AUTHOR("Dimitri Fedrau "); +MODULE_LICENSE("GPL"); --=20 2.39.5