diff options
| author | H Hartley Sweeten <hartleys@visionengravers.com> | 2013-06-11 13:38:59 -0400 |
|---|---|---|
| committer | Thierry Reding <thierry.reding@gmail.com> | 2013-06-21 05:32:51 -0400 |
| commit | 76abbdde2d95a3807d0dc6bf9f84d03d0dbd4f3d (patch) | |
| tree | 63a5476d6fbf80ec90b813461ec7ec67ff462684 /include/linux | |
| parent | 3dd0a909479c1d372341d749b4ff94cd638b57da (diff) | |
pwm: Add sysfs interface
Add a simple sysfs interface to the generic PWM framework.
/sys/class/pwm/
`-- pwmchipN/ for each PWM chip
|-- export (w/o) ask the kernel to export a PWM channel
|-- npwm (r/o) number of PWM channels in this PWM chip
|-- pwmX/ for each exported PWM channel
| |-- duty_cycle (r/w) duty cycle (in nanoseconds)
| |-- enable (r/w) enable/disable PWM
| |-- period (r/w) period (in nanoseconds)
| `-- polarity (r/w) polarity of PWM (normal/inversed)
`-- unexport (w/o) return a PWM channel to the kernel
Based on work by Lars Poeschel.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Lars Poeschel <poeschel@lemonage.de>
Cc: Ryan Mallon <rmallon@gmail.com>
Cc: Rob Landley <rob@landley.net>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/pwm.h | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/include/linux/pwm.h b/include/linux/pwm.h index a4df2042b79c..f0feafd184a0 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h | |||
| @@ -76,6 +76,7 @@ enum pwm_polarity { | |||
| 76 | enum { | 76 | enum { |
| 77 | PWMF_REQUESTED = 1 << 0, | 77 | PWMF_REQUESTED = 1 << 0, |
| 78 | PWMF_ENABLED = 1 << 1, | 78 | PWMF_ENABLED = 1 << 1, |
| 79 | PWMF_EXPORTED = 1 << 2, | ||
| 79 | }; | 80 | }; |
| 80 | 81 | ||
| 81 | struct pwm_device { | 82 | struct pwm_device { |
| @@ -86,7 +87,9 @@ struct pwm_device { | |||
| 86 | struct pwm_chip *chip; | 87 | struct pwm_chip *chip; |
| 87 | void *chip_data; | 88 | void *chip_data; |
| 88 | 89 | ||
| 89 | unsigned int period; /* in nanoseconds */ | 90 | unsigned int period; /* in nanoseconds */ |
| 91 | unsigned int duty_cycle; /* in nanoseconds */ | ||
| 92 | enum pwm_polarity polarity; | ||
| 90 | }; | 93 | }; |
| 91 | 94 | ||
| 92 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) | 95 | static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period) |
| @@ -100,6 +103,17 @@ static inline unsigned int pwm_get_period(struct pwm_device *pwm) | |||
| 100 | return pwm ? pwm->period : 0; | 103 | return pwm ? pwm->period : 0; |
| 101 | } | 104 | } |
| 102 | 105 | ||
| 106 | static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty) | ||
| 107 | { | ||
| 108 | if (pwm) | ||
| 109 | pwm->duty_cycle = duty; | ||
| 110 | } | ||
| 111 | |||
| 112 | static inline unsigned int pwm_get_duty_cycle(struct pwm_device *pwm) | ||
| 113 | { | ||
| 114 | return pwm ? pwm->duty_cycle : 0; | ||
| 115 | } | ||
| 116 | |||
| 103 | /* | 117 | /* |
| 104 | * pwm_set_polarity - configure the polarity of a PWM signal | 118 | * pwm_set_polarity - configure the polarity of a PWM signal |
| 105 | */ | 119 | */ |
| @@ -278,4 +292,17 @@ static inline void pwm_add_table(struct pwm_lookup *table, size_t num) | |||
| 278 | } | 292 | } |
| 279 | #endif | 293 | #endif |
| 280 | 294 | ||
| 295 | #ifdef CONFIG_PWM_SYSFS | ||
| 296 | void pwmchip_sysfs_export(struct pwm_chip *chip); | ||
| 297 | void pwmchip_sysfs_unexport(struct pwm_chip *chip); | ||
| 298 | #else | ||
| 299 | static inline void pwmchip_sysfs_export(struct pwm_chip *chip) | ||
| 300 | { | ||
| 301 | } | ||
| 302 | |||
| 303 | static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip) | ||
| 304 | { | ||
| 305 | } | ||
| 306 | #endif /* CONFIG_PWM_SYSFS */ | ||
| 307 | |||
| 281 | #endif /* __LINUX_PWM_H */ | 308 | #endif /* __LINUX_PWM_H */ |
