wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | Ported to U-Boot by Christian Pellegrin <chri@ascensit.com> |
| 3 | |
| 4 | Based on sources from the Linux kernel (pcnet_cs.c, 8390.h) and |
| 5 | eCOS(if_dp83902a.c, if_dp83902a.h). Both of these 2 wonderful world |
| 6 | are GPL, so this is, of course, GPL. |
| 7 | |
| 8 | |
| 9 | ========================================================================== |
| 10 | |
| 11 | dev/dp83902a.h |
| 12 | |
| 13 | National Semiconductor DP83902a ethernet chip |
| 14 | |
| 15 | ========================================================================== |
| 16 | ####ECOSGPLCOPYRIGHTBEGIN#### |
| 17 | ------------------------------------------- |
| 18 | This file is part of eCos, the Embedded Configurable Operating System. |
| 19 | Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
| 20 | |
| 21 | eCos is free software; you can redistribute it and/or modify it under |
| 22 | the terms of the GNU General Public License as published by the Free |
| 23 | Software Foundation; either version 2 or (at your option) any later version. |
| 24 | |
| 25 | eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
| 26 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 27 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 28 | for more details. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License along |
| 31 | with eCos; if not, write to the Free Software Foundation, Inc., |
| 32 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 33 | |
| 34 | As a special exception, if other files instantiate templates or use macros |
| 35 | or inline functions from this file, or you compile this file and link it |
| 36 | with other works to produce a work based on this file, this file does not |
| 37 | by itself cause the resulting work to be covered by the GNU General Public |
| 38 | License. However the source code for this file must still be made available |
| 39 | in accordance with section (3) of the GNU General Public License. |
| 40 | |
| 41 | This exception does not invalidate any other reasons why a work based on |
| 42 | this file might be covered by the GNU General Public License. |
| 43 | |
| 44 | Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
Vlad Lungu | a78b0cd | 2007-10-04 20:47:10 +0300 | [diff] [blame] | 45 | at http://sources.redhat.com/ecos/ecos-license/ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 46 | ------------------------------------------- |
| 47 | ####ECOSGPLCOPYRIGHTEND#### |
| 48 | ####BSDCOPYRIGHTBEGIN#### |
| 49 | |
| 50 | ------------------------------------------- |
| 51 | |
| 52 | Portions of this software may have been derived from OpenBSD or other sources, |
| 53 | and are covered by the appropriate copyright disclaimers included herein. |
| 54 | |
| 55 | ------------------------------------------- |
| 56 | |
| 57 | ####BSDCOPYRIGHTEND#### |
| 58 | ========================================================================== |
| 59 | #####DESCRIPTIONBEGIN#### |
| 60 | |
| 61 | Author(s): gthomas |
| 62 | Contributors: gthomas, jskov |
| 63 | Date: 2001-06-13 |
| 64 | Purpose: |
| 65 | Description: |
| 66 | |
| 67 | ####DESCRIPTIONEND#### |
| 68 | |
| 69 | ========================================================================== |
| 70 | |
| 71 | */ |
| 72 | |
| 73 | /* |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 74 | * NE2000 support header file. |
| 75 | * Created by Nobuhiro Iwamatsu <iwamatsu@nigauri.org> |
| 76 | */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 77 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 78 | #ifndef __DRIVERS_NE2000_H__ |
| 79 | #define __DRIVERS_NE2000_H__ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 80 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 81 | /* Enable NE2000 basic init function */ |
| 82 | #define NE2000_BASIC_INIT |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 83 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 84 | #define DP_DATA 0x10 |
| 85 | #define START_PG 0x50 /* First page of TX buffer */ |
| 86 | #define STOP_PG 0x80 /* Last page +1 of RX ring */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 87 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 88 | #define RX_START 0x50 |
| 89 | #define RX_END 0x80 |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 90 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 91 | #define DP_IN(_b_, _o_, _d_) (_d_) = *( (vu_char *) ((_b_)+(_o_))) |
| 92 | #define DP_OUT(_b_, _o_, _d_) *( (vu_char *) ((_b_)+(_o_))) = (_d_) |
| 93 | #define DP_IN_DATA(_b_, _d_) (_d_) = *( (vu_char *) ((_b_))) |
| 94 | #define DP_OUT_DATA(_b_, _d_) *( (vu_char *) ((_b_))) = (_d_) |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 95 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 96 | static void pcnet_reset_8390(void) |
| 97 | { |
| 98 | int i, r; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 99 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 100 | PRINTK("nic base is %lx\n", nic_base); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 101 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 102 | n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); |
| 103 | PRINTK("cmd (at %lx) is %x\n", nic_base+ E8390_CMD, n2k_inb(E8390_CMD)); |
| 104 | n2k_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, E8390_CMD); |
| 105 | PRINTK("cmd (at %lx) is %x\n", nic_base+ E8390_CMD, n2k_inb(E8390_CMD)); |
| 106 | n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); |
| 107 | PRINTK("cmd (at %lx) is %x\n", nic_base+ E8390_CMD, n2k_inb(E8390_CMD)); |
| 108 | n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 109 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 110 | n2k_outb(n2k_inb(PCNET_RESET), PCNET_RESET); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 111 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 112 | for (i = 0; i < 100; i++) { |
| 113 | if ((r = (n2k_inb(EN0_ISR) & ENISR_RESET)) != 0) |
| 114 | break; |
| 115 | PRINTK("got %x in reset\n", r); |
| 116 | udelay(100); |
| 117 | } |
| 118 | n2k_outb(ENISR_RESET, EN0_ISR); /* Ack intr. */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 119 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 120 | if (i == 100) |
| 121 | printf("pcnet_reset_8390() did not complete.\n"); |
| 122 | } /* pcnet_reset_8390 */ |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 123 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 124 | int get_prom(u8* mac_addr) |
| 125 | { |
| 126 | u8 prom[32]; |
| 127 | int i, j; |
| 128 | struct { |
| 129 | u_char value, offset; |
| 130 | } program_seq[] = { |
| 131 | {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/ |
| 132 | {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */ |
| 133 | {0x00, EN0_RCNTLO}, /* Clear the count regs. */ |
| 134 | {0x00, EN0_RCNTHI}, |
| 135 | {0x00, EN0_IMR}, /* Mask completion irq. */ |
| 136 | {0xFF, EN0_ISR}, |
| 137 | {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */ |
| 138 | {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */ |
| 139 | {32, EN0_RCNTLO}, |
| 140 | {0x00, EN0_RCNTHI}, |
| 141 | {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */ |
| 142 | {0x00, EN0_RSARHI}, |
| 143 | {E8390_RREAD+E8390_START, E8390_CMD}, |
| 144 | }; |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 145 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 146 | PRINTK("trying to get MAC via prom reading\n"); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 147 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 148 | pcnet_reset_8390(); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 149 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 150 | mdelay(10); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 151 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 152 | for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++) |
| 153 | n2k_outb(program_seq[i].value, program_seq[i].offset); |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 154 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 155 | PRINTK("PROM:"); |
| 156 | for (i = 0; i < 32; i++) { |
| 157 | prom[i] = n2k_inb(PCNET_DATAPORT); |
| 158 | PRINTK(" %02x", prom[i]); |
| 159 | } |
| 160 | PRINTK("\n"); |
| 161 | for (i = 0; i < NR_INFO; i++) { |
| 162 | if ((prom[0] == hw_info[i].a0) && |
| 163 | (prom[2] == hw_info[i].a1) && |
| 164 | (prom[4] == hw_info[i].a2)) { |
| 165 | PRINTK("matched board %d\n", i); |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | if ((i < NR_INFO) || ((prom[28] == 0x57) && (prom[30] == 0x57))) { |
| 170 | PRINTK("on exit i is %d/%ld\n", i, NR_INFO); |
| 171 | PRINTK("MAC address is "); |
| 172 | for (j = 0; j < 6; j++){ |
| 173 | mac_addr[j] = prom[j<<1]; |
| 174 | PRINTK("%02x:",mac_addr[i]); |
| 175 | } |
| 176 | PRINTK("\n"); |
| 177 | return (i < NR_INFO) ? i : 0; |
| 178 | } |
| 179 | return NULL; |
| 180 | } |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 181 | |
wdenk | f806271 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 182 | |
goda.yusuke | 7b603ad | 2008-03-05 17:08:20 +0900 | [diff] [blame^] | 183 | #endif /* __DRIVERS_NE2000_H__ */ |