* [PATCH 1/3] pwm: bcm2835: calculate scaler in pwm_config
2015-12-01 22:55 [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
@ 2015-12-01 22:55 ` Stefan Wahren
2015-12-01 22:55 ` [PATCH 2/3] pwm: bcm2835: prevent division by zero Stefan Wahren
` (3 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Stefan Wahren @ 2015-12-01 22:55 UTC (permalink / raw)
To: linux-arm-kernel
Currently pwm-bcm2835 assumes a fixed clock rate and stores the
resulting scaler in the driver structure. But with the upcoming
PWM clock support for clk-bcm2835 the rate could change.
So calculate the scaler in pwm_config.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/pwm/pwm-bcm2835.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index b4c7f95..174cca9 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -29,7 +29,6 @@
struct bcm2835_pwm {
struct pwm_chip chip;
struct device *dev;
- unsigned long scaler;
void __iomem *base;
struct clk *clk;
};
@@ -66,6 +65,7 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
{
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
+ unsigned long scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
if (period_ns <= MIN_PERIOD) {
dev_err(pc->dev, "period %d not supported, minimum %d\n",
@@ -73,8 +73,8 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
return -EINVAL;
}
- writel(duty_ns / pc->scaler, pc->base + DUTY(pwm->hwpwm));
- writel(period_ns / pc->scaler, pc->base + PERIOD(pwm->hwpwm));
+ writel(duty_ns / scaler, pc->base + DUTY(pwm->hwpwm));
+ writel(period_ns / scaler, pc->base + PERIOD(pwm->hwpwm));
return 0;
}
@@ -156,8 +156,6 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
if (ret)
return ret;
- pc->scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
-
pc->chip.dev = &pdev->dev;
pc->chip.ops = &bcm2835_pwm_ops;
pc->chip.npwm = 2;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 2/3] pwm: bcm2835: prevent division by zero
2015-12-01 22:55 [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
2015-12-01 22:55 ` [PATCH 1/3] pwm: bcm2835: calculate scaler in pwm_config Stefan Wahren
@ 2015-12-01 22:55 ` Stefan Wahren
2015-12-01 23:16 ` Eric Anholt
2015-12-02 15:23 ` Mathieu Poirier
2015-12-01 22:55 ` [PATCH 3/3] pwm: bcm2835: fix email address specifiction Stefan Wahren
` (2 subsequent siblings)
4 siblings, 2 replies; 12+ messages in thread
From: Stefan Wahren @ 2015-12-01 22:55 UTC (permalink / raw)
To: linux-arm-kernel
It's possible that the pwm clock become an orphan. So better
check the result of clk_get_rate in order to prevent a division
by zero.
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/pwm/pwm-bcm2835.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index 174cca9..31a6992 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -65,7 +65,15 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
int duty_ns, int period_ns)
{
struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
- unsigned long scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
+ unsigned long rate = clk_get_rate(pc->clk);
+ unsigned long scaler;
+
+ if (!rate) {
+ dev_err(pc->dev, "failed to get clock rate\n");
+ return -EINVAL;
+ }
+
+ scaler = NSEC_PER_SEC / rate;
if (period_ns <= MIN_PERIOD) {
dev_err(pc->dev, "period %d not supported, minimum %d\n",
--
1.7.9.5
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 2/3] pwm: bcm2835: prevent division by zero
2015-12-01 22:55 ` [PATCH 2/3] pwm: bcm2835: prevent division by zero Stefan Wahren
@ 2015-12-01 23:16 ` Eric Anholt
2015-12-02 17:08 ` Stefan Wahren
2015-12-02 15:23 ` Mathieu Poirier
1 sibling, 1 reply; 12+ messages in thread
From: Eric Anholt @ 2015-12-01 23:16 UTC (permalink / raw)
To: linux-arm-kernel
Stefan Wahren <stefan.wahren@i2se.com> writes:
> It's possible that the pwm clock become an orphan. So better
> check the result of clk_get_rate in order to prevent a division
> by zero.
How would we lose our clock when we're keeping the clock enabled from
driver probe until remove?
Patches 1 and 3 are:
Reviewed-by: Eric Anholt <eric@anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151201/646cc66d/attachment.sig>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/3] pwm: bcm2835: prevent division by zero
2015-12-01 22:55 ` [PATCH 2/3] pwm: bcm2835: prevent division by zero Stefan Wahren
2015-12-01 23:16 ` Eric Anholt
@ 2015-12-02 15:23 ` Mathieu Poirier
2015-12-02 19:41 ` Eric Anholt
1 sibling, 1 reply; 12+ messages in thread
From: Mathieu Poirier @ 2015-12-02 15:23 UTC (permalink / raw)
To: linux-arm-kernel
On 1 December 2015 at 15:55, Stefan Wahren <stefan.wahren@i2se.com> wrote:
> It's possible that the pwm clock become an orphan. So better
> check the result of clk_get_rate in order to prevent a division
> by zero.
>
> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
> ---
> drivers/pwm/pwm-bcm2835.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
> index 174cca9..31a6992 100644
> --- a/drivers/pwm/pwm-bcm2835.c
> +++ b/drivers/pwm/pwm-bcm2835.c
> @@ -65,7 +65,15 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
> int duty_ns, int period_ns)
> {
> struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
> - unsigned long scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
> + unsigned long rate = clk_get_rate(pc->clk);
> + unsigned long scaler;
> +
> + if (!rate) {
> + dev_err(pc->dev, "failed to get clock rate\n");
> + return -EINVAL;
> + }
> +
> + scaler = NSEC_PER_SEC / rate;
Stefan,
Please merge this code into patch 1/3. That way it is done the right
way the first time around.
Thanks,
Mathieu
>
> if (period_ns <= MIN_PERIOD) {
> dev_err(pc->dev, "period %d not supported, minimum %d\n",
> --
> 1.7.9.5
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 2/3] pwm: bcm2835: prevent division by zero
2015-12-02 15:23 ` Mathieu Poirier
@ 2015-12-02 19:41 ` Eric Anholt
0 siblings, 0 replies; 12+ messages in thread
From: Eric Anholt @ 2015-12-02 19:41 UTC (permalink / raw)
To: linux-arm-kernel
Mathieu Poirier <mathieu.poirier@linaro.org> writes:
> On 1 December 2015 at 15:55, Stefan Wahren <stefan.wahren@i2se.com> wrote:
>> It's possible that the pwm clock become an orphan. So better
>> check the result of clk_get_rate in order to prevent a division
>> by zero.
>>
>> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
>> ---
>> drivers/pwm/pwm-bcm2835.c | 10 +++++++++-
>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
>> index 174cca9..31a6992 100644
>> --- a/drivers/pwm/pwm-bcm2835.c
>> +++ b/drivers/pwm/pwm-bcm2835.c
>> @@ -65,7 +65,15 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>> int duty_ns, int period_ns)
>> {
>> struct bcm2835_pwm *pc = to_bcm2835_pwm(chip);
>> - unsigned long scaler = NSEC_PER_SEC / clk_get_rate(pc->clk);
>> + unsigned long rate = clk_get_rate(pc->clk);
>> + unsigned long scaler;
>> +
>> + if (!rate) {
>> + dev_err(pc->dev, "failed to get clock rate\n");
>> + return -EINVAL;
>> + }
>> +
>> + scaler = NSEC_PER_SEC / rate;
>
> Stefan,
>
> Please merge this code into patch 1/3. That way it is done the right
> way the first time around.
They're separate changes and are good as separate patches.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151202/f419b922/attachment-0001.sig>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/3] pwm: bcm2835: fix email address specifiction
2015-12-01 22:55 [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
2015-12-01 22:55 ` [PATCH 1/3] pwm: bcm2835: calculate scaler in pwm_config Stefan Wahren
2015-12-01 22:55 ` [PATCH 2/3] pwm: bcm2835: prevent division by zero Stefan Wahren
@ 2015-12-01 22:55 ` Stefan Wahren
2015-12-15 17:59 ` [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
2015-12-16 15:38 ` Thierry Reding
4 siblings, 0 replies; 12+ messages in thread
From: Stefan Wahren @ 2015-12-01 22:55 UTC (permalink / raw)
To: linux-arm-kernel
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/pwm/pwm-bcm2835.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
index 31a6992..c5dbf16 100644
--- a/drivers/pwm/pwm-bcm2835.c
+++ b/drivers/pwm/pwm-bcm2835.c
@@ -206,6 +206,6 @@ static struct platform_driver bcm2835_pwm_driver = {
};
module_platform_driver(bcm2835_pwm_driver);
-MODULE_AUTHOR("Bart Tanghe <bart.tanghe at thomasmore.be");
+MODULE_AUTHOR("Bart Tanghe <bart.tanghe@thomasmore.be>");
MODULE_DESCRIPTION("Broadcom BCM2835 PWM driver");
MODULE_LICENSE("GPL v2");
--
1.7.9.5
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH 0/3] pwm: bcm2835: improve clock handling
2015-12-01 22:55 [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
` (2 preceding siblings ...)
2015-12-01 22:55 ` [PATCH 3/3] pwm: bcm2835: fix email address specifiction Stefan Wahren
@ 2015-12-15 17:59 ` Stefan Wahren
2015-12-15 18:24 ` Eric Anholt
2015-12-16 15:38 ` Thierry Reding
4 siblings, 1 reply; 12+ messages in thread
From: Stefan Wahren @ 2015-12-15 17:59 UTC (permalink / raw)
To: linux-arm-kernel
> Stefan Wahren <stefan.wahren@i2se.com> hat am 1. Dezember 2015 um 23:55
> geschrieben:
>
>
> With the upcoming PWM clock support the pwm-bcm2835 should take
> more care about the clock handling. But this patch series doesn't
> depend on these clock driver changes.
>
> Stefan Wahren (3):
> pwm: bcm2835: calculate scaler in pwm_config
> pwm: bcm2835: prevent division by zero
> pwm: bcm2835: fix email address specifiction
>
> drivers/pwm/pwm-bcm2835.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
gently ping
^ permalink raw reply [flat|nested] 12+ messages in thread* [PATCH 0/3] pwm: bcm2835: improve clock handling
2015-12-01 22:55 [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
` (3 preceding siblings ...)
2015-12-15 17:59 ` [PATCH 0/3] pwm: bcm2835: improve clock handling Stefan Wahren
@ 2015-12-16 15:38 ` Thierry Reding
4 siblings, 0 replies; 12+ messages in thread
From: Thierry Reding @ 2015-12-16 15:38 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Dec 01, 2015 at 10:55:38PM +0000, Stefan Wahren wrote:
> With the upcoming PWM clock support the pwm-bcm2835 should take
> more care about the clock handling. But this patch series doesn't
> depend on these clock driver changes.
>
> Stefan Wahren (3):
> pwm: bcm2835: calculate scaler in pwm_config
> pwm: bcm2835: prevent division by zero
> pwm: bcm2835: fix email address specifiction
>
> drivers/pwm/pwm-bcm2835.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
All three patches applied with Eric's Reviewed-by, thanks.
Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20151216/973a08fa/attachment-0001.sig>
^ permalink raw reply [flat|nested] 12+ messages in thread