pwm: Send a uevent on the pwmchip device upon channel sysfs (un)export
authorFabrice Gasnier <fabrice.gasnier@st.com>
Mon, 1 Oct 2018 13:23:57 +0000 (15:23 +0200)
committerpopcornmix <popcornmix@gmail.com>
Mon, 13 May 2019 23:08:17 +0000 (00:08 +0100)
commiteafa122a48ddf892818a3666082afd716b1e5311
treefdbe6c34bd5fcfe87d51b7eb4c1e09119dac9fad
parente60f6ba54a0cb6ee18eeb9f0ff2f239625934863
pwm: Send a uevent on the pwmchip device upon channel sysfs (un)export

commit 552c02e3e7cfe2744b59de285aaea70021ae95c9 upstream.

This patch sends a uevent (KOBJ_CHANGE) on the pwmchipN device,
everytime a pwmX channel has been exported/unexported via sysfs. This
allows udev to implement rules on such events, like:

SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\
        chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\
        chown -R root:gpio
/sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770
/sys/devices/platform/soc/*.pwm/pwm/pwmchip*\
'"

This is a replacement patch for commit 7e5d1fd75c3d ("pwm: Set class for
exported channels in sysfs"), see [1].

basic testing:
$ udevadm monitor --environment &
$ echo 0 > /sys/class/pwm/pwmchip0/export
KERNEL[197.321736] change   /devices/.../pwm/pwmchip0 (pwm)
ACTION=change
DEVPATH=/devices/.../pwm/pwmchip0
EXPORT=pwm0
SEQNUM=2045
SUBSYSTEM=pwm

[1] https://lkml.org/lkml/2018/9/25/713

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Tested-by: Gottfried Haider <gottfried.haider@gmail.com>
Tested-by: Michal Vokáč <michal.vokac@ysoft.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/sysfs.c