]> Git Repo - J-u-boot.git/blob - drivers/net/dm9000x.c
Merge patch series "memory: ti-aemif: Add DM support"
[J-u-boot.git] / drivers / net / dm9000x.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *   dm9000.c: Version 1.2 12/15/2003
4  *
5  *      A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
6  *      Copyright (C) 1997  Sten Wang
7  *
8  *   (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
9  *
10  * V0.11        06/20/2001      REG_0A bit3=1, default enable BP with DA match
11  *      06/22/2001      Support DM9801 progrmming
12  *                      E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
13  *                      E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
14  *              R17 = (R17 & 0xfff0) | NF + 3
15  *                      E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
16  *              R17 = (R17 & 0xfff0) | NF
17  *
18  * v1.00                        modify by simon 2001.9.5
19  *                      change for kernel 2.4.x
20  *
21  * v1.1   11/09/2001    fix force mode bug
22  *
23  * v1.2   03/18/2003       Weilun Huang <[email protected]>:
24  *                      Fixed phy reset.
25  *                      Added tx/rx 32 bit mode.
26  *                      Cleaned up for kernel merge.
27  *
28  * --------------------------------------
29  *
30  *        12/15/2003       Initial port to u-boot by
31  *                      Sascha Hauer <[email protected]>
32  *
33  *        06/03/2008    Remy Bohmer <[email protected]>
34  *                      - Fixed the driver to work with DM9000A.
35  *                        (check on ISR receive status bit before reading the
36  *                        FIFO as described in DM9000 programming guide and
37  *                        application notes)
38  *                      - Added autodetect of databus width.
39  *                      - Made debug code compile again.
40  *                      - Adapt eth_send such that it matches the DM9000*
41  *                        application notes. Needed to make it work properly
42  *                        for DM9000A.
43  *                      - Adapted reset procedure to match DM9000 application
44  *                        notes (i.e. double reset)
45  *                      - some minor code cleanups
46  *                      These changes are tested with DM9000{A,EP,E} together
47  *                      with a 200MHz Atmel AT91SAM9261 core
48  *
49  * TODO: external MII is not functional, only internal at the moment.
50  */
51
52 #include <command.h>
53 #include <dm.h>
54 #include <malloc.h>
55 #include <net.h>
56 #include <asm/io.h>
57 #include <linux/delay.h>
58
59 #include "dm9000x.h"
60
61 /* Structure/enum declaration ------------------------------- */
62 struct dm9000_priv {
63         u32 runt_length_counter;        /* counter: RX length < 64byte */
64         u32 long_length_counter;        /* counter: RX length > 1514byte */
65         u32 reset_counter;      /* counter: RESET */
66         u32 reset_tx_timeout;   /* RESET caused by TX Timeout */
67         u32 reset_rx_status;    /* RESET caused by RX Statsus wrong */
68         u16 tx_pkt_cnt;
69         u16 queue_start_addr;
70         u16 dbug_cnt;
71         u8 phy_addr;
72         u8 device_wait_reset;   /* device state */
73         unsigned char srom[128];
74         void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count);
75         void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count);
76         void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen);
77         void __iomem *base_io;
78         void __iomem *base_data;
79 };
80
81 /* DM9000 network board routine ---------------------------- */
82 #ifndef CONFIG_DM9000_BYTE_SWAPPED
83 #define dm9000_outb(d, r) writeb((d), (r))
84 #define dm9000_outw(d, r) writew((d), (r))
85 #define dm9000_outl(d, r) writel((d), (r))
86 #define dm9000_inb(r) readb(r)
87 #define dm9000_inw(r) readw(r)
88 #define dm9000_inl(r) readl(r)
89 #else
90 #define dm9000_outb(d, r) __raw_writeb(d, r)
91 #define dm9000_outw(d, r) __raw_writew(d, r)
92 #define dm9000_outl(d, r) __raw_writel(d, r)
93 #define dm9000_inb(r) __raw_readb(r)
94 #define dm9000_inw(r) __raw_readw(r)
95 #define dm9000_inl(r) __raw_readl(r)
96 #endif
97
98 #ifdef DEBUG
99 static void dm9000_dump_packet(const char *func, u8 *packet, int length)
100 {
101         int i;
102
103         printf("%s: length: %d\n", func, length);
104
105         for (i = 0; i < length; i++) {
106                 if (i % 8 == 0)
107                         printf("\n%s: %02x: ", func, i);
108                 printf("%02x ", packet[i]);
109         }
110
111         printf("\n");
112 }
113 #else
114 static void dm9000_dump_packet(const char *func, u8 *packet, int length) {}
115 #endif
116
117 static void dm9000_outblk_8bit(struct dm9000_priv *db, void *data_ptr, int count)
118 {
119         int i;
120
121         for (i = 0; i < count; i++)
122                 dm9000_outb((((u8 *)data_ptr)[i] & 0xff), db->base_data);
123 }
124
125 static void dm9000_outblk_16bit(struct dm9000_priv *db, void *data_ptr, int count)
126 {
127         int i;
128         u32 tmplen = (count + 1) / 2;
129
130         for (i = 0; i < tmplen; i++)
131                 dm9000_outw(((u16 *)data_ptr)[i], db->base_data);
132 }
133
134 static void dm9000_outblk_32bit(struct dm9000_priv *db, void *data_ptr, int count)
135 {
136         int i;
137         u32 tmplen = (count + 3) / 4;
138
139         for (i = 0; i < tmplen; i++)
140                 dm9000_outl(((u32 *)data_ptr)[i], db->base_data);
141 }
142
143 static void dm9000_inblk_8bit(struct dm9000_priv *db, void *data_ptr, int count)
144 {
145         int i;
146
147         for (i = 0; i < count; i++)
148                 ((u8 *)data_ptr)[i] = dm9000_inb(db->base_data);
149 }
150
151 static void dm9000_inblk_16bit(struct dm9000_priv *db, void *data_ptr, int count)
152 {
153         int i;
154         u32 tmplen = (count + 1) / 2;
155
156         for (i = 0; i < tmplen; i++)
157                 ((u16 *)data_ptr)[i] = dm9000_inw(db->base_data);
158 }
159
160 static void dm9000_inblk_32bit(struct dm9000_priv *db, void *data_ptr, int count)
161 {
162         int i;
163         u32 tmplen = (count + 3) / 4;
164
165         for (i = 0; i < tmplen; i++)
166                 ((u32 *)data_ptr)[i] = dm9000_inl(db->base_data);
167 }
168
169 static void dm9000_rx_status_32bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
170 {
171         u32 tmpdata;
172
173         dm9000_outb(DM9000_MRCMD, db->base_io);
174
175         tmpdata = dm9000_inl(db->base_data);
176         *rxstatus = __le16_to_cpu(tmpdata);
177         *rxlen = __le16_to_cpu(tmpdata >> 16);
178 }
179
180 static void dm9000_rx_status_16bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
181 {
182         dm9000_outb(DM9000_MRCMD, db->base_io);
183
184         *rxstatus = __le16_to_cpu(dm9000_inw(db->base_data));
185         *rxlen = __le16_to_cpu(dm9000_inw(db->base_data));
186 }
187
188 static void dm9000_rx_status_8bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen)
189 {
190         dm9000_outb(DM9000_MRCMD, db->base_io);
191
192         *rxstatus =
193             __le16_to_cpu(dm9000_inb(db->base_data) +
194                           (dm9000_inb(db->base_data) << 8));
195         *rxlen =
196             __le16_to_cpu(dm9000_inb(db->base_data) +
197                           (dm9000_inb(db->base_data) << 8));
198 }
199
200 /*
201  *  Read a byte from I/O port
202  */
203 static u8 dm9000_ior(struct dm9000_priv *db, int reg)
204 {
205         dm9000_outb(reg, db->base_io);
206         return dm9000_inb(db->base_data);
207 }
208
209 /*
210  *  Write a byte to I/O port
211  */
212 static void dm9000_iow(struct dm9000_priv *db, int reg, u8 value)
213 {
214         dm9000_outb(reg, db->base_io);
215         dm9000_outb(value, db->base_data);
216 }
217
218 /*
219  *  Read a word from phyxcer
220  */
221 static u16 dm9000_phy_read(struct dm9000_priv *db, int reg)
222 {
223         u16 val;
224
225         /* Fill the phyxcer register into REG_0C */
226         dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg);
227         dm9000_iow(db, DM9000_EPCR, 0xc);       /* Issue phyxcer read command */
228         udelay(100);                    /* Wait read complete */
229         dm9000_iow(db, DM9000_EPCR, 0x0);       /* Clear phyxcer read command */
230         val = (dm9000_ior(db, DM9000_EPDRH) << 8) |
231               dm9000_ior(db, DM9000_EPDRL);
232
233         /* The read data keeps on REG_0D & REG_0E */
234         debug("%s(0x%x): 0x%x\n", __func__, reg, val);
235         return val;
236 }
237
238 /*
239  *  Write a word to phyxcer
240  */
241 static void dm9000_phy_write(struct dm9000_priv *db, int reg, u16 value)
242 {
243         /* Fill the phyxcer register into REG_0C */
244         dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg);
245
246         /* Fill the written data into REG_0D & REG_0E */
247         dm9000_iow(db, DM9000_EPDRL, (value & 0xff));
248         dm9000_iow(db, DM9000_EPDRH, ((value >> 8) & 0xff));
249         dm9000_iow(db, DM9000_EPCR, 0xa);       /* Issue phyxcer write command */
250         udelay(500);                    /* Wait write complete */
251         dm9000_iow(db, DM9000_EPCR, 0x0);       /* Clear phyxcer write command */
252         debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value);
253 }
254
255 /*
256  * Search DM9000 board, allocate space and register it
257  */
258 static int dm9000_probe(struct dm9000_priv *db)
259 {
260         u32 id_val;
261
262         id_val = dm9000_ior(db, DM9000_VIDL);
263         id_val |= dm9000_ior(db, DM9000_VIDH) << 8;
264         id_val |= dm9000_ior(db, DM9000_PIDL) << 16;
265         id_val |= dm9000_ior(db, DM9000_PIDH) << 24;
266         if (id_val != DM9000_ID) {
267                 printf("dm9000 not found at 0x%p id: 0x%08x\n",
268                        db->base_io, id_val);
269                 return -1;
270         }
271
272         printf("dm9000 i/o: 0x%p, id: 0x%x\n", db->base_io, id_val);
273         return 0;
274 }
275
276 /* General Purpose dm9000 reset routine */
277 static void dm9000_reset(struct dm9000_priv *db)
278 {
279         debug("resetting DM9000\n");
280
281         /*
282          * Reset DM9000,
283          * see DM9000 Application Notes V1.22 Jun 11, 2004 page 29
284          */
285
286         /* DEBUG: Make all GPIO0 outputs, all others inputs */
287         dm9000_iow(db, DM9000_GPCR, GPCR_GPIO0_OUT);
288         /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
289         dm9000_iow(db, DM9000_GPR, 0);
290         /* Step 2: Software reset */
291         dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
292
293         do {
294                 debug("resetting the DM9000, 1st reset\n");
295                 udelay(25); /* Wait at least 20 us */
296         } while (dm9000_ior(db, DM9000_NCR) & 1);
297
298         dm9000_iow(db, DM9000_NCR, 0);
299         dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
300
301         do {
302                 debug("resetting the DM9000, 2nd reset\n");
303                 udelay(25); /* Wait at least 20 us */
304         } while (dm9000_ior(db, DM9000_NCR) & 1);
305
306         /* Check whether the ethernet controller is present */
307         if ((dm9000_ior(db, DM9000_PIDL) != 0x0) ||
308             (dm9000_ior(db, DM9000_PIDH) != 0x90))
309                 printf("ERROR: resetting DM9000 -> not responding\n");
310 }
311
312 /* Initialize dm9000 board */
313 static int dm9000_init_common(struct dm9000_priv *db, u8 enetaddr[6])
314 {
315         int i, oft, lnk;
316         u8 io_mode;
317
318         /* RESET device */
319         dm9000_reset(db);
320
321         if (dm9000_probe(db) < 0)
322                 return -1;
323
324         /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
325         io_mode = dm9000_ior(db, DM9000_ISR) >> 6;
326
327         switch (io_mode) {
328         case 0x0:  /* 16-bit mode */
329                 printf("DM9000: running in 16 bit mode\n");
330                 db->outblk    = dm9000_outblk_16bit;
331                 db->inblk     = dm9000_inblk_16bit;
332                 db->rx_status = dm9000_rx_status_16bit;
333                 break;
334         case 0x01:  /* 32-bit mode */
335                 printf("DM9000: running in 32 bit mode\n");
336                 db->outblk    = dm9000_outblk_32bit;
337                 db->inblk     = dm9000_inblk_32bit;
338                 db->rx_status = dm9000_rx_status_32bit;
339                 break;
340         case 0x02: /* 8 bit mode */
341                 printf("DM9000: running in 8 bit mode\n");
342                 db->outblk    = dm9000_outblk_8bit;
343                 db->inblk     = dm9000_inblk_8bit;
344                 db->rx_status = dm9000_rx_status_8bit;
345                 break;
346         default:
347                 /* Assume 8 bit mode, will probably not work anyway */
348                 printf("DM9000: Undefined IO-mode:0x%x\n", io_mode);
349                 db->outblk    = dm9000_outblk_8bit;
350                 db->inblk     = dm9000_inblk_8bit;
351                 db->rx_status = dm9000_rx_status_8bit;
352                 break;
353         }
354
355         /* Program operating register, only internal phy supported */
356         dm9000_iow(db, DM9000_NCR, 0x0);
357         /* TX Polling clear */
358         dm9000_iow(db, DM9000_TCR, 0);
359         /* Less 3Kb, 200us */
360         dm9000_iow(db, DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
361         /* Flow Control : High/Low Water */
362         dm9000_iow(db, DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
363         /* SH FIXME: This looks strange! Flow Control */
364         dm9000_iow(db, DM9000_FCR, 0x0);
365         /* Special Mode */
366         dm9000_iow(db, DM9000_SMCR, 0);
367         /* clear TX status */
368         dm9000_iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
369         /* Clear interrupt status */
370         dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
371
372         printf("MAC: %pM\n", enetaddr);
373         if (!is_valid_ethaddr(enetaddr))
374                 printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n");
375
376         /* fill device MAC address registers */
377         for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
378                 dm9000_iow(db, oft, enetaddr[i]);
379         for (i = 0, oft = 0x16; i < 8; i++, oft++)
380                 dm9000_iow(db, oft, 0xff);
381
382         /* read back mac, just to be sure */
383         for (i = 0, oft = 0x10; i < 6; i++, oft++)
384                 debug("%02x:", dm9000_ior(db, oft));
385         debug("\n");
386
387         /* Activate DM9000 */
388         /* RX enable */
389         dm9000_iow(db, DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
390         /* Enable TX/RX interrupt mask */
391         dm9000_iow(db, DM9000_IMR, IMR_PAR);
392
393         i = 0;
394         while (!(dm9000_phy_read(db, 1) & 0x20)) {      /* autonegation complete bit */
395                 udelay(1000);
396                 i++;
397                 if (i == 10000) {
398                         printf("could not establish link\n");
399                         return 0;
400                 }
401         }
402
403         /* see what we've got */
404         lnk = dm9000_phy_read(db, 17) >> 12;
405         printf("operating at ");
406         switch (lnk) {
407         case 1:
408                 printf("10M half duplex ");
409                 break;
410         case 2:
411                 printf("10M full duplex ");
412                 break;
413         case 4:
414                 printf("100M half duplex ");
415                 break;
416         case 8:
417                 printf("100M full duplex ");
418                 break;
419         default:
420                 printf("unknown: %d ", lnk);
421                 break;
422         }
423         printf("mode\n");
424         return 0;
425 }
426
427 /*
428  * Hardware start transmission.
429  * Send a packet to media from the upper layer.
430  */
431 static int dm9000_send_common(struct dm9000_priv *db, void *packet, int length)
432 {
433         int tmo;
434
435         dm9000_dump_packet(__func__, packet, length);
436
437         dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
438
439         /* Move data to DM9000 TX RAM */
440         dm9000_outb(DM9000_MWCMD, db->base_io); /* Prepare for TX-data */
441
442         /* push the data to the TX-fifo */
443         db->outblk(db, packet, length);
444
445         /* Set TX length to DM9000 */
446         dm9000_iow(db, DM9000_TXPLL, length & 0xff);
447         dm9000_iow(db, DM9000_TXPLH, (length >> 8) & 0xff);
448
449         /* Issue TX polling command */
450         dm9000_iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
451
452         /* wait for end of transmission */
453         tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
454         while (!(dm9000_ior(db, DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
455                !(dm9000_ior(db, DM9000_ISR) & IMR_PTM)) {
456                 if (get_timer(0) >= tmo) {
457                         printf("transmission timeout\n");
458                         break;
459                 }
460         }
461         dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
462
463         debug("transmit done\n\n");
464         return 0;
465 }
466
467 /*
468  * Stop the interface.
469  * The interface is stopped when it is brought.
470  */
471 static void dm9000_halt_common(struct dm9000_priv *db)
472 {
473         /* RESET device */
474         dm9000_phy_write(db, 0, 0x8000);        /* PHY RESET */
475         dm9000_iow(db, DM9000_GPR, 0x01);       /* Power-Down PHY */
476         dm9000_iow(db, DM9000_IMR, 0x80);       /* Disable all interrupt */
477         dm9000_iow(db, DM9000_RCR, 0x00);       /* Disable RX */
478 }
479
480 /*
481  * Received a packet and pass to upper layer
482  */
483 static int dm9000_recv_common(struct dm9000_priv *db, uchar *rdptr)
484 {
485         u8 rxbyte;
486         u16 rxstatus, rxlen = 0;
487
488         /*
489          * Check packet ready or not, we must check
490          * the ISR status first for DM9000A
491          */
492         if (!(dm9000_ior(db, DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
493                 return 0;
494
495         dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
496
497         /* There is _at least_ 1 package in the fifo, read them all */
498         dm9000_ior(db, DM9000_MRCMDX);  /* Dummy read */
499
500         /*
501          * Get most updated data,
502          * only look at bits 0:1, See application notes DM9000
503          */
504         rxbyte = dm9000_inb(db->base_data) & 0x03;
505
506         /* Status check: this byte must be 0 or 1 */
507         if (rxbyte > DM9000_PKT_RDY) {
508                 dm9000_iow(db, DM9000_RCR, 0x00);       /* Stop Device */
509                 dm9000_iow(db, DM9000_ISR, 0x80);       /* Stop INT request */
510                 printf("DM9000 error: status check fail: 0x%x\n",
511                        rxbyte);
512                 return -EINVAL;
513         }
514
515         if (rxbyte != DM9000_PKT_RDY)
516                 return 0; /* No packet received, ignore */
517
518         debug("receiving packet\n");
519
520         /* A packet ready now  & Get status/length */
521         db->rx_status(db, &rxstatus, &rxlen);
522
523         debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen);
524
525         /* Move data from DM9000 */
526         /* Read received packet from RX SRAM */
527         db->inblk(db, rdptr, rxlen);
528
529         if (rxstatus & 0xbf00 || rxlen < 0x40 || rxlen > DM9000_PKT_MAX) {
530                 if (rxstatus & 0x100)
531                         printf("rx fifo error\n");
532                 if (rxstatus & 0x200)
533                         printf("rx crc error\n");
534                 if (rxstatus & 0x8000)
535                         printf("rx length error\n");
536                 if (rxlen > DM9000_PKT_MAX) {
537                         printf("rx length too big\n");
538                         dm9000_reset(db);
539                 }
540                 return -EINVAL;
541         }
542
543         return rxlen;
544 }
545
546 /*
547  * Read a word data from SROM
548  */
549 #if !defined(CONFIG_DM9000_NO_SROM)
550 static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to)
551 {
552         dm9000_iow(db, DM9000_EPAR, offset);
553         dm9000_iow(db, DM9000_EPCR, 0x4);
554         mdelay(8);
555         dm9000_iow(db, DM9000_EPCR, 0x0);
556         to[0] = dm9000_ior(db, DM9000_EPDRL);
557         to[1] = dm9000_ior(db, DM9000_EPDRH);
558 }
559
560 static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr)
561 {
562         int i;
563
564         for (i = 0; i < 3; i++)
565                 dm9000_read_srom_word(db, i, enetaddr + (2 * i));
566 }
567 #else
568 static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {}
569 #endif
570
571 static int dm9000_start(struct udevice *dev)
572 {
573         struct dm9000_priv *db = dev_get_priv(dev);
574         struct eth_pdata *pdata = dev_get_plat(dev);
575
576         return dm9000_init_common(db, pdata->enetaddr);
577 }
578
579 static void dm9000_stop(struct udevice *dev)
580 {
581         struct dm9000_priv *db = dev_get_priv(dev);
582
583         dm9000_halt_common(db);
584 }
585
586 static int dm9000_send(struct udevice *dev, void *packet, int length)
587 {
588         struct dm9000_priv *db = dev_get_priv(dev);
589         int ret;
590
591         ret = dm9000_send_common(db, packet, length);
592
593         return ret ? 0 : -ETIMEDOUT;
594 }
595
596 static int dm9000_recv(struct udevice *dev, int flags, uchar **packetp)
597 {
598         struct dm9000_priv *db = dev_get_priv(dev);
599         uchar *data = net_rx_packets[0];
600         int ret;
601
602         ret = dm9000_recv_common(db, data);
603         if (ret > 0)
604                 *packetp = (void *)data;
605
606         return ret >= 0 ? ret : -EAGAIN;
607 }
608
609 static int dm9000_write_hwaddr(struct udevice *dev)
610 {
611         struct dm9000_priv *db = dev_get_priv(dev);
612         struct eth_pdata *pdata = dev_get_plat(dev);
613         int i, oft;
614
615         /* fill device MAC address registers */
616         for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
617                 dm9000_iow(db, oft, pdata->enetaddr[i]);
618
619         for (i = 0, oft = 0x16; i < 8; i++, oft++)
620                 dm9000_iow(db, oft, 0xff);
621
622         /* read back mac, just to be sure */
623         for (i = 0, oft = 0x10; i < 6; i++, oft++)
624                 debug("%02x:", dm9000_ior(db, oft));
625
626         debug("\n");
627
628         return 0;
629 }
630
631 static int dm9000_read_rom_hwaddr(struct udevice *dev)
632 {
633         struct dm9000_priv *db = dev_get_priv(dev);
634         struct eth_pdata *pdata = dev_get_plat(dev);
635
636         dm9000_get_enetaddr(db, pdata->enetaddr);
637
638         return !is_valid_ethaddr(pdata->enetaddr);
639 }
640
641 static int dm9000_bind(struct udevice *dev)
642 {
643         return device_set_name(dev, dev->name);
644 }
645
646 static int dm9000_of_to_plat(struct udevice *dev)
647 {
648         struct dm9000_priv *db = dev_get_priv(dev);
649         struct eth_pdata *pdata = dev_get_plat(dev);
650
651         pdata->iobase = dev_read_addr_index(dev, 0);
652         db->base_io = (void __iomem *)pdata->iobase;
653         db->base_data = dev_read_addr_index_ptr(dev, 1);
654
655         return 0;
656 }
657
658 static const struct eth_ops dm9000_ops = {
659         .start          = dm9000_start,
660         .stop           = dm9000_stop,
661         .send           = dm9000_send,
662         .recv           = dm9000_recv,
663         .write_hwaddr   = dm9000_write_hwaddr,
664         .read_rom_hwaddr = dm9000_read_rom_hwaddr,
665 };
666
667 static const struct udevice_id dm9000_ids[] = {
668         { .compatible = "davicom,dm9000" },
669         { }
670 };
671
672 U_BOOT_DRIVER(dm9000) = {
673         .name           = "eth_dm9000",
674         .id             = UCLASS_ETH,
675         .of_match       = dm9000_ids,
676         .bind           = dm9000_bind,
677         .of_to_plat = dm9000_of_to_plat,
678         .ops            = &dm9000_ops,
679         .priv_auto      = sizeof(struct dm9000_priv),
680         .plat_auto      = sizeof(struct eth_pdata),
681         .flags          = DM_FLAG_ALLOC_PRIV_DMA,
682 };
This page took 0.062422 seconds and 4 git commands to generate.