From nobody Thu Dec 18 08:32:25 2025 Received: from mail11.truemail.it (mail11.truemail.it [217.194.8.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E76E23534D; Wed, 2 Apr 2025 10:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.194.8.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743589324; cv=none; b=WDjlSi9S9K1+uk6q/ykdf9t5o4NF811G9V3DKHzzOiZAXSqkjt2/eIfg4m9vm/Cu2Dd6J4G93CvzmpCJ65b44s+UIqV3/p6tz/1aZD6fHOpEg5bxIzhIpK6YEVFK+98oX97QxV/eCDNSpyaQhCJsAcM8Y2hQJHA2vjOucM12gF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743589324; c=relaxed/simple; bh=oPk6ucGcDI1wEgXM+63PrveBDg05TKuPFs6H/5AgwpU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FXcEJrHuY5WyelYxIu65TyYwF3uGpuMlolxy92ZDbH9cIbdDLM4gnwC3ejgqzOvHiuV7BeV5QQTKMLql+Ga1LhTeUNpu6OwNDz/HWAijKwnth5eTfpD7OkyIkAO51DwQK/U5Sk34bs8Uv2FbkA7bjT2YW7L24TCvwipjQDDi+3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=dolcini.it; spf=pass smtp.mailfrom=dolcini.it; dkim=pass (2048-bit key) header.d=dolcini.it header.i=@dolcini.it header.b=r2wXuuto; arc=none smtp.client-ip=217.194.8.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=dolcini.it Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dolcini.it Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dolcini.it header.i=@dolcini.it header.b="r2wXuuto" Received: from francesco-nb.corp.toradex.com (31-10-206-125.static.upc.ch [31.10.206.125]) by mail11.truemail.it (Postfix) with ESMTPA id 19F6F1F936; Wed, 2 Apr 2025 12:21:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dolcini.it; s=default; t=1743589313; bh=U0nPMu7F4Ahw1UZcx/AIz4XJ14OTdfCkOQ65to8yGPo=; h=From:To:Subject; b=r2wXuutoPk+kTdd849Dkw7VavNojN8naow68u6fboOdY8y/L384ISL7lB1HjOHHiI +Xd3evMsy4TZ/DQTKP75k/Wv/NYJV/wyxdZ4w3LQ4QC4kbKYVbXLIcmVSlrrjpJLr4 3b5srBpiOJEyFqwZNXFCjSIsSdlAt2dg++PRjgkcoFXto+z7jJlg4vGuVwVETlzUSw /DPJAqrc28jGsnxCgCn1PaUxmM3F5RxFQahSysu2+tChyg7VVdiuI3U09ngkuXQVii erzIdNMqaXfBaIGRuma+OqBaRIbP7t/lr5otBTZSvNKmqbjyhuQKlAGapu4+8EFqOE ve20ofcO2ahZw== From: Francesco Dolcini To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , Quentin Schulz Cc: Francesco Dolcini , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output Date: Wed, 2 Apr 2025 12:21:45 +0200 Message-Id: <20250402102146.65406-2-francesco@dolcini.it> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250402102146.65406-1-francesco@dolcini.it> References: <20250402102146.65406-1-francesco@dolcini.it> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Francesco Dolcini Add properties to describe the fan and the PWM controller output. Link: https://www.ti.com/lit/gpn/amc6821 Signed-off-by: Francesco Dolcini Reviewed-by: Rob Herring (Arm) --- v4: - add #pwm-cells description - remove useless first #pwm-cells, that was supposed to be the instance number v3: https://lore.kernel.org/all/20250331155229.147879-2-francesco@dolcini.i= t/ - explicitly describe the fan, use standard PWM and FAN bindings - pwm.yaml cannot be referenced, because of the $nodename pattern that is enforced there v2: https://lore.kernel.org/all/20250224180801.128685-2-francesco@dolcini.i= t/ - no changes v1: https://lore.kernel.org/all/20250218165633.106867-2-francesco@dolcini.i= t/ --- .../devicetree/bindings/hwmon/ti,amc6821.yaml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml b/Docu= mentation/devicetree/bindings/hwmon/ti,amc6821.yaml index 5d33f1a23d03..9ca7356760a7 100644 --- a/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml +++ b/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml @@ -28,6 +28,17 @@ properties: i2c-mux: type: object =20 + fan: + $ref: fan-common.yaml# + unevaluatedProperties: false + + "#pwm-cells": + const: 2 + description: | + Number of cells in a PWM specifier. + - cell 0: PWM period in nanoseconds + - cell 1: PWM polarity: 0 or PWM_POLARITY_INVERTED + required: - compatible - reg @@ -50,9 +61,14 @@ examples: #address-cells =3D <1>; #size-cells =3D <0>; =20 - fan@18 { + fan_controller: fan@18 { compatible =3D "ti,amc6821"; reg =3D <0x18>; + #pwm-cells =3D <2>; + + fan { + pwms =3D <&fan_controller 40000 0>; + }; }; }; =20 --=20 2.39.5 From nobody Thu Dec 18 08:32:25 2025 Received: from mail11.truemail.it (mail11.truemail.it [217.194.8.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E70B23496B; Wed, 2 Apr 2025 10:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.194.8.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743589324; cv=none; b=P9k3vt+5V5QtAYazJp9Q47OaevPus7YWWkg1RHbYHETLRHFYZNlqyBsmQpstn8kNRitpnKB1hvNtG/BBiln4dxuV8dWYBaP3CKZwspTyDHNK2KkS9bDtCE8DgRaEaE8loubuEQwp1PbTG0Te7jHTqDMZISAfZ4eLzB16YbWUhRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743589324; c=relaxed/simple; bh=026L5mpFASeol/7opVh9CmSxoITExZz10Pcyq8430eU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Lz8mkBoMXlui6TBqiI/dHGnaUzYw19Dp3eOus9jS3ipQdeQ28EqNGpRabABiEYVyRF6nRFmIRCQUAqgXI1RkyNIEdpq2mx/Q3RgJ4kE1rjkI1ZxAVphqnuwFCUIyEEJrnvks8YhYxLyhQpc9OXW7kItOjoJrZNiA4hCtA/Zywc8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=dolcini.it; spf=pass smtp.mailfrom=dolcini.it; dkim=pass (2048-bit key) header.d=dolcini.it header.i=@dolcini.it header.b=Iq1BRouQ; arc=none smtp.client-ip=217.194.8.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=dolcini.it Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dolcini.it Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dolcini.it header.i=@dolcini.it header.b="Iq1BRouQ" Received: from francesco-nb.corp.toradex.com (31-10-206-125.static.upc.ch [31.10.206.125]) by mail11.truemail.it (Postfix) with ESMTPA id CF18B1F942; Wed, 2 Apr 2025 12:21:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dolcini.it; s=default; t=1743589314; bh=W9Ytkjyg7W4FjQduy9rzFOZWJ4BB5kGItiVAPwrBlZo=; h=From:To:Subject; b=Iq1BRouQ6dwtoocS2wdk7M2Jp9YUcXGWpxObc2Y1DCirTM5VVJT0aC9roj/u2BR1Y 4RzMp8vhqxVI56m2sw5oizD+uwh4BTW7ARpJS74YT9AYygF6prXHmDGAAf7NIEpiAb v1h77AnBsPX4Cc0e94uxrBIaq3QhX4WunpRAqokGrzHE9PdQ8bHG2rB+AElwKl9va9 2RnVLCnMDKR2vHR9IxZIgoAwZlwrGofh+tIo7MdHrgWW+0/7p7JhB5VJQ6PbHIHDHk IlS+RiXxmlkaapzByTIzroSVOe9sW+PjD9K0z86folu85FpYmRlB6v265A/AdaoXDg FbsaPZ4qmRweQ== From: Francesco Dolcini To: Jean Delvare , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Farouk Bouabid , Quentin Schulz Cc: Francesco Dolcini , linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF Date: Wed, 2 Apr 2025 12:21:46 +0200 Message-Id: <20250402102146.65406-3-francesco@dolcini.it> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250402102146.65406-1-francesco@dolcini.it> References: <20250402102146.65406-1-francesco@dolcini.it> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Francesco Dolcini Add support to configure the PWM-Out pin polarity based on the device tree. The binding would allow also to configure the PWM period, this is currently not implemented by the driver. The driver has a module option to set the PWM polarity (normal=3D0, inverted=3D1), when specified it always takes the precedence over the DT. Signed-off-by: Francesco Dolcini Reviewed-by: Guenter Roeck --- v4: - remove first #pwm-cells v3: https://lore.kernel.org/all/20250331155229.147879-3-francesco@dolcini.i= t/ - configure PWM polarity using standard PWM DT properties v2: https://lore.kernel.org/lkml/20250224180801.128685-3-francesco@dolcini.= it/ - pwminv module parameter takes always the precedence over the DT property v1: https://lore.kernel.org/all/20250218165633.106867-3-francesco@dolcini.i= t/ --- drivers/hwmon/amc6821.c | 50 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c index 1e3c6acd8974..13a789cc85d2 100644 --- a/drivers/hwmon/amc6821.c +++ b/drivers/hwmon/amc6821.c @@ -23,9 +23,12 @@ #include #include #include +#include #include #include =20 +#include + /* * Addresses to scan. */ @@ -37,7 +40,7 @@ static const unsigned short normal_i2c[] =3D {0x18, 0x19,= 0x1a, 0x2c, 0x2d, 0x2e, * Insmod parameters */ =20 -static int pwminv; /*Inverted PWM output. */ +static int pwminv =3D -1; /*Inverted PWM output. */ module_param(pwminv, int, 0444); =20 static int init =3D 1; /*Power-on initialization.*/ @@ -845,9 +848,43 @@ static int amc6821_detect(struct i2c_client *client, s= truct i2c_board_info *info return 0; } =20 -static int amc6821_init_client(struct amc6821_data *data) +static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client) +{ + enum pwm_polarity polarity =3D PWM_POLARITY_NORMAL; + struct of_phandle_args args; + struct device_node *fan_np; + + /* + * For backward compatibility, the pwminv module parameter takes + * always the precedence over any other device description + */ + if (pwminv =3D=3D 0) + return PWM_POLARITY_NORMAL; + if (pwminv > 0) + return PWM_POLARITY_INVERSED; + + fan_np =3D of_get_child_by_name(client->dev.of_node, "fan"); + if (!fan_np) + return PWM_POLARITY_NORMAL; + + if (of_parse_phandle_with_args(fan_np, "pwms", "#pwm-cells", 0, &args)) + goto out; + of_node_put(args.np); + + if (args.args_count !=3D 2) + goto out; + + if (args.args[1] & PWM_POLARITY_INVERTED) + polarity =3D PWM_POLARITY_INVERSED; +out: + of_node_put(fan_np); + return polarity; +} + +static int amc6821_init_client(struct i2c_client *client, struct amc6821_d= ata *data) { struct regmap *regmap =3D data->regmap; + u32 regval; int err; =20 if (init) { @@ -864,11 +901,14 @@ static int amc6821_init_client(struct amc6821_data *d= ata) if (err) return err; =20 + regval =3D AMC6821_CONF1_START; + if (amc6821_pwm_polarity(client) =3D=3D PWM_POLARITY_INVERSED) + regval |=3D AMC6821_CONF1_PWMINV; + err =3D regmap_update_bits(regmap, AMC6821_REG_CONF1, AMC6821_CONF1_THERMOVIE | AMC6821_CONF1_FANIE | AMC6821_CONF1_START | AMC6821_CONF1_PWMINV, - AMC6821_CONF1_START | - (pwminv ? AMC6821_CONF1_PWMINV : 0)); + regval); if (err) return err; } @@ -916,7 +956,7 @@ static int amc6821_probe(struct i2c_client *client) "Failed to initialize regmap\n"); data->regmap =3D regmap; =20 - err =3D amc6821_init_client(data); + err =3D amc6821_init_client(client, data); if (err) return err; =20 --=20 2.39.5