mtd: spi: Add DM support to SH QSPI driver
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)
drivers/spi/sh_qspi.c +150 -65
@@ -67,15 +67,12 @@ struct sh_qspi_regs { };struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI struct spi_slave slave; +#endif struct sh_qspi_regs *regs; }; -static inline struct sh_qspi_slave *to_sh_qspi (struct spi_slave *slave) -{ - return container_of(slave, struct sh_qspi_slave, slave); -} -static void sh_qspi_init (struct sh_qspi_slave *ss) {/* QSPI initialize */
@@ -119,15 +116,8 @@ static void sh_qspi_init(struct sh_qspi_slave *ss)setbits_8 (&ss->regs->spcr,SPCR_SPE ); } -int spi_cs_is_valid (unsigned int bus,unsigned int cs) -{ -return 1 ; -} - -void spi_cs_activate (struct spi_slave *slave) +static void sh_qspi_cs_activate (struct sh_qspi_slave *ss) { -struct sh_qspi_slave *ss =to_sh_qspi (slave); -/* Set master mode only */ writeb (SPCR_MSTR , &ss->regs->spcr);
@@ -147,61 +137,15 @@ void spi_cs_activate(struct spi_slave *slave)setbits_8 (&ss->regs->spcr,SPCR_SPE ); } -void spi_cs_deactivate (struct spi_slave *slave) +static void sh_qspi_cs_deactivate (struct sh_qspi_slave *ss) { -struct sh_qspi_slave *ss =to_sh_qspi (slave); -/* Disable SPI Function */ clrbits_8 (&ss->regs->spcr,SPCR_SPE ); } -void spi_init (void ) -{ -/* nothing to do */ -} - -struct spi_slave *spi_setup_slave (unsigned int bus,unsigned int cs, -unsigned int max_hz,unsigned int mode) -{ -struct sh_qspi_slave *ss; - -if (!spi_cs_is_valid (bus, cs)) -return NULL ; - - ss = spi_alloc_slave(struct sh_qspi_slave, bus, cs); -if (!ss) { -printf ("SPI_error: Fail to allocate sh_qspi_slave\n" ); -return NULL ; - } - - ss->regs = (struct sh_qspi_regs *)SH_QSPI_BASE ; - -/* Init SH QSPI */ -sh_qspi_init (ss); - -return &ss->slave; -} - -void spi_free_slave (struct spi_slave *slave) +static int sh_qspi_xfer_common (struct sh_qspi_slave *ss,unsigned int bitlen, +const void *dout,void *din,unsigned long flags) { -struct sh_qspi_slave *spi =to_sh_qspi (slave); - -free (spi); -} - -int spi_claim_bus (struct spi_slave *slave) -{ -return 0 ; -} - -void spi_release_bus (struct spi_slave *slave) -{ -} - -int spi_xfer (struct spi_slave *slave,unsigned int bitlen,const void *dout, -void *din,unsigned long flags) -{ -struct sh_qspi_slave *ss =to_sh_qspi (slave);u32 nbyte, chunk;int i, ret =0 ;u8 dtdata =0 , drdata;
@@ -210,7 +154,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,if (dout ==NULL && din ==NULL ) {if (flags &SPI_XFER_END ) -spi_cs_deactivate (slave); +sh_qspi_cs_deactivate (ss);return 0 ; }
@@ -222,7 +166,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, nbyte = bitlen /8 ;if (flags &SPI_XFER_BEGIN ) { -spi_cs_activate (slave); +sh_qspi_cs_activate (ss);/* Set 1048576 byte */ writel (0x100000 , spbmul0);
@@ -273,7 +217,148 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, }if (flags &SPI_XFER_END ) -spi_cs_deactivate (slave); +sh_qspi_cs_deactivate (ss);return ret; } + +#ifndef CONFIG_DM_SPI +static inline struct sh_qspi_slave *to_sh_qspi (struct spi_slave *slave) +{ + return container_of(slave, struct sh_qspi_slave, slave); +} + +int spi_cs_is_valid (unsigned int bus,unsigned int cs) +{ +return 1 ; +} + +void spi_cs_activate (struct spi_slave *slave) +{ +struct sh_qspi_slave *ss =to_sh_qspi (slave); + +sh_qspi_cs_activate (ss); +} + +void spi_cs_deactivate (struct spi_slave *slave) +{ +struct sh_qspi_slave *ss =to_sh_qspi (slave); + +sh_qspi_cs_deactivate (ss); +} + +void spi_init (void ) +{ +/* nothing to do */ +} + +struct spi_slave *spi_setup_slave (unsigned int bus,unsigned int cs, +unsigned int max_hz,unsigned int mode) +{ +struct sh_qspi_slave *ss; + +if (!spi_cs_is_valid (bus, cs)) +return NULL ; + + ss = spi_alloc_slave(struct sh_qspi_slave, bus, cs); +if (!ss) { +printf ("SPI_error: Fail to allocate sh_qspi_slave\n" ); +return NULL ; + } + + ss->regs = (struct sh_qspi_regs *)SH_QSPI_BASE ; + +/* Init SH QSPI */ +sh_qspi_init (ss); + +return &ss->slave; +} + +void spi_free_slave (struct spi_slave *slave) +{ +struct sh_qspi_slave *spi =to_sh_qspi (slave); + +free (spi); +} + +int spi_claim_bus (struct spi_slave *slave) +{ +return 0 ; +} + +void spi_release_bus (struct spi_slave *slave) +{ +} + +int spi_xfer (struct spi_slave *slave,unsigned int bitlen, +const void *dout,void *din,unsigned long flags) +{ +struct sh_qspi_slave *ss =to_sh_qspi (slave); + +return sh_qspi_xfer_common (ss, bitlen, dout, din, flags); +} + +#else + +#include <dm.h> + +static int sh_qspi_xfer (struct udevice *dev,unsigned int bitlen, +const void *dout,void *din,unsigned long flags) +{ +struct udevice *bus = dev->parent; +struct sh_qspi_slave *ss =dev_get_platdata (bus); + +return sh_qspi_xfer_common (ss, bitlen, dout, din, flags); +} + +static int sh_qspi_set_speed (struct udevice *dev,uint speed) +{ +/* This is a SPI NOR controller, do nothing. */ +return 0 ; +} + +static int sh_qspi_set_mode (struct udevice *dev,uint mode) +{ +/* This is a SPI NOR controller, do nothing. */ +return 0 ; +} + +static int sh_qspi_probe (struct udevice *dev) +{ +struct sh_qspi_slave *ss =dev_get_platdata (dev); + +sh_qspi_init (ss); + +return 0 ; +} + +static int sh_qspi_ofdata_to_platdata (struct udevice *dev) +{ +struct sh_qspi_slave *plat =dev_get_platdata (dev); + + plat->regs = (struct sh_qspi_regs *)dev_read_addr (dev); + +return 0 ; +} + +static const struct dm_spi_ops sh_qspi_ops = { + .xfer = sh_qspi_xfer, + .set_speed = sh_qspi_set_speed, + .set_mode = sh_qspi_set_mode, +}; + +static const struct udevice_id sh_qspi_ids[] = { + { .compatible ="renesas,qspi" }, + { } +}; + +U_BOOT_DRIVER (sh_qspi) = { + .name ="sh_qspi" , + .id =UCLASS_SPI , + .of_match = sh_qspi_ids, + .ops = &sh_qspi_ops, + .ofdata_to_platdata = sh_qspi_ofdata_to_platdata, + .platdata_auto_alloc_size =sizeof (struct sh_qspi_slave ), + .probe = sh_qspi_probe, +}; +#endif
Signature · 1 line
2.16.2
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 15 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0
drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 4 lines
drivers/spi/sh_qspi.c +1
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI
We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
Jagan.
Signature · 4 lines
Jagan Teki Senior Linux Kernel Engineer | Amarula Solutions U-Boot, Linux | Upstream Maintainer Hyderabad, India.
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 18 lines · Jagan Teki
Quoted 17 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };
Quoted 6 lines
drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 2 lines
drivers/spi/sh_qspi.c +1
-0struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
The SPL on that board (silk) has 16 kiB limit, right now I am at 15500 B with gcc 7.x already, adding any more overhead will make it overflow. So while I'd like to have it all fancy DM and stuff, it's not possible.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 26 lines · Marek Vasut
Quoted 18 lines · Jagan Teki
Quoted 17 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };Quoted 6 lines
drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 2 lines
drivers/spi/sh_qspi.c +1
-0struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
Quoted 3 lines
The SPL on that board (silk) has 16 kiB limit, right now I am at 15500 B with gcc 7.x already, adding any more overhead will make it overflow. So while I'd like to have it all fancy DM and stuff, it's not possible.
How about having simple glue code for SPL, since it anyway used for read in real?
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 27 lines · Jagan Teki
Quoted 26 lines · Marek Vasut
Quoted 24 lines · Jagan Teki
Quoted 15 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 4 lines
drivers/spi/sh_qspi.c +1
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
Quoted 6 lines
Quoted 3 lines
The SPL on that board (silk) has 16 kiB limit, right now I am at 15500 B with gcc 7.x already, adding any more overhead will make it overflow. So while I'd like to have it all fancy DM and stuff, it's not possible.
How about having simple glue code for SPL, since it anyway used for read in real?
I'd prefer to use the same driver for both SPL and U-Boot instead of hacking stuff up. Not sure what exactly you mean by "glue" though.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 32 lines · Marek Vasut
Quoted 31 lines · Jagan Teki
Quoted 29 lines · Marek Vasut
Quoted 18 lines · Jagan Teki
Quoted 17 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };Quoted 6 lines
drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 2 lines
drivers/spi/sh_qspi.c +1
-0struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
The SPL on that board (silk) has 16 kiB limit, right now I am at 15500 B with gcc 7.x already, adding any more overhead will make it overflow. So while I'd like to have it all fancy DM and stuff, it's not possible.
Quoted 5 lines
Quoted 2 lines
How about having simple glue code for SPL, since it anyway used for read in real?
I'd prefer to use the same driver for both SPL and U-Boot instead of hacking stuff up. Not sure what exactly you mean by "glue" though.
Something that bypass spi stack and read the flash with local code, this usually suited for low SRAM size like silk example spl_spi_sunxi.c
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 36 lines · Jagan Teki
Quoted 35 lines · Marek Vasut
Quoted 33 lines · Jagan Teki
Quoted 26 lines · Marek Vasut
Quoted 18 lines · Jagan Teki
Quoted 17 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };Quoted 6 lines
drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 2 lines
drivers/spi/sh_qspi.c +1
-0struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
Quoted 3 lines
The SPL on that board (silk) has 16 kiB limit, right now I am at 15500 B with gcc 7.x already, adding any more overhead will make it overflow. So while I'd like to have it all fancy DM and stuff, it's not possible.
How about having simple glue code for SPL, since it anyway used for read in real?
Quoted 6 lines
Quoted 2 lines
I'd prefer to use the same driver for both SPL and U-Boot instead of hacking stuff up. Not sure what exactly you mean by "glue" though.
Something that bypass spi stack and read the flash with local code, this usually suited for low SRAM size like silk example
spl_spi_sunxi.c
But I am not _that_ cripplingly low, so I'd prefer to stick to a standard solution instead of some hack.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
Quoted 40 lines · Marek Vasut
Quoted 39 lines · Jagan Teki
Quoted 37 lines · Marek Vasut
Quoted 27 lines · Jagan Teki
Quoted 26 lines · Marek Vasut
Quoted 24 lines · Jagan Teki
Quoted 15 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>--- drivers/spi/sh_qspi.c | 215 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 150 insertions(+), 65 deletions(-)drivers/spi/sh_qspi.c +0
-0drivers/spi/sh_qspi.c struct sh_qspi_regs { · line 70
Quoted 4 lines
drivers/spi/sh_qspi.c +1
-0@@ -67,15 +67,12 @@ struct sh_qspi_regs { };struct sh_qspi_slave { +#ifndef CONFIG_DM_SPI We are trying to drop non-dm code as much as possible (with MIGRATION.txt policy), how about adding PLTADATA or spi read glue code or any other?
Quoted 6 lines
Quoted 3 lines
The SPL on that board (silk) has 16 kiB limit, right now I am at 15500 B with gcc 7.x already, adding any more overhead will make it overflow. So while I'd like to have it all fancy DM and stuff, it's not possible.
How about having simple glue code for SPL, since it anyway used for read in real?
I'd prefer to use the same driver for both SPL and U-Boot instead of hacking stuff up. Not sure what exactly you mean by "glue" though.
Quoted 6 lines
Quoted 3 lines
Something that bypass spi stack and read the flash with local code, this usually suited for low SRAM size like silk example
spl_spi_sunxi.cBut I am not _that_ cripplingly low, so I'd prefer to stick to a standard solution instead of some hack.
OK, is this a fix or shall I take it for next?
PATCH 1/1 mtd: spi: Add DM support to SH QSPI driver
In reply to Marek VasutQuoted 7 lines · Marek Vasut
Add DM support to the SH QSPI driver while retaining non-DM support. The later is required as this driver is used in SPL which has a size limitation of 16 kiB.
Signed-off-by Marek Vasut <[email protected]>Cc Nobuhiro Iwamatsu <[email protected]>
Applied to u-boot-spi/master