[aadk-commits] qwell: u-boot/trunk r17 - in /u-boot/trunk/u-boot_1.1.3: ./ board/s800i/ exam...

aadk-commits at lists.digium.com aadk-commits at lists.digium.com
Sat Nov 4 09:51:39 MST 2006


Author: qwell
Date: Sat Nov  4 10:51:39 2006
New Revision: 17

URL: http://svn.digium.com/view/aadk?rev=17&view=rev
Log:
Add AADK changes for u-boot/

Added:
    u-boot/trunk/u-boot_1.1.3/board/s800i/
    u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/flash.c   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/post-memory.c   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/s800i.c   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/stm_m25p64.c   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/u-boot-flash.lds   (with props)
    u-boot/trunk/u-boot_1.1.3/board/s800i/u-boot.lds   (with props)
    u-boot/trunk/u-boot_1.1.3/include/configs/s800i.h   (with props)
Modified:
    u-boot/trunk/u-boot_1.1.3/Makefile
    u-boot/trunk/u-boot_1.1.3/examples/Makefile
    u-boot/trunk/u-boot_1.1.3/include/configs/bf537.h
    u-boot/trunk/u-boot_1.1.3/lib_blackfin/blackfin_board.h

Modified: u-boot/trunk/u-boot_1.1.3/Makefile
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/Makefile?rev=17&r1=16&r2=17&view=diff
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/Makefile (original)
+++ u-boot/trunk/u-boot_1.1.3/Makefile Sat Nov  4 10:51:39 2006
@@ -147,7 +147,9 @@
 LIBS += drivers/sk98lin/libsk98lin.a
 
 ifneq ($(BOARD), bf537-stamp)
+ifneq ($(BOARD), s800i)
 LIBS += post/libpost.a post/cpu/libcpu.a
+endif
 endif
 
 LIBS += common/libcommon.a
@@ -162,8 +164,10 @@
 SUBDIRS	= tools \
 	  examples
 ifneq ($(BOARD), bf537-stamp)
+ifneq ($(BOARD), s800i)
 SUBDIRS += post \
 	  post/cpu
+endif
 endif
 .PHONY : $(SUBDIRS)
 
@@ -1652,6 +1656,9 @@
 bf537_config	:	unconfig
 	@./mkconfig $(@:_config=) blackfin bf537 bf537-stamp
 
