Linux PWM subsystem development
 help / color / mirror / Atom feed
From: claudiu beznea <claudiu.beznea@tuxon.dev>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Cc: linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	kernel@pengutronix.de
Subject: Re: [PATCH 3/5] pwm: atmel-tcb: Put per-channel data into driver data
Date: Thu, 27 Jul 2023 08:59:54 +0300	[thread overview]
Message-ID: <3a53c437-80ff-2a35-09f2-fe16377ea829@tuxon.dev> (raw)
In-Reply-To: <20230719192013.4051193-4-u.kleine-koenig@pengutronix.de>



On 19.07.2023 22:20, Uwe Kleine-König wrote:
> This simplifies the code, reduces the number of memory allocations and
> pointer dereferences.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Claudiu Beznea <claudiu.beznea@tuxon.dev>

> ---
>   drivers/pwm/pwm-atmel-tcb.c | 29 +++++++++--------------------
>   1 file changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-atmel-tcb.c b/drivers/pwm/pwm-atmel-tcb.c
> index 2826fc216d29..ae274bd7907d 100644
> --- a/drivers/pwm/pwm-atmel-tcb.c
> +++ b/drivers/pwm/pwm-atmel-tcb.c
> @@ -57,7 +57,7 @@ struct atmel_tcb_pwm_chip {
>   	struct clk *clk;
>   	struct clk *gclk;
>   	struct clk *slow_clk;
> -	struct atmel_tcb_pwm_device *pwms[NPWM];
> +	struct atmel_tcb_pwm_device pwms[NPWM];
>   	struct atmel_tcb_channel bkup;
>   };
>   
> @@ -73,7 +73,7 @@ static int atmel_tcb_pwm_set_polarity(struct pwm_chip *chip,
>   				      enum pwm_polarity polarity)
>   {
>   	struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
> -	struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
> +	struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
>   
>   	tcbpwm->polarity = polarity;
>   
> @@ -84,19 +84,13 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
>   				 struct pwm_device *pwm)
>   {
>   	struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
> -	struct atmel_tcb_pwm_device *tcbpwm;
> +	struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
>   	unsigned cmr;
>   	int ret;
>   
> -	tcbpwm = devm_kzalloc(chip->dev, sizeof(*tcbpwm), GFP_KERNEL);
> -	if (!tcbpwm)
> -		return -ENOMEM;
> -
>   	ret = clk_prepare_enable(tcbpwmc->clk);
> -	if (ret) {
> -		devm_kfree(chip->dev, tcbpwm);
> +	if (ret)
>   		return ret;
> -	}
>   
>   	tcbpwm->polarity = PWM_POLARITY_NORMAL;
>   	tcbpwm->duty = 0;
> @@ -131,25 +125,20 @@ static int atmel_tcb_pwm_request(struct pwm_chip *chip,
>   	regmap_write(tcbpwmc->regmap, ATMEL_TC_REG(tcbpwmc->channel, CMR), cmr);
>   	spin_unlock(&tcbpwmc->lock);
>   
> -	tcbpwmc->pwms[pwm->hwpwm] = tcbpwm;
> -
>   	return 0;
>   }
>   
>   static void atmel_tcb_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
>   {
>   	struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
> -	struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
>   
>   	clk_disable_unprepare(tcbpwmc->clk);
> -	tcbpwmc->pwms[pwm->hwpwm] = NULL;
> -	devm_kfree(chip->dev, tcbpwm);
>   }
>   
>   static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
>   {
>   	struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
> -	struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
> +	struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
>   	unsigned cmr;
>   	enum pwm_polarity polarity = tcbpwm->polarity;
>   
> @@ -206,7 +195,7 @@ static void atmel_tcb_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
>   static int atmel_tcb_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
>   {
>   	struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
> -	struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
> +	struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
>   	u32 cmr;
>   	enum pwm_polarity polarity = tcbpwm->polarity;
>   
> @@ -291,7 +280,7 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>   				int duty_ns, int period_ns)
>   {
>   	struct atmel_tcb_pwm_chip *tcbpwmc = to_tcb_chip(chip);
> -	struct atmel_tcb_pwm_device *tcbpwm = tcbpwmc->pwms[pwm->hwpwm];
> +	struct atmel_tcb_pwm_device *tcbpwm = &tcbpwmc->pwms[pwm->hwpwm];
>   	struct atmel_tcb_pwm_device *atcbpwm = NULL;
>   	int i = 0;
>   	int slowclk = 0;
> @@ -338,9 +327,9 @@ static int atmel_tcb_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>   	period = div_u64(period_ns, min);
>   
>   	if (pwm->hwpwm == 0)
> -		atcbpwm = tcbpwmc->pwms[1];
> +		atcbpwm = &tcbpwmc->pwms[1];
>   	else
> -		atcbpwm = tcbpwmc->pwms[0];
> +		atcbpwm = &tcbpwmc->pwms[0];
>   
>   	/*
>   	 * PWM devices provided by the TCB driver are grouped by 2.

  reply	other threads:[~2023-07-27  6:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 19:20 [PATCH 0/5] pwm: atmel-tcb: Some driver maintenance Uwe Kleine-König
2023-07-19 19:20 ` [PATCH 1/5] pwm: atmel-tcb: Harmonize resource allocation order Uwe Kleine-König
2023-07-27  6:00   ` claudiu beznea
2023-07-27  7:00     ` Uwe Kleine-König
2023-07-19 19:20 ` [PATCH 2/5] pwm: atmel-tcb: Fix resource freeing in error path and remove Uwe Kleine-König
2023-07-27  6:00   ` claudiu beznea
2023-07-19 19:20 ` [PATCH 3/5] pwm: atmel-tcb: Put per-channel data into driver data Uwe Kleine-König
2023-07-27  5:59   ` claudiu beznea [this message]
2023-07-19 19:20 ` [PATCH 4/5] pwm: atmel-tcb: Unroll atmel_tcb_pwm_set_polarity() into only caller Uwe Kleine-König
2023-07-27  5:59   ` claudiu beznea
2023-07-19 19:20 ` [PATCH 5/5] pwm: atmel-tcb: Don't track polarity in driver data Uwe Kleine-König
2023-07-27  5:59   ` claudiu beznea
2023-07-28  7:36 ` [PATCH 0/5] pwm: atmel-tcb: Some driver maintenance Thierry Reding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3a53c437-80ff-2a35-09f2-fe16377ea829@tuxon.dev \
    --to=claudiu.beznea@tuxon.dev \
    --cc=alexandre.belloni@bootlin.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox