1 From 30759f3a1d9090c99769dc76964ea414b5129d85 Mon Sep 17 00:00:00 2001
2 From: Fabrice Gasnier <fabrice.gasnier@st.com>
3 Date: Mon, 1 Oct 2018 15:23:57 +0200
4 Subject: [PATCH 308/725] pwm: Send a uevent on the pwmchip device upon channel
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 commit 552c02e3e7cfe2744b59de285aaea70021ae95c9 upstream.
12 This patch sends a uevent (KOBJ_CHANGE) on the pwmchipN device,
13 everytime a pwmX channel has been exported/unexported via sysfs. This
14 allows udev to implement rules on such events, like:
16 SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\
17 chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\
19 /sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770
20 /sys/devices/platform/soc/*.pwm/pwm/pwmchip*\
23 This is a replacement patch for commit 7e5d1fd75c3d ("pwm: Set class for
24 exported channels in sysfs"), see [1].
27 $ udevadm monitor --environment &
28 $ echo 0 > /sys/class/pwm/pwmchip0/export
29 KERNEL[197.321736] change /devices/.../pwm/pwmchip0 (pwm)
31 DEVPATH=/devices/.../pwm/pwmchip0
36 [1] https://lkml.org/lkml/2018/9/25/713
38 Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
39 Tested-by: Gottfried Haider <gottfried.haider@gmail.com>
40 Tested-by: Michal Vokáč <michal.vokac@ysoft.com>
41 Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
43 drivers/pwm/sysfs.c | 11 +++++++++++
44 1 file changed, 11 insertions(+)
46 --- a/drivers/pwm/sysfs.c
47 +++ b/drivers/pwm/sysfs.c
48 @@ -249,6 +249,7 @@ static void pwm_export_release(struct de
49 static int pwm_export_child(struct device *parent, struct pwm_device *pwm)
51 struct pwm_export *export;
55 if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags))
56 @@ -276,6 +277,10 @@ static int pwm_export_child(struct devic
60 + pwm_prop[0] = kasprintf(GFP_KERNEL, "EXPORT=pwm%u", pwm->hwpwm);
62 + kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop);
67 @@ -288,6 +293,7 @@ static int pwm_unexport_match(struct dev
68 static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm)
73 if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags))
75 @@ -296,6 +302,11 @@ static int pwm_unexport_child(struct dev
79 + pwm_prop[0] = kasprintf(GFP_KERNEL, "UNEXPORT=pwm%u", pwm->hwpwm);
81 + kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop);
84 /* for device_find_child() */
86 device_unregister(child);