diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-04-14 15:17:40 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2016-05-17 08:48:03 -0400 |
commit | 15fa8a43c147213a9563903c87b29671035eb6e8 (patch) | |
tree | ececf11f09885f32d8b27334d180c8a080882000 | |
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>
-rw-r--r-- | drivers/pwm/core.c | 3 | ||||
-rw-r--r-- | include/linux/pwm.h | 28 |
2 files changed, 31 insertions, 0 deletions
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index c240b5437145..a909c64ee863 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c | |||
@@ -270,6 +270,9 @@ int pwmchip_add_with_polarity(struct pwm_chip *chip, | |||
270 | pwm->hwpwm = i; | 270 | pwm->hwpwm = i; |
271 | pwm->state.polarity = polarity; | 271 | pwm->state.polarity = polarity; |
272 | 272 | ||
273 | if (chip->ops->get_state) | ||
274 | chip->ops->get_state(chip, pwm, &pwm->state); | ||
275 | |||
273 | radix_tree_insert(&pwm_tree, pwm->pwm, pwm); | 276 | radix_tree_insert(&pwm_tree, pwm->pwm, pwm); |
274 | } | 277 | } |
275 | 278 | ||
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, | |||
206 | 206 | ||
207 | static inline void pwm_apply_args(struct pwm_device *pwm) | 207 | static inline void pwm_apply_args(struct pwm_device *pwm) |
208 | { | 208 | { |
209 | /* | ||
210 | * PWM users calling pwm_apply_args() expect to have a fresh config | ||
211 | * where the polarity and period are set according to pwm_args info. | ||
212 | * The problem is, polarity can only be changed when the PWM is | ||
213 | * disabled. | ||
214 | * | ||
215 | * PWM drivers supporting hardware readout may declare the PWM device | ||
216 | * as enabled, and prevent polarity setting, which changes from the | ||
217 | * existing behavior, where all PWM devices are declared as disabled | ||
218 | * at startup (even if they are actually enabled), thus authorizing | ||
219 | * polarity setting. | ||
220 | * | ||
221 | * Instead of setting ->enabled to false, we call pwm_disable() | ||
222 | * before pwm_set_polarity() to ensure that everything is configured | ||
223 | * as expected, and the PWM is really disabled when the user request | ||
224 | * it. | ||
225 | * | ||
226 | * Note that PWM users requiring a smooth handover between the | ||
227 | * bootloader and the kernel (like critical regulators controlled by | ||
228 | * PWM devices) will have to switch to the atomic API and avoid calling | ||
229 | * pwm_apply_args(). | ||
230 | */ | ||
231 | pwm_disable(pwm); | ||
209 | pwm_set_polarity(pwm, pwm->args.polarity); | 232 | pwm_set_polarity(pwm, pwm->args.polarity); |
210 | } | 233 | } |
211 | 234 | ||
@@ -217,6 +240,9 @@ static inline void pwm_apply_args(struct pwm_device *pwm) | |||
217 | * @set_polarity: configure the polarity of this PWM | 240 | * @set_polarity: configure the polarity of this PWM |
218 | * @enable: enable PWM output toggling | 241 | * @enable: enable PWM output toggling |
219 | * @disable: disable PWM output toggling | 242 | * @disable: disable PWM output toggling |
243 | * @get_state: get the current PWM state. This function is only | ||
244 | * called once per PWM device when the PWM chip is | ||
245 | * registered. | ||
220 | * @dbg_show: optional routine to show contents in debugfs | 246 | * @dbg_show: optional routine to show contents in debugfs |
221 | * @owner: helps prevent removal of modules exporting active PWMs | 247 | * @owner: helps prevent removal of modules exporting active PWMs |
222 | */ | 248 | */ |
@@ -229,6 +255,8 @@ struct pwm_ops { | |||
229 | enum pwm_polarity polarity); | 255 | enum pwm_polarity polarity); |
230 | int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); | 256 | int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm); |
231 | void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); | 257 | void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm); |
258 | void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm, | ||
259 | struct pwm_state *state); | ||
232 | #ifdef CONFIG_DEBUG_FS | 260 | #ifdef CONFIG_DEBUG_FS |
233 | void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s); | 261 | void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s); |
234 | #endif | 262 | #endif |