[U-Boot] [PATCH 1/3] arm: atmel: at91sam9x5: cleanup cs configure for spi

Andreas Bießmann andreas.devel at googlemail.com
Tue Dec 17 10:06:12 CET 2013


Hi Bo,

On 12/10/2013 09:14 AM, Bo Shen wrote:
> As the cs for spi is worked in gpio mode, so no need to configure
> it as peripheral and then configure to gpio.

That statement may be correct.

> 
> Signed-off-by: Bo Shen <voice.shen at atmel.com>
> ---
> 
>  arch/arm/cpu/arm926ejs/at91/at91sam9x5_devices.c |   28 +++++-----------------
>  board/atmel/at91sam9x5ek/at91sam9x5ek.c          |    1 -
>  2 files changed, 6 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/arm/cpu/arm926ejs/at91/at91sam9x5_devices.c b/arch/arm/cpu/arm926ejs/at91/at91sam9x5_devices.c
> index 6d94572..745dce6 100644
> --- a/arch/arm/cpu/arm926ejs/at91/at91sam9x5_devices.c
> +++ b/arch/arm/cpu/arm926ejs/at91/at91sam9x5_devices.c
> @@ -130,20 +130,12 @@ void at91_spi0_hw_init(unsigned long cs_mask)
>  	writel(1 << ATMEL_ID_SPI0, &pmc->pcer);
>  
>  	if (cs_mask & (1 << 0))
> -		at91_set_a_periph(AT91_PIO_PORTA, 14, 0);
> -	if (cs_mask & (1 << 1))
> -		at91_set_b_periph(AT91_PIO_PORTA, 7, 0);
> -	if (cs_mask & (1 << 2))
> -		at91_set_b_periph(AT91_PIO_PORTA, 1, 0);
> -	if (cs_mask & (1 << 3))
> -		at91_set_b_periph(AT91_PIO_PORTB, 3, 0);
> -	if (cs_mask & (1 << 4))
>  		at91_set_pio_output(AT91_PIO_PORTA, 14, 0);
> -	if (cs_mask & (1 << 5))
> +	if (cs_mask & (1 << 1))
>  		at91_set_pio_output(AT91_PIO_PORTA, 7, 0);
> -	if (cs_mask & (1 << 6))
> +	if (cs_mask & (1 << 2))
>  		at91_set_pio_output(AT91_PIO_PORTA, 1, 0);
> -	if (cs_mask & (1 << 7))
> +	if (cs_mask & (1 << 3))
>  		at91_set_pio_output(AT91_PIO_PORTB, 3, 0);
>  }
>  
> @@ -159,20 +151,12 @@ void at91_spi1_hw_init(unsigned long cs_mask)
>  	writel(1 << ATMEL_ID_SPI1, &pmc->pcer);
>  
>  	if (cs_mask & (1 << 0))
> -		at91_set_b_periph(AT91_PIO_PORTA, 8, 0);
> -	if (cs_mask & (1 << 1))
> -		at91_set_b_periph(AT91_PIO_PORTA, 0, 0);
> -	if (cs_mask & (1 << 2))
> -		at91_set_b_periph(AT91_PIO_PORTA, 31, 0);
> -	if (cs_mask & (1 << 3))
> -		at91_set_b_periph(AT91_PIO_PORTA, 30, 0);
> -	if (cs_mask & (1 << 4))
>  		at91_set_pio_output(AT91_PIO_PORTA, 8, 0);
> -	if (cs_mask & (1 << 5))
> +	if (cs_mask & (1 << 1))
>  		at91_set_pio_output(AT91_PIO_PORTA, 0, 0);
> -	if (cs_mask & (1 << 6))
> +	if (cs_mask & (1 << 2))
>  		at91_set_pio_output(AT91_PIO_PORTA, 31, 0);
> -	if (cs_mask & (1 << 7))
> +	if (cs_mask & (1 << 3))
>  		at91_set_pio_output(AT91_PIO_PORTA, 30, 0);
>  }

But these changes to at91_spiX_hw_init() are wrong!

The point is that we want to set the spi CS line to GPIO or peripheral
mode by the function. Maybe the interface is bad but all of these
functions behave like this. The assumption is that we always have 4 SPI
CS per port, to setup the first one as peripheral we need to give 0x01
as mask, to setup the same CS as GPIO we need to apply offset of 4 bits
-> 0x10 mask.

>  #endif
> diff --git a/board/atmel/at91sam9x5ek/at91sam9x5ek.c b/board/atmel/at91sam9x5ek/at91sam9x5ek.c
> index 6f67c34..fb74a30 100644
> --- a/board/atmel/at91sam9x5ek/at91sam9x5ek.c
> +++ b/board/atmel/at91sam9x5ek/at91sam9x5ek.c
> @@ -272,7 +272,6 @@ int board_init(void)
>  
>  #ifdef CONFIG_ATMEL_SPI
>  	at91_spi0_hw_init(1 << 0);
> -	at91_spi0_hw_init(1 << 4);

So the correct change would be to remove the first line and leave the
at91_spiX_hw_init() untouched.

>  #endif
>  
>  #ifdef CONFIG_MACB
> 

@jagannadh.teki: I grabbed that patch delegated to you @ patchwork.

Best regards

Andreas Bießmann


More information about the U-Boot mailing list