diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-04-14 21:17:40 +0200 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2016-05-17 14:48:03 +0200 |
commit | 15fa8a43c147213a9563903c87b29671035eb6e8 (patch) | |
tree | ececf11f09885f32d8b27334d180c8a080882000 /include | |
parent | 09a7e4a3d9fcb95ade2cb02167e85fbeb8315ce0 (diff) |
pwm: Add hardware readout infrastructure
Add a ->get_state() function to the pwm_ops struct to let PWM drivers
initialize the PWM state attached to a PWM device.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/pwm.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 150563a806d6..33f8decd9f38 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -206,6 +206,29 @@ static inline void pwm_get_args(const struct pwm_device *pwm, static inline void pwm_apply_args(struct pwm_device *pwm) { + /* + * PWM users calling pwm_apply_args() expect to have a fresh config + * where the polarity and period are set according to pwm_args info. + * The problem is, polarity can only be changed when the PWM is + * disabled. + * + * PWM drivers supporting hardware readout may declare the PWM device + * as enabled, and prevent polarity setting, which changes from the + * existing behavior, where all PWM devices are declared as disabled + * at startup (even if they are actually enabled), thus authorizing + * polarity setting. + * + * Instead of setting ->enabled to false, we call pwm_disable() + * before pwm_set_polarity() to ensure that everything is configured + * as expected, and the PWM is really disabled when the user request + * it. + * + * Note that PWM users requiring a smooth handover between the + * bootloader and the kernel (like critical regulators controlled by + * PWM devices) will have to switch to the atomic API and avoid calling + * pwm_apply_args(). + */ + pwm_disable(pwm); pwm_set_polarity(pwm, pwm->args.polarity); } @@ -217,6 +240,9 @@ static inline void pwm_apply_args(struct pwm_device *pwm) * @set_polarity: configure the polarity of this PWM * @enable: enable PWM output toggling * @disable: disable PWM output toggling + * @get_state: get the current PWM state. This function is only + * called once per PWM device when the PWM chip is + * registered. * @dbg_show: optional routine to show contents in debugfs * @owner: helps prevent removal of modules exporting active PWMs */ @@ -229,6 +255,8 @@ struct pwm_ops { enum pwm_polarity polarity); int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); + void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, + struct pwm_state *state); #ifdef CONFIG_DEBUG_FS void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s); #endif |