linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips
@ 2024-02-14  9:30 Uwe Kleine-König
  2024-02-14  9:30 ` [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Uwe Kleine-König
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-14  9:30 UTC (permalink / raw)
  To: linux-pwm, Jonathan Corbet, Jonathan Cameron, James Clark,
	Andy Shevchenko, Mark Brown, Hector Martin, Sven Peter,
	Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	Florian Fainelli, Ray Jui, Scott Branden, Alexander Shiyan,
	Benson Leung, Philipp Zabel, Shawn Guo, Sascha Hauer,
	Paul Cercueil, Vladimir Zapolskiy, Mika Westerberg,
	Andy Shevchenko, Linus Walleij, 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, Bartosz Golaszewski, Andrzej Hajda,
	Robert Foss, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Pavel Machek, Lee Jones,
	Anjelique Melendez, Bjorn Andersson, Kees Cook, Rob Herring,
	Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: kernel, linux-doc, 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, linux-gpio, 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, Douglas Anderson, Laurent Pinchart,
	Jonas Karlman, dri-devel, linux-leds, greybus-dev, linux-staging,
	Gustavo A. R. Silva, linux-hardening

Hello,

this is v6 of the series introducing better lifetime tracking for
pwmchips that addresses (for now theoretic) lifetime issues of pwm
chips. Addressing these is a necessary precondition to introduce chardev
support for PWMs.

Locking got more complicated due to non-sleeping chips, so I dropped
the character device patch because it got still more incomplete now.
Also I'm not yet entirely sure about patches #162 and #163 and I expect
them to change before they can go in. My plan for the next merge window
is to get the patches in up to #160. After that the addition of chardev
support (including correct locking) can continue without having to touch
the lowlevel driver. So the idea of this series is to get the driver
adaptions out of the way as this requires some cross-tree coordination.

The patches that touch files outside of drivers/pwm include:

 - gpio: mvebu: Make use of devm_pwmchip_alloc() function
   It already has an Ack by Linus Walleij.

 - drm/bridge: ti-sn65dsi86: Make use of pwmchip_parent() accessor
 - drm/bridge: ti-sn65dsi86: Make use of devm_pwmchip_alloc() function
   The 2nd already has an Ack by Douglas Anderson which I tend to assume
   good enough to merge this via my pwm tree, too. An Ack for the first
   patch would be nice.

 - leds: qcom-lpg: Make use of devm_pwmchip_alloc() function
   Already has an Ack by Lee Jones.

 - staging: greybus: pwm: Change prototype of helpers to prepare further changes
 - staging: greybus: pwm: Make use of pwmchip_parent() accessor
 - staging: greybus: pwm: Rely on pwm framework to pass a valid hwpwm
 - staging: greybus: pwm: Drop unused gb_connection_set_data()
 - staging: greybus: pwm: Rework how the number of PWM lines is determined
 - staging: greybus: pwm: Make use of devm_pwmchip_alloc() function
   The greybus patches already got an Ack by Greg Kroah-Hartman in an
   earlier series, but I dropped it as the patches changed considerably.

For the patches that already have an Ack by the respective maintainers
I'll assume this is good enough to merge the patches via the pwm tree.
Please object if you don't agree.  For the others an Ack with that
semantic would be nice. If you want to merge via your tree, that would
need some coordination. The adaptions depend on patches #1 - #3, so this
would involve an immutable branch or waiting until these patches reached
your tree via the mainline tree. The series rebases fine on today's
next, so at least for now there are no conflicts that git cannot resolve
automatically.

The biggest changes compared to v5 are:

 - Make pwmchip_parent's parameter const
 - Use pwmchip_parent also in drivers/pwm/sysfs.c and drivers/pwm/core.c
 - Several bug fixes in the conversions I found during the rework
 - Provide a non-devm pwmchip_alloc() function earlier (for the greybus
   pwm driver)
 - Increase alignment of driver private data to ARCH_DMA_MINALIGN bytes
 - Split several patches to make the easier reviewable

The series is available via git at

	https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm-lifetime-tracking

if you want to give it a test. I'll keep this branch updated for the
feedback I get here.

Best regards
Uwe

Uwe Kleine-König (164):
  pwm: Provide an inline function to get the parent device of a given
    chip
  pwm: Provide wrappers for storing and getting driver private data
  pwm: Provide pwmchip_alloc() function and a devm variant of it
  pwm: ab8500: Make use of pwmchip_parent() accessor
  pwm: ab8500: Introduce a local pwm_chip variable in .probe()
  pwm: ab8500: Make use of devm_pwmchip_alloc() function
  pwm: apple: Make use of devm_pwmchip_alloc() function
  pwm: atmel: Change prototype of a helper to prepare further changes
  pwm: atmel: Make use of pwmchip_parent() accessor
  pwm: atmel: Make use of devm_pwmchip_alloc() function
  pwm: atmel-hlcdc: Prepare removing pwm_chip from driver data
  pwm: atmel-hlcdc: Make use of devm_pwmchip_alloc() function
  pwm: atmel-tcb: Make use of pwmchip_parent() accessor
  pwm: atmel-tcb: Prepare removing pwm_chip from driver data
  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 pwmchip_parent() accessor
  pwm: bcm-kona: Make use of devm_pwmchip_alloc() function
  pwm: berlin: Prepare removing pwm_chip from driver data
  pwm: berlin: Make use of devm_pwmchip_alloc() function
  pwm: brcmstb: Make use of devm_pwmchip_alloc() function
  pwm: clk: Prepare removing pwm_chip from driver data
  pwm: clk: Make use of devm_pwmchip_alloc() function
  pwm: clps711x: Make use of devm_pwmchip_alloc() function
  pwm: crc: Simplify code to determine the pwmchip's parent device
  pwm: crc: Make use of pwmchip_parent() accessor
  pwm: crc: Make use of devm_pwmchip_alloc() function
  pwm: cros-ec: Change prototype of helpers to prepare further changes
  pwm: cros-ec: Make use of pwmchip_parent() accessor
  pwm: cros-ec: Make use of devm_pwmchip_alloc() function
  pwm: dwc: Prepare removing pwm_chip from driver data
  pwm: dwc: Make use of devm_pwmchip_alloc() function
  pwm: dwc-core: Make use of pwmchip_parent() accessor
  pwm: ep93xx: Make use of pwmchip_parent() accessor
  pwm: ep93xx: Make use of devm_pwmchip_alloc() function
  pwm: fsl-ftm: Change prototype of a helper to prepare further changes
  pwm: fsl-ftm: Make use of pwmchip_parent() accessor
  pwm: fsl-ftm: Prepare removing pwm_chip from driver data
  pwm: fsl-ftm: Make use of devm_pwmchip_alloc() function
  pwm: hibvt: Consistently name driver data hi_pwm_chip
  pwm: hibvt: Make use of devm_pwmchip_alloc() function
  pwm: img: Drop write-only variable from driver private data
  pwm: img: Make use of pwmchip_parent() accessor
  pwm: img: Prepare removing pwm_chip from driver data
  pwm: img: Make use of devm_pwmchip_alloc() function
  pwm: imx1: Make use of devm_pwmchip_alloc() function
  pwm: imx27: Make use of pwmchip_parent() accessor
  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: Create a wrapper for converting a pwm_chip to driver
    data
  pwm: iqs620a: Prepare removing pwm_chip from driver data
  pwm: iqs620a: Make use of devm_pwmchip_alloc() function
  pwm: jz4740: Change prototype of a helper to prepare further changes
  pwm: jz4740: Make use of pwmchip_parent() accessor
  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: Drop hardly used member from driver private data
  pwm: lpc18xx-sct: Make use of pwmchip_parent() accessor
  pwm: lpc18xx-sct: Prepare removing pwm_chip from driver data
  pwm: lpc18xx-sct: Make use of devm_pwmchip_alloc() function
  pwm: lpc32xx: Make use of devm_pwmchip_alloc() function
  pwm: lpss: Make use of pwmchip_parent() accessor
  pwm: lpss: Don't set driver data
  pwm: lpss-*: Make use of devm_pwmchip_alloc() function
  pwm: mediatek: Make use of pwmchip_parent() accessor
  pwm: mediatek: Make use of devm_pwmchip_alloc() function
  pwm: meson: Change prototype of a few helpers to prepare further
    changes
  pwm: meson: Make use of pwmchip_parent() accessor
  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 pwmchip_parent() accessor
  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 pwmchip_parent() accessor
  pwm: omap-dmtimer: Prepare removing pwm_chip from driver data
  pwm: omap-dmtimer: Make use of devm_pwmchip_alloc() function
  pwm: pca9685: Prepare removing pwm_chip from driver data
  pwm: pca9685: Make use of pwmchip_parent() accessor
  pwm: pca9685: Make use of devm_pwmchip_alloc() function
  pwm: pxa: Make use of devm_pwmchip_alloc() function
  pwm: raspberrypi-poe: Make use of pwmchip_parent() accessor
  pwm: raspberrypi-poe: Make use of devm_pwmchip_alloc() function
  pwm: rcar: Make use of pwmchip_parent() accessor
  pwm: rcar: Prepare removing pwm_chip from driver data
  pwm: rcar: Make use of devm_pwmchip_alloc() function
  pwm: renesas-tpu: Make use of devm_pwmchip_alloc() function
  pwm: rochchip: Prepare removing pwm_chip from driver data
  pwm: rockchip: Make use of devm_pwmchip_alloc() function
  pwm: rz-mtu3: Make use of pwmchip_parent() accessor
  pwm: rz-mtu3: Prepare removing pwm_chip from driver data
  pwm: rz-mtu3: Make use of devm_pwmchip_alloc() function
  pwm: samsung: Simplify code to determine the pwmchip's parent device
  pwm: samsung: Change prototype of helpers to prepare further changes
  pwm: samsung: Make use of pwmchip_parent() accessor
  pwm: samsung: Simplify by using devm functions in probe
  pwm: samsung: Simplify using dev_err_probe()
  pwm: samsung: Make use of devm_pwmchip_alloc() function
  pwm: sifive: Simplify code to determine the pwmchip's parent device
  pwm: sifive: Prepare removing pwm_chip from driver data
  pwm: sifive: Make use of pwmchip_parent() accessor
  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: Rework how the available channels are counted
  pwm: sprd: Drop duplicated tracking of the parent device
  pwm: sprd: Make use of devm_pwmchip_alloc() function
  pwm: sti: Prepare removing pwm_chip from driver data
  pwm: sti: Make use of devm_pwmchip_alloc() function
  pwm: stm32: Simplify code to determine the pwmchip's parent device
  pwm: stm32: Change prototype of a helper to prepare further changes
  pwm: stm32: Prepare removing pwm_chip from driver data
  pwm: stm32: Change prototype of helper that detects npwm to prepare
    further changes
  pwm: stm32: Make use of devm_pwmchip_alloc() function
  pwm: stm32-lp: Simplify code to determine the pwmchip's parent device
  pwm: stm32-lp: Prepare removing pwm_chip from driver data
  pwm: stm32-lp: Make use of pwmchip_parent() accessor
  pwm: stm32-lp: Make use of devm_pwmchip_alloc() function
  pwm: stmpe: Make use of pwmchip_parent() accessor
  pwm: stmpe: Make use of devm_pwmchip_alloc() function
  pwm: sun4i: Make use of pwmchip_parent() accessor
  pwm: sun4i: Prepare removing pwm_chip from driver data
  pwm: sun4i: Consistently name driver data sun4ichip
  pwm: sun4i: Make use of devm_pwmchip_alloc() function
  pwm: sunplus: Make use of devm_pwmchip_alloc() function
  pwm: tegra: Drop duplicated tracking of the parent device
  pwm: tegra: Prepare removing pwm_chip from driver data
  pwm: tegra: Make use of devm_pwmchip_alloc() function
  pwm: tiecap: Simplify code to determine the pwmchip's parent device
  pwm: tiecap: Change prototype of helpers to prepare further changes
  pwm: tiecap: Make use of pwmchip_parent() accessor
  pwm: tiecap: Make use of devm_pwmchip_alloc() function
  pwm: tiehrpwm: Simplify code to determine the pwmchip's parent device
  pwm: tiehrpwm: Change prototype of helpers to prepare further changes
  pwm: tiehrpwm: Make use of pwmchip_parent() accessor
  pwm: tiehrpwm: Make use of devm_pwmchip_alloc() function
  pwm: twl: Make use of pwmchip_parent() accessor
  pwm: twl: Make use of devm_pwmchip_alloc() function
  pwm: twl-led: Make use of pwmchip_parent() accessor
  pwm: twl-led: Make use of devm_pwmchip_alloc() function
  pwm: visconti: Make use of devm_pwmchip_alloc() function
  pwm: vt8500: Change prototype of a helper to prepare further changes
  pwm: vt8500: Introduce a local pwm_chip variable in .probe()
  pwm: vt8500: Make use of pwmchip_parent() accessor
  pwm: vt8500: Make use of devm_pwmchip_alloc() function
  pwm: xilinx: Prepare removing pwm_chip from driver data
  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 pwmchip_parent() accessor
  drm/bridge: ti-sn65dsi86: Make use of devm_pwmchip_alloc() function
  leds: qcom-lpg: Make use of devm_pwmchip_alloc() function
  staging: greybus: pwm: Change prototype of helpers to prepare further
    changes
  staging: greybus: pwm: Make use of pwmchip_parent() accessor
  staging: greybus: pwm: Rely on pwm framework to pass a valid hwpwm
  staging: greybus: pwm: Drop unused gb_connection_set_data()
  staging: greybus: pwm: Rework how the number of PWM lines is
    determined
  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()

 .../driver-api/driver-model/devres.rst        |   1 +
 Documentation/driver-api/pwm.rst              |  11 +-
 drivers/gpio/gpio-mvebu.c                     |  18 +-
 drivers/gpu/drm/bridge/ti-sn65dsi86.c         |  31 +--
 drivers/leds/rgb/leds-qcom-lpg.c              |  16 +-
 drivers/pinctrl/intel/pinctrl-intel.c         |   6 +-
 drivers/pwm/Kconfig                           |   4 -
 drivers/pwm/Makefile                          |   3 +-
 drivers/pwm/core.c                            | 184 +++++++++++++-----
 drivers/pwm/pwm-ab8500.c                      |  36 ++--
 drivers/pwm/pwm-apple.c                       |  18 +-
 drivers/pwm/pwm-atmel-hlcdc.c                 |  37 ++--
 drivers/pwm/pwm-atmel-tcb.c                   |  32 +--
 drivers/pwm/pwm-atmel.c                       |  34 ++--
 drivers/pwm/pwm-bcm-iproc.c                   |  19 +-
 drivers/pwm/pwm-bcm-kona.c                    |  23 ++-
 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                    |  26 +--
 drivers/pwm/pwm-dwc.c                         |  17 +-
 drivers/pwm/pwm-dwc.h                         |   9 +-
 drivers/pwm/pwm-ep93xx.c                      |  21 +-
 drivers/pwm/pwm-fsl-ftm.c                     |  49 ++---
 drivers/pwm/pwm-hibvt.c                       |  70 ++++---
 drivers/pwm/pwm-img.c                         |  60 +++---
 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                     |  30 +--
 drivers/pwm/pwm-jz4740.c                      |  36 ++--
 drivers/pwm/pwm-keembay.c                     |  17 +-
 drivers/pwm/pwm-lp3943.c                      |  17 +-
 drivers/pwm/pwm-lpc18xx-sct.c                 |  34 ++--
 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                       |  14 +-
 drivers/pwm/pwm-omap-dmtimer.c                |  47 +++--
 drivers/pwm/pwm-pca9685.c                     | 161 +++++++--------
 drivers/pwm/pwm-pxa.c                         |  21 +-
 drivers/pwm/pwm-raspberrypi-poe.c             |  20 +-
 drivers/pwm/pwm-rcar.c                        |  27 ++-
 drivers/pwm/pwm-renesas-tpu.c                 |  20 +-
 drivers/pwm/pwm-rockchip.c                    |  24 +--
 drivers/pwm/pwm-rz-mtu3.c                     |  60 +++---
 drivers/pwm/pwm-samsung.c                     |  94 ++++-----
 drivers/pwm/pwm-sifive.c                      |  30 +--
 drivers/pwm/pwm-sl28cpld.c                    |  13 +-
 drivers/pwm/pwm-spear.c                       |  18 +-
 drivers/pwm/pwm-sprd.c                        |  58 +++---
 drivers/pwm/pwm-sti.c                         |  61 +++---
 drivers/pwm/pwm-stm32-lp.c                    |  31 ++-
 drivers/pwm/pwm-stm32.c                       |  56 +++---
 drivers/pwm/pwm-stmpe.c                       |  58 +++---
 drivers/pwm/pwm-sun4i.c                       | 100 +++++-----
 drivers/pwm/pwm-sunplus.c                     |  17 +-
 drivers/pwm/pwm-tegra.c                       |  50 ++---
 drivers/pwm/pwm-tiecap.c                      |  55 +++---
 drivers/pwm/pwm-tiehrpwm.c                    |  72 +++----
 drivers/pwm/pwm-twl-led.c                     |  55 +++---
 drivers/pwm/pwm-twl.c                         |  50 +++--
 drivers/pwm/pwm-visconti.c                    |  17 +-
 drivers/pwm/pwm-vt8500.c                      |  43 ++--
 drivers/pwm/pwm-xilinx.c                      |  34 ++--
 drivers/pwm/sysfs.c                           |  45 +----
 drivers/staging/greybus/pwm.c                 | 133 ++++++-------
 include/linux/platform_data/x86/pwm-lpss.h    |   4 +-
 include/linux/pwm.h                           |  56 ++++--
 81 files changed, 1502 insertions(+), 1423 deletions(-)


base-commit: ab105bfee27776dd946f8003d1e895fbf7674a3f
-- 
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 v6 001/164] pwm: Provide an inline function to get the parent device of a given chip
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
@ 2024-02-14  9:30 ` Uwe Kleine-König
  2024-02-14 10:39   ` Greg Kroah-Hartman
  2024-02-14  9:30 ` [PATCH v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it Uwe Kleine-König
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-14  9:30 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, 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, 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, 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 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.

Make use of this function in the framework's core sources.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/core.c  | 42 +++++++++++++++++++++---------------------
 drivers/pwm/sysfs.c |  4 ++--
 include/linux/pwm.h |  5 +++++
 3 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 1b4c3d0caa82..830a697826af 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -71,18 +71,18 @@ static void pwm_apply_debug(struct pwm_device *pwm,
 
 	if (s2.polarity != state->polarity &&
 	    state->duty_cycle < state->period)
-		dev_warn(chip->dev, ".apply ignored .polarity\n");
+		dev_warn(pwmchip_parent(chip), ".apply ignored .polarity\n");
 
 	if (state->enabled &&
 	    last->polarity == state->polarity &&
 	    last->period > s2.period &&
 	    last->period <= state->period)
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 ".apply didn't pick the best available period (requested: %llu, applied: %llu, possible: %llu)\n",
 			 state->period, s2.period, last->period);
 
 	if (state->enabled && state->period < s2.period)
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 ".apply is supposed to round down period (requested: %llu, applied: %llu)\n",
 			 state->period, s2.period);
 
