Add SPI driver for MPC5121 PSC SPI
Subsystems (3)
cover Add SPI driver for MPC5121 PSC SPI
Anatolij Gustschin (2):
powerpc/mpc5121: move PSC FIFO memory init to platform code
spi: Add SPI master driver for MPC5121 PSC
arch/powerpc/include/asm/mpc52xx_psc.h | 1 + arch/powerpc/platforms/512x/mpc512x_shared.c | 78 ++++ drivers/serial/mpc52xx_uart.c | 69 --- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mpc512x_psc_spi.c | 576 ++++++++++++++++++++++++++ 6 files changed, 663 insertions(+), 69 deletions(-) create mode 100644 drivers/spi/mpc512x_psc_spi.c
------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 1272633687-6935-1-git-send-email-agust-ynQEQJNshbs@public.gmane.org
PATCH 1/2 powerpc/mpc5121: move PSC FIFO memory init to platform code
Since PSC could also be used in other modes than UART mode we move PSC FIFO memory initialization from serial driver to common platform code. The initialized FIFO memory slices may not overlap, so the most easy way would be to configure them all at once at init time for all PSC devices. This is now done by this patch.
--- arch/powerpc/platforms/512x/mpc512x_shared.c | 78 ++++++++++++++++++++++++++ drivers/serial/mpc52xx_uart.c | 69 ----------------------- 2 files changed, 78 insertions(+), 69 deletions(-)
arch/powerpc/platforms/512x/mpc512x_shared.c +78 -0
@@ -26,6 +26,7 @@#include <asm/prom.h> #include <asm/time.h> #include <asm/mpc5121.h> +#include <asm/mpc52xx_psc.h> #include "mpc512x.h"
@@ -369,9 +370,86 @@ void __init mpc512x_declare_of_platform_devices(void) } } +#define DEFAULT_FIFO_SIZE 16 + +static unsigned int __init get_fifo_size (struct device_node *np, +char *prop_name) +{ +const unsigned int *fp; + + fp =of_get_property (np, prop_name,NULL ); +if (fp) +return *fp; + +pr_warning ("no %s property in %s node, defaulting to %d\n" , + prop_name, np->full_name,DEFAULT_FIFO_SIZE ); + +return DEFAULT_FIFO_SIZE ; +} + +#define FIFOC (_base) ((struct mpc512x_psc_fifo __iomem *) \ + ((u32)(_base) + sizeof(struct mpc52xx_psc))) + +/* Init PSC FIFO space for TX and RX slices */ +void __init mpc512x_psc_fifo_init (void ) +{ +struct device_node *np; +void __iomem *psc; +unsigned int tx_fifo_size; +unsigned int rx_fifo_size; +int fifobase =0 ;/* current fifo address in 32 bit words */ + +for_each_compatible_node (np,NULL ,"fsl,mpc5121-psc" ) { + tx_fifo_size =get_fifo_size (np,"fsl,tx-fifo-size" ); + rx_fifo_size =get_fifo_size (np,"fsl,rx-fifo-size" ); + +/* size in register is in 4 byte units */ + tx_fifo_size /=4 ; + rx_fifo_size /=4 ; +if (!tx_fifo_size) + tx_fifo_size =1 ; +if (!rx_fifo_size) + rx_fifo_size =1 ; + + psc =of_iomap (np,0 ); +if (!psc) { +pr_err ("%s: Can't map %s device\n" , + __func__, np->full_name); +continue ; + } + +/* FIFO space is 4KiB, check if requested size is available */ +if ((fifobase + tx_fifo_size + rx_fifo_size) >0x1000 ) { +pr_err ("%s: no fifo space available for %s\n" , + __func__, np->full_name); +iounmap (psc); +/* +* chances are that another device requests less +* fifo space, so we continue. +*/ +continue ; + } + +/* set tx and rx fifo size registers */ +out_be32 (&FIFOC (psc)->txsz, (fifobase <<16 ) | tx_fifo_size); + fifobase += tx_fifo_size; +out_be32 (&FIFOC (psc)->rxsz, (fifobase <<16 ) | rx_fifo_size); + fifobase += rx_fifo_size; + +/* reset and enable the slices */ +out_be32 (&FIFOC (psc)->txcmd,0x80 ); +out_be32 (&FIFOC (psc)->txcmd,0x01 ); +out_be32 (&FIFOC (psc)->rxcmd,0x80 ); +out_be32 (&FIFOC (psc)->rxcmd,0x01 ); + +iounmap (psc); + } +} +void __init mpc512x_init (void ) {mpc512x_declare_of_platform_devices ();mpc5121_clk_init ();mpc512x_restart_init (); +mpc512x_psc_fifo_init (); }
drivers/serial/mpc52xx_uart.c +0 -69
85 lines not on this page · raw message
Signature · 4 lines
1.6.3.3 ------------------------------------------------------------------------------
A message that is not in the archive (sent off-list or not yet received): 1272633687-6935-2-git-send-email-agust-ynQEQJNshbs@public.gmane.org
PATCH 2/2 spi: Add SPI master driver for MPC5121 PSC
--- arch/powerpc/include/asm/mpc52xx_psc.h | 1 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/mpc512x_psc_spi.c | 576 ++++++++++++++++++++++++++++++++ 4 files changed, 585 insertions(+), 0 deletions(-) create mode 100644 drivers/spi/mpc512x_psc_spi.c
arch/powerpc/include/asm/mpc52xx_psc.h +1 -0
@@ -248,6 +248,7 @@ struct mpc52xx_psc_fifo {u16 tflwfptr;/* PSC + 0x9e */ }; +#define MPC512x_PSC_FIFO_EOF 0x100#define MPC512x_PSC_FIFO_RESET_SLICE 0x80#define MPC512x_PSC_FIFO_ENABLE_SLICE 0x01#define MPC512x_PSC_FIFO_ENABLE_DMA 0x04
drivers/spi/Kconfig +7 -0
@@ -165,6 +165,13 @@ config SPI_MPC52xx_PSC This enables using the Freescale MPC52xx Programmable Serial Controller in master SPI mode. +config SPI_MPC512x_PSC + tristate "Freescale MPC512x PSC SPI controller" + depends on SPI_MASTER && PPC_MPC512x + help + This enables using the Freescale MPC5121 Programmable Serial + Controller in SPI master mode. + config SPI_MPC8xxx tristate "Freescale MPC8xxx SPI controller" depends on FSL_SOC
drivers/spi/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_SPI_OMAP24XX) += omap2_mcspi.o obj-$(CONFIG_SPI_OMAP_100K) += omap_spi_100k.o obj-$(CONFIG_SPI_ORION) += orion_spi.o obj-$(CONFIG_SPI_PL022) += amba-pl022.o +obj-$(CONFIG_SPI_MPC512x_PSC) += mpc512x_psc_spi.o obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o obj-$(CONFIG_SPI_MPC52xx) += mpc52xx_spi.o obj-$(CONFIG_SPI_MPC8xxx) += spi_mpc8xxx.o
drivers/spi/mpc512x_psc_spi.c new file +576 -0
576 lines not on this page · raw message
Signature · 4 lines
1.6.3.3 ------------------------------------------------------------------------------
Re: [PATCH 1/2] powerpc/mpc5121: move PSC FIFO memory init to platform code
In reply to a message not in the archiveQuoted 8 lines · Anatolij Gustschin
Since PSC could also be used in other modes than UART mode we move PSC FIFO memory initialization from serial driver to common platform code. The initialized FIFO memory slices may not overlap, so the most easy way would be to configure them all at once at init time for all PSC devices. This is now done by this patch.
Signed-off-by Anatolij Gustschin <[email protected]>
Looks good. I'll pick it up.
g.
Quoted 199 lines
---
arch/powerpc/platforms/512x/mpc512x_shared.c | 78 ++++++++++++++++++++++++++drivers/serial/mpc52xx_uart.c| 69 -----------------------2 files changed, 78 insertions(+), 69 deletions(-)arch/powerpc/platforms/512x/mpc512x_shared.c +78
-0@@ -26,6 +26,7 @@ #include <asm/prom.h> #include <asm/time.h> #include <asm/mpc5121.h> +#include <asm/mpc52xx_psc.h> #include "mpc512x.h"@@ -369,9 +370,86 @@ void __init mpc512x_declare_of_platform_devices(void) } } +#define DEFAULT_FIFO_SIZE 16 + +static unsigned int __init get_fifo_size (struct device_node *np, + char *prop_name) +{ + const unsigned int *fp; + + fp = of_get_property(np, prop_name, NULL); + if (fp) + return *fp; + + pr_warning("no %s property in %s node, defaulting to %d\n", + prop_name, np->full_name, DEFAULT_FIFO_SIZE); + + return DEFAULT_FIFO_SIZE; +} + +#define FIFOC (_base) ((struct mpc512x_psc_fifo __iomem *) \ + ((u32)(_base) + sizeof(struct mpc52xx_psc))) + +/* Init PSC FIFO space for TX and RX slices */ +void __init mpc512x_psc_fifo_init (void ) +{ + struct device_node *np; + void __iomem *psc; + unsigned int tx_fifo_size; + unsigned int rx_fifo_size; + int fifobase = 0; /* current fifo address in 32 bit words */ + + for_each_compatible_node(np, NULL, "fsl,mpc5121-psc") { + tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size"); + rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size"); + + /* size in register is in 4 byte units */ + tx_fifo_size /= 4; + rx_fifo_size /= 4; + if (!tx_fifo_size) + tx_fifo_size = 1; + if (!rx_fifo_size) + rx_fifo_size = 1; + + psc = of_iomap(np, 0); + if (!psc) { + pr_err("%s: Can't map %s device\n", + __func__, np->full_name); + continue; + } + + /* FIFO space is 4KiB, check if requested size is available */ + if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) { + pr_err("%s: no fifo space available for %s\n", + __func__, np->full_name); + iounmap(psc); + /* + * chances are that another device requests less + * fifo space, so we continue. + */ + continue; + } + + /* set tx and rx fifo size registers */ + out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size); + fifobase += tx_fifo_size; + out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size); + fifobase += rx_fifo_size; + + /* reset and enable the slices */ + out_be32(&FIFOC(psc)->txcmd, 0x80); + out_be32(&FIFOC(psc)->txcmd, 0x01); + out_be32(&FIFOC(psc)->rxcmd, 0x80); + out_be32(&FIFOC(psc)->rxcmd, 0x01); + + iounmap(psc); + } +} + void __init mpc512x_init(void) { mpc512x_declare_of_platform_devices(); mpc5121_clk_init(); mpc512x_restart_init(); + mpc512x_psc_fifo_init(); }drivers/serial/mpc52xx_uart.c +0
-70@@ -430,34 +430,10 @@ static unsigned long mpc512x_getuartclk(void *p) return mpc5xxx_get_bus_frequency(p); } -#define DEFAULT_FIFO_SIZE 16 - -static unsigned int __init get_fifo_size (struct device_node *np, - char *fifo_name) -{ - const unsigned int *fp; - - fp = of_get_property(np, fifo_name, NULL); - if (fp) - return *fp; - - pr_warning("no %s property in %s node, defaulting to %d\n", - fifo_name, np->full_name, DEFAULT_FIFO_SIZE); - - return DEFAULT_FIFO_SIZE; -} - -#define FIFOC (_base) ((struct mpc512x_psc_fifo __iomem *) \ - ((u32)(_base) + sizeof(struct mpc52xx_psc))) - /* Init PSC FIFO Controller */ static int __init mpc512x_psc_fifoc_init(void) { struct device_node *np; - void __iomem *psc; - unsigned int tx_fifo_size; - unsigned int rx_fifo_size; - int fifobase = 0; /* current fifo address in 32 bit words */ np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-psc-fifo");@@ -480,51 +456,6 @@ static int __init mpc512x_psc_fifoc_init(void) return -ENODEV; } - for_each_compatible_node(np, NULL, "fsl,mpc5121-psc-uart") { - tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size"); - rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size"); - - /* size in register is in 4 byte units */ - tx_fifo_size /= 4; - rx_fifo_size /= 4; - if (!tx_fifo_size) - tx_fifo_size = 1; - if (!rx_fifo_size) - rx_fifo_size = 1; - - psc = of_iomap(np, 0); - if (!psc) { - pr_err("%s: Can't map %s device\n", - __func__, np->full_name); - continue; - } - - /* FIFO space is 4KiB, check if requested size is available */ - if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) { - pr_err("%s: no fifo space available for %s\n", - __func__, np->full_name); - iounmap(psc); - /* - * chances are that another device requests less - * fifo space, so we continue. - */ - continue; - } - /* set tx and rx fifo size registers */ - out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size); - fifobase += tx_fifo_size; - out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size); - fifobase += rx_fifo_size; - - /* reset and enable the slices */ - out_be32(&FIFOC(psc)->txcmd, 0x80); - out_be32(&FIFOC(psc)->txcmd, 0x01); - out_be32(&FIFOC(psc)->rxcmd, 0x80); - out_be32(&FIFOC(psc)->rxcmd, 0x01); - - iounmap(psc); - } - return 0; } --1.6.3.3
Signature · 4 lines
Grant Likely, B.Sc., P.Eng. Secret Lab Technologies Ltd. ------------------------------------------------------------------------------