199767f8919635c4928607450d9e0abb932109ceToomas Soome/******************************************************************************
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Filename: spi_flash.c
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Instantiation of SPI flash control routines supporting AT45DB161B
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Revision information:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 17JAN2005 kb_admin initial creation
199767f8919635c4928607450d9e0abb932109ceToomas Soome * adapted from external sources
199767f8919635c4928607450d9e0abb932109ceToomas Soome * tested for basic operation only!!!
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BEGIN_KBDD_BLOCK
199767f8919635c4928607450d9e0abb932109ceToomas Soome * No warranty, expressed or implied, is included with this software. It is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * provided "AS IS" and no warranty of any kind including statutory or aspects
199767f8919635c4928607450d9e0abb932109ceToomas Soome * relating to merchantability or fitness for any purpose is provided. All
199767f8919635c4928607450d9e0abb932109ceToomas Soome * intellectual property rights of others is maintained with the respective
199767f8919635c4928607450d9e0abb932109ceToomas Soome * owners. This software is not copyrighted and is intended for reference
199767f8919635c4928607450d9e0abb932109ceToomas Soome * only.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * END_BLOCK
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome *****************************************************************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "at91rm9200.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "spi_flash.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "lib.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*********************** PRIVATE FUNCTIONS/DATA ******************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic spiCommand_t spi_command;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char tx_commandBuffer[8], rx_commandBuffer[8];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void SendCommand(spiCommand_t *pCommand)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Private function sends 8-bit value to the device and returns the 8-bit
199767f8919635c4928607450d9e0abb932109ceToomas Soome * value in response.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSendCommand(spiCommand_t *pCommand)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome AT91PS_SPI pSPI = AT91C_BASE_SPI;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_PTCR = AT91C_PDC_TXTDIS | AT91C_PDC_RXTDIS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RPR = (unsigned)pCommand->rx_cmd;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RCR = pCommand->rx_cmd_size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TPR = (unsigned)pCommand->tx_cmd;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TCR = pCommand->tx_cmd_size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TNPR = (unsigned)pCommand->tx_data;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TNCR = pCommand->tx_data_size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RNPR = (unsigned)pCommand->rx_data;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RNCR = pCommand->rx_data_size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_PTCR = AT91C_PDC_TXTEN | AT91C_PDC_RXTEN;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // wait for completion
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (!(pSPI->SPI_SR & AT91C_SPI_SPENDRX))
199767f8919635c4928607450d9e0abb932109ceToomas Soome Delay(700);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * char GetFlashStatus(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Private function to return device status.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char
199767f8919635c4928607450d9e0abb932109ceToomas SoomeGetFlashStatus(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset((char *)&spi_command, 0, sizeof(spi_command));
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(tx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[0] = STATUS_REGISTER_READ;
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(rx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd = tx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd = rx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd_size = 2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd_size = 2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome SendCommand(&spi_command);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (rx_commandBuffer[1]);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void WaitForDeviceReady(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Private function to poll until the device is ready for next operation.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void
199767f8919635c4928607450d9e0abb932109ceToomas SoomeWaitForDeviceReady(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (!(GetFlashStatus() & 0x80)) ;
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*************************** GLOBAL FUNCTIONS ********************************/
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void SPI_ReadFlash(unsigned flash_addr, unsigned dest_addr, unsigned size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global function to read the SPI flash device using the continuous read
199767f8919635c4928607450d9e0abb932109ceToomas Soome * array command.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSPI_ReadFlash(unsigned flash_addr, char *dest_addr, unsigned size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned pageAddress, byteAddress;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // determine page address
199767f8919635c4928607450d9e0abb932109ceToomas Soome pageAddress = flash_addr / FLASH_PAGE_SIZE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // determine byte address
199767f8919635c4928607450d9e0abb932109ceToomas Soome byteAddress = flash_addr % FLASH_PAGE_SIZE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(tx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BOOT_BWCT
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[0] = 0xd2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[1] = ((pageAddress >> 6) & 0xFF);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[2] = ((pageAddress << 2) & 0xFC) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((byteAddress >> 8) & 0x3);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[3] = byteAddress & 0xFF;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd = tx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd_size = 8;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_data_size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_data = dest_addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(rx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd = rx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd_size = 8;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_data_size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_data = dest_addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[0] = CONTINUOUS_ARRAY_READ_HF;
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((byteAddress >> 8) & 0x7);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[3] = byteAddress & 0xFF;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd = tx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd_size = 5;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_data_size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_data = dest_addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(rx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd = rx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd_size = 5;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_data_size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_data = dest_addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome SendCommand(&spi_command);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void SPI_WriteFlash(unsigned flash_addr, unsigned src_addr, unsigned size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global function to program the SPI flash device. Notice the warning
199767f8919635c4928607450d9e0abb932109ceToomas Soome * provided in lower-level functions regarding corruption of data in non-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * page aligned write operations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSPI_WriteFlash(unsigned flash_addr, char *src_addr, unsigned size)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned pageAddress, byteAddress;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // determine page address
199767f8919635c4928607450d9e0abb932109ceToomas Soome pageAddress = flash_addr / FLASH_PAGE_SIZE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // determine byte address
199767f8919635c4928607450d9e0abb932109ceToomas Soome byteAddress = flash_addr % FLASH_PAGE_SIZE;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(tx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BOOT_BWCT
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[0] = 0x82;
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[1] = ((pageAddress >> 6) & 0xFF);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[2] = ((pageAddress << 2) & 0xFC) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((byteAddress >> 8) & 0x3);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[3] = (byteAddress & 0xFF);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER;
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((byteAddress >> 8) & 0x7);
199767f8919635c4928607450d9e0abb932109ceToomas Soome tx_commandBuffer[3] = (byteAddress & 0xFF);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome p_memset(rx_commandBuffer, 0, 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd = tx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd = rx_commandBuffer;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_cmd_size = 4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_cmd_size = 4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_data_size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.tx_data = src_addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_data_size = size;
199767f8919635c4928607450d9e0abb932109ceToomas Soome spi_command.rx_data = src_addr;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome SendCommand(&spi_command);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome WaitForDeviceReady();
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_START
199767f8919635c4928607450d9e0abb932109ceToomas Soome * void SPI_InitFlash(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Global function to initialize the SPI flash device/accessor functions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * .KB_C_FN_DEFINITION_END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas SoomeSPI_InitFlash(void)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome AT91PS_PIO pPio;
199767f8919635c4928607450d9e0abb932109ceToomas Soome AT91PS_SPI pSPI = AT91C_BASE_SPI;
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned value;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // enable CS0, CLK, MOSI, MISO
199767f8919635c4928607450d9e0abb932109ceToomas Soome pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pPio->PIO_ASR = AT91C_PIO_PA3 | AT91C_PIO_PA1 | AT91C_PIO_PA0 |
199767f8919635c4928607450d9e0abb932109ceToomas Soome AT91C_PIO_PA2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pPio->PIO_PDR = AT91C_PIO_PA3 | AT91C_PIO_PA1 | AT91C_PIO_PA0 |
199767f8919635c4928607450d9e0abb932109ceToomas Soome AT91C_PIO_PA2;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // enable clocks to SPI
199767f8919635c4928607450d9e0abb932109ceToomas Soome AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_SPI;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome // reset the SPI
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_CR = AT91C_SPI_SWRST;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_MR = (0xf << 24) | AT91C_SPI_MSTR | AT91C_SPI_MODFDIS |
199767f8919635c4928607450d9e0abb932109ceToomas Soome (0xE << 16);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_CSR[0] = AT91C_SPI_CPOL | (4 << 16) | (2 << 8);
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_CR = AT91C_SPI_SPIEN;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_PTCR = AT91C_PDC_TXTDIS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_PTCR = AT91C_PDC_RXTDIS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RNPR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RNCR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TNPR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TNCR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RPR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_RCR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TPR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_TCR = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_PTCR = AT91C_PDC_RXTEN;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pSPI->SPI_PTCR = AT91C_PDC_TXTEN;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome value = pSPI->SPI_RDR;
199767f8919635c4928607450d9e0abb932109ceToomas Soome value = pSPI->SPI_SR;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome value = GetFlashStatus() & 0xFC;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef BOOT_BWCT
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (value != 0xB4 && value != 0xAC)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" Bad SPI status: 0x%x\n", value);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (value != 0xBC)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf(" Bad SPI status: 0x%x\n", value);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome}