162a114da3b31f18f63ba23f5de53730702f0c10
[openwrt/staging/wigyori.git] /
1 From 8c2925d1981738ba8d8db4cbbb1052dfa2d42766 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/773] pwm: Send a uevent on the pwmchip device upon channel
5 sysfs (un)export
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 commit 552c02e3e7cfe2744b59de285aaea70021ae95c9 upstream.
11
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:
15
16 SUBSYSTEM=="pwm*", PROGRAM="/bin/sh -c '\
17 chown -R root:gpio /sys/class/pwm && chmod -R 770 /sys/class/pwm;\
18 chown -R root:gpio
19 /sys/devices/platform/soc/*.pwm/pwm/pwmchip* && chmod -R 770
20 /sys/devices/platform/soc/*.pwm/pwm/pwmchip*\
21 '"
22
23 This is a replacement patch for commit 7e5d1fd75c3d ("pwm: Set class for
24 exported channels in sysfs"), see [1].
25
26 basic testing:
27 $ udevadm monitor --environment &
28 $ echo 0 > /sys/class/pwm/pwmchip0/export
29 KERNEL[197.321736] change /devices/.../pwm/pwmchip0 (pwm)
30 ACTION=change
31 DEVPATH=/devices/.../pwm/pwmchip0
32 EXPORT=pwm0
33 SEQNUM=2045
34 SUBSYSTEM=pwm
35
36 [1] https://lkml.org/lkml/2018/9/25/713
37
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>
42 ---
43 drivers/pwm/sysfs.c | 11 +++++++++++
44 1 file changed, 11 insertions(+)
45
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)
50 {
51 struct pwm_export *export;
52 + char *pwm_prop[2];
53 int ret;
54
55 if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags))
56 @@ -276,6 +277,10 @@ static int pwm_export_child(struct devic
57 export = NULL;
58 return ret;
59 }
60 + pwm_prop[0] = kasprintf(GFP_KERNEL, "EXPORT=pwm%u", pwm->hwpwm);
61 + pwm_prop[1] = NULL;
62 + kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop);
63 + kfree(pwm_prop[0]);
64
65 return 0;
66 }
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)
69 {
70 struct device *child;
71 + char *pwm_prop[2];
72
73 if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags))
74 return -ENODEV;
75 @@ -296,6 +302,11 @@ static int pwm_unexport_child(struct dev
76 if (!child)
77 return -ENODEV;
78
79 + pwm_prop[0] = kasprintf(GFP_KERNEL, "UNEXPORT=pwm%u", pwm->hwpwm);
80 + pwm_prop[1] = NULL;
81 + kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop);
82 + kfree(pwm_prop[0]);
83 +
84 /* for device_find_child() */
85 put_device(child);
86 device_unregister(child);