Skip to contentSkip to conversation

gpio: mvebu: fixes for PWM/blink

PATCH In review Richard Genoud 4 participants 10 messages Jun 1, 2017 – Jun 12, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover gpio: mvebu: fixes for PWM/blink

These are 2 fixes for gpio-mvebu, related to the PWM support introduced by commit 757642f9a584 ("gpio: mvebu: Add limited PWM support") As that commit was merged in 4.12-rc1, I guess these commits are 4.12 material.

Changes from v1:
- Add tags Fixes: and Reviewed-by:
- Add some comments to motivate the mvpwm->chip->base = -1 choice
instead of mvpwm->chip->base = mvchip->chip.base

Richard Genoud (2):
gpio: mvebu: fix blink counter register selection
gpio: mvebu: fix gpio bank registration when pwm is used

 drivers/gpio/gpio-mvebu.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
#1 lore raw

PATCH v2 1/2 gpio: mvebu: fix blink counter register selection

The blink counter A was always selected because 0 was forced in the blink select counter register.
The variable 'set' was obviously there to be used as the register value, selecting the B counter when id==1 and A counter when id==0.

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")
---
 drivers/gpio/gpio-mvebu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-mvebu.c +1 -1
index 19a92efabbef..cdef2c78cb3b 100644
@@ -747,7 +747,7 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
 		set = U32_MAX;
 	else
 		return -EINVAL;
-	writel_relaxed(0, mvebu_gpioreg_blink_counter_select(mvchip));
+	writel_relaxed(set, mvebu_gpioreg_blink_counter_select(mvchip));
 
 	mvpwm = devm_kzalloc(dev, sizeof(struct mvebu_pwm), GFP_KERNEL);
 	if (!mvpwm)
#7 lore raw

PATCH v2 2/2 gpio: mvebu: fix gpio bank registration when pwm is used

In reply to Richard Genoud

If more than one gpio bank has the "pwm" property, only one will be registered successfully, all the others will fail with:
mvebu-gpio: probe of f1018140.gpio failed with error -17

That's because in alloc_pwms(), the chip->base (aka "int pwm"), was not set (thus, ==0) ; and 0 is a meaningful start value in alloc_pwm(). What was intended is mvpwm->chip->base = -1.
Like that, the numbering will be done auto-magically

Moreover, as the region might be already occupied by another pwm, we shouldn't force:
mvpwm->chip->base = 0
nor
mvpwm->chip->base = id * MVEBU_MAX_GPIO_PER_BANK;

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")
---
 drivers/gpio/gpio-mvebu.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpio/gpio-mvebu.c +7 -0
index cdef2c78cb3b..5104b6398139 100644
@@ -768,6 +768,13 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
 	mvpwm->chip.dev = dev;
 	mvpwm->chip.ops = &mvebu_pwm_ops;
 	mvpwm->chip.npwm = mvchip->chip.ngpio;
+	/*
+	 * There may already be some PWM allocated, so we can't force
+	 * mvpwm->chip.base to a fixed point like mvchip->chip.base.
+	 * So, we let pwmchip_add() do the numbering and take the next free
+	 * region.
+	 */
+	mvpwm->chip.base = -1;
 
 	spin_lock_init(&mvpwm->lock);
 
Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCHv2 2/2] gpio: mvebu: fix gpio bank registration when pwm is used

Hi Richard,

Quoted 15 lines · Richard Genoud

If more than one gpio bank has the "pwm" property, only one will be registered successfully, all the others will fail with:
mvebu-gpio: probe of f1018140.gpio failed with error -17

That's because in alloc_pwms(), the chip->base (aka "int pwm"), was not set (thus, ==0) ; and 0 is a meaningful start value in alloc_pwm(). What was intended is mvpwm->chip->base = -1.
Like that, the numbering will be done auto-magically

Moreover, as the region might be already occupied by another pwm, we shouldn't force:
mvpwm->chip->base = 0
nor
mvpwm->chip->base = id * MVEBU_MAX_GPIO_PER_BANK;

Quoted 4 lines

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")

Thanks,

Gregory

Quoted 22 lines
---
 drivers/gpio/gpio-mvebu.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpio/gpio-mvebu.c +7 -0
