linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: ir-rx51: Switch to atomic PWM API
@ 2021-10-31 22:15 Maíra Canal
  2021-11-04 15:29 ` Uwe Kleine-König
  0 siblings, 1 reply; 3+ messages in thread
From: Maíra Canal @ 2021-10-31 22:15 UTC (permalink / raw)
  To: sean, mchehab, thierry.reding, u.kleine-koenig, lee.jones
  Cc: linux-media, linux-kernel, linux-pwm

Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and
replace it for the atomic PWM API.

Signed-off-by: Maíra Canal <maira.canal@usp.br>
---
V1 -> V2: remove conceptually wrong chunk of code and correct the position
of pwm_init_state function
---
 drivers/media/rc/ir-rx51.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
index a0d9c02a7588..41d4a4338072 100644
--- a/drivers/media/rc/ir-rx51.c
+++ b/drivers/media/rc/ir-rx51.c
@@ -19,6 +19,7 @@
 struct ir_rx51 {
 	struct rc_dev *rcdev;
 	struct pwm_device *pwm;
+	struct pwm_state *state;
 	struct hrtimer timer;
 	struct device	     *dev;
 	wait_queue_head_t     wqueue;
@@ -32,22 +33,22 @@ struct ir_rx51 {
 
 static inline void ir_rx51_on(struct ir_rx51 *ir_rx51)
 {
-	pwm_enable(ir_rx51->pwm);
+	ir_rx51->state->enabled = true;
+	pwm_apply_state(ir_rx51->pwm, ir_rx51->state);
 }
 
 static inline void ir_rx51_off(struct ir_rx51 *ir_rx51)
 {
-	pwm_disable(ir_rx51->pwm);
+	ir_rx51->state->enabled = false;
+	pwm_apply_state(ir_rx51->pwm, ir_rx51->state);
 }
 
 static int init_timing_params(struct ir_rx51 *ir_rx51)
 {
-	struct pwm_device *pwm = ir_rx51->pwm;
-	int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
+	struct pwm_state *state = ir_rx51->state;
 
-	duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100);
-
-	pwm_config(pwm, duty, period);
+	state->period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
+	pwm_set_relative_duty_cycle(state, ir_rx51->duty_cycle, 100);
 
 	return 0;
 }
@@ -242,6 +243,7 @@ static int ir_rx51_probe(struct platform_device *dev)
 
 	/* Use default, in case userspace does not set the carrier */
 	ir_rx51.freq = DIV_ROUND_CLOSEST_ULL(pwm_get_period(pwm), NSEC_PER_SEC);
+	pwm_init_state(pwm, ir_rx51.state);
 	pwm_put(pwm);
 
 	hrtimer_init(&ir_rx51.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] media: ir-rx51: Switch to atomic PWM API
  2021-10-31 22:15 [PATCH v2] media: ir-rx51: Switch to atomic PWM API Maíra Canal
@ 2021-11-04 15:29 ` Uwe Kleine-König
  2021-11-04 17:43   ` Uwe Kleine-König
  0 siblings, 1 reply; 3+ messages in thread
From: Uwe Kleine-König @ 2021-11-04 15:29 UTC (permalink / raw)
  To: Maíra Canal
  Cc: sean, mchehab, thierry.reding, lee.jones, linux-media,
	linux-kernel, linux-pwm

[-- Attachment #1: Type: text/plain, Size: 2564 bytes --]

On Sun, Oct 31, 2021 at 07:15:45PM -0300, Maíra Canal wrote:
> Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and
> replace it for the atomic PWM API.
> 
> Signed-off-by: Maíra Canal <maira.canal@usp.br>
> ---
> V1 -> V2: remove conceptually wrong chunk of code and correct the position
> of pwm_init_state function
> ---
>  drivers/media/rc/ir-rx51.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
> index a0d9c02a7588..41d4a4338072 100644
> --- a/drivers/media/rc/ir-rx51.c
> +++ b/drivers/media/rc/ir-rx51.c
> @@ -19,6 +19,7 @@
>  struct ir_rx51 {
>  	struct rc_dev *rcdev;
>  	struct pwm_device *pwm;
> +	struct pwm_state *state;
>  	struct hrtimer timer;
>  	struct device	     *dev;
>  	wait_queue_head_t     wqueue;
> @@ -32,22 +33,22 @@ struct ir_rx51 {
>  
>  static inline void ir_rx51_on(struct ir_rx51 *ir_rx51)
>  {
> -	pwm_enable(ir_rx51->pwm);
> +	ir_rx51->state->enabled = true;
> +	pwm_apply_state(ir_rx51->pwm, ir_rx51->state);
>  }
>  
>  static inline void ir_rx51_off(struct ir_rx51 *ir_rx51)
>  {
> -	pwm_disable(ir_rx51->pwm);
> +	ir_rx51->state->enabled = false;
> +	pwm_apply_state(ir_rx51->pwm, ir_rx51->state);
>  }
>  
>  static int init_timing_params(struct ir_rx51 *ir_rx51)
>  {
> -	struct pwm_device *pwm = ir_rx51->pwm;
> -	int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
> +	struct pwm_state *state = ir_rx51->state;
>  
> -	duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100);
> -
> -	pwm_config(pwm, duty, period);
> +	state->period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
> +	pwm_set_relative_duty_cycle(state, ir_rx51->duty_cycle, 100);
>  
>  	return 0;
>  }
> @@ -242,6 +243,7 @@ static int ir_rx51_probe(struct platform_device *dev)
>  
>  	/* Use default, in case userspace does not set the carrier */
>  	ir_rx51.freq = DIV_ROUND_CLOSEST_ULL(pwm_get_period(pwm), NSEC_PER_SEC);
> +	pwm_init_state(pwm, ir_rx51.state);
>  	pwm_put(pwm);
>  

Orthogonal to this patch I wonder why probe calls pwm_get() and
pwm_put(), just to have another call to pwm_get() in the open callback.

Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>


>  	hrtimer_init(&ir_rx51.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> -- 
> 2.31.1
> 
> 

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] media: ir-rx51: Switch to atomic PWM API
  2021-11-04 15:29 ` Uwe Kleine-König
