[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <07ec64e7-041d-4f5a-a04c-daa4b0794111@roeck-us.net>
Date: Wed, 19 Feb 2025 05:46:10 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: Quentin Schulz <quentin.schulz@...rry.de>,
Francesco Dolcini <francesco@...cini.it>, Jean Delvare <jdelvare@...e.com>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Farouk Bouabid <farouk.bouabid@...rry.de>
Cc: Francesco Dolcini <francesco.dolcini@...adex.com>,
linux-hwmon@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 2/2] hwmon: (amc6821) Add PWM polarity configuration
with OF
On 2/19/25 02:08, Quentin Schulz wrote:
> Hi Francesco,
>
> On 2/18/25 5:56 PM, Francesco Dolcini wrote:
>> From: Francesco Dolcini <francesco.dolcini@...adex.com>
>>
>> Add support to configure the PWM-Out pin polarity based on a device
>> tree property.
>>
>> Signed-off-by: Francesco Dolcini <francesco.dolcini@...adex.com>
>> ---
>> drivers/hwmon/amc6821.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
>> index 1e3c6acd8974..1ea2d97eebca 100644
>> --- a/drivers/hwmon/amc6821.c
>> +++ b/drivers/hwmon/amc6821.c
>> @@ -845,7 +845,7 @@ static int amc6821_detect(struct i2c_client *client, struct i2c_board_info *info
>> return 0;
>> }
>> -static int amc6821_init_client(struct amc6821_data *data)
>> +static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *data)
>> {
>> struct regmap *regmap = data->regmap;
>> int err;
>> @@ -864,6 +864,9 @@ static int amc6821_init_client(struct amc6821_data *data)
>> if (err)
>> return err;
>> + if (of_property_read_bool(client->dev.of_node, "ti,pwm-inverted"))
>
> I know that the AMC6821 is doing a lot of smart things, but this really tickled me. PWM controllers actually do support that already via PWM_POLARITY_INVERTED flag for example. See Documentation/devicetree/bindings/hwmon/adt7475.yaml which seems to be another HWMON driver which acts as a PWM controller. I'm not sure this is relevant, applicable or desired but I wanted to highlight this.
>
>> + pwminv = 1;
>> +
>
> This is silently overriding the module parameter.
>
> I don't think this is a good idea, at the very least not silently.
>
> I would suggest to add some logic in the probe function to set this value and check its consistency.
>
> Something like:
>
> """
> diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
> index 1e3c6acd89740..3a13a914e2bbb 100644
> --- a/drivers/hwmon/amc6821.c
> +++ b/drivers/hwmon/amc6821.c
> @@ -37,7 +37,7 @@ static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e,
> * Insmod parameters
> */
>
> -static int pwminv; /*Inverted PWM output. */
> +static int pwminv = -1; /* -1 not modified by the user, 0 default PWM output, 1 inverted PWM output */
> module_param(pwminv, int, 0444);
>
> static int init = 1; /*Power-on initialization.*/
> @@ -904,6 +904,7 @@ static int amc6821_probe(struct i2c_client *client)
> struct amc6821_data *data;
> struct device *hwmon_dev;
> struct regmap *regmap;
> + bool pwminv_dt;
> int err;
>
> data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL);
> @@ -916,6 +917,18 @@ static int amc6821_probe(struct i2c_client *client)
> "Failed to initialize regmap\n");
> data->regmap = regmap;
>
> + pwminv_dt = of_property_read_bool(client->dev.of_node, "ti,pwm-inverted");
> +
> + if (pwminv == -1) {
> + pwminv = pwminv_dt;
A devicetree property, associated with a single instance of the driver,
overriding a module parameter affecting all instances ? This is a no-go.
Guenter
Powered by blists - more mailing lists