dm9000x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. dm9000.c: Version 1.2 12/15/2003
  3. A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
  4. Copyright (C) 1997 Sten Wang
  5. * SPDX-License-Identifier: GPL-2.0+
  6. (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
  7. V0.11 06/20/2001 REG_0A bit3=1, default enable BP with DA match
  8. 06/22/2001 Support DM9801 progrmming
  9. E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
  10. E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
  11. R17 = (R17 & 0xfff0) | NF + 3
  12. E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
  13. R17 = (R17 & 0xfff0) | NF
  14. v1.00 modify by simon 2001.9.5
  15. change for kernel 2.4.x
  16. v1.1 11/09/2001 fix force mode bug
  17. v1.2 03/18/2003 Weilun Huang <weilun_huang@davicom.com.tw>:
  18. Fixed phy reset.
  19. Added tx/rx 32 bit mode.
  20. Cleaned up for kernel merge.
  21. --------------------------------------
  22. 12/15/2003 Initial port to u-boot by
  23. Sascha Hauer <saschahauer@web.de>
  24. 06/03/2008 Remy Bohmer <linux@bohmer.net>
  25. - Fixed the driver to work with DM9000A.
  26. (check on ISR receive status bit before reading the
  27. FIFO as described in DM9000 programming guide and
  28. application notes)
  29. - Added autodetect of databus width.
  30. - Made debug code compile again.
  31. - Adapt eth_send such that it matches the DM9000*
  32. application notes. Needed to make it work properly
  33. for DM9000A.
  34. - Adapted reset procedure to match DM9000 application
  35. notes (i.e. double reset)
  36. - some minor code cleanups
  37. These changes are tested with DM9000{A,EP,E} together
  38. with a 200MHz Atmel AT91SAM9261 core
  39. TODO: external MII is not functional, only internal at the moment.
  40. */
  41. #include <common.h>
  42. #include <command.h>
  43. #include <net.h>
  44. #include <asm/io.h>
  45. #include <dm9000.h>
  46. #include "dm9000x.h"
  47. /* Board/System/Debug information/definition ---------------- */
  48. /* #define CONFIG_DM9000_DEBUG */
  49. #ifdef CONFIG_DM9000_DEBUG
  50. #define DM9000_DBG(fmt,args...) printf(fmt, ##args)
  51. #define DM9000_DMP_PACKET(func,packet,length) \
  52. do { \
  53. int i; \
  54. printf("%s: length: %d\n", func, length); \
  55. for (i = 0; i < length; i++) { \
  56. if (i % 8 == 0) \
  57. printf("\n%s: %02x: ", func, i); \
  58. printf("%02x ", ((unsigned char *) packet)[i]); \
  59. } printf("\n"); \
  60. } while(0)
  61. #else
  62. #define DM9000_DBG(fmt,args...)
  63. #define DM9000_DMP_PACKET(func,packet,length)
  64. #endif
  65. /* Structure/enum declaration ------------------------------- */
  66. typedef struct board_info {
  67. u32 runt_length_counter; /* counter: RX length < 64byte */
  68. u32 long_length_counter; /* counter: RX length > 1514byte */
  69. u32 reset_counter; /* counter: RESET */
  70. u32 reset_tx_timeout; /* RESET caused by TX Timeout */
  71. u32 reset_rx_status; /* RESET caused by RX Statsus wrong */
  72. u16 tx_pkt_cnt;
  73. u16 queue_start_addr;
  74. u16 dbug_cnt;
  75. u8 phy_addr;
  76. u8 device_wait_reset; /* device state */
  77. unsigned char srom[128];
  78. void (*outblk)(volatile void *data_ptr, int count);
  79. void (*inblk)(void *data_ptr, int count);
  80. void (*rx_status)(u16 *RxStatus, u16 *RxLen);
  81. struct eth_device netdev;
  82. } board_info_t;
  83. static board_info_t dm9000_info;
  84. /* function declaration ------------------------------------- */
  85. static int dm9000_probe(void);
  86. static u16 dm9000_phy_read(int);
  87. static void dm9000_phy_write(int, u16);
  88. static u8 DM9000_ior(int);
  89. static void DM9000_iow(int reg, u8 value);
  90. /* DM9000 network board routine ---------------------------- */
  91. #ifndef CONFIG_DM9000_BYTE_SWAPPED
  92. #define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r))
  93. #define DM9000_outw(d,r) writew(d, (volatile u16 *)(r))
  94. #define DM9000_outl(d,r) writel(d, (volatile u32 *)(r))
  95. #define DM9000_inb(r) readb((volatile u8 *)(r))
  96. #define DM9000_inw(r) readw((volatile u16 *)(r))
  97. #define DM9000_inl(r) readl((volatile u32 *)(r))
  98. #else
  99. #define DM9000_outb(d, r) __raw_writeb(d, r)
  100. #define DM9000_outw(d, r) __raw_writew(d, r)
  101. #define DM9000_outl(d, r) __raw_writel(d, r)
  102. #define DM9000_inb(r) __raw_readb(r)
  103. #define DM9000_inw(r) __raw_readw(r)
  104. #define DM9000_inl(r) __raw_readl(r)
  105. #endif
  106. #ifdef CONFIG_DM9000_DEBUG
  107. static void
  108. dump_regs(void)
  109. {
  110. DM9000_DBG("\n");
  111. DM9000_DBG("NCR (0x00): %02x\n", DM9000_ior(0));
  112. DM9000_DBG("NSR (0x01): %02x\n", DM9000_ior(1));
  113. DM9000_DBG("TCR (0x02): %02x\n", DM9000_ior(2));
  114. DM9000_DBG("TSRI (0x03): %02x\n", DM9000_ior(3));
  115. DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4));
  116. DM9000_DBG("RCR (0x05): %02x\n", DM9000_ior(5));
  117. DM9000_DBG("RSR (0x06): %02x\n", DM9000_ior(6));
  118. DM9000_DBG("ISR (0xFE): %02x\n", DM9000_ior(DM9000_ISR));
  119. DM9000_DBG("\n");
  120. }
  121. #endif
  122. static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
  123. {
  124. int i;
  125. for (i = 0; i < count; i++)
  126. DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
  127. }
  128. static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
  129. {
  130. int i;
  131. u32 tmplen = (count + 1) / 2;
  132. for (i = 0; i < tmplen; i++)
  133. DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
  134. }
  135. static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
  136. {
  137. int i;
  138. u32 tmplen = (count + 3) / 4;
  139. for (i = 0; i < tmplen; i++)
  140. DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
  141. }
  142. static void dm9000_inblk_8bit(void *data_ptr, int count)
  143. {
  144. int i;
  145. for (i = 0; i < count; i++)
  146. ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA);
  147. }
  148. static void dm9000_inblk_16bit(void *data_ptr, int count)
  149. {
  150. int i;
  151. u32 tmplen = (count + 1) / 2;
  152. for (i = 0; i < tmplen; i++)
  153. ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA);
  154. }
  155. static void dm9000_inblk_32bit(void *data_ptr, int count)
  156. {
  157. int i;
  158. u32 tmplen = (count + 3) / 4;
  159. for (i = 0; i < tmplen; i++)
  160. ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA);
  161. }
  162. static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
  163. {
  164. u32 tmpdata;
  165. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  166. tmpdata = DM9000_inl(DM9000_DATA);
  167. *RxStatus = __le16_to_cpu(tmpdata);
  168. *RxLen = __le16_to_cpu(tmpdata >> 16);
  169. }
  170. static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
  171. {
  172. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  173. *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA));
  174. *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA));
  175. }
  176. static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
  177. {
  178. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  179. *RxStatus =
  180. __le16_to_cpu(DM9000_inb(DM9000_DATA) +
  181. (DM9000_inb(DM9000_DATA) << 8));
  182. *RxLen =
  183. __le16_to_cpu(DM9000_inb(DM9000_DATA) +
  184. (DM9000_inb(DM9000_DATA) << 8));
  185. }
  186. /*
  187. Search DM9000 board, allocate space and register it
  188. */
  189. int
  190. dm9000_probe(void)
  191. {
  192. u32 id_val;
  193. id_val = DM9000_ior(DM9000_VIDL);
  194. id_val |= DM9000_ior(DM9000_VIDH) << 8;
  195. id_val |= DM9000_ior(DM9000_PIDL) << 16;
  196. id_val |= DM9000_ior(DM9000_PIDH) << 24;
  197. if (id_val == DM9000_ID) {
  198. printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
  199. id_val);
  200. return 0;
  201. } else {
  202. printf("dm9000 not found at 0x%08x id: 0x%08x\n",
  203. CONFIG_DM9000_BASE, id_val);
  204. return -1;
  205. }
  206. }
  207. /* General Purpose dm9000 reset routine */
  208. static void
  209. dm9000_reset(void)
  210. {
  211. DM9000_DBG("resetting DM9000\n");
  212. /* Reset DM9000,
  213. see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
  214. /* DEBUG: Make all GPIO0 outputs, all others inputs */
  215. DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
  216. /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
  217. DM9000_iow(DM9000_GPR, 0);
  218. /* Step 2: Software reset */
  219. DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
  220. do {
  221. DM9000_DBG("resetting the DM9000, 1st reset\n");
  222. udelay(25); /* Wait at least 20 us */
  223. } while (DM9000_ior(DM9000_NCR) & 1);
  224. DM9000_iow(DM9000_NCR, 0);
  225. DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
  226. do {
  227. DM9000_DBG("resetting the DM9000, 2nd reset\n");
  228. udelay(25); /* Wait at least 20 us */
  229. } while (DM9000_ior(DM9000_NCR) & 1);
  230. /* Check whether the ethernet controller is present */
  231. if ((DM9000_ior(DM9000_PIDL) != 0x0) ||
  232. (DM9000_ior(DM9000_PIDH) != 0x90))
  233. printf("ERROR: resetting DM9000 -> not responding\n");
  234. }
  235. /* Initialize dm9000 board
  236. */
  237. static int dm9000_init(struct eth_device *dev, bd_t *bd)
  238. {
  239. int i, oft, lnk;
  240. u8 io_mode;
  241. struct board_info *db = &dm9000_info;
  242. DM9000_DBG("%s\n", __func__);
  243. /* RESET device */
  244. dm9000_reset();
  245. if (dm9000_probe() < 0)
  246. return -1;
  247. /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
  248. io_mode = DM9000_ior(DM9000_ISR) >> 6;
  249. switch (io_mode) {
  250. case 0x0: /* 16-bit mode */
  251. printf("DM9000: running in 16 bit mode\n");
  252. db->outblk = dm9000_outblk_16bit;
  253. db->inblk = dm9000_inblk_16bit;
  254. db->rx_status = dm9000_rx_status_16bit;
  255. break;
  256. case 0x01: /* 32-bit mode */
  257. printf("DM9000: running in 32 bit mode\n");
  258. db->outblk = dm9000_outblk_32bit;
  259. db->inblk = dm9000_inblk_32bit;
  260. db->rx_status = dm9000_rx_status_32bit;
  261. break;
  262. case 0x02: /* 8 bit mode */
  263. printf("DM9000: running in 8 bit mode\n");
  264. db->outblk = dm9000_outblk_8bit;
  265. db->inblk = dm9000_inblk_8bit;
  266. db->rx_status = dm9000_rx_status_8bit;
  267. break;
  268. default:
  269. /* Assume 8 bit mode, will probably not work anyway */
  270. printf("DM9000: Undefined IO-mode:0x%x\n", io_mode);
  271. db->outblk = dm9000_outblk_8bit;
  272. db->inblk = dm9000_inblk_8bit;
  273. db->rx_status = dm9000_rx_status_8bit;
  274. break;
  275. }
  276. /* Program operating register, only internal phy supported */
  277. DM9000_iow(DM9000_NCR, 0x0);
  278. /* TX Polling clear */
  279. DM9000_iow(DM9000_TCR, 0);
  280. /* Less 3Kb, 200us */
  281. DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
  282. /* Flow Control : High/Low Water */
  283. DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
  284. /* SH FIXME: This looks strange! Flow Control */
  285. DM9000_iow(DM9000_FCR, 0x0);
  286. /* Special Mode */
  287. DM9000_iow(DM9000_SMCR, 0);
  288. /* clear TX status */
  289. DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
  290. /* Clear interrupt status */
  291. DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
  292. printf("MAC: %pM\n", dev->enetaddr);
  293. /* fill device MAC address registers */
  294. for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
  295. DM9000_iow(oft, dev->enetaddr[i]);
  296. for (i = 0, oft = 0x16; i < 8; i++, oft++)
  297. DM9000_iow(oft, 0xff);
  298. /* read back mac, just to be sure */
  299. for (i = 0, oft = 0x10; i < 6; i++, oft++)
  300. DM9000_DBG("%02x:", DM9000_ior(oft));
  301. DM9000_DBG("\n");
  302. /* Activate DM9000 */
  303. /* RX enable */
  304. DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
  305. /* Enable TX/RX interrupt mask */
  306. DM9000_iow(DM9000_IMR, IMR_PAR);
  307. i = 0;
  308. while (!(dm9000_phy_read(1) & 0x20)) { /* autonegation complete bit */
  309. udelay(1000);
  310. i++;
  311. if (i == 10000) {
  312. printf("could not establish link\n");
  313. return 0;
  314. }
  315. }
  316. /* see what we've got */
  317. lnk = dm9000_phy_read(17) >> 12;
  318. printf("operating at ");
  319. switch (lnk) {
  320. case 1:
  321. printf("10M half duplex ");
  322. break;
  323. case 2:
  324. printf("10M full duplex ");
  325. break;
  326. case 4:
  327. printf("100M half duplex ");
  328. break;
  329. case 8:
  330. printf("100M full duplex ");
  331. break;
  332. default:
  333. printf("unknown: %d ", lnk);
  334. break;
  335. }
  336. printf("mode\n");
  337. return 0;
  338. }
  339. /*
  340. Hardware start transmission.
  341. Send a packet to media from the upper layer.
  342. */
  343. static int dm9000_send(struct eth_device *netdev, void *packet, int length)
  344. {
  345. int tmo;
  346. struct board_info *db = &dm9000_info;
  347. DM9000_DMP_PACKET(__func__ , packet, length);
  348. DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
  349. /* Move data to DM9000 TX RAM */
  350. DM9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
  351. /* push the data to the TX-fifo */
  352. (db->outblk)(packet, length);
  353. /* Set TX length to DM9000 */
  354. DM9000_iow(DM9000_TXPLL, length & 0xff);
  355. DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
  356. /* Issue TX polling command */
  357. DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
  358. /* wait for end of transmission */
  359. tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
  360. while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
  361. !(DM9000_ior(DM9000_ISR) & IMR_PTM) ) {
  362. if (get_timer(0) >= tmo) {
  363. printf("transmission timeout\n");
  364. break;
  365. }
  366. }
  367. DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
  368. DM9000_DBG("transmit done\n\n");
  369. return 0;
  370. }
  371. /*
  372. Stop the interface.
  373. The interface is stopped when it is brought.
  374. */
  375. static void dm9000_halt(struct eth_device *netdev)
  376. {
  377. DM9000_DBG("%s\n", __func__);
  378. /* RESET devie */
  379. dm9000_phy_write(0, 0x8000); /* PHY RESET */
  380. DM9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */
  381. DM9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */
  382. DM9000_iow(DM9000_RCR, 0x00); /* Disable RX */
  383. }
  384. /*
  385. Received a packet and pass to upper layer
  386. */
  387. static int dm9000_rx(struct eth_device *netdev)
  388. {
  389. u8 rxbyte, *rdptr = (u8 *) NetRxPackets[0];
  390. u16 RxStatus, RxLen = 0;
  391. struct board_info *db = &dm9000_info;
  392. /* Check packet ready or not, we must check
  393. the ISR status first for DM9000A */
  394. if (!(DM9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
  395. return 0;
  396. DM9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
  397. /* There is _at least_ 1 package in the fifo, read them all */
  398. for (;;) {
  399. DM9000_ior(DM9000_MRCMDX); /* Dummy read */
  400. /* Get most updated data,
  401. only look at bits 0:1, See application notes DM9000 */
  402. rxbyte = DM9000_inb(DM9000_DATA) & 0x03;
  403. /* Status check: this byte must be 0 or 1 */
  404. if (rxbyte > DM9000_PKT_RDY) {
  405. DM9000_iow(DM9000_RCR, 0x00); /* Stop Device */
  406. DM9000_iow(DM9000_ISR, 0x80); /* Stop INT request */
  407. printf("DM9000 error: status check fail: 0x%x\n",
  408. rxbyte);
  409. return 0;
  410. }
  411. if (rxbyte != DM9000_PKT_RDY)
  412. return 0; /* No packet received, ignore */
  413. DM9000_DBG("receiving packet\n");
  414. /* A packet ready now & Get status/length */
  415. (db->rx_status)(&RxStatus, &RxLen);
  416. DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
  417. /* Move data from DM9000 */
  418. /* Read received packet from RX SRAM */
  419. (db->inblk)(rdptr, RxLen);
  420. if ((RxStatus & 0xbf00) || (RxLen < 0x40)
  421. || (RxLen > DM9000_PKT_MAX)) {
  422. if (RxStatus & 0x100) {
  423. printf("rx fifo error\n");
  424. }
  425. if (RxStatus & 0x200) {
  426. printf("rx crc error\n");
  427. }
  428. if (RxStatus & 0x8000) {
  429. printf("rx length error\n");
  430. }
  431. if (RxLen > DM9000_PKT_MAX) {
  432. printf("rx length too big\n");
  433. dm9000_reset();
  434. }
  435. } else {
  436. DM9000_DMP_PACKET(__func__ , rdptr, RxLen);
  437. DM9000_DBG("passing packet to upper layer\n");
  438. NetReceive(NetRxPackets[0], RxLen);
  439. }
  440. }
  441. return 0;
  442. }
  443. /*
  444. Read a word data from SROM
  445. */
  446. #if !defined(CONFIG_DM9000_NO_SROM)
  447. void dm9000_read_srom_word(int offset, u8 *to)
  448. {
  449. DM9000_iow(DM9000_EPAR, offset);
  450. DM9000_iow(DM9000_EPCR, 0x4);
  451. udelay(8000);
  452. DM9000_iow(DM9000_EPCR, 0x0);
  453. to[0] = DM9000_ior(DM9000_EPDRL);
  454. to[1] = DM9000_ior(DM9000_EPDRH);
  455. }
  456. void dm9000_write_srom_word(int offset, u16 val)
  457. {
  458. DM9000_iow(DM9000_EPAR, offset);
  459. DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
  460. DM9000_iow(DM9000_EPDRL, (val & 0xff));
  461. DM9000_iow(DM9000_EPCR, 0x12);
  462. udelay(8000);
  463. DM9000_iow(DM9000_EPCR, 0);
  464. }
  465. #endif
  466. static void dm9000_get_enetaddr(struct eth_device *dev)
  467. {
  468. #if !defined(CONFIG_DM9000_NO_SROM)
  469. int i;
  470. for (i = 0; i < 3; i++)
  471. dm9000_read_srom_word(i, dev->enetaddr + (2 * i));
  472. #endif
  473. }
  474. /*
  475. Read a byte from I/O port
  476. */
  477. static u8
  478. DM9000_ior(int reg)
  479. {
  480. DM9000_outb(reg, DM9000_IO);
  481. return DM9000_inb(DM9000_DATA);
  482. }
  483. /*
  484. Write a byte to I/O port
  485. */
  486. static void
  487. DM9000_iow(int reg, u8 value)
  488. {
  489. DM9000_outb(reg, DM9000_IO);
  490. DM9000_outb(value, DM9000_DATA);
  491. }
  492. /*
  493. Read a word from phyxcer
  494. */
  495. static u16
  496. dm9000_phy_read(int reg)
  497. {
  498. u16 val;
  499. /* Fill the phyxcer register into REG_0C */
  500. DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
  501. DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */
  502. udelay(100); /* Wait read complete */
  503. DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */
  504. val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);
  505. /* The read data keeps on REG_0D & REG_0E */
  506. DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
  507. return val;
  508. }
  509. /*
  510. Write a word to phyxcer
  511. */
  512. static void
  513. dm9000_phy_write(int reg, u16 value)
  514. {
  515. /* Fill the phyxcer register into REG_0C */
  516. DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
  517. /* Fill the written data into REG_0D & REG_0E */
  518. DM9000_iow(DM9000_EPDRL, (value & 0xff));
  519. DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
  520. DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */
  521. udelay(500); /* Wait write complete */
  522. DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */
  523. DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
  524. }
  525. int dm9000_initialize(bd_t *bis)
  526. {
  527. struct eth_device *dev = &(dm9000_info.netdev);
  528. /* Load MAC address from EEPROM */
  529. dm9000_get_enetaddr(dev);
  530. dev->init = dm9000_init;
  531. dev->halt = dm9000_halt;
  532. dev->send = dm9000_send;
  533. dev->recv = dm9000_rx;
  534. sprintf(dev->name, "dm9000");
  535. eth_register(dev);
  536. return 0;
  537. }