From: Alex Elder <elder@ieee.org>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"James Clark" <james.clark@arm.com>,
linux-pwm@vger.kernel.org, "Hector Martin" <marcan@marcan.st>,
"Sven Peter" <sven@svenpeter.dev>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Florian Fainelli" <florian.fainelli@broadcom.com>,
"Ray Jui" <rjui@broadcom.com>,
"Scott Branden" <sbranden@broadcom.com>,
"Alexander Shiyan" <shc_work@mail.ru>,
"Benson Leung" <bleung@chromium.org>,
"Shawn Guo" <shawnguo@kernel.org>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Paul Cercueil" <paul@crapouillou.net>,
"Vladimir Zapolskiy" <vz@mleia.com>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Matthias Brugger" <matthias.bgg@gmail.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Kevin Hilman" <khilman@baylibre.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Daire McNamara" <daire.mcnamara@microchip.com>,
"Jonathan Neuschäfer" <j.neuschaefer@gmx.net>,
"Heiko Stuebner" <heiko@sntech.de>,
"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Michael Walle" <mwalle@kernel.org>,
"Orson Zhai" <orsonzhai@gmail.com>,
"Baolin Wang" <baolin.wang@linux.alibaba.com>,
"Chunyan Zhang" <zhang.lyra@gmail.com>,
"Fabrice Gasnier" <fabrice.gasnier@foss.st.com>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Chen-Yu Tsai" <wens@csie.org>,
"Jernej Skrabec" <jernej.skrabec@gmail.com>,
"Samuel Holland" <samuel@sholland.org>,
"Hammer Hsieh" <hammerh0314@gmail.com>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
"Nobuhiro Iwamatsu" <nobuhiro1.iwamatsu@toshiba.co.jp>,
"Sean Anderson" <sean.anderson@seco.com>,
"Michal Simek" <michal.simek@amd.com>,
"Linus Walleij" <linus.walleij@linaro.org>,
"Bartosz Golaszewski" <brgl@bgdev.pl>,
"Andrzej Hajda" <andrzej.hajda@intel.com>,
"Robert Foss" <rfoss@kernel.org>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>, "Pavel Machek" <pavel@ucw.cz>,
"Lee Jones" <lee@kernel.org>,
"Anjelique Melendez" <quic_amelende@quicinc.com>,
"Andi Shyti" <andi.shyti@kernel.org>,
"Lu Hongfei" <luhongfei@vivo.com>,
"Bjorn Andersson" <quic_bjorande@quicinc.com>,
"Luca Weiss" <luca@z3ntu.xyz>, "Johan Hovold" <johan@kernel.org>
Cc: linux-doc@vger.kernel.org, kernel@pengutronix.de,
Alyssa Rosenzweig <alyssa@rosenzweig.io>,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
linux-rpi-kernel@lists.infradead.org,
Guenter Roeck <groeck@chromium.org>,
chrome-platform@lists.linux.dev,
Fabio Estevam <festevam@gmail.com>,
NXP Linux Team <linux-imx@nxp.com>,
linux-mips@vger.kernel.org, platform-driver-x86@vger.kernel.org,
linux-mediatek@lists.infradead.org,
Jerome Brunet <jbrunet@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
linux-amlogic@lists.infradead.org,
linux-riscv@lists.infradead.org,
linux-rockchip@lists.infradead.org,
Alim Akhtar <alim.akhtar@samsung.com>,
linux-samsung-soc@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org,
linux-gpio@vger.kernel.org,
Douglas Anderson <dianders@chromium.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org,
greybus-dev@lists.linaro.org, linux-staging@lists.linux.dev
Subject: Re: [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function
Date: Fri, 26 Jan 2024 08:56:33 -0600 [thread overview]
Message-ID: <db05fb6a-2ea5-4e00-ac03-adc1897d96de@ieee.org> (raw)
In-Reply-To: <f59b1a4a8d6fba65e4d3e8698310c9cb1d4c43ce.1706182805.git.u.kleine-koenig@pengutronix.de>
On 1/25/24 6:09 AM, Uwe Kleine-König wrote:
> This function allocates a struct pwm_chip and driver data. Compared to
> the status quo the split into pwm_chip and driver data is new, otherwise
> it doesn't change anything relevant (yet).
>
> The intention is that after all drivers are switched to use this
> allocation function, its possible to add a struct device to struct
> pwm_chip to properly track the latter's lifetime without touching all
> drivers again. Proper lifetime tracking is a necessary precondition to
> introduce character device support for PWMs (that implements atomic
> setting and doesn't suffer from the sysfs overhead of the /sys/class/pwm
> userspace support).
>
> The new function pwmchip_priv() (obviously?) only works for chips
> allocated with devm_pwmchip_alloc().
I think this looks good. Two questions:
- Should you explicitly align the private data? Or do you believe
the default alignment (currently pointer size aligned) is adequate?
- Is there a non-devres version of the allocation function?
-Alex
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> .../driver-api/driver-model/devres.rst | 1 +
> Documentation/driver-api/pwm.rst | 10 ++++----
> drivers/pwm/core.c | 25 +++++++++++++++++++
> include/linux/pwm.h | 2 ++
> 4 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
> index c5f99d834ec5..e4df72c408d2 100644
> --- a/Documentation/driver-api/driver-model/devres.rst
> +++ b/Documentation/driver-api/driver-model/devres.rst
> @@ -420,6 +420,7 @@ POWER
> devm_reboot_mode_unregister()
>
> PWM
> + devm_pwmchip_alloc()
> devm_pwmchip_add()
> devm_pwm_get()
> devm_fwnode_pwm_get()
> diff --git a/Documentation/driver-api/pwm.rst b/Documentation/driver-api/pwm.rst
> index 3c28ccc4b611..cee66c7f0335 100644
> --- a/Documentation/driver-api/pwm.rst
> +++ b/Documentation/driver-api/pwm.rst
> @@ -143,11 +143,11 @@ to implement the pwm_*() functions itself. This means that it's impossible
> to have multiple PWM drivers in the system. For this reason it's mandatory
> for new drivers to use the generic PWM framework.
>
> -A new PWM controller/chip can be added using pwmchip_add() and removed
> -again with pwmchip_remove(). pwmchip_add() takes a filled in struct
> -pwm_chip as argument which provides a description of the PWM chip, the
> -number of PWM devices provided by the chip and the chip-specific
> -implementation of the supported PWM operations to the framework.
> +A new PWM controller/chip can be allocated using devm_pwmchip_alloc, then added
> +using pwmchip_add() and removed again with pwmchip_remove(). pwmchip_add()
> +takes a filled in struct pwm_chip as argument which provides a description of
> +the PWM chip, the number of PWM devices provided by the chip and the
> +chip-specific implementation of the supported PWM operations to the framework.
>
> When implementing polarity support in a PWM driver, make sure to respect the
> signal conventions in the PWM framework. By definition, normal polarity
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 1b4c3d0caa82..b821a2b0b172 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -454,6 +454,31 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
> }
> EXPORT_SYMBOL_GPL(of_pwm_single_xlate);
>
> +static void *pwmchip_priv(struct pwm_chip *chip)
> +{
> + return (void *)chip + sizeof(*chip);
> +}
> +
> +struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv)
> +{
> + struct pwm_chip *chip;
> + size_t alloc_size;
> +
> + alloc_size = size_add(sizeof(*chip), sizeof_priv);
> +
> + chip = devm_kzalloc(parent, alloc_size, GFP_KERNEL);
> + if (!chip)
> + return ERR_PTR(-ENOMEM);
> +
> + chip->dev = parent;
> + chip->npwm = npwm;
> +
> + pwmchip_set_drvdata(chip, pwmchip_priv(chip));
> +
> + return chip;
> +}
> +EXPORT_SYMBOL_GPL(devm_pwmchip_alloc);
> +
> static void of_pwmchip_add(struct pwm_chip *chip)
> {
> if (!chip->dev || !chip->dev->of_node)
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index 2c49d2fe2fe7..8bc7504aa7d4 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -403,6 +403,8 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm)
> int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
> unsigned long timeout);
>
> +struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv);
> +
> int __pwmchip_add(struct pwm_chip *chip, struct module *owner);
> #define pwmchip_add(chip) __pwmchip_add(chip, THIS_MODULE)
> void pwmchip_remove(struct pwm_chip *chip);
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2024-02-23 17:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 12:08 [PATCH v5 000/111] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
2024-01-25 12:08 ` [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip Uwe Kleine-König
2024-01-25 14:14 ` AngeloGioacchino Del Regno
2024-01-25 19:32 ` Florian Fainelli
2024-01-25 20:29 ` Uwe Kleine-König
2024-01-25 20:54 ` Uwe Kleine-König
2024-01-25 12:08 ` [PATCH v5 019/111] pwm: meson: Make use of pwmchip_parent() macro Uwe Kleine-König
2024-01-25 12:09 ` [PATCH v5 039/111] pwm: Provide wrappers for storing and getting driver private data Uwe Kleine-König
2024-01-25 14:13 ` AngeloGioacchino Del Regno
2024-01-25 12:09 ` [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function Uwe Kleine-König
2024-01-26 14:56 ` Alex Elder [this message]
2024-01-26 17:10 ` Uwe Kleine-König
2024-01-25 12:09 ` [PATCH v5 072/111] pwm: meson: Make use of " 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=db05fb6a-2ea5-4e00-ac03-adc1897d96de@ieee.org \
--to=elder@ieee.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=alexandre.torgue@foss.st.com \
--cc=alim.akhtar@samsung.com \
--cc=alyssa@rosenzweig.io \
--cc=andi.shyti@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andrzej.hajda@intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=asahi@lists.linux.dev \
--cc=baolin.wang@linux.alibaba.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bhelgaas@google.com \
--cc=bleung@chromium.org \
--cc=brgl@bgdev.pl \
--cc=chrome-platform@lists.linux.dev \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor.dooley@microchip.com \
--cc=corbet@lwn.net \
--cc=daire.mcnamara@microchip.com \
--cc=daniel@ffwll.ch \
--cc=dianders@chromium.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=fabrice.gasnier@foss.st.com \
--cc=festevam@gmail.com \
--cc=florian.fainelli@broadcom.com \
--cc=gregkh@linuxfoundation.org \
--cc=greybus-dev@lists.linaro.org \
--cc=groeck@chromium.org \
--cc=hammerh0314@gmail.com \
--cc=hdegoede@redhat.com \
--cc=heiko@sntech.de \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=j.neuschaefer@gmx.net \
--cc=james.clark@arm.com \
--cc=jbrunet@baylibre.com \
--cc=jernej.skrabec@gmail.com \
--cc=johan@kernel.org \
--cc=jonas@kwiboo.se \
--cc=jonathanh@nvidia.com \
--cc=kernel@pengutronix.de \
--cc=khilman@baylibre.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lee@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-leds@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=luca@z3ntu.xyz \
--cc=luhongfei@vivo.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=marcan@marcan.st \
--cc=martin.blumenstingl@googlemail.com \
--cc=matthias.bgg@gmail.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=michal.simek@amd.com \
--cc=mripard@kernel.org \
--cc=mwalle@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=nicolas.ferre@microchip.com \
--cc=nobuhiro1.iwamatsu@toshiba.co.jp \
--cc=orsonzhai@gmail.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=paul@crapouillou.net \
--cc=pavel@ucw.cz \
--cc=platform-driver-x86@vger.kernel.org \
--cc=quic_amelende@quicinc.com \
--cc=quic_bjorande@quicinc.com \
--cc=rfoss@kernel.org \
--cc=rjui@broadcom.com \
--cc=s.hauer@pengutronix.de \
--cc=samuel@sholland.org \
--cc=sbranden@broadcom.com \
--cc=sean.anderson@seco.com \
--cc=shawnguo@kernel.org \
--cc=shc_work@mail.ru \
--cc=sven@svenpeter.dev \
--cc=thierry.reding@gmail.com \
--cc=tzimmermann@suse.de \
--cc=u.kleine-koenig@pengutronix.de \
--cc=vz@mleia.com \
--cc=wens@csie.org \
--cc=zhang.lyra@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