diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 9206fc0..05dad93 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -23,6 +23,7 @@ /** * struct pwm_args - board-dependent PWM arguments * @period_ns: reference period + * @polarity: reference polarity * * This structure describes board-dependent arguments attached to a PWM * device. These arguments are usually retrieved from the PWM lookup table or @@ -35,6 +36,7 @@ struct pwm_args { unsigned int period_ns; + unsigned int polarity; }; struct pwm_device { @@ -63,7 +65,7 @@ return NULL; } -static int set_duty_period_ns(struct param_d *p, void *priv) +static int apply_params(struct param_d *p, void *priv) { struct pwm_device *pwm = priv; @@ -112,12 +114,12 @@ list_add_tail(&pwm->node, &pwm_list); - p = dev_add_param_uint32(&pwm->dev, "duty_ns", set_duty_period_ns, + p = dev_add_param_uint32(&pwm->dev, "duty_ns", apply_params, NULL, &pwm->params.duty_ns, "%u", pwm); if (IS_ERR(p)) return PTR_ERR(p); - p = dev_add_param_uint32(&pwm->dev, "period_ns", set_duty_period_ns, + p = dev_add_param_uint32(&pwm->dev, "period_ns", apply_params, NULL, &pwm->params.period_ns, "%u", pwm); if (IS_ERR(p)) return PTR_ERR(p); @@ -127,6 +129,11 @@ if (IS_ERR(p)) return PTR_ERR(p); + p = dev_add_param_bool(&pwm->dev, "inverted", apply_params, + NULL, &pwm->params.polarity, pwm); + if (IS_ERR(p)) + return PTR_ERR(p); + return 0; } EXPORT_SYMBOL_GPL(pwmchip_add); @@ -234,6 +241,11 @@ if (args.args_count > 1) pwm->args.period_ns = args.args[1]; + pwm->args.polarity = PWM_POLARITY_NORMAL; + + if (args.args_count > 2 && args.args[2] & PWM_POLARITY_INVERTED) + pwm->args.polarity = PWM_POLARITY_INVERTED; + ret = __pwm_request(pwm); if (ret) return ERR_PTR(ret); @@ -277,7 +289,7 @@ * This functions prepares a state that can later be tweaked and applied * 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 - * with the reference values defined in pwm->args. + * 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_state(). * @@ -298,6 +310,7 @@ pwm_get_args(pwm, &args); state->period_ns = args.period_ns; + state->polarity = args.polarity; state->duty_ns = 0; } EXPORT_SYMBOL_GPL(pwm_init_state); diff --git a/include/pwm.h b/include/pwm.h index 67ea0f9..b67ab13 100644 --- a/include/pwm.h +++ b/include/pwm.h @@ -2,18 +2,24 @@ #ifndef __PWM_H #define __PWM_H +#include + struct pwm_device; struct device_d; +#define PWM_POLARITY_NORMAL 0 + /* * struct pwm_state - state of a PWM channel * @period_ns: PWM period (in nanoseconds) * @duty_ns: PWM duty cycle (in nanoseconds) + * @polarity: PWM polarity * @p_enable: PWM enabled status */ struct pwm_state { unsigned int period_ns; unsigned int duty_ns; + unsigned int polarity; unsigned int p_enable; };