mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
synced 2026-04-23 08:55:56 -04:00
pwm: Make it possible to apply PWM changes in atomic context
Some PWM devices require sleeping, for example if the pwm device is connected over I2C. However, many PWM devices could be used from atomic context, e.g. memory mapped PWM. This is useful for, for example, the pwm-ir-tx driver which requires precise timing. Sleeping causes havoc with the generated IR signal. Since not all PWM devices can support atomic context, we also add a pwm_might_sleep() function to check if is not supported. Signed-off-by: Sean Young <sean@mess.org> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
This commit is contained in:
committed by
Thierry Reding
parent
752193da3f
commit
7170d3beaf
@@ -285,6 +285,7 @@ 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
|
||||
* @pwms: array of PWM devices allocated by the framework
|
||||
*/
|
||||
struct pwm_chip {
|
||||
@@ -297,6 +298,7 @@ struct pwm_chip {
|
||||
struct pwm_device * (*of_xlate)(struct pwm_chip *chip,
|
||||
const struct of_phandle_args *args);
|
||||
unsigned int of_pwm_n_cells;
|
||||
bool atomic;
|
||||
|
||||
/* only used internally by the PWM framework */
|
||||
struct pwm_device *pwms;
|
||||
@@ -305,6 +307,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_atomic(struct pwm_device *pwm, const struct pwm_state *state);
|
||||
int pwm_adjust_config(struct pwm_device *pwm);
|
||||
|
||||
/**
|
||||
@@ -375,6 +378,17 @@ static inline void pwm_disable(struct pwm_device *pwm)
|
||||
pwm_apply_might_sleep(pwm, &state);
|
||||
}
|
||||
|
||||
/**
|
||||
* pwm_might_sleep() - is pwm_apply_atomic() supported?
|
||||
* @pwm: PWM device
|
||||
*
|
||||
* Returns: false if pwm_apply_atomic() can be called from atomic context.
|
||||
*/
|
||||
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);
|
||||
@@ -403,6 +417,11 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev,
|
||||
struct fwnode_handle *fwnode,
|
||||
const char *con_id);
|
||||
#else
|
||||
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)
|
||||
{
|
||||
@@ -410,6 +429,12 @@ static inline int pwm_apply_might_sleep(struct pwm_device *pwm,
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int pwm_apply_atomic(struct pwm_device *pwm,
|
||||
const struct pwm_state *state)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int pwm_adjust_config(struct pwm_device *pwm)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
Reference in New Issue
Block a user