Skip to contentSkip to conversation

SPI: spi-gpio: store chipselect information in private structure

PATCH RESEND Applied Daniel Mack 3 participants 11 messages Aug 1, 2012 – Sep 5, 2012 9 messages not in the archive

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

PATCH RESEND 1/2 SPI: spi-gpio: store chipselect information in private structure

The spi-gpio driver currently assumes the chipselect gpio number is stored in ->controller_data of the device's static board information.

In devicetree environments, this information is unavailable and has to be derived from the DT node.

This patch moves the gpio storage to the controller's private data so the DT bindings can easily build upon the driver.

Cc Mark Brown <broonie-yzvPICuk2AATkU/[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Linus Walleij <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>
---
 drivers/spi/spi-gpio.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/spi/spi-gpio.c +24 -10
index 0b56cfc..ff7263c 100644
@@ -46,6 +46,7 @@ struct spi_gpio {
 	struct spi_bitbang		bitbang;
 	struct spi_gpio_platform_data	pdata;
 	struct platform_device		*pdev;
+	int				cs_gpios[0];
 };
 
 /*----------------------------------------------------------------------*/
@@ -89,15 +90,21 @@ struct spi_gpio {
 
 /*----------------------------------------------------------------------*/
 
-static inline const struct spi_gpio_platform_data * __pure
-spi_to_pdata(const struct spi_device *spi)
+static inline struct spi_gpio * __pure
+spi_to_spi_gpio(const struct spi_device *spi)
 {
 	const struct spi_bitbang	*bang;
-	const struct spi_gpio		*spi_gpio;
+	struct spi_gpio			*spi_gpio;
 
 	bang = spi_master_get_devdata(spi->master);
 	spi_gpio = container_of(bang, struct spi_gpio, bitbang);
-	return &spi_gpio->pdata;
+	return spi_gpio;
+}
+
+static inline struct spi_gpio_platform_data * __pure
+spi_to_pdata(const struct spi_device *spi)
+{
+	return &spi_to_spi_gpio(spi)->pdata;
 }
 
 /* this is #defined to avoid unused-variable warnings when inlining */
@@ -210,7 +217,8 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi,
 
 static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
 {
-	unsigned long cs = (unsigned long) spi->controller_data;
+	struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
+	unsigned int cs = spi_gpio->cs_gpios[spi->chip_select];
 
 	/* set initial clock polarity */
 	if (is_active)
@@ -224,8 +232,9 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active)
 
 static int spi_gpio_setup(struct spi_device *spi)
 {
-	unsigned long	cs = (unsigned long) spi->controller_data;
-	int		status = 0;
+	unsigned int		cs = (unsigned int) spi->controller_data;
+	int			status = 0;
+	struct spi_gpio		*spi_gpio = spi_to_spi_gpio(spi);
 
 	if (spi->bits_per_word > 32)
 		return -EINVAL;
@@ -239,8 +248,11 @@ static int spi_gpio_setup(struct spi_device *spi)
 					!(spi->mode & SPI_CS_HIGH));
 		}
 	}
-	if (!status)
+	if (!status) {
 		status = spi_bitbang_setup(spi);
+		spi_gpio->cs_gpios[spi->chip_select] = cs;
+	}
+
 	if (status) {
 		if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT)
 			gpio_free(cs);
@@ -250,7 +262,8 @@ static int spi_gpio_setup(struct spi_device *spi)
 
 static void spi_gpio_cleanup(struct spi_device *spi)
 {
-	unsigned long	cs = (unsigned long) spi->controller_data;
+	struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi);
+	unsigned int cs = spi_gpio->cs_gpios[spi->chip_select];
 
 	if (cs != SPI_GPIO_NO_CHIPSELECT)
 		gpio_free(cs);
@@ -331,7 +344,8 @@ static int __devinit spi_gpio_probe(struct platform_device *pdev)
 	if (status < 0)
 		return status;
 
