Linux-Amlogic Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 000/111] pwm: Improve lifetime tracking for pwm_chips
@ 2024-01-25 12:08 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
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 12:08 UTC (permalink / raw)
  To: linux-pwm, Benson Leung, Claudiu Beznea, Nicolas Ferre,
	Alexandre Belloni, Florian Fainelli, Ray Jui, Scott Branden,
	Shawn Guo, Sascha Hauer, Paul Cercueil, Vladimir Zapolskiy,
	Matthias Brugger, AngeloGioacchino Del Regno, Neil Armstrong,
	Kevin Hilman, Krzysztof Kozlowski, Palmer Dabbelt, Paul Walmsley,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland, Andrzej Hajda, Robert Foss,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Johan Hovold, Alex Elder, Greg Kroah-Hartman,
	Jonathan Corbet, Andy Shevchenko, Jonathan Cameron, Bjorn Helgaas,
	James Clark, Hector Martin, Sven Peter, Alexander Shiyan,
	Hans de Goede, Ilpo Järvinen, Conor Dooley, Daire McNamara,
	Jonathan Neuschäfer, Heiko Stuebner, Michael Walle,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Hammer Hsieh,
	Thierry Reding, Jonathan Hunter, Nobuhiro Iwamatsu, Sean Anderson,
	Michal Simek, Linus Walleij, Bartosz Golaszewski, Pavel Machek,
	Lee Jones, Anjelique Melendez, Andi Shyti, Lu Hongfei,
	Bjorn Andersson, Luca Weiss, Kees Cook
  Cc: kernel, Guenter Roeck, chrome-platform, linux-arm-kernel,
	Broadcom internal kernel review list, Fabio Estevam,
	NXP Linux Team, linux-mips, linux-mediatek, Jerome Brunet,
	Martin Blumenstingl, linux-amlogic, linux-rpi-kernel, Alim Akhtar,
	linux-samsung-soc, linux-riscv, linux-stm32, linux-sunxi,
	Douglas Anderson, Laurent Pinchart, Jonas Karlman, dri-devel,
	greybus-dev, linux-staging, linux-doc, Alyssa Rosenzweig, asahi,
	platform-driver-x86, linux-rockchip, linux-tegra, linux-gpio,
	linux-leds, Gustavo A. R. Silva, linux-hardening

Hello,

