xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc85xx/ether_fcc.c (revision 412411cb2e6f5694b717d8ff574bcf61bfc476cf)
1a47a12beSStefan Roese /*
2a47a12beSStefan Roese  * MPC8560 FCC Fast Ethernet
3a47a12beSStefan Roese  * Copyright (c) 2003 Motorola,Inc.
4a47a12beSStefan Roese  * Xianghua Xiao, (X.Xiao@motorola.com)
5a47a12beSStefan Roese  *
6a47a12beSStefan Roese  * Copyright (c) 2000 MontaVista Software, Inc.   Dan Malek (dmalek@jlc.net)
7a47a12beSStefan Roese  *
8a47a12beSStefan Roese  * (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9a47a12beSStefan Roese  * Marius Groeger <mgroeger@sysgo.de>
10a47a12beSStefan Roese  *
11a47a12beSStefan Roese  * See file CREDITS for list of people who contributed to this
12a47a12beSStefan Roese  * project.
13a47a12beSStefan Roese  *
14a47a12beSStefan Roese  * This program is free software; you can redistribute it and/or
15a47a12beSStefan Roese  * modify it under the terms of the GNU General Public License as
16a47a12beSStefan Roese  * published by the Free Software Foundation; either version 2 of
17a47a12beSStefan Roese  * the License, or (at your option) any later version.
18a47a12beSStefan Roese  *
19a47a12beSStefan Roese  * This program is distributed in the hope that it will be useful,
20a47a12beSStefan Roese  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21a47a12beSStefan Roese  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22a47a12beSStefan Roese  * GNU General Public License for more details.
23a47a12beSStefan Roese  *
24a47a12beSStefan Roese  * You should have received a copy of the GNU General Public License
25a47a12beSStefan Roese  * along with this program; if not, write to the Free Software
26a47a12beSStefan Roese  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27a47a12beSStefan Roese  * MA 02111-1307 USA
28a47a12beSStefan Roese  */
29a47a12beSStefan Roese 
30a47a12beSStefan Roese /*
31a47a12beSStefan Roese  * MPC8560 FCC Fast Ethernet
32a47a12beSStefan Roese  * Basic ET HW initialization and packet RX/TX routines
33a47a12beSStefan Roese  *
34a47a12beSStefan Roese  * This code will not perform the IO port configuration. This should be
35a47a12beSStefan Roese  * done in the iop_conf_t structure specific for the board.
36a47a12beSStefan Roese  *
37a47a12beSStefan Roese  * TODO:
38a47a12beSStefan Roese  * add a PHY driver to do the negotiation
39a47a12beSStefan Roese  * reflect negotiation results in FPSMR
40a47a12beSStefan Roese  * look for ways to configure the board specific stuff elsewhere, eg.
41a47a12beSStefan Roese  *    config_xxx.h or the board directory
42a47a12beSStefan Roese  */
43a47a12beSStefan Roese 
44a47a12beSStefan Roese #include <common.h>
45a47a12beSStefan Roese #include <malloc.h>
46a47a12beSStefan Roese #include <asm/cpm_85xx.h>
47a47a12beSStefan Roese #include <command.h>
48a47a12beSStefan Roese #include <config.h>
49a47a12beSStefan Roese #include <net.h>
50a47a12beSStefan Roese 
51a47a12beSStefan Roese #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
52a47a12beSStefan Roese #include <miiphy.h>
53a47a12beSStefan Roese #endif
54a47a12beSStefan Roese 
55e2a53458SMike Frysinger #if defined(CONFIG_ETHER_ON_FCC) && defined(CONFIG_CMD_NET)
56a47a12beSStefan Roese 
57a47a12beSStefan Roese static struct ether_fcc_info_s
58a47a12beSStefan Roese {
59a47a12beSStefan Roese 	int ether_index;
60a47a12beSStefan Roese 	int proff_enet;
61a47a12beSStefan Roese 	ulong cpm_cr_enet_sblock;
62a47a12beSStefan Roese 	ulong cpm_cr_enet_page;
63a47a12beSStefan Roese 	ulong cmxfcr_mask;
64a47a12beSStefan Roese 	ulong cmxfcr_value;
65a47a12beSStefan Roese }
66a47a12beSStefan Roese 	ether_fcc_info[] =
67a47a12beSStefan Roese {
68a47a12beSStefan Roese #ifdef CONFIG_ETHER_ON_FCC1
69a47a12beSStefan Roese {
70a47a12beSStefan Roese 	0,
71a47a12beSStefan Roese 	PROFF_FCC1,
72a47a12beSStefan Roese 	CPM_CR_FCC1_SBLOCK,
73a47a12beSStefan Roese 	CPM_CR_FCC1_PAGE,
74a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_MASK1,
75a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_VALUE1
76a47a12beSStefan Roese },
77a47a12beSStefan Roese #endif
78a47a12beSStefan Roese 
79a47a12beSStefan Roese #ifdef CONFIG_ETHER_ON_FCC2
80a47a12beSStefan Roese {
81a47a12beSStefan Roese 	1,
82a47a12beSStefan Roese 	PROFF_FCC2,
83a47a12beSStefan Roese 	CPM_CR_FCC2_SBLOCK,
84a47a12beSStefan Roese 	CPM_CR_FCC2_PAGE,
85a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_MASK2,
86a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_VALUE2
87a47a12beSStefan Roese },
88a47a12beSStefan Roese #endif
89a47a12beSStefan Roese 
90a47a12beSStefan Roese #ifdef CONFIG_ETHER_ON_FCC3
91a47a12beSStefan Roese {
92a47a12beSStefan Roese 	2,
93a47a12beSStefan Roese 	PROFF_FCC3,
94a47a12beSStefan Roese 	CPM_CR_FCC3_SBLOCK,
95a47a12beSStefan Roese 	CPM_CR_FCC3_PAGE,
96a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_MASK3,
97a47a12beSStefan Roese 	CONFIG_SYS_CMXFCR_VALUE3
98a47a12beSStefan Roese },
99a47a12beSStefan Roese #endif
100a47a12beSStefan Roese };
101a47a12beSStefan Roese 
102a47a12beSStefan Roese /*---------------------------------------------------------------------*/
103a47a12beSStefan Roese 
104a47a12beSStefan Roese /* Maximum input DMA size.  Must be a should(?) be a multiple of 4. */
105a47a12beSStefan Roese #define PKT_MAXDMA_SIZE         1520
106a47a12beSStefan Roese 
107a47a12beSStefan Roese /* The FCC stores dest/src/type, data, and checksum for receive packets. */
108a47a12beSStefan Roese #define PKT_MAXBUF_SIZE         1518
109a47a12beSStefan Roese #define PKT_MINBUF_SIZE         64
110a47a12beSStefan Roese 
111a47a12beSStefan Roese /* Maximum input buffer size.  Must be a multiple of 32. */
112a47a12beSStefan Roese #define PKT_MAXBLR_SIZE         1536
113a47a12beSStefan Roese 
114a47a12beSStefan Roese #define TOUT_LOOP 1000000
115a47a12beSStefan Roese 
116a47a12beSStefan Roese #define TX_BUF_CNT 2
117a47a12beSStefan Roese 
118a47a12beSStefan Roese static uint rxIdx;	/* index of the current RX buffer */
119a47a12beSStefan Roese static uint txIdx;	/* index of the current TX buffer */
120a47a12beSStefan Roese 
121a47a12beSStefan Roese /*
122a47a12beSStefan Roese  * FCC Ethernet Tx and Rx buffer descriptors.
123a47a12beSStefan Roese  * Provide for Double Buffering
124a47a12beSStefan Roese  * Note: PKTBUFSRX is defined in net.h
125a47a12beSStefan Roese  */
126a47a12beSStefan Roese 
127a47a12beSStefan Roese typedef volatile struct rtxbd {
128a47a12beSStefan Roese     cbd_t rxbd[PKTBUFSRX];
129a47a12beSStefan Roese     cbd_t txbd[TX_BUF_CNT];
130a47a12beSStefan Roese } RTXBD;
131a47a12beSStefan Roese 
132a47a12beSStefan Roese /*  Good news: the FCC supports external BDs! */
133a47a12beSStefan Roese #ifdef __GNUC__
134a47a12beSStefan Roese static RTXBD rtx __attribute__ ((aligned(8)));
135a47a12beSStefan Roese #else
136a47a12beSStefan Roese #error "rtx must be 64-bit aligned"
137a47a12beSStefan Roese #endif
138a47a12beSStefan Roese 
139a47a12beSStefan Roese #undef ET_DEBUG
140a47a12beSStefan Roese 
141*412411cbSJoe Hershberger static int fec_send(struct eth_device *dev, void *packet, int length)
142a47a12beSStefan Roese {
143a47a12beSStefan Roese     int i = 0;
144a47a12beSStefan Roese     int result = 0;
145a47a12beSStefan Roese 
146a47a12beSStefan Roese     if (length <= 0) {
147a47a12beSStefan Roese 	printf("fec: bad packet size: %d\n", length);
148a47a12beSStefan Roese 	goto out;
149a47a12beSStefan Roese     }
150a47a12beSStefan Roese 
151a47a12beSStefan Roese     for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
152a47a12beSStefan Roese 	if (i >= TOUT_LOOP) {
153a47a12beSStefan Roese 	    printf("fec: tx buffer not ready\n");
154a47a12beSStefan Roese 	    goto out;
155a47a12beSStefan Roese 	}
156a47a12beSStefan Roese     }
157a47a12beSStefan Roese 
158a47a12beSStefan Roese     rtx.txbd[txIdx].cbd_bufaddr = (uint)packet;
159a47a12beSStefan Roese     rtx.txbd[txIdx].cbd_datlen = length;
160a47a12beSStefan Roese     rtx.txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST | \
161a47a12beSStefan Roese 			       BD_ENET_TX_TC | BD_ENET_TX_PAD);
162a47a12beSStefan Roese 
163a47a12beSStefan Roese     for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
164a47a12beSStefan Roese 	if (i >= TOUT_LOOP) {
165a47a12beSStefan Roese 	    printf("fec: tx error\n");
166a47a12beSStefan Roese 	    goto out;
167a47a12beSStefan Roese 	}
168a47a12beSStefan Roese     }
169a47a12beSStefan Roese 
170a47a12beSStefan Roese #ifdef ET_DEBUG
171a47a12beSStefan Roese     printf("cycles: 0x%x txIdx=0x%04x status: 0x%04x\n", i, txIdx,rtx.txbd[txIdx].cbd_sc);
172a47a12beSStefan Roese     printf("packets at 0x%08x, length_in_bytes=0x%x\n",(uint)packet,length);
173a47a12beSStefan Roese     for(i=0;i<(length/16 + 1);i++) {
174a47a12beSStefan Roese 	 printf("%08x %08x %08x %08x\n",*((uint *)rtx.txbd[txIdx].cbd_bufaddr+i*4),\
175a47a12beSStefan Roese     *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 1),*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 2), \
176a47a12beSStefan Roese     *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 3));
177a47a12beSStefan Roese     }
178a47a12beSStefan Roese #endif
179a47a12beSStefan Roese 
180a47a12beSStefan Roese     /* return only status bits */
181a47a12beSStefan Roese     result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
182a47a12beSStefan Roese     txIdx = (txIdx + 1) % TX_BUF_CNT;
183a47a12beSStefan Roese 
184a47a12beSStefan Roese out:
185a47a12beSStefan Roese     return result;
186a47a12beSStefan Roese }
187a47a12beSStefan Roese 
188a47a12beSStefan Roese static int fec_recv(struct eth_device* dev)
189a47a12beSStefan Roese {
190a47a12beSStefan Roese     int length;
191a47a12beSStefan Roese 
192a47a12beSStefan Roese     for (;;)
193a47a12beSStefan Roese     {
194a47a12beSStefan Roese 	if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
195a47a12beSStefan Roese 	    length = -1;
196a47a12beSStefan Roese 	    break;     /* nothing received - leave for() loop */
197a47a12beSStefan Roese 	}
198a47a12beSStefan Roese 	length = rtx.rxbd[rxIdx].cbd_datlen;
199a47a12beSStefan Roese 
200a47a12beSStefan Roese 	if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
201a47a12beSStefan Roese 	    printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
202a47a12beSStefan Roese 	}
203a47a12beSStefan Roese 	else {
204a47a12beSStefan Roese 	    /* Pass the packet up to the protocol layers. */
205a47a12beSStefan Roese 	    NetReceive(NetRxPackets[rxIdx], length - 4);
206a47a12beSStefan Roese 	}
207a47a12beSStefan Roese 
208a47a12beSStefan Roese 
209a47a12beSStefan Roese 	/* Give the buffer back to the FCC. */
210a47a12beSStefan Roese 	rtx.rxbd[rxIdx].cbd_datlen = 0;
211a47a12beSStefan Roese 
212a47a12beSStefan Roese 	/* wrap around buffer index when necessary */
213a47a12beSStefan Roese 	if ((rxIdx + 1) >= PKTBUFSRX) {
214a47a12beSStefan Roese 	    rtx.rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
215a47a12beSStefan Roese 	    rxIdx = 0;
216a47a12beSStefan Roese 	}
217a47a12beSStefan Roese 	else {
218a47a12beSStefan Roese 	    rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
219a47a12beSStefan Roese 	    rxIdx++;
220a47a12beSStefan Roese 	}
221a47a12beSStefan Roese     }
222a47a12beSStefan Roese     return length;
223a47a12beSStefan Roese }
224a47a12beSStefan Roese 
225a47a12beSStefan Roese 
226a47a12beSStefan Roese static int fec_init(struct eth_device* dev, bd_t *bis)
227a47a12beSStefan Roese {
228a47a12beSStefan Roese     struct ether_fcc_info_s * info = dev->priv;
229a47a12beSStefan Roese     int i;
230a47a12beSStefan Roese     volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
231a47a12beSStefan Roese     volatile ccsr_cpm_cp_t *cp = &(cpm->im_cpm_cp);
232a47a12beSStefan Roese     fcc_enet_t *pram_ptr;
233a47a12beSStefan Roese     unsigned long mem_addr;
234a47a12beSStefan Roese 
235a47a12beSStefan Roese #if 0
236a47a12beSStefan Roese     mii_discover_phy();
237a47a12beSStefan Roese #endif
238a47a12beSStefan Roese 
239a47a12beSStefan Roese     /* 28.9 - (1-2): ioports have been set up already */
240a47a12beSStefan Roese 
241a47a12beSStefan Roese     /* 28.9 - (3): connect FCC's tx and rx clocks */
242a47a12beSStefan Roese     cpm->im_cpm_mux.cmxuar = 0; /* ATM */
243a47a12beSStefan Roese     cpm->im_cpm_mux.cmxfcr = (cpm->im_cpm_mux.cmxfcr & ~info->cmxfcr_mask) |
244a47a12beSStefan Roese 							info->cmxfcr_value;
245a47a12beSStefan Roese 
246a47a12beSStefan Roese     /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, set Mode Ethernet */
247a47a12beSStefan Roese     if(info->ether_index == 0) {
248a47a12beSStefan Roese 	cpm->im_cpm_fcc1.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
249a47a12beSStefan Roese     } else if (info->ether_index == 1) {
250a47a12beSStefan Roese 	cpm->im_cpm_fcc2.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
251a47a12beSStefan Roese     } else if (info->ether_index == 2) {
252a47a12beSStefan Roese 	cpm->im_cpm_fcc3.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
253a47a12beSStefan Roese     }
254a47a12beSStefan Roese 
255a47a12beSStefan Roese     /* 28.9 - (5): FPSMR: enable full duplex, select CCITT CRC for Ethernet,MII */
256a47a12beSStefan Roese     if(info->ether_index == 0) {
257a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
258a47a12beSStefan Roese     } else if (info->ether_index == 1){
259a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
260a47a12beSStefan Roese     } else if (info->ether_index == 2){
261a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
262a47a12beSStefan Roese     }
263a47a12beSStefan Roese 
264a47a12beSStefan Roese     /* 28.9 - (6): FDSR: Ethernet Syn */
265a47a12beSStefan Roese     if(info->ether_index == 0) {
266a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fdsr = 0xD555;
267a47a12beSStefan Roese     } else if (info->ether_index == 1) {
268a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fdsr = 0xD555;
269a47a12beSStefan Roese     } else if (info->ether_index == 2) {
270a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fdsr = 0xD555;
271a47a12beSStefan Roese     }
272a47a12beSStefan Roese 
273a47a12beSStefan Roese     /* reset indeces to current rx/tx bd (see eth_send()/eth_rx()) */
274a47a12beSStefan Roese     rxIdx = 0;
275a47a12beSStefan Roese     txIdx = 0;
276a47a12beSStefan Roese 
277a47a12beSStefan Roese     /* Setup Receiver Buffer Descriptors */
278a47a12beSStefan Roese     for (i = 0; i < PKTBUFSRX; i++)
279a47a12beSStefan Roese     {
280a47a12beSStefan Roese       rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
281a47a12beSStefan Roese       rtx.rxbd[i].cbd_datlen = 0;
282a47a12beSStefan Roese       rtx.rxbd[i].cbd_bufaddr = (uint)NetRxPackets[i];
283a47a12beSStefan Roese     }
284a47a12beSStefan Roese     rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
285a47a12beSStefan Roese 
286a47a12beSStefan Roese     /* Setup Ethernet Transmitter Buffer Descriptors */
287a47a12beSStefan Roese     for (i = 0; i < TX_BUF_CNT; i++)
288a47a12beSStefan Roese     {
289a47a12beSStefan Roese       rtx.txbd[i].cbd_sc = 0;
290a47a12beSStefan Roese       rtx.txbd[i].cbd_datlen = 0;
291a47a12beSStefan Roese       rtx.txbd[i].cbd_bufaddr = 0;
292a47a12beSStefan Roese     }
293a47a12beSStefan Roese     rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
294a47a12beSStefan Roese 
295a47a12beSStefan Roese     /* 28.9 - (7): initialize parameter ram */
296a47a12beSStefan Roese     pram_ptr = (fcc_enet_t *)&(cpm->im_dprambase[info->proff_enet]);
297a47a12beSStefan Roese 
298a47a12beSStefan Roese     /* clear whole structure to make sure all reserved fields are zero */
299a47a12beSStefan Roese     memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
300a47a12beSStefan Roese 
301a47a12beSStefan Roese     /*
302a47a12beSStefan Roese      * common Parameter RAM area
303a47a12beSStefan Roese      *
304a47a12beSStefan Roese      * Allocate space in the reserved FCC area of DPRAM for the
305a47a12beSStefan Roese      * internal buffers.  No one uses this space (yet), so we
306a47a12beSStefan Roese      * can do this.  Later, we will add resource management for
307a47a12beSStefan Roese      * this area.
308a47a12beSStefan Roese      * CPM_FCC_SPECIAL_BASE:	0xB000 for MPC8540, MPC8560
309a47a12beSStefan Roese      *				0x9000 for MPC8541, MPC8555
310a47a12beSStefan Roese      */
311a47a12beSStefan Roese     mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
312a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
313a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
314a47a12beSStefan Roese     /*
315a47a12beSStefan Roese      * Set maximum bytes per receive buffer.
316a47a12beSStefan Roese      * It must be a multiple of 32.
317a47a12beSStefan Roese      */
318a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE; /* 1536 */
319a47a12beSStefan Roese     /* localbus SDRAM should be preferred */
320a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
321a47a12beSStefan Roese 				       CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
322a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
323a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rbdstat = 0;
324a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rbdlen = 0;
325a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_rdptr = 0;
326a47a12beSStefan Roese     /* localbus SDRAM should be preferred */
327a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
328a47a12beSStefan Roese 				       CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
329a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
330a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tbdstat = 0;
331a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tbdlen = 0;
332a47a12beSStefan Roese     pram_ptr->fen_genfcc.fcc_tdptr = 0;
333a47a12beSStefan Roese 
334a47a12beSStefan Roese     /* protocol-specific area */
335a47a12beSStefan Roese     pram_ptr->fen_statbuf = 0x0;
336a47a12beSStefan Roese     pram_ptr->fen_cmask = 0xdebb20e3;	/* CRC mask */
337a47a12beSStefan Roese     pram_ptr->fen_cpres = 0xffffffff;	/* CRC preset */
338a47a12beSStefan Roese     pram_ptr->fen_crcec = 0;
339a47a12beSStefan Roese     pram_ptr->fen_alec = 0;
340a47a12beSStefan Roese     pram_ptr->fen_disfc = 0;
341a47a12beSStefan Roese     pram_ptr->fen_retlim = 15;		/* Retry limit threshold */
342a47a12beSStefan Roese     pram_ptr->fen_retcnt = 0;
343a47a12beSStefan Roese     pram_ptr->fen_pper = 0;
344a47a12beSStefan Roese     pram_ptr->fen_boffcnt = 0;
345a47a12beSStefan Roese     pram_ptr->fen_gaddrh = 0;
346a47a12beSStefan Roese     pram_ptr->fen_gaddrl = 0;
347a47a12beSStefan Roese     pram_ptr->fen_mflr = PKT_MAXBUF_SIZE;   /* maximum frame length register */
348a47a12beSStefan Roese     /*
349a47a12beSStefan Roese      * Set Ethernet station address.
350a47a12beSStefan Roese      *
351a47a12beSStefan Roese      * This is supplied in the board information structure, so we
352a47a12beSStefan Roese      * copy that into the controller.
353a47a12beSStefan Roese      * So far we have only been given one Ethernet address. We make
354a47a12beSStefan Roese      * it unique by setting a few bits in the upper byte of the
355a47a12beSStefan Roese      * non-static part of the address.
356a47a12beSStefan Roese      */
357a47a12beSStefan Roese #define ea eth_get_dev()->enetaddr
358a47a12beSStefan Roese     pram_ptr->fen_paddrh = (ea[5] << 8) + ea[4];
359a47a12beSStefan Roese     pram_ptr->fen_paddrm = (ea[3] << 8) + ea[2];
360a47a12beSStefan Roese     pram_ptr->fen_paddrl = (ea[1] << 8) + ea[0];
361a47a12beSStefan Roese #undef ea
362a47a12beSStefan Roese     pram_ptr->fen_ibdcount = 0;
363a47a12beSStefan Roese     pram_ptr->fen_ibdstart = 0;
364a47a12beSStefan Roese     pram_ptr->fen_ibdend = 0;
365a47a12beSStefan Roese     pram_ptr->fen_txlen = 0;
366a47a12beSStefan Roese     pram_ptr->fen_iaddrh = 0;  /* disable hash */
367a47a12beSStefan Roese     pram_ptr->fen_iaddrl = 0;
368a47a12beSStefan Roese     pram_ptr->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register: 64 */
369a47a12beSStefan Roese     /* pad pointer. use tiptr since we don't need a specific padding char */
370a47a12beSStefan Roese     pram_ptr->fen_padptr = pram_ptr->fen_genfcc.fcc_tiptr;
371a47a12beSStefan Roese     pram_ptr->fen_maxd1 = PKT_MAXDMA_SIZE;	/* maximum DMA1 length:1520 */
372a47a12beSStefan Roese     pram_ptr->fen_maxd2 = PKT_MAXDMA_SIZE;	/* maximum DMA2 length:1520 */
373a47a12beSStefan Roese 
374a47a12beSStefan Roese #if defined(ET_DEBUG)
375a47a12beSStefan Roese     printf("parm_ptr(0xff788500) = %p\n",pram_ptr);
376a47a12beSStefan Roese     printf("pram_ptr->fen_genfcc.fcc_rbase %08x\n",
377a47a12beSStefan Roese 	pram_ptr->fen_genfcc.fcc_rbase);
378a47a12beSStefan Roese     printf("pram_ptr->fen_genfcc.fcc_tbase %08x\n",
379a47a12beSStefan Roese 	pram_ptr->fen_genfcc.fcc_tbase);
380a47a12beSStefan Roese #endif
381a47a12beSStefan Roese 
382a47a12beSStefan Roese     /* 28.9 - (8)(9): clear out events in FCCE */
383a47a12beSStefan Roese     /* 28.9 - (9): FCCM: mask all events */
384a47a12beSStefan Roese     if(info->ether_index == 0) {
385a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fcce = ~0x0;
386a47a12beSStefan Roese 	cpm->im_cpm_fcc1.fccm = 0;
387a47a12beSStefan Roese     } else if (info->ether_index == 1) {
388a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fcce = ~0x0;
389a47a12beSStefan Roese 	cpm->im_cpm_fcc2.fccm = 0;
390a47a12beSStefan Roese     } else if (info->ether_index == 2) {
391a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fcce = ~0x0;
392a47a12beSStefan Roese 	cpm->im_cpm_fcc3.fccm = 0;
393a47a12beSStefan Roese     }
394a47a12beSStefan Roese 
395a47a12beSStefan Roese     /* 28.9 - (10-12): we don't use ethernet interrupts */
396a47a12beSStefan Roese 
397a47a12beSStefan Roese     /* 28.9 - (13)
398a47a12beSStefan Roese      *
399a47a12beSStefan Roese      * Let's re-initialize the channel now.  We have to do it later
400a47a12beSStefan Roese      * than the manual describes because we have just now finished
401a47a12beSStefan Roese      * the BD initialization.
402a47a12beSStefan Roese      */
403a47a12beSStefan Roese     cp->cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
404a47a12beSStefan Roese 			    info->cpm_cr_enet_sblock,
405a47a12beSStefan Roese 			    0x0c,
406a47a12beSStefan Roese 			    CPM_CR_INIT_TRX) | CPM_CR_FLG;
407a47a12beSStefan Roese     do {
408a47a12beSStefan Roese 	__asm__ __volatile__ ("eieio");
409a47a12beSStefan Roese     } while (cp->cpcr & CPM_CR_FLG);
410a47a12beSStefan Roese 
411a47a12beSStefan Roese     /* 28.9 - (14): enable tx/rx in gfmr */
412a47a12beSStefan Roese     if(info->ether_index == 0) {
413a47a12beSStefan Roese 	cpm->im_cpm_fcc1.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
414a47a12beSStefan Roese     } else if (info->ether_index == 1) {
415a47a12beSStefan Roese 	cpm->im_cpm_fcc2.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
416a47a12beSStefan Roese     } else if (info->ether_index == 2) {
417a47a12beSStefan Roese 	cpm->im_cpm_fcc3.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
418a47a12beSStefan Roese     }
419a47a12beSStefan Roese 
420a47a12beSStefan Roese     return 1;
421a47a12beSStefan Roese }
422a47a12beSStefan Roese 
423a47a12beSStefan Roese static void fec_halt(struct eth_device* dev)
424a47a12beSStefan Roese {
425a47a12beSStefan Roese     struct ether_fcc_info_s * info = dev->priv;
426a47a12beSStefan Roese     volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
427a47a12beSStefan Roese 
428a47a12beSStefan Roese     /* write GFMR: disable tx/rx */
429a47a12beSStefan Roese     if(info->ether_index == 0) {
430a47a12beSStefan Roese 	cpm->im_cpm_fcc1.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
431a47a12beSStefan Roese     } else if(info->ether_index == 1) {
432a47a12beSStefan Roese 	cpm->im_cpm_fcc2.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
433a47a12beSStefan Roese     } else if(info->ether_index == 2) {
434a47a12beSStefan Roese 	cpm->im_cpm_fcc3.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
435a47a12beSStefan Roese     }
436a47a12beSStefan Roese }
437a47a12beSStefan Roese 
438a47a12beSStefan Roese int fec_initialize(bd_t *bis)
439a47a12beSStefan Roese {
440a47a12beSStefan Roese 	struct eth_device* dev;
441a47a12beSStefan Roese 	int i;
442a47a12beSStefan Roese 
443a47a12beSStefan Roese 	for (i = 0; i < sizeof(ether_fcc_info) / sizeof(ether_fcc_info[0]); i++)
444a47a12beSStefan Roese 	{
445a47a12beSStefan Roese 		dev = (struct eth_device*) malloc(sizeof *dev);
446a47a12beSStefan Roese 		memset(dev, 0, sizeof *dev);
447a47a12beSStefan Roese 
44848690d80SHeiko Schocher 		sprintf(dev->name, "FCC%d",
449a47a12beSStefan Roese 			ether_fcc_info[i].ether_index + 1);
450a47a12beSStefan Roese 		dev->priv   = &ether_fcc_info[i];
451a47a12beSStefan Roese 		dev->init   = fec_init;
452a47a12beSStefan Roese 		dev->halt   = fec_halt;
453a47a12beSStefan Roese 		dev->send   = fec_send;
454a47a12beSStefan Roese 		dev->recv   = fec_recv;
455a47a12beSStefan Roese 
456a47a12beSStefan Roese 		eth_register(dev);
457a47a12beSStefan Roese 
458a47a12beSStefan Roese #if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) \
459a47a12beSStefan Roese 		&& defined(CONFIG_BITBANGMII)
460a47a12beSStefan Roese 		miiphy_register(dev->name,
461a47a12beSStefan Roese 				bb_miiphy_read,	bb_miiphy_write);
462a47a12beSStefan Roese #endif
463a47a12beSStefan Roese 	}
464a47a12beSStefan Roese 
465a47a12beSStefan Roese 	return 1;
466a47a12beSStefan Roese }
467a47a12beSStefan Roese 
468a47a12beSStefan Roese #endif
469