@ 2021-11-04 17:43   ` Uwe Kleine-König
  0 siblings, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2021-11-04 17:43 UTC (permalink / raw)
  To: Maíra Canal
  Cc: sean, mchehab, thierry.reding, lee.jones, linux-media,
	linux-kernel, linux-pwm

[-- Attachment #1: Type: text/plain, Size: 2871 bytes --]

On Thu, Nov 04, 2021 at 04:29:13PM +0100, Uwe Kleine-König wrote:
> On Sun, Oct 31, 2021 at 07:15:45PM -0300, Maíra Canal wrote:
> > Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and
> > replace it for the atomic PWM API.
> > 
> > Signed-off-by: Maíra Canal <maira.canal@usp.br>
> > ---
> > V1 -> V2: remove conceptually wrong chunk of code and correct the position
> > of pwm_init_state function
> > ---
> >  drivers/media/rc/ir-rx51.c | 16 +++++++++-------
> >  1 file changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/media/rc/ir-rx51.c b/drivers/media/rc/ir-rx51.c
> > index a0d9c02a7588..41d4a4338072 100644
> > --- a/drivers/media/rc/ir-rx51.c
> > +++ b/drivers/media/rc/ir-rx51.c
> > @@ -19,6 +19,7 @@
> >  struct ir_rx51 {
> >  	struct rc_dev *rcdev;
> >  	struct pwm_device *pwm;
> > +	struct pwm_state *state;
> >  	struct hrtimer timer;
> >  	struct device	     *dev;
> >  	wait_queue_head_t     wqueue;
> > @@ -32,22 +33,22 @@ struct ir_rx51 {
> >  
> >  static inline void ir_rx51_on(struct ir_rx51 *ir_rx51)
> >  {
> > -	pwm_enable(ir_rx51->pwm);
> > +	ir_rx51->state->enabled = true;
> > +	pwm_apply_state(ir_rx51->pwm, ir_rx51->state);
> >  }
> >  
> >  static inline void ir_rx51_off(struct ir_rx51 *ir_rx51)
> >  {
> > -	pwm_disable(ir_rx51->pwm);
> > +	ir_rx51->state->enabled = false;
> > +	pwm_apply_state(ir_rx51->pwm, ir_rx51->state);
> >  }
> >  
> >  static int init_timing_params(struct ir_rx51 *ir_rx51)
> >  {
> > -	struct pwm_device *pwm = ir_rx51->pwm;
> > -	int duty, period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
> > +	struct pwm_state *state = ir_rx51->state;
> >  
> > -	duty = DIV_ROUND_CLOSEST(ir_rx51->duty_cycle * period, 100);
> > -
> > -	pwm_config(pwm, duty, period);
> > +	state->period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, ir_rx51->freq);
> > +	pwm_set_relative_duty_cycle(state, ir_rx51->duty_cycle, 100);
> >  
> >  	return 0;
> >  }
> > @@ -242,6 +243,7 @@ static int ir_rx51_probe(struct platform_device *dev)
> >  
> >  	/* Use default, in case userspace does not set the carrier */
> >  	ir_rx51.freq = DIV_ROUND_CLOSEST_ULL(pwm_get_period(pwm), NSEC_PER_SEC);
> > +	pwm_init_state(pwm, ir_rx51.state);
> >  	pwm_put(pwm);
> >  
> 
> Orthogonal to this patch I wonder why probe calls pwm_get() and
> pwm_put(), just to have another call to pwm_get() in the open callback.
> 
> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Oh, I missed something: the member added to struct ir_rx51 must be a
plain struct pwm_state, not a pointer to it. As suggested here the
driver runs into a NULL pointer exception.

Best regards
Uwe


-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-04 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-31 22:15 [PATCH v2] media: ir-rx51: Switch to atomic PWM API Maíra Canal
2021-11-04 15:29 ` Uwe Kleine-König
2021-11-04 17:43   ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).