hwmon: Driver for Nuvoton NCT7363Y
Subsystems (4)
v6 cover hwmon: Driver for Nuvoton NCT7363Y
From: Ban Feng <[email protected]>
NCT7363Y is an I2C based hardware monitoring chip from Nuvoton.
Changes since version 5:
- use lower case for inline function
- remove enum chips and refine code
- use regmap_read_bulk() to avoid the locks
- add fan speed low limit (register 0x6c, 0x6d) and alarm attributes (register 0x34, 0x35)
- add regmap caching capabilities
- fix "checkpatch --strict" report in FANIN_SEL
- Macro argument reuse 'x' - possible side-effects
Changes since version 4:
- add Datasheet information and refine words in yaml and rst files
- remove fan-common.yaml since it is already in hwmon-next
- refine the commit messages
- modify the type of returned value in some functions
- refine lock/unlock in nct7363_write_pwm and accessing HVAL/LVAL registers
- refine nct7363_init_chip
- add range check in nct7363_present_pwm_fanin
- add i2c_device_id table
- add nct7362 to of_device_id and i2c_device_id table
Changes since version 3:
- Cherry-pick the fan-common.yaml in [1]
- Fix "checkpatch --strict" report
- Replace BIT_CHECK() with BIT()
- Fix CamelCase defines or variables
- Drop enum chips
- Drop all local caching and just read values through regmap
- Drop chip auto-detection since it increases boot time
[1]: https://patchwork.kernel.org/project/linux-hwmon/patch/
[email protected]/
Changes since version 2:
- Cherry-pick the fan-common.yaml in [1]
- Fix nct736x typo and add unevaluatedProperties
[1]: https://patchwork.kernel.org/project/linux-hwmon/patch/
[email protected]/
Changes since version 1:
- Modify NCT736X(nct736x) to NCT7363Y(nct7363)
- Convert to devm_hwmon_device_register_with_info API
- All ID tables are next to each other and should be consistent between i2c_device_id and of_device_id
- Ref. fan-common.yaml and modify properties (nuvoton,pwm-mask/ nuvoton,fanin-mask) to (pwms/tach-ch)
- Convert to devm_regmap_init_i2c API
- Remove unused function (watchdog timer)
- Fix uninitialized symbol which is reported by kernel test robot
Ban Feng (2):
dt-bindings: hwmon: Add NCT7363Y documentation
hwmon: Add driver for I2C chip Nuvoton NCT7363Y
.../bindings/hwmon/nuvoton,nct7363.yaml | 66 +++ Documentation/hwmon/index.rst | 1 + Documentation/hwmon/nct7363.rst | 33 ++ MAINTAINERS | 8 + drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/nct7363.c | 446 ++++++++++++++++++ 7 files changed, 566 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml create mode 100644 Documentation/hwmon/nct7363.rst create mode 100644 drivers/hwmon/nct7363.c
Signature · 1 line
2.34.1
PATCH v6 1/2 dt-bindings: hwmon: Add NCT7363Y documentation
From: Ban Feng <[email protected]>
Add bindings for the Nuvoton NCT7363Y Fan Controller
--- .../bindings/hwmon/nuvoton,nct7363.yaml | 66 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 72 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml
Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml new file +66 -0
@@ -0,0 +1,66 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/nuvoton,nct7363.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton NCT7363Y Hardware Monitoring IC + +maintainers: + - Ban Feng <[email protected]> + +description: | + The NCT7363Y is a fan controller which provides up to 16 independent + FAN input monitors, and up to 16 independent PWM outputs with SMBus interface. + + Datasheets: Available from Nuvoton upon request + +properties: + compatible: + enum: + - nuvoton,nct7363 + - nuvoton,nct7362 + + reg: + maxItems: 1 + + "#pwm-cells": + const: 2 + +patternProperties: + "^fan-[0-9]+$": + $ref: fan-common.yaml# + unevaluatedProperties: false + required: + - pwms + - tach-ch + +required: + - compatible + - reg + - "#pwm-cells" + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + hwmon: hwmon@22 { + compatible = "nuvoton,nct7363"; + reg = <0x22>; + #pwm-cells = <2>; + + fan-0 { + pwms = <&hwmon 0 50000>; + tach-ch = /bits/ 8 <0x00>; + }; + fan-1 { + pwms = <&hwmon 1 50000>; + tach-ch = /bits/ 8 <0x01>; + }; + }; + };
MAINTAINERS +6 -0
@@ -15882,6 +15882,12 @@ S: Maintained F: Documentation/devicetree/bindings/hwmon/nuvoton,nct6775.yaml F: drivers/hwmon/nct6775-i2c.c +NCT7363 HARDWARE MONITOR DRIVER +M: Ban Feng <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml + NETCONSOLE M: Breno Leitao <[email protected]> S: Maintained
Signature · 1 line
2.34.1
Re: [PATCH v6 1/2] dt-bindings: hwmon: Add NCT7363Y documentation
Quoted 8 lines · On Tue, Oct 22, 2024 at 01:29:04PM +0800, [email protected] wrote:
From: Ban Feng <[email protected]>
Add bindings for the Nuvoton NCT7363Y Fan Controller
Reviewed-by Rob Herring <[email protected]>Reviewed-by Paul Menzel <[email protected]>Signed-off-by Ban Feng <[email protected]>
Applied.
Thanks,
Guenter
PATCH v6 2/2 hwmon: Add driver for I2C chip Nuvoton NCT7363Y
In reply to [email protected]From: Ban Feng <[email protected]>
The NCT7363Y is a fan controller which provides up to 16 independent FAN input monitors. It can report each FAN input count values. The NCT7363Y also provides up to 16 independent PWM outputs. Each PWM can output specific PWM signal by manual mode to control the FAN duty outside.
--- Documentation/hwmon/index.rst | 1 + Documentation/hwmon/nct7363.rst | 35 +++ MAINTAINERS | 2 + drivers/hwmon/Kconfig | 11 + drivers/hwmon/Makefile | 1 + drivers/hwmon/nct7363.c | 447 ++++++++++++++++++++++++++++++++ 6 files changed, 497 insertions(+) create mode 100644 Documentation/hwmon/nct7363.rst create mode 100644 drivers/hwmon/nct7363.c
Documentation/hwmon/index.rst +1 -0
@@ -174,6 +174,7 @@ Hardware Monitoring Kernel Drivers mpq8785 nct6683 nct6775 + nct7363 nct7802 nct7904 npcm750-pwm-fan
Documentation/hwmon/nct7363.rst new file +35 -0
@@ -0,0 +1,35 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver nct7363 +===================== + +Supported chip: + + * Nuvoton NCT7363Y + + Prefix: nct7363 + + Addresses: I2C 0x20, 0x21, 0x22, 0x23 + +Author: Ban Feng <[email protected]> + + +Description +----------- + +The NCT7363Y is a fan controller which provides up to 16 independent +FAN input monitors, and up to 16 independent PWM outputs with SMBus interface. + + +Sysfs entries +------------- + +Currently, the driver supports the following features: + +========== ========================================== +fanX_input provide current fan rotation value in RPM +fanX_alarm report fan low speed real status +fanX_min get or set fan count threshold + +pwmX get or set PWM fan control value. +========== ==========================================
MAINTAINERS +2 -0
@@ -15887,6 +15887,8 @@ M: Ban Feng <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/hwmon/nuvoton,nct7363.yaml +F: Documentation/hwmon/nct7363.rst +F: drivers/hwmon/nct7363.c NETCONSOLE M: Breno Leitao <[email protected]>
drivers/hwmon/Kconfig +11 -0
@@ -1670,6 +1670,17 @@ config SENSORS_NCT6775_I2C This driver can also be built as a module. If so, the module will be called nct6775-i2c. +config SENSORS_NCT7363 + tristate "Nuvoton NCT7363Y" + depends on I2C + select REGMAP_I2C + help + If you say yes here you get support for the Nuvoton NCT7363Y + hardware monitoring chip. + + This driver can also be built as a module. If so, the module + will be called nct7363. + config SENSORS_NCT7802 tristate "Nuvoton NCT7802Y" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -171,6 +171,7 @@ obj-$(CONFIG_SENSORS_NCT6775_CORE) += nct6775-core.o nct6775-objs := nct6775-platform.o obj-$(CONFIG_SENSORS_NCT6775) += nct6775.o obj-$(CONFIG_SENSORS_NCT6775_I2C) += nct6775-i2c.o +obj-$(CONFIG_SENSORS_NCT7363) += nct7363.o obj-$(CONFIG_SENSORS_NCT7802) += nct7802.o obj-$(CONFIG_SENSORS_NCT7904) += nct7904.o obj-$(CONFIG_SENSORS_NPCM7XX) += npcm750-pwm-fan.o
drivers/hwmon/nct7363.c new file +447 -0
447 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v6 2/2] hwmon: Add driver for I2C chip Nuvoton NCT7363Y
Le 22/10/2024 à 07:29, [email protected] a écrit :
Quoted 10 lines
From: Ban Feng <[email protected]>
The NCT7363Y is a fan controller which provides up to 16 independent FAN input monitors. It can report each FAN input count values. The NCT7363Y also provides up to 16 independent PWM outputs. Each PWM can output specific PWM signal by manual mode to control the FAN duty outside.
Signed-off-by Ban Feng <[email protected]>---
Hi,
a few nitpick, should there be a v7 and if they make sense to you.
drivers/hwmon/nct7363.c line 52
Quoted 4 lines
drivers/hwmon/nct7363.c new file +4
-0+static const struct of_device_id nct7363_of_match[] = { + { .compatible ="nuvoton,nct7363" , }, + { .compatible ="nuvoton,nct7362" , }, + { },
Usually, a comma is not added after a terminator entry.
Quoted 7 lines
drivers/hwmon/nct7363.c new file +7
-0+}; +MODULE_DEVICE_TABLE (of, nct7363_of_match); + +struct nct7363_data { +struct regmap *regmap; + +u16 fanin_mask;
drivers/hwmon/nct7363.c line 69
Quoted 10 lines
drivers/hwmon/nct7363.c new file +10
-0+u16 pwm_mask; +}; + +static int nct7363_read_fan (struct device *dev,u32 attr,int channel, +long *val) +{ +struct nct7363_data *data =dev_get_drvdata (dev); +unsigned int reg; +u8 regval[2 ]; +int ret =0 ;
No need to init.
Quoted 39 lines
drivers/hwmon/nct7363.c new file +39
-0+u16 cnt; + +switch (attr) { +case hwmon_fan_input: +/* +* High-byte register should be read first to latch +* synchronous low-byte value +*/ + ret =regmap_bulk_read (data->regmap, +NCT7363_REG_FANINX_HVAL (channel), + ®val,2 ); +if (ret) +return ret; + + cnt = (regval[0 ] <<5 ) | (regval[1 ] &NCT7363_FANINX_LVAL_MASK ); + *val =fan_from_reg (cnt); +return 0 ; +case hwmon_fan_min: + ret =regmap_bulk_read (data->regmap, +NCT7363_REG_FANINX_HL (channel), + ®val,2 ); +if (ret) +return ret; + + cnt = (regval[0 ] <<5 ) | (regval[1 ] &NCT7363_FANINX_LVAL_MASK ); + *val =fan_from_reg (cnt); +return 0 ; +case hwmon_fan_alarm: + ret =regmap_read (data->regmap, +NCT7363_REG_LSRS (channel), ®); +if (ret) +return ret; + + *val = (long )ALARM_SEL (reg, channel) >0 ?1 :0 ; +return 0 ; +default : +return -EOPNOTSUPP ; + } +}
...
Quoted 7 lines
drivers/hwmon/nct7363.c new file +7
-0+static int nct7363_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct device_node *child; +struct nct7363_data *data; +struct device *hwmon_dev; +int ret;
drivers/hwmon/nct7363.c line 414
Quoted 10 lines
drivers/hwmon/nct7363.c new file +10
-0+ + data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + data->regmap =devm_regmap_init_i2c (client, &nct7363_regmap_config); +if (IS_ERR (data->regmap)) +return PTR_ERR (data->regmap); + +for_each_child_of_node (dev->of_node, child) {
for_each_child_of_node_scoped() to slightly simplify code and save a few lines?
Quoted 5 lines
drivers/hwmon/nct7363.c new file +5
-0+ ret =nct7363_present_pwm_fanin (dev, child, data); +if (ret) { +of_node_put (child); +return ret; + }
drivers/hwmon/nct7363.c line 429
Quoted 10 lines
drivers/hwmon/nct7363.c new file +10
-0+ } + +/* Initialize the chip */ + ret =nct7363_init_chip (data); +if (ret) +return ret; + + hwmon_dev = +devm_hwmon_device_register_with_info (dev, client->name, data, + &nct7363_chip_info,NULL );
return devm_hwmon_device_register_with_info()?
drivers/hwmon/nct7363.c line 431
Quoted 2 lines
drivers/hwmon/nct7363.c new file +2
-0+return PTR_ERR_OR_ZERO (hwmon_dev); +}
...
CJ
Guenter Roeck
maintainerRe: [PATCH v6 2/2] hwmon: Add driver for I2C chip Nuvoton NCT7363Y
On 10/22/24 00:20, Christophe JAILLET wrote:
[ ... ]
Quoted 6 lines
Quoted 3 lines
+
hwmon_dev=
+ devm_hwmon_device_register_with_info(dev,client->name, data, +&nct7363_chip_info, NULL);return
devm_hwmon_device_register_with_info()?
No, because the function needs to return an integer, not a pointer. And
return PTR_ERR_OR_ZERO(devm_hwmon_device_register_with_info(...));
would look a bit awkward.
Guenter
Re: [PATCH v6 2/2] hwmon: Add driver for I2C chip Nuvoton NCT7363Y
Quoted 10 lines · Guenter Roeck
On 10/22/24 00:20, Christophe JAILLET wrote:
[ ... ]Quoted 6 lines
drivers/hwmon/nct7363.c line 429
Quoted 3 lines
drivers/hwmon/nct7363.c new file +3
-0+ hwmon_dev = +devm_hwmon_device_register_with_info (dev, client->name, data, + &nct7363_chip_info,NULL );return
devm_hwmon_device_register_with_info()?
Quoted 7 lines
No, because the function needs to return an integer, not a pointer. And
return PTR_ERR_OR_ZERO(devm_hwmon_device_register_with_info(...));would look a bit awkward.
Guenter
Hi Guenter and Christophe,
I'll keep following this driver and check with these suggestions.
Thanks,
Ban
Guenter Roeck
maintainerRe: [PATCH v6 2/2] hwmon: Add driver for I2C chip Nuvoton NCT7363Y
In reply to [email protected]Quoted 9 lines · On Tue, Oct 22, 2024 at 01:29:05PM +0800, [email protected] wrote:
From: Ban Feng <[email protected]>
The NCT7363Y is a fan controller which provides up to 16 independent FAN input monitors. It can report each FAN input count values. The NCT7363Y also provides up to 16 independent PWM outputs. Each PWM can output specific PWM signal by manual mode to control the FAN duty outside.
Signed-off-by Ban Feng <[email protected]>
Applied. I did fix a couple of the nitpicks raised by Christophe, but I did not replace for_each_child_of_node() with for_each_child_of_node_scoped() since I can not test the code and did not want to make a functional change.
Thanks,
Guenter
Re: [PATCH v6 2/2] hwmon: Add driver for I2C chip Nuvoton NCT7363Y
Quoted 12 lines · Guenter Roeck
Quoted 9 lines · On Tue, Oct 22, 2024 at 01:29:05PM +0800, [email protected] wrote:
From: Ban Feng <[email protected]>
The NCT7363Y is a fan controller which provides up to 16 independent FAN input monitors. It can report each FAN input count values. The NCT7363Y also provides up to 16 independent PWM outputs. Each PWM can output specific PWM signal by manual mode to control the FAN duty outside.
Signed-off-by Ban Feng <[email protected]>
Quoted 7 lines
Applied. I did fix a couple of the nitpicks raised by Christophe, but I did not replace
for_each_child_of_node()withfor_each_child_of_node_scoped()since I can not test the code and did not want to make a functional change.Thanks,
Guenter
Hi Guenter,
Appreciate your kind support,
I'll keep following your version and check the part of for_each_child_of_node_scoped.
Thanks,
Ban