Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 2 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 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 <weilun_huang@davicom.com.tw>: |
| 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 <saschahauer@web.de> |
| 32 | * |
| 33 | * 06/03/2008 Remy Bohmer <linux@bohmer.net> |
| 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 | */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 51 | |
| 52 | #include <common.h> |
| 53 | #include <command.h> |
| 54 | #include <net.h> |
| 55 | #include <asm/io.h> |
Remy Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 56 | #include <dm9000.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 57 | #include <linux/delay.h> |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 58 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 59 | #include "dm9000x.h" |
| 60 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 61 | /* Structure/enum declaration ------------------------------- */ |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 62 | struct board_info { |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 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 */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 73 | unsigned char srom[128]; |
Marek Vasut | 7823b23 | 2022-04-13 04:15:28 +0200 | [diff] [blame] | 74 | void (*outblk)(void *data_ptr, int count); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 75 | void (*inblk)(void *data_ptr, int count); |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 76 | void (*rx_status)(u16 *rxstatus, u16 *rxlen); |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 77 | struct eth_device netdev; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 78 | }; |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 79 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 80 | static struct board_info dm9000_info; |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 81 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 82 | /* function declaration ------------------------------------- */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 83 | static int dm9000_probe(void); |
Andy Fleming | 0d2df96 | 2011-03-22 22:49:13 -0500 | [diff] [blame] | 84 | static u16 dm9000_phy_read(int); |
| 85 | static void dm9000_phy_write(int, u16); |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 86 | static u8 dm9000_ior(int); |
| 87 | static void dm9000_iow(int reg, u8 value); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 88 | |
| 89 | /* DM9000 network board routine ---------------------------- */ |
Jason Jin | c74c436 | 2011-08-25 15:46:43 +0800 | [diff] [blame] | 90 | #ifndef CONFIG_DM9000_BYTE_SWAPPED |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 91 | #define dm9000_outb(d, r) writeb((d), (r)) |
| 92 | #define dm9000_outw(d, r) writew((d), (r)) |
| 93 | #define dm9000_outl(d, r) writel((d), (r)) |
Marek Vasut | 7823b23 | 2022-04-13 04:15:28 +0200 | [diff] [blame] | 94 | #define dm9000_inb(r) readb(r) |
| 95 | #define dm9000_inw(r) readw(r) |
| 96 | #define dm9000_inl(r) readl(r) |
Jason Jin | c74c436 | 2011-08-25 15:46:43 +0800 | [diff] [blame] | 97 | #else |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 98 | #define dm9000_outb(d, r) __raw_writeb(d, r) |
| 99 | #define dm9000_outw(d, r) __raw_writew(d, r) |
| 100 | #define dm9000_outl(d, r) __raw_writel(d, r) |
| 101 | #define dm9000_inb(r) __raw_readb(r) |
| 102 | #define dm9000_inw(r) __raw_readw(r) |
| 103 | #define dm9000_inl(r) __raw_readl(r) |
Jason Jin | c74c436 | 2011-08-25 15:46:43 +0800 | [diff] [blame] | 104 | #endif |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 105 | |
Marek Vasut | 52006d2 | 2022-04-13 04:15:27 +0200 | [diff] [blame] | 106 | #ifdef DEBUG |
| 107 | static void dm9000_dump_packet(const char *func, u8 *packet, int length) |
| 108 | { |
| 109 | int i; |
| 110 | |
| 111 | printf("%s: length: %d\n", func, length); |
| 112 | |
| 113 | for (i = 0; i < length; i++) { |
| 114 | if (i % 8 == 0) |
| 115 | printf("\n%s: %02x: ", func, i); |
| 116 | printf("%02x ", packet[i]); |
| 117 | } |
| 118 | |
| 119 | printf("\n"); |
| 120 | } |
| 121 | #else |
| 122 | static void dm9000_dump_packet(const char *func, u8 *packet, int length) {} |
| 123 | #endif |
| 124 | |
Marek Vasut | 7823b23 | 2022-04-13 04:15:28 +0200 | [diff] [blame] | 125 | static void dm9000_outblk_8bit(void *data_ptr, int count) |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 126 | { |
| 127 | int i; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 128 | |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 129 | for (i = 0; i < count; i++) |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 130 | dm9000_outb((((u8 *)data_ptr)[i] & 0xff), DM9000_DATA); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Marek Vasut | 7823b23 | 2022-04-13 04:15:28 +0200 | [diff] [blame] | 133 | static void dm9000_outblk_16bit(void *data_ptr, int count) |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 134 | { |
| 135 | int i; |
| 136 | u32 tmplen = (count + 1) / 2; |
| 137 | |
| 138 | for (i = 0; i < tmplen; i++) |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 139 | dm9000_outw(((u16 *)data_ptr)[i], DM9000_DATA); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 140 | } |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 141 | |
Marek Vasut | 7823b23 | 2022-04-13 04:15:28 +0200 | [diff] [blame] | 142 | static void dm9000_outblk_32bit(void *data_ptr, int count) |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 143 | { |
| 144 | int i; |
| 145 | u32 tmplen = (count + 3) / 4; |
| 146 | |
| 147 | for (i = 0; i < tmplen; i++) |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 148 | dm9000_outl(((u32 *)data_ptr)[i], DM9000_DATA); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void dm9000_inblk_8bit(void *data_ptr, int count) |
| 152 | { |
| 153 | int i; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 154 | |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 155 | for (i = 0; i < count; i++) |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 156 | ((u8 *)data_ptr)[i] = dm9000_inb(DM9000_DATA); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void dm9000_inblk_16bit(void *data_ptr, int count) |
| 160 | { |
| 161 | int i; |
| 162 | u32 tmplen = (count + 1) / 2; |
| 163 | |
| 164 | for (i = 0; i < tmplen; i++) |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 165 | ((u16 *)data_ptr)[i] = dm9000_inw(DM9000_DATA); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 166 | } |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 167 | |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 168 | static void dm9000_inblk_32bit(void *data_ptr, int count) |
| 169 | { |
| 170 | int i; |
| 171 | u32 tmplen = (count + 3) / 4; |
| 172 | |
| 173 | for (i = 0; i < tmplen; i++) |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 174 | ((u32 *)data_ptr)[i] = dm9000_inl(DM9000_DATA); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 177 | static void dm9000_rx_status_32bit(u16 *rxstatus, u16 *rxlen) |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 178 | { |
Remy Bohmer | 2e1604f | 2008-06-04 10:47:25 +0200 | [diff] [blame] | 179 | u32 tmpdata; |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 180 | |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 181 | dm9000_outb(DM9000_MRCMD, DM9000_IO); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 182 | |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 183 | tmpdata = dm9000_inl(DM9000_DATA); |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 184 | *rxstatus = __le16_to_cpu(tmpdata); |
| 185 | *rxlen = __le16_to_cpu(tmpdata >> 16); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 188 | static void dm9000_rx_status_16bit(u16 *rxstatus, u16 *rxlen) |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 189 | { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 190 | dm9000_outb(DM9000_MRCMD, DM9000_IO); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 191 | |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 192 | *rxstatus = __le16_to_cpu(dm9000_inw(DM9000_DATA)); |
| 193 | *rxlen = __le16_to_cpu(dm9000_inw(DM9000_DATA)); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 196 | static void dm9000_rx_status_8bit(u16 *rxstatus, u16 *rxlen) |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 197 | { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 198 | dm9000_outb(DM9000_MRCMD, DM9000_IO); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 199 | |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 200 | *rxstatus = |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 201 | __le16_to_cpu(dm9000_inb(DM9000_DATA) + |
| 202 | (dm9000_inb(DM9000_DATA) << 8)); |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 203 | *rxlen = |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 204 | __le16_to_cpu(dm9000_inb(DM9000_DATA) + |
| 205 | (dm9000_inb(DM9000_DATA) << 8)); |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 206 | } |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 207 | |
| 208 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 209 | * Search DM9000 board, allocate space and register it |
| 210 | */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 211 | int |
| 212 | dm9000_probe(void) |
| 213 | { |
| 214 | u32 id_val; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 215 | |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 216 | id_val = dm9000_ior(DM9000_VIDL); |
| 217 | id_val |= dm9000_ior(DM9000_VIDH) << 8; |
| 218 | id_val |= dm9000_ior(DM9000_PIDL) << 16; |
| 219 | id_val |= dm9000_ior(DM9000_PIDH) << 24; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 220 | if (id_val != DM9000_ID) { |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 221 | printf("dm9000 not found at 0x%08x id: 0x%08x\n", |
| 222 | CONFIG_DM9000_BASE, id_val); |
| 223 | return -1; |
| 224 | } |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 225 | |
| 226 | printf("dm9000 i/o: 0x%x, id: 0x%x\n", CONFIG_DM9000_BASE, id_val); |
| 227 | return 0; |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* General Purpose dm9000 reset routine */ |
| 231 | static void |
| 232 | dm9000_reset(void) |
| 233 | { |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 234 | debug("resetting DM9000\n"); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 235 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 236 | /* |
| 237 | * Reset DM9000, |
| 238 | * see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 |
| 239 | */ |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 240 | |
Andrew Dyer | a62f5d4 | 2008-08-26 17:03:38 -0500 | [diff] [blame] | 241 | /* DEBUG: Make all GPIO0 outputs, all others inputs */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 242 | dm9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 243 | /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 244 | dm9000_iow(DM9000_GPR, 0); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 245 | /* Step 2: Software reset */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 246 | dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 247 | |
| 248 | do { |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 249 | debug("resetting the DM9000, 1st reset\n"); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 250 | udelay(25); /* Wait at least 20 us */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 251 | } while (dm9000_ior(DM9000_NCR) & 1); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 252 | |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 253 | dm9000_iow(DM9000_NCR, 0); |
| 254 | dm9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 255 | |
| 256 | do { |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 257 | debug("resetting the DM9000, 2nd reset\n"); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 258 | udelay(25); /* Wait at least 20 us */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 259 | } while (dm9000_ior(DM9000_NCR) & 1); |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 260 | |
| 261 | /* Check whether the ethernet controller is present */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 262 | if ((dm9000_ior(DM9000_PIDL) != 0x0) || |
| 263 | (dm9000_ior(DM9000_PIDH) != 0x90)) |
Remy Bohmer | 2f13d2c | 2008-06-03 15:26:24 +0200 | [diff] [blame] | 264 | printf("ERROR: resetting DM9000 -> not responding\n"); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 267 | /* Initialize dm9000 board */ |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 268 | static int dm9000_init(struct eth_device *dev, struct bd_info *bd) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 269 | { |
| 270 | int i, oft, lnk; |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 271 | u8 io_mode; |
| 272 | struct board_info *db = &dm9000_info; |
| 273 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 274 | /* RESET device */ |
| 275 | dm9000_reset(); |
Andrew Dyer | a62f5d4 | 2008-08-26 17:03:38 -0500 | [diff] [blame] | 276 | |
| 277 | if (dm9000_probe() < 0) |
| 278 | return -1; |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 279 | |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 280 | /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 281 | io_mode = dm9000_ior(DM9000_ISR) >> 6; |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 282 | |
| 283 | switch (io_mode) { |
| 284 | case 0x0: /* 16-bit mode */ |
| 285 | printf("DM9000: running in 16 bit mode\n"); |
| 286 | db->outblk = dm9000_outblk_16bit; |
| 287 | db->inblk = dm9000_inblk_16bit; |
| 288 | db->rx_status = dm9000_rx_status_16bit; |
| 289 | break; |
| 290 | case 0x01: /* 32-bit mode */ |
| 291 | printf("DM9000: running in 32 bit mode\n"); |
| 292 | db->outblk = dm9000_outblk_32bit; |
| 293 | db->inblk = dm9000_inblk_32bit; |
| 294 | db->rx_status = dm9000_rx_status_32bit; |
| 295 | break; |
| 296 | case 0x02: /* 8 bit mode */ |
| 297 | printf("DM9000: running in 8 bit mode\n"); |
| 298 | db->outblk = dm9000_outblk_8bit; |
| 299 | db->inblk = dm9000_inblk_8bit; |
| 300 | db->rx_status = dm9000_rx_status_8bit; |
| 301 | break; |
| 302 | default: |
| 303 | /* Assume 8 bit mode, will probably not work anyway */ |
| 304 | printf("DM9000: Undefined IO-mode:0x%x\n", io_mode); |
| 305 | db->outblk = dm9000_outblk_8bit; |
| 306 | db->inblk = dm9000_inblk_8bit; |
| 307 | db->rx_status = dm9000_rx_status_8bit; |
| 308 | break; |
| 309 | } |
| 310 | |
Andrew Dyer | a62f5d4 | 2008-08-26 17:03:38 -0500 | [diff] [blame] | 311 | /* Program operating register, only internal phy supported */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 312 | dm9000_iow(DM9000_NCR, 0x0); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 313 | /* TX Polling clear */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 314 | dm9000_iow(DM9000_TCR, 0); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 315 | /* Less 3Kb, 200us */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 316 | dm9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 317 | /* Flow Control : High/Low Water */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 318 | dm9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 319 | /* SH FIXME: This looks strange! Flow Control */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 320 | dm9000_iow(DM9000_FCR, 0x0); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 321 | /* Special Mode */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 322 | dm9000_iow(DM9000_SMCR, 0); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 323 | /* clear TX status */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 324 | dm9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 325 | /* Clear interrupt status */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 326 | dm9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 327 | |
Ben Warren | 8707f62 | 2009-10-21 21:53:39 -0700 | [diff] [blame] | 328 | printf("MAC: %pM\n", dev->enetaddr); |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 329 | if (!is_valid_ethaddr(dev->enetaddr)) |
Andrew Ruder | 1c377d1 | 2013-10-22 19:09:02 -0500 | [diff] [blame] | 330 | printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n"); |
Andrew Dyer | a62f5d4 | 2008-08-26 17:03:38 -0500 | [diff] [blame] | 331 | |
| 332 | /* fill device MAC address registers */ |
| 333 | for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 334 | dm9000_iow(oft, dev->enetaddr[i]); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 335 | for (i = 0, oft = 0x16; i < 8; i++, oft++) |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 336 | dm9000_iow(oft, 0xff); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 337 | |
| 338 | /* read back mac, just to be sure */ |
| 339 | for (i = 0, oft = 0x10; i < 6; i++, oft++) |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 340 | debug("%02x:", dm9000_ior(oft)); |
| 341 | debug("\n"); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 342 | |
| 343 | /* Activate DM9000 */ |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 344 | /* RX enable */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 345 | dm9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 346 | /* Enable TX/RX interrupt mask */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 347 | dm9000_iow(DM9000_IMR, IMR_PAR); |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 348 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 349 | i = 0; |
Andy Fleming | 0d2df96 | 2011-03-22 22:49:13 -0500 | [diff] [blame] | 350 | while (!(dm9000_phy_read(1) & 0x20)) { /* autonegation complete bit */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 351 | udelay(1000); |
| 352 | i++; |
| 353 | if (i == 10000) { |
| 354 | printf("could not establish link\n"); |
| 355 | return 0; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /* see what we've got */ |
Andy Fleming | 0d2df96 | 2011-03-22 22:49:13 -0500 | [diff] [blame] | 360 | lnk = dm9000_phy_read(17) >> 12; |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 361 | printf("operating at "); |
| 362 | switch (lnk) { |
| 363 | case 1: |
| 364 | printf("10M half duplex "); |
| 365 | break; |
| 366 | case 2: |
| 367 | printf("10M full duplex "); |
| 368 | break; |
| 369 | case 4: |
| 370 | printf("100M half duplex "); |
| 371 | break; |
| 372 | case 8: |
| 373 | printf("100M full duplex "); |
| 374 | break; |
| 375 | default: |
| 376 | printf("unknown: %d ", lnk); |
| 377 | break; |
| 378 | } |
| 379 | printf("mode\n"); |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 384 | * Hardware start transmission. |
| 385 | * Send a packet to media from the upper layer. |
| 386 | */ |
Joe Hershberger | ab1ac41 | 2012-05-21 14:45:23 +0000 | [diff] [blame] | 387 | static int dm9000_send(struct eth_device *netdev, void *packet, int length) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 388 | { |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 389 | int tmo; |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 390 | struct board_info *db = &dm9000_info; |
| 391 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 392 | dm9000_dump_packet(__func__, packet, length); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 393 | |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 394 | dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ |
Remy Bohmer | 16cb264 | 2008-06-03 15:26:23 +0200 | [diff] [blame] | 395 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 396 | /* Move data to DM9000 TX RAM */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 397 | dm9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 398 | |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 399 | /* push the data to the TX-fifo */ |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 400 | db->outblk(packet, length); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 401 | |
| 402 | /* Set TX length to DM9000 */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 403 | dm9000_iow(DM9000_TXPLL, length & 0xff); |
| 404 | dm9000_iow(DM9000_TXPLH, (length >> 8) & 0xff); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 405 | |
| 406 | /* Issue TX polling command */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 407 | dm9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 408 | |
| 409 | /* wait for end of transmission */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 410 | tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 411 | while (!(dm9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || |
| 412 | !(dm9000_ior(DM9000_ISR) & IMR_PTM)) { |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 413 | if (get_timer(0) >= tmo) { |
| 414 | printf("transmission timeout\n"); |
| 415 | break; |
| 416 | } |
| 417 | } |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 418 | dm9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ |
Remy Bohmer | 16cb264 | 2008-06-03 15:26:23 +0200 | [diff] [blame] | 419 | |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 420 | debug("transmit done\n\n"); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 425 | * Stop the interface. |
| 426 | * The interface is stopped when it is brought. |
| 427 | */ |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 428 | static void dm9000_halt(struct eth_device *netdev) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 429 | { |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 430 | /* RESET device */ |
Andy Fleming | 0d2df96 | 2011-03-22 22:49:13 -0500 | [diff] [blame] | 431 | dm9000_phy_write(0, 0x8000); /* PHY RESET */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 432 | dm9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */ |
| 433 | dm9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */ |
| 434 | dm9000_iow(DM9000_RCR, 0x00); /* Disable RX */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 438 | * Received a packet and pass to upper layer |
| 439 | */ |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 440 | static int dm9000_rx(struct eth_device *netdev) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 441 | { |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 442 | u8 rxbyte; |
| 443 | u8 *rdptr = (u8 *)net_rx_packets[0]; |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 444 | u16 rxstatus, rxlen = 0; |
Remy Bohmer | 5f63bf4 | 2008-06-03 15:26:21 +0200 | [diff] [blame] | 445 | struct board_info *db = &dm9000_info; |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 446 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 447 | /* |
| 448 | * Check packet ready or not, we must check |
| 449 | * the ISR status first for DM9000A |
| 450 | */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 451 | if (!(dm9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 452 | return 0; |
| 453 | |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 454 | dm9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 455 | |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 456 | /* There is _at least_ 1 package in the fifo, read them all */ |
| 457 | for (;;) { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 458 | dm9000_ior(DM9000_MRCMDX); /* Dummy read */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 459 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 460 | /* |
| 461 | * Get most updated data, |
| 462 | * only look at bits 0:1, See application notes DM9000 |
| 463 | */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 464 | rxbyte = dm9000_inb(DM9000_DATA) & 0x03; |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 465 | |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 466 | /* Status check: this byte must be 0 or 1 */ |
| 467 | if (rxbyte > DM9000_PKT_RDY) { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 468 | dm9000_iow(DM9000_RCR, 0x00); /* Stop Device */ |
| 469 | dm9000_iow(DM9000_ISR, 0x80); /* Stop INT request */ |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 470 | printf("DM9000 error: status check fail: 0x%x\n", |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 471 | rxbyte); |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 472 | return 0; |
| 473 | } |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 474 | |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 475 | if (rxbyte != DM9000_PKT_RDY) |
| 476 | return 0; /* No packet received, ignore */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 477 | |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 478 | debug("receiving packet\n"); |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 479 | |
| 480 | /* A packet ready now & Get status/length */ |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 481 | db->rx_status(&rxstatus, &rxlen); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 482 | |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 483 | debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 484 | |
| 485 | /* Move data from DM9000 */ |
| 486 | /* Read received packet from RX SRAM */ |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 487 | db->inblk(rdptr, rxlen); |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 488 | |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 489 | if (rxstatus & 0xbf00 || rxlen < 0x40 || |
| 490 | rxlen > DM9000_PKT_MAX) { |
| 491 | if (rxstatus & 0x100) |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 492 | printf("rx fifo error\n"); |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 493 | if (rxstatus & 0x200) |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 494 | printf("rx crc error\n"); |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 495 | if (rxstatus & 0x8000) |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 496 | printf("rx length error\n"); |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 497 | if (rxlen > DM9000_PKT_MAX) { |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 498 | printf("rx length too big\n"); |
| 499 | dm9000_reset(); |
| 500 | } |
| 501 | } else { |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 502 | dm9000_dump_packet(__func__, rdptr, rxlen); |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 503 | |
Marek Vasut | ed76122 | 2022-04-13 04:15:24 +0200 | [diff] [blame] | 504 | debug("passing packet to upper layer\n"); |
Marek Vasut | 5248e56 | 2022-04-13 04:15:25 +0200 | [diff] [blame] | 505 | net_process_received_packet(net_rx_packets[0], rxlen); |
Remy Bohmer | eec38a1 | 2008-06-03 15:26:25 +0200 | [diff] [blame] | 506 | } |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 507 | } |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 512 | * Read a word data from SROM |
| 513 | */ |
Remy Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 514 | #if !defined(CONFIG_DM9000_NO_SROM) |
| 515 | void dm9000_read_srom_word(int offset, u8 *to) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 516 | { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 517 | dm9000_iow(DM9000_EPAR, offset); |
| 518 | dm9000_iow(DM9000_EPCR, 0x4); |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 519 | mdelay(8); |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 520 | dm9000_iow(DM9000_EPCR, 0x0); |
| 521 | to[0] = dm9000_ior(DM9000_EPDRL); |
| 522 | to[1] = dm9000_ior(DM9000_EPDRH); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 523 | } |
| 524 | |
Remy Bohmer | cd9a36c | 2009-05-03 12:11:40 +0200 | [diff] [blame] | 525 | void dm9000_write_srom_word(int offset, u16 val) |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 526 | { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 527 | dm9000_iow(DM9000_EPAR, offset); |
| 528 | dm9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff)); |
| 529 | dm9000_iow(DM9000_EPDRL, (val & 0xff)); |
| 530 | dm9000_iow(DM9000_EPCR, 0x12); |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 531 | mdelay(8); |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 532 | dm9000_iow(DM9000_EPCR, 0); |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 533 | } |
Ben Warren | 8707f62 | 2009-10-21 21:53:39 -0700 | [diff] [blame] | 534 | |
| 535 | static void dm9000_get_enetaddr(struct eth_device *dev) |
| 536 | { |
Ben Warren | 8707f62 | 2009-10-21 21:53:39 -0700 | [diff] [blame] | 537 | int i; |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 538 | |
Ben Warren | 8707f62 | 2009-10-21 21:53:39 -0700 | [diff] [blame] | 539 | for (i = 0; i < 3; i++) |
| 540 | dm9000_read_srom_word(i, dev->enetaddr + (2 * i)); |
Ben Warren | 8707f62 | 2009-10-21 21:53:39 -0700 | [diff] [blame] | 541 | } |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 542 | #else |
| 543 | static void dm9000_get_enetaddr(struct eth_device *dev) {} |
| 544 | #endif |
stefano babic | 6708a60 | 2007-08-30 23:01:49 +0200 | [diff] [blame] | 545 | |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 546 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 547 | * Read a byte from I/O port |
| 548 | */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 549 | static u8 |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 550 | dm9000_ior(int reg) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 551 | { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 552 | dm9000_outb(reg, DM9000_IO); |
| 553 | return dm9000_inb(DM9000_DATA); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 557 | * Write a byte to I/O port |
| 558 | */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 559 | static void |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 560 | dm9000_iow(int reg, u8 value) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 561 | { |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 562 | dm9000_outb(reg, DM9000_IO); |
| 563 | dm9000_outb(value, DM9000_DATA); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 567 | * Read a word from phyxcer |
| 568 | */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 569 | static u16 |
Andy Fleming | 0d2df96 | 2011-03-22 22:49:13 -0500 | [diff] [blame] | 570 | dm9000_phy_read(int reg) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 571 | { |
| 572 | u16 val; |
| 573 | |
| 574 | /* Fill the phyxcer register into REG_0C */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 575 | dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); |
| 576 | dm9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 577 | udelay(100); /* Wait read complete */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 578 | dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ |
| 579 | val = (dm9000_ior(DM9000_EPDRH) << 8) | dm9000_ior(DM9000_EPDRL); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 580 | |
| 581 | /* The read data keeps on REG_0D & REG_0E */ |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 582 | debug("%s(0x%x): 0x%x\n", __func__, reg, val); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 583 | return val; |
| 584 | } |
| 585 | |
| 586 | /* |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 587 | * Write a word to phyxcer |
| 588 | */ |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 589 | static void |
Andy Fleming | 0d2df96 | 2011-03-22 22:49:13 -0500 | [diff] [blame] | 590 | dm9000_phy_write(int reg, u16 value) |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 591 | { |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 592 | /* Fill the phyxcer register into REG_0C */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 593 | dm9000_iow(DM9000_EPAR, DM9000_PHY | reg); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 594 | |
| 595 | /* Fill the written data into REG_0D & REG_0E */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 596 | dm9000_iow(DM9000_EPDRL, (value & 0xff)); |
| 597 | dm9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); |
| 598 | dm9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ |
Remy Bohmer | 61b8dbd | 2008-06-03 15:26:26 +0200 | [diff] [blame] | 599 | udelay(500); /* Wait write complete */ |
Marek Vasut | eb2749a | 2022-04-13 04:15:23 +0200 | [diff] [blame] | 600 | dm9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 601 | debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value); |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 602 | } |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 603 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 604 | int dm9000_initialize(struct bd_info *bis) |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 605 | { |
Marek Vasut | a4aa048 | 2022-04-13 04:15:29 +0200 | [diff] [blame^] | 606 | struct eth_device *dev = &dm9000_info.netdev; |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 607 | |
Ben Warren | 8707f62 | 2009-10-21 21:53:39 -0700 | [diff] [blame] | 608 | /* Load MAC address from EEPROM */ |
| 609 | dm9000_get_enetaddr(dev); |
| 610 | |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 611 | dev->init = dm9000_init; |
| 612 | dev->halt = dm9000_halt; |
| 613 | dev->send = dm9000_send; |
| 614 | dev->recv = dm9000_rx; |
Ben Whitten | 34fd6c9 | 2015-12-30 13:05:58 +0000 | [diff] [blame] | 615 | strcpy(dev->name, "dm9000"); |
Remy Bohmer | 7eefd92 | 2009-05-02 21:49:18 +0200 | [diff] [blame] | 616 | |
| 617 | eth_register(dev); |
| 618 | |
| 619 | return 0; |
| 620 | } |