dm9000x.c 16 KB

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