blob: d324a000846cd3897dfaff7e5bca35e5b30e05a3 [file] [log] [blame]
wdenkf8062712005-01-09 23:16:25 +00001/*
2Ported to U-Boot by Christian Pellegrin <chri@ascensit.com>
3
4Based on sources from the Linux kernel (pcnet_cs.c, 8390.h) and
5eCOS(if_dp83902a.c, if_dp83902a.h). Both of these 2 wonderful world
6are GPL, so this is, of course, GPL.
7
wdenkf8062712005-01-09 23:16:25 +00008==========================================================================
9
10 dev/dp83902a.h
11
12 National Semiconductor DP83902a ethernet chip
13
14==========================================================================
15####ECOSGPLCOPYRIGHTBEGIN####
16 -------------------------------------------
17 This file is part of eCos, the Embedded Configurable Operating System.
18 Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
19
20 eCos is free software; you can redistribute it and/or modify it under
21 the terms of the GNU General Public License as published by the Free
22 Software Foundation; either version 2 or (at your option) any later version.
23
24 eCos is distributed in the hope that it will be useful, but WITHOUT ANY
25 WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 for more details.
28
29 You should have received a copy of the GNU General Public License along
30 with eCos; if not, write to the Free Software Foundation, Inc.,
31 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
32
33 As a special exception, if other files instantiate templates or use macros
34 or inline functions from this file, or you compile this file and link it
35 with other works to produce a work based on this file, this file does not
36 by itself cause the resulting work to be covered by the GNU General Public
37 License. However the source code for this file must still be made available
38 in accordance with section (3) of the GNU General Public License.
39
40 This exception does not invalidate any other reasons why a work based on
41 this file might be covered by the GNU General Public License.
42
43 Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
Vlad Lungua78b0cd2007-10-04 20:47:10 +030044 at http://sources.redhat.com/ecos/ecos-license/
wdenkf8062712005-01-09 23:16:25 +000045 -------------------------------------------
46####ECOSGPLCOPYRIGHTEND####
47####BSDCOPYRIGHTBEGIN####
48
49 -------------------------------------------
50
51 Portions of this software may have been derived from OpenBSD or other sources,
52 and are covered by the appropriate copyright disclaimers included herein.
53
54 -------------------------------------------
55
56####BSDCOPYRIGHTEND####
57==========================================================================
58#####DESCRIPTIONBEGIN####
59
60 Author(s): gthomas
61 Contributors: gthomas, jskov
62 Date: 2001-06-13
63 Purpose:
64 Description:
65
66####DESCRIPTIONEND####
67
68==========================================================================
wdenkf8062712005-01-09 23:16:25 +000069*/
70
71/*
goda.yusuke7b603ad2008-03-05 17:08:20 +090072 * NE2000 support header file.
73 * Created by Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
74 */
wdenkf8062712005-01-09 23:16:25 +000075
goda.yusuke7b603ad2008-03-05 17:08:20 +090076#ifndef __DRIVERS_NE2000_H__
77#define __DRIVERS_NE2000_H__
wdenkf8062712005-01-09 23:16:25 +000078
goda.yusuke7b603ad2008-03-05 17:08:20 +090079/* Enable NE2000 basic init function */
80#define NE2000_BASIC_INIT
wdenkf8062712005-01-09 23:16:25 +000081
goda.yusuke7b603ad2008-03-05 17:08:20 +090082#define DP_DATA 0x10
83#define START_PG 0x50 /* First page of TX buffer */
84#define STOP_PG 0x80 /* Last page +1 of RX ring */
wdenkf8062712005-01-09 23:16:25 +000085
goda.yusuke7b603ad2008-03-05 17:08:20 +090086#define RX_START 0x50
87#define RX_END 0x80
wdenkf8062712005-01-09 23:16:25 +000088
goda.yusuke7b603ad2008-03-05 17:08:20 +090089#define DP_IN(_b_, _o_, _d_) (_d_) = *( (vu_char *) ((_b_)+(_o_)))
90#define DP_OUT(_b_, _o_, _d_) *( (vu_char *) ((_b_)+(_o_))) = (_d_)
91#define DP_IN_DATA(_b_, _d_) (_d_) = *( (vu_char *) ((_b_)))
92#define DP_OUT_DATA(_b_, _d_) *( (vu_char *) ((_b_))) = (_d_)
wdenkf8062712005-01-09 23:16:25 +000093
goda.yusuke7b603ad2008-03-05 17:08:20 +090094static void pcnet_reset_8390(void)
95{
96 int i, r;
wdenkf8062712005-01-09 23:16:25 +000097
goda.yusuke7b603ad2008-03-05 17:08:20 +090098 PRINTK("nic base is %lx\n", nic_base);
wdenkf8062712005-01-09 23:16:25 +000099
goda.yusuke7b603ad2008-03-05 17:08:20 +0900100 n2k_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD);
101 PRINTK("cmd (at %lx) is %x\n", nic_base+ E8390_CMD, n2k_inb(E8390_CMD));
102 n2k_outb(E8390_NODMA+E8390_PAGE1+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_PAGE0+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);
wdenkf8062712005-01-09 23:16:25 +0000107
goda.yusuke7b603ad2008-03-05 17:08:20 +0900108 n2k_outb(n2k_inb(PCNET_RESET), PCNET_RESET);
wdenkf8062712005-01-09 23:16:25 +0000109
goda.yusuke7b603ad2008-03-05 17:08:20 +0900110 for (i = 0; i < 100; i++) {
111 if ((r = (n2k_inb(EN0_ISR) & ENISR_RESET)) != 0)
112 break;
113 PRINTK("got %x in reset\n", r);
114 udelay(100);
115 }
116 n2k_outb(ENISR_RESET, EN0_ISR); /* Ack intr. */
wdenkf8062712005-01-09 23:16:25 +0000117
goda.yusuke7b603ad2008-03-05 17:08:20 +0900118 if (i == 100)
119 printf("pcnet_reset_8390() did not complete.\n");
120} /* pcnet_reset_8390 */
wdenkf8062712005-01-09 23:16:25 +0000121
goda.yusuke7b603ad2008-03-05 17:08:20 +0900122int get_prom(u8* mac_addr)
123{
124 u8 prom[32];
125 int i, j;
126 struct {
127 u_char value, offset;
128 } program_seq[] = {
129 {E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100130 {0x48, EN0_DCFG}, /* Set byte-wide (0x48) access. */
131 {0x00, EN0_RCNTLO}, /* Clear the count regs. */
goda.yusuke7b603ad2008-03-05 17:08:20 +0900132 {0x00, EN0_RCNTHI},
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100133 {0x00, EN0_IMR}, /* Mask completion irq. */
goda.yusuke7b603ad2008-03-05 17:08:20 +0900134 {0xFF, EN0_ISR},
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100135 {E8390_RXOFF, EN0_RXCR}, /* 0x20 Set to monitor */
136 {E8390_TXOFF, EN0_TXCR}, /* 0x02 and loopback mode. */
goda.yusuke7b603ad2008-03-05 17:08:20 +0900137 {32, EN0_RCNTLO},
138 {0x00, EN0_RCNTHI},
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100139 {0x00, EN0_RSARLO}, /* DMA starting at 0x0000. */
goda.yusuke7b603ad2008-03-05 17:08:20 +0900140 {0x00, EN0_RSARHI},
141 {E8390_RREAD+E8390_START, E8390_CMD},
142 };
wdenkf8062712005-01-09 23:16:25 +0000143
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100144 PRINTK ("trying to get MAC via prom reading\n");
wdenkf8062712005-01-09 23:16:25 +0000145
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100146 pcnet_reset_8390 ();
wdenkf8062712005-01-09 23:16:25 +0000147
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100148 mdelay (10);
wdenkf8062712005-01-09 23:16:25 +0000149
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100150 for (i = 0; i < sizeof (program_seq) / sizeof (program_seq[0]); i++)
151 n2k_outb (program_seq[i].value, program_seq[i].offset);
wdenkf8062712005-01-09 23:16:25 +0000152
Wolfgang Denk840a0d72008-03-26 00:52:10 +0100153 PRINTK ("PROM:");
154 for (i = 0; i < 32; i++) {
155 prom[i] = n2k_inb (PCNET_DATAPORT);
156 PRINTK (" %02x", prom[i]);
157 }
158 PRINTK ("\n");
159 for (i = 0; i < NR_INFO; i++) {
160 if ((prom[0] == hw_info[i].a0) &&
161 (prom[2] == hw_info[i].a1) &&
162 (prom[4] == hw_info[i].a2)) {
163 PRINTK ("matched board %d\n", i);
164 break;
165 }
166 }
167 if ((i < NR_INFO) || ((prom[28] == 0x57) && (prom[30] == 0x57))) {
168 PRINTK ("on exit i is %d/%ld\n", i, NR_INFO);
169 PRINTK ("MAC address is ");
170 for (j = 0; j < 6; j++) {
171 mac_addr[j] = prom[j << 1];
172 PRINTK ("%02x:", mac_addr[i]);
173 }
174 PRINTK ("\n");
175 return (i < NR_INFO) ? i : 0;
176 }
177 return NULL;
goda.yusuke7b603ad2008-03-05 17:08:20 +0900178}
goda.yusuke7b603ad2008-03-05 17:08:20 +0900179#endif /* __DRIVERS_NE2000_H__ */