spi: Add PPC4xx SPI driver
PATCH v3 1/1 spi: Add PPC4xx SPI driver
This adds a SPI driver for the SPI controller found in the IBM/AMCC 4xx PowerPC's.
---
Changes in v3:
- When the device is removed the GPIOs are released. The memory for the GPIO array is freed.
Changes in v2:
- Now the gpios property is correctly decoded and the resulting gpio numbers are used as the devices chip selects.
So we can describe the SPI node like this:
SPI0: spi@ef600900 {
#address-cells = <1>;
#size-cells = <0>;
...
/* two GPIOs, representing two chip selects: 0 and 1 */
gpios = <&GPIO0 5 0 &GPIO1 16 0>;
mmc-slot@0 {
reg = <0>;
...
};
touchscreen@1 {
reg = <1>;
...
};
}Special thanks to Wolfgang Ocker and Anton Vorontsov for their input.
drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi_ppc4xx.c | 594 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 602 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/spi_ppc4xx.c
drivers/spi/Kconfig +7 -0
@@ -155,6 +155,13 @@ config SPI_ORION help This enables using the SPI master controller on the Orion chips. +config SPI_PPC4xx + tristate "PPC4xx SPI Controller" + depends on 4xx && SPI_MASTER + select SPI_BITBANG + help + This selects a driver for the PPC4xx SPI Controller. + config SPI_PXA2XX tristate "PXA2xx SSP SPI master" depends on ARCH_PXA && EXPERIMENTAL
drivers/spi/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o obj-$(CONFIG_SPI_ORION) += orion_spi.o obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o +obj-$(CONFIG_SPI_PPC4xx) += spi_ppc4xx.o obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o obj-$(CONFIG_SPI_TXX9) += spi_txx9.o
drivers/spi/spi_ppc4xx.c new file +594 -0
594 lines not on this page · raw message
Signature · 8 lines
1.6.0.3 ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): 1225000124-29366-1-git-send-email-sr-ynQEQJNshbs@public.gmane.org
Quoted 36 lines · Stefan Roese
This adds a SPI driver for the SPI controller found in the IBM/AMCC 4xx PowerPC's.
Signed-off-by Stefan Roese <[email protected]>Signed-off-by Wolfgang Ocker <[email protected]>---
Changes in v3:
- When the device is removed the GPIOs are released. The memory for the GPIO array is freed.Changes in v2:
- Now the gpios property is correctly decoded and the resulting gpio numbers are used as the devices chip selects.So we can describe the SPI node like this:
SPI0: spi@ef600900 { #address-cells = <1>; #size-cells = <0>; ... /* two GPIOs, representing two chip selects: 0 and 1 */ gpios = <&GPIO0 5 0 &GPIO1 16 0>; mmc-slot@0 { reg = <0>; ... }; touchscreen@1 { reg = <1>; ... }; }
Quoted 1 line
Special thanks to Wolfgang Ocker and Anton Vorontsov for their input.
Looks pretty good. Just a few minor comments/questions below.
Also, do you have a patch for a DTS file that gives an example of how to instantiate the SPI stuff in the device tree?
Quoted 12 lines
drivers/spi/spi_ppc4xx.c new file +7
-0+#include <linux/module.h> +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/errno.h> +#include <linux/wait.h> +#include <linux/of_platform.h> +#include <linux/of_spi.h>
drivers/spi/spi_ppc4xx.c line 34
Quoted 10 lines
drivers/spi/spi_ppc4xx.c new file +10
-0+#include <linux/of_gpio.h> +#include <linux/interrupt.h> +#include <linux/delay.h> + +#include <linux/gpio.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi_bitbang.h> + +#include <asm/io.h> +#include <asm/dcr-native.h>
Should maybe just be <asm/dcr.h>
Quoted 2 lines
drivers/spi/spi_ppc4xx.c new file +2
-0+#include <asm/dcr-regs.h> +
<snip>
Quoted 13 lines
drivers/spi/spi_ppc4xx.c new file +13
-0+/* SPI Controller driver's private data. */ +struct ppc4xx_spi { +/* bitbang has to be first */ +struct spi_bitbang bitbang; +struct completion done; + +u64 mapbase; +u64 mapsize; +int irqnum; +/* need this to set the SPI clock */ +unsigned int opb_freq; + +/* for transfers */
drivers/spi/spi_ppc4xx.c line 108
Quoted 10 lines
drivers/spi/spi_ppc4xx.c new file +10
-0+int len; +int count; +/* data buffers */ +const unsigned char *tx; +unsigned char *rx; + +int *gpios; +unsigned int num_gpios; + +volatile struct spi_ppc4xx_regs __iomem *regs;/* pointer to the registers */
volatile?
Quoted 3 lines
drivers/spi/spi_ppc4xx.c new file +3
-0+struct spi_master *master; +struct device *dev; +};
<snip>
Quoted 9 lines
drivers/spi/spi_ppc4xx.c new file +9
-0+static int spi_ppc4xx_txrx (struct spi_device *spi,struct spi_transfer *t) +{ +struct ppc4xx_spi *hw; +u8 data; + +dev_dbg (&spi->dev,"txrx: tx %p, rx %p, len %d\n" , + t->tx_buf, t->rx_buf, t->len); + + hw =spi_master_get_devdata (spi->master);
drivers/spi/spi_ppc4xx.c line 139
Quoted 10 lines
drivers/spi/spi_ppc4xx.c new file +10
-0+ + hw->tx = t->tx_buf; + hw->rx = t->rx_buf; + hw->len = t->len; + hw->count =0 ; + +/* send the first byte */ + data = hw->tx ? hw->tx[0 ] :0 ; +out_8 (&hw->regs->txd, data); +out_8 (&hw->regs->cr,SPI_PPC4XX_CR_STR );
Maybe iowrite8? Same comment elsewhere.
Quoted 5 lines
drivers/spi/spi_ppc4xx.c new file +5
-0+wait_for_completion (&hw->done); + +return hw->count; +} +
<snip>
drivers/spi/spi_ppc4xx.c line 563
Quoted 4 lines
drivers/spi/spi_ppc4xx.c new file +4
-0+static struct of_device_id spi_ppc4xx_of_match[] = { + { .compatible ="ibm,spi" , }, + {}, +};
I'm wondering if that is too generic of a match. In theory, IBM could have another SPI controller that isn't for 4xx. Maybe "ibm,spi-4xx" ?
josh
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): 20081029145305.GA3676-JVa43G0qJ78RlTYtMZUE4cJ8OCA1ciLf@public.gmane.org
Quoted 2 lines · Josh Boyer
Also, do you have a patch for a DTS file that gives an example of how to instantiate the SPI stuff in the device tree?
I'll second that request. I've updated the device tree for my Kilauea (405EX) board but am not sure I have everything correct.
Also, any pointers to sample/test code incorporating a spi protocol driver would be incredibly helpful. I'm very new to device driver programming and don't really know what I'm doing yet. I seem to be getting the spi_ppc4xx and spi_bitbang modules loaded, but am unsure how to verify proper initialization and what next steps I need to follow in order to develop and associate a protocol driver.
I'd like to start quite simply - some test routines that would drive data over the SPI connector on my Kilauea, using a spare GPIO pin as a chip select. I've got a logic analyzer from which to verify the results.
I've been reading through all the documentation I can find but am a little stuck. A concrete example with a SPI protocol driver would be quite useful.
Thanks,
-jmh
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): 8f9e78f00810301624k5925a52ah924960f869388233-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 2 lines · Jason Hanna
Also, any pointers to sample/test code incorporating a spi protocol driver would be incredibly helpful.
Look at Documentation/spi/*.c ... for user mode code hooking up through "spidev".
Quoted 5 lines
I'm very new to device driver
programming and don't really know what I'm doing yet. I seem to be getting thespi_ppc4xxandspi_bitbangmodules loaded, but am unsure how to verify proper initialization and what next steps I need to follow in order to develop and associate a protocol driver.
Documentation/spi/spi-summary should help.
And sticking a 'scope on the outputs (as you
said you plan) is a decent place to start,
if you don't have something to talk to yet.
- dave
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Quoted 1 line · Josh Boyer
Looks pretty good. Just a few minor comments/questions below.
Thanks. I also added some comments below.
Quoted 2 lines
Also, do you have a patch for a DTS file that gives an example of how to instantiate the SPI stuff in the device tree?
OK, I'll add a DTS patch to the next version.
Quoted 16 lines
Quoted 16 lines
drivers/spi/spi_ppc4xx.c new file +11
-0+#include <linux/module.h> +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/errno.h> +#include <linux/wait.h> +#include <linux/of_platform.h> +#include <linux/of_spi.h> +#include <linux/of_gpio.h> +#include <linux/interrupt.h> +#include <linux/delay.h> +
Quoted 8 lines
drivers/spi/spi_ppc4xx.c line 34
Quoted 6 lines
drivers/spi/spi_ppc4xx.c new file +6
-0+#include <linux/gpio.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi_bitbang.h> + +#include <asm/io.h> +#include <asm/dcr-native.h> Should maybe just be <
asm/dcr.h>
Fixed.
Quoted 23 lines
Quoted 2 lines
drivers/spi/spi_ppc4xx.c new file +2
-0+#include <asm/dcr-regs.h> +<snip>
Quoted 18 lines
drivers/spi/spi_ppc4xx.c new file +18
-0+/* SPI Controller driver's private data. */ +struct ppc4xx_spi { +/* bitbang has to be first */ +struct spi_bitbang bitbang; +struct completion done; + +u64 mapbase; +u64 mapsize; +int irqnum; +/* need this to set the SPI clock */ +unsigned int opb_freq; + +/* for transfers */ +int len; +int count; +/* data buffers */ +const unsigned char *tx; +unsigned char *rx;
Quoted 8 lines
Quoted 6 lines
drivers/spi/spi_ppc4xx.c new file +5
-0+ +int *gpios; +unsigned int num_gpios; + +volatile struct spi_ppc4xx_regs __iomem *regs;/* pointer to the registers */
volatile?
Fixed.
Quoted 19 lines
Quoted 3 lines
drivers/spi/spi_ppc4xx.c new file +3
-0+struct spi_master *master; +struct device *dev; +};<snip>
Quoted 13 lines
+static int
spi_ppc4xx_txrx(struct spi_device *spi, struct spi_transfer *t)+{drivers/spi/spi_ppc4xx.c new file +11
-0+struct ppc4xx_spi *hw; +u8 data; + +dev_dbg (&spi->dev,"txrx: tx %p, rx %p, len %d\n" , + t->tx_buf, t->rx_buf, t->len); + + hw =spi_master_get_devdata (spi->master); + + hw->tx = t->tx_buf; + hw->rx = t->rx_buf; + hw->len = t->len;
Quoted 8 lines
drivers/spi/spi_ppc4xx.c line 139
Quoted 6 lines
drivers/spi/spi_ppc4xx.c new file +6
-0+ hw->count =0 ; + +/* send the first byte */ + data = hw->tx ? hw->tx[0 ] :0 ; +out_8 (&hw->regs->txd, data); +out_8 (&hw->regs->cr,SPI_PPC4XX_CR_STR );Maybe iowrite8? Same comment elsewhere.
Why? We use the in_/out_xxx() accessor function for all other 4xx driver as well.
Quoted 8 lines
Quoted 5 lines
drivers/spi/spi_ppc4xx.c new file +5
-0+wait_for_completion (&hw->done); + +return hw->count; +} +<snip>
Quoted 8 lines
drivers/spi/spi_ppc4xx.c line 563
Quoted 4 lines
drivers/spi/spi_ppc4xx.c new file +4
-0+static struct of_device_id spi_ppc4xx_of_match[] = { + { .compatible ="ibm,spi" , }, + {}, +};I'm wondering if that is too generic of a match. In theory, IBM could have another SPI controller that isn't for 4xx. Maybe "ibm,spi-4xx" ?
Right. I was doing it the same way as already done before, e.g. "ibm,iic". For the gpio driver we already switched to "ibm,ppc4xx-gpio". So how about "ibm,ppc4xx-spi"?
Thanks.
Best regards,
Stefan
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · On Fri, 31 Oct 2008 09:31:19 +0100 Stefan Roese…
Quoted 1 line · Josh Boyer
Looks pretty good. Just a few minor comments/questions below.
Thanks. I also added some comments below.
Quoted 2 lines
Also, do you have a patch for a DTS file that gives an example of how to instantiate the SPI stuff in the device tree?
OK, I'll add a DTS patch to the next version.
Ok thanks.
Quoted 9 lines
Quoted 6 lines
drivers/spi/spi_ppc4xx.c line 139
Quoted 4 lines
drivers/spi/spi_ppc4xx.c new file +4
-0+/* send the first byte */ + data = hw->tx ? hw->tx[0 ] :0 ; +out_8 (&hw->regs->txd, data); +out_8 (&hw->regs->cr,SPI_PPC4XX_CR_STR );Maybe iowrite8? Same comment elsewhere.
Why? We use the in_/out_xxx() accessor function for all other 4xx driver as well.
Yeah. We used to have all of 4xx in arch/ppc too. ;)
Seriously though, it doesn't really bother me too much. The io{read,write} functions do have a bit better clarity as to endian-ness though.
Quoted 17 lines
Quoted 8 lines
Quoted 5 lines
drivers/spi/spi_ppc4xx.c new file +5
-0+wait_for_completion (&hw->done); + +return hw->count; +} +<snip>
Quoted 8 lines
drivers/spi/spi_ppc4xx.c line 563
Quoted 4 lines
drivers/spi/spi_ppc4xx.c new file +4
-0+static struct of_device_id spi_ppc4xx_of_match[] = { + { .compatible ="ibm,spi" , }, + {}, +};I'm wondering if that is too generic of a match. In theory, IBM could have another SPI controller that isn't for 4xx. Maybe "ibm,spi-4xx" ?
Quoted 3 lines
Right. I was doing it the same way as already done before, e.g. "ibm,iic". For the gpio driver we already switched to "ibm,ppc4xx-gpio". So how about "ibm,ppc4xx-spi"?
Sounds fine to me.
josh
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/