@@ -91,20 +91,20 @@ static void pwm_apply_debug(struct pwm_device *pwm,
 	    last->period == s2.period &&
 	    last->duty_cycle > s2.duty_cycle &&
 	    last->duty_cycle <= state->duty_cycle)
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 ".apply didn't pick the best available duty cycle (requested: %llu/%llu, applied: %llu/%llu, possible: %llu/%llu)\n",
 			 state->duty_cycle, state->period,
 			 s2.duty_cycle, s2.period,
 			 last->duty_cycle, last->period);
 
 	if (state->enabled && state->duty_cycle < s2.duty_cycle)
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 ".apply is supposed to round down duty_cycle (requested: %llu/%llu, applied: %llu/%llu)\n",
 			 state->duty_cycle, state->period,
 			 s2.duty_cycle, s2.period);
 
 	if (!state->enabled && s2.enabled && s2.duty_cycle > 0)
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 "requested disabled, but yielded enabled with duty > 0\n");
 
 	/* reapply the state that the driver reported being configured. */
@@ -112,7 +112,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
 	trace_pwm_apply(pwm, &s1, err);
 	if (err) {
 		*last = s1;
-		dev_err(chip->dev, "failed to reapply current setting\n");
+		dev_err(pwmchip_parent(chip), "failed to reapply current setting\n");
 		return;
 	}
 