index cdef2c78cb3b..5104b6398139 100644
@@ -768,6 +768,13 @@ static int mvebu_pwm_probe(struct platform_device *pdev,
 	mvpwm->chip.dev = dev;
 	mvpwm->chip.ops = &mvebu_pwm_ops;
 	mvpwm->chip.npwm = mvchip->chip.ngpio;
+	/*
+	 * There may already be some PWM allocated, so we can't force
+	 * mvpwm->chip.base to a fixed point like mvchip->chip.base.
+	 * So, we let pwmchip_add() do the numbering and take the next free
+	 * region.
+	 */
+	mvpwm->chip.base = -1;
 
 	spin_lock_init(&mvpwm->lock);
 
Signature · 4 lines
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#2 lore raw

Re: [PATCHv2 1/2] gpio: mvebu: fix blink counter register selection

In reply to Richard Genoud
Quoted 11 lines · Richard Genoud

The blink counter A was always selected because 0 was forced in the blink select counter register.
The variable 'set' was obviously there to be used as the register value, selecting the B counter when id==1 and A counter when id==0.

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")

Patch applied for fixes.

It appears this will clash with patches on the development branch :(

I might screw up the merges so help me check the end result later.

Yours,
Linus Walleij

#9 lore raw

Re: [PATCHv2 2/2] gpio: mvebu: fix gpio bank registration when pwm is used

In reply to Richard Genoud
Quoted 15 lines · Richard Genoud

If more than one gpio bank has the "pwm" property, only one will be registered successfully, all the others will fail with:
mvebu-gpio: probe of f1018140.gpio failed with error -17

That's because in alloc_pwms(), the chip->base (aka "int pwm"), was not set (thus, ==0) ; and 0 is a meaningful start value in alloc_pwm(). What was intended is mvpwm->chip->base = -1.
Like that, the numbering will be done auto-magically

Moreover, as the region might be already occupied by another pwm, we shouldn't force:
mvpwm->chip->base = 0
nor
mvpwm->chip->base = id * MVEBU_MAX_GPIO_PER_BANK;

Quoted 4 lines

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")

Patch applied for fixes with Gregory's review tag.

Yours,
Linus Walleij

#3 lore raw

Re: [PATCHv2 1/2] gpio: mvebu: fix blink counter register selection

In reply to Linus Walleij

2017-06-09 9:37 GMT+02:00 Linus Walleij <[email protected]>:

Quoted 14 lines · Richard Genoud
Quoted 6 lines

The blink counter A was always selected because 0 was forced in the blink select counter register.
The variable 'set' was obviously there to be used as the register value, selecting the B counter when id==1 and A counter when id==0.

Quoted 6 lines

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Quoted 6 lines

Patch applied for fixes.

It appears this will clash with patches on the development branch :(

I might screw up the merges so help me check the end result later.

Ok, no problem !

Quoted 3 lines

Yours,
Linus Walleij

Thanks !
Richard.

#4 lore raw

Re: [PATCHv2 1/2] gpio: mvebu: fix blink counter register selection

In reply to Linus Walleij
Quoted 10 lines · On Fri, 9 Jun 2017 09:37:55 +0200 Linus Walleij <[email protected]>…
Quoted 7 lines · Richard Genoud

The blink counter A was always selected because 0 was forced in the blink select counter register.
The variable 'set' was obviously there to be used as the register value, selecting the B counter when id==1 and A counter when id==0.

Tested on clearfog-pro (Marvell 88F6828)

Quoted 8 lines
Quoted 4 lines
Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")

Patch applied for fixes.

It appears this will clash with patches on the development branch :(

Hi Linus,

The commit 2233bf7a92e7 ("gpio: mvebu: switch to regmap for register access") which you likely mean breaks gpio-keys, reported about an hour ago, so you might just want to drop that one for now instead as it needs mor work anyway.

Ralph

#5 lore raw

Re: [PATCHv2 1/2] gpio: mvebu: fix blink counter register selection

Quoted 20 lines · Ralph Sennhauser
Quoted 17 lines · On Fri, 9 Jun 2017 09:37:55 +0200 Linus Walleij <[email protected]>…
Quoted 11 lines · Richard Genoud

The blink counter A was always selected because 0 was forced in the blink select counter register.
The variable 'set' was obviously there to be used as the register value, selecting the B counter when id==1 and A counter when id==0.

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")

Patch applied for fixes.

Quoted 8 lines
Quoted 1 line

It appears this will clash with patches on the development branch :(

Hi Linus,

The commit 2233bf7a92e7 ("gpio: mvebu: switch to regmap for register access") which you likely mean breaks gpio-keys, reported about an hour ago, so you might just want to drop that one for now instead as it needs mor work anyway.

I would like to get an indication from Thomas and/or Gregory if they think it is a good idea to revert or if they just wanna fix it.

We still have development time before we even start merging for v4.13 and then we have all the release candidates. No point to throw up hands this early?

Yours,
Linus Walleij

#6 lore raw

Re: [PATCHv2 1/2] gpio: mvebu: fix blink counter register selection

Hi Linus,

Quoted 28 lines · On Sun, 11 Jun 2017 23:48:34 +0200 Linus Walleij <[email protected]>…
Quoted 26 lines · Ralph Sennhauser
Quoted 16 lines · On Fri, 9 Jun 2017 09:37:55 +0200 Linus Walleij <[email protected]>…
Quoted 6 lines · Richard Genoud

The blink counter A was always selected because 0 was forced in the blink select counter register.
The variable 'set' was obviously there to be used as the register value, selecting the B counter when id==1 and A counter when id==0.

Quoted 6 lines

Tested on clearfog-pro (Marvell 88F6828)

Fixes 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Quoted 4 lines

Patch applied for fixes.

It appears this will clash with patches on the development branch :(

Hi Linus,

Quoted 7 lines
Quoted 4 lines

The commit 2233bf7a92e7 ("gpio: mvebu: switch to regmap for register access") which you likely mean breaks gpio-keys, reported about an hour ago, so you might just want to drop that one for now instead as it needs mor work anyway.

I would like to get an indication from Thomas and/or Gregory if they think it is a good idea to revert or if they just wanna fix it.

A fix patch by Gregory exists by now ([PATCH v2] gpio: mvebu: fix regmap_update_bits usage).

Quoted 3 lines

We still have development time before we even start merging for v4.13 and then we have all the release candidates. No point to throw up hands this early?

Ah, not throwing hands. Just thought the author might prefer to rebase the patch himself when fixing the bug so there is just one clean patch for the change as there is still enough time for that before the merge window opens.

Ralph