summaryrefslogtreecommitdiff
path: root/include/linux/pwm.h
diff options
context:
space:
mode:
authorSean Young <sean@mess.org>2023-12-19 19:30:27 +0300
committerThierry Reding <thierry.reding@gmail.com>2023-12-20 18:07:06 +0300
commit7170d3beafc2373dd76b6b5d6e617d89e4e42b8b (patch)
tree0c5b06c6031df723f752de7120acf85a915c458a /include/linux/pwm.h
parent752193da3f8b0aa819a27fc741d46ab046be315e (diff)
downloadlinux-7170d3beafc2373dd76b6b5d6e617d89e4e42b8b.tar.xz
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>
Diffstat (limited to 'include/linux/pwm.h')
-rw-r--r--include/linux/pwm.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/include/linux/pwm.h b/include/linux/pwm.h
index c9cb87b59ac8..495af3627939 100644
--- a/include/linux/pwm.h
+++ b/include/linux/pwm.h
@@ -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;