this is v5 of this series. The relevant changes since v4
(https://lore.kernel.org/linux-pwm/cover.1701860672.git.u.kleine-koenig@pengutronix.de):

 - New first patch to reshuffle functions in core.c. This is a
   preparation for the later changes which brings functions in a better
   order to not need declarations.
 - Fix kernel docs in several drivers
 - Added a few ack and review tags received for v4
 - non-trivially rebased to current pwm/for-next
   (the changes to drivers/gpu/drm/bridge/ti-sn65dsi86.c were intrusive
   enough to not add the ack tag by Robert Foss I got).

Handling got a bit more complicated with the recent addition of
pwm_apply_atomic/pwm_apply_might_sleep the locking got more complicated.
I didn't work out all the necessary details. So this series won't work
as is. However as there is probably some more coordination needed to get
the patches in that touch files outside of drivers/pwm and I'm confident
they can stay as is, I want to get the biggest part of this series in
(up to patch #106) during the next merge window and get them into next
soon. After that I can spend the time necessary to fix the locking maybe
to get the remaining bits in during the following merge window.

There are patches touching drivers/gpu/drm/bridge/ti-sn65dsi86.c (#37
and #104), drivers/staging/greybus/pwm.c (#38 and #106),
drivers/gpio/gpio-mvebu.c (#103) and drivers/leds/rgb/leds-qcom-lpg.c
(#105). These depend on earlier patches in this series (#3, #39 and #40)
The patches touching staging/greybus and leds-qcom-lpg already have a
maintainer ack, so I'd merge them via my tree. For the other two it
would be nice to get an ack to merge via my tree, too. But if you want
to merge via your own tree, please tell, so we can coordinate
accordingly.

Best regards
Uwe

Uwe Kleine-König (111):
  pwm: Reorder symbols in core.c
  pwm: cros-ec: Change prototype of helpers to prepare further changes
  pwm: Provide a macro to get the parent device of a given chip
  pwm: ab8500: Make use of pwmchip_parent() macro
  pwm: atmel: Make use of pwmchip_parent() macro
  pwm: atmel-tcb: Make use of pwmchip_parent() macro
  pwm: bcm-kona: Make use of pwmchip_parent() macro
  pwm: crc: Make use of pwmchip_parent() macro
  pwm: cros-ec: Make use of pwmchip_parent() macro
  pwm: dwc: Make use of pwmchip_parent() macro
  pwm: ep93xx: Make use of pwmchip_parent() macro
  pwm: fsl-ftm: Make use of pwmchip_parent() macro
  pwm: img: Make use of parent device pointer in driver data
  pwm: imx27: Make use of pwmchip_parent() macro
  pwm: jz4740: Make use of pwmchip_parent() macro
  pwm: lpc18xx-sct: Make use of parent device pointer in driver data
  pwm: lpss: Make use of pwmchip_parent() macro
  pwm: mediatek: Make use of pwmchip_parent() macro
  pwm: meson: Make use of pwmchip_parent() macro
  pwm: mtk-disp: Make use of pwmchip_parent() macro
  pwm: omap: Make use of pwmchip_parent() macro
  pwm: pca9685: Store parent device in driver data
  pwm: raspberrypi-poe: Make use of pwmchip_parent() macro
  pwm: rcar: Make use of pwmchip_parent() macro
  pwm: rz-mtu3: Make use of pwmchip_parent() macro
  pwm: samsung: Make use of pwmchip_parent() macro
  pwm: sifive: Make use of pwmchip_parent() macro
  pwm: stm32-lp: Make use of pwmchip_parent() macro
  pwm: stm32: Make use of pwmchip_parent() macro
  pwm: stmpe: Make use of pwmchip_parent() macro
  pwm: sun4i: Make use of pwmchip_parent() macro
  pwm: tiecap: Make use of pwmchip_parent() macro
  pwm: tiehrpwm: Make use of pwmchip_parent() macro
  pwm: twl-led: Make use of pwmchip_parent() macro
  pwm: twl: Make use of pwmchip_parent() macro
  pwm: vt8500: Make use of pwmchip_parent() macro
  drm/bridge: ti-sn65dsi86: Make use of pwmchip_parent() macro
  staging: greybus: pwm: Make use of pwmchip_parent() macro
  pwm: Provide wrappers for storing and getting driver private data
  pwm: Provide devm_pwmchip_alloc() function
  pwm: ab8500: Make use of devm_pwmchip_alloc() function
  pwm: apple: Make use of devm_pwmchip_alloc() function
  pwm: atmel-hlcdc: Make use of devm_pwmchip_alloc() function
  pwm: atmel: Make use of devm_pwmchip_alloc() function
  pwm: atmel-tcb: Make use of devm_pwmchip_alloc() function
  pwm: bcm2835: Make use of devm_pwmchip_alloc() function
  pwm: bcm-iproc: Make use of devm_pwmchip_alloc() function
  pwm: bcm-kona: Make use of devm_pwmchip_alloc() function
  pwm: berlin: Make use of devm_pwmchip_alloc() function
  pwm: brcmstb: Make use of devm_pwmchip_alloc() function
  pwm: clk: Make use of devm_pwmchip_alloc() function
  pwm: clps711x: Make use of devm_pwmchip_alloc() function
  pwm: crc: Make use of devm_pwmchip_alloc() function
  pwm: cros-ec: Make use of devm_pwmchip_alloc() function
  pwm: dwc: Make use of devm_pwmchip_alloc() function
  pwm: ep93xx: Make use of devm_pwmchip_alloc() function
  pwm: fsl-ftm: Make use of devm_pwmchip_alloc() function
  pwm: hibvt: Make use of devm_pwmchip_alloc() function
  pwm: img: Make use of devm_pwmchip_alloc() function
  pwm: imx1: Make use of devm_pwmchip_alloc() function
  pwm: imx27: Make use of devm_pwmchip_alloc() function
  pwm: imx-tpm: Make use of devm_pwmchip_alloc() function
  pwm: intel-lgm: Make use of devm_pwmchip_alloc() function
  pwm: iqs620a: Make use of devm_pwmchip_alloc() function
  pwm: jz4740: Make use of devm_pwmchip_alloc() function
  pwm: keembay: Make use of devm_pwmchip_alloc() function
  pwm: lp3943: Make use of devm_pwmchip_alloc() function
  pwm: lpc18xx-sct: Make use of devm_pwmchip_alloc() function
  pwm: lpc32xx: Make use of devm_pwmchip_alloc() function
  pwm: lpss-*: Make use of devm_pwmchip_alloc() function
  pwm: mediatek: Make use of devm_pwmchip_alloc() function
  pwm: meson: Make use of devm_pwmchip_alloc() function
  pwm: microchip-core: Make use of devm_pwmchip_alloc() function
  pwm: mtk-disp: Make use of devm_pwmchip_alloc() function
  pwm: mxs: Make use of devm_pwmchip_alloc() function
  pwm: ntxec: Make use of devm_pwmchip_alloc() function
  pwm: omap-dmtimer: Make use of devm_pwmchip_alloc() function
  pwm: pca9685: Make use of devm_pwmchip_alloc() function
  pwm: pxa: Make use of devm_pwmchip_alloc() function
  pwm: raspberrypi-poe: Make use of devm_pwmchip_alloc() function
  pwm: rcar: Make use of devm_pwmchip_alloc() function
  pwm: renesas-tpu: Make use of devm_pwmchip_alloc() function
  pwm: rockchip: Make use of devm_pwmchip_alloc() function
  pwm: rz-mtu3: Make use of devm_pwmchip_alloc() function
  pwm: samsung: Make use of devm_pwmchip_alloc() function
  pwm: sifive: Make use of devm_pwmchip_alloc() function
  pwm: sl28cpld: Make use of devm_pwmchip_alloc() function
  pwm: spear: Make use of devm_pwmchip_alloc() function
  pwm: sprd: Make use of devm_pwmchip_alloc() function
  pwm: sti: Make use of devm_pwmchip_alloc() function
  pwm: stm32-lp: Make use of devm_pwmchip_alloc() function
  pwm: stm32: Make use of devm_pwmchip_alloc() function
  pwm: stmpe: Make use of devm_pwmchip_alloc() function
  pwm: sun4i: Make use of devm_pwmchip_alloc() function
  pwm: sunplus: Make use of devm_pwmchip_alloc() function
  pwm: tegra: Make use of devm_pwmchip_alloc() function
  pwm: tiecap: Make use of devm_pwmchip_alloc() function
  pwm: twl-led: Make use of devm_pwmchip_alloc() function
  pwm: twl: Make use of devm_pwmchip_alloc() function
  pwm: visconti: Make use of devm_pwmchip_alloc() function
  pwm: vt8500: Make use of devm_pwmchip_alloc() function
  pwm: xilinx: Make use of devm_pwmchip_alloc() function
  gpio: mvebu: Make use of devm_pwmchip_alloc() function
  drm/bridge: ti-sn65dsi86: Make use of devm_pwmchip_alloc() function
  leds: qcom-lpg: Make use of devm_pwmchip_alloc() function
  staging: greybus: pwm: Make use of devm_pwmchip_alloc() function
  pwm: Ensure that pwm_chips are allocated using pwmchip_alloc()
  pwm: Ensure a struct pwm has the same lifetime as its pwm_chip
  pwm: Ensure the memory backing a PWM chip isn't freed while used
  pwm: Make pwmchip_[sg]et_drvdata() a wrapper around dev_set_drvdata()
  WIP: pwm: Add support for pwmchip devices for faster and easier
    userspace access

 .../driver-api/driver-model/devres.rst        |   1 +
 Documentation/driver-api/pwm.rst              |  10 +-
 drivers/gpio/gpio-mvebu.c                     |  18 +-
 drivers/gpu/drm/bridge/ti-sn65dsi86.c         |  31 +-
 drivers/leds/rgb/leds-qcom-lpg.c              |  16 +-
 drivers/pwm/Kconfig                           |   4 -
 drivers/pwm/Makefile                          |   3 +-
 drivers/pwm/core.c                            | 958 ++++++++++++------
 drivers/pwm/pwm-ab8500.c                      |  36 +-
 drivers/pwm/pwm-apple.c                       |  18 +-
 drivers/pwm/pwm-atmel-hlcdc.c                 |  35 +-
 drivers/pwm/pwm-atmel-tcb.c                   |  26 +-
 drivers/pwm/pwm-atmel.c                       |  37 +-
 drivers/pwm/pwm-bcm-iproc.c                   |  19 +-
 drivers/pwm/pwm-bcm-kona.c                    |  21 +-
 drivers/pwm/pwm-bcm2835.c                     |  19 +-
 drivers/pwm/pwm-berlin.c                      |  29 +-
 drivers/pwm/pwm-brcmstb.c                     |  17 +-
 drivers/pwm/pwm-clk.c                         |  27 +-
 drivers/pwm/pwm-clps711x.c                    |  17 +-
 drivers/pwm/pwm-crc.c                         |  22 +-
 drivers/pwm/pwm-cros-ec.c                     |  58 +-
 drivers/pwm/pwm-dwc-core.c                    |  25 +-
 drivers/pwm/pwm-dwc.c                         |  18 +-
 drivers/pwm/pwm-dwc.h                         |   9 +-
 drivers/pwm/pwm-ep93xx.c                      |  21 +-
 drivers/pwm/pwm-fsl-ftm.c                     |  48 +-
 drivers/pwm/pwm-hibvt.c                       |  25 +-
 drivers/pwm/pwm-img.c                         |  51 +-
 drivers/pwm/pwm-imx-tpm.c                     |  34 +-
 drivers/pwm/pwm-imx1.c                        |  20 +-
 drivers/pwm/pwm-imx27.c                       |  26 +-
 drivers/pwm/pwm-intel-lgm.c                   |  17 +-
 drivers/pwm/pwm-iqs620a.c                     |  37 +-
 drivers/pwm/pwm-jz4740.c                      |  36 +-
 drivers/pwm/pwm-keembay.c                     |  17 +-
 drivers/pwm/pwm-lp3943.c                      |  17 +-
 drivers/pwm/pwm-lpc18xx-sct.c                 |  35 +-
 drivers/pwm/pwm-lpc32xx.c                     |  21 +-
 drivers/pwm/pwm-lpss-pci.c                    |  10 +-
 drivers/pwm/pwm-lpss-platform.c               |  10 +-
 drivers/pwm/pwm-lpss.c                        |  34 +-
 drivers/pwm/pwm-lpss.h                        |   1 -
 drivers/pwm/pwm-mediatek.c                    |  29 +-
 drivers/pwm/pwm-meson.c                       |  57 +-
 drivers/pwm/pwm-microchip-core.c              |  17 +-
 drivers/pwm/pwm-mtk-disp.c                    |  25 +-
 drivers/pwm/pwm-mxs.c                         |  32 +-
 drivers/pwm/pwm-ntxec.c                       |  30 +-
 drivers/pwm/pwm-omap-dmtimer.c                |  47 +-
 drivers/pwm/pwm-pca9685.c                     |  98 +-
 drivers/pwm/pwm-pxa.c                         |  19 +-
 drivers/pwm/pwm-raspberrypi-poe.c             |  20 +-
 drivers/pwm/pwm-rcar.c                        |  25 +-
 drivers/pwm/pwm-renesas-tpu.c                 |  18 +-
 drivers/pwm/pwm-rockchip.c                    |  24 +-
 drivers/pwm/pwm-rz-mtu3.c                     |  39 +-
 drivers/pwm/pwm-samsung.c                     |  57 +-
 drivers/pwm/pwm-sifive.c                      |  30 +-
 drivers/pwm/pwm-sl28cpld.c                    |  13 +-
 drivers/pwm/pwm-spear.c                       |  18 +-
 drivers/pwm/pwm-sprd.c                        |  50 +-
 drivers/pwm/pwm-sti.c                         |  34 +-
 drivers/pwm/pwm-stm32-lp.c                    |  29 +-
 drivers/pwm/pwm-stm32.c                       |  53 +-
 drivers/pwm/pwm-stmpe.c                       |  58 +-
 drivers/pwm/pwm-sun4i.c                       |  38 +-
 drivers/pwm/pwm-sunplus.c                     |  17 +-
 drivers/pwm/pwm-tegra.c                       |  27 +-
 drivers/pwm/pwm-tiecap.c                      |  55 +-
 drivers/pwm/pwm-tiehrpwm.c                    |  72 +-
 drivers/pwm/pwm-twl-led.c                     |  58 +-
 drivers/pwm/pwm-twl.c                         |  50 +-
 drivers/pwm/pwm-visconti.c                    |  17 +-
 drivers/pwm/pwm-vt8500.c                      |  41 +-
 drivers/pwm/pwm-xilinx.c                      |  34 +-
 drivers/pwm/sysfs.c                           |  64 +-
 drivers/staging/greybus/pwm.c                 | 130 +--
 include/linux/platform_data/x86/pwm-lpss.h    |   4 +-
 include/linux/pwm.h                           |  39 +-
 include/uapi/linux/pwm.h                      |  23 +
 81 files changed, 1870 insertions(+), 1555 deletions(-)
 create mode 100644 include/uapi/linux/pwm.h


base-commit: 6530623212338fc0902e211ea624e790aacb00ef
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip
  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 ` Uwe Kleine-König
  2024-01-25 14:14   ` AngeloGioacchino Del Regno
  2024-01-25 19:32   ` Florian Fainelli
  2024-01-25 12:08 ` [PATCH v5 019/111] pwm: meson: Make use of pwmchip_parent() macro Uwe Kleine-König
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 12:08 UTC (permalink / raw)
  To: linux-pwm, Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	Florian Fainelli, Ray Jui, Scott Branden, Benson Leung, Shawn Guo,
	Sascha Hauer, Paul Cercueil, Matthias Brugger,
	AngeloGioacchino Del Regno, Neil Armstrong, Kevin Hilman,
	Krzysztof Kozlowski, Palmer Dabbelt, Paul Walmsley,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland, Andrzej Hajda, Robert Foss,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: kernel, linux-arm-kernel, Broadcom internal kernel review list,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, linux-mediatek, Jerome Brunet, Martin Blumenstingl,
	linux-amlogic, linux-rpi-kernel, Alim Akhtar, linux-samsung-soc,
	linux-riscv, linux-stm32, linux-sunxi, Douglas Anderson,
	Laurent Pinchart, Jonas Karlman, dri-devel, greybus-dev,
	linux-staging

Currently a pwm_chip stores in its struct device *dev member a pointer
to the parent device. Preparing a change that embeds a full struct
device in struct pwm_chip, this accessor macro should be used in all
drivers directly accessing chip->dev now. This way struct pwm_chip and
this macro can be changed without having to touch all drivers in the
same change set.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 include/linux/pwm.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 8ffe9ae7a23a..d7966918f301 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -289,6 +289,11 @@ struct pwm_chip {
 	struct pwm_device *pwms;
 };
 
+static inline struct device *pwmchip_parent(struct pwm_chip *chip)
+{
+	return chip->dev;
+}
+
 #if IS_ENABLED(CONFIG_PWM)
 /* PWM user APIs */
 int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state);
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v5 019/111] pwm: meson: Make use of pwmchip_parent() macro
  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 12:08 ` 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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 12:08 UTC (permalink / raw)
  To: Neil Armstrong, Kevin Hilman, linux-pwm
  Cc: Jerome Brunet, Martin Blumenstingl, linux-arm-kernel,
	linux-amlogic, kernel

struct pwm_chip::dev is about to change. To not have to touch this
driver in the same commit as struct pwm_chip::dev, use the macro
provided for exactly this purpose.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-meson.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 2971bbf3b5e7..dd0e18437be9 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -122,7 +122,7 @@ static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
 {
 	struct meson_pwm *meson = to_meson_pwm(chip);
 	struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
-	struct device *dev = chip->dev;
+	struct device *dev = pwmchip_parent(chip);
 	int err;
 
 	err = clk_prepare_enable(channel->clk);
@@ -143,9 +143,10 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 	clk_disable_unprepare(channel->clk);
 }
 
-static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
+static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
 			  const struct pwm_state *state)
 {
+	struct meson_pwm *meson = to_meson_pwm(chip);
 	struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
 	unsigned int cnt, duty_cnt;
 	unsigned long fin_freq;
@@ -169,19 +170,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
 
 	fin_freq = clk_round_rate(channel->clk, freq);
 	if (fin_freq == 0) {
-		dev_err(meson->chip.dev, "invalid source clock frequency\n");
+		dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq);
+	dev_dbg(pwmchip_parent(chip), "fin_freq: %lu Hz\n", fin_freq);
 
 	cnt = div_u64(fin_freq * period, NSEC_PER_SEC);
 	if (cnt > 0xffff) {
-		dev_err(meson->chip.dev, "unable to get period cnt\n");
+		dev_err(pwmchip_parent(chip), "unable to get period cnt\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(meson->chip.dev, "period=%llu cnt=%u\n", period, cnt);
+	dev_dbg(pwmchip_parent(chip), "period=%llu cnt=%u\n", period, cnt);
 
 	if (duty == period) {
 		channel->hi = cnt;
@@ -192,7 +193,7 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
 	} else {
 		duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC);
 
-		dev_dbg(meson->chip.dev, "duty=%llu duty_cnt=%u\n", duty, duty_cnt);
+		dev_dbg(pwmchip_parent(chip), "duty=%llu duty_cnt=%u\n", duty, duty_cnt);
 
 		channel->hi = duty_cnt;
 		channel->lo = cnt - duty_cnt;
@@ -203,8 +204,9 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm,
 	return 0;
 }
 
-static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm)
+static void meson_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 {
+	struct meson_pwm *meson = to_meson_pwm(chip);
 	struct meson_pwm_channel *channel = &meson->channels[pwm->hwpwm];
 	struct meson_pwm_channel_data *channel_data;
 	unsigned long flags;
@@ -215,7 +217,7 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm)
 
 	err = clk_set_rate(channel->clk, channel->rate);
 	if (err)
-		dev_err(meson->chip.dev, "setting clock rate failed\n");
+		dev_err(pwmchip_parent(chip), "setting clock rate failed\n");
 
 	spin_lock_irqsave(&meson->lock, flags);
 
@@ -230,8 +232,9 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm)
 	spin_unlock_irqrestore(&meson->lock, flags);
 }
 
-static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm)
+static void meson_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 {
+	struct meson_pwm *meson = to_meson_pwm(chip);
 	unsigned long flags;
 	u32 value;
 
@@ -269,16 +272,16 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 			channel->hi = ~0;
 			channel->lo = 0;
 
-			meson_pwm_enable(meson, pwm);
+			meson_pwm_enable(chip, pwm);
 		} else {
-			meson_pwm_disable(meson, pwm);
+			meson_pwm_disable(chip, pwm);
 		}
 	} else {
-		err = meson_pwm_calc(meson, pwm, state);
+		err = meson_pwm_calc(chip, pwm, state);
 		if (err < 0)
 			return err;
 
-		meson_pwm_enable(meson, pwm);
+		meson_pwm_enable(chip, pwm);
 	}
 
 	return 0;
@@ -432,10 +435,11 @@ static const struct of_device_id meson_pwm_matches[] = {
 };
 MODULE_DEVICE_TABLE(of, meson_pwm_matches);
 
-static int meson_pwm_init_channels(struct meson_pwm *meson)
+static int meson_pwm_init_channels(struct pwm_chip *chip)
 {
+	struct meson_pwm *meson = to_meson_pwm(chip);
 	struct clk_parent_data mux_parent_data[MESON_MAX_MUX_PARENTS] = {};
-	struct device *dev = meson->chip.dev;
+	struct device *dev = pwmchip_parent(chip);
 	unsigned int i;
 	char name[255];
 	int err;
@@ -543,7 +547,7 @@ static int meson_pwm_probe(struct platform_device *pdev)
 
 	meson->data = of_device_get_match_data(&pdev->dev);
 
-	err = meson_pwm_init_channels(meson);
+	err = meson_pwm_init_channels(&meson->chip);
 	if (err < 0)
 		return err;
 
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v5 039/111] pwm: Provide wrappers for storing and getting driver private data
  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 12:08 ` [PATCH v5 019/111] pwm: meson: Make use of pwmchip_parent() macro Uwe Kleine-König
@ 2024-01-25 12:09 ` 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-25 12:09 ` [PATCH v5 072/111] pwm: meson: Make use of " Uwe Kleine-König
  4 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 12:09 UTC (permalink / raw)
  To: linux-pwm, Hector Martin, Sven Peter, Nicolas Ferre,
	Alexandre Belloni, Claudiu Beznea, Florian Fainelli, Ray Jui,
	Scott Branden, Alexander Shiyan, Benson Leung, Shawn Guo,
	Sascha Hauer, Paul Cercueil, Vladimir Zapolskiy, Hans de Goede,
	Ilpo Järvinen, Matthias Brugger, AngeloGioacchino Del Regno,
	Neil Armstrong, Kevin Hilman, Conor Dooley, Daire McNamara,
	Jonathan Neuschäfer, Heiko Stuebner, Krzysztof Kozlowski,
	Palmer Dabbelt, Paul Walmsley, Michael Walle, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Fabrice Gasnier, Maxime Coquelin,
	Alexandre Torgue, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hammer Hsieh, Thierry Reding, Jonathan Hunter, Nobuhiro Iwamatsu,
	Sean Anderson, Michal Simek, Linus Walleij, Bartosz Golaszewski,
	Andrzej Hajda, Robert Foss, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Daniel Vetter, Pavel Machek,
	Lee Jones, Anjelique Melendez, Andi Shyti, Lu Hongfei,
	Bjorn Andersson, Luca Weiss, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman
  Cc: kernel, Alyssa Rosenzweig, asahi, linux-arm-kernel,
	Broadcom internal kernel review list, linux-rpi-kernel,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, platform-driver-x86, linux-mediatek, Jerome Brunet,
	Martin Blumenstingl, linux-amlogic, linux-riscv, linux-rockchip,
	Alim Akhtar, linux-samsung-soc, linux-stm32, linux-sunxi,
	linux-tegra, linux-gpio, Douglas Anderson, Laurent Pinchart,
	Jonas Karlman, dri-devel, linux-leds, greybus-dev, linux-staging

These functions are useful to store and query driver private data a
After struct pwm_chip got its own struct device, this can make use of
dev_get_drvdata() and dev_set_drvdata() on that device.  These functions
are required already now to convert drivers to pwmchip_alloc() which
must happen before changing pwm_chip::dev.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 include/linux/pwm.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index d7966918f301..2c49d2fe2fe7 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -272,6 +272,7 @@ struct pwm_ops {
  * @npwm: number of PWMs controlled by this chip
  * @of_xlate: request a PWM device given a device tree PWM specifier
  * @atomic: can the driver's ->apply() be called in atomic context
+ * @driver_data: Private pointer for driver specific info
  * @pwms: array of PWM devices allocated by the framework
  */
 struct pwm_chip {
@@ -286,6 +287,7 @@ struct pwm_chip {
 	bool atomic;
 
 	/* only used internally by the PWM framework */
+	void *driver_data;
 	struct pwm_device *pwms;
 };
 
@@ -294,6 +296,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->driver_data;
+}
+
+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->driver_data = data;
+}
+
 #if IS_ENABLED(CONFIG_PWM)
 /* PWM user APIs */
 int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state);
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function
  2024-01-25 12:08 [PATCH v5 000/111] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (2 preceding siblings ...)
  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 12:09 ` Uwe Kleine-König
  2024-01-26 14:56   ` Alex Elder
  2024-01-25 12:09 ` [PATCH v5 072/111] pwm: meson: Make use of " Uwe Kleine-König
  4 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 12:09 UTC (permalink / raw)
  To: Jonathan Corbet, Greg Kroah-Hartman, Andy Shevchenko,
	Jonathan Cameron, Bjorn Helgaas, James Clark, linux-pwm,
	Hector Martin, Sven Peter, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Florian Fainelli, Ray Jui, Scott Branden,
	Alexander Shiyan, Benson Leung, Shawn Guo, Sascha Hauer,
	Paul Cercueil, Vladimir Zapolskiy, Hans de Goede,
	Ilpo Järvinen, Matthias Brugger, AngeloGioacchino Del Regno,
	Neil Armstrong, Kevin Hilman, Conor Dooley, Daire McNamara,
	Jonathan Neuschäfer, Heiko Stuebner, Krzysztof Kozlowski,
	Palmer Dabbelt, Paul Walmsley, Michael Walle, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Fabrice Gasnier, Maxime Coquelin,
	Alexandre Torgue, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hammer Hsieh, Thierry Reding, Jonathan Hunter, Nobuhiro Iwamatsu,
	Sean Anderson, Michal Simek, Linus Walleij, Bartosz Golaszewski,
	Andrzej Hajda, Robert Foss, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Daniel Vetter, Pavel Machek,
	Lee Jones, Anjelique Melendez, Andi Shyti, Lu Hongfei,
	Bjorn Andersson, Luca Weiss, Johan Hovold, Alex Elder
  Cc: linux-doc, kernel, Alyssa Rosenzweig, asahi, linux-arm-kernel,
	Broadcom internal kernel review list, linux-rpi-kernel,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, platform-driver-x86, linux-mediatek, Jerome Brunet,
	Martin Blumenstingl, linux-amlogic, linux-riscv, linux-rockchip,
	Alim Akhtar, linux-samsung-soc, linux-stm32, linux-sunxi,
	linux-tegra, linux-gpio, Douglas Anderson, Laurent Pinchart,
	Jonas Karlman, dri-devel, linux-leds, greybus-dev, linux-staging

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().

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);
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v5 072/111] pwm: meson: Make use of devm_pwmchip_alloc() function
  2024-01-25 12:08 [PATCH v5 000/111] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (3 preceding siblings ...)
  2024-01-25 12:09 ` [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function Uwe Kleine-König
@ 2024-01-25 12:09 ` Uwe Kleine-König
  4 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 12:09 UTC (permalink / raw)
  To: Neil Armstrong, Kevin Hilman, linux-pwm
  Cc: Jerome Brunet, Martin Blumenstingl, linux-arm-kernel,
	linux-amlogic, kernel

This prepares the pwm-meson driver to further changes of the pwm core
outlined in the commit introducing devm_pwmchip_alloc(). There is no
intended semantical change and the driver should behave as before.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-meson.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index dd0e18437be9..40a5b64c26f5 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -102,7 +102,6 @@ struct meson_pwm_data {
 };
 
 struct meson_pwm {
-	struct pwm_chip chip;
 	const struct meson_pwm_data *data;
 	struct meson_pwm_channel channels[MESON_NUM_PWMS];
 	void __iomem *base;
@@ -115,7 +114,7 @@ struct meson_pwm {
 
 static inline struct meson_pwm *to_meson_pwm(struct pwm_chip *chip)
 {
-	return container_of(chip, struct meson_pwm, chip);
+	return pwmchip_get_drvdata(chip);
 }
 
 static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
@@ -449,7 +448,7 @@ static int meson_pwm_init_channels(struct pwm_chip *chip)
 		mux_parent_data[i].name = meson->data->parent_names[i];
 	}
 
-	for (i = 0; i < meson->chip.npwm; i++) {
+	for (i = 0; i < chip->npwm; i++) {
 		struct meson_pwm_channel *channel = &meson->channels[i];
 		struct clk_parent_data div_parent = {}, gate_parent = {};
 		struct clk_init_data init = {};
@@ -529,29 +528,29 @@ static int meson_pwm_init_channels(struct pwm_chip *chip)
 
 static int meson_pwm_probe(struct platform_device *pdev)
 {
+	struct pwm_chip *chip;
 	struct meson_pwm *meson;
 	int err;
 
-	meson = devm_kzalloc(&pdev->dev, sizeof(*meson), GFP_KERNEL);
-	if (!meson)
-		return -ENOMEM;
+	chip = devm_pwmchip_alloc(&pdev->dev, MESON_NUM_PWMS, sizeof(*meson));
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
+	meson = to_meson_pwm(chip);
 
 	meson->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(meson->base))
 		return PTR_ERR(meson->base);
 
 	spin_lock_init(&meson->lock);
-	meson->chip.dev = &pdev->dev;
-	meson->chip.ops = &meson_pwm_ops;
-	meson->chip.npwm = MESON_NUM_PWMS;
+	chip->ops = &meson_pwm_ops;
 
 	meson->data = of_device_get_match_data(&pdev->dev);
 
-	err = meson_pwm_init_channels(&meson->chip);
+	err = meson_pwm_init_channels(chip);
 	if (err < 0)
 		return err;
 
-	err = devm_pwmchip_add(&pdev->dev, &meson->chip);
+	err = devm_pwmchip_add(&pdev->dev, chip);
 	if (err < 0)
 		return dev_err_probe(&pdev->dev, err,
 				     "failed to register PWM chip\n");
-- 
2.43.0


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 039/111] pwm: Provide wrappers for storing and getting driver private data
  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
  0 siblings, 0 replies; 13+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-01-25 14:13 UTC (permalink / raw)
  To: Uwe Kleine-König, linux-pwm, Hector Martin, Sven Peter,
	Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
	Florian Fainelli, Ray Jui, Scott Branden, Alexander Shiyan,
	Benson Leung, Shawn Guo, Sascha Hauer, Paul Cercueil,
	Vladimir Zapolskiy, Hans de Goede, Ilpo Järvinen,
	Matthias Brugger, Neil Armstrong, Kevin Hilman, Conor Dooley,
	Daire McNamara, Jonathan Neuschäfer, Heiko Stuebner,
	Krzysztof Kozlowski, Palmer Dabbelt, Paul Walmsley, Michael Walle,
	Orson Zhai, Baolin Wang, Chunyan Zhang, Fabrice Gasnier,
	Maxime Coquelin, Alexandre Torgue, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Hammer Hsieh, Thierry Reding, Jonathan Hunter,
	Nobuhiro Iwamatsu, Sean Anderson, Michal Simek, Linus Walleij,
	Bartosz Golaszewski, Andrzej Hajda, Robert Foss,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Pavel Machek, Lee Jones, Anjelique Melendez,
	Andi Shyti, Lu Hongfei, Bjorn Andersson, Luca Weiss, Johan Hovold,
	Alex Elder, Greg Kroah-Hartman
  Cc: kernel, Alyssa Rosenzweig, asahi, linux-arm-kernel,
	Broadcom internal kernel review list, linux-rpi-kernel,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, platform-driver-x86, linux-mediatek, Jerome Brunet,
	Martin Blumenstingl, linux-amlogic, linux-riscv, linux-rockchip,
	Alim Akhtar, linux-samsung-soc, linux-stm32, linux-sunxi,
	linux-tegra, linux-gpio, Douglas Anderson, Laurent Pinchart,
	Jonas Karlman, dri-devel, linux-leds, greybus-dev, linux-staging

Il 25/01/24 13:09, Uwe Kleine-König ha scritto:
> These functions are useful to store and query driver private data a
> After struct pwm_chip got its own struct device, this can make use of
> dev_get_drvdata() and dev_set_drvdata() on that device.  These functions
> are required already now to convert drivers to pwmchip_alloc() which
> must happen before changing pwm_chip::dev.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip
  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
  1 sibling, 0 replies; 13+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-01-25 14:14 UTC (permalink / raw)
  To: Uwe Kleine-König, linux-pwm, Claudiu Beznea, Nicolas Ferre,
	Alexandre Belloni, Florian Fainelli, Ray Jui, Scott Branden,
	Benson Leung, Shawn Guo, Sascha Hauer, Paul Cercueil,
	Matthias Brugger, Neil Armstrong, Kevin Hilman,
	Krzysztof Kozlowski, Palmer Dabbelt, Paul Walmsley,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland, Andrzej Hajda, Robert Foss,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: kernel, linux-arm-kernel, Broadcom internal kernel review list,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, linux-mediatek, Jerome Brunet, Martin Blumenstingl,
	linux-amlogic, linux-rpi-kernel, Alim Akhtar, linux-samsung-soc,
	linux-riscv, linux-stm32, linux-sunxi, Douglas Anderson,
	Laurent Pinchart, Jonas Karlman, dri-devel, greybus-dev,
	linux-staging

Il 25/01/24 13:08, Uwe Kleine-König ha scritto:
> Currently a pwm_chip stores in its struct device *dev member a pointer
> to the parent device. Preparing a change that embeds a full struct
> device in struct pwm_chip, this accessor macro should be used in all
> drivers directly accessing chip->dev now. This way struct pwm_chip and
> this macro can be changed without having to touch all drivers in the
> same change set.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

> ---
>   include/linux/pwm.h | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/include/linux/pwm.h b/include/linux/pwm.h
> index 8ffe9ae7a23a..d7966918f301 100644
> --- a/include/linux/pwm.h
> +++ b/include/linux/pwm.h
> @@ -289,6 +289,11 @@ struct pwm_chip {
>   	struct pwm_device *pwms;
>   };
>   
> +static inline struct device *pwmchip_parent(struct pwm_chip *chip)
> +{
> +	return chip->dev;
> +}
> +
>   #if IS_ENABLED(CONFIG_PWM)
>   /* PWM user APIs */
>   int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state);




_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Florian Fainelli @ 2024-01-25 19:32 UTC (permalink / raw)
  To: Uwe Kleine-König, linux-pwm, Claudiu Beznea, Nicolas Ferre,
	Alexandre Belloni, Ray Jui, Scott Branden, Benson Leung,
	Shawn Guo, Sascha Hauer, Paul Cercueil, Matthias Brugger,
	AngeloGioacchino Del Regno, Neil Armstrong, Kevin Hilman,
	Krzysztof Kozlowski, Palmer Dabbelt, Paul Walmsley,
	Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue, Chen-Yu Tsai,
	Jernej Skrabec, Samuel Holland, Andrzej Hajda, Robert Foss,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: kernel, linux-arm-kernel, Broadcom internal kernel review list,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, linux-mediatek, Jerome Brunet, Martin Blumenstingl,
	linux-amlogic, linux-rpi-kernel, Alim Akhtar, linux-samsung-soc,
	linux-riscv, linux-stm32, linux-sunxi, Douglas Anderson,
	Laurent Pinchart, Jonas Karlman, dri-devel, greybus-dev,
	linux-staging


[-- Attachment #1.1: Type: text/plain, Size: 553 bytes --]

On 1/25/24 04:08, Uwe Kleine-König wrote:
> Currently a pwm_chip stores in its struct device *dev member a pointer
> to the parent device. Preparing a change that embeds a full struct
> device in struct pwm_chip, this accessor macro should be used in all
> drivers directly accessing chip->dev now. This way struct pwm_chip and
> this macro can be changed without having to touch all drivers in the
> same change set.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Nit: this is not a macro but an inline function.
-- 
Florian


[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip
  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
  0 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 20:29 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: linux-pwm, Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	Ray Jui, Scott Branden, Benson Leung, Shawn Guo, Sascha Hauer,
	Paul Cercueil, Matthias Brugger, AngeloGioacchino Del Regno,
	Neil Armstrong, Kevin Hilman, Krzysztof Kozlowski, Palmer Dabbelt,
	Paul Walmsley, Fabrice Gasnier, Maxime Coquelin, Alexandre Torgue,
	Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Andrzej Hajda,
	Robert Foss, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Johan Hovold, Alex Elder,
	Greg Kroah-Hartman, dri-devel, linux-mips, Laurent Pinchart,
	Alim Akhtar, Guenter Roeck, linux-riscv, Fabio Estevam,
	linux-stm32, Jerome Brunet, chrome-platform, linux-samsung-soc,
	linux-staging, Broadcom internal kernel review list,
	NXP Linux Team, linux-sunxi, Jonas Karlman, Martin Blumenstingl,
	greybus-dev, linux-mediatek, linux-rpi-kernel, linux-amlogic,
	linux-arm-kernel, Douglas Anderson, kernel


[-- Attachment #1.1: Type: text/plain, Size: 1384 bytes --]

On Thu, Jan 25, 2024 at 11:32:47AM -0800, Florian Fainelli wrote:
> On 1/25/24 04:08, Uwe Kleine-König wrote:
> > Currently a pwm_chip stores in its struct device *dev member a pointer
> > to the parent device. Preparing a change that embeds a full struct
> > device in struct pwm_chip, this accessor macro should be used in all
> > drivers directly accessing chip->dev now. This way struct pwm_chip and
> > this macro can be changed without having to touch all drivers in the
> > same change set.
> > 
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> Nit: this is not a macro but an inline function.

Oh right, it used to be a macro, but I changed that. I made the commit
log read:

    pwm: Provide an inline function to get the parent device of a given chip

    Currently a pwm_chip stores in its struct device *dev member a pointer
    to the parent device. Preparing a change that embeds a full struct
    device in struct pwm_chip, this accessor function should be used in all
    drivers directly accessing chip->dev now. This way struct pwm_chip and
    this new function can be changed without having to touch all drivers in
    the same change set.

Thanks,
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 003/111] pwm: Provide a macro to get the parent device of a given chip
  2024-01-25 20:29     ` Uwe Kleine-König
@ 2024-01-25 20:54       ` Uwe Kleine-König
  0 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-25 20:54 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: Alexandre Belloni, Douglas Anderson, Alim Akhtar,
	Alexandre Torgue, dri-devel, Nicolas Ferre, Paul Cercueil,
	Laurent Pinchart, Andrzej Hajda, linux-amlogic, Guenter Roeck,
	linux-riscv, David Airlie, linux-stm32, Jerome Brunet,
	chrome-platform, linux-samsung-soc, Robert Foss, Samuel Holland,
	Kevin Hilman, linux-staging, Jernej Skrabec, Chen-Yu Tsai,
	Broadcom internal kernel review list, NXP Linux Team, linux-mips,
	linux-sunxi, linux-pwm, Thomas Zimmermann, Jonas Karlman,
	Martin Blumenstingl, Ray Jui, Sascha Hauer, Maarten Lankhorst,
	Johan Hovold, Maxime Ripard, greybus-dev, Fabrice Gasnier,
	linux-mediatek, linux-rpi-kernel, Fabio Estevam, Paul Walmsley,
	Matthias Brugger, Daniel Vetter, Benson Leung, kernel,
	linux-arm-kernel, AngeloGioacchino Del Regno, Neil Armstrong,
	Alex Elder, Scott Branden, Greg Kroah-Hartman, Claudiu Beznea,
	Krzysztof Kozlowski, Palmer Dabbelt, Maxime Coquelin, Shawn Guo


[-- Attachment #1.1: Type: text/plain, Size: 2329 bytes --]

On Thu, Jan 25, 2024 at 09:29:37PM +0100, Uwe Kleine-König wrote:
> On Thu, Jan 25, 2024 at 11:32:47AM -0800, Florian Fainelli wrote:
> > On 1/25/24 04:08, Uwe Kleine-König wrote:
> > > Currently a pwm_chip stores in its struct device *dev member a pointer
> > > to the parent device. Preparing a change that embeds a full struct
> > > device in struct pwm_chip, this accessor macro should be used in all
> > > drivers directly accessing chip->dev now. This way struct pwm_chip and
> > > this macro can be changed without having to touch all drivers in the
> > > same change set.
> > > 
> > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > 
> > Nit: this is not a macro but an inline function.
> 
> Oh right, it used to be a macro, but I changed that. I made the commit
> log read:
> 
>     pwm: Provide an inline function to get the parent device of a given chip
> 
>     Currently a pwm_chip stores in its struct device *dev member a pointer
>     to the parent device. Preparing a change that embeds a full struct
>     device in struct pwm_chip, this accessor function should be used in all
>     drivers directly accessing chip->dev now. This way struct pwm_chip and
>     this new function can be changed without having to touch all drivers in
>     the same change set.

While looking into further feedback, I noticed I did the same mistake in
all the patches that convert the drivers to use this function. I did

	git filter-branch --msg-filter 'sed "s/Make use of pwmchip_parent() macro/Make use of pwmchip_parent() accessor/; s/commit as struct pwm_chip::dev, use the macro/commit as struct pwm_chip::dev, use the accessor/; s/provided for exactly this purpose./function provided for exactly this purpose./"' linus/master..

on my branch to make the typical commit log read:

	pwm: atmel: Make use of pwmchip_parent() accessor
	
	struct pwm_chip::dev is about to change. To not have to touch this
	driver in the same commit as struct pwm_chip::dev, use the accessor
	function provided for exactly this purpose.

I wont resend the whole series if this is the only change to it.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function
  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
  2024-01-26 17:10     ` Uwe Kleine-König
  0 siblings, 1 reply; 13+ messages in thread
From: Alex Elder @ 2024-01-26 14:56 UTC (permalink / raw)
  To: Uwe Kleine-König, Jonathan Corbet, Greg Kroah-Hartman,
	Andy Shevchenko, Jonathan Cameron, Bjorn Helgaas, James Clark,
	linux-pwm, Hector Martin, Sven Peter, Nicolas Ferre,
	Alexandre Belloni, Claudiu Beznea, Florian Fainelli, Ray Jui,
	Scott Branden, Alexander Shiyan, Benson Leung, Shawn Guo,
	Sascha Hauer, Paul Cercueil, Vladimir Zapolskiy, Hans de Goede,
	Ilpo Järvinen, Matthias Brugger, AngeloGioacchino Del Regno,
	Neil Armstrong, Kevin Hilman, Conor Dooley, Daire McNamara,
	Jonathan Neuschäfer, Heiko Stuebner, Krzysztof Kozlowski,
	Palmer Dabbelt, Paul Walmsley, Michael Walle, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Fabrice Gasnier, Maxime Coquelin,
	Alexandre Torgue, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hammer Hsieh, Thierry Reding, Jonathan Hunter, Nobuhiro Iwamatsu,
	Sean Anderson, Michal Simek, Linus Walleij, Bartosz Golaszewski,
	Andrzej Hajda, Robert Foss, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Daniel Vetter, Pavel Machek,
	Lee Jones, Anjelique Melendez, Andi Shyti, Lu Hongfei,
	Bjorn Andersson, Luca Weiss, Johan Hovold
  Cc: linux-doc, kernel, Alyssa Rosenzweig, asahi, linux-arm-kernel,
	Broadcom internal kernel review list, linux-rpi-kernel,
	Guenter Roeck, chrome-platform, Fabio Estevam, NXP Linux Team,
	linux-mips, platform-driver-x86, linux-mediatek, Jerome Brunet,
	Martin Blumenstingl, linux-amlogic, linux-riscv, linux-rockchip,
	Alim Akhtar, linux-samsung-soc, linux-stm32, linux-sunxi,
	linux-tegra, linux-gpio, Douglas Anderson, Laurent Pinchart,
	Jonas Karlman, dri-devel, linux-leds, greybus-dev, linux-staging

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v5 040/111] pwm: Provide devm_pwmchip_alloc() function
  2024-01-26 14:56   ` Alex Elder
@ 2024-01-26 17:10     ` Uwe Kleine-König
  0 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-01-26 17:10 UTC (permalink / raw)
  To: Alex Elder
  Cc: Jonathan Corbet, Greg Kroah-Hartman, Andy Shevchenko,
	Jonathan Cameron, Bjorn Helgaas, James Clark, linux-pwm,
	Hector Martin, Sven Peter, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Florian Fainelli, Ray Jui, Scott Branden,
	Alexander Shiyan, Benson Leung, Shawn Guo, Sascha Hauer,
	Paul Cercueil, Vladimir Zapolskiy, Hans de Goede,
	Ilpo Järvinen, Matthias Brugger, AngeloGioacchino Del Regno,
	Neil Armstrong, Kevin Hilman, Conor Dooley, Daire McNamara,
	Jonathan Neuschäfer, Heiko Stuebner, Krzysztof Kozlowski,
	Palmer Dabbelt, Paul Walmsley, Michael Walle, Orson Zhai,
	Baolin Wang, Chunyan Zhang, Fabrice Gasnier, Maxime Coquelin,
	Alexandre Torgue, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Hammer Hsieh, Thierry Reding, Jonathan Hunter, Nobuhiro Iwamatsu,
	Sean Anderson, Michal Simek, Linus Walleij, Bartosz Golaszewski,
	Andrzej Hajda, Robert Foss, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Daniel Vetter, Pavel Machek,
	Lee Jones, Anjelique Melendez, Andi Shyti, Lu Hongfei,
	Bjorn Andersson, Luca Weiss, Johan Hovold, Douglas Anderson,
	linux-doc, dri-devel, platform-driver-x86, Laurent Pinchart,
	Alim Akhtar, Guenter Roeck, linux-riscv, Fabio Estevam,
	linux-stm32, Alyssa Rosenzweig, Jerome Brunet, chrome-platform,
	linux-samsung-soc, linux-staging, linux-rockchip,
	Broadcom internal kernel review list, NXP Linux Team, linux-leds,
	linux-sunxi, Jonas Karlman, Martin Blumenstingl, linux-gpio,
	linux-mediatek, linux-rpi-kernel, linux-tegra, linux-amlogic,
	linux-arm-kernel, greybus-dev, linux-mips, asahi, kernel


[-- Attachment #1.1: Type: text/plain, Size: 1836 bytes --]

Hello Alex,

On Fri, Jan 26, 2024 at 08:56:33AM -0600, Alex Elder wrote:
> 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?

I'm not aware of a requirement for a higher order alignment (but I might
well miss something). I did my tests on arm, nothing exploded there.
Maybe the conservative approach of asserting the same alignment as
kmalloc would be a good idea. I'll think and research about that.

iio uses ARCH_DMA_MINALIGN, net uses 32 (NETDEV_ALIGN).

> - Is there a non-devres version of the allocation function?

Patch #109 introduces a non-devres variant. As it's not used it's a
static function though. Can easily be changed is a use case pops up.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-02-23 17:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox