From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guenter Roeck Subject: Re: [PATCH v4 04/24] hwmon: pwm-fan: use pwm_get_xxx() helpers where appropriate Date: Mon, 16 Nov 2015 07:59:23 -0800 Message-ID: <5649FD5B.3000208@roeck-us.net> References: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com> <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> Reply-To: linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Return-path: In-Reply-To: <1447664207-24370-5-git-send-email-boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org> List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , To: Boris Brezillon , Thierry Reding , linux-pwm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: Mike Turquette , Stephen Boyd , linux-clk-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Mark Brown , Liam Girdwood , Kamil Debski , lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org, Jean Delvare , Dmitry Torokhov , linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Bryan Wu , Richard Purdie , Jacek Anaszewski , linux-leds-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Maxime Ripard , Chen-Yu Tsai , linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, Joachim Eastwood , Thomas Petazzoni , Heiko Stuebner , linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Jingoo Han , Lee Jones , linux-fbdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Jean-Christophe List-Id: linux-leds@vger.kernel.org On 11/16/2015 12:56 AM, Boris Brezillon wrote: > Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field. > Doing that will ease adaptation of the PWM framework to support atomic > update. > > Signed-off-by: Boris Brezillon > --- > Patch generated with the following coccinelle script: > > --->8--- > virtual patch > > @@ > struct pwm_device *p; > expression e; > @@ > ( > -(p)->polarity = e; > +pwm_set_polarity((p), e); > | > -(p)->polarity > +pwm_get_polarity((p)) s/((p))/(p)/ > | > -(p)->period = e; > +pwm_set_period((p), e); > | > -(p)->period > +pwm_get_period((p)) s/((p))/(p)/ > | > -(p)->duty_cycle = e; > +pwm_set_duty_cycle((p), e); The (p) seems unnecessary here. > | > -(p)->duty_cycle > +pwm_get_duty_cycle((p)) s/((p))/(p)/ > ) > --->8--- > --- > drivers/hwmon/pwm-fan.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index 3e23003..105b964 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -47,8 +47,8 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) > if (ctx->pwm_value == pwm) > goto exit_set_pwm_err; > > - duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(pwm * (pwm_get_period((ctx->pwm)) - 1), MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); Please drop all the unnecessary ( ). Thanks, Guenter > if (ret) > goto exit_set_pwm_err; > > @@ -234,10 +234,10 @@ static int pwm_fan_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, ctx); > > /* Set duty cycle to maximum allowed */ > - duty_cycle = ctx->pwm->period - 1; > + duty_cycle = pwm_get_period((ctx->pwm)) - 1; > ctx->pwm_value = MAX_PWM; > > - ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); > + ret = pwm_config(ctx->pwm, duty_cycle, pwm_get_period((ctx->pwm))); > if (ret) { > dev_err(&pdev->dev, "Failed to configure PWM\n"); > return ret; > @@ -309,8 +309,9 @@ static int pwm_fan_resume(struct device *dev) > if (ctx->pwm_value == 0) > return 0; > > - duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(ctx->pwm_value * (pwm_get_period((ctx->pwm)) - 1), > + MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); > if (ret) > return ret; > return pwm_enable(ctx->pwm); > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752955AbbKPP7j (ORCPT ); Mon, 16 Nov 2015 10:59:39 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:53203 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752516AbbKPP7a (ORCPT ); Mon, 16 Nov 2015 10:59:30 -0500 Subject: Re: [PATCH v4 04/24] hwmon: pwm-fan: use pwm_get_xxx() helpers where appropriate To: Boris Brezillon , Thierry Reding , linux-pwm@vger.kernel.org References: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com> <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> Cc: Mike Turquette , Stephen Boyd , linux-clk@vger.kernel.org, Mark Brown , Liam Girdwood , Kamil Debski , lm-sensors@lm-sensors.org, Jean Delvare , Dmitry Torokhov , linux-input@vger.kernel.org, Bryan Wu , Richard Purdie , Jacek Anaszewski , linux-leds@vger.kernel.org, Maxime Ripard , Chen-Yu Tsai , linux-sunxi@googlegroups.com, Joachim Eastwood , Thomas Petazzoni , Heiko Stuebner , linux-rockchip@lists.infradead.org, Jingoo Han , Lee Jones , linux-fbdev@vger.kernel.org, Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Robert Jarzmik , Alexandre Belloni , Julia Lawall , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org From: Guenter Roeck Message-ID: <5649FD5B.3000208@roeck-us.net> Date: Mon, 16 Nov 2015 07:59:23 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated_sender: linux@roeck-us.net X-OutGoing-Spam-Status: No, score=0.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: linux@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/16/2015 12:56 AM, Boris Brezillon wrote: > Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field. > Doing that will ease adaptation of the PWM framework to support atomic > update. > > Signed-off-by: Boris Brezillon > --- > Patch generated with the following coccinelle script: > > --->8--- > virtual patch > > @@ > struct pwm_device *p; > expression e; > @@ > ( > -(p)->polarity = e; > +pwm_set_polarity((p), e); > | > -(p)->polarity > +pwm_get_polarity((p)) s/((p))/(p)/ > | > -(p)->period = e; > +pwm_set_period((p), e); > | > -(p)->period > +pwm_get_period((p)) s/((p))/(p)/ > | > -(p)->duty_cycle = e; > +pwm_set_duty_cycle((p), e); The (p) seems unnecessary here. > | > -(p)->duty_cycle > +pwm_get_duty_cycle((p)) s/((p))/(p)/ > ) > --->8--- > --- > drivers/hwmon/pwm-fan.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index 3e23003..105b964 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -47,8 +47,8 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) > if (ctx->pwm_value == pwm) > goto exit_set_pwm_err; > > - duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(pwm * (pwm_get_period((ctx->pwm)) - 1), MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); Please drop all the unnecessary ( ). Thanks, Guenter > if (ret) > goto exit_set_pwm_err; > > @@ -234,10 +234,10 @@ static int pwm_fan_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, ctx); > > /* Set duty cycle to maximum allowed */ > - duty_cycle = ctx->pwm->period - 1; > + duty_cycle = pwm_get_period((ctx->pwm)) - 1; > ctx->pwm_value = MAX_PWM; > > - ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); > + ret = pwm_config(ctx->pwm, duty_cycle, pwm_get_period((ctx->pwm))); > if (ret) { > dev_err(&pdev->dev, "Failed to configure PWM\n"); > return ret; > @@ -309,8 +309,9 @@ static int pwm_fan_resume(struct device *dev) > if (ctx->pwm_value == 0) > return 0; > > - duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(ctx->pwm_value * (pwm_get_period((ctx->pwm)) - 1), > + MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); > if (ret) > return ret; > return pwm_enable(ctx->pwm); > From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guenter Roeck Date: Mon, 16 Nov 2015 15:59:23 +0000 Subject: Re: [PATCH v4 04/24] hwmon: pwm-fan: use pwm_get_xxx() helpers where appropriate Message-Id: <5649FD5B.3000208@roeck-us.net> List-Id: References: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com> <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> In-Reply-To: <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-arm-kernel@lists.infradead.org On 11/16/2015 12:56 AM, Boris Brezillon wrote: > Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field. > Doing that will ease adaptation of the PWM framework to support atomic > update. > > Signed-off-by: Boris Brezillon > --- > Patch generated with the following coccinelle script: > > --->8--- > virtual patch > > @@ > struct pwm_device *p; > expression e; > @@ > ( > -(p)->polarity = e; > +pwm_set_polarity((p), e); > | > -(p)->polarity > +pwm_get_polarity((p)) s/((p))/(p)/ > | > -(p)->period = e; > +pwm_set_period((p), e); > | > -(p)->period > +pwm_get_period((p)) s/((p))/(p)/ > | > -(p)->duty_cycle = e; > +pwm_set_duty_cycle((p), e); The (p) seems unnecessary here. > | > -(p)->duty_cycle > +pwm_get_duty_cycle((p)) s/((p))/(p)/ > ) > --->8--- > --- > drivers/hwmon/pwm-fan.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index 3e23003..105b964 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -47,8 +47,8 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) > if (ctx->pwm_value = pwm) > goto exit_set_pwm_err; > > - duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(pwm * (pwm_get_period((ctx->pwm)) - 1), MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); Please drop all the unnecessary ( ). Thanks, Guenter > if (ret) > goto exit_set_pwm_err; > > @@ -234,10 +234,10 @@ static int pwm_fan_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, ctx); > > /* Set duty cycle to maximum allowed */ > - duty_cycle = ctx->pwm->period - 1; > + duty_cycle = pwm_get_period((ctx->pwm)) - 1; > ctx->pwm_value = MAX_PWM; > > - ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); > + ret = pwm_config(ctx->pwm, duty_cycle, pwm_get_period((ctx->pwm))); > if (ret) { > dev_err(&pdev->dev, "Failed to configure PWM\n"); > return ret; > @@ -309,8 +309,9 @@ static int pwm_fan_resume(struct device *dev) > if (ctx->pwm_value = 0) > return 0; > > - duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(ctx->pwm_value * (pwm_get_period((ctx->pwm)) - 1), > + MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); > if (ret) > return ret; > return pwm_enable(ctx->pwm); > From mboxrd@z Thu Jan 1 00:00:00 1970 From: linux@roeck-us.net (Guenter Roeck) Date: Mon, 16 Nov 2015 07:59:23 -0800 Subject: [PATCH v4 04/24] hwmon: pwm-fan: use pwm_get_xxx() helpers where appropriate In-Reply-To: <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> References: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com> <1447664207-24370-5-git-send-email-boris.brezillon@free-electrons.com> Message-ID: <5649FD5B.3000208@roeck-us.net> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On 11/16/2015 12:56 AM, Boris Brezillon wrote: > Use pwm_get_xxx() helpers instead of directly accessing the pwm->xxx field. > Doing that will ease adaptation of the PWM framework to support atomic > update. > > Signed-off-by: Boris Brezillon > --- > Patch generated with the following coccinelle script: > > --->8--- > virtual patch > > @@ > struct pwm_device *p; > expression e; > @@ > ( > -(p)->polarity = e; > +pwm_set_polarity((p), e); > | > -(p)->polarity > +pwm_get_polarity((p)) s/((p))/(p)/ > | > -(p)->period = e; > +pwm_set_period((p), e); > | > -(p)->period > +pwm_get_period((p)) s/((p))/(p)/ > | > -(p)->duty_cycle = e; > +pwm_set_duty_cycle((p), e); The (p) seems unnecessary here. > | > -(p)->duty_cycle > +pwm_get_duty_cycle((p)) s/((p))/(p)/ > ) > --->8--- > --- > drivers/hwmon/pwm-fan.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c > index 3e23003..105b964 100644 > --- a/drivers/hwmon/pwm-fan.c > +++ b/drivers/hwmon/pwm-fan.c > @@ -47,8 +47,8 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) > if (ctx->pwm_value == pwm) > goto exit_set_pwm_err; > > - duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(pwm * (pwm_get_period((ctx->pwm)) - 1), MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); Please drop all the unnecessary ( ). Thanks, Guenter > if (ret) > goto exit_set_pwm_err; > > @@ -234,10 +234,10 @@ static int pwm_fan_probe(struct platform_device *pdev) > platform_set_drvdata(pdev, ctx); > > /* Set duty cycle to maximum allowed */ > - duty_cycle = ctx->pwm->period - 1; > + duty_cycle = pwm_get_period((ctx->pwm)) - 1; > ctx->pwm_value = MAX_PWM; > > - ret = pwm_config(ctx->pwm, duty_cycle, ctx->pwm->period); > + ret = pwm_config(ctx->pwm, duty_cycle, pwm_get_period((ctx->pwm))); > if (ret) { > dev_err(&pdev->dev, "Failed to configure PWM\n"); > return ret; > @@ -309,8 +309,9 @@ static int pwm_fan_resume(struct device *dev) > if (ctx->pwm_value == 0) > return 0; > > - duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM); > - ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); > + duty = DIV_ROUND_UP(ctx->pwm_value * (pwm_get_period((ctx->pwm)) - 1), > + MAX_PWM); > + ret = pwm_config(ctx->pwm, duty, pwm_get_period((ctx->pwm))); > if (ret) > return ret; > return pwm_enable(ctx->pwm); >