-	master = spi_alloc_master(&pdev->dev, sizeof *spi_gpio);
+	master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) +
+					(sizeof(int) * SPI_N_CHIPSEL));
 	if (!master) {
 		status = -ENOMEM;
 		goto gpio_free;
Signature · 9 lines
1.7.11.2


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
#2 lore raw

PATCH RESEND 2/2 SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive

This patch adds DT bindings to the spi-gpio driver and some documentation about how to use it.

Cc Mark Brown <broonie-yzvPICuk2AATkU/[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Linus Walleij <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>
---
 Documentation/devicetree/bindings/spi/spi-gpio.txt | 29 +++++++
 drivers/spi/spi-gpio.c                             | 99 +++++++++++++++++++++-
 2 files changed, 125 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-gpio.txt
Documentation/devicetree/bindings/spi/spi-gpio.txt new file +29 -0
new file mode 100644
index 0000000..8a824be
@@ -0,0 +1,29 @@
+SPI-GPIO devicetree bindings
+
+Required properties:
+
+ - compatible: should be set to "spi-gpio"
+ - #address-cells: should be set to <0x1>
+ - ranges
+ - gpio-sck: GPIO spec for the SCK line to use
+ - gpio-miso: GPIO spec for the MISO line to use
+ - gpio-mosi: GPIO spec for the MOSI line to use
+ - cs-gpios: GPIOs to use for chipselect lines
+ - num-chipselects: number of chipselect lines
+
+Example:
+
+	spi {
+		compatible = "spi-gpio";
+		#address-cells = <0x1>;
+		ranges;
+
+		gpio-sck = <&gpio 95 0>;
+		gpio-miso = <&gpio 98 0>;
+		gpio-mosi = <&gpio 97 0>;
+		cs-gpios = <&gpio 125 0>;
+		num-chipselects = <1>;
+
+		/* clients */
+	};
+
drivers/spi/spi-gpio.c +96 -3

147 lines not on this page · raw message

Signature · 9 lines
1.7.11.2


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Applied
#17 lore raw
In reply to a message not in the archive
Quoted 2 lines · Daniel Mack

The spi-gpio driver currently assumes the chipselect gpio number is stored in ->controller_data of the device's static board information.

Applied both, thanks. It's a bit sad that we need an explict property for num-chipselects though.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

Acked-by
#4 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 9 lines · Daniel Mack

This patch adds DT bindings to the spi-gpio driver and some documentation about how to use it.

Cc Mark Brown <broonie-yzvPICuk2AATkU/[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Linus Walleij <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>

From a GPIO point of view this looks good to me.

Yours,
Linus Walleij

#6 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 5 lines · Linus Walleij
Quoted 3 lines · Daniel Mack

This patch adds DT bindings to the spi-gpio driver and some documentation about how to use it.

Quoted 8 lines
Quoted 4 lines
Cc Mark Brown <broonie-yzvPICuk2AATkU/[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>
Cc Linus Walleij <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>

From a GPIO point of view this looks good to me.

Ok, thanks. Mark, did the patches reach you this time? I think they should go thru the SPI tree.

Thanks,
Daniel

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#19 lore raw
In reply to a message not in the archive
Quoted 7 lines · Mark Brown
Quoted 2 lines · Daniel Mack

The spi-gpio driver currently assumes the chipselect gpio number is stored in ->controller_data of the device's static board information.

Applied both, thanks. It's a bit sad that we need an explict property for num-chipselects though.

We don't need that, and a patch to change it would be trivial.

IIRC, there was just no agreement on deriving that information implicitly via the count of given GPIOs, and I don't know what should be considered more important - resemblance between drivers bindings or simplicity.

We could of course change that for all SPI master drivers at once.

Daniel

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#8 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 4 lines · Daniel Mack
Quoted 1 line

Ok, thanks. Mark, did the patches reach you this time? I think they should go thru the SPI tree.

Yeah no problem, Mark is always faster than me ...

Yours,
Linus Walleij

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#10 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 8 lines · Linus Walleij
Quoted 4 lines · Daniel Mack
Quoted 1 line

Ok, thanks. Mark, did the patches reach you this time? I think they should go thru the SPI tree.

Yeah no problem, Mark is always faster than me ...

Hmm, I don't know whether anyone took those patches yet? Mark?

Thanks,
Daniel

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#12 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 11 lines · Daniel Mack
Quoted 8 lines · Linus Walleij
Quoted 4 lines · Daniel Mack
Quoted 1 line

Ok, thanks. Mark, did the patches reach you this time? I think they should go thru the SPI tree.

Yeah no problem, Mark is always faster than me ...

Hmm, I don't know whether anyone took those patches yet? Mark?

Mark better take them, ping on Mark.

Yours,
Linus Walleij

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#14 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 5 lines · Linus Walleij
Quoted 1 line · Daniel Mack

Hmm, I don't know whether anyone took those patches yet? Mark?

Mark better take them, ping on Mark.

IIRC I did reply saying that the patches didn't apply for me, in any case I don't have them any more - can you please check that they apply against my -next branch and resend?

git://git.kernel.org/pub/scm/kernel/git/broonie/misc.git spi-next

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

#16 lore raw

Re: [PATCH resend 2/2] SPI: spi-gpio: Add DT bindings

In reply to a message not in the archive
Quoted 10 lines · Mark Brown
Quoted 5 lines · Linus Walleij
Quoted 1 line · Daniel Mack

Hmm, I don't know whether anyone took those patches yet? Mark?

Mark better take them, ping on Mark.

IIRC I did reply saying that the patches didn't apply for me, in any case I don't have them any more - can you please check that they apply against my -next branch and resend?

Sure, will do. They applied cleanly on top of the spi-next branch though. Nevermind :)

Daniel

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/