* [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
@ 2015-04-27 3:44 ` Michael Welling
0 siblings, 0 replies; 16+ messages in thread
From: Michael Welling @ 2015-04-27 3:44 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A, linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Cc: Michael Welling
This patch allows for GPIOs specified in the devicetree to be used as SPI
chipselects on TI OMAP2 SoCs.
Tested on the AM3354.
Signed-off-by: Michael Welling <mwelling-EkmVulN54Sk@public.gmane.org>
---
v2: Considers the possible use of SPI_CS_HIGH during chip select activation.
drivers/spi/spi-omap2-mcspi.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index d1a5b9f..5e388a8 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -35,6 +35,7 @@
#include <linux/gcd.h>
#include <linux/spi/spi.h>
+#include <linux/gpio.h>
#include <linux/platform_data/spi-omap2-mcspi.h>
@@ -246,6 +247,12 @@ static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active)
{
u32 l;
+ if (gpio_is_valid(spi->cs_gpio)) {
+ gpio_set_value(spi->cs_gpio, (cs_active) ?
+ !!(spi->mode & SPI_CS_HIGH) :
+ !(spi->mode & SPI_CS_HIGH));
+ }
+
l = mcspi_cached_chconf0(spi);
if (cs_active)
l |= OMAP2_MCSPI_CHCONF_FORCE;
@@ -1015,6 +1022,12 @@ static int omap2_mcspi_setup(struct spi_device *spi)
if (ret < 0)
return ret;
+ if (gpio_is_valid(spi->cs_gpio)) {
+ if (gpio_request(spi->cs_gpio, dev_name(&spi->dev)) == 0)
+ gpio_direction_output(spi->cs_gpio,
+ !(spi->mode & SPI_CS_HIGH));
+ }
+
ret = omap2_mcspi_setup_transfer(spi, NULL);
pm_runtime_mark_last_busy(mcspi->dev);
pm_runtime_put_autosuspend(mcspi->dev);
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
@ 2015-04-27 3:44 ` Michael Welling
0 siblings, 0 replies; 16+ messages in thread
From: Michael Welling @ 2015-04-27 3:44 UTC (permalink / raw)
To: broonie, linux-spi, linux-kernel; +Cc: Michael Welling
This patch allows for GPIOs specified in the devicetree to be used as SPI
chipselects on TI OMAP2 SoCs.
Tested on the AM3354.
Signed-off-by: Michael Welling <mwelling@ieee.org>
---
v2: Considers the possible use of SPI_CS_HIGH during chip select activation.
drivers/spi/spi-omap2-mcspi.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
index d1a5b9f..5e388a8 100644
--- a/drivers/spi/spi-omap2-mcspi.c
+++ b/drivers/spi/spi-omap2-mcspi.c
@@ -35,6 +35,7 @@
#include <linux/gcd.h>
#include <linux/spi/spi.h>
+#include <linux/gpio.h>
#include <linux/platform_data/spi-omap2-mcspi.h>
@@ -246,6 +247,12 @@ static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active)
{
u32 l;
+ if (gpio_is_valid(spi->cs_gpio)) {
+ gpio_set_value(spi->cs_gpio, (cs_active) ?
+ !!(spi->mode & SPI_CS_HIGH) :
+ !(spi->mode & SPI_CS_HIGH));
+ }
+
l = mcspi_cached_chconf0(spi);
if (cs_active)
l |= OMAP2_MCSPI_CHCONF_FORCE;
@@ -1015,6 +1022,12 @@ static int omap2_mcspi_setup(struct spi_device *spi)
if (ret < 0)
return ret;
+ if (gpio_is_valid(spi->cs_gpio)) {
+ if (gpio_request(spi->cs_gpio, dev_name(&spi->dev)) == 0)
+ gpio_direction_output(spi->cs_gpio,
+ !(spi->mode & SPI_CS_HIGH));
+ }
+
ret = omap2_mcspi_setup_transfer(spi, NULL);
pm_runtime_mark_last_busy(mcspi->dev);
pm_runtime_put_autosuspend(mcspi->dev);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 16+ messages in thread[parent not found: <1430106270-17142-1-git-send-email-mwelling-EkmVulN54Sk@public.gmane.org>]
* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
2015-04-27 3:44 ` Michael Welling
@ 2015-04-27 19:55 ` Mark Brown
-1 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2015-04-27 19:55 UTC (permalink / raw)
To: Michael Welling
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
> + if (gpio_is_valid(spi->cs_gpio)) {
> + gpio_set_value(spi->cs_gpio, (cs_active) ?
> + !!(spi->mode & SPI_CS_HIGH) :
> + !(spi->mode & SPI_CS_HIGH));
> + }
Two problems here. One is that the above logic statement is just not
readable (the repitition of hecks, the ternery operator, the
indentation...) and the other is that the core chipselect support
already handles GPIO chipselects so you should really be converting the
driver to use that. At the very least the code needs to be legible
though.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
@ 2015-04-27 19:55 ` Mark Brown
0 siblings, 0 replies; 16+ messages in thread
From: Mark Brown @ 2015-04-27 19:55 UTC (permalink / raw)
To: Michael Welling; +Cc: linux-spi, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
> + if (gpio_is_valid(spi->cs_gpio)) {
> + gpio_set_value(spi->cs_gpio, (cs_active) ?
> + !!(spi->mode & SPI_CS_HIGH) :
> + !(spi->mode & SPI_CS_HIGH));
> + }
Two problems here. One is that the above logic statement is just not
readable (the repitition of hecks, the ternery operator, the
indentation...) and the other is that the core chipselect support
already handles GPIO chipselects so you should really be converting the
driver to use that. At the very least the code needs to be legible
though.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread[parent not found: <20150427195550.GE22845-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>]
* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
2015-04-27 19:55 ` Mark Brown
@ 2015-04-28 1:21 ` Michael Welling
-1 siblings, 0 replies; 16+ messages in thread
From: Michael Welling @ 2015-04-28 1:21 UTC (permalink / raw)
To: Mark Brown
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Mon, Apr 27, 2015 at 08:55:50PM +0100, Mark Brown wrote:
> On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
>
> > + if (gpio_is_valid(spi->cs_gpio)) {
> > + gpio_set_value(spi->cs_gpio, (cs_active) ?
> > + !!(spi->mode & SPI_CS_HIGH) :
> > + !(spi->mode & SPI_CS_HIGH));
> > + }
>
> Two problems here. One is that the above logic statement is just not
> readable (the repitition of hecks, the ternery operator, the
> indentation...) and the other is that the core chipselect support
> already handles GPIO chipselects so you should really be converting the
> driver to use that. At the very least the code needs to be legible
> though.
Before I send another patch how does this look?
if (gpio_is_valid(spi->cs_gpio)) {
if (cs_active)
gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
else
gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
}
If I were to attempt to convert the driver to use the core chipselect support,
how would I go about doing it?
Is there another driver that I can use for reference?
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
@ 2015-04-28 1:21 ` Michael Welling
0 siblings, 0 replies; 16+ messages in thread
From: Michael Welling @ 2015-04-28 1:21 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-spi, linux-kernel
On Mon, Apr 27, 2015 at 08:55:50PM +0100, Mark Brown wrote:
> On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
>
> > + if (gpio_is_valid(spi->cs_gpio)) {
> > + gpio_set_value(spi->cs_gpio, (cs_active) ?
> > + !!(spi->mode & SPI_CS_HIGH) :
> > + !(spi->mode & SPI_CS_HIGH));
> > + }
>
> Two problems here. One is that the above logic statement is just not
> readable (the repitition of hecks, the ternery operator, the
> indentation...) and the other is that the core chipselect support
> already handles GPIO chipselects so you should really be converting the
> driver to use that. At the very least the code needs to be legible
> though.
Before I send another patch how does this look?
if (gpio_is_valid(spi->cs_gpio)) {
if (cs_active)
gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
else
gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
}
If I were to attempt to convert the driver to use the core chipselect support,
how would I go about doing it?
Is there another driver that I can use for reference?
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
2015-04-28 1:21 ` Michael Welling
(?)
@ 2015-04-28 5:32 ` Martin Sperl
[not found] ` <55B19D93-B930-4363-9D44-0E97B4B836BF-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
-1 siblings, 1 reply; 16+ messages in thread
From: Martin Sperl @ 2015-04-28 5:32 UTC (permalink / raw)
To: Michael Welling; +Cc: Mark Brown, linux-spi, linux-kernel
> On 28.04.2015, at 03:21, Michael Welling <mwelling@ieee.org> wrote:
> If I were to attempt to convert the driver to use the core chipselect support,
> how would I go about doing it?
>
> Is there another driver that I can use for reference?
You may look into this patch: e34ff011c70e5f4ef219141711142d5111ae6ebb
for the spi-bcm2835 driver, which did the conversion to the new transfer_one
interface (and framework based GPIO chipselects).
For most parts all you have to do is take the contents of the loop over all the
spi_transfers inside your master->transfer_one_message method and create a new
method with it and assign it to master->transfer_one.
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
2015-04-28 1:21 ` Michael Welling
@ 2015-04-28 14:04 ` Ezequiel Garcia
-1 siblings, 0 replies; 16+ messages in thread
From: Ezequiel Garcia @ 2015-04-28 14:04 UTC (permalink / raw)
To: Michael Welling
Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On 04/27/2015 10:21 PM, Michael Welling wrote:
> On Mon, Apr 27, 2015 at 08:55:50PM +0100, Mark Brown wrote:
>> On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
>>
>>> + if (gpio_is_valid(spi->cs_gpio)) {
>>> + gpio_set_value(spi->cs_gpio, (cs_active) ?
>>> + !!(spi->mode & SPI_CS_HIGH) :
>>> + !(spi->mode & SPI_CS_HIGH));
>>> + }
>>
>> Two problems here. One is that the above logic statement is just not
>> readable (the repitition of hecks, the ternery operator, the
>> indentation...) and the other is that the core chipselect support
>> already handles GPIO chipselects so you should really be converting the
>> driver to use that. At the very least the code needs to be legible
>> though.
>
> Before I send another patch how does this look?
>
> if (gpio_is_valid(spi->cs_gpio)) {
> if (cs_active)
> gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
> else
> gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
> }
>
> If I were to attempt to convert the driver to use the core chipselect support,
> how would I go about doing it?
>
> Is there another driver that I can use for reference?
We've recently done that for spi-img-spfi.c.
--
Ezequiel
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
@ 2015-04-28 14:04 ` Ezequiel Garcia
0 siblings, 0 replies; 16+ messages in thread
From: Ezequiel Garcia @ 2015-04-28 14:04 UTC (permalink / raw)
To: Michael Welling; +Cc: Mark Brown, linux-spi, linux-kernel
On 04/27/2015 10:21 PM, Michael Welling wrote:
> On Mon, Apr 27, 2015 at 08:55:50PM +0100, Mark Brown wrote:
>> On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
>>
>>> + if (gpio_is_valid(spi->cs_gpio)) {
>>> + gpio_set_value(spi->cs_gpio, (cs_active) ?
>>> + !!(spi->mode & SPI_CS_HIGH) :
>>> + !(spi->mode & SPI_CS_HIGH));
>>> + }
>>
>> Two problems here. One is that the above logic statement is just not
>> readable (the repitition of hecks, the ternery operator, the
>> indentation...) and the other is that the core chipselect support
>> already handles GPIO chipselects so you should really be converting the
>> driver to use that. At the very least the code needs to be legible
>> though.
>
> Before I send another patch how does this look?
>
> if (gpio_is_valid(spi->cs_gpio)) {
> if (cs_active)
> gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
> else
> gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
> }
>
> If I were to attempt to convert the driver to use the core chipselect support,
> how would I go about doing it?
>
> Is there another driver that I can use for reference?
We've recently done that for spi-img-spfi.c.
--
Ezequiel
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
2015-04-28 14:04 ` Ezequiel Garcia
(?)
@ 2015-04-28 22:50 ` Michael Welling
-1 siblings, 0 replies; 16+ messages in thread
From: Michael Welling @ 2015-04-28 22:50 UTC (permalink / raw)
To: Ezequiel Garcia; +Cc: Mark Brown, linux-spi, linux-kernel
On Tue, Apr 28, 2015 at 11:04:09AM -0300, Ezequiel Garcia wrote:
> On 04/27/2015 10:21 PM, Michael Welling wrote:
> > On Mon, Apr 27, 2015 at 08:55:50PM +0100, Mark Brown wrote:
> >> On Sun, Apr 26, 2015 at 10:44:30PM -0500, Michael Welling wrote:
> >>
> >>> + if (gpio_is_valid(spi->cs_gpio)) {
> >>> + gpio_set_value(spi->cs_gpio, (cs_active) ?
> >>> + !!(spi->mode & SPI_CS_HIGH) :
> >>> + !(spi->mode & SPI_CS_HIGH));
> >>> + }
> >>
> >> Two problems here. One is that the above logic statement is just not
> >> readable (the repitition of hecks, the ternery operator, the
> >> indentation...) and the other is that the core chipselect support
> >> already handles GPIO chipselects so you should really be converting the
> >> driver to use that. At the very least the code needs to be legible
> >> though.
> >
> > Before I send another patch how does this look?
> >
> > if (gpio_is_valid(spi->cs_gpio)) {
> > if (cs_active)
> > gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
> > else
> > gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
> > }
> >
> > If I were to attempt to convert the driver to use the core chipselect support,
> > how would I go about doing it?
> >
> > Is there another driver that I can use for reference?
>
> We've recently done that for spi-img-spfi.c.
>
Okay, thanks for pointing that out.
> --
> Ezequiel
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects
2015-04-28 1:21 ` Michael Welling
` (2 preceding siblings ...)
(?)
@ 2015-04-28 14:34 ` Mark Brown
[not found] ` <20150428143425.GS22845-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
-1 siblings, 1 reply; 16+ messages in thread
From: Mark Brown @ 2015-04-28 14:34 UTC (permalink / raw)
To: Michael Welling; +Cc: linux-spi, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 697 bytes --]
On Mon, Apr 27, 2015 at 08:21:50PM -0500, Michael Welling wrote:
> Before I send another patch how does this look?
> if (gpio_is_valid(spi->cs_gpio)) {
> if (cs_active)
> gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
> else
> gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
> }
That's good but please have braces around the inner if for clarity.
> If I were to attempt to convert the driver to use the core chipselect support,
> how would I go about doing it?
> Is there another driver that I can use for reference?
Martin and Ezequiel already gave you some good examples - in general
anything providing the set_cs() operation should be reasonable to look
at.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2015-04-29 10:47 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-27 3:44 [PATCH v2] spi: omap2-mcspi: Add support for GPIO chipselects Michael Welling
2015-04-27 3:44 ` Michael Welling
[not found] ` <1430106270-17142-1-git-send-email-mwelling-EkmVulN54Sk@public.gmane.org>
2015-04-27 19:55 ` Mark Brown
2015-04-27 19:55 ` Mark Brown
[not found] ` <20150427195550.GE22845-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-04-28 1:21 ` Michael Welling
2015-04-28 1:21 ` Michael Welling
2015-04-28 5:32 ` Martin Sperl
[not found] ` <55B19D93-B930-4363-9D44-0E97B4B836BF-d5rIkyn9cnPYtjvyW6yDsg@public.gmane.org>
2015-04-28 22:49 ` Michael Welling
2015-04-28 22:49 ` Michael Welling
2015-04-28 14:04 ` Ezequiel Garcia
2015-04-28 14:04 ` Ezequiel Garcia
2015-04-28 22:50 ` Michael Welling
2015-04-28 14:34 ` Mark Brown
[not found] ` <20150428143425.GS22845-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-04-28 23:06 ` Michael Welling
2015-04-28 23:06 ` Michael Welling
2015-04-29 10:47 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.