All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Thierry Reding <thierry.reding@gmail.com>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	linux-pwm@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH 1/3] pwm: Provide wrappers for storing and getting private data
Date: Thu, 30 Nov 2023 14:50:27 +0000	[thread overview]
Message-ID: <20231130145027.GA3259151@google.com> (raw)
In-Reply-To: <20231124215208.616551-2-u.kleine-koenig@pengutronix.de>

On Fri, 24 Nov 2023, Uwe Kleine-König wrote:

> Also call pwmchip_set_drvdata() in pwmchip_alloc() to have a sane
> default. Might replace pwmchip_priv()?!
> 
> After struct pwm_chip got its own struct device, this can make use of
> dev_get_drvdata() and dev_set_drvdata() on that device.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/pwm/core.c  |  2 ++
>  include/linux/pwm.h | 19 +++++++++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 17577a1c4efc..0cbce704cc0b 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -216,6 +216,8 @@ struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, si
>  	chip->dev = parent;
>  	chip->npwm = npwm;
>  
> +	pwmchip_set_drvdata(chip, pwmchip_priv(chip));
> +
>  	return chip;
>  }
>  EXPORT_SYMBOL_GPL(devm_pwmchip_alloc);
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index 3c62cf329ee0..7a32ac687717 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -302,6 +302,7 @@ struct pwm_chip {
>  
>  	/* only used internally by the PWM framework */
>  	struct pwm_device *pwms;
> +	void *drvdata;

I appreciate that this may be temporary, but why not use the precedent
already set by struct device?

  void            *driver_data;

>  };
>  
>  static inline struct device *pwmchip_parent(struct pwm_chip *chip)
> @@ -309,6 +310,24 @@ static inline struct device *pwmchip_parent(struct pwm_chip *chip)
>  	return chip->dev;
>  }
>  
> +static inline void *pwmchip_get_drvdata(struct pwm_chip *chip)
> +{
> +	/*
> +	 * After pwm_chip got a dedicated struct device, this can be replaced by
> +	 * dev_get_drvdata(&chip->dev);
> +	 */
> +	return chip->drvdata;
> +}
> +
> +static inline void pwmchip_set_drvdata(struct pwm_chip *chip, void *data)
> +{
> +	/*
> +	 * After pwm_chip got a dedicated struct device, this can be replaced by
> +	 * dev_set_drvdata(&chip->dev, data);
> +	 */
> +	chip->drvdata = data;
> +}
> +
>  #if IS_ENABLED(CONFIG_PWM)
>  /* PWM user APIs */
>  int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state);
> -- 
> 2.42.0
> 

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2023-11-30 14:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-24 21:52 [PATCH 0/3] pwm: Alternative way to convert leds-qcom-lpg to devm_pwmchip_alloc() Uwe Kleine-König
2023-11-24 21:52 ` [PATCH 1/3] pwm: Provide wrappers for storing and getting private data Uwe Kleine-König
2023-11-30 14:50   ` Lee Jones [this message]
2023-11-30 15:37     ` Uwe Kleine-König
2023-11-24 21:52 ` [PATCH 2/3] leds: qcom-lpg: Introduce a wrapper for getting driver data from a pwm chip Uwe Kleine-König
2023-11-24 21:52 ` [PATCH 3/3] leds: qcom-lpg: Make use of devm_pwmchip_alloc() function Uwe Kleine-König
2023-11-30 14:53 ` [PATCH 0/3] pwm: Alternative way to convert leds-qcom-lpg to devm_pwmchip_alloc() Lee Jones
2023-11-30 15:41   ` Uwe Kleine-König

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=20231130145027.GA3259151@google.com \
    --to=lee@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=kernel@pengutronix.de \
    --cc=linux-pwm@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.