diff mbox series

[v3,4/4] pwm: imx27: return error, if clean PWM setup fails

Message ID 20230815104332.55044-4-Leif.Middelschulte@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v3,1/4] pwm: imx27: fix race condition .apply,.get_state | expand

Commit Message

Leif Middelschulte Aug. 15, 2023, 10:43 a.m. UTC
Instead of issuing a warning, return an error (as adviced[0]), if the
FIFO cannot be cleanly set up.

[0] https://lore.kernel.org/lkml/20230310174517.rb7xxrougkse2lrc@pengutronix.de/T/#ec9560c1f613d9c0d7b77d72ad9051768812f80db

Signed-off-by: Leif Middelschulte <Leif.Middelschulte@gmail.com>
---
 drivers/pwm/pwm-imx27.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Uwe Kleine-König Sept. 6, 2023, 3:44 p.m. UTC | #1
On Tue, Aug 15, 2023 at 12:43:32PM +0200, Leif Middelschulte wrote:
> Instead of issuing a warning, return an error (as adviced[0]), if the
> FIFO cannot be cleanly set up.
> 
> [0] https://lore.kernel.org/lkml/20230310174517.rb7xxrougkse2lrc@pengutronix.de/T/#ec9560c1f613d9c0d7b77d72ad9051768812f80db
> 
> Signed-off-by: Leif Middelschulte <Leif.Middelschulte@gmail.com>
> ---
>  drivers/pwm/pwm-imx27.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c
> index 9673e809d212..5fd6d34a7722 100644
> --- a/drivers/pwm/pwm-imx27.c
> +++ b/drivers/pwm/pwm-imx27.c
> @@ -133,14 +133,15 @@ static int pwm_imx27_wait_fifo_empty(struct pwm_chip *chip,
>  		sr = readl(imx->mmio_base + MX3_PWMSR);
>  		fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr);
>  		if (fifoav == MX3_PWMSR_FIFOAV_EMPTY)
> -			return;
> +			return 0;
>  		/* if the FIFO value does not decrease, there is another problem */
>  		if (previous_fifoav == fifoav)
>  			break;
>  		previous_fifoav = fifoav;
>  		msleep(period_ms);
>  	}
> -	dev_warn(dev, "FIFO has been refilled concurrently\n");
> +
> +	return -EAGAIN;
>  }
>  
>  static int pwm_imx27_get_state(struct pwm_chip *chip,
> @@ -208,7 +209,9 @@ static int pwm_imx27_get_state(struct pwm_chip *chip,
>  		 * been supplied and a period expired between the call of the wait
>  		 * function and the subsequent readl.
>  		 */
> -		pwm_imx27_wait_fifo_empty(chip, pwm);
> +		ret = pwm_imx27_wait_fifo_empty(chip, pwm);
> +		if (ret)
> +			return ret;
>  		val = readl(imx->mmio_base + MX3_PWMSAR);
>  	} else {
>  		val = imx->duty_cycle;

I'd squash this into the patch introducing pwm_imx27_wait_fifo_empty,
too.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-imx27.c b/drivers/pwm/pwm-imx27.c
index 9673e809d212..5fd6d34a7722 100644
--- a/drivers/pwm/pwm-imx27.c
+++ b/drivers/pwm/pwm-imx27.c
@@ -133,14 +133,15 @@  static int pwm_imx27_wait_fifo_empty(struct pwm_chip *chip,
 		sr = readl(imx->mmio_base + MX3_PWMSR);
 		fifoav = FIELD_GET(MX3_PWMSR_FIFOAV, sr);
 		if (fifoav == MX3_PWMSR_FIFOAV_EMPTY)
-			return;
+			return 0;
 		/* if the FIFO value does not decrease, there is another problem */
 		if (previous_fifoav == fifoav)
 			break;
 		previous_fifoav = fifoav;
 		msleep(period_ms);
 	}
-	dev_warn(dev, "FIFO has been refilled concurrently\n");
+
+	return -EAGAIN;
 }
 
 static int pwm_imx27_get_state(struct pwm_chip *chip,
@@ -208,7 +209,9 @@  static int pwm_imx27_get_state(struct pwm_chip *chip,
 		 * been supplied and a period expired between the call of the wait
 		 * function and the subsequent readl.
 		 */
-		pwm_imx27_wait_fifo_empty(chip, pwm);
+		ret = pwm_imx27_wait_fifo_empty(chip, pwm);
+		if (ret)
+			return ret;
 		val = readl(imx->mmio_base + MX3_PWMSAR);
 	} else {
 		val = imx->duty_cycle;