[3/4] bus: ts-nbus: convert to atomic PWM API

Message ID 20181026184157.16371-3-u.kleine-koenig@pengutronix.de
State New
Headers show
Series
  • [1/4] pwm: Add new helper to initialize a pwm_state variable with defaults
Related show

Commit Message

Uwe Kleine-König Oct. 26, 2018, 6:41 p.m.
The legacy PWM API should be removed in the long run, so convert a user
to the atomic PWM API.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/bus/ts-nbus.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

Comments

Thierry Reding Nov. 14, 2018, 12:15 p.m. | #1
On Fri, Oct 26, 2018 at 08:41:57PM +0200, Uwe Kleine-König wrote:
> The legacy PWM API should be removed in the long run, so convert a user
> to the atomic PWM API.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/bus/ts-nbus.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
> index 073fd9011154..51f5ed870ad1 100644
> --- a/drivers/bus/ts-nbus.c
> +++ b/drivers/bus/ts-nbus.c
> @@ -282,7 +282,7 @@ EXPORT_SYMBOL_GPL(ts_nbus_write);
>  static int ts_nbus_probe(struct platform_device *pdev)
>  {
>  	struct pwm_device *pwm;
> -	struct pwm_args pargs;
> +	struct pwm_state pstate;
>  	struct device *dev = &pdev->dev;
>  	struct ts_nbus *ts_nbus;
>  	int ret;
> @@ -305,25 +305,19 @@ static int ts_nbus_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	pwm_get_args(pwm, &pargs);
> -	if (!pargs.period) {
> +	pwm_get_state_default(pwm, &pstate);
> +	if (!pstate.period) {
>  		dev_err(&pdev->dev, "invalid PWM period\n");
>  		return -EINVAL;
>  	}
>  
> -	/*
> -	 * FIXME: pwm_apply_args() should be removed when switching to
> -	 * the atomic PWM API.
> -	 */
> -	pwm_apply_args(pwm);
> -	ret = pwm_config(pwm, pargs.period, pargs.period);
> +	/* We can start the FPGA and populate the peripherals now. */
> +	pstate.enabled = true;
> +	pstate.duty_cycle = pstate.period;
> +	ret = pwm_apply_state(pwm, &pstate);
>  	if (ret < 0)
>  		return ret;
>  
> -	/*
> -	 * we can now start the FPGA and populate the peripherals.
> -	 */
> -	pwm_enable(pwm);
>  	ts_nbus->pwm = pwm;
>  
>  	/*

This looks suspiciously like the PWM is actually powering this bus. It
would've been better to model that as a PWM driven regulator rather than
an PWM consumer.

Either way I don't see why pwm_get_state_default() would be useful here.

Thierry

Patch

diff --git a/drivers/bus/ts-nbus.c b/drivers/bus/ts-nbus.c
index 073fd9011154..51f5ed870ad1 100644
--- a/drivers/bus/ts-nbus.c
+++ b/drivers/bus/ts-nbus.c
@@ -282,7 +282,7 @@  EXPORT_SYMBOL_GPL(ts_nbus_write);
 static int ts_nbus_probe(struct platform_device *pdev)
 {
 	struct pwm_device *pwm;
-	struct pwm_args pargs;
+	struct pwm_state pstate;
 	struct device *dev = &pdev->dev;
 	struct ts_nbus *ts_nbus;
 	int ret;
@@ -305,25 +305,19 @@  static int ts_nbus_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	pwm_get_args(pwm, &pargs);
-	if (!pargs.period) {
+	pwm_get_state_default(pwm, &pstate);
+	if (!pstate.period) {
 		dev_err(&pdev->dev, "invalid PWM period\n");
 		return -EINVAL;
 	}
 
-	/*
-	 * FIXME: pwm_apply_args() should be removed when switching to
-	 * the atomic PWM API.
-	 */
-	pwm_apply_args(pwm);
-	ret = pwm_config(pwm, pargs.period, pargs.period);
+	/* We can start the FPGA and populate the peripherals now. */
+	pstate.enabled = true;
+	pstate.duty_cycle = pstate.period;
+	ret = pwm_apply_state(pwm, &pstate);
 	if (ret < 0)
 		return ret;
 
-	/*
-	 * we can now start the FPGA and populate the peripherals.
-	 */
-	pwm_enable(pwm);
 	ts_nbus->pwm = pwm;
 
 	/*