@@ -127,7 +127,7 @@ static void pwm_apply_debug(struct pwm_device *pwm,
 	    s1.polarity != last->polarity ||
 	    (s1.enabled && s1.period != last->period) ||
 	    (s1.enabled && s1.duty_cycle != last->duty_cycle)) {
-		dev_err(chip->dev,
+		dev_err(pwmchip_parent(chip),
 			".apply is not idempotent (ena=%d pol=%d %llu/%llu) -> (ena=%d pol=%d %llu/%llu)\n",
 			s1.enabled, s1.polarity, s1.duty_cycle, s1.period,
 			last->enabled, last->polarity, last->duty_cycle,
@@ -318,7 +318,7 @@ static struct pwm_chip *pwmchip_find_by_name(const char *name)
 	mutex_lock(&pwm_lock);
 
 	idr_for_each_entry_ul(&pwm_chips, chip, tmp, id) {
-		const char *chip_name = dev_name(chip->dev);
+		const char *chip_name = dev_name(pwmchip_parent(chip));
 
 		if (chip_name && strcmp(chip_name, name) == 0) {
 			mutex_unlock(&pwm_lock);
@@ -456,19 +456,19 @@ EXPORT_SYMBOL_GPL(of_pwm_single_xlate);
 
 static void of_pwmchip_add(struct pwm_chip *chip)
 {
-	if (!chip->dev || !chip->dev->of_node)
+	if (!pwmchip_parent(chip) || !pwmchip_parent(chip)->of_node)
 		return;
 
 	if (!chip->of_xlate)
 		chip->of_xlate = of_pwm_xlate_with_flags;
 
-	of_node_get(chip->dev->of_node);
+	of_node_get(pwmchip_parent(chip)->of_node);
 }
 
 static void of_pwmchip_remove(struct pwm_chip *chip)
 {
-	if (chip->dev)
-		of_node_put(chip->dev->of_node);
+	if (pwmchip_parent(chip))
+		of_node_put(pwmchip_parent(chip)->of_node);
 }
 
 static bool pwm_ops_check(const struct pwm_chip *chip)
@@ -479,7 +479,7 @@ static bool pwm_ops_check(const struct pwm_chip *chip)
 		return false;
 
 	if (IS_ENABLED(CONFIG_PWM_DEBUG) && !ops->get_state)
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 "Please implement the .get_state() callback\n");
 
 	return true;
@@ -500,7 +500,7 @@ int __pwmchip_add(struct pwm_chip *chip, struct module *owner)
 	unsigned int i;
 	int ret;
 
-	if (!chip || !chip->dev || !chip->ops || !chip->npwm)
+	if (!chip || !pwmchip_parent(chip) || !chip->ops || !chip->npwm)
 		return -EINVAL;
 
 	if (!pwm_ops_check(chip))
@@ -594,15 +594,15 @@ static struct device_link *pwm_device_link_add(struct device *dev,
 		 * impact the PM sequence ordering: the PWM supplier may get
 		 * suspended before the consumer.
 		 */
-		dev_warn(pwm->chip->dev,
+		dev_warn(pwmchip_parent(pwm->chip),
 			 "No consumer device specified to create a link to\n");
 		return NULL;
 	}
 
-	dl = device_link_add(dev, pwm->chip->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
+	dl = device_link_add(dev, pwmchip_parent(pwm->chip), DL_FLAG_AUTOREMOVE_CONSUMER);
 	if (!dl) {
 		dev_err(dev, "failed to create device link to %s\n",
-			dev_name(pwm->chip->dev));
+			dev_name(pwmchip_parent(pwm->chip)));
 		return ERR_PTR(-EINVAL);
 	}
 
@@ -617,7 +617,7 @@ static struct pwm_chip *fwnode_to_pwmchip(struct fwnode_handle *fwnode)
 	mutex_lock(&pwm_lock);
 
 	idr_for_each_entry_ul(&pwm_chips, chip, tmp, id)
-		if (chip->dev && device_match_fwnode(chip->dev, fwnode)) {
+		if (pwmchip_parent(chip) && device_match_fwnode(pwmchip_parent(chip), fwnode)) {
 			mutex_unlock(&pwm_lock);
 			return chip;
 		}
@@ -1085,8 +1085,8 @@ static int pwm_seq_show(struct seq_file *s, void *v)
 
 	seq_printf(s, "%s%d: %s/%s, %d PWM device%s\n",
 		   (char *)s->private, chip->id,
-		   chip->dev->bus ? chip->dev->bus->name : "no-bus",
-		   dev_name(chip->dev), chip->npwm,
+		   pwmchip_parent(chip)->bus ? pwmchip_parent(chip)->bus->name : "no-bus",
+		   dev_name(pwmchip_parent(chip)), chip->npwm,
 		   (chip->npwm != 1) ? "s" : "");
 
 	pwm_dbg_show(chip, s);
diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 1698609d91c8..3f434a771fb5 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -509,10 +509,10 @@ void pwmchip_sysfs_export(struct pwm_chip *chip)
 	 * If device_create() fails the pwm_chip is still usable by
 	 * the kernel it's just not exported.
 	 */
-	parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip,
+	parent = device_create(&pwm_class, pwmchip_parent(chip), MKDEV(0, 0), chip,
 			       "pwmchip%d", chip->id);
 	if (IS_ERR(parent)) {
-		dev_warn(chip->dev,
+		dev_warn(pwmchip_parent(chip),
 			 "device_create failed for pwm_chip sysfs export\n");
 	}
 }
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 8ffe9ae7a23a..07af6910bdce 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(const 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 v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
  2024-02-14  9:30 ` [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Uwe Kleine-König
@ 2024-02-14  9:30 ` Uwe Kleine-König
  2024-02-14 12:49   ` Andy Shevchenko
  2024-02-14  9:31 ` [PATCH v6 070/164] pwm: meson: Change prototype of a few helpers to prepare further changes Uwe Kleine-König
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-14  9:30 UTC (permalink / raw)
  To: Jonathan Corbet, Jonathan Cameron, James Clark, Andy Shevchenko,
	Mark Brown, linux-pwm, Hector Martin, Sven Peter, Claudiu Beznea,
	Nicolas Ferre, Alexandre Belloni, Florian Fainelli, Ray Jui,
	Scott Branden, Alexander Shiyan, Benson Leung, Shawn Guo,
	Sascha Hauer, Paul Cercueil, Vladimir Zapolskiy, Mika Westerberg,
	Andy Shevchenko, Linus Walleij, 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, Bartosz Golaszewski, Pavel Machek,
	Lee Jones, Anjelique Melendez, Bjorn Andersson, Kees Cook,
	Rob Herring
  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, linux-gpio, 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-leds

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 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              | 11 ++--
 drivers/pwm/core.c                            | 58 +++++++++++++++++++
 include/linux/pwm.h                           | 22 +++++++
 4 files changed, 87 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..b41b1c56477f 100644
--- a/Documentation/driver-api/pwm.rst
+++ b/Documentation/driver-api/pwm.rst
@@ -143,11 +143,12 @@ 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 pwmchip_alloc(), then
+registered using pwmchip_add() and removed again with pwmchip_remove(). To undo
+pwmchip_alloc() use pwmchip_put(). 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 830a697826af..9fc6f4fa71d6 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -454,6 +454,64 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
 }
 EXPORT_SYMBOL_GPL(of_pwm_single_xlate);
 
+#define PWMCHIP_ALIGN ARCH_DMA_MINALIGN
+
+static void *pwmchip_priv(struct pwm_chip *chip)
+{
+	return (void *)chip + ALIGN(sizeof(*chip), PWMCHIP_ALIGN);
+}
+
+/* This is the counterpart to pwmchip_alloc */
+void pwmchip_put(struct pwm_chip *chip)
+{
+	kfree(chip);
+}
+EXPORT_SYMBOL_GPL(pwmchip_put);
+
+struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv)
+{
+	struct pwm_chip *chip;
+	size_t alloc_size;
+
+	alloc_size = size_add(ALIGN(sizeof(*chip), PWMCHIP_ALIGN), sizeof_priv);
+
+	chip = kzalloc(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(pwmchip_alloc);
+
+static void devm_pwmchip_put(void *data)
+{
+	struct pwm_chip *chip = data;
+
+	pwmchip_put(chip);
+}
+
+struct pwm_chip *devm_pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv)
+{
+	struct pwm_chip *chip;
+	int ret;
+
+	chip = pwmchip_alloc(parent, npwm, sizeof_priv);
+	if (IS_ERR(chip))
+		return chip;
+
+	ret = devm_add_action_or_reset(parent, devm_pwmchip_put, chip);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return chip;
+}
+EXPORT_SYMBOL_GPL(devm_pwmchip_alloc);
+
 static void of_pwmchip_add(struct pwm_chip *chip)
 {
 	if (!pwmchip_parent(chip) || !pwmchip_parent(chip)->of_node)
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index 29a7d9140f77..4a6568dfdf3f 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -403,6 +403,10 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm)
 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
 		unsigned long timeout);
 
+void pwmchip_put(struct pwm_chip *chip);
+struct pwm_chip *pwmchip_alloc(struct device *parent, unsigned int npwm, size_t sizeof_priv);
+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);
@@ -475,6 +479,24 @@ static inline int pwm_capture(struct pwm_device *pwm,
 	return -EINVAL;
 }
 
+static inline void pwmchip_put(struct pwm_chip *chip)
+{
+}
+
+static inline struct pwm_chip *pwmchip_alloc(struct device *parent,
+					     unsigned int npwm,
+					     size_t sizeof_priv)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+static inline struct pwm_chip *devm_pwmchip_alloc(struct device *parent,
+						  unsigned int npwm,
+						  size_t sizeof_priv)
+{
+	return pwmchip_alloc(parent, npwm, sizeof_priv);
+}
+
 static inline int pwmchip_add(struct pwm_chip *chip)
 {
 	return -EINVAL;
-- 
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 v6 070/164] pwm: meson: Change prototype of a few helpers to prepare further changes
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
  2024-02-14  9:30 ` [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Uwe Kleine-König
  2024-02-14  9:30 ` [PATCH v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it Uwe Kleine-König
@ 2024-02-14  9:31 ` Uwe Kleine-König
  2024-02-14  9:31 ` [PATCH v6 071/164] pwm: meson: Make use of pwmchip_parent() accessor Uwe Kleine-König
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-14  9:31 UTC (permalink / raw)
  To: Neil Armstrong, Kevin Hilman, linux-pwm
  Cc: Jerome Brunet, Martin Blumenstingl, linux-arm-kernel,
	linux-amlogic, kernel

This prepares the driver for further changes that will make it harder to
determine the pwm_chip from a given meson_pwm. To just not have to do
that, rework meson_pwm_calc(), meson_pwm_enable(), meson_pwm_disable()
and meson_pwm_init_channels() to take a pwm_chip.

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..7ce41811537d 100644
--- a/drivers/pwm/pwm-meson.c
+++ b/drivers/pwm/pwm-meson.c
@@ -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(chip->dev, "invalid source clock frequency\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq);
+	dev_dbg(chip->dev, "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(chip->dev, "unable to get period cnt\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(meson->chip.dev, "period=%llu cnt=%u\n", period, cnt);
+	dev_dbg(chip->dev, "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(chip->dev, "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(chip->dev, "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 = chip->dev;
 	unsigned int i;
 	char name[255];
 	int err;
@@ -445,7 +449,7 @@ static int meson_pwm_init_channels(struct meson_pwm *meson)
 		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 = {};
@@ -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 v6 071/164] pwm: meson: Make use of pwmchip_parent() accessor
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (2 preceding siblings ...)
  2024-02-14  9:31 ` [PATCH v6 070/164] pwm: meson: Change prototype of a few helpers to prepare further changes Uwe Kleine-König
@ 2024-02-14  9:31 ` Uwe Kleine-König
  2024-02-14  9:31 ` [PATCH v6 072/164] pwm: meson: Make use of devm_pwmchip_alloc() function Uwe Kleine-König
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-14  9:31 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 accessor
function provided for exactly this purpose.

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

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 7ce41811537d..8f67d6ba443d 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);
@@ -170,19 +170,19 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
 
 	fin_freq = clk_round_rate(channel->clk, freq);
 	if (fin_freq == 0) {
-		dev_err(chip->dev, "invalid source clock frequency\n");
+		dev_err(pwmchip_parent(chip), "invalid source clock frequency\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(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(chip->dev, "unable to get period cnt\n");
+		dev_err(pwmchip_parent(chip), "unable to get period cnt\n");
 		return -EINVAL;
 	}
 
-	dev_dbg(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;
@@ -193,7 +193,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
 	} else {
 		duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC);
 
-		dev_dbg(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;
@@ -217,7 +217,7 @@ static void meson_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 
 	err = clk_set_rate(channel->clk, channel->rate);
 	if (err)
-		dev_err(chip->dev, "setting clock rate failed\n");
+		dev_err(pwmchip_parent(chip), "setting clock rate failed\n");
 
 	spin_lock_irqsave(&meson->lock, flags);
 
@@ -439,7 +439,7 @@ 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 = chip->dev;
+	struct device *dev = pwmchip_parent(chip);
 	unsigned int i;
 	char name[255];
 	int 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 v6 072/164] pwm: meson: Make use of devm_pwmchip_alloc() function
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (3 preceding siblings ...)
  2024-02-14  9:31 ` [PATCH v6 071/164] pwm: meson: Make use of pwmchip_parent() accessor Uwe Kleine-König
@ 2024-02-14  9:31 ` Uwe Kleine-König
  2024-02-15 11:46 ` [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-14  9:31 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 | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c
index 8f67d6ba443d..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)
@@ -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 v6 001/164] pwm: Provide an inline function to get the parent device of a given chip
  2024-02-14  9:30 ` [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Uwe Kleine-König
@ 2024-02-14 10:39   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 13+ messages in thread
From: Greg Kroah-Hartman @ 2024-02-14 10:39 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-pwm, Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	Florian Fainelli, Ray Jui, Scott Branden, Benson Leung,
	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, Johan Hovold, Alex Elder, 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, greybus-dev,
	linux-staging

On Wed, Feb 14, 2024 at 10:30:48AM +0100, 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 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.
> 
> Make use of this function in the framework's core sources.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

_______________________________________________
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 v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it
  2024-02-14  9:30 ` [PATCH v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it Uwe Kleine-König
@ 2024-02-14 12:49   ` Andy Shevchenko
  2024-02-15 12:01     ` Uwe Kleine-König
  0 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2024-02-14 12:49 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jonathan Corbet, Jonathan Cameron, James Clark, Mark Brown,
	linux-pwm, Hector Martin, Sven Peter, Claudiu Beznea,
	Nicolas Ferre, Alexandre Belloni, Florian Fainelli, Ray Jui,
	Scott Branden, Alexander Shiyan, Benson Leung, Shawn Guo,
	Sascha Hauer, Paul Cercueil, Vladimir Zapolskiy, Mika Westerberg,
	Linus Walleij, 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, Bartosz Golaszewski, Pavel Machek,
	Lee Jones, Anjelique Melendez, Bjorn Andersson, Kees Cook,
	Rob Herring, 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, linux-gpio, 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-leds

On Wed, Feb 14, 2024 at 10:30:50AM +0100, 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 pwmchip_alloc().

...

> +#define PWMCHIP_ALIGN ARCH_DMA_MINALIGN
> +
> +static void *pwmchip_priv(struct pwm_chip *chip)
> +{
> +	return (void *)chip + ALIGN(sizeof(*chip), PWMCHIP_ALIGN);
> +}

Why not use dma_get_cache_alignment() ?

...

> +/* This is the counterpart to pwmchip_alloc */

pwmchip_alloc()

...

> +EXPORT_SYMBOL_GPL(pwmchip_put);

> +EXPORT_SYMBOL_GPL(pwmchip_alloc);

> +EXPORT_SYMBOL_GPL(devm_pwmchip_alloc);

Are these exported via namespace? If no, can they be from day 1?

...

> +static inline void pwmchip_put(struct pwm_chip *chip)
> +{
> +}

Can be one line, but it's up to the present style in this header.

-- 
With Best Regards,
Andy Shevchenko



_______________________________________________
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 v6 000/164] pwm: Improve lifetime tracking for pwm_chips
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (4 preceding siblings ...)
  2024-02-14  9:31 ` [PATCH v6 072/164] pwm: meson: Make use of devm_pwmchip_alloc() function Uwe Kleine-König
@ 2024-02-15 11:46 ` Uwe Kleine-König
  2024-03-25  1:54 ` patchwork-bot+chrome-platform
  2024-03-25  2:13 ` patchwork-bot+chrome-platform
  7 siblings, 0 replies; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-15 11:46 UTC (permalink / raw)
  To: linux-pwm, Jonathan Corbet, Jonathan Cameron, James Clark,
	Andy Shevchenko, Mark Brown, Hector Martin, Sven Peter,
	Claudiu Beznea, Nicolas Ferre, Alexandre Belloni,
	Florian Fainelli, Ray Jui, Scott Branden, Alexander Shiyan,
	Benson Leung, Philipp Zabel, Shawn Guo, Sascha Hauer,
	Paul Cercueil, Vladimir Zapolskiy, Mika Westerberg,
	Andy Shevchenko, Linus Walleij, 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, Bartosz Golaszewski, Andrzej Hajda,
	Robert Foss, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter, Pavel Machek, Lee Jones,
	Anjelique Melendez, Bjorn Andersson, Kees Cook, Rob Herring,
	Johan Hovold, Alex Elder, Greg Kroah-Hartman
  Cc: 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, Gustavo A. R. Silva, linux-mips, asahi, kernel,
	linux-hardening


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

Hello,

On Wed, Feb 14, 2024 at 10:30:47AM +0100, Uwe Kleine-König wrote:
> this is v6 of the series introducing better lifetime tracking for
> pwmchips that addresses (for now theoretic) lifetime issues of pwm
> chips. Addressing these is a necessary precondition to introduce chardev
> support for PWMs.
> 
> Locking got more complicated due to non-sleeping chips, so I dropped
> the character device patch because it got still more incomplete now.
> Also I'm not yet entirely sure about patches #162 and #163 and I expect
> them to change before they can go in. My plan for the next merge window
> is to get the patches in up to #160. After that the addition of chardev
> support (including correct locking) can continue without having to touch
> the lowlevel driver. So the idea of this series is to get the driver
> adaptions out of the way as this requires some cross-tree coordination.
> 
> The patches that touch files outside of drivers/pwm include:
> 
>  - gpio: mvebu: Make use of devm_pwmchip_alloc() function
>    It already has an Ack by Linus Walleij.
> 
>  - drm/bridge: ti-sn65dsi86: Make use of pwmchip_parent() accessor
>  - drm/bridge: ti-sn65dsi86: Make use of devm_pwmchip_alloc() function
>    The 2nd already has an Ack by Douglas Anderson which I tend to assume
>    good enough to merge this via my pwm tree, too. An Ack for the first
>    patch would be nice.
> 
>  - leds: qcom-lpg: Make use of devm_pwmchip_alloc() function
>    Already has an Ack by Lee Jones.
> 
>  - staging: greybus: pwm: Change prototype of helpers to prepare further changes
>  - staging: greybus: pwm: Make use of pwmchip_parent() accessor
>  - staging: greybus: pwm: Rely on pwm framework to pass a valid hwpwm
>  - staging: greybus: pwm: Drop unused gb_connection_set_data()
>  - staging: greybus: pwm: Rework how the number of PWM lines is determined
>  - staging: greybus: pwm: Make use of devm_pwmchip_alloc() function
>    The greybus patches already got an Ack by Greg Kroah-Hartman in an
>    earlier series, but I dropped it as the patches changed considerably.

After getting the needed acks, I pushed out this series in

https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next

up to patch #161.

(But don't let you stop looking at the changes, reviews are still
welcome.)

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 v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it
  2024-02-14 12:49   ` Andy Shevchenko
@ 2024-02-15 12:01     ` Uwe Kleine-König
  2024-02-15 13:51       ` Nuno Sá
  0 siblings, 1 reply; 13+ messages in thread
From: Uwe Kleine-König @ 2024-02-15 12:01 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Alexandre Belloni, Michael Walle, Heiko Stuebner, linux-doc,
	Linus Walleij, Paul Walmsley, Alexandre Torgue, Nicolas Ferre,
	Paul Cercueil, linux-tegra, Conor Dooley, Thierry Reding,
	James Clark, Pavel Machek, Broadcom internal kernel review list,
	Guenter Roeck, chrome-platform, Nobuhiro Iwamatsu, Fabio Estevam,
	linux-riscv, Alyssa Rosenzweig, Jerome Brunet, Rob Herring,
	Samuel Holland, linux-samsung-soc, Bjorn Andersson,
	Florian Fainelli, Jonathan Corbet, Sean Anderson, Benson Leung,
	Bartosz Golaszewski, Lee Jones, Jernej Skrabec, Jonathan Hunter,
	Hammer Hsieh, linux-rockchip, Chen-Yu Tsai, Michal Simek,
	NXP Linux Team, linux-leds, Ilpo Järvinen, Alim Akhtar,
	linux-mips, linux-sunxi, platform-driver-x86, linux-pwm,
	Kees Cook, Sven Peter, Martin Blumenstingl, Ray Jui,
	Sascha Hauer, Jonathan Neuschäfer, Vladimir Zapolskiy,
	Hans de Goede, Mark Brown, linux-mediatek, linux-rpi-kernel,
	Baolin Wang, Jonathan Cameron, Matthias Brugger, linux-amlogic,
	Orson Zhai, Mika Westerberg, kernel, linux-arm-kernel,
	AngeloGioacchino Del Regno, Neil Armstrong, Alexander Shiyan,
	Scott Branden, linux-gpio, Daire McNamara, Chunyan Zhang,
	Hector Martin, linux-stm32, Claudiu Beznea, Krzysztof Kozlowski,
	Fabrice Gasnier, Palmer Dabbelt, asahi, Maxime Coquelin,
	Kevin Hilman, Shawn Guo, Anjelique Melendez


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

On Wed, Feb 14, 2024 at 02:49:26PM +0200, Andy Shevchenko wrote:
> On Wed, Feb 14, 2024 at 10:30:50AM +0100, 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 pwmchip_alloc().
> 
> ...
> 
> > +#define PWMCHIP_ALIGN ARCH_DMA_MINALIGN
> > +
> > +static void *pwmchip_priv(struct pwm_chip *chip)
> > +{
> > +	return (void *)chip + ALIGN(sizeof(*chip), PWMCHIP_ALIGN);
> > +}
> 
> Why not use dma_get_cache_alignment() ?

Hmm, that function returns 1 if ARCH_HAS_DMA_MINALIGN isn't defined. The
idea of using ARCH_DMA_MINALIGN was to ensure that the priv data has the
same minimal alignment as kmalloc(). Took my inspriration from
https://lore.kernel.org/r/20240209-counter-align-fix-v2-1-5777ea0a2722@analog.com
. The implementation of dma_get_cache_alignment suggests that not all
archs provide ARCH_DMA_MINALIGN? Also there is ARCH_KMALLOC_MINALIGN.
Hmm, don't know yet what to do here.

> > +/* This is the counterpart to pwmchip_alloc */
> 
> pwmchip_alloc()

Ack.
 
> > +EXPORT_SYMBOL_GPL(pwmchip_put);
> 
> > +EXPORT_SYMBOL_GPL(pwmchip_alloc);
> 
> > +EXPORT_SYMBOL_GPL(devm_pwmchip_alloc);
> 
> Are these exported via namespace? If no, can they be from day 1?

I added that to my todo list for all pwm functions. Will address that
separately.

Thanks for your feedback
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 v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it
  2024-02-15 12:01     ` Uwe Kleine-König
@ 2024-02-15 13:51       ` Nuno Sá
  0 siblings, 0 replies; 13+ messages in thread
From: Nuno Sá @ 2024-02-15 13:51 UTC (permalink / raw)
  To: Uwe Kleine-König, Andy Shevchenko
  Cc: Alexandre Belloni, Michael Walle, Heiko Stuebner, linux-doc,
	Linus Walleij, Paul Walmsley, Alexandre Torgue, Nicolas Ferre,
	Paul Cercueil, linux-tegra, Conor Dooley, Thierry Reding,
	James Clark, Pavel Machek, Broadcom internal kernel review list,
	Guenter Roeck, chrome-platform, Nobuhiro Iwamatsu, Fabio Estevam,
	linux-riscv, Alyssa Rosenzweig, Jerome Brunet, Rob Herring,
	Samuel Holland, linux-samsung-soc, Bjorn Andersson,
	Florian Fainelli, Jonathan Corbet, Sean Anderson, Benson Leung,
	Bartosz Golaszewski, Lee Jones, Jernej Skrabec, Jonathan Hunter,
	Hammer Hsieh, linux-rockchip, Chen-Yu Tsai, Michal Simek,
	NXP Linux Team, linux-leds, Ilpo Järvinen, Alim Akhtar,
	linux-mips, linux-sunxi, platform-driver-x86, linux-pwm,
	Kees Cook, Sven Peter, Martin Blumenstingl, Ray Jui,
	Sascha Hauer, Jonathan Neuschäfer, Vladimir Zapolskiy,
	Hans de Goede, Mark Brown, linux-mediatek, linux-rpi-kernel,
	Baolin Wang, Jonathan Cameron, Matthias Brugger, linux-amlogic,
	Orson Zhai, Mika Westerberg, kernel, linux-arm-kernel,
	AngeloGioacchino Del Regno, Neil Armstrong, Alexander Shiyan,
	Scott Branden, linux-gpio, Daire McNamara, Chunyan Zhang,
	Hector Martin, linux-stm32, Claudiu Beznea, Krzysztof Kozlowski,
	Fabrice Gasnier, Palmer Dabbelt, asahi, Maxime Coquelin,
	Kevin Hilman, Shawn Guo, Anjelique Melendez

On Thu, 2024-02-15 at 13:01 +0100, Uwe Kleine-König wrote:
> On Wed, Feb 14, 2024 at 02:49:26PM +0200, Andy Shevchenko wrote:
> > On Wed, Feb 14, 2024 at 10:30:50AM +0100, 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 pwmchip_alloc().
> > 
> > ...
> > 
> > > +#define PWMCHIP_ALIGN ARCH_DMA_MINALIGN
> > > +
> > > +static void *pwmchip_priv(struct pwm_chip *chip)
> > > +{
> > > +	return (void *)chip + ALIGN(sizeof(*chip), PWMCHIP_ALIGN);
> > > +}
> > 
> > Why not use dma_get_cache_alignment() ?
> 
> Hmm, that function returns 1 if ARCH_HAS_DMA_MINALIGN isn't defined. The
> idea of using ARCH_DMA_MINALIGN was to ensure that the priv data has the
> same minimal alignment as kmalloc(). Took my inspriration from
> https://lore.kernel.org/r/20240209-counter-align-fix-v2-1-5777ea0a2722@analog.com
> . The implementation of dma_get_cache_alignment suggests that not all
> archs provide ARCH_DMA_MINALIGN? Also there is ARCH_KMALLOC_MINALIGN.
> Hmm, don't know yet what to do here.

Here it goes my 2 cents... AFAIK, ARCH_DMA_MINALIGN gives you the same alignment
guarantees than devm_kmalloc() for instance. In some archs it will effectively be the
same as ARCH_KMALLOC_MINALIGN. Now, I think it only matters if the owners of private
data intend to have a DMA safe buffer in their structs. If that is the case, we need
to ensure a proper alignment for that structure. In IIO for example, the construct is
like this:

https://elixir.bootlin.com/linux/latest/source/drivers/iio/dac/ltc2688.c#L96

The buffers should come last in the struct so they are alone in the line. In IIO,
Jonathan has a strict policy for this. Like, even if you just want to transfer 2/4
bytes via spi, we need to make the buffer safe (apparently there are some controllers
only doing DMA - even for small transfers).

I would say that if unsure, go with ARCH_DMA_MINALIGN. You just might waste some
space in some archs. OTOH, if you think DMA is not really a thing for pwm chips, you
might go ARCH_KMALLOC_MINALIGN. And since you already have your own PWMCHIP_ALIGN, it
should be easy to change the requirements down the road (if needed).

That said, I'm not familiar with dma_get_cache_alignment().

- Nuno Sá


_______________________________________________
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 v6 000/164] pwm: Improve lifetime tracking for pwm_chips
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (5 preceding siblings ...)
  2024-02-15 11:46 ` [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
@ 2024-03-25  1:54 ` patchwork-bot+chrome-platform
  2024-03-25  2:13 ` patchwork-bot+chrome-platform
  7 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-03-25  1:54 UTC (permalink / raw)
  To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig_=3Cu=2Ekleine-koenig=40pengutronix=2Ede=3E?=
  Cc: linux-pwm, corbet, Jonathan.Cameron, james.clark,
	andriy.shevchenko, broonie, marcan, sven, claudiu.beznea,
	nicolas.ferre, alexandre.belloni, florian.fainelli, rjui,
	sbranden, shc_work, bleung, p.zabel, shawnguo, s.hauer, paul, vz,
	mika.westerberg, andy, linus.walleij, hdegoede, ilpo.jarvinen,
	matthias.bgg, angelogioacchino.delregno, neil.armstrong, khilman,
	conor.dooley, daire.mcnamara, j.neuschaefer, heiko,
	krzysztof.kozlowski, palmer, paul.walmsley, mwalle, orsonzhai,
	baolin.wang, zhang.lyra, fabrice.gasnier, mcoquelin.stm32,
	alexandre.torgue, wens, jernej.skrabec, samuel, hammerh0314,
	thierry.reding, jonathanh, nobuhiro1.iwamatsu, sean.anderson,
	michal.simek, brgl, andrzej.hajda, rfoss, maarten.lankhorst,
	mripard, tzimmermann, airlied, daniel, pavel, lee, quic_amelende,
	quic_bjorande, keescook, robh, johan, elder, gregkh, kernel,
	linux-doc, alyssa, asahi, linux-arm-kernel,
	bcm-kernel-feedback-list, linux-rpi-kernel, groeck,
	chrome-platform, festevam, linux-imx, linux-mips, linux-gpio,
	platform-driver-x86, linux-mediatek, jbrunet,
	martin.blumenstingl, linux-amlogic, linux-riscv, linux-rockchip,
	alim.akhtar, linux-samsung-soc, linux-stm32, linux-sunxi,
	linux-tegra, dianders, Laurent.pinchart, jonas, dri-devel,
	linux-leds, greybus-dev, linux-staging, gustavoars,
	linux-hardening

Hello:

This series was applied to chrome-platform/linux.git (for-kernelci)
by Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:

On Wed, 14 Feb 2024 10:30:47 +0100 you wrote:
> Hello,
> 
> this is v6 of the series introducing better lifetime tracking for
> pwmchips that addresses (for now theoretic) lifetime issues of pwm
> chips. Addressing these is a necessary precondition to introduce chardev
> support for PWMs.
> 
> [...]

Here is the summary with links:
  - [v6,001/164] pwm: Provide an inline function to get the parent device of a given chip
    https://git.kernel.org/chrome-platform/c/4e59267c7a20
  - [v6,003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it
    https://git.kernel.org/chrome-platform/c/024913dbf99f
  - [v6,029/164] pwm: cros-ec: Change prototype of helpers to prepare further changes
    https://git.kernel.org/chrome-platform/c/7256c2e79b8e
  - [v6,030/164] pwm: cros-ec: Make use of pwmchip_parent() accessor
    https://git.kernel.org/chrome-platform/c/19a568a8d3c4
  - [v6,031/164] pwm: cros-ec: Make use of devm_pwmchip_alloc() function
    https://git.kernel.org/chrome-platform/c/452be9421eda

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
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 v6 000/164] pwm: Improve lifetime tracking for pwm_chips
  2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
                   ` (6 preceding siblings ...)
  2024-03-25  1:54 ` patchwork-bot+chrome-platform
@ 2024-03-25  2:13 ` patchwork-bot+chrome-platform
  7 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-03-25  2:13 UTC (permalink / raw)
  To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig_=3Cu=2Ekleine-koenig=40pengutronix=2Ede=3E?=
  Cc: linux-pwm, corbet, Jonathan.Cameron, james.clark,
	andriy.shevchenko, broonie, marcan, sven, claudiu.beznea,
	nicolas.ferre, alexandre.belloni, florian.fainelli, rjui,
	sbranden, shc_work, bleung, p.zabel, shawnguo, s.hauer, paul, vz,
	mika.westerberg, andy, linus.walleij, hdegoede, ilpo.jarvinen,
	matthias.bgg, angelogioacchino.delregno, neil.armstrong, khilman,
	conor.dooley, daire.mcnamara, j.neuschaefer, heiko,
	krzysztof.kozlowski, palmer, paul.walmsley, mwalle, orsonzhai,
	baolin.wang, zhang.lyra, fabrice.gasnier, mcoquelin.stm32,
	alexandre.torgue, wens, jernej.skrabec, samuel, hammerh0314,
	thierry.reding, jonathanh, nobuhiro1.iwamatsu, sean.anderson,
	michal.simek, brgl, andrzej.hajda, rfoss, maarten.lankhorst,
	mripard, tzimmermann, airlied, daniel, pavel, lee, quic_amelende,
	quic_bjorande, keescook, robh, johan, elder, gregkh, kernel,
	linux-doc, alyssa, asahi, linux-arm-kernel,
	bcm-kernel-feedback-list, linux-rpi-kernel, groeck,
	chrome-platform, festevam, linux-imx, linux-mips, linux-gpio,
	platform-driver-x86, linux-mediatek, jbrunet,
	martin.blumenstingl, linux-amlogic, linux-riscv, linux-rockchip,
	alim.akhtar, linux-samsung-soc, linux-stm32, linux-sunxi,
	linux-tegra, dianders, Laurent.pinchart, jonas, dri-devel,
	linux-leds, greybus-dev, linux-staging, gustavoars,
	linux-hardening

Hello:

This series was applied to chrome-platform/linux.git (for-next)
by Uwe Kleine-König <u.kleine-koenig@pengutronix.de>:

On Wed, 14 Feb 2024 10:30:47 +0100 you wrote:
> Hello,
> 
> this is v6 of the series introducing better lifetime tracking for
> pwmchips that addresses (for now theoretic) lifetime issues of pwm
> chips. Addressing these is a necessary precondition to introduce chardev
> support for PWMs.
> 
> [...]

Here is the summary with links:
  - [v6,001/164] pwm: Provide an inline function to get the parent device of a given chip
    https://git.kernel.org/chrome-platform/c/4e59267c7a20
  - [v6,003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it
    https://git.kernel.org/chrome-platform/c/024913dbf99f
  - [v6,029/164] pwm: cros-ec: Change prototype of helpers to prepare further changes
    https://git.kernel.org/chrome-platform/c/7256c2e79b8e
  - [v6,030/164] pwm: cros-ec: Make use of pwmchip_parent() accessor
    https://git.kernel.org/chrome-platform/c/19a568a8d3c4
  - [v6,031/164] pwm: cros-ec: Make use of devm_pwmchip_alloc() function
    https://git.kernel.org/chrome-platform/c/452be9421eda

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
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-04-29 15:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14  9:30 [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
2024-02-14  9:30 ` [PATCH v6 001/164] pwm: Provide an inline function to get the parent device of a given chip Uwe Kleine-König
2024-02-14 10:39   ` Greg Kroah-Hartman
2024-02-14  9:30 ` [PATCH v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it Uwe Kleine-König
2024-02-14 12:49   ` Andy Shevchenko
2024-02-15 12:01     ` Uwe Kleine-König
2024-02-15 13:51       ` Nuno Sá
2024-02-14  9:31 ` [PATCH v6 070/164] pwm: meson: Change prototype of a few helpers to prepare further changes Uwe Kleine-König
2024-02-14  9:31 ` [PATCH v6 071/164] pwm: meson: Make use of pwmchip_parent() accessor Uwe Kleine-König
2024-02-14  9:31 ` [PATCH v6 072/164] pwm: meson: Make use of devm_pwmchip_alloc() function Uwe Kleine-König
2024-02-15 11:46 ` [PATCH v6 000/164] pwm: Improve lifetime tracking for pwm_chips Uwe Kleine-König
2024-03-25  1:54 ` patchwork-bot+chrome-platform
2024-03-25  2:13 ` patchwork-bot+chrome-platform

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 NNTP newsgroup(s).