public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Andreas Bießmann" <andreas.devel@googlemail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 12/15] ATMEL: fix dataflash (dirty)
Date: Fri, 18 Feb 2011 13:33:38 +0100	[thread overview]
Message-ID: <4D5E6722.6040803@gmail.com> (raw)
In-Reply-To: <1298033414-11481-13-git-send-email-u-boot@emk-elektronik.de>

Am 18.02.2011 13:50, schrieb Reinhard Meyer:
> Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>
> ---
>  drivers/spi/atmel_dataflash_spi.c |   94 ++++++++++++++++++++++--------------
>  include/dataflash.h               |    1 -
>  2 files changed, 57 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/spi/atmel_dataflash_spi.c b/drivers/spi/atmel_dataflash_spi.c
> index 4a5c4aa..6e632cc 100644
> --- a/drivers/spi/atmel_dataflash_spi.c
> +++ b/drivers/spi/atmel_dataflash_spi.c
> @@ -21,13 +21,21 @@
>  
>  #include <common.h>
>  #ifndef CONFIG_AT91_LEGACY
> -#define CONFIG_AT91_LEGACY
> -#warning Please update to use C structur SoC access !
> +# define CONFIG_AT91_LEGACY

this would be CONFIG_ATMEL_LEGACY

> +# warning Please update to use C structur SoC access !
>  #endif
> -#include <asm/arch/hardware.h>
> +#include <common.h>
> +#include <spi.h>
> +#include <malloc.h>
> +
> +#include <asm/io.h>
> +
>  #include <asm/arch/clk.h>
> +#include <asm/arch/hardware.h>
> +
> +#include "atmel_spi.h"
> +
>  #include <asm/arch/gpio.h>
> -#include <asm/arch/io.h>
>  #include <asm/arch/at91_pio.h>
>  #include <asm/arch/at91_spi.h>
>  
> @@ -41,18 +49,18 @@
>  void AT91F_SpiInit(void)
>  {
>  	/* Reset the SPI */
> -	writel(AT91_SPI_SWRST, AT91_BASE_SPI + AT91_SPI_CR);
> +	writel(AT91_SPI_SWRST, ATMEL_BASE_SPI0 + AT91_SPI_CR);
>  
>  	/* Configure SPI in Master Mode with No CS selected !!! */
>  	writel(AT91_SPI_MSTR | AT91_SPI_MODFDIS | AT91_SPI_PCS,
> -	       AT91_BASE_SPI + AT91_SPI_MR);
> +	       ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  
>  	/* Configure CS0 */
>  	writel(AT91_SPI_NCPHA |
>  	       (AT91_SPI_DLYBS & DATAFLASH_TCSS) |
>  	       (AT91_SPI_DLYBCT & DATAFLASH_TCHS) |
>  	       ((get_mck_clk_rate() / AT91_SPI_CLK) << 8),
> -	       AT91_BASE_SPI + AT91_SPI_CSR(0));
> +	       ATMEL_BASE_SPI0 + AT91_SPI_CSR(0));
>  
>  #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS1
>  	/* Configure CS1 */
> @@ -60,7 +68,7 @@ void AT91F_SpiInit(void)
>  	       (AT91_SPI_DLYBS & DATAFLASH_TCSS) |
>  	       (AT91_SPI_DLYBCT & DATAFLASH_TCHS) |
>  	       ((get_mck_clk_rate() / AT91_SPI_CLK) << 8),
> -	       AT91_BASE_SPI + AT91_SPI_CSR(1));
> +	       ATMEL_BASE_SPI0 + AT91_SPI_CSR(1));
>  #endif
>  #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS2
>  	/* Configure CS2 */
> @@ -68,7 +76,7 @@ void AT91F_SpiInit(void)
>  	       (AT91_SPI_DLYBS & DATAFLASH_TCSS) |
>  	       (AT91_SPI_DLYBCT & DATAFLASH_TCHS) |
>  	       ((get_mck_clk_rate() / AT91_SPI_CLK) << 8),
> -	       AT91_BASE_SPI + AT91_SPI_CSR(2));
> +	       ATMEL_BASE_SPI0 + AT91_SPI_CSR(2));
>  #endif
>  #ifdef CONFIG_SYS_DATAFLASH_LOGIC_ADDR_CS3
>  	/* Configure CS3 */
> @@ -76,21 +84,22 @@ void AT91F_SpiInit(void)
>  	       (AT91_SPI_DLYBS & DATAFLASH_TCSS) |
>  	       (AT91_SPI_DLYBCT & DATAFLASH_TCHS) |
>  	       ((get_mck_clk_rate() / AT91_SPI_CLK) << 8),
> -	       AT91_BASE_SPI + AT91_SPI_CSR(3));
> +	       ATMEL_BASE_SPI0 + AT91_SPI_CSR(3));
>  #endif
>  
>  	/* SPI_Enable */
> -	writel(AT91_SPI_SPIEN, AT91_BASE_SPI + AT91_SPI_CR);
> +	writel(AT91_SPI_SPIEN, ATMEL_BASE_SPI0 + AT91_SPI_CR);
>  
> -	while (!(readl(AT91_BASE_SPI + AT91_SPI_SR) & AT91_SPI_SPIENS));
> +	while (!(readl(ATMEL_BASE_SPI0 + AT91_SPI_SR) & AT91_SPI_SPIENS))
> +		;
>  
>  	/*
>  	 * Add tempo to get SPI in a safe state.
>  	 * Should not be needed for new silicon (Rev B)
>  	 */
>  	udelay(500000);
> -	readl(AT91_BASE_SPI + AT91_SPI_SR);
> -	readl(AT91_BASE_SPI + AT91_SPI_RDR);
> +	readl(ATMEL_BASE_SPI0 + AT91_SPI_SR);
> +	readl(ATMEL_BASE_SPI0 + AT91_SPI_RDR);
>  
>  }
>  
> @@ -100,33 +109,33 @@ void AT91F_SpiEnable(int cs)
>  
>  	switch (cs) {
>  	case 0:	/* Configure SPI CS0 for Serial DataFlash AT45DBxx */
> -		mode = readl(AT91_BASE_SPI + AT91_SPI_MR);
> +		mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		mode &= 0xFFF0FFFF;
>  		writel(mode | ((AT91_SPI_PCS0_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
> -		       AT91_BASE_SPI + AT91_SPI_MR);
> +		       ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		break;
>  	case 1:	/* Configure SPI CS1 for Serial DataFlash AT45DBxx */
> -		mode = readl(AT91_BASE_SPI + AT91_SPI_MR);
> +		mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		mode &= 0xFFF0FFFF;
>  		writel(mode | ((AT91_SPI_PCS1_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
> -		       AT91_BASE_SPI + AT91_SPI_MR);
> +		       ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		break;
>  	case 2:	/* Configure SPI CS2 for Serial DataFlash AT45DBxx */
> -		mode = readl(AT91_BASE_SPI + AT91_SPI_MR);
> +		mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		mode &= 0xFFF0FFFF;
>  		writel(mode | ((AT91_SPI_PCS2_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
> -		       AT91_BASE_SPI + AT91_SPI_MR);
> +		       ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		break;
>  	case 3:
> -		mode = readl(AT91_BASE_SPI + AT91_SPI_MR);
> +		mode = readl(ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		mode &= 0xFFF0FFFF;
>  		writel(mode | ((AT91_SPI_PCS3_DATAFLASH_CARD<<16) & AT91_SPI_PCS),
> -		       AT91_BASE_SPI + AT91_SPI_MR);
> +		       ATMEL_BASE_SPI0 + AT91_SPI_MR);
>  		break;
>  	}
>  
>  	/* SPI_Enable */
> -	writel(AT91_SPI_SPIEN, AT91_BASE_SPI + AT91_SPI_CR);
> +	writel(AT91_SPI_SPIEN, ATMEL_BASE_SPI0 + AT91_SPI_CR);
>  }
>  
>  unsigned int AT91F_SpiWrite1(AT91PS_DataflashDesc pDesc);
> @@ -134,37 +143,48 @@ unsigned int AT91F_SpiWrite1(AT91PS_DataflashDesc pDesc);
>  unsigned int AT91F_SpiWrite(AT91PS_DataflashDesc pDesc)
>  {
>  	unsigned int timeout;
> +	unsigned int timebase;
>  
>  	pDesc->state = BUSY;
>  
> -	writel(AT91_SPI_TXTDIS + AT91_SPI_RXTDIS, AT91_BASE_SPI + AT91_SPI_PTCR);
> +	writel(AT91_SPI_TXTDIS + AT91_SPI_RXTDIS,
> +		ATMEL_BASE_SPI0 + AT91_SPI_PTCR);
>  
>  	/* Initialize the Transmit and Receive Pointer */
> -	writel((unsigned int)pDesc->rx_cmd_pt, AT91_BASE_SPI + AT91_SPI_RPR);
> -	writel((unsigned int)pDesc->tx_cmd_pt, AT91_BASE_SPI + AT91_SPI_TPR);
> +	writel((unsigned int)pDesc->rx_cmd_pt,
> +		ATMEL_BASE_SPI0 + AT91_SPI_RPR);
> +	writel((unsigned int)pDesc->tx_cmd_pt,
> +		ATMEL_BASE_SPI0 + AT91_SPI_TPR);
>  
>  	/* Intialize the Transmit and Receive Counters */
> -	writel(pDesc->rx_cmd_size, AT91_BASE_SPI + AT91_SPI_RCR);
> -	writel(pDesc->tx_cmd_size, AT91_BASE_SPI + AT91_SPI_TCR);
> +	writel(pDesc->rx_cmd_size, ATMEL_BASE_SPI0 + AT91_SPI_RCR);
> +	writel(pDesc->tx_cmd_size, ATMEL_BASE_SPI0 + AT91_SPI_TCR);
>  
>  	if (pDesc->tx_data_size != 0) {
>  		/* Initialize the Next Transmit and Next Receive Pointer */
> -		writel((unsigned int)pDesc->rx_data_pt, AT91_BASE_SPI + AT91_SPI_RNPR);
> -		writel((unsigned int)pDesc->tx_data_pt, AT91_BASE_SPI + AT91_SPI_TNPR);
> +		writel((unsigned int)pDesc->rx_data_pt,
> +			ATMEL_BASE_SPI0 + AT91_SPI_RNPR);
> +		writel((unsigned int)pDesc->tx_data_pt,
> +			ATMEL_BASE_SPI0 + AT91_SPI_TNPR);
>  
>  		/* Intialize the Next Transmit and Next Receive Counters */
> -		writel(pDesc->rx_data_size, AT91_BASE_SPI + AT91_SPI_RNCR);
> -		writel(pDesc->tx_data_size, AT91_BASE_SPI + AT91_SPI_TNCR);
> +		writel(pDesc->rx_data_size,
> +			ATMEL_BASE_SPI0 + AT91_SPI_RNCR);
> +		writel(pDesc->tx_data_size,
> +			ATMEL_BASE_SPI0 + AT91_SPI_TNCR);
>  	}
>  
>  	/* arm simple, non interrupt dependent timer */
> -	reset_timer_masked();
> +	timebase = get_timer(0);
>  	timeout = 0;
>  
> -	writel(AT91_SPI_TXTEN + AT91_SPI_RXTEN, AT91_BASE_SPI + AT91_SPI_PTCR);
> -	while (!(readl(AT91_BASE_SPI + AT91_SPI_SR) & AT91_SPI_RXBUFF) &&
> -		((timeout = get_timer_masked()) < CONFIG_SYS_SPI_WRITE_TOUT));
> -	writel(AT91_SPI_TXTDIS + AT91_SPI_RXTDIS, AT91_BASE_SPI + AT91_SPI_PTCR);
> +	writel(AT91_SPI_TXTEN + AT91_SPI_RXTEN,
> +		ATMEL_BASE_SPI0 + AT91_SPI_PTCR);
> +	while (!(readl(ATMEL_BASE_SPI0 + AT91_SPI_SR) & AT91_SPI_RXBUFF) &&
> +		((timeout = get_timer(timebase)) < CONFIG_SYS_SPI_WRITE_TOUT))
> +		;
> +	writel(AT91_SPI_TXTDIS + AT91_SPI_RXTDIS,
> +		ATMEL_BASE_SPI0 + AT91_SPI_PTCR);
>  	pDesc->state = IDLE;
>  
>  	if (timeout >= CONFIG_SYS_SPI_WRITE_TOUT) {
> diff --git a/include/dataflash.h b/include/dataflash.h
> index 63b3bf9..96ac097 100644
> --- a/include/dataflash.h
> +++ b/include/dataflash.h
> @@ -34,7 +34,6 @@
>  #define _DataFlash_h
>  
>  
> -#include <asm/arch/hardware.h>
>  #include "config.h"
>  
>  /*number of protected area*/

  reply	other threads:[~2011-02-18 12:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18 12:49 [U-Boot] [PATCH 0/15] ATMEL rework Reinhard Meyer
2011-02-18 12:49 ` [U-Boot] [PATCH 01/15] AT91: rework at91sam9260.h Reinhard Meyer
2011-02-18 12:50   ` [U-Boot] [PATCH 02/15] AT91: rework at91sam9261.h Reinhard Meyer
2011-02-18 12:50     ` [U-Boot] [PATCH 03/15] AT91: rework at91sam9263.h Reinhard Meyer
2011-02-18 12:50       ` [U-Boot] [PATCH 04/15] AT91: rework at91sam9g45.h Reinhard Meyer
2011-02-18 12:50         ` [U-Boot] [PATCH 05/15] AT91: cleanup hardware.h, remove memory-map.h Reinhard Meyer
2011-02-18 12:25           ` Andreas Bießmann
2011-02-18 12:50             ` Reinhard Meyer
2011-02-18 12:50           ` [U-Boot] [PATCH 06/15] AT91: fix related arch-at91 header files Reinhard Meyer
2011-02-18 12:27             ` Andreas Bießmann
2011-02-18 12:52               ` Reinhard Meyer
2011-02-18 12:50             ` [U-Boot] [PATCH 07/15] AT91: fix related at91 system/driver files Reinhard Meyer
2011-02-18 12:50               ` [U-Boot] [PATCH 08/15] AT91: fix related at91 driver files Reinhard Meyer
2011-02-18 12:50                 ` [U-Boot] [PATCH 09/15] ATMEL: fix related common atmel " Reinhard Meyer
2011-02-18 12:50                   ` [U-Boot] [PATCH 10/15] AT91: cleanup at91sam9260_matrix.h to struct SoC access Reinhard Meyer
2011-02-18 12:50                     ` [U-Boot] [PATCH 11/15] AT91: change includes from asm/arch/io.h to asm/io.h Reinhard Meyer
2011-02-18 12:50                       ` [U-Boot] [PATCH 12/15] ATMEL: fix dataflash (dirty) Reinhard Meyer
2011-02-18 12:33                         ` Andreas Bießmann [this message]
2011-02-18 12:56                           ` Reinhard Meyer
2011-02-18 12:50                         ` [U-Boot] [PATCH 13/15] AT91: remove LEGACY from at91_rstc.h Reinhard Meyer
2011-02-18 12:50                           ` [U-Boot] [PATCH 14/15] AT91: fix at91sam_wdt.c to reworked header files Reinhard Meyer
2011-02-18 12:50                             ` [U-Boot] [PATCH 15/15] AT91: fix timer.c - remove reset_timer() Reinhard Meyer
2011-04-17 15:25   ` [U-Boot] [PATCH 01/15] AT91: rework at91sam9260.h Andreas Bießmann
2011-02-19  9:08 ` [U-Boot] [PATCH 0/15] ATMEL rework Remy Bohmer
2011-04-11  9:13 ` Reinhard Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D5E6722.6040803@gmail.com \
    --to=andreas.devel@googlemail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox