Skip to contentSkip to conversation

spi: core: use gpio_request_one for configured gpio cs

PATCH In review Martin Hundebøll 5 participants 11 messages Jul 24, 2017 – Jul 27, 2017 5 messages not in the archive SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: core: use gpio_request_one for configured gpio cs

Some gpio controllers requires lines to be configured as outputs to make subsequent calls to gpio_set_value() have any effect.

Add a call to gpio_request_one() for configured gpio chip-selects to make it work on (at least) mvebu gpio controllers.

---
 drivers/spi/spi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/spi/spi.c +6 -1
index 0725c78b0de6..b7bfc52525aa 100644
@@ -2010,8 +2010,13 @@ static int of_spi_register_master(struct spi_controller *ctlr)
 	for (i = 0; i < ctlr->num_chipselect; i++)
 		cs[i] = -ENOENT;
 
-	for (i = 0; i < nb; i++)
+	for (i = 0; i < nb; i++) {
 		cs[i] = of_get_named_gpio(np, "cs-gpios", i);
+		if (gpio_is_valid(cs[i]) &&
+		    gpio_request_one(cs[i], 0, "spi-cs") < 0)
+			dev_warn(&master->dev,
+				 "gpio_request_one failed for chipselect %i\n", i);
+	}
 
 	return 0;
 }
Signature · 6 lines
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20170724095327.18602-1-mnhu-rjjw5hvvQKZaa/[email protected]

#2 lore raw

+Cc: Mika, Jarkko

Quoted 6 lines · Martin Hundebøll

Some gpio controllers requires lines to be configured as outputs to make subsequent calls to gpio_set_value() have any effect.

Add a call to gpio_request_one() for configured gpio chip-selects to make it work on (at least) mvebu gpio controllers.

More and more hacks around plain GPIO integers... :-(

Perhaps we need to discuss how to convert SPI core to use GPIO descriptors everywhere.

Quoted 31 lines
---
 drivers/spi/spi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/spi/spi.c +6 -2
index 0725c78b0de6..b7bfc52525aa 100644
@@ -2010,8 +2010,13 @@ static int of_spi_register_master(struct spi_controller *ctlr)
        for (i = 0; i < ctlr->num_chipselect; i++)
                cs[i] = -ENOENT;
 
-       for (i = 0; i < nb; i++)
+       for (i = 0; i < nb; i++) {
                cs[i] = of_get_named_gpio(np, "cs-gpios", i);
+               if (gpio_is_valid(cs[i]) &&
+                   gpio_request_one(cs[i], 0, "spi-cs") < 0)
+                       dev_warn(&master->dev,
+                                "gpio_request_one failed for chipselect %i\n", i);
+       }
 
        return 0;
 }
--

2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CAHp75VdQbw9rkxq0tvYquacYViZqWKAqOTKHjLPtP=uZi8zzsg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 5 lines · Martin Hundebøll

Some gpio controllers requires lines to be configured as outputs to make subsequent calls to gpio_set_value() have any effect.

Add a call to gpio_request_one() for configured gpio chip-selects to make it work on (at least) mvebu gpio controllers.

