Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Apr 2006 22:03:57 GMT
From:      Warner Losh <imp@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 95834 for review
Message-ID:  <200604212203.k3LM3vZM024547@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=95834

Change 95834 by imp@imp_hammer on 2006/04/21 22:03:52

	Adjust for differently sized part.  I think that this hard coding
	is unwise, but it works for me for the moment.
	nits also

Affected files ...

.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.c#2 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.h#2 edit

Differences ...

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.c#2 (text+ko) ====

@@ -39,8 +39,9 @@
  * value in response.
  * .KB_C_FN_DEFINITION_END
  */
-static void SendCommand(spiCommand_t *pCommand) {
-
+static void
+SendCommand(spiCommand_t *pCommand)
+{
 	unsigned	value;
 
 	AT91C_BASE_SPI->SPI_PTCR = AT91C_PDC_TXTDIS + AT91C_PDC_RXTDIS;
@@ -72,7 +73,9 @@
  *  Private function to return device status.
  * .KB_C_FN_DEFINITION_END
  */
-static char GetFlashStatus(void) {
+static char
+GetFlashStatus(void)
+{
 
 	p_memset(tx_commandBuffer, 0, 8);
 	tx_commandBuffer[0] = STATUS_REGISTER_READ;
@@ -95,7 +98,9 @@
  *  Private function to poll until the device is ready for next operation.
  * .KB_C_FN_DEFINITION_END
  */
-static void WaitForDeviceReady(void) {
+static void
+WaitForDeviceReady(void)
+{
 	while (!(GetFlashStatus() & 0x80)) ;
 }
 
@@ -110,14 +115,16 @@
  * data in FLASH_PAGE_SIZE intervals.  This also corrupts the data in RAM.
  * .KB_C_FN_DEFINITION_END
  */
-static void ProgramBuffer(unsigned pageAddress, unsigned byteAddress,
-			unsigned src_addr, unsigned size) {
+static void
+ProgramBuffer(unsigned pageAddress, unsigned byteAddress,
+    unsigned src_addr, unsigned size)
+{
 
 	p_memset(tx_commandBuffer, 0, 8);
 	tx_commandBuffer[0] = PROGRAM_THROUGH_BUFFER;
-	tx_commandBuffer[1] = ((pageAddress >> 6) & 0x3F);
-	tx_commandBuffer[2] = ((pageAddress << 2) & 0xFC) |
-				((byteAddress >> 8) & 0x3);
+	tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
+	tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
+				((byteAddress >> 8) & 0x7);
 	tx_commandBuffer[3] = (byteAddress & 0xFF);
 
 	p_memset(rx_commandBuffer, 0, 8);
@@ -138,7 +145,7 @@
 }
 
 
-/* ************************** GLOBAL FUNCTIONS ********************************/
+/*************************** GLOBAL FUNCTIONS ********************************/
 
 
 /*
@@ -148,8 +155,9 @@
  * array command.
  * .KB_C_FN_DEFINITION_END
  */
-void SPI_ReadFlash(unsigned flash_addr, unsigned dest_addr, unsigned size) {
-
+void
+SPI_ReadFlash(unsigned flash_addr, unsigned dest_addr, unsigned size)
+{
 	unsigned	pageAddress, byteAddress;
 
 	// determine page address
@@ -159,10 +167,9 @@
 	byteAddress = flash_addr % FLASH_PAGE_SIZE;
 
 	p_memset(tx_commandBuffer, 0, 8);
-	tx_commandBuffer[0] = CONTINUOUS_ARRAY_READ;
-	tx_commandBuffer[1] = (pageAddress >> 6) & 0x3F;
-	tx_commandBuffer[2] = ((pageAddress << 2) & 0xFC) |
-				((byteAddress >> 8) & 0x3);
+	tx_commandBuffer[1] = ((pageAddress >> 5) & 0xFF);
+	tx_commandBuffer[2] = ((pageAddress << 3) & 0xF8) |
+				((byteAddress >> 8) & 0x7);
 	tx_commandBuffer[3] = (byteAddress & 0xFF);
 
 	p_memset(rx_commandBuffer, 0, 8);
@@ -189,8 +196,9 @@
  * page aligned write operations.
  * .KB_C_FN_DEFINITION_END
  */
-void SPI_WriteFlash(unsigned flash_addr, unsigned src_addr, unsigned size) {
-
+void
+SPI_WriteFlash(unsigned flash_addr, unsigned src_addr, unsigned size)
+{
 	unsigned	pageAddress, byteAddress, this_size;
 
 	// determine page address
@@ -221,8 +229,9 @@
  *  Global function to initialize the SPI flash device/accessor functions.
  * .KB_C_FN_DEFINITION_END
  */
-void SPI_InitFlash(void) {
-
+void
+SPI_InitFlash(void)
+{
 	AT91PS_PIO	pPio;
 	AT91PS_SPI	pSPI = AT91C_BASE_SPI;
 	unsigned	value;
@@ -230,18 +239,13 @@
 
 	// enable CS0, CLK, MOSI, MISO
 	pPio = (AT91PS_PIO)AT91C_BASE_PIOA;
-	pPio->PIO_ASR = (((unsigned)AT91C_PA3_NPCS0) |
-		((unsigned)AT91C_PA1_MOSI) |
-		((unsigned)AT91C_PA0_MISO) |
-		((unsigned)AT91C_PA2_SPCK));
-	pPio->PIO_BSR = 0;
-	pPio->PIO_PDR = (((unsigned)AT91C_PA3_NPCS0) |
-		((unsigned)AT91C_PA1_MOSI) |
-		((unsigned)AT91C_PA0_MISO) |
-		((unsigned)AT91C_PA2_SPCK));
+	pPio->PIO_ASR = AT91C_PA3_NPCS0 | AT91C_PA1_MOSI | AT91C_PA0_MISO |
+	    AT91C_PA2_SPCK;
+	pPio->PIO_PDR = AT91C_PA3_NPCS0 | AT91C_PA1_MOSI | AT91C_PA0_MISO |
+	    AT91C_PA2_SPCK;
 
 	// enable clocks to SPI
-	AT91C_BASE_PMC->PMC_PCER = ((unsigned) 1 << AT91C_ID_SPI);
+	AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_SPI;
 
 	// reset the SPI
 	pSPI->SPI_CR = AT91C_SPI_SWRST;

==== //depot/projects/arm/src/sys/boot/arm/at91/libat91/spi_flash.h#2 (text+ko) ====

@@ -36,7 +36,7 @@
 void SPI_WriteFlash(unsigned flash_addr, unsigned dest_addr, unsigned size);
 void SPI_InitFlash(void);
 
-#define FLASH_PAGE_SIZE	528
+#define FLASH_PAGE_SIZE	1056
 
 // Flash commands
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604212203.k3LM3vZM024547>