Linux-PWM Archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee@kernel.org>, Bartosz Golaszewski <brgl@bgdev.pl>
Cc: linux-pwm@vger.kernel.org, kernel@pengutronix.de
Subject: [PATCH 1/3] pwm: Provide wrappers for storing and getting private data
Date: Fri, 24 Nov 2023 22:52:10 +0100	[thread overview]
Message-ID: <20231124215208.616551-2-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20231124215208.616551-1-u.kleine-koenig@pengutronix.de>

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;
 };
 
 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


  reply	other threads:[~2023-11-24 21:52 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 ` Uwe Kleine-König [this message]
2023-11-30 14:50   ` [PATCH 1/3] pwm: Provide wrappers for storing and getting private data Lee Jones
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=20231124215208.616551-2-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=brgl@bgdev.pl \
    --cc=kernel@pengutronix.de \
    --cc=lee@kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).