All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] pwm: Add support for character devices
@ 2024-03-17 10:40 Uwe Kleine-König
  2024-03-17 10:40 ` [PATCH 1/8] pwm: Ensure that pwm_chips are allocated using pwmchip_alloc() Uwe Kleine-König
                   ` (8 more replies)
  0 siblings, 9 replies; 24+ messages in thread
From: Uwe Kleine-König @ 2024-03-17 10:40 UTC (permalink / raw)
  To: linux-pwm; +Cc: kernel, Kees Cook, Gustavo A. R. Silva, linux-hardening

Hello,

After the necessary changes to the lowlevel drivers got in for v6.9-rc1
here come some changes to the core to implement /dev/pwmchipX character
devices.

In my tests on an ARM STM32MP1 programming a PWM using the character
device is ~4 times faster than just changing duty_cycle via the sysfs
API. It also has the advantage that (similar to pwm_apply_*) the target
state is provided to the kernel with a single call, instead of having to
program the individual settings one after another via sysfs (in the
right order to not cross states not supported by the driver). 

Note the representation of a PWM waveform is different here compared to
the in-kernel representation. A PWM waveform is represented using:

	period
	duty_cycle
	duty_offset

A disabled PWM is represented by period = 0. For an inversed wave use:

	duty_offset = duty_cycle
	duty_cycle = period - duty_cycle;

. However there are some difficulties yet that make it hard to provide a
consistent API to userspace and so for now duty_offset isn't (fully)
supported yet. That needs some more consideration and can be added
later.

A userspace lib together with some simple test programs making use of
this new API can be found at

	https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/libpwm.git

.

The start of the series is some cleanup and preparation. The lifetime
and locking patches are needed to not crash the kernel when a character
device is open while a lowlevel driver goes away.

I look forward to feedback,
Uwe

Uwe Kleine-König (8):
  pwm: Ensure that pwm_chips are allocated using pwmchip_alloc()
  pwm: Give some sysfs related variables and functions better names
  pwm: Move contents of sysfs.c into core.c
  pwm: Ensure a struct pwm has the same lifetime as its pwm_chip
  pwm: Add a struct device to struct pwm_chip
  pwm: Make pwmchip_[sg]et_drvdata() a wrapper around dev_set_drvdata()
  pwm: Add more locking
  pwm: Add support for pwmchip devices for faster and easier userspace
    access

 drivers/pwm/Kconfig      |   4 -
 drivers/pwm/Makefile     |   1 -
 drivers/pwm/core.c       | 988 +++++++++++++++++++++++++++++++++++++--
 drivers/pwm/sysfs.c      | 545 ---------------------
 include/linux/pwm.h      |  51 +-
 include/uapi/linux/pwm.h |  23 +
 6 files changed, 993 insertions(+), 619 deletions(-)
 delete mode 100644 drivers/pwm/sysfs.c
 create mode 100644 include/uapi/linux/pwm.h

base-commit: dd6c6d57ab61d496f6ff7d6ca38611062af142a1
-- 
2.43.0


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

end of thread, other threads:[~2024-05-07  6:12 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-17 10:40 [PATCH 0/8] pwm: Add support for character devices Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 1/8] pwm: Ensure that pwm_chips are allocated using pwmchip_alloc() Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 2/8] pwm: Give some sysfs related variables and functions better names Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 3/8] pwm: Move contents of sysfs.c into core.c Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 4/8] pwm: Ensure a struct pwm has the same lifetime as its pwm_chip Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 5/8] pwm: Add a struct device to struct pwm_chip Uwe Kleine-König
2024-03-28 18:44   ` David Lechner
2024-03-29 10:19     ` Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 6/8] pwm: Make pwmchip_[sg]et_drvdata() a wrapper around dev_set_drvdata() Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 7/8] pwm: Add more locking Uwe Kleine-König
2024-03-18  7:28   ` Thorsten Scherer
     [not found]   ` <CGME20240404120932eucas1p1b3c1e07bf6f41f6330725148b0268b13@eucas1p1.samsung.com>
2024-04-04 12:09     ` Marek Szyprowski
2024-04-04 12:09       ` Marek Szyprowski
2024-04-04 15:33       ` Uwe Kleine-König
2024-04-04 15:33         ` Uwe Kleine-König
2024-04-04 15:33         ` Uwe Kleine-König
2024-03-17 10:40 ` [PATCH 8/8] pwm: Add support for pwmchip devices for faster and easier userspace access Uwe Kleine-König
2024-04-08 15:42   ` John Ernberg
2024-04-09  7:49     ` Uwe Kleine-König
2024-04-15 11:27       ` John Ernberg
2024-05-07  1:11   ` Kent Gibson
2024-05-07  6:12     ` Uwe Kleine-König
2024-04-13  9:22 ` [PATCH 0/8] pwm: Add support for character devices Uwe Kleine-König
2024-04-22 18:59   ` David Lechner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.