+s800i_config	:	unconfig
+	@./mkconfig $(@:_config=) blackfin bf533 s800i
+
 serial_bf537_config:	unconfig
 	@./mkconfig $(@:_config=) blackfin bf537 serial_bf537
 

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile Sat Nov  4 10:51:39 2006
@@ -1,0 +1,44 @@
+#
+# U-boot - Makefile
+#
+# Copyright (c) 2005 blackfin.uclinux.org
+#
+# (C) Copyright 2000-2004
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+include $(TOPDIR)/config.mk
+
+LIB	= lib$(BOARD).a
+
+OBJS	= $(BOARD).o flash.o ether_bf537.o post-memory.o stm_m25p64.o adm.o
+
+$(LIB):	.depend $(OBJS)
+	$(AR) crv $@ $(OBJS)
+
+#########################################################################
+
+.depend:	Makefile $(SOBJS:.o=.S) $(OBJS:.o=.c)
+		$(CC) -M $(CFLAGS) $(SOBJS:.o=.S) $(OBJS:.o=.c) > $@
+
+sinclude .depend
+
+#########################################################################

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/Makefile
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c Sat Nov  4 10:51:39 2006
@@ -1,0 +1,95 @@
+/*
+ * ADMTek 6996 Driver code taken from switch-adm.c 
+ *
+ * ADMTEK Adm6996I switch configuration module
+ *
+ * Copyright (C) 2006 Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
+ * 02110-1301, USA.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <command.h>
+#include <asm/blackfin.h>
+#include "adm.h" 
+
+static int portmap[] = { 0x1, 0x3, 0x5, 0x7, 0x8, 0x9 };
+
+static void adm_wait(void)
+{
+	/* poll the STABUSY bit */
+	while(*pEMAC_STAADD & STABUSY);
+}
+
+static void adm_write(u16 RegAddr, u16 Data)
+{
+	adm_wait();
+	
+	*pEMAC_STADAT = Data;
+
+	*pEMAC_STAADD = ((RegAddr & 0x3ff) << 6) |
+		STAOP | STAIE | STABUSY;
+}
+
+/*********************************************************************************
+ *		Read an off-chip register in a PHY through the MDC/MDIO port     *
+ *********************************************************************************/
+static u16  adm_read(u16 RegAddr)
+{
+	u16 Data;
+
+	adm_wait();
+
+	*pEMAC_STAADD = ((RegAddr & 0x3ff) << 6) |
+				STAIE | STABUSY;
+	
+	adm_wait();
+	
+	Data = (u16)*pEMAC_STADAT;
+	
+	return Data;
+}
+
+
+void adm_init(void)
+{
+	int x;
+	u16 sysctl;
+	/* Enable PHY output */
+	*pVR_CTL |= PHYCLKOE;
+	/* MDC  = 2.5 MHz */
+	sysctl = SET_MDCDIV(24);
+	/* Odd word alignment for Receive Frame DMA word */
+	/* Configure checksum support and rcve frame word alignment */
+	sysctl |= RXDWA | RXCKS;
+	*pEMAC_SYSCTL  = sysctl;
+	/* Check signature */
+	for (x=0;x<10;x++) 
+		adm_read(0);
+	if (adm_read(0) != 0x4154)
+		return;
+	adm_write(portmap[0], 0x840F);
+	for (x=1;x<5;x++) {
+		adm_write(portmap[x], 0x842F);
+	}
+	printf("Switch: ADM6996I/IX\n");
+		
+	
+}
+

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/adm.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h Sat Nov  4 10:51:39 2006
@@ -1,0 +1,7 @@
+#ifndef _UBOOT_ADM_H
+#define _UBOOT_ADM_H
+
+/* ADM Stuff */
+extern void adm_init(void);
+
+#endif

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/adm.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk Sat Nov  4 10:51:39 2006
@@ -1,0 +1,26 @@
+#
+# (C) Copyright 2001
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+
+TEXT_BASE = 0x03FC0000
+PLATFORM_CPPFLAGS += -I$(TOPDIR)
+

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/config.mk
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c Sat Nov  4 10:51:39 2006
@@ -1,0 +1,458 @@
+/*
+ * ADI Blackfin 537 MAC Ethernet
+ *
+ * Copyright (c) 2005 Analog Device, Inc. 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/blackfin.h>
+#include <net.h>
+#include <command.h>
+#include "ether_bf537.h"
+
+#ifdef CONFIG_POST
+#include <post.h>
+#endif
+
+#undef DEBUG_ETHERNET
+
+#ifdef DEBUG_ETHERNET
+#define DEBUGF(fmt,args...) printf(fmt,##args)
+#else
+#define DEBUGF(fmt,args...)
+#endif
+
+#if (CONFIG_COMMANDS & CFG_CMD_NET)
+
+#define RXBUF_BASE_ADDR		0xFF900000
+#define TXBUF_BASE_ADDR		0xFF800000
+#define TX_BUF_CNT		1
+
+#define TOUT_LOOP 		1000000
+
+ADI_ETHER_BUFFER *txbuf[TX_BUF_CNT];
+ADI_ETHER_BUFFER *rxbuf[PKTBUFSRX];
+static	u16 txIdx;		/* index of the current RX buffer */
+static  u16 rxIdx;		/* index of the current TX buffer */
+
+u8  SrcAddr[6] = {0x02,0x80,0xAD,0x20,0x31,0xB8};
+u16 PHYregs[NO_PHY_REGS];/* u16 PHYADDR; */
+
+// DMAx_CONFIG values at DMA Restart
+const ADI_DMA_CONFIG_REG rxdmacfg ={1, 1, 2, 0, 0, 0, 0, 5, 7};
+/*	
+	rxdmacfg.b_DMA_EN = 1;	// enabled
+	rxdmacfg.b_WNR    = 1;	// write to memory
+	rxdmacfg.b_WDSIZE = 2;	// wordsize is 32 bits
+	rxdmacfg.b_DMA2D  = 0;	// N/A
+	rxdmacfg.b_RESTART= 0;	// N/A
+	rxdmacfg.b_DI_SEL = 0;	// N/A
+	rxdmacfg.b_DI_EN  = 0;	// no interrupt
+	rxdmacfg.b_NDSIZE = 5;	// 5 half words is desc size.
+	rxdmacfg.b_FLOW   = 7;	// large desc flow
+*/
+
+const ADI_DMA_CONFIG_REG txdmacfg ={ 1, 0, 2, 0, 0, 0, 0, 5, 7 };
+/*	
+	txdmacfg.b_DMA_EN = 1;	// enabled
+	txdmacfg.b_WNR    = 0;	// read from memory
+	txdmacfg.b_WDSIZE = 2;	// wordsize is 32 bits
+	txdmacfg.b_DMA2D  = 0;	// N/A
+	txdmacfg.b_RESTART= 0;	// N/A
+	txdmacfg.b_DI_SEL = 0;	// N/A
+	txdmacfg.b_DI_EN  = 0;	// no interrupt
+	txdmacfg.b_NDSIZE = 5;	// 5 half words is desc size.
+	txdmacfg.b_FLOW   = 7;	// large desc flow
+*/
+
+ADI_ETHER_BUFFER *SetupRxBuffer(int no);
+ADI_ETHER_BUFFER *SetupTxBuffer(int no);
+
+
+int eth_send(volatile void *packet, int length)
+{	
+	int i;
+	int result = 0;
+	unsigned int *buf;
+	buf = (unsigned int *)packet;
+
+	if(length<=0){
+		printf("Ethernet: bad packet size: %d\n",length);
+		goto out;
+	}
+	
+	if((*pDMA2_IRQ_STATUS & DMA_ERR)!=0){
+			printf("Ethernet: tx DMA error\n");
+			goto out;
+	}
+	
+	for(i=0;(*pDMA2_IRQ_STATUS & DMA_RUN) != 0; i++){
+		if(i>TOUT_LOOP){
+			puts("Ethernet: tx time out\n");
+			goto out;
+			}
+	}
+	txbuf[txIdx]->FrmData->NoBytes = length;
+	memcpy(txbuf[txIdx]->FrmData->Dest,packet,length);
+	txbuf[txIdx]->Dma[0].START_ADDR = (u32)txbuf[txIdx]->FrmData;
+	*pDMA2_NEXT_DESC_PTR = &txbuf[txIdx]->Dma[0];
+	*pDMA2_CONFIG  = *((u16 *)&txdmacfg);
+	*pEMAC_OPMODE |= TE;
+	
+	for(i=0;(txbuf[txIdx]->StatusWord & TX_COMP) ==0; i++){
+		if(i>TOUT_LOOP){
+			puts("Ethernet: tx error\n");
+			goto out;
+		}
+	}
+	result = txbuf[txIdx]->StatusWord;
+	txbuf[txIdx]->StatusWord = 0;
+	if((txIdx+1) >= TX_BUF_CNT)
+		txIdx = 0;
+	else
+		txIdx++;
+out:
+	return result;
+}
+
+
+int eth_rx(void)
+{	
+	int length;
+	
+	for(;;){
+	if((rxbuf[rxIdx]->StatusWord & RX_COMP) == 0){
+		length = -1;
+		break;
+	}
+	if((rxbuf[rxIdx]->StatusWord & RX_DMAO) != 0){
+		printf("Ethernet: rx dma overrun\n");
+		break;
+	}
+	if((rxbuf[rxIdx]->StatusWord & RX_OK) == 0){
+		printf("Ethernet: rx error\n");
+		break;
+	}
+	length = rxbuf[rxIdx]->StatusWord & 0x000007FF;
+	if(length <= 4){
+		printf("Ethernet: bad frame\n");
+		break;
+	}
+	NetRxPackets[rxIdx] = (volatile uchar *)(rxbuf[rxIdx]->FrmData->Dest);
+	NetReceive(NetRxPackets[rxIdx],length - 4);
+	*pDMA1_IRQ_STATUS |= DMA_DONE|DMA_ERR;
+	rxbuf[rxIdx]->StatusWord = 0x00000000;
+	if((rxIdx+1) >= PKTBUFSRX)
+		rxIdx = 0;
+	else
+		rxIdx ++;
+	}
+	
+	return length;
+}
+
+/**************************************************************
+ *
+ * Ethernet Initialization Routine
+ *
+ *************************************************************/
+
+int eth_init(bd_t *bis)
+{
+	u32	opmode;
+	int 	dat;
+	int 	i;
+	DEBUGF("Eth_init: ......\n");
+
+	txIdx = 0;
+	rxIdx = 0;
+
+/* Initialize System Register */
+	if(SetupSystemRegs(&dat)< 0)
+		return -1;
+
+/* Initialize EMAC address */
+	SetupMacAddr(SrcAddr);
+
+/* Initialize TX and RX buffer */
+	for(i=0;i<PKTBUFSRX;i++)
+		{
+		rxbuf[i] = SetupRxBuffer(i);
+		if(i>0){
+			rxbuf[i-1]->Dma[1].NEXT_DESC_PTR = &(rxbuf[i]->Dma[0]);
+			if(i== (PKTBUFSRX -1))
+				rxbuf[i]->Dma[1].NEXT_DESC_PTR = &(rxbuf[0]->Dma[0]);
+				}
+		}
+	for(i=0;i<TX_BUF_CNT;i++)
+		{
+		txbuf[i] = SetupTxBuffer(i);
+		if(i>0) {
+			txbuf[i-1]->Dma[1].NEXT_DESC_PTR = &(txbuf[i]->Dma[0]);
+			if(i== (TX_BUF_CNT -1))
+				txbuf[i]->Dma[1].NEXT_DESC_PTR = &(txbuf[0]->Dma[0]);
+				}
+		}
+
+/* Set RX DMA */	
+	*pDMA1_NEXT_DESC_PTR = &rxbuf[0]->Dma[0];
+	*pDMA1_CONFIG = *((u16*)&rxbuf[0]->Dma[0].CONFIG);
+
+#if 0
+/* Wait MII done */
+	PollMdcDone();
+#endif	
+
+/* We enable only RX here */
+/* ASTP   : Enable Automatic Pad Stripping
+   PR     : Promiscuous Mode for test
+   PSF    : Receive frames with total length less than 64 bytes.
+   FDMODE : Full Duplex Mode
+   LB	  : Internal Loopback for test
+   RE     : Receiver Enable */
+	if(dat == FDMODE)
+		opmode = ASTP|FDMODE|PSF;
+	else
+		opmode = ASTP|PSF;
+	opmode |= RE;
+	/* Turn on the EMAC */
+	*pEMAC_OPMODE = opmode;
+	return 0;
+}
+
+
+void eth_halt(void)
+{
+	DEBUGF("Eth_halt: ......\n");
+	/* Turn off the EMAC */
+	*pEMAC_OPMODE = 0x00000000;
+	/* Turn off the EMAC RX DMA */
+	*pDMA1_CONFIG = 0x0000;
+	*pDMA2_CONFIG = 0x0000;
+
+}
+
+void SetupMacAddr(u8 *MACaddr)
+{
+	char *tmp,*end;
+	int	i;
+	/* this depends on a little-endian machine */
+	tmp = getenv("ethaddr");
+	if(tmp){
+		for(i=0;i<6;i++){
+			MACaddr[i] = tmp?simple_strtoul(tmp, &end, 16):0;
+			if(tmp)
+				tmp = (*end)?end+1:end;
+		}
+	
+		printf("EthMAC: %02X:%02X:%02X:%02X:%02X:%02X\n",MACaddr[0],MACaddr[1],
+				MACaddr[2],MACaddr[3],MACaddr[4],MACaddr[5]);
+		*pEMAC_ADDRLO = *(u32 *)&MACaddr[0];
+		*pEMAC_ADDRHI = *(u16 *)&MACaddr[4];
+	}
+}
+
+#if 0
+void SoftResetPHY(void)
+{
+	u16 phydat;
+	/* set the reset bit */
+	WrPHYReg(PHYADDR, PHY_MODECTL, PHY_RESET);
+	/* and clear it again */
+	WrPHYReg(PHYADDR, PHY_MODECTL, 0x0000);
+	do {
+	/* poll until reset is complete */
+		phydat = RdPHYReg(PHYADDR, PHY_MODECTL);
+	} while ((phydat & PHY_RESET) != 0);
+}
+#endif
+
+int SetupSystemRegs(int *opmode)
+{
+#if 0
+	/* auto negotiation on  */
+        /* full duplex          */
+        /* 100 Mbps             */
+        phydat = PHY_ANEG_EN | PHY_DUPLEX | PHY_SPD_SET;
+        WrPHYReg(PHYADDR, PHY_MODECTL, phydat);
+	do{
+	udelay(1000);
+	phydat = RdPHYReg(PHYADDR,PHY_MODESTAT);
+	if(count>3000){
+		printf("Link is down, please check your network connection\n");
+		return -1;
+		}
+	count++;
+	}while(!(phydat & 0x0004));
+	
+	phydat = RdPHYReg(PHYADDR, PHY_ANLPAR);
+	if((phydat & 0x0100) || (phydat & 0x0040))
+		*opmode = FDMODE;
+	else
+		*opmode = 0;
+#endif
+	*opmode = FDMODE;
+	*pEMAC_MMC_CTL = RSTC | CROLL;
+	
+	/* Initialize the TX DMA channel registers */
+	*pDMA2_X_COUNT	= 0;
+	*pDMA2_X_MODIFY = 4;
+	*pDMA2_Y_COUNT  = 0;
+	*pDMA2_Y_MODIFY = 0;
+	
+	/* Initialize the RX DMA channel registers */
+	*pDMA1_X_COUNT	= 0;
+	*pDMA1_X_MODIFY = 4;
+	*pDMA1_Y_COUNT  = 0;
+	*pDMA1_Y_MODIFY = 0;
+	return 0;
+}	
+
+ADI_ETHER_BUFFER *SetupRxBuffer(int no)
+{
+	ADI_ETHER_FRAME_BUFFER *frmbuf;
+	ADI_ETHER_BUFFER	*buf;
+	int nobytes_buffer = sizeof(ADI_ETHER_BUFFER[2])/2;	/* ensure a multi. of 4 */
+	int total_size  = nobytes_buffer+RECV_BUFSIZE;
+	
+	buf = (ADI_ETHER_BUFFER *)(RXBUF_BASE_ADDR + no*total_size);
+	frmbuf = (ADI_ETHER_FRAME_BUFFER *)(RXBUF_BASE_ADDR + no*total_size + nobytes_buffer);
+	
+	memset(buf, 0x00, nobytes_buffer);
+	buf->FrmData = frmbuf;
+	memset(frmbuf, 0xfe, RECV_BUFSIZE);
+	
+	/* set up first desc to point to receive frame buffer */
+	buf->Dma[0].NEXT_DESC_PTR = &(buf->Dma[1]);
+	buf->Dma[0].START_ADDR    = (u32)buf->FrmData;
+	buf->Dma[0].CONFIG.b_DMA_EN = 1;	/* enabled */
+	buf->Dma[0].CONFIG.b_WNR    = 1;	/* Write to memory */
+	buf->Dma[0].CONFIG.b_WDSIZE = 2;	/* wordsize is 32 bits */
+	buf->Dma[0].CONFIG.b_NDSIZE = 5;	/* 5 half words is desc size. */
+	buf->Dma[0].CONFIG.b_FLOW   = 7;	/* large desc flow */
+	
+	/* set up second desc to point to status word */
+	buf->Dma[1].NEXT_DESC_PTR = &(buf->Dma[0]);
+	buf->Dma[1].START_ADDR    = (u32)&buf->IPHdrChksum;
+	buf->Dma[1].CONFIG.b_DMA_EN = 1;	/* enabled */
+	buf->Dma[1].CONFIG.b_WNR    = 1;	/* Write to memory */
+	buf->Dma[1].CONFIG.b_WDSIZE = 2;	/* wordsize is 32 bits */
+	buf->Dma[1].CONFIG.b_DI_EN  = 1;	/* enable interrupt */
+	buf->Dma[1].CONFIG.b_NDSIZE = 5;	/* must be 0 when FLOW is 0 */ 
+	buf->Dma[1].CONFIG.b_FLOW   = 7;	/* stop */
+	
+	return buf;
+}	
+
+ADI_ETHER_BUFFER *SetupTxBuffer(int no)
+{
+        ADI_ETHER_FRAME_BUFFER *frmbuf;
+	ADI_ETHER_BUFFER        *buf;
+        int nobytes_buffer = sizeof(ADI_ETHER_BUFFER[2])/2;     /* ensure a multi. of 4 */
+        int total_size  = nobytes_buffer+RECV_BUFSIZE;
+                                                                                                                                                             
+        buf = (ADI_ETHER_BUFFER *)(TXBUF_BASE_ADDR + no*total_size);
+	frmbuf = (ADI_ETHER_FRAME_BUFFER *)(TXBUF_BASE_ADDR + no*total_size + nobytes_buffer);
+	
+        memset(buf, 0x00, nobytes_buffer);
+	buf->FrmData = frmbuf;
+	memset(frmbuf, 0x00, RECV_BUFSIZE);
+                                                                                                                                                             
+        /* set up first desc to point to receive frame buffer */
+        buf->Dma[0].NEXT_DESC_PTR = &(buf->Dma[1]);
+        buf->Dma[0].START_ADDR    = (u32)buf->FrmData;
+        buf->Dma[0].CONFIG.b_DMA_EN = 1;        /* enabled */
+        buf->Dma[0].CONFIG.b_WNR    = 0;        /* Read to memory */
+        buf->Dma[0].CONFIG.b_WDSIZE = 2;        /* wordsize is 32 bits */
+        buf->Dma[0].CONFIG.b_NDSIZE = 5;        /* 5 half words is desc size. */
+        buf->Dma[0].CONFIG.b_FLOW   = 7;        /* large desc flow */
+                                                                                                                                                             
+        /* set up second desc to point to status word */
+        buf->Dma[1].NEXT_DESC_PTR = &(buf->Dma[0]);
+        buf->Dma[1].START_ADDR    = (u32)&buf->StatusWord;
+        buf->Dma[1].CONFIG.b_DMA_EN = 1;        /* enabled */
+        buf->Dma[1].CONFIG.b_WNR    = 1;        /* Write to memory */
+        buf->Dma[1].CONFIG.b_WDSIZE = 2;        /* wordsize is 32 bits */
+        buf->Dma[1].CONFIG.b_DI_EN  = 1;        /* enable interrupt */
+        buf->Dma[1].CONFIG.b_NDSIZE = 0;        /* must be 0 when FLOW is 0 */
+        buf->Dma[1].CONFIG.b_FLOW   = 0;        /* stop */
+                                                                                                                                                             
+        return buf;
+}
+
+#if defined(CONFIG_POST) && defined(CFG_POST_ETHER)
+int ether_post_test(int flags)
+{
+	uchar buf[64];
+	int i, value = 0;
+	int length;
+	
+	printf("\n--------");
+	eth_init(NULL);
+	/* construct the package */
+	buf[0] = buf[6] = (unsigned char)(*pEMAC_ADDRLO &0xFF);
+        buf[1] = buf[7] = (unsigned char)((*pEMAC_ADDRLO &0xFF00)     >>  8);
+        buf[2] = buf[8] = (unsigned char)((*pEMAC_ADDRLO &0xFF0000)   >> 16);
+        buf[3] = buf[9] = (unsigned char)((*pEMAC_ADDRLO &0xFF000000) >> 24);
+        buf[4] = buf[10]= (unsigned char)(*pEMAC_ADDRHI &0xFF);
+        buf[5] = buf[11]= (unsigned char)((*pEMAC_ADDRHI &0xFF00)     >>  8);
+	buf[12] = 0x08;		/* Type: ARP */
+	buf[13] = 0x06;
+	buf[14] = 0x00;		/* Hardware type: Ethernet */
+	buf[15] = 0x01;
+	buf[16] = 0x08;		/* Protocal type: IP */
+	buf[17] = 0x00;
+	buf[18] = 0x06;		/* Hardware size    */
+	buf[19] = 0x04;		/* Protocol size    */
+	buf[20] = 0x00;		/* Opcode: request  */
+	buf[21] = 0x01;
+	
+        for(i=0;i<42;i++)
+                buf[i+22] = i;
+	printf("--------Send 64 bytes......\n");
+	eth_send((volatile void *)buf,64);
+	for(i=0;i<100;i++){
+		udelay(10000);
+		if((rxbuf[rxIdx]->StatusWord & RX_COMP) !=0){
+			value = 1;
+			break;
+		}
+	}
+	if(value == 0){
+		printf("--------EMAC can't receive any data\n");
+		eth_halt();
+		return -1;
+	}
+	length = rxbuf[rxIdx]->StatusWord & 0x000007FF -4;
+        for(i=0;i<length;i++){
+                if(rxbuf[rxIdx]->FrmData->Dest[i] != buf[i]){
+                        printf("--------EMAC receive error data!\n");
+			eth_halt();
+                        return -1;
+                }
+        }
+	printf("--------receive %d bytes, matched\n", length);
+        eth_halt();
+	return 0;
+}
+#endif
+#endif  /* CFG_CMD_NET */

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h Sat Nov  4 10:51:39 2006
@@ -1,0 +1,71 @@
+#define PHYADDR		0x01
+#define NO_PHY_REGS	0x20
+
+#define DEFAULT_PHY_PHYID1	0x0007
+#define DEFAULT_PHY_PHYID2	0xC0A3
+#define PHY_MODECTL		0x00
+#define PHY_MODESTAT		0x01
+#define PHY_PHYID1		0x02
+#define PHY_PHYID2		0x03
+#define PHY_ANAR		0x04
+#define PHY_ANLPAR		0x05
+#define PHY_ANER		0x06
+
+#define PHY_RESET		0x8000
+#define PHY_ANEG_EN		0x1000
+#define PHY_DUPLEX		0x0100
+#define PHY_SPD_SET		0x2000
+
+#define RECV_BUFSIZE	(0x614)
+
+typedef volatile u32	   reg32;
+typedef volatile u16	   reg16;
+
+typedef struct ADI_DMA_CONFIG_REG {
+	u16 b_DMA_EN:1;		/*0		Enabled				*/
+	u16 b_WNR:1;		/*1		Direction			*/
+	u16 b_WDSIZE:2;		/*2:3	Transfer word size			*/
+	u16 b_DMA2D:1;		/*4		DMA mode			*/
+	u16 b_RESTART:1;	/*5		Retain FIFO			*/
+	u16 b_DI_SEL:1;		/*6		Data interrupt timing select	*/
+	u16 b_DI_EN:1;		/*7		Data interrupt enabled		*/
+	u16 b_NDSIZE:4;		/*8:11	Flex descriptor size			*/
+	u16 b_FLOW:3;		/*12:14	Flow					*/
+} ADI_DMA_CONFIG_REG;
+
+typedef struct adi_ether_frame_buffer {
+	u16		NoBytes;		/* the no. of following bytes	*/
+	u8		Dest[6];		/* destination MAC address	*/
+	u8		Srce[6];		/* source MAC address		*/
+	u16		LTfield;		/* length/type field		*/
+	u8		Data[0];		/* payload bytes		*/
+} ADI_ETHER_FRAME_BUFFER;
+/* 16 bytes/struct	*/
+
+typedef struct dma_descriptor {
+	struct dma_descriptor*	NEXT_DESC_PTR;
+	u32			START_ADDR;
+	ADI_DMA_CONFIG_REG	CONFIG;
+} DMA_DESCRIPTOR;
+/* 10 bytes/struct in 12 bytes */
+
+typedef struct adi_ether_buffer {
+	DMA_DESCRIPTOR		Dma[2];	/* first for the frame, second for the status */
+	ADI_ETHER_FRAME_BUFFER	*FrmData;	/* pointer to data	*/
+	struct adi_ether_buffer	*pNext;	/* next buffer	*/
+	struct adi_ether_buffer	*pPrev;	/* prev buffer	*/
+	u16	IPHdrChksum;	/* the IP header checksum	*/
+	u16	IPPayloadChksum;	/* the IP header and payload checksum	*/
+	u32	StatusWord;		/* the frame status word	*/
+} ADI_ETHER_BUFFER;
+/* 40 bytes/struct in 44 bytes */
+
+void SetupMacAddr(u8 *MACaddr);
+
+void PollMdcDone(void);
+void WrPHYReg(u16 PHYAddr, u16 RegAddr, u16 Data);
+u16  RdPHYReg(u16 PHYAddr, u16 RegAddr);
+void SoftResetPHY(void);
+void DumpPHYRegs(void);
+
+int SetupSystemRegs(int *opmode);

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/ether_bf537.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h Sat Nov  4 10:51:39 2006
@@ -1,0 +1,128 @@
+/*
+ * U-boot - flash-defines.h
+ *
+ * Copyright (c) 2005 blackfin.uclinux.org
+ *
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __FLASHDEFINES_H__
+#define __FLASHDEFINES_H__
+
+#include <common.h>
+
+#define V_ULONG(a)		(*(volatile unsigned long *)( a ))
+#define V_BYTE(a)		(*(volatile unsigned char *)( a ))
+#define TRUE			0x1
+#define FALSE			0x0
+#define BUFFER_SIZE		0x80000
+#define NO_COMMAND		0
+#define GET_CODES		1
+#define RESET			2
+#define WRITE			3
+#define FILL			4
+#define ERASE_ALL		5
+#define ERASE_SECT		6
+#define READ			7
+#define GET_SECTNUM		8
+#define FLASH_START_L 		0x0000
+#define FLASH_START_H 		0x2000
+#define FLASH_MAN_ST 		2
+#define RESET_VAL		0xF0
+
+
+asm("#define FLASH_START_L 0x0000");
+asm("#define FLASH_START_H 0x2000");
+
+flash_info_t flash_info[CFG_MAX_FLASH_BANKS];
+
+int get_codes(void);
+int poll_toggle_bit(long lOffset);
+void reset_flash(void);
+int erase_flash(void);
+int erase_block_flash(int);
+void unlock_flash(long lOffset);
+int write_data(long lStart, long lCount, uchar *pnData);
+int read_flash(long nOffset, int *pnValue);
+int write_flash(long nOffset, int nValue);
+void get_sector_number(long lOffset, int *pnSector);
+int GetSectorProtectionStatus(flash_info_t * info, int nSector);
+int GetOffset(int nBlock);
+int AFP_NumSectors = 71;
+long AFP_SectorSize2 = 0x10000;
+int AFP_SectorSize1 = 0x2000;
+
+
+#define NUM_SECTORS		71
+
+#define WRITESEQ1		0x0AAA
+#define WRITESEQ2		0x0554
+#define WRITESEQ3		0x0AAA
+#define WRITESEQ4		0x0AAA
+#define WRITESEQ5		0x0554
+#define WRITESEQ6		0x0AAA
+#define WRITEDATA1		0xaa
+#define WRITEDATA2		0x55
+#define WRITEDATA3		0x80
+#define WRITEDATA4		0xaa
+#define WRITEDATA5		0x55
+#define WRITEDATA6		0x10
+#define PriFlashABegin		0
+#define SecFlashABegin		8
+#define SecFlashBBegin		36
+#define PriFlashAOff		0x0
+#define PriFlashBOff		0x100000
+#define SecFlashAOff		0x10000
+#define SecFlashBOff		0x280000
+#define INVALIDLOCNSTART	0x20270000
+#define INVALIDLOCNEND		0x20280000
+#define BlockEraseVal		0x30
+#define UNLOCKDATA1		0xaa
+#define UNLOCKDATA2		0x55
+#define UNLOCKDATA3		0xa0
+#define GETCODEDATA1		0xaa
+#define GETCODEDATA2		0x55
+#define GETCODEDATA3		0x90
+#define SecFlashASec1Off	0x200000
+#define SecFlashASec2Off	0x204000
+#define SecFlashASec3Off	0x206000
+#define SecFlashASec4Off	0x208000
+#define SecFlashAEndOff		0x210000
+#define SecFlashBSec1Off	0x280000
+#define SecFlashBSec2Off	0x284000
+#define SecFlashBSec3Off	0x286000
+#define SecFlashBSec4Off	0x288000
+#define SecFlashBEndOff		0x290000
+
+#define SECT32			32
+#define SECT33			33
+#define SECT34			34
+#define SECT35			35
+#define SECT36			36
+#define SECT37			37
+#define SECT38			38
+#define SECT39			39
+
+#define FLASH_SUCCESS	0
+#define FLASH_FAIL	-1
+
+#endif

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: u-boot/trunk/u-boot_1.1.3/board/s800i/flash-defines.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: u-boot/trunk/u-boot_1.1.3/board/s800i/flash.c
URL: http://svn.digium.com/view/aadk/u-boot/trunk/u-boot_1.1.3/board/s800i/flash.c?rev=17&view=auto
==============================================================================
--- u-boot/trunk/u-boot_1.1.3/board/s800i/flash.c (added)
+++ u-boot/trunk/u-boot_1.1.3/board/s800i/flash.c Sat Nov  4 10:51:39 2006
@@ -1,0 +1,371 @@
+/*
+ * U-boot - flash.c Flash driver for PSD4256GV
+ *
+ * Copyright (c) 2005 blackfin.uclinux.org
+ * This file is based on BF533EzFlash.c originally written by Analog Devices, Inc.
+ *
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <malloc.h>
+#include "flash-defines.h"
+
+void flash_reset(void)
+{
+	reset_flash();
+}
+
+unsigned long flash_get_size(ulong baseaddr, flash_info_t * info,
+			     int bank_flag)
+{
+	int id = 0, i = 0;
+	static int FlagDev = 1;
+
+	id = get_codes();
+	if(FlagDev)	{
+		FlagDev = 0;
+	}
+	info->flash_id = id;
+	switch (bank_flag) {
+	case 0:
+		for (i = PriFlashABegin; i < SecFlashABegin; i++)
+			info->start[i] = (baseaddr + (i * AFP_SectorSize1));
+		for (i = SecFlashABegin; i < NUM_SECTORS; i++)
+			info->start[i] = (baseaddr + SecFlashAOff + ((i-SecFlashABegin) * AFP_SectorSize2));
+		info->size = 0x400000;
+		info->sector_count = NUM_SECTORS;
+		break;
+	case 1:
+		info->start[0] = baseaddr + SecFlashASec1Off;
+		info->start[1] = baseaddr + SecFlashASec2Off;
+		info->start[2] = baseaddr + SecFlashASec3Off;
+		info->start[3] = baseaddr + SecFlashASec4Off;
+		info->size = 0x10000;
+		info->sector_count = 4;
+		break;
+	case 2:
+		info->start[0] = baseaddr + SecFlashBSec1Off;
+		info->start[1] = baseaddr + SecFlashBSec2Off;
+		info->start[2] = baseaddr + SecFlashBSec3Off;
+		info->start[3] = baseaddr + SecFlashBSec4Off;
+		info->size = 0x10000;
+		info->sector_count = 4;
+		break;
+	}
+	return (info->size);
+}
+
+unsigned long flash_init(void)
+{
+	unsigned long size_b;
+	int i;
+
+	size_b = 0;
+	for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
+		flash_info[i].flash_id = FLASH_UNKNOWN;
+	}
+
+	size_b = flash_get_size(CFG_FLASH_BASE, &flash_info[0], 0);
+
+	if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b == 0) {
+		printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
+			size_b, size_b >> 20);
+	}
+
+	/* flash_protect (int flag, ulong from, ulong to, flash_info_t *info) */
+	(void)flash_protect(FLAG_PROTECT_SET,CFG_FLASH_BASE,(flash_info[0].start[2] - 1),&flash_info[0]);
+	(void)flash_protect(FLAG_PROTECT_SET, 0x203F0000, 0x203FFFFF, &flash_info[0]);
+
+	return (size_b);
+}
+
+void flash_print_info(flash_info_t * info)
+{
+	int i;
+
+	if (info->flash_id == FLASH_UNKNOWN) {
+		printf("missing or unknown FLASH type\n");
+		return;
+	}
+	
+	switch (info->flash_id) {
+	case (STM_ID_29W320DB & 0xFFFF):
+		printf("ST Microelectronics ");
+		break;
+	default:
+		printf("Unknown Vendor ");
+		break;
+	}
+	for (i = 0; i < info->sector_count; ++i) {
+		if ((i % 5) == 0)
+			printf("\n   ");
+		printf(" %08lX%s",
+			info->start[i],
+			info->protect[i] ? " (RO)" : "     ");
+	}
+	printf("\n");
+	return;
+}
+
+int flash_erase(flash_info_t * info, int s_first, int s_last)
+{
+	int cnt = 0,i;
+	int prot,sect;
+
+	prot = 0;
+        for (sect = s_first; sect <= s_last; ++sect) {
+                if (info->protect[sect])
+                        prot++;
+        }
+	if (prot)
+                printf ("- Warning: %d protected sectors will not be erased!\n", prot);
+        else
+                printf ("\n");	
+
+	cnt = s_last - s_first + 1;
+
+	printf("Erasing Flash locations, Please Wait\n");
+	for (i = s_first; i <= s_last; i++) {
+		if (info->protect[i] == 0) {	/* not protected */
+			if(erase_block_flash(i) < 0) {
+				printf("Error Sector erasing \n");
+				return FLASH_FAIL;
+			}
+		}
+	}
+	printf ("\n");
+	return FLASH_SUCCESS;
+}
+
+int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt)
+{
+	int d;
+	if(addr%2){
+		read_flash(addr-1-CFG_FLASH_BASE,&d);
+		d = (int)((d&0x00FF)|(*src++<<8));
+		write_data(addr-1,2,&d);
+		write_data(addr+1,cnt-1,src);
+		}
+	else
+		write_data(addr, cnt, src);
+	return FLASH_SUCCESS;
+}
+
+
+int write_data(long lStart, long lCount, uchar *pnData)
+{
+	long i = 0;
+	unsigned long ulOffset = lStart - CFG_FLASH_BASE;
+	int d;
+	int nSector = 0;
+	int flag = 0;
+
+	if(lCount%2){
+		flag = 1;	
+		lCount = lCount -1;
+		}
+	
+	for(i = 0; i< lCount-1;i+=2,ulOffset+=2){
+		get_sector_number(ulOffset, &nSector);
+		read_flash(ulOffset, &d);
+		if(d != 0xffff) {
+                                printf("Flash not erased at offset 0x%x Please erase to reprogram \n",ulOffset);
+                	        return FLASH_FAIL;
+                        	}
+		unlock_flash(ulOffset);
+		d = (int)(pnData[i]|pnData[i+1]<<8);
+		write_flash(ulOffset,d); 
+		if(poll_toggle_bit(ulOffset) < 0){
+                                printf("Error programming the flash \n");
+                                return FLASH_FAIL;
+                        	}
+	if((i>0)&&(!(i%AFP_SectorSize2)))
+		printf(".");
+	}
+	if(flag){
+		get_sector_number(ulOffset, &nSector);
+                read_flash(ulOffset, &d);
+                if(d != 0xffff) {
+                                printf("Flash not erased at offset 0x%x Please erase to reprogram \n",ulOffset);
+                                return FLASH_FAIL;
+                                }
+                unlock_flash(ulOffset);
+                d = (int)(pnData[i]|(d&0xFF00));
+                write_flash(ulOffset,d);
+                if(poll_toggle_bit(ulOffset) < 0){
+                                printf("Error programming the flash \n");
+                                return FLASH_FAIL;
+                                }
+		}
+	return FLASH_SUCCESS;
+}
+
+int write_flash(long nOffset, int nValue)
+{
+	long addr;
+
+	addr = (CFG_FLASH_BASE + nOffset);
+	*(unsigned volatile short *) addr = nValue;
+	__builtin_bfin_ssync();
+	return FLASH_SUCCESS;
+}
+
+int read_flash(long nOffset, int *pnValue)
+{
+	unsigned short *pFlashAddr = (unsigned short *)(CFG_FLASH_BASE + nOffset);
+
+	*pnValue = *pFlashAddr;
+
+	return TRUE;
+}
+
+int poll_toggle_bit(long lOffset)
+{
+	unsigned int u1,u2;
+	volatile unsigned long *FB = (volatile unsigned long *)(CFG_FLASH_BASE + lOffset);
+	while(1) {
+		u1 = *(volatile unsigned short *)FB;
+		u2 = *(volatile unsigned short *)FB;
+		u1^= u2;
+		if( !(u1 & 0x0040))
+			break;
+		if( !(u2 & 0x0020))
+			continue;
+		else{
+			 u1 = *(volatile unsigned short *)FB;
+	                 u2 = *(volatile unsigned short *)FB;
+			 u1^= u2;
+			 if( !(u1 & 0x0040))
+                        	break;
+			 else{
+				reset_flash();
+				return FLASH_FAIL;
+				}
+			}
+		}
+	return FLASH_SUCCESS;
+}
+
+void reset_flash(void)
+{
+	write_flash(WRITESEQ1, RESET_VAL);
+	/* Wait for 10 micro seconds */
+	udelay(10);
+}
+
+int erase_flash(void)
+{
+	write_flash(WRITESEQ1, WRITEDATA1);
+	write_flash(WRITESEQ2, WRITEDATA2);
+	write_flash(WRITESEQ3, WRITEDATA3);
+	write_flash(WRITESEQ4, WRITEDATA4);
+	write_flash(WRITESEQ5, WRITEDATA5);
+	write_flash(WRITESEQ6, WRITEDATA6);
+
+	if(poll_toggle_bit(0x0000) < 0)
+		return FLASH_FAIL;
+
+	return FLASH_SUCCESS;
+}
+
+int erase_block_flash(int nBlock)
+{
+	long ulSectorOff = 0x0;
+
+	if ((nBlock < 0) || (nBlock > AFP_NumSectors))
+		return FALSE;
+		
+	// figure out the offset of the block in flash

[... 2099 lines stripped ...]


More information about the aadk-commits mailing list