mxc_spi refactoring (for mx6q and mx6qsabrelite)
Subsystems (3)
v3 cover mxc_spi refactoring (for mx6q and mx6qsabrelite)
This patch set refactors mxc_spi as described in
http://lists.denx.de/pipermail/u-boot/2010-March/068791.html and requested in http://lists.denx.de/pipermail/u-boot/2012-January/116023.html
in order to add support for the MX6Q in general and the mx6qsabrelite specifically.
Patch 1 simply moves the conditional parts of mxc_spi.c into the respective CPU-specific imx-regs.h files.
Patch 2 adds general support for SPI to the i.MX6.
Patch 3 adds support to the mx6qsabrelite board
Patch 4 modifies the 'sf' command to allow a default chip-select to be specified by board headers as is done on efika et al. This allows a bare 'sf' probe command:
U-Boot> sf probe
instead of the more cumbersome usage when a GPIO is tacked onto the chip-select. Otherwise, this command-line would be needed to specify GP3:19 on SabreLite:
U-Boot> sf probe 0x5300
Patch 5 adds default chip-select values for mx6qsabrelite platform.
Patch 6 adds reference macros for use in storing the environment in serial flash to match the use on Freescale's U-Boot release
This patch set has been compiled against the following configurations, but only tested on mx6qsabrelite:
mx6qsabrelite mx51evk mx31pdk mx35pdk
PATCH v3 1/6 mxc_spi: move machine specifics into CPU headers
Move (E)CSPI register declarations into the imx-regs.h files for each supported CPU
Introduce two new macros to control conditional setup
MXC_CSPI - Used for processors with the Configurable Serial Peripheral Interface (MX3x) MXC_ECSPI - For processors with Enhanced Configurable... (MX5x, MX6x)
--- arch/arm/include/asm/arch-mx31/imx-regs.h | 27 ++++++++ arch/arm/include/asm/arch-mx35/imx-regs.h | 25 ++++++++ arch/arm/include/asm/arch-mx5/imx-regs.h | 30 +++++++++ drivers/spi/mxc_spi.c | 93 ++--------------------------- 4 files changed, 88 insertions(+), 87 deletions(-)
arch/arm/include/asm/arch-mx31/imx-regs.h +27 -0
@@ -890,4 +890,31 @@ struct esdc_regs {#define MXC_EHCI_IPPUE_DOWN (1 << 8)#define MXC_EHCI_IPPUE_UP (1 << 9) +/* +* CSPI register definitions +*/ +#define MXC_CSPI +#define MXC_CSPICTRL_EN (1 << 0) +#define MXC_CSPICTRL_MODE (1 << 1) +#define MXC_CSPICTRL_XCH (1 << 2) +#define MXC_CSPICTRL_SMC (1 << 3) +#define MXC_CSPICTRL_POL (1 << 4) +#define MXC_CSPICTRL_PHA (1 << 5) +#define MXC_CSPICTRL_SSCTL (1 << 6) +#define MXC_CSPICTRL_SSPOL (1 << 7) +#define MXC_CSPICTRL_CHIPSELECT (x) (((x) & 0x3) << 24) +#define MXC_CSPICTRL_BITCOUNT (x) (((x) & 0x1f) << 8) +#define MXC_CSPICTRL_DATARATE (x) (((x) & 0x7) << 16) +#define MXC_CSPICTRL_TC (1 << 8) +#define MXC_CSPICTRL_RXOVF (1 << 6) +#define MXC_CSPICTRL_MAXBITS 0x1f + +#define MXC_CSPIPERIOD_32KHZ (1 << 15) +#define MAX_SPI_BYTES 4 + +#define MXC_SPI_BASE_ADDRESSES \ + 0x43fa4000, \ + 0x50010000, \ + 0x53f84000, +#endif /* __ASM_ARCH_MX31_IMX_REGS_H */
arch/arm/include/asm/arch-mx35/imx-regs.h +25 -0
@@ -179,6 +179,31 @@#define IPU_CONF_IC_EN (1<<1)#define IPU_CONF_SCI_EN (1<<0) +/* +* CSPI register definitions +*/ +#define MXC_CSPI +#define MXC_CSPICTRL_EN (1 << 0) +#define MXC_CSPICTRL_MODE (1 << 1) +#define MXC_CSPICTRL_XCH (1 << 2) +#define MXC_CSPICTRL_SMC (1 << 3) +#define MXC_CSPICTRL_POL (1 << 4) +#define MXC_CSPICTRL_PHA (1 << 5) +#define MXC_CSPICTRL_SSCTL (1 << 6) +#define MXC_CSPICTRL_SSPOL (1 << 7) +#define MXC_CSPICTRL_CHIPSELECT (x) (((x) & 0x3) << 12) +#define MXC_CSPICTRL_BITCOUNT (x) (((x) & 0xfff) << 20) +#define MXC_CSPICTRL_DATARATE (x) (((x) & 0x7) << 16) +#define MXC_CSPICTRL_TC (1 << 7) +#define MXC_CSPICTRL_RXOVF (1 << 6) +#define MXC_CSPICTRL_MAXBITS 0xfff +#define MXC_CSPIPERIOD_32KHZ (1 << 15) +#define MAX_SPI_BYTES 4 + +#define MXC_SPI_BASE_ADDRESSES \ + 0x43fa4000, \ + 0x50010000, +#define GPIO_PORT_NUM 3#define GPIO_NUM_PIN 32
arch/arm/include/asm/arch-mx5/imx-regs.h +30 -0
@@ -223,6 +223,36 @@#define CS0_32M_CS1_32M_CS2_32M_CS3_32M 3/* +* CSPI register definitions +*/ +#define MXC_ECSPI +#define MXC_CSPICTRL_EN (1 << 0) +#define MXC_CSPICTRL_MODE (1 << 1) +#define MXC_CSPICTRL_XCH (1 << 2) +#define MXC_CSPICTRL_CHIPSELECT (x) (((x) & 0x3) << 12) +#define MXC_CSPICTRL_BITCOUNT (x) (((x) & 0xfff) << 20) +#define MXC_CSPICTRL_PREDIV (x) (((x) & 0xF) << 12) +#define MXC_CSPICTRL_POSTDIV (x) (((x) & 0xF) << 8) +#define MXC_CSPICTRL_SELCHAN (x) (((x) & 0x3) << 18) +#define MXC_CSPICTRL_MAXBITS 0xfff +#define MXC_CSPICTRL_TC (1 << 7) +#define MXC_CSPICTRL_RXOVF (1 << 6) +#define MXC_CSPIPERIOD_32KHZ (1 << 15) +#define MAX_SPI_BYTES 32 + +/* Bit position inside CTRL register to be associated with SS */ +#define MXC_CSPICTRL_CHAN 18 + +/* Bit position inside CON register to be associated with SS */ +#define MXC_CSPICON_POL 4 +#define MXC_CSPICON_PHA 0 +#define MXC_CSPICON_SSPOL 12 +#define MXC_SPI_BASE_ADDRESSES \ + CSPI1_BASE_ADDR, \ + CSPI2_BASE_ADDR, \ + CSPI3_BASE_ADDR, + +/* * Number of GPIO pins per port */ #define GPIO_NUM_PIN 32
drivers/spi/mxc_spi.c +6 -87
127 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v3 2/6 mx6q: Add support for ECSPI through mxc_spi driver
In reply to Eric Nelson--- arch/arm/include/asm/arch-mx6/imx-regs.h | 44 ++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-)
arch/arm/include/asm/arch-mx6/imx-regs.h +44 -0
@@ -190,6 +190,50 @@ struct src {u32 gpr10; }; +/* ECSPI registers */ +struct cspi_regs { +u32 rxdata; +u32 txdata; +u32 ctrl; +u32 cfg; +u32 intr; +u32 dma; +u32 stat; +u32 period; +}; + +/* +* CSPI register definitions +*/ +#define MXC_ECSPI +#define MXC_CSPICTRL_EN (1 << 0) +#define MXC_CSPICTRL_MODE (1 << 1) +#define MXC_CSPICTRL_XCH (1 << 2) +#define MXC_CSPICTRL_CHIPSELECT (x) (((x) & 0x3) << 12) +#define MXC_CSPICTRL_BITCOUNT (x) (((x) & 0xfff) << 20) +#define MXC_CSPICTRL_PREDIV (x) (((x) & 0xF) << 12) +#define MXC_CSPICTRL_POSTDIV (x) (((x) & 0xF) << 8) +#define MXC_CSPICTRL_SELCHAN (x) (((x) & 0x3) << 18) +#define MXC_CSPICTRL_MAXBITS 0xfff +#define MXC_CSPICTRL_TC (1 << 7) +#define MXC_CSPICTRL_RXOVF (1 << 6) +#define MXC_CSPIPERIOD_32KHZ (1 << 15) +#define MAX_SPI_BYTES 32 + +/* Bit position inside CTRL register to be associated with SS */ +#define MXC_CSPICTRL_CHAN 18 + +/* Bit position inside CON register to be associated with SS */ +#define MXC_CSPICON_POL 4 +#define MXC_CSPICON_PHA 0 +#define MXC_CSPICON_SSPOL 12 +#define MXC_SPI_BASE_ADDRESSES \ + ECSPI1_BASE_ADDR, \ + ECSPI2_BASE_ADDR, \ + ECSPI3_BASE_ADDR, \ + ECSPI4_BASE_ADDR, \ + ECSPI5_BASE_ADDR +struct iim_regs {u32 ctrl;u32 ctrl_set;
Signature · 1 line
1.7.1
PATCH v3 3/6 mx6q: mx6qsabrelite: Add ECSPI support to the Sabrelite platform
In reply to Eric Nelson--- board/freescale/mx6qsabrelite/imximage.cfg | 2 +- board/freescale/mx6qsabrelite/mx6qsabrelite.c | 25 +++++++++++++++++++++++++ include/configs/mx6qsabrelite.h | 9 +++++++++ 3 files changed, 35 insertions(+), 1 deletions(-)
board/freescale/mx6qsabrelite/imximage.cfg +1 -1
@@ -156,7 +156,7 @@ DATA 4 0x021b0404 0x00011006 # set the default clock gate to save power DATA 4 0x020c4068 0x00C03F3F -DATA 4 0x020c406c 0x0030FC00 +DATA 4 0x020c406c 0x0030FC03 DATA 4 0x020c4070 0x0FFFC000 DATA 4 0x020c4074 0x3FF00000 DATA 4 0x020c4078 0x00FFF300
board/freescale/mx6qsabrelite/mx6qsabrelite.c +25 -0
@@ -46,6 +46,10 @@ DECLARE_GLOBAL_DATA_PTR; PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \ PAD_CTL_DSE_40ohm | PAD_CTL_HYS) +#define SPI_PAD_CTRL (PAD_CTL_HYS | \ + PAD_CTL_PUS_100K_DOWN | PAD_CTL_SPEED_MED | \ + PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST) +int dram_init (void ) { gd->ram_size =get_ram_size ((void *)PHYS_SDRAM ,PHYS_SDRAM_SIZE );
@@ -193,6 +197,23 @@ int board_mmc_init(bd_t *bis) }#endif +#ifdef CONFIG_MXC_SPI +iomux_v3_cfg_t ecspi1_pads[] = { +/* SS1 */ +MX6Q_PAD_EIM_D19__GPIO_3_19 |MUX_PAD_CTRL (SPI_PAD_CTRL ), +MX6Q_PAD_EIM_D17__ECSPI1_MISO |MUX_PAD_CTRL (SPI_PAD_CTRL ), +MX6Q_PAD_EIM_D18__ECSPI1_MOSI |MUX_PAD_CTRL (SPI_PAD_CTRL ), +MX6Q_PAD_EIM_D16__ECSPI1_SCLK |MUX_PAD_CTRL (SPI_PAD_CTRL ), +}; + +void setup_spi (void ) +{ +gpio_direction_output (IMX_GPIO_NR (3 ,19 ),1 ); +imx_iomux_v3_setup_multiple_pads (ecspi1_pads, +ARRAY_SIZE (ecspi1_pads)); +} +#endif +#define MII_1000BASET_CTRL 0x9#define MII_EXTENDED_CTRL 0xb#define MII_EXTENDED_DATAW 0xc
@@ -250,6 +271,10 @@ int board_early_init_f(void) {setup_iomux_uart (); +#ifdef CONFIG_MXC_SPI +setup_spi (); +#endif +return 0 ; }
include/configs/mx6qsabrelite.h +9 -0
@@ -44,6 +44,15 @@#define CONFIG_MXC_UART #define CONFIG_MXC_UART_BASE UART2_BASE +#define CONFIG_CMD_SF +#ifdef CONFIG_CMD_SF +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_SST +#define CONFIG_MXC_SPI +#define CONFIG_SF_DEFAULT_SPEED 25000000 +#define CONFIG_SF_DEFAULT_MODE (SPI_MODE_0) +#endif +/* MMC Configs */ #define CONFIG_FSL_ESDHC #define CONFIG_FSL_USDHC
Signature · 1 line
1.7.1
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
In reply to Eric NelsonThis patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
On boards that use the mxc_spi driver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead of
U-Boot> sf probe 0x5300
--- common/cmd_sf.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-)
common/cmd_sf.c +23 -11
@@ -70,20 +70,28 @@ static int do_spi_flash_probe(int argc, char * const argv[])char *endp;struct spi_flash *new; -if (argc <2 ) -return -1 ; - - cs =simple_strtoul (argv[1 ], &endp,0 ); -if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' )) +#ifndef CONFIG_SPI_FLASH_CS +if (argc <2 ) { +printf ("%s: missing arguments\n" , __func__);return -1 ; -if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ; +#endif - bus = cs; - cs =simple_strtoul (endp +1 , &endp,0 ); -if (*endp !=0 ) +if (argc >=2 ) { + cs =simple_strtoul (argv[1 ], &endp,0 ); +if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' ))return -1 ; +if (*endp ==':' ) { +if (endp[1 ] ==0 ) +return -1 ; + + bus = cs; + cs =simple_strtoul (endp +1 , &endp,0 ); +if (*endp !=0 ) +return -1 ; + } }if (argc >=3 ) {
@@ -299,7 +307,11 @@ usage:U_BOOT_CMD ( sf,5 ,1 , do_spi_flash,"SPI flash sub-system" , +#ifndef CONFIG_SPI_FLASH_CS "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n" +#else +"probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" +#endif" and chip select\n" "sf read addr offset len - read `len' bytes starting at\n" " `offset' to memory at `addr'\n"
Signature · 1 line
1.7.1
Fabio Estevam
reviewerPATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
Quoted 9 lines · Eric Nelson
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
On boards that use the
mxc_spidriver and a GPIO for chip select, this allows
a much simpler command line:
U-Boot> sf probe
instead of
Quoted 5 lines
U-Boot> sf probe 0x5300Signed-off-by Eric Nelson <[email protected]>Acked-by Dirk Behme <[email protected]>Acked-by Stefano Babic <[email protected]>
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
In reply to Eric NelsonQuoted 9 lines · On Tuesday 24 January 2012 11:18:22 Eric Nelson wrote:
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
On boards that use the
mxc_spidriver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead ofU-Boot> sf probe 0x5300
NAK (to this version of the patch): missing README update, and other issues below
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 76
Quoted 7 lines
common/cmd_sf.c +3
-0+#ifndef CONFIG_SPI_FLASH_CS +if (argc <2 ) { +printf ("%s: missing arguments\n" , __func__);return -1 ;
return cmd_usage(cmdtp);
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 80
Quoted 7 lines
common/cmd_sf.c +4
-3-if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ; +#endif
you're setting the default CS, not locking it in. so a better config knob name would be something like:
CONFIG_SF_DEFAULT_CS
this matches the existing CONFIG_SF_XXX defines
also, you have a spurious space before the semicolon there
common/cmd_sf.c usage: · line 317
Quoted 11 lines
U_BOOT_CMD(
common/cmd_sf.c +4
-0sf,5 ,1 , do_spi_flash,"SPI flash sub-system" , +#ifndef CONFIG_SPI_FLASH_CS "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n" +#else +"probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" +#endif" and chip select\n" "sf read addr offset len - read `len' bytes starting at\n" " `offset' to memory at `addr'\n"
this is ugly. i'd rather just omit it and not worry about the syntax being perfect.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120124/0eb55ae8/attachment.pgp>
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
Quoted 5 lines · Mike Frysinger
Quoted 4 lines · On Tuesday 24 January 2012 11:18:22 Eric Nelson wrote:
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
Quoted 9 lines
Quoted 5 lines
On boards that use the
mxc_spidriver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead ofU-Boot> sf probe 0x5300NAK (to this version of the patch): missing README update, and other issues below
Which README? The only references I find to serial flash support are in board-specific README files.
~/u-boot$ find . -iname \*readme\* | xargs grep -w sf
./doc/README.p2041rdb: => sf erase 0 100000
./doc/README.p2041rdb: => sf write 1000000 0 $filesize
./doc/README.p2041rdb: => sf erase 110000 10000
./doc/README.p2041rdb: => sf write 1000000 110000 $filesize
./doc/README.sh7757lcr: => sf probe 0 ./doc/README.sh7757lcr: => sf erase 0 80000 ./doc/README.sh7757lcr: => sf write 0x89000000 0 80000
I can start one of those for the SabreLite board, but that's un-related to this patch.
Quoted 23 lines
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 76
Quoted 7 lines
common/cmd_sf.c +3
-0+#ifndef CONFIG_SPI_FLASH_CS +if (argc<2 ) { +printf ("%s: missing arguments\n" , __func__);return -1 ;return cmd_usage(cmdtp);common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 80
Quoted 7 lines
common/cmd_sf.c +4
-3-if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ; +#endif you're setting the default CS, not locking it in. so a better config knob name would be something like:
CONFIG_SF_DEFAULT_CS
this matches the existingCONFIG_SF_XXXdefines
Quoted 2 lines
also, you have a spurious space before the semicolon there
Thanks Mike,
FWIW, I chose this name on purpose to make life easier on a couple of other boards immediately (efika and vision2):
~/u-boot$ grep CONFIG_SPI_FLASH_CS include/configs/*
include/configs/efikamx.h:#define CONFIG_SPI_FLASH_CS (1 | 121 << 8)
include/configs/m28evk.h:#define CONFIG_SPI_FLASH_CS 2include/configs/mx6qsabrelite.h.rej: #define CONFIG_SPI_FLASH_CS 1
include/configs/vision2.h:#define CONFIG_SPI_FLASH_CS (1 | (121 << 8))
Quoted 6 lines
Quoted 6 lines
U_BOOT_CMD(
sf, 5, 1,do_spi_flash,
"SPI flash sub-system",common/cmd_sf.c +2
-0+#ifndef CONFIG_SPI_FLASH_CS "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n" +#else
Quoted 8 lines
common/cmd_sf.c usage: · line 317
Quoted 5 lines
common/cmd_sf.c +2
-0+ "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" +#endif " and chip select\n" "sf read addr offset len - read `len' bytes starting at\n" " `offset' to memory at `addr'\n" this is ugly. i'd rather just omit it and not worry about the syntax being perfect.
Works for me.
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
Quoted 13 lines · On Thursday 26 January 2012 20:22:22 Eric Nelson wrote:
Quoted 12 lines · Mike Frysinger
Quoted 11 lines · On Tuesday 24 January 2012 11:18:22 Eric Nelson wrote:
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
On boards that use the
mxc_spidriver and a GPIO for chip select, thisallows a much simpler command line:
U-Boot> sf probeinstead of
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
U-Boot> sf probe 0x5300NAK (to this version of the patch): missing README update, and other issues below
Which README? The only references I find to serial flash support are in board-specific README files.
all new CONFIG_xxx defines should be documented in the top level README. granted, the existin SF ones have slipped in without being documented, but that's bad for them ;).
Quoted 17 lines
Quoted 17 lines
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 80
Quoted 10 lines
common/cmd_sf.c +4
-3-if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ; +#endif you're setting the default CS, not locking it in. so a better config knob name
would be something like:
CONFIG_SF_DEFAULT_CS
Quoted 8 lines
Quoted 3 lines
this matches the existing
CONFIG_SF_XXXdefinesalso, you have a spurious space before the semicolon there
Thanks Mike,
FWIW, I chose this name on purpose to make life easier on a couple of other boards immediately (efika and vision2):
those boards are dumb -- that define isn't used anywhere, so that's just dead code. cmd_sf has a standard already, so new defines specific to cmd_sf should follow that.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120126/18da5739/attachment.pgp>
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
Quoted 19 lines · Mike Frysinger
Quoted 18 lines · On Thursday 26 January 2012 20:22:22 Eric Nelson wrote:
Quoted 16 lines · Mike Frysinger
Quoted 4 lines · On Tuesday 24 January 2012 11:18:22 Eric Nelson wrote:
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
Quoted 8 lines
On boards that use the
mxc_spidriver and a GPIO for chip select, thisallows a much simpler command line:
U-Boot> sf probeinstead of
U-Boot> sf probe 0x5300NAK (to this version of the patch): missing README update, and other issues below
Quoted 7 lines
Quoted 2 lines
Which README? The only references I find to serial flash support are in board-specific README files.
all new
CONFIG_xxxdefines should be documented in the top level README. granted, the existin SF ones have slipped in without being documented, but that's bad for them ;).
Ok. I'll re-send with README updates.
Quoted 23 lines
Quoted 23 lines
Quoted 14 lines
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 80
Quoted 10 lines
common/cmd_sf.c +4
-3-if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ; +#endif you're setting the default CS, not locking it in. so a better config knob name
Quoted 6 lines
would be something like:
CONFIG_SF_DEFAULT_CSthis matches the existing
CONFIG_SF_XXXdefinesalso, you have a spurious space before the semicolon there
Thanks Mike,
Quoted 7 lines
Quoted 2 lines
FWIW, I chose this name on purpose to make life easier on a couple of other boards immediately (efika and vision2):
those boards are dumb -- that define isn't used anywhere, so that's just dead code.
cmd_sfhas a standard already, so new defines specific tocmd_sfshould follow that.
-mike
Ok. I'll let their maintainers update appropriately.
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
In reply to Eric NelsonHi Eric,
please see my comments below.
Quoted 23 lines · Eric Nelson
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
On boards that use the
mxc_spidriver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead ofU-Boot> sf probe 0x5300Signed-off-by Eric Nelson <[email protected]>Acked-by Dirk Behme <[email protected]>Acked-by Stefano Babic <[email protected]>--- common/cmd_sf.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-)common/cmd_sf.c +0
-0@@ -70,20 +70,28 @@ static int do_spi_flash_probe(int argc, char * const argv[])char *endp;
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 75
Quoted 10 lines
common/cmd_sf.c +3
-5struct spi_flash *new; -if (argc <2 ) -return -1 ; - - cs =simple_strtoul (argv[1 ], &endp,0 ); -if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' )) +#ifndef CONFIG_SPI_FLASH_CS +if (argc <2 ) { +printf ("%s: missing arguments\n" , __func__);
I think this format for the error message is a little bit untypical for u-boot. We do not show up the internal C function name. Better would be to show the command usage, right?
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 79
Quoted 7 lines
common/cmd_sf.c +3
-3return -1; -if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ;
Other options for the spi flash subsystem are called CONFIG_SF_DEFAULT_MODE|SPEED. It think it make sense to call this CONFIG_SF_DEFAULT_CS and CONFIG_SF_DEFAULT_BUS (see below).
Quoted 23 lines
common/cmd_sf.c +13
-3+#endif - bus = cs; - cs =simple_strtoul (endp +1 , &endp,0 ); -if (*endp !=0 ) +if (argc >=2 ) { + cs =simple_strtoul (argv[1 ], &endp,0 ); +if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' ))return -1 ; +if (*endp ==':' ) { +if (endp[1 ] ==0 ) +return -1 ; + + bus = cs; + cs =simple_strtoul (endp +1 , &endp,0 ); +if (*endp !=0 ) +return -1 ; + } }if (argc >=3 ) {@@ -299,7 +307,11 @@ usage: U_BOOT_CMD(
common/cmd_sf.c usage: · line 317
Quoted 10 lines
common/cmd_sf.c +4
-0sf,5 ,1 , do_spi_flash,"SPI flash sub-system" , +#ifndef CONFIG_SPI_FLASH_CS "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n" +#else +"probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" +#endif" and chip select\n" "sf read addr offset len - read `len' bytes starting at\n" " `offset' to memory at `addr'\n"
Can you also add a config option for the SPI bus number? I think these two need to handled in the same patch.
So you could add this stuff:
common/cmd_sf.c +4 -0
@@ -63,7 +63,11 @@ static int sf_parse_len_arg(char *arg, ulong *len)static int do_spi_flash_probe (int argc,char *const argv[]) { +#ifdef CONFIG_SF_DEFAULT_BUS +unsigned int bus =CONFIG_SF_DEFAULT_BUS ; +#else unsigned int bus =0 ; +#endif unsigned int cs;unsigned int speed =CONFIG_SF_DEFAULT_SPEED ;unsigned int mode =CONFIG_SF_DEFAULT_MODE ;
Matthias
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
common/cmd_sf.c static int sf_parse_len_arg(char *arg, ulong *len) · line 70
Quoted 12 lines · On Wednesday 25 January 2012 10:10:18 Matthias Fuchs wrote:
Can you also add a config option for the SPI bus number? I think these two need to handled in the same patch.
So you could add this stuff:
static int
do_spi_flash_probe(int argc, char * const argv[]){common/cmd_sf.c +4
-0+#ifdef CONFIG_SF_DEFAULT_BUS +unsigned int bus =CONFIG_SF_DEFAULT_BUS ; +#else unsigned int bus =0 ; +#endif
move the default logic to the top of the file like the existing CONFIG_SF_DEFAULT_SPEED, then the code later on only needs to do:
unsigned int bus = CONFIG_SF_DEFAULT_BUS;
otherwise, this suggestion sounds good too
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120125/4e46854f/attachment.pgp>
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
In reply to Matthias FuchsQuoted 30 lines · Matthias Fuchs
Hi Eric,
please see my comments below.
Quoted 25 lines · Eric Nelson
This patch allows a board configuration file to provide a default chip-select for serial flash so that first argument to the 'sf' command is optional.
On boards that use the
mxc_spidriver and a GPIO for chip select, this allows a much simpler command line:
U-Boot> sf probe
instead ofU-Boot> sf probe 0x5300Signed-off-by Eric Nelson<[email protected]>Acked-by Dirk Behme<[email protected]>Acked-by Stefano Babic<[email protected]>--- common/cmd_sf.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-)common/cmd_sf.c +0
-0@@ -70,20 +70,28 @@ static int do_spi_flash_probe(int argc, char * const argv[])char *endp;struct spi_flash *new;
Quoted 12 lines
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 75
Quoted 8 lines
common/cmd_sf.c +3
-5-if (argc<2 ) -return -1 ; - - cs =simple_strtoul (argv[1 ],&endp,0 ); -if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' )) +#ifndef CONFIG_SPI_FLASH_CS +if (argc<2 ) { +printf ("%s: missing arguments\n" , __func__);I think this format for the error message is a little bit untypical for u-boot. We do not show up the internal C function name. Better would be to show the command usage, right?
Looking at this area of the code in more detail, there are quite a few cases where improper usage silently return -1.
I'm inclined to either follow that lead or toss them together with a "goto usage" as done in do_spi_flash().
Any preferences?
Quoted 11 lines
common/cmd_sf.c static int do_spi_flash_probe(int argc, char * const argv[]) · line 79
Quoted 7 lines
common/cmd_sf.c +3
-3return -1; -if (*endp ==':' ) { -if (endp[1 ] ==0 ) -return -1 ; + } +#else + cs =CONFIG_SPI_FLASH_CS ;Other options for the spi flash subsystem are called CONFIG_SF_DEFAULT_MODE|SPEED. It think it make sense to call this
CONFIG_SF_DEFAULT_CSandCONFIG_SF_DEFAULT_BUS(see below).
See include/configs/efikamx.h (reference to unused symbol CONFIG_SPI_FLASH_CS).
Quoted 45 lines
Quoted 23 lines
common/cmd_sf.c +13
-3+#endif - bus = cs; - cs =simple_strtoul (endp +1 ,&endp,0 ); -if (*endp !=0 ) +if (argc>=2 ) { + cs =simple_strtoul (argv[1 ],&endp,0 ); +if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' ))return -1 ; +if (*endp ==':' ) { +if (endp[1 ] ==0 ) +return -1 ; + + bus = cs; + cs =simple_strtoul (endp +1 ,&endp,0 ); +if (*endp !=0 ) +return -1 ; + } }if (argc>=3 ) {@@ -299,7 +307,11 @@ usage: U_BOOT_CMD(common/cmd_sf.c usage: · line 317
Quoted 10 lines
common/cmd_sf.c +4
-0sf,5 ,1 , do_spi_flash,"SPI flash sub-system" , +#ifndef CONFIG_SPI_FLASH_CS "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n" +#else +"probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" +#endif" and chip select\n" "sf read addr offset len - read `len' bytes starting at\n" " `offset' to memory at `addr'\n" Can you also add a config option for the SPI bus number? I think these two need to handled in the same patch.
So you could add this stuff:
common/cmd_sf.c +0
-0@@ -63,7 +63,11 @@ static int sf_parse_len_arg(char *arg, ulong *len)
common/cmd_sf.c static int sf_parse_len_arg(char *arg, ulong *len) · line 73
Quoted 10 lines
common/cmd_sf.c +4
-0static int do_spi_flash_probe (int argc,char *const argv[]) { +#ifdef CONFIG_SF_DEFAULT_BUS +unsigned int bus =CONFIG_SF_DEFAULT_BUS ; +#else unsigned int bus =0 ; +#endif unsigned int cs;unsigned int speed =CONFIG_SF_DEFAULT_SPEED ;unsigned int mode =CONFIG_SF_DEFAULT_MODE ;
Can do.
PATCH v3 4/6 sf command: allow default chip select through CONFIG_SPI_FLASH_CS
Quoted 21 lines · On Thursday 26 January 2012 20:36:22 Eric Nelson wrote:
Quoted 7 lines · Matthias Fuchs
Quoted 6 lines · Eric Nelson
common/cmd_sf.c +0
-0char *endp;struct spi_flash *new;Quoted 12 lines
common/cmd_sf.c
Quoted 8 lines
common/cmd_sf.c +3
-5-if (argc<2 ) -return -1 ; - - cs =simple_strtoul (argv[1 ],&endp,0 ); -if (*argv[1 ] ==0 || (*endp !=0 && *endp !=':' )) +#ifndef CONFIG_SPI_FLASH_CS +if (argc<2 ) { +printf ("%s: missing arguments\n" , __func__);I think this format for the error message is a little bit untypical for u-boot. We do not show up the internal C function name. Better would be to show the command usage, right?
Quoted 7 lines
Looking at this area of the code in more detail, there are quite a few cases where improper usage silently return -1.
I'm inclined to either follow that lead or toss them together with a "goto usage" as done in
do_spi_flash().Any preferences?
invalid syntax should return cmd_usage(). errors should return non-zero, not usage information.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120126/a40c1afd/attachment.pgp>
PATCH v3 5/6 mx6q: mx6qsabrelite: Provide default chip-select for serial flash
In reply to Eric Nelson--- include/configs/mx6qsabrelite.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/configs/mx6qsabrelite.h +1 -0
@@ -46,6 +46,7 @@#define CONFIG_CMD_SF #ifdef CONFIG_CMD_SF +#define CONFIG_SPI_FLASH_CS 0x5300#define CONFIG_SPI_FLASH #define CONFIG_SPI_FLASH_SST #define CONFIG_MXC_SPI
Signature · 1 line
1.7.1
PATCH v3 6/6 mx6q: mx6qsabrelite: Conditionally define macros for environment in serial flash
In reply to Eric NelsonThe default settings store the persistent environment on SD card and not serial flash (SPI NOR).
To use SPI NOR to save the environment instead of SD card, edit include/configs/mx6qsabrelite.h and
- undefine CONFIG_ENV_IS_IN_MMC
- define CONFIG_ENV_IS_IN_SPI_FLASH
The SPI driver can take as chip select the controller's chip selects as well as an external GPIO. The LSB byte has the value of the internal chip select, the highest (thought as 16-bit value) contains the GPIO number.
The GPIO used on Sabre Lite is GP3:19 == 83.
--- include/configs/mx6qsabrelite.h | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
include/configs/mx6qsabrelite.h +11 -1
@@ -174,10 +174,20 @@/* FLASH and environment organization */ #define CONFIG_SYS_NO_FLASH -#define CONFIG_ENV_OFFSET (6 * 64 * 1024)#define CONFIG_ENV_SIZE (8 * 1024) +#define CONFIG_ENV_IS_IN_MMC +/* #define CONFIG_ENV_IS_IN_SPI_FLASH */ + +#if defined(CONFIG_ENV_IS_IN_MMC ) +#define CONFIG_ENV_OFFSET (6 * 64 * 1024)#define CONFIG_SYS_MMC_ENV_DEV 0 +#elif defined(CONFIG_ENV_IS_IN_SPI_FLASH ) +#define CONFIG_ENV_OFFSET (768 * 1024) +#define CONFIG_ENV_SECT_SIZE (8 * 1024) +#define CONFIG_ENV_SPI_CS 0x5300 +#define CONFIG_ENV_SPI_MODE SPI_MODE_0 +#endif #define CONFIG_OF_LIBFDT
Signature · 1 line
1.7.1