More and more hacks around plain GPIO integers... :-(

Perhaps we need to discuss how to convert SPI core to use GPIO descriptors everywhere.

The best way would be to test the work that Chris Packham submitted in May to do this, it'll need a refresh now and it ought to get some testing on ep93xx but sadly nobody working on ep93xx has responded - I think at this point I'd probably just apply and let people test -next.

#5 lore raw
Quoted 10 lines · Mark Brown
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Martin Hundebøll

Some gpio controllers requires lines to be configured as outputs to make subsequent calls to gpio_set_value() have any effect.

Add a call to gpio_request_one() for configured gpio chip-selects to make it work on (at least) mvebu gpio controllers.

More and more hacks around plain GPIO integers... :-(

Quoted 8 lines
Quoted 2 lines

Perhaps we need to discuss how to convert SPI core to use GPIO descriptors everywhere.

The best way would be to test the work that Chris Packham submitted in May to do this, it'll need a refresh now and it ought to get some testing on ep93xx but sadly nobody working on ep93xx has responded - I think at this point I'd probably just apply and let people test -next.

My patchset kind of stalled. I can do a refresh if there's interest. But I really do need some help from people with access to hardware (I can cover spi-orion and spi-fsl-espi but that's about it). After the initial RFC series I posted in May I found that iMX platforms use the integer cs_gpio field for both native chipselects and gpio based ones (values < 0 indicate native CS) so again I'd be coding blind trying to disentangle that.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): e668b7529837444085b9df3a563c3fe3-5g7mGxlPNYb6GjIOKuZY+ItlCAj8ZROq@public.gmane.org

#7 lore raw
Quoted 34 lines · Chris Packham
Quoted 2 lines · Mark Brown
Quoted 1 line · Andy Shevchenko

On Mon, Jul 24, 2017 at 12:53 PM, Martin Hundebøll <[email protected]>

Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line

Some gpio controllers requires lines to be configured as outputs to

make

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

subsequent calls to gpio_set_value() have any effect.

Add a call to gpio_request_one() for configured gpio chip-selects

to

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

make it work on (at least) mvebu gpio controllers.

More and more hacks around plain GPIO integers... :-(

Perhaps we need to discuss how to convert SPI core to use GPIO descriptors everywhere.

The best way would be to test the work that Chris Packham submitted

in

Quoted 2 lines

May to do this, it'll need a refresh now and it ought to get some testing on ep93xx but sadly nobody working on ep93xx has responded -

I

Quoted 1 line

think at this point I'd probably just apply and let people test

-next.

Quoted 1 line

My patchset kind of stalled. I can do a refresh if there's interest. But
I really do need some help from people with access to hardware (I can cover spi-orion and spi-fsl-espi but that's about it). After the initial
RFC series I posted in May I found that iMX platforms use the integer cs_gpio field for both native chipselects and gpio based ones (values <

Quoted 3 lines

0 indicate native CS) so again I'd be coding blind trying to disentangle
that.

My submission was more or less a fly-by patch, but I'd be happy to test/debug patches on spi-imx if you CC me on the series.

Any other drivers with special gpio-cs handling?

// Martin

Signature · 5 lines
Sent from my Android device with K-9 Mail. Please excuse my brevity.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
Quoted 10 lines · Martin Hundebøll
Quoted 7 lines

My patchset kind of stalled. I can do a refresh if there's interest. But I really do need some help from people with access to hardware (I can cover spi-orion and spi-fsl-espi but that's about it). After the initial RFC series I posted in May I found that iMX platforms use the integer cs_gpio field for both native chipselects and gpio based ones (values < 0 indicate native CS) so again I'd be coding blind trying to disentangle that.

My submission was more or less a fly-by patch, but I'd be happy to test/debug patches on spi-imx if you CC me on the series.

Thanks for the offer. Now I just need to get a few round tuits.

Quoted 3 lines

Any other drivers with special gpio-cs handling?

Based on a quick grep spi-{atmel,davinci,ep93xx,gpio,imx,mt65xx,stm32} all do stuff with cs_gpios outside of the spi core. I think at least some of those a trivially handled if we let the core code do the gpio management.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 3027e39333a24fa7a4ce540d96b0e6f3-5g7mGxlPNYb6GjIOKuZY+ItlCAj8ZROq@public.gmane.org

#10 lore raw
Quoted 9 lines · Chris Packham
Quoted 8 lines · Martin Hundebøll
Quoted 7 lines

My patchset kind of stalled. I can do a refresh if there's interest. But I really do need some help from people with access to hardware (I can cover spi-orion and spi-fsl-espi but that's about it). After the initial RFC series I posted in May I found that iMX platforms use the integer cs_gpio field for both native chipselects and gpio based ones (values < 0 indicate native CS) so again I'd be coding blind trying to disentangle that.

Quoted 4 lines
Quoted 2 lines

My submission was more or less a fly-by patch, but I'd be happy to test/debug patches on spi-imx if you CC me on the series.

Thanks for the offer. Now I just need to get a few round tuits.

Can you please, resend the latest you have with Cc'ing me?

Quoted 7 lines
Quoted 2 lines

Any other drivers with special gpio-cs handling?

Based on a quick grep spi-{atmel,davinci,ep93xx,gpio,imx,mt65xx,stm32} all do stuff with cs_gpios outside of the spi core. I think at least some of those a trivially handled if we let the core code do the gpio management.

I have got ep93xx board from Mika to test, so, I can perhaps perform tests later, after I got pxa2xx working.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw
Quoted 21 lines · Andy Shevchenko
Quoted 9 lines · Chris Packham
Quoted 8 lines · Martin Hundebøll
Quoted 7 lines

My patchset kind of stalled. I can do a refresh if there's interest. But I really do need some help from people with access to hardware (I can cover spi-orion and spi-fsl-espi but that's about it). After the initial RFC series I posted in May I found that iMX platforms use the integer cs_gpio field for both native chipselects and gpio based ones (values < 0 indicate native CS) so again I'd be coding blind trying to disentangle that.

Quoted 4 lines
Quoted 2 lines

My submission was more or less a fly-by patch, but I'd be happy to test/debug patches on spi-imx if you CC me on the series.

Thanks for the offer. Now I just need to get a few round tuits.

Can you please, resend the latest you have with Cc'ing me?

Quoted 3 lines
Quoted 2 lines

Any other drivers with special gpio-cs handling?

Quoted 8 lines
Quoted 4 lines

Based on a quick grep spi-{atmel,davinci,ep93xx,gpio,imx,mt65xx,stm32} all do stuff with cs_gpios outside of the spi core. I think at least some of those a trivially handled if we let the core code do the gpio management.

I have got ep93xx board from Mika to test, so, I can perhaps perform tests later, after I got pxa2xx working.

Sure I'll rebase the series against linux-next#master I notice there is a rename of some variables in areas I'm touching.

Should come through shortly.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw
In reply to a message not in the archive
Quoted 10 lines · Chris Packham
Quoted 4 lines · Mark Brown

The best way would be to test the work that Chris Packham submitted in May to do this, it'll need a refresh now and it ought to get some testing on ep93xx but sadly nobody working on ep93xx has responded - I think at this point I'd probably just apply and let people test -next.

My patchset kind of stalled. I can do a refresh if there's interest. But I really do need some help from people with access to hardware (I can cover spi-orion and spi-fsl-espi but that's about it). After the initial

It's definitely something that'd be really helpful. If we get it merged near the start of a development cycle that should give plenty of opportunities for people to test.

Quoted 4 lines

RFC series I posted in May I found that iMX platforms use the integer cs_gpio field for both native chipselects and gpio based ones (values < 0 indicate native CS) so again I'd be coding blind trying to disentangle that.

i.MX is actively developed (even the SPI driver in particular) so that should be no problem at least.

A message that is not in the archive (sent off-list or not yet received): 20170724120249.mpyv7f3t4q3eihrg-GFdadSzt00ze9xe1eoZjHA@public.gmane.org

#15 lore raw
Quoted 6 lines · Mark Brown
Quoted 1 line · Andy Shevchenko

More and more hacks around plain GPIO integers... :-(

I have to say now I've looked at the patch I'm also struggling to see how this is a hack around anything...

In case we switch to GPIO descriptors we can do a generic CS allocation / request. The part in the patch does something witch would be used only in OF case, while ACPI or built-in device properties are missing.

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html