[U-Boot] [PATCH 1/3] mx53_smd: add spi nor support

Stefano Babic sbabic at denx.de
Fri Aug 17 12:36:34 CEST 2012


On 15/08/2012 08:38, Terry Lv wrote:
> Add spi nor support to mx53 smd, including iomux, configs, etc.
> To test spi nor on mx53 smd:

Hi Terry,

> MX53SMD U-Boot > sf probe 0:21249
> JEDEC ID: 0x202016
> m25p32 (4096 Kbytes)
> SF: Detected m25p32 with page size 0 Bytes, total 4 MiB
> 
> Here, 21249 is integer of hex 0x5301. 0x01 is cs and 0x53 is active gpio
> number.

I think sf probe accepts also parameter in hex, such as sf probe 0x5301.


> 
> Signed-off-by: Terry Lv <r65388 at freescale.com>
> ---
>  board/freescale/mx53smd/mx53smd.c |   63 +++++++++++++++++++++++++++++++++++++
>  include/configs/mx53smd.h         |   17 ++++++++++
>  2 files changed, 80 insertions(+), 0 deletions(-)
> 
> diff --git a/board/freescale/mx53smd/mx53smd.c b/board/freescale/mx53smd/mx53smd.c
> index 87fa7fa..abb1e9b 100644
> --- a/board/freescale/mx53smd/mx53smd.c
> +++ b/board/freescale/mx53smd/mx53smd.c
> @@ -127,6 +127,65 @@ static void setup_iomux_fec(void)
>  			PAD_CTL_HYS_ENABLE | PAD_CTL_PKE_ENABLE);
>  }
>  
> +#ifdef CONFIG_MXC_SPI
> +static void setup_iomux_spi(u8 bus, u8 ss)
> +{
> +	switch (bus) {
> +	case 0:
> +		/* SCLK */
> +		mxc_request_iomux(MX53_PIN_EIM_D16, IOMUX_CONFIG_ALT4);
> +		mxc_iomux_set_pad(MX53_PIN_EIM_D16,
> +				PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +		mxc_iomux_set_input(MX53_ECSPI1_IPP_CSPI_CLK_IN_SELECT_INPUT,
> +				0x3);
> +
> +		/* MISO */
> +		mxc_request_iomux(MX53_PIN_EIM_D17, IOMUX_CONFIG_ALT4);
> +		mxc_iomux_set_pad(MX53_PIN_EIM_D17,
> +				PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +		mxc_iomux_set_input(MX53_ECSPI1_IPP_IND_MISO_SELECT_INPUT,
> +				0x3);
> +
> +		/* MOSI */
> +		mxc_request_iomux(MX53_PIN_EIM_D18, IOMUX_CONFIG_ALT4);
> +		mxc_iomux_set_pad(MX53_PIN_EIM_D18,
> +				PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +		mxc_iomux_set_input(MX53_ECSPI1_IPP_IND_MOSI_SELECT_INPUT,
> +				0x3);
> +
> +		if (0 == ss) {
> +			mxc_request_iomux(MX53_PIN_EIM_EB2,
> +						IOMUX_CONFIG_ALT4);
> +			mxc_iomux_set_pad(MX53_PIN_EIM_EB2,
> +				PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +			mxc_iomux_set_input(
> +				MX53_ECSPI1_IPP_IND_SS_B_1_SELECT_INPUT,
> +				0x3);
> +
> +			mxc_request_iomux(MX53_PIN_EIM_EB2, IOMUX_CONFIG_ALT1);
> +			mxc_iomux_set_pad(MX53_PIN_EIM_EB2,
> +					PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +		} else if (1 == ss){
> +			mxc_request_iomux(MX53_PIN_EIM_D19, IOMUX_CONFIG_ALT4);
> +			mxc_iomux_set_pad(MX53_PIN_EIM_D19,
> +				PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +			mxc_iomux_set_input(
> +					MX53_ECSPI1_IPP_IND_SS_B_2_SELECT_INPUT,
> +					0x2);
> +
> +			mxc_request_iomux(MX53_PIN_EIM_D19, IOMUX_CONFIG_ALT1);
> +			mxc_iomux_set_pad(MX53_PIN_EIM_D19,
> +					PAD_CTL_HYS_ENABLE | PAD_CTL_DRV_HIGH);
> +		}

Instead of this if-else, it can be more readable if you introduce a
switch-case, printing in the default case an error message if the cs is
not expected.

> +		break;
> +	case 1:
> +	case 2:
> +	default:
> +		break;

bus different as 1 is an error currently on this board. Insert a default
case, with some message as "unsupported" or such like that.

> diff --git a/include/configs/mx53smd.h b/include/configs/mx53smd.h
> index 48b32dd..e830c1b 100644
> --- a/include/configs/mx53smd.h
> +++ b/include/configs/mx53smd.h
> @@ -65,6 +65,23 @@
>  #define CONFIG_CMD_FAT
>  #define CONFIG_DOS_PARTITION
>  
> +/* SPI Configs*/
> +#define CONFIG_CMD_SPI
> +#define CONFIG_MXC_SPI
> +#define CONFIG_SPI_VER_2_3	1

Ok, this depends on your previous patchset. It must be merged firstly
before applying this series. Can you mention it in the next changelog ?


> +#define CONFIG_CSPI1_BASE_ADDR	CSPI1_BASE_ADDR
> +#define CONFIG_CSPI2_BASE_ADDR	CSPI2_BASE_ADDR
> +#define CONFIG_CSPI3_BASE_ADDR	CSPI3_BASE_ADDR
> +
> +/* SPI Flash Configs */
> +#define CONFIG_CMD_SF
> +#define CONFIG_SPI_FLASH
> +#define CONFIG_SPI_FLASH_STMICRO	1
> +#define CONFIG_SF_DEFAULT_SPEED 25000000
> +#define CONFIG_SF_DEFAULT_MODE  (SPI_MODE_0)
> +#define CONFIG_SPI_FLASH_BUS	0
> +#define CONFIG_SPI_FLASH_CS	1

There is also a CONFIG_SF_DEFAULT_CS, if you like to use it. You can set
it to 0x5301 (better write as in your comment, (GPIO << 8) + CS) and sf
probe will take it automatically.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================


More information about the U-Boot mailing list