blob: 3c4eb1a7eba942b225f5cb59546319ff0243c3d1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +00002/*
3 * MPC8560 FCC Fast Ethernet
4 * Copyright (c) 2003 Motorola,Inc.
5 * Xianghua Xiao, (X.Xiao@motorola.com)
6 *
7 * Copyright (c) 2000 MontaVista Software, Inc. Dan Malek (dmalek@jlc.net)
8 *
9 * (C) Copyright 2000 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Marius Groeger <mgroeger@sysgo.de>
wdenk9c53f402003-10-15 23:53:47 +000011 */
12
13/*
14 * MPC8560 FCC Fast Ethernet
15 * Basic ET HW initialization and packet RX/TX routines
16 *
17 * This code will not perform the IO port configuration. This should be
18 * done in the iop_conf_t structure specific for the board.
19 *
20 * TODO:
21 * add a PHY driver to do the negotiation
22 * reflect negotiation results in FPSMR
23 * look for ways to configure the board specific stuff elsewhere, eg.
24 * config_xxx.h or the board directory
25 */
26
27#include <common.h>
28#include <malloc.h>
29#include <asm/cpm_85xx.h>
30#include <command.h>
31#include <config.h>
32#include <net.h>
33
Jon Loeliger526e5ce2007-07-09 19:06:00 -050034#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +020035#include <miiphy.h>
36#endif
37
Mike Frysingera23230c2011-10-02 10:01:27 +000038#if defined(CONFIG_ETHER_ON_FCC) && defined(CONFIG_CMD_NET)
wdenk9c53f402003-10-15 23:53:47 +000039
40static struct ether_fcc_info_s
41{
42 int ether_index;
43 int proff_enet;
44 ulong cpm_cr_enet_sblock;
45 ulong cpm_cr_enet_page;
46 ulong cmxfcr_mask;
47 ulong cmxfcr_value;
48}
49 ether_fcc_info[] =
50{
51#ifdef CONFIG_ETHER_ON_FCC1
52{
53 0,
54 PROFF_FCC1,
55 CPM_CR_FCC1_SBLOCK,
56 CPM_CR_FCC1_PAGE,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057 CONFIG_SYS_CMXFCR_MASK1,
58 CONFIG_SYS_CMXFCR_VALUE1
wdenk9c53f402003-10-15 23:53:47 +000059},
60#endif
61
62#ifdef CONFIG_ETHER_ON_FCC2
63{
64 1,
65 PROFF_FCC2,
66 CPM_CR_FCC2_SBLOCK,
67 CPM_CR_FCC2_PAGE,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068 CONFIG_SYS_CMXFCR_MASK2,
69 CONFIG_SYS_CMXFCR_VALUE2
wdenk9c53f402003-10-15 23:53:47 +000070},
71#endif
72
73#ifdef CONFIG_ETHER_ON_FCC3
74{
75 2,
76 PROFF_FCC3,
77 CPM_CR_FCC3_SBLOCK,
78 CPM_CR_FCC3_PAGE,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079 CONFIG_SYS_CMXFCR_MASK3,
80 CONFIG_SYS_CMXFCR_VALUE3
wdenk9c53f402003-10-15 23:53:47 +000081},
82#endif
83};
84
85/*---------------------------------------------------------------------*/
86
87/* Maximum input DMA size. Must be a should(?) be a multiple of 4. */
88#define PKT_MAXDMA_SIZE 1520
89
90/* The FCC stores dest/src/type, data, and checksum for receive packets. */
91#define PKT_MAXBUF_SIZE 1518
92#define PKT_MINBUF_SIZE 64
93
94/* Maximum input buffer size. Must be a multiple of 32. */
95#define PKT_MAXBLR_SIZE 1536
96
97#define TOUT_LOOP 1000000
98
99#define TX_BUF_CNT 2
100
101static uint rxIdx; /* index of the current RX buffer */
102static uint txIdx; /* index of the current TX buffer */
103
104/*
105 * FCC Ethernet Tx and Rx buffer descriptors.
106 * Provide for Double Buffering
107 * Note: PKTBUFSRX is defined in net.h
108 */
109
110typedef volatile struct rtxbd {
111 cbd_t rxbd[PKTBUFSRX];
112 cbd_t txbd[TX_BUF_CNT];
113} RTXBD;
114
115/* Good news: the FCC supports external BDs! */
116#ifdef __GNUC__
117static RTXBD rtx __attribute__ ((aligned(8)));
118#else
119#error "rtx must be 64-bit aligned"
120#endif
121
wdenkd0245fc2005-04-13 10:02:42 +0000122#undef ET_DEBUG
wdenk9c53f402003-10-15 23:53:47 +0000123
Joe Hershberger6947d5f2012-05-22 07:56:12 +0000124static int fec_send(struct eth_device *dev, void *packet, int length)
wdenk9c53f402003-10-15 23:53:47 +0000125{
126 int i = 0;
127 int result = 0;
128
129 if (length <= 0) {
130 printf("fec: bad packet size: %d\n", length);
131 goto out;
132 }
133
134 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
135 if (i >= TOUT_LOOP) {
136 printf("fec: tx buffer not ready\n");
137 goto out;
138 }
139 }
140
141 rtx.txbd[txIdx].cbd_bufaddr = (uint)packet;
142 rtx.txbd[txIdx].cbd_datlen = length;
143 rtx.txbd[txIdx].cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_LAST | \
wdenkfaaa6022005-04-21 21:10:22 +0000144 BD_ENET_TX_TC | BD_ENET_TX_PAD);
wdenk9c53f402003-10-15 23:53:47 +0000145
146 for(i=0; rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_READY; i++) {
147 if (i >= TOUT_LOOP) {
148 printf("fec: tx error\n");
149 goto out;
150 }
151 }
152
153#ifdef ET_DEBUG
154 printf("cycles: 0x%x txIdx=0x%04x status: 0x%04x\n", i, txIdx,rtx.txbd[txIdx].cbd_sc);
155 printf("packets at 0x%08x, length_in_bytes=0x%x\n",(uint)packet,length);
156 for(i=0;i<(length/16 + 1);i++) {
157 printf("%08x %08x %08x %08x\n",*((uint *)rtx.txbd[txIdx].cbd_bufaddr+i*4),\
158 *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 1),*((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 2), \
159 *((uint *)rtx.txbd[txIdx].cbd_bufaddr + i*4 + 3));
160 }
161#endif
162
163 /* return only status bits */
164 result = rtx.txbd[txIdx].cbd_sc & BD_ENET_TX_STATS;
165 txIdx = (txIdx + 1) % TX_BUF_CNT;
166
167out:
168 return result;
169}
170
171static int fec_recv(struct eth_device* dev)
172{
173 int length;
174
175 for (;;)
176 {
177 if (rtx.rxbd[rxIdx].cbd_sc & BD_ENET_RX_EMPTY) {
178 length = -1;
179 break; /* nothing received - leave for() loop */
180 }
181 length = rtx.rxbd[rxIdx].cbd_datlen;
182
183 if (rtx.rxbd[rxIdx].cbd_sc & 0x003f) {
184 printf("fec: rx error %04x\n", rtx.rxbd[rxIdx].cbd_sc);
185 }
186 else {
187 /* Pass the packet up to the protocol layers. */
Joe Hershberger9f09a362015-04-08 01:41:06 -0500188 net_process_received_packet(net_rx_packets[rxIdx], length - 4);
wdenk9c53f402003-10-15 23:53:47 +0000189 }
190
191
192 /* Give the buffer back to the FCC. */
193 rtx.rxbd[rxIdx].cbd_datlen = 0;
194
195 /* wrap around buffer index when necessary */
196 if ((rxIdx + 1) >= PKTBUFSRX) {
197 rtx.rxbd[PKTBUFSRX - 1].cbd_sc = (BD_ENET_RX_WRAP | BD_ENET_RX_EMPTY);
198 rxIdx = 0;
199 }
200 else {
201 rtx.rxbd[rxIdx].cbd_sc = BD_ENET_RX_EMPTY;
202 rxIdx++;
203 }
204 }
205 return length;
206}
207
208
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900209static int fec_init(struct eth_device* dev, struct bd_info *bis)
wdenk9c53f402003-10-15 23:53:47 +0000210{
211 struct ether_fcc_info_s * info = dev->priv;
212 int i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200213 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
Kumar Galacd113a02007-11-28 00:36:33 -0600214 volatile ccsr_cpm_cp_t *cp = &(cpm->im_cpm_cp);
wdenk9c53f402003-10-15 23:53:47 +0000215 fcc_enet_t *pram_ptr;
216 unsigned long mem_addr;
217
218#if 0
219 mii_discover_phy();
220#endif
221
222 /* 28.9 - (1-2): ioports have been set up already */
223
224 /* 28.9 - (3): connect FCC's tx and rx clocks */
Kumar Galacd113a02007-11-28 00:36:33 -0600225 cpm->im_cpm_mux.cmxuar = 0; /* ATM */
226 cpm->im_cpm_mux.cmxfcr = (cpm->im_cpm_mux.cmxfcr & ~info->cmxfcr_mask) |
wdenk9c53f402003-10-15 23:53:47 +0000227 info->cmxfcr_value;
228
229 /* 28.9 - (4): GFMR: disable tx/rx, CCITT CRC, set Mode Ethernet */
230 if(info->ether_index == 0) {
Kumar Galacd113a02007-11-28 00:36:33 -0600231 cpm->im_cpm_fcc1.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
wdenk9c53f402003-10-15 23:53:47 +0000232 } else if (info->ether_index == 1) {
Kumar Galacd113a02007-11-28 00:36:33 -0600233 cpm->im_cpm_fcc2.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
wdenk9c53f402003-10-15 23:53:47 +0000234 } else if (info->ether_index == 2) {
Kumar Galacd113a02007-11-28 00:36:33 -0600235 cpm->im_cpm_fcc3.gfmr = FCC_GFMR_MODE_ENET | FCC_GFMR_TCRC_32;
wdenk9c53f402003-10-15 23:53:47 +0000236 }
237
238 /* 28.9 - (5): FPSMR: enable full duplex, select CCITT CRC for Ethernet,MII */
239 if(info->ether_index == 0) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200240 cpm->im_cpm_fcc1.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
wdenk9c53f402003-10-15 23:53:47 +0000241 } else if (info->ether_index == 1){
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200242 cpm->im_cpm_fcc2.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
wdenk9c53f402003-10-15 23:53:47 +0000243 } else if (info->ether_index == 2){
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200244 cpm->im_cpm_fcc3.fpsmr = CONFIG_SYS_FCC_PSMR | FCC_PSMR_ENCRC;
wdenk9c53f402003-10-15 23:53:47 +0000245 }
246
247 /* 28.9 - (6): FDSR: Ethernet Syn */
248 if(info->ether_index == 0) {
Kumar Galacd113a02007-11-28 00:36:33 -0600249 cpm->im_cpm_fcc1.fdsr = 0xD555;
wdenk9c53f402003-10-15 23:53:47 +0000250 } else if (info->ether_index == 1) {
Kumar Galacd113a02007-11-28 00:36:33 -0600251 cpm->im_cpm_fcc2.fdsr = 0xD555;
wdenk9c53f402003-10-15 23:53:47 +0000252 } else if (info->ether_index == 2) {
Kumar Galacd113a02007-11-28 00:36:33 -0600253 cpm->im_cpm_fcc3.fdsr = 0xD555;
wdenk9c53f402003-10-15 23:53:47 +0000254 }
255
256 /* reset indeces to current rx/tx bd (see eth_send()/eth_rx()) */
257 rxIdx = 0;
258 txIdx = 0;
259
260 /* Setup Receiver Buffer Descriptors */
261 for (i = 0; i < PKTBUFSRX; i++)
262 {
263 rtx.rxbd[i].cbd_sc = BD_ENET_RX_EMPTY;
264 rtx.rxbd[i].cbd_datlen = 0;
Joe Hershberger9f09a362015-04-08 01:41:06 -0500265 rtx.rxbd[i].cbd_bufaddr = (uint)net_rx_packets[i];
wdenk9c53f402003-10-15 23:53:47 +0000266 }
267 rtx.rxbd[PKTBUFSRX - 1].cbd_sc |= BD_ENET_RX_WRAP;
268
269 /* Setup Ethernet Transmitter Buffer Descriptors */
270 for (i = 0; i < TX_BUF_CNT; i++)
271 {
272 rtx.txbd[i].cbd_sc = 0;
273 rtx.txbd[i].cbd_datlen = 0;
274 rtx.txbd[i].cbd_bufaddr = 0;
275 }
276 rtx.txbd[TX_BUF_CNT - 1].cbd_sc |= BD_ENET_TX_WRAP;
277
278 /* 28.9 - (7): initialize parameter ram */
Kumar Galacd113a02007-11-28 00:36:33 -0600279 pram_ptr = (fcc_enet_t *)&(cpm->im_dprambase[info->proff_enet]);
wdenk9c53f402003-10-15 23:53:47 +0000280
281 /* clear whole structure to make sure all reserved fields are zero */
282 memset((void*)pram_ptr, 0, sizeof(fcc_enet_t));
283
284 /*
285 * common Parameter RAM area
286 *
287 * Allocate space in the reserved FCC area of DPRAM for the
288 * internal buffers. No one uses this space (yet), so we
289 * can do this. Later, we will add resource management for
Wolfgang Denk3bd697b2005-12-06 15:02:31 +0100290 * this area.
291 * CPM_FCC_SPECIAL_BASE: 0xB000 for MPC8540, MPC8560
292 * 0x9000 for MPC8541, MPC8555
wdenk9c53f402003-10-15 23:53:47 +0000293 */
294 mem_addr = CPM_FCC_SPECIAL_BASE + ((info->ether_index) * 64);
295 pram_ptr->fen_genfcc.fcc_riptr = mem_addr;
296 pram_ptr->fen_genfcc.fcc_tiptr = mem_addr+32;
297 /*
298 * Set maximum bytes per receive buffer.
299 * It must be a multiple of 32.
300 */
301 pram_ptr->fen_genfcc.fcc_mrblr = PKT_MAXBLR_SIZE; /* 1536 */
302 /* localbus SDRAM should be preferred */
303 pram_ptr->fen_genfcc.fcc_rstate = (CPMFCR_GBL | CPMFCR_EB |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200304 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
wdenk9c53f402003-10-15 23:53:47 +0000305 pram_ptr->fen_genfcc.fcc_rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
306 pram_ptr->fen_genfcc.fcc_rbdstat = 0;
307 pram_ptr->fen_genfcc.fcc_rbdlen = 0;
308 pram_ptr->fen_genfcc.fcc_rdptr = 0;
309 /* localbus SDRAM should be preferred */
310 pram_ptr->fen_genfcc.fcc_tstate = (CPMFCR_GBL | CPMFCR_EB |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200311 CONFIG_SYS_CPMFCR_RAMTYPE) << 24;
wdenk9c53f402003-10-15 23:53:47 +0000312 pram_ptr->fen_genfcc.fcc_tbase = (unsigned int)(&rtx.txbd[txIdx]);
313 pram_ptr->fen_genfcc.fcc_tbdstat = 0;
314 pram_ptr->fen_genfcc.fcc_tbdlen = 0;
315 pram_ptr->fen_genfcc.fcc_tdptr = 0;
316
317 /* protocol-specific area */
318 pram_ptr->fen_statbuf = 0x0;
319 pram_ptr->fen_cmask = 0xdebb20e3; /* CRC mask */
320 pram_ptr->fen_cpres = 0xffffffff; /* CRC preset */
321 pram_ptr->fen_crcec = 0;
322 pram_ptr->fen_alec = 0;
323 pram_ptr->fen_disfc = 0;
324 pram_ptr->fen_retlim = 15; /* Retry limit threshold */
325 pram_ptr->fen_retcnt = 0;
326 pram_ptr->fen_pper = 0;
327 pram_ptr->fen_boffcnt = 0;
328 pram_ptr->fen_gaddrh = 0;
329 pram_ptr->fen_gaddrl = 0;
330 pram_ptr->fen_mflr = PKT_MAXBUF_SIZE; /* maximum frame length register */
331 /*
332 * Set Ethernet station address.
333 *
334 * This is supplied in the board information structure, so we
335 * copy that into the controller.
336 * So far we have only been given one Ethernet address. We make
337 * it unique by setting a few bits in the upper byte of the
338 * non-static part of the address.
339 */
Joe Hershberger11cd5a02015-03-22 17:09:00 -0500340#define ea eth_get_ethaddr()
wdenk9c53f402003-10-15 23:53:47 +0000341 pram_ptr->fen_paddrh = (ea[5] << 8) + ea[4];
342 pram_ptr->fen_paddrm = (ea[3] << 8) + ea[2];
343 pram_ptr->fen_paddrl = (ea[1] << 8) + ea[0];
344#undef ea
345 pram_ptr->fen_ibdcount = 0;
346 pram_ptr->fen_ibdstart = 0;
347 pram_ptr->fen_ibdend = 0;
348 pram_ptr->fen_txlen = 0;
349 pram_ptr->fen_iaddrh = 0; /* disable hash */
350 pram_ptr->fen_iaddrl = 0;
351 pram_ptr->fen_minflr = PKT_MINBUF_SIZE; /* minimum frame length register: 64 */
352 /* pad pointer. use tiptr since we don't need a specific padding char */
353 pram_ptr->fen_padptr = pram_ptr->fen_genfcc.fcc_tiptr;
354 pram_ptr->fen_maxd1 = PKT_MAXDMA_SIZE; /* maximum DMA1 length:1520 */
355 pram_ptr->fen_maxd2 = PKT_MAXDMA_SIZE; /* maximum DMA2 length:1520 */
356
357#if defined(ET_DEBUG)
358 printf("parm_ptr(0xff788500) = %p\n",pram_ptr);
359 printf("pram_ptr->fen_genfcc.fcc_rbase %08x\n",
360 pram_ptr->fen_genfcc.fcc_rbase);
361 printf("pram_ptr->fen_genfcc.fcc_tbase %08x\n",
362 pram_ptr->fen_genfcc.fcc_tbase);
363#endif
364
365 /* 28.9 - (8)(9): clear out events in FCCE */
366 /* 28.9 - (9): FCCM: mask all events */
367 if(info->ether_index == 0) {
Kumar Galacd113a02007-11-28 00:36:33 -0600368 cpm->im_cpm_fcc1.fcce = ~0x0;
369 cpm->im_cpm_fcc1.fccm = 0;
wdenk9c53f402003-10-15 23:53:47 +0000370 } else if (info->ether_index == 1) {
Kumar Galacd113a02007-11-28 00:36:33 -0600371 cpm->im_cpm_fcc2.fcce = ~0x0;
372 cpm->im_cpm_fcc2.fccm = 0;
wdenk9c53f402003-10-15 23:53:47 +0000373 } else if (info->ether_index == 2) {
Kumar Galacd113a02007-11-28 00:36:33 -0600374 cpm->im_cpm_fcc3.fcce = ~0x0;
375 cpm->im_cpm_fcc3.fccm = 0;
wdenk9c53f402003-10-15 23:53:47 +0000376 }
377
378 /* 28.9 - (10-12): we don't use ethernet interrupts */
379
380 /* 28.9 - (13)
381 *
382 * Let's re-initialize the channel now. We have to do it later
383 * than the manual describes because we have just now finished
384 * the BD initialization.
385 */
386 cp->cpcr = mk_cr_cmd(info->cpm_cr_enet_page,
387 info->cpm_cr_enet_sblock,
388 0x0c,
389 CPM_CR_INIT_TRX) | CPM_CR_FLG;
390 do {
391 __asm__ __volatile__ ("eieio");
392 } while (cp->cpcr & CPM_CR_FLG);
393
394 /* 28.9 - (14): enable tx/rx in gfmr */
395 if(info->ether_index == 0) {
Kumar Galacd113a02007-11-28 00:36:33 -0600396 cpm->im_cpm_fcc1.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
wdenk9c53f402003-10-15 23:53:47 +0000397 } else if (info->ether_index == 1) {
Kumar Galacd113a02007-11-28 00:36:33 -0600398 cpm->im_cpm_fcc2.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
wdenk9c53f402003-10-15 23:53:47 +0000399 } else if (info->ether_index == 2) {
Kumar Galacd113a02007-11-28 00:36:33 -0600400 cpm->im_cpm_fcc3.gfmr |= FCC_GFMR_ENT | FCC_GFMR_ENR;
wdenk9c53f402003-10-15 23:53:47 +0000401 }
402
wdenkfaaa6022005-04-21 21:10:22 +0000403 return 1;
wdenk9c53f402003-10-15 23:53:47 +0000404}
405
406static void fec_halt(struct eth_device* dev)
407{
408 struct ether_fcc_info_s * info = dev->priv;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200409 volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
wdenk9c53f402003-10-15 23:53:47 +0000410
411 /* write GFMR: disable tx/rx */
412 if(info->ether_index == 0) {
Kumar Galacd113a02007-11-28 00:36:33 -0600413 cpm->im_cpm_fcc1.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
wdenk9c53f402003-10-15 23:53:47 +0000414 } else if(info->ether_index == 1) {
Kumar Galacd113a02007-11-28 00:36:33 -0600415 cpm->im_cpm_fcc2.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
wdenk9c53f402003-10-15 23:53:47 +0000416 } else if(info->ether_index == 2) {
Kumar Galacd113a02007-11-28 00:36:33 -0600417 cpm->im_cpm_fcc3.gfmr &= ~(FCC_GFMR_ENT | FCC_GFMR_ENR);
wdenk9c53f402003-10-15 23:53:47 +0000418 }
419}
420
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900421int fec_initialize(struct bd_info *bis)
wdenk9c53f402003-10-15 23:53:47 +0000422{
423 struct eth_device* dev;
424 int i;
425
Robert P. J. Day0c911592016-05-23 06:49:21 -0400426 for (i = 0; i < ARRAY_SIZE(ether_fcc_info); i++)
wdenk9c53f402003-10-15 23:53:47 +0000427 {
428 dev = (struct eth_device*) malloc(sizeof *dev);
429 memset(dev, 0, sizeof *dev);
430
Heiko Schocherc5e84052010-07-20 17:45:02 +0200431 sprintf(dev->name, "FCC%d",
wdenk9c53f402003-10-15 23:53:47 +0000432 ether_fcc_info[i].ether_index + 1);
433 dev->priv = &ether_fcc_info[i];
434 dev->init = fec_init;
435 dev->halt = fec_halt;
436 dev->send = fec_send;
437 dev->recv = fec_recv;
438
439 eth_register(dev);
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200440
Jon Loeliger526e5ce2007-07-09 19:06:00 -0500441#if (defined(CONFIG_MII) || defined(CONFIG_CMD_MII)) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200442 && defined(CONFIG_BITBANGMII)
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500443 int retval;
444 struct mii_dev *mdiodev = mdio_alloc();
445 if (!mdiodev)
446 return -ENOMEM;
447 strncpy(mdiodev->name, dev->name, MDIO_NAME_LEN);
448 mdiodev->read = bb_miiphy_read;
449 mdiodev->write = bb_miiphy_write;
450
451 retval = mdio_register(mdiodev);
452 if (retval < 0)
453 return retval;
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200454#endif
wdenk9c53f402003-10-15 23:53:47 +0000455 }
456
457 return 1;
458}
459
Jon Loeliger07efe2a2007-07-10 10:27:39 -0500460#endif