From 80e8d5b8b4cc158d3ce7ba49b08af28c9c710ebb Mon Sep 17 00:00:00 2001 From: Nuno Sa Date: Wed, 4 Dec 2024 15:36:52 +0100 Subject: [PATCH] pwm: core: sync with main In the pi branch pwm_apply_state() does not exist any longer. And that would break a lot of ADI out of tree users. In order to keep those users in sync between branches, keep using pwm_apply_state(). On top of that, pwm_apply_might_sleep() and pwm_apply_atomic() also have some user so that those also have to be present. Hence the pwm core is totally in sync with the main branch which meas some automatic cherry picking can fail. Signed-off-by: Nuno Sa --- drivers/pwm/core.c | 43 +++++++++++-------------------------------- include/linux/pwm.h | 43 +++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 50 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index ac932716b2d56..4e786fe535049 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -176,7 +176,7 @@ of_pwm_single_xlate(struct pwm_chip *chip, const struct of_phandle_args *args) pwm->args.period = args->args[0]; pwm->args.polarity = PWM_POLARITY_NORMAL; - if (args->args_count == 2 && args->args[1] & PWM_POLARITY_INVERTED) + if (args->args_count == 2 && args->args[2] & PWM_POLARITY_INVERTED) pwm->args.polarity = PWM_POLARITY_INVERSED; return pwm; @@ -382,8 +382,8 @@ struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, } EXPORT_SYMBOL_GPL(pwm_request_from_chip); -static void pwm_apply_debug(struct pwm_device *pwm, - const struct pwm_state *state) +static void pwm_apply_state_debug(struct pwm_device *pwm, + const struct pwm_state *state) { struct pwm_state *last = &pwm->last; struct pwm_chip *chip = pwm->chip; @@ -488,11 +488,6 @@ static void pwm_apply_debug(struct pwm_device *pwm, } } -/** - * __pwm_apply() - atomically apply a new state to a PWM device - * @pwm: PWM device - * @state: new state to apply - */ static int __pwm_apply(struct pwm_device *pwm, const struct pwm_state *state) { struct pwm_chip *chip; @@ -523,45 +518,29 @@ static int __pwm_apply(struct pwm_device *pwm, const struct pwm_state *state) * only do this after pwm->state was applied as some * implementations of .get_state depend on this */ - pwm_apply_debug(pwm, state); + pwm_apply_state_debug(pwm, state); return 0; } /** - * pwm_apply_might_sleep() - atomically apply a new state to a PWM device - * Cannot be used in atomic context. + * pwm_apply_state() - atomically apply a new state to a PWM device * @pwm: PWM device * @state: new state to apply */ -int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state) +int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state) { - int err; - /* * Some lowlevel driver's implementations of .apply() make use of * mutexes, also with some drivers only returning when the new - * configuration is active calling pwm_apply_might_sleep() from atomic context + * configuration is active calling pwm_apply_state() from atomic context * is a bad idea. So make it explicit that calling this function might * sleep. */ might_sleep(); - - if (IS_ENABLED(CONFIG_PWM_DEBUG) && pwm->chip->atomic) { - /* - * Catch any drivers that have been marked as atomic but - * that will sleep anyway. - */ - non_block_start(); - err = __pwm_apply(pwm, state); - non_block_end(); - } else { - err = __pwm_apply(pwm, state); - } - - return err; + return __pwm_apply(pwm, state); } -EXPORT_SYMBOL_GPL(pwm_apply_might_sleep); +EXPORT_SYMBOL_GPL(pwm_apply_state); /** * pwm_apply_atomic() - apply a new state to a PWM device from atomic context @@ -634,7 +613,7 @@ int pwm_adjust_config(struct pwm_device *pwm) state.period = pargs.period; state.polarity = pargs.polarity; - return pwm_apply_might_sleep(pwm, &state); + return pwm_apply_state(pwm, &state); } /* @@ -657,7 +636,7 @@ int pwm_adjust_config(struct pwm_device *pwm) state.duty_cycle = state.period - state.duty_cycle; } - return pwm_apply_might_sleep(pwm, &state); + return pwm_apply_state(pwm, &state); } EXPORT_SYMBOL_GPL(pwm_adjust_config); diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 69ebdf44de12f..d61416f2771fb 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -41,8 +41,8 @@ struct pwm_args { }; enum { - PWMF_REQUESTED = 0, - PWMF_EXPORTED = 1, + PWMF_REQUESTED = 1 << 0, + PWMF_EXPORTED = 1 << 1, }; /* @@ -97,8 +97,8 @@ struct pwm_device { * @state: state to fill with the current PWM state * * The returned PWM state represents the state that was applied by a previous call to - * pwm_apply_might_sleep(). Drivers may have to slightly tweak that state before programming it to - * hardware. If pwm_apply_might_sleep() was never called, this returns either the current hardware + * pwm_apply_state(). Drivers may have to slightly tweak that state before programming it to + * hardware. If pwm_apply_state() was never called, this returns either the current hardware * state (if supported) or the default settings. */ static inline void pwm_get_state(const struct pwm_device *pwm, @@ -162,20 +162,20 @@ static inline void pwm_get_args(const struct pwm_device *pwm, } /** - * pwm_init_state() - prepare a new state to be applied with pwm_apply_might_sleep() + * pwm_init_state() - prepare a new state to be applied with pwm_apply_state() * @pwm: PWM device * @state: state to fill with the prepared PWM state * * This functions prepares a state that can later be tweaked and applied - * to the PWM device with pwm_apply_might_sleep(). This is a convenient function + * to the PWM device with pwm_apply_state(). This is a convenient function * that first retrieves the current PWM state and the replaces the period * and polarity fields with the reference values defined in pwm->args. * Once the function returns, you can adjust the ->enabled and ->duty_cycle - * fields according to your needs before calling pwm_apply_might_sleep(). + * fields according to your needs before calling pwm_apply_state(). * * ->duty_cycle is initially set to zero to avoid cases where the current * ->duty_cycle value exceed the pwm_args->period one, which would trigger - * an error if the user calls pwm_apply_might_sleep() without adjusting ->duty_cycle + * an error if the user calls pwm_apply_state() without adjusting ->duty_cycle * first. */ static inline void pwm_init_state(const struct pwm_device *pwm, @@ -232,7 +232,7 @@ pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale) * * pwm_init_state(pwm, &state); * pwm_set_relative_duty_cycle(&state, 50, 100); - * pwm_apply_might_sleep(pwm, &state); + * pwm_apply_state(pwm, &state); * * This functions returns -EINVAL if @duty_cycle and/or @scale are * inconsistent (@scale == 0 or @duty_cycle > @scale). @@ -292,7 +292,6 @@ struct pwm_ops { * @npwm: number of PWMs controlled by this chip * @of_xlate: request a PWM device given a device tree PWM specifier * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier - * @atomic: can the driver's ->apply() be called in atomic context * @list: list node for internal use * @pwms: array of PWM devices allocated by the framework */ @@ -314,7 +313,7 @@ struct pwm_chip { #if IS_ENABLED(CONFIG_PWM) /* PWM user APIs */ -int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state); +int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state); int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state); int pwm_adjust_config(struct pwm_device *pwm); @@ -364,7 +363,7 @@ static inline int pwm_enable(struct pwm_device *pwm) return 0; state.enabled = true; - return pwm_apply_might_sleep(pwm, &state); + return pwm_apply_state(pwm, &state); } /** @@ -383,7 +382,7 @@ static inline void pwm_disable(struct pwm_device *pwm) return; state.enabled = false; - pwm_apply_might_sleep(pwm, &state); + pwm_apply_state(pwm, &state); } /** @@ -397,6 +396,7 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm) return !pwm->chip->atomic; } + /* PWM provider APIs */ int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, unsigned long timeout); @@ -430,11 +430,11 @@ static inline bool pwm_might_sleep(struct pwm_device *pwm) return true; } -static inline int pwm_apply_might_sleep(struct pwm_device *pwm, - const struct pwm_state *state) +static inline int pwm_apply_state(struct pwm_device *pwm, + const struct pwm_state *state) { might_sleep(); - return -EOPNOTSUPP; + return -ENOTSUPP; } static inline int pwm_apply_atomic(struct pwm_device *pwm, @@ -443,9 +443,10 @@ static inline int pwm_apply_atomic(struct pwm_device *pwm, return -EOPNOTSUPP; } + static inline int pwm_adjust_config(struct pwm_device *pwm) { - return -EOPNOTSUPP; + return -ENOTSUPP; } static inline int pwm_config(struct pwm_device *pwm, int duty_ns, @@ -534,6 +535,12 @@ devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode, } #endif +static inline int pwm_apply_might_sleep(struct pwm_device *pwm, + const struct pwm_state *state) +{ + return pwm_apply_state(pwm, state); +} + static inline void pwm_apply_args(struct pwm_device *pwm) { struct pwm_state state = { }; @@ -565,7 +572,7 @@ static inline void pwm_apply_args(struct pwm_device *pwm) state.phase = 0; state.usage_power = false; - pwm_apply_might_sleep(pwm, &state); + pwm_apply_state(pwm, &state); } struct pwm_lookup {