media: rc: pwm-ir-tx: Switch to atomic PWM API
Subsystems (4)
PATCH 1/1 media: rc: pwm-ir-tx: Switch to atomic PWM API
Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and replace it for the atomic PWM API.
Signed-off-by Maíra Canal <[email protected]>
--- drivers/media/rc/pwm-ir-tx.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/media/rc/pwm-ir-tx.c +10 -4
@@ -53,6 +53,7 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf, {struct pwm_ir *pwm_ir = dev->priv;struct pwm_device *pwm = pwm_ir->pwm; +struct pwm_state state;int i, duty, period;ktime_t edge;long delta;
@@ -60,15 +61,19 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf, period =DIV_ROUND_CLOSEST (NSEC_PER_SEC , pwm_ir->carrier); duty =DIV_ROUND_CLOSEST (pwm_ir->duty_cycle * period,100 ); -pwm_config (pwm, duty, period); +pwm_init_state (pwm, &state); + + state.duty_cycle = duty; + state.period = period; edge =ktime_get ();for (i =0 ; i < count; i++) {if (i %2 )// space -pwm_disable (pwm); + state.enabled = false;else -pwm_enable (pwm); + state.enabled = true; +pwm_apply_state (pwm, &state); edge =ktime_add_us (edge, txbuf[i]); delta =ktime_us_delta (edge,ktime_get ());
@@ -76,7 +81,8 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf,usleep_range (delta, delta +10 ); } -pwm_disable (pwm); + state.enabled = false; +pwm_apply_state (pwm, &state);return count; }
Signature · 1 line
2.31.1
Sean Young
maintainerHi Maíra,
Your patch looks good, just some very minor nits.
Quoted 21 lines · Maíra Canal
Remove legacy PWM interface (
pwm_config,pwm_enable,pwm_disable) and replace it for the atomic PWM API.Signed-off-by Maíra Canal <[email protected]>--- drivers/media/rc/pwm-ir-tx.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/media/rc/pwm-ir-tx.c +1
-0@@ -53,6 +53,7 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf, {struct pwm_ir *pwm_ir = dev->priv;struct pwm_device *pwm = pwm_ir->pwm; +struct pwm_state state;int i, duty, period;ktime_t edge;long delta;
drivers/media/rc/pwm-ir-tx.c static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf, · line 67
Quoted 8 lines
drivers/media/rc/pwm-ir-tx.c +4
-1@@ -60,15 +61,19 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf, period =DIV_ROUND_CLOSEST (NSEC_PER_SEC , pwm_ir->carrier); duty =DIV_ROUND_CLOSEST (pwm_ir->duty_cycle * period,100 ); -pwm_config (pwm, duty, period); +pwm_init_state (pwm, &state); + + state.duty_cycle = duty; + state.period = period;
There is no reason to have the period and duty local variables any more; the result of DIV_ROUND_CLOSEST(..) can be assigned directly.
drivers/media/rc/pwm-ir-tx.c static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf, · line 75
Quoted 9 lines
drivers/media/rc/pwm-ir-tx.c +2
-2edge =ktime_get ();for (i =0 ; i < count; i++) {if (i %2 )// space -pwm_disable (pwm); + state.enabled = false;else -pwm_enable (pwm); + state.enabled = true;
This could be simply:
state.enabled = (i % 2) == 0;
Quoted 16 lines
drivers/media/rc/pwm-ir-tx.c +3
-1+pwm_apply_state (pwm, &state); edge =ktime_add_us (edge, txbuf[i]); delta =ktime_us_delta (edge,ktime_get ());@@ -76,7 +81,8 @@ static int pwm_ir_tx(struct rc_dev *dev, unsigned int *txbuf,usleep_range (delta, delta +10 ); } -pwm_disable (pwm); + state.enabled = false; +pwm_apply_state (pwm, &state);return count; }Signature · 1 line
2.31.1
Thanks
Sean