]> git.sur5r.net Git - u-boot/blob - drivers/net/fec_mxc.c
b5619ebbae05db09c8d8bfe614590320d314313a
[u-boot] / drivers / net / fec_mxc.c
1 /*
2  * (C) Copyright 2009 Ilya Yanok, Emcraft Systems Ltd <yanok@emcraft.com>
3  * (C) Copyright 2008,2009 Eric Jarrige <eric.jarrige@armadeus.org>
4  * (C) Copyright 2008 Armadeus Systems nc
5  * (C) Copyright 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
6  * (C) Copyright 2007 Pengutronix, Juergen Beisert <j.beisert@pengutronix.de>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <malloc.h>
26 #include <net.h>
27 #include <miiphy.h>
28 #include "fec_mxc.h"
29
30 #include <asm/arch/clock.h>
31 #include <asm/arch/imx-regs.h>
32 #include <asm/io.h>
33 #include <asm/errno.h>
34
35 DECLARE_GLOBAL_DATA_PTR;
36
37 #ifndef CONFIG_MII
38 #error "CONFIG_MII has to be defined!"
39 #endif
40
41 #undef DEBUG
42
43 struct nbuf {
44         uint8_t data[1500];     /**< actual data */
45         int length;             /**< actual length */
46         int used;               /**< buffer in use or not */
47         uint8_t head[16];       /**< MAC header(6 + 6 + 2) + 2(aligned) */
48 };
49
50 struct fec_priv gfec = {
51         .eth       = (struct ethernet_regs *)IMX_FEC_BASE,
52         .xcv_type  = MII100,
53         .rbd_base  = NULL,
54         .rbd_index = 0,
55         .tbd_base  = NULL,
56         .tbd_index = 0,
57         .bd        = NULL,
58         .rdb_ptr   = NULL,
59         .base_ptr  = NULL,
60 };
61
62 /*
63  * MII-interface related functions
64  */
65 static int fec_miiphy_read(char *dev, uint8_t phyAddr, uint8_t regAddr,
66                 uint16_t *retVal)
67 {
68         struct eth_device *edev = eth_get_dev_by_name(dev);
69         struct fec_priv *fec = (struct fec_priv *)edev->priv;
70
71         uint32_t reg;           /* convenient holder for the PHY register */
72         uint32_t phy;           /* convenient holder for the PHY */
73         uint32_t start;
74
75         /*
76          * reading from any PHY's register is done by properly
77          * programming the FEC's MII data register.
78          */
79         writel(FEC_IEVENT_MII, &fec->eth->ievent);
80         reg = regAddr << FEC_MII_DATA_RA_SHIFT;
81         phy = phyAddr << FEC_MII_DATA_PA_SHIFT;
82
83         writel(FEC_MII_DATA_ST | FEC_MII_DATA_OP_RD | FEC_MII_DATA_TA |
84                         phy | reg, &fec->eth->mii_data);
85
86         /*
87          * wait for the related interrupt
88          */
89         start = get_timer_masked();
90         while (!(readl(&fec->eth->ievent) & FEC_IEVENT_MII)) {
91                 if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
92                         printf("Read MDIO failed...\n");
93                         return -1;
94                 }
95         }
96
97         /*
98          * clear mii interrupt bit
99          */
100         writel(FEC_IEVENT_MII, &fec->eth->ievent);
101
102         /*
103          * it's now safe to read the PHY's register
104          */
105         *retVal = readl(&fec->eth->mii_data);
106         debug("fec_miiphy_read: phy: %02x reg:%02x val:%#x\n", phyAddr,
107                         regAddr, *retVal);
108         return 0;
109 }
110
111 static int fec_miiphy_write(char *dev, uint8_t phyAddr, uint8_t regAddr,
112                 uint16_t data)
113 {
114         struct eth_device *edev = eth_get_dev_by_name(dev);
115         struct fec_priv *fec = (struct fec_priv *)edev->priv;
116
117         uint32_t reg;           /* convenient holder for the PHY register */
118         uint32_t phy;           /* convenient holder for the PHY */
119         uint32_t start;
120
121         reg = regAddr << FEC_MII_DATA_RA_SHIFT;
122         phy = phyAddr << FEC_MII_DATA_PA_SHIFT;
123
124         writel(FEC_MII_DATA_ST | FEC_MII_DATA_OP_WR |
125                 FEC_MII_DATA_TA | phy | reg | data, &fec->eth->mii_data);
126
127         /*
128          * wait for the MII interrupt
129          */
130         start = get_timer_masked();
131         while (!(readl(&fec->eth->ievent) & FEC_IEVENT_MII)) {
132                 if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
133                         printf("Write MDIO failed...\n");
134                         return -1;
135                 }
136         }
137
138         /*
139          * clear MII interrupt bit
140          */
141         writel(FEC_IEVENT_MII, &fec->eth->ievent);
142         debug("fec_miiphy_write: phy: %02x reg:%02x val:%#x\n", phyAddr,
143                         regAddr, data);
144
145         return 0;
146 }
147
148 static int miiphy_restart_aneg(struct eth_device *dev)
149 {
150         /*
151          * Wake up from sleep if necessary
152          * Reset PHY, then delay 300ns
153          */
154 #ifdef CONFIG_MX27
155         miiphy_write(dev->name, CONFIG_FEC_MXC_PHYADDR, PHY_MIPGSR, 0x00FF);
156 #endif
157         miiphy_write(dev->name, CONFIG_FEC_MXC_PHYADDR, PHY_BMCR,
158                         PHY_BMCR_RESET);
159         udelay(1000);
160
161         /*
162          * Set the auto-negotiation advertisement register bits
163          */
164         miiphy_write(dev->name, CONFIG_FEC_MXC_PHYADDR, PHY_ANAR,
165                         PHY_ANLPAR_TXFD | PHY_ANLPAR_TX | PHY_ANLPAR_10FD |
166                         PHY_ANLPAR_10 | PHY_ANLPAR_PSB_802_3);
167         miiphy_write(dev->name, CONFIG_FEC_MXC_PHYADDR, PHY_BMCR,
168                         PHY_BMCR_AUTON | PHY_BMCR_RST_NEG);
169
170         return 0;
171 }
172
173 static int miiphy_wait_aneg(struct eth_device *dev)
174 {
175         uint32_t start;
176         uint16_t status;
177
178         /*
179          * Wait for AN completion
180          */
181         start = get_timer_masked();
182         do {
183                 if (get_timer(start) > (CONFIG_SYS_HZ * 5)) {
184                         printf("%s: Autonegotiation timeout\n", dev->name);
185                         return -1;
186                 }
187
188                 if (miiphy_read(dev->name, CONFIG_FEC_MXC_PHYADDR,
189                                         PHY_BMSR, &status)) {
190                         printf("%s: Autonegotiation failed. status: 0x%04x\n",
191                                         dev->name, status);
192                         return -1;
193                 }
194         } while (!(status & PHY_BMSR_LS));
195
196         return 0;
197 }
198 static int fec_rx_task_enable(struct fec_priv *fec)
199 {
200         writel(1 << 24, &fec->eth->r_des_active);
201         return 0;
202 }
203
204 static int fec_rx_task_disable(struct fec_priv *fec)
205 {
206         return 0;
207 }
208
209 static int fec_tx_task_enable(struct fec_priv *fec)
210 {
211         writel(1 << 24, &fec->eth->x_des_active);
212         return 0;
213 }
214
215 static int fec_tx_task_disable(struct fec_priv *fec)
216 {
217         return 0;
218 }
219
220 /**
221  * Initialize receive task's buffer descriptors
222  * @param[in] fec all we know about the device yet
223  * @param[in] count receive buffer count to be allocated
224  * @param[in] size size of each receive buffer
225  * @return 0 on success
226  *
227  * For this task we need additional memory for the data buffers. And each
228  * data buffer requires some alignment. Thy must be aligned to a specific
229  * boundary each (DB_DATA_ALIGNMENT).
230  */
231 static int fec_rbd_init(struct fec_priv *fec, int count, int size)
232 {
233         int ix;
234         uint32_t p = 0;
235
236         /* reserve data memory and consider alignment */
237         if (fec->rdb_ptr == NULL)
238                 fec->rdb_ptr = malloc(size * count + DB_DATA_ALIGNMENT);
239         p = (uint32_t)fec->rdb_ptr;
240         if (!p) {
241                 puts("fec_imx27: not enough malloc memory!\n");
242                 return -ENOMEM;
243         }
244         memset((void *)p, 0, size * count + DB_DATA_ALIGNMENT);
245         p += DB_DATA_ALIGNMENT-1;
246         p &= ~(DB_DATA_ALIGNMENT-1);
247
248         for (ix = 0; ix < count; ix++) {
249                 writel(p, &fec->rbd_base[ix].data_pointer);
250                 p += size;
251                 writew(FEC_RBD_EMPTY, &fec->rbd_base[ix].status);
252                 writew(0, &fec->rbd_base[ix].data_length);
253         }
254         /*
255          * mark the last RBD to close the ring
256          */
257         writew(FEC_RBD_WRAP | FEC_RBD_EMPTY, &fec->rbd_base[ix - 1].status);
258         fec->rbd_index = 0;
259
260         return 0;
261 }
262
263 /**
264  * Initialize transmit task's buffer descriptors
265  * @param[in] fec all we know about the device yet
266  *
267  * Transmit buffers are created externally. We only have to init the BDs here.\n
268  * Note: There is a race condition in the hardware. When only one BD is in
269  * use it must be marked with the WRAP bit to use it for every transmitt.
270  * This bit in combination with the READY bit results into double transmit
271  * of each data buffer. It seems the state machine checks READY earlier then
272  * resetting it after the first transfer.
273  * Using two BDs solves this issue.
274  */
275 static void fec_tbd_init(struct fec_priv *fec)
276 {
277         writew(0x0000, &fec->tbd_base[0].status);
278         writew(FEC_TBD_WRAP, &fec->tbd_base[1].status);
279         fec->tbd_index = 0;
280 }
281
282 /**
283  * Mark the given read buffer descriptor as free
284  * @param[in] last 1 if this is the last buffer descriptor in the chain, else 0
285  * @param[in] pRbd buffer descriptor to mark free again
286  */
287 static void fec_rbd_clean(int last, struct fec_bd *pRbd)
288 {
289         /*
290          * Reset buffer descriptor as empty
291          */
292         if (last)
293                 writew(FEC_RBD_WRAP | FEC_RBD_EMPTY, &pRbd->status);
294         else
295                 writew(FEC_RBD_EMPTY, &pRbd->status);
296         /*
297          * no data in it
298          */
299         writew(0, &pRbd->data_length);
300 }
301
302 static int fec_get_hwaddr(struct eth_device *dev, unsigned char *mac)
303 {
304         struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
305         int i;
306
307         for (i = 0; i < 6; i++)
308                 mac[6-1-i] = readl(&iim->iim_bank_area0[IIM0_MAC + i]);
309
310         return is_valid_ether_addr(mac);
311 }
312
313 static int fec_set_hwaddr(struct eth_device *dev, unsigned char *mac)
314 {
315         struct fec_priv *fec = (struct fec_priv *)dev->priv;
316
317         writel(0, &fec->eth->iaddr1);
318         writel(0, &fec->eth->iaddr2);
319         writel(0, &fec->eth->gaddr1);
320         writel(0, &fec->eth->gaddr2);
321
322         /*
323          * Set physical address
324          */
325         writel((mac[0] << 24) + (mac[1] << 16) + (mac[2] << 8) + mac[3],
326                         &fec->eth->paddr1);
327         writel((mac[4] << 24) + (mac[5] << 16) + 0x8808, &fec->eth->paddr2);
328
329         return 0;
330 }
331
332 /**
333  * Start the FEC engine
334  * @param[in] dev Our device to handle
335  */
336 static int fec_open(struct eth_device *edev)
337 {
338         struct fec_priv *fec = (struct fec_priv *)edev->priv;
339
340         debug("fec_open: fec_open(dev)\n");
341         /* full-duplex, heartbeat disabled */
342         writel(1 << 2, &fec->eth->x_cntrl);
343         fec->rbd_index = 0;
344
345         /*
346          * Enable FEC-Lite controller
347          */
348         writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_ETHER_EN,
349                 &fec->eth->ecntrl);
350
351         miiphy_wait_aneg(edev);
352         miiphy_speed(edev->name, CONFIG_FEC_MXC_PHYADDR);
353         miiphy_duplex(edev->name, CONFIG_FEC_MXC_PHYADDR);
354
355         /*
356          * Enable SmartDMA receive task
357          */
358         fec_rx_task_enable(fec);
359
360         udelay(100000);
361         return 0;
362 }
363
364 static int fec_init(struct eth_device *dev, bd_t* bd)
365 {
366         uint32_t base;
367         struct fec_priv *fec = (struct fec_priv *)dev->priv;
368
369         /*
370          * reserve memory for both buffer descriptor chains at once
371          * Datasheet forces the startaddress of each chain is 16 byte
372          * aligned
373          */
374         if (fec->base_ptr == NULL)
375                 fec->base_ptr = malloc((2 + FEC_RBD_NUM) *
376                                 sizeof(struct fec_bd) + DB_ALIGNMENT);
377         base = (uint32_t)fec->base_ptr;
378         if (!base) {
379                 puts("fec_imx27: not enough malloc memory!\n");
380                 return -ENOMEM;
381         }
382         memset((void *)base, 0, (2 + FEC_RBD_NUM) *
383                         sizeof(struct fec_bd) + DB_ALIGNMENT);
384         base += (DB_ALIGNMENT-1);
385         base &= ~(DB_ALIGNMENT-1);
386
387         fec->rbd_base = (struct fec_bd *)base;
388
389         base += FEC_RBD_NUM * sizeof(struct fec_bd);
390
391         fec->tbd_base = (struct fec_bd *)base;
392
393         /*
394          * Set interrupt mask register
395          */
396         writel(0x00000000, &fec->eth->imask);
397
398         /*
399          * Clear FEC-Lite interrupt event register(IEVENT)
400          */
401         writel(0xffffffff, &fec->eth->ievent);
402
403
404         /*
405          * Set FEC-Lite receive control register(R_CNTRL):
406          */
407         if (fec->xcv_type == SEVENWIRE) {
408                 /*
409                  * Frame length=1518; 7-wire mode
410                  */
411                 writel(0x05ee0020, &fec->eth->r_cntrl); /* FIXME 0x05ee0000 */
412         } else {
413                 /*
414                  * Frame length=1518; MII mode;
415                  */
416                 writel(0x05ee0024, &fec->eth->r_cntrl); /* FIXME 0x05ee0004 */
417                 /*
418                  * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
419                  * and do not drop the Preamble.
420                  */
421                 writel((((imx_get_fecclk() / 1000000) + 2) / 5) << 1,
422                                 &fec->eth->mii_speed);
423                 debug("fec_init: mii_speed %#lx\n",
424                                 (((imx_get_fecclk() / 1000000) + 2) / 5) << 1);
425         }
426         /*
427          * Set Opcode/Pause Duration Register
428          */
429         writel(0x00010020, &fec->eth->op_pause);        /* FIXME 0xffff0020; */
430         writel(0x2, &fec->eth->x_wmrk);
431         /*
432          * Set multicast address filter
433          */
434         writel(0x00000000, &fec->eth->gaddr1);
435         writel(0x00000000, &fec->eth->gaddr2);
436
437
438         /* clear MIB RAM */
439         long *mib_ptr = (long *)(IMX_FEC_BASE + 0x200);
440         while (mib_ptr <= (long *)(IMX_FEC_BASE + 0x2FC))
441                 *mib_ptr++ = 0;
442
443         /* FIFO receive start register */
444         writel(0x520, &fec->eth->r_fstart);
445
446         /* size and address of each buffer */
447         writel(FEC_MAX_PKT_SIZE, &fec->eth->emrbr);
448         writel((uint32_t)fec->tbd_base, &fec->eth->etdsr);
449         writel((uint32_t)fec->rbd_base, &fec->eth->erdsr);
450
451         /*
452          * Initialize RxBD/TxBD rings
453          */
454         if (fec_rbd_init(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE) < 0) {
455                 free(fec->base_ptr);
456                 fec->base_ptr = NULL;
457                 return -ENOMEM;
458         }
459         fec_tbd_init(fec);
460
461
462         if (fec->xcv_type != SEVENWIRE)
463                 miiphy_restart_aneg(dev);
464
465         fec_open(dev);
466         return 0;
467 }
468
469 /**
470  * Halt the FEC engine
471  * @param[in] dev Our device to handle
472  */
473 static void fec_halt(struct eth_device *dev)
474 {
475         struct fec_priv *fec = &gfec;
476         int counter = 0xffff;
477
478         /*
479          * issue graceful stop command to the FEC transmitter if necessary
480          */
481         writel(FEC_TCNTRL_GTS | readl(&fec->eth->x_cntrl),
482                         &fec->eth->x_cntrl);
483
484         debug("eth_halt: wait for stop regs\n");
485         /*
486          * wait for graceful stop to register
487          */
488         while ((counter--) && (!(readl(&fec->eth->ievent) & FEC_IEVENT_GRA)))
489                 udelay(1);
490
491         /*
492          * Disable SmartDMA tasks
493          */
494         fec_tx_task_disable(fec);
495         fec_rx_task_disable(fec);
496
497         /*
498          * Disable the Ethernet Controller
499          * Note: this will also reset the BD index counter!
500          */
501         writel(readl(&fec->eth->ecntrl) & ~FEC_ECNTRL_ETHER_EN, &fec->eth->ecntrl);
502         fec->rbd_index = 0;
503         fec->tbd_index = 0;
504         debug("eth_halt: done\n");
505 }
506
507 /**
508  * Transmit one frame
509  * @param[in] dev Our ethernet device to handle
510  * @param[in] packet Pointer to the data to be transmitted
511  * @param[in] length Data count in bytes
512  * @return 0 on success
513  */
514 static int fec_send(struct eth_device *dev, volatile void* packet, int length)
515 {
516         unsigned int status;
517
518         /*
519          * This routine transmits one frame.  This routine only accepts
520          * 6-byte Ethernet addresses.
521          */
522         struct fec_priv *fec = (struct fec_priv *)dev->priv;
523
524         /*
525          * Check for valid length of data.
526          */
527         if ((length > 1500) || (length <= 0)) {
528                 printf("Payload (%d) to large!\n", length);
529                 return -1;
530         }
531
532         /*
533          * Setup the transmit buffer
534          * Note: We are always using the first buffer for transmission,
535          * the second will be empty and only used to stop the DMA engine
536          */
537         writew(length, &fec->tbd_base[fec->tbd_index].data_length);
538         writel((uint32_t)packet, &fec->tbd_base[fec->tbd_index].data_pointer);
539         /*
540          * update BD's status now
541          * This block:
542          * - is always the last in a chain (means no chain)
543          * - should transmitt the CRC
544          * - might be the last BD in the list, so the address counter should
545          *   wrap (-> keep the WRAP flag)
546          */
547         status = readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_WRAP;
548         status |= FEC_TBD_LAST | FEC_TBD_TC | FEC_TBD_READY;
549         writew(status, &fec->tbd_base[fec->tbd_index].status);
550
551         /*
552          * Enable SmartDMA transmit task
553          */
554         fec_tx_task_enable(fec);
555
556         /*
557          * wait until frame is sent .
558          */
559         while (readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_READY) {
560                 udelay(1);
561         }
562         debug("fec_send: status 0x%x index %d\n",
563                         readw(&fec->tbd_base[fec->tbd_index].status),
564                         fec->tbd_index);
565         /* for next transmission use the other buffer */
566         if (fec->tbd_index)
567                 fec->tbd_index = 0;
568         else
569                 fec->tbd_index = 1;
570
571         return 0;
572 }
573
574 /**
575  * Pull one frame from the card
576  * @param[in] dev Our ethernet device to handle
577  * @return Length of packet read
578  */
579 static int fec_recv(struct eth_device *dev)
580 {
581         struct fec_priv *fec = (struct fec_priv *)dev->priv;
582         struct fec_bd *rbd = &fec->rbd_base[fec->rbd_index];
583         unsigned long ievent;
584         int frame_length, len = 0;
585         struct nbuf *frame;
586         uint16_t bd_status;
587         uchar buff[FEC_MAX_PKT_SIZE];
588
589         /*
590          * Check if any critical events have happened
591          */
592         ievent = readl(&fec->eth->ievent);
593         writel(ievent, &fec->eth->ievent);
594         debug("fec_recv: ievent 0x%x\n", ievent);
595         if (ievent & FEC_IEVENT_BABR) {
596                 fec_halt(dev);
597                 fec_init(dev, fec->bd);
598                 printf("some error: 0x%08lx\n", ievent);
599                 return 0;
600         }
601         if (ievent & FEC_IEVENT_HBERR) {
602                 /* Heartbeat error */
603                 writel(0x00000001 | readl(&fec->eth->x_cntrl),
604                                 &fec->eth->x_cntrl);
605         }
606         if (ievent & FEC_IEVENT_GRA) {
607                 /* Graceful stop complete */
608                 if (readl(&fec->eth->x_cntrl) & 0x00000001) {
609                         fec_halt(dev);
610                         writel(~0x00000001 & readl(&fec->eth->x_cntrl),
611                                         &fec->eth->x_cntrl);
612                         fec_init(dev, fec->bd);
613                 }
614         }
615
616         /*
617          * ensure reading the right buffer status
618          */
619         bd_status = readw(&rbd->status);
620         debug("fec_recv: status 0x%x\n", bd_status);
621
622         if (!(bd_status & FEC_RBD_EMPTY)) {
623                 if ((bd_status & FEC_RBD_LAST) && !(bd_status & FEC_RBD_ERR) &&
624                         ((readw(&rbd->data_length) - 4) > 14)) {
625                         /*
626                          * Get buffer address and size
627                          */
628                         frame = (struct nbuf *)readl(&rbd->data_pointer);
629                         frame_length = readw(&rbd->data_length) - 4;
630                         /*
631                          *  Fill the buffer and pass it to upper layers
632                          */
633                         memcpy(buff, frame->data, frame_length);
634                         NetReceive(buff, frame_length);
635                         len = frame_length;
636                 } else {
637                         if (bd_status & FEC_RBD_ERR)
638                                 printf("error frame: 0x%08lx 0x%08x\n",
639                                                 (ulong)rbd->data_pointer,
640                                                 bd_status);
641                 }
642                 /*
643                  * free the current buffer, restart the engine
644                  * and move forward to the next buffer
645                  */
646                 fec_rbd_clean(fec->rbd_index == (FEC_RBD_NUM - 1) ? 1 : 0, rbd);
647                 fec_rx_task_enable(fec);
648                 fec->rbd_index = (fec->rbd_index + 1) % FEC_RBD_NUM;
649         }
650         debug("fec_recv: stop\n");
651
652         return len;
653 }
654
655 static int fec_probe(bd_t *bd)
656 {
657         struct eth_device *edev;
658         struct fec_priv *fec = &gfec;
659         unsigned char ethaddr_str[20];
660         unsigned char ethaddr[6];
661         char *tmp = getenv("ethaddr");
662         char *end;
663
664         /* create and fill edev struct */
665         edev = (struct eth_device *)malloc(sizeof(struct eth_device));
666         if (!edev) {
667                 puts("fec_imx27: not enough malloc memory!\n");
668                 return -ENOMEM;
669         }
670         edev->priv = fec;
671         edev->init = fec_init;
672         edev->send = fec_send;
673         edev->recv = fec_recv;
674         edev->halt = fec_halt;
675
676         fec->eth = (struct ethernet_regs *)IMX_FEC_BASE;
677         fec->bd = bd;
678
679         fec->xcv_type = MII100;
680
681         /* Reset chip. */
682         writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_RESET, &fec->eth->ecntrl);
683         while (readl(&fec->eth->ecntrl) & 1)
684                 udelay(10);
685
686         /*
687          * Set interrupt mask register
688          */
689         writel(0x00000000, &fec->eth->imask);
690
691         /*
692          * Clear FEC-Lite interrupt event register(IEVENT)
693          */
694         writel(0xffffffff, &fec->eth->ievent);
695
696         /*
697          * Set FEC-Lite receive control register(R_CNTRL):
698          */
699         /*
700          * Frame length=1518; MII mode;
701          */
702         writel(0x05ee0024, &fec->eth->r_cntrl); /* FIXME 0x05ee0004 */
703         /*
704          * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
705          * and do not drop the Preamble.
706          */
707         writel((((imx_get_fecclk() / 1000000) + 2) / 5) << 1,
708                         &fec->eth->mii_speed);
709         debug("fec_init: mii_speed %#lx\n",
710                         (((imx_get_fecclk() / 1000000) + 2) / 5) << 1);
711
712         sprintf(edev->name, "FEC_MXC");
713
714         miiphy_register(edev->name, fec_miiphy_read, fec_miiphy_write);
715
716         eth_register(edev);
717
718         if ((NULL != tmp) && (12 <= strlen(tmp))) {
719                 int i;
720                 /* convert MAC from string to int */
721                 for (i = 0; i < 6; i++) {
722                         ethaddr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
723                         if (tmp)
724                                 tmp = (*end) ? end + 1 : end;
725                 }
726         } else if (fec_get_hwaddr(edev, ethaddr) == 0) {
727                 printf("got MAC address from EEPROM: %pM\n", ethaddr);
728                 setenv("ethaddr", (char *)ethaddr_str);
729         }
730         memcpy(edev->enetaddr, ethaddr, 6);
731         fec_set_hwaddr(edev, ethaddr);
732
733         return 0;
734 }
735
736 int fecmxc_initialize(bd_t *bd)
737 {
738         int lout = 1;
739
740         debug("eth_init: fec_probe(bd)\n");
741         lout = fec_probe(bd);
742
743         return lout;
744 }