Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH V2 0/3] pwm: bcm2835: Minor fixes
@ 2019-08-24 14:09 Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 1/3] pwm: bcm2835: suppress error message for invalid period_ns Stefan Wahren
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stefan Wahren @ 2019-08-24 14:09 UTC (permalink / raw)
  To: Thierry Reding, Eric Anholt, Florian Fainelli, Ray Jui, Scott Branden
  Cc: linux-pwm, Stefan Wahren, linux-arm-kernel

This small patch series contains minor fixes for clock handling and the
period range check.

Changes in V2:
- simplified patch 3 inspired by Uwe's suggestion
- add Uwe's Ack

Stefan Wahren (3):
  pwm: bcm2835: suppress error message for invalid period_ns
  pwm: bcm2835: fix period_ns range check
  pwm: bcm2835: suppress error message during deferred probe

 drivers/pwm/pwm-bcm2835.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

--
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH V2 1/3] pwm: bcm2835: suppress error message for invalid period_ns
  2019-08-24 14:09 [PATCH V2 0/3] pwm: bcm2835: Minor fixes Stefan Wahren
@ 2019-08-24 14:09 ` Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 2/3] pwm: bcm2835: fix period_ns range check Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 3/3] pwm: bcm2835: suppress error message during deferred probe Stefan Wahren
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2019-08-24 14:09 UTC (permalink / raw)
  To: Thierry Reding, Eric Anholt, Florian Fainelli, Ray Jui, Scott Branden
  Cc: linux-pwm, Stefan Wahren, linux-arm-kernel

The PWM config can be triggered via sysfs, so we better suppress the
error message in case of an invalid period to avoid kernel log spamming.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-bcm2835.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index f6fe0b9..5276306 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -72,11 +72,8 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,

 	scaler = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate);

-	if (period_ns <= MIN_PERIOD) {
-		dev_err(pc->dev, "period %d not supported, minimum %d\n",
-			period_ns, MIN_PERIOD);
+	if (period_ns <= MIN_PERIOD)
 		return -EINVAL;
-	}

 	writel(DIV_ROUND_CLOSEST(duty_ns, scaler),
 	       pc->base + DUTY(pwm->hwpwm));
--
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH V2 2/3] pwm: bcm2835: fix period_ns range check
  2019-08-24 14:09 [PATCH V2 0/3] pwm: bcm2835: Minor fixes Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 1/3] pwm: bcm2835: suppress error message for invalid period_ns Stefan Wahren
@ 2019-08-24 14:09 ` Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 3/3] pwm: bcm2835: suppress error message during deferred probe Stefan Wahren
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2019-08-24 14:09 UTC (permalink / raw)
  To: Thierry Reding, Eric Anholt, Florian Fainelli, Ray Jui, Scott Branden
  Cc: linux-pwm, Stefan Wahren, linux-arm-kernel

The range check for period_ns was written under assumption of a fixed
PWM clock. With clk-bcm2835 driver the PWM clock is a dynamic one.
So fix this by doing the range check on the period register value.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/pwm/pwm-bcm2835.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index 5276306..2c82386 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -21,7 +21,7 @@
 #define PERIOD(x)		(((x) * 0x10) + 0x10)
 #define DUTY(x)			(((x) * 0x10) + 0x14)

-#define MIN_PERIOD		108		/* 9.2 MHz max. PWM clock */
+#define PERIOD_MIN		0x2

 struct bcm2835_pwm {
 	struct pwm_chip chip;
@@ -64,6 +64,7 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
 	unsigned long rate = clk_get_rate(pc->clk);
 	unsigned long scaler;
+	u32 period;

 	if (!rate) {
 		dev_err(pc->dev, "failed to get clock rate\n");
@@ -71,14 +72,14 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	}

 	scaler = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate);
+	period = DIV_ROUND_CLOSEST(period_ns, scaler);

-	if (period_ns <= MIN_PERIOD)
+	if (period < PERIOD_MIN)
 		return -EINVAL;

 	writel(DIV_ROUND_CLOSEST(duty_ns, scaler),
 	       pc->base + DUTY(pwm->hwpwm));
-	writel(DIV_ROUND_CLOSEST(period_ns, scaler),
-	       pc->base + PERIOD(pwm->hwpwm));
+	writel(period, pc->base + PERIOD(pwm->hwpwm));

 	return 0;
 }
--
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH V2 3/3] pwm: bcm2835: suppress error message during deferred probe
  2019-08-24 14:09 [PATCH V2 0/3] pwm: bcm2835: Minor fixes Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 1/3] pwm: bcm2835: suppress error message for invalid period_ns Stefan Wahren
  2019-08-24 14:09 ` [PATCH V2 2/3] pwm: bcm2835: fix period_ns range check Stefan Wahren
@ 2019-08-24 14:09 ` Stefan Wahren
  2019-08-24 15:13   ` Uwe Kleine-König
  2 siblings, 1 reply; 5+ messages in thread
From: Stefan Wahren @ 2019-08-24 14:09 UTC (permalink / raw)
  To: Thierry Reding, Eric Anholt, Florian Fainelli, Ray Jui, Scott Branden
  Cc: linux-pwm, Stefan Wahren, linux-arm-kernel

This suppresses error messages in case the PWM clock isn't ready yet.

Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 drivers/pwm/pwm-bcm2835.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index 2c82386..91e24f0 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -153,8 +153,11 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)

 	pc->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(pc->clk)) {
-		dev_err(&pdev->dev, "clock not found: %ld\n", PTR_ERR(pc->clk));
-		return PTR_ERR(pc->clk);
+		ret = PTR_ERR(pc->clk);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "clock not found: %d\n", ret);
+
+		return ret;
 	}

 	ret = clk_prepare_enable(pc->clk);
--
2.7.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH V2 3/3] pwm: bcm2835: suppress error message during deferred probe
  2019-08-24 14:09 ` [PATCH V2 3/3] pwm: bcm2835: suppress error message during deferred probe Stefan Wahren
@ 2019-08-24 15:13   ` Uwe Kleine-König
  0 siblings, 0 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2019-08-24 15:13 UTC (permalink / raw)
  To: Stefan Wahren
  Cc: linux-pwm, Florian Fainelli, Scott Branden, Ray Jui, Eric Anholt,
	Thierry Reding, linux-arm-kernel

On Sat, Aug 24, 2019 at 04:09:48PM +0200, Stefan Wahren wrote:
> This suppresses error messages in case the PWM clock isn't ready yet.
> 
> Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-24 14:09 [PATCH V2 0/3] pwm: bcm2835: Minor fixes Stefan Wahren
2019-08-24 14:09 ` [PATCH V2 1/3] pwm: bcm2835: suppress error message for invalid period_ns Stefan Wahren
2019-08-24 14:09 ` [PATCH V2 2/3] pwm: bcm2835: fix period_ns range check Stefan Wahren
2019-08-24 14:09 ` [PATCH V2 3/3] pwm: bcm2835: suppress error message during deferred probe Stefan Wahren
2019-08-24 15:13   ` Uwe Kleine-König

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox