dm9000x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. } board_info_t;
  89. static board_info_t dm9000_info;
  90. /* function declaration ------------------------------------- */
  91. int eth_init(bd_t * bd);
  92. int eth_send(volatile void *, int);
  93. int eth_rx(void);
  94. void eth_halt(void);
  95. static int dm9000_probe(void);
  96. static u16 phy_read(int);
  97. static void phy_write(int, u16);
  98. static u8 DM9000_ior(int);
  99. static void DM9000_iow(int reg, u8 value);
  100. /* DM9000 network board routine ---------------------------- */
  101. #define DM9000_outb(d,r) ( *(volatile u8 *)r = d )
  102. #define DM9000_outw(d,r) ( *(volatile u16 *)r = d )
  103. #define DM9000_outl(d,r) ( *(volatile u32 *)r = d )
  104. #define DM9000_inb(r) (*(volatile u8 *)r)
  105. #define DM9000_inw(r) (*(volatile u16 *)r)
  106. #define DM9000_inl(r) (*(volatile u32 *)r)
  107. #ifdef CONFIG_DM9000_DEBUG
  108. static void
  109. dump_regs(void)
  110. {
  111. DM9000_DBG("\n");
  112. DM9000_DBG("NCR (0x00): %02x\n", DM9000_ior(0));
  113. DM9000_DBG("NSR (0x01): %02x\n", DM9000_ior(1));
  114. DM9000_DBG("TCR (0x02): %02x\n", DM9000_ior(2));
  115. DM9000_DBG("TSRI (0x03): %02x\n", DM9000_ior(3));
  116. DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4));
  117. DM9000_DBG("RCR (0x05): %02x\n", DM9000_ior(5));
  118. DM9000_DBG("RSR (0x06): %02x\n", DM9000_ior(6));
  119. DM9000_DBG("ISR (0xFE): %02x\n", DM9000_ior(DM9000_ISR));
  120. DM9000_DBG("\n");
  121. }
  122. #endif
  123. static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
  124. {
  125. int i;
  126. for (i = 0; i < count; i++)
  127. DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
  128. }
  129. static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
  130. {
  131. int i;
  132. u32 tmplen = (count + 1) / 2;
  133. for (i = 0; i < tmplen; i++)
  134. DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
  135. }
  136. static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
  137. {
  138. int i;
  139. u32 tmplen = (count + 3) / 4;
  140. for (i = 0; i < tmplen; i++)
  141. DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
  142. }
  143. static void dm9000_inblk_8bit(void *data_ptr, int count)
  144. {
  145. int i;
  146. for (i = 0; i < count; i++)
  147. ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA);
  148. }
  149. static void dm9000_inblk_16bit(void *data_ptr, int count)
  150. {
  151. int i;
  152. u32 tmplen = (count + 1) / 2;
  153. for (i = 0; i < tmplen; i++)
  154. ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA);
  155. }
  156. static void dm9000_inblk_32bit(void *data_ptr, int count)
  157. {
  158. int i;
  159. u32 tmplen = (count + 3) / 4;
  160. for (i = 0; i < tmplen; i++)
  161. ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA);
  162. }
  163. static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
  164. {
  165. u32 tmpdata;
  166. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  167. tmpdata = DM9000_inl(DM9000_DATA);
  168. *RxStatus = __le16_to_cpu(tmpdata);
  169. *RxLen = __le16_to_cpu(tmpdata >> 16);
  170. }
  171. static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
  172. {
  173. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  174. *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA));
  175. *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA));
  176. }
  177. static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
  178. {
  179. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  180. *RxStatus =
  181. __le16_to_cpu(DM9000_inb(DM9000_DATA) +
  182. (DM9000_inb(DM9000_DATA) << 8));
  183. *RxLen =
  184. __le16_to_cpu(DM9000_inb(DM9000_DATA) +
  185. (DM9000_inb(DM9000_DATA) << 8));
  186. }
  187. /*
  188. Search DM9000 board, allocate space and register it
  189. */
  190. int
  191. dm9000_probe(void)
  192. {
  193. u32 id_val;
  194. id_val = DM9000_ior(DM9000_VIDL);
  195. id_val |= DM9000_ior(DM9000_VIDH) << 8;
  196. id_val |= DM9000_ior(DM9000_PIDL) << 16;
  197. id_val |= DM9000_ior(DM9000_PIDH) << 24;
  198. if (id_val == DM9000_ID) {
  199. printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
  200. id_val);
  201. return 0;
  202. } else {
  203. printf("dm9000 not found at 0x%08x id: 0x%08x\n",
  204. CONFIG_DM9000_BASE, id_val);
  205. return -1;
  206. }
  207. }
  208. /* General Purpose dm9000 reset routine */
  209. static void
  210. dm9000_reset(void)
  211. {
  212. DM9000_DBG("resetting DM9000\n");
  213. /* Reset DM9000,
  214. see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
  215. /* DEBUG: Make all GPIO0 outputs, all others inputs */
  216. DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
  217. /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
  218. DM9000_iow(DM9000_GPR, 0);
  219. /* Step 2: Software reset */
  220. DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
  221. do {
  222. DM9000_DBG("resetting the DM9000, 1st reset\n");
  223. udelay(25); /* Wait at least 20 us */
  224. } while (DM9000_ior(DM9000_NCR) & 1);
  225. DM9000_iow(DM9000_NCR, 0);
  226. DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
  227. do {
  228. DM9000_DBG("resetting the DM9000, 2nd reset\n");
  229. udelay(25); /* Wait at least 20 us */
  230. } while (DM9000_ior(DM9000_NCR) & 1);
  231. /* Check whether the ethernet controller is present */
  232. if ((DM9000_ior(DM9000_PIDL) != 0x0) ||
  233. (DM9000_ior(DM9000_PIDH) != 0x90))
  234. printf("ERROR: resetting DM9000 -> not responding\n");
  235. }
  236. /* Initilize dm9000 board
  237. */
  238. int
  239. eth_init(bd_t * bd)
  240. {
  241. int i, oft, lnk;
  242. u8 io_mode;
  243. struct board_info *db = &dm9000_info;
  244. uchar enetaddr[6];
  245. DM9000_DBG("eth_init()\n");
  246. /* RESET device */
  247. dm9000_reset();
  248. if (dm9000_probe() < 0)
  249. return -1;
  250. /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
  251. io_mode = DM9000_ior(DM9000_ISR) >> 6;
  252. switch (io_mode) {
  253. case 0x0: /* 16-bit mode */
  254. printf("DM9000: running in 16 bit mode\n");
  255. db->outblk = dm9000_outblk_16bit;
  256. db->inblk = dm9000_inblk_16bit;
  257. db->rx_status = dm9000_rx_status_16bit;
  258. break;
  259. case 0x01: /* 32-bit mode */
  260. printf("DM9000: running in 32 bit mode\n");
  261. db->outblk = dm9000_outblk_32bit;
  262. db->inblk = dm9000_inblk_32bit;
  263. db->rx_status = dm9000_rx_status_32bit;
  264. break;
  265. case 0x02: /* 8 bit mode */
  266. printf("DM9000: running in 8 bit mode\n");
  267. db->outblk = dm9000_outblk_8bit;
  268. db->inblk = dm9000_inblk_8bit;
  269. db->rx_status = dm9000_rx_status_8bit;
  270. break;
  271. default:
  272. /* Assume 8 bit mode, will probably not work anyway */
  273. printf("DM9000: Undefined IO-mode:0x%x\n", io_mode);
  274. db->outblk = dm9000_outblk_8bit;
  275. db->inblk = dm9000_inblk_8bit;
  276. db->rx_status = dm9000_rx_status_8bit;
  277. break;
  278. }
  279. /* Program operating register, only internal phy supported */
  280. DM9000_iow(DM9000_NCR, 0x0);
  281. /* TX Polling clear */
  282. DM9000_iow(DM9000_TCR, 0);
  283. /* Less 3Kb, 200us */
  284. DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
  285. /* Flow Control : High/Low Water */
  286. DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
  287. /* SH FIXME: This looks strange! Flow Control */
  288. DM9000_iow(DM9000_FCR, 0x0);
  289. /* Special Mode */
  290. DM9000_iow(DM9000_SMCR, 0);
  291. /* clear TX status */
  292. DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
  293. /* Clear interrupt status */
  294. DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
  295. /* Set Node address */
  296. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  297. #if !defined(CONFIG_DM9000_NO_SROM)
  298. for (i = 0; i < 3; i++)
  299. dm9000_read_srom_word(i, enetaddr + 2 * i);
  300. eth_setenv_enetaddr("ethaddr", enetaddr);
  301. #endif
  302. }
  303. printf("MAC: %pM\n", enetaddr);
  304. /* fill device MAC address registers */
  305. for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
  306. DM9000_iow(oft, enetaddr[i]);
  307. for (i = 0, oft = 0x16; i < 8; i++, oft++)
  308. DM9000_iow(oft, 0xff);
  309. /* read back mac, just to be sure */
  310. for (i = 0, oft = 0x10; i < 6; i++, oft++)
  311. DM9000_DBG("%02x:", DM9000_ior(oft));
  312. DM9000_DBG("\n");
  313. /* Activate DM9000 */
  314. /* RX enable */
  315. DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN);
  316. /* Enable TX/RX interrupt mask */
  317. DM9000_iow(DM9000_IMR, IMR_PAR);
  318. i = 0;
  319. while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */
  320. udelay(1000);
  321. i++;
  322. if (i == 10000) {
  323. printf("could not establish link\n");
  324. return 0;
  325. }
  326. }
  327. /* see what we've got */
  328. lnk = phy_read(17) >> 12;
  329. printf("operating at ");
  330. switch (lnk) {
  331. case 1:
  332. printf("10M half duplex ");
  333. break;
  334. case 2:
  335. printf("10M full duplex ");
  336. break;
  337. case 4:
  338. printf("100M half duplex ");
  339. break;
  340. case 8:
  341. printf("100M full duplex ");
  342. break;
  343. default:
  344. printf("unknown: %d ", lnk);
  345. break;
  346. }
  347. printf("mode\n");
  348. return 0;
  349. }
  350. /*
  351. Hardware start transmission.
  352. Send a packet to media from the upper layer.
  353. */
  354. int
  355. eth_send(volatile void *packet, int length)
  356. {
  357. int tmo;
  358. struct board_info *db = &dm9000_info;
  359. DM9000_DMP_PACKET("eth_send", packet, length);
  360. DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
  361. /* Move data to DM9000 TX RAM */
  362. DM9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */
  363. /* push the data to the TX-fifo */
  364. (db->outblk)(packet, length);
  365. /* Set TX length to DM9000 */
  366. DM9000_iow(DM9000_TXPLL, length & 0xff);
  367. DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff);
  368. /* Issue TX polling command */
  369. DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */
  370. /* wait for end of transmission */
  371. tmo = get_timer(0) + 5 * CONFIG_SYS_HZ;
  372. while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) ||
  373. !(DM9000_ior(DM9000_ISR) & IMR_PTM) ) {
  374. if (get_timer(0) >= tmo) {
  375. printf("transmission timeout\n");
  376. break;
  377. }
  378. }
  379. DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */
  380. DM9000_DBG("transmit done\n\n");
  381. return 0;
  382. }
  383. /*
  384. Stop the interface.
  385. The interface is stopped when it is brought.
  386. */
  387. void
  388. eth_halt(void)
  389. {
  390. DM9000_DBG("eth_halt\n");
  391. /* RESET devie */
  392. phy_write(0, 0x8000); /* PHY RESET */
  393. DM9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */
  394. DM9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */
  395. DM9000_iow(DM9000_RCR, 0x00); /* Disable RX */
  396. }
  397. /*
  398. Received a packet and pass to upper layer
  399. */
  400. int
  401. eth_rx(void)
  402. {
  403. u8 rxbyte, *rdptr = (u8 *) NetRxPackets[0];
  404. u16 RxStatus, RxLen = 0;
  405. struct board_info *db = &dm9000_info;
  406. /* Check packet ready or not, we must check
  407. the ISR status first for DM9000A */
  408. if (!(DM9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */
  409. return 0;
  410. DM9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */
  411. /* There is _at least_ 1 package in the fifo, read them all */
  412. for (;;) {
  413. DM9000_ior(DM9000_MRCMDX); /* Dummy read */
  414. /* Get most updated data,
  415. only look at bits 0:1, See application notes DM9000 */
  416. rxbyte = DM9000_inb(DM9000_DATA) & 0x03;
  417. /* Status check: this byte must be 0 or 1 */
  418. if (rxbyte > DM9000_PKT_RDY) {
  419. DM9000_iow(DM9000_RCR, 0x00); /* Stop Device */
  420. DM9000_iow(DM9000_ISR, 0x80); /* Stop INT request */
  421. printf("DM9000 error: status check fail: 0x%x\n",
  422. rxbyte);
  423. return 0;
  424. }
  425. if (rxbyte != DM9000_PKT_RDY)
  426. return 0; /* No packet received, ignore */
  427. DM9000_DBG("receiving packet\n");
  428. /* A packet ready now & Get status/length */
  429. (db->rx_status)(&RxStatus, &RxLen);
  430. DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen);
  431. /* Move data from DM9000 */
  432. /* Read received packet from RX SRAM */
  433. (db->inblk)(rdptr, RxLen);
  434. if ((RxStatus & 0xbf00) || (RxLen < 0x40)
  435. || (RxLen > DM9000_PKT_MAX)) {
  436. if (RxStatus & 0x100) {
  437. printf("rx fifo error\n");
  438. }
  439. if (RxStatus & 0x200) {
  440. printf("rx crc error\n");
  441. }
  442. if (RxStatus & 0x8000) {
  443. printf("rx length error\n");
  444. }
  445. if (RxLen > DM9000_PKT_MAX) {
  446. printf("rx length too big\n");
  447. dm9000_reset();
  448. }
  449. } else {
  450. DM9000_DMP_PACKET("eth_rx", rdptr, RxLen);
  451. DM9000_DBG("passing packet to upper layer\n");
  452. NetReceive(NetRxPackets[0], RxLen);
  453. }
  454. }
  455. return 0;
  456. }
  457. /*
  458. Read a word data from SROM
  459. */
  460. #if !defined(CONFIG_DM9000_NO_SROM)
  461. void dm9000_read_srom_word(int offset, u8 *to)
  462. {
  463. DM9000_iow(DM9000_EPAR, offset);
  464. DM9000_iow(DM9000_EPCR, 0x4);
  465. udelay(8000);
  466. DM9000_iow(DM9000_EPCR, 0x0);
  467. to[0] = DM9000_ior(DM9000_EPDRL);
  468. to[1] = DM9000_ior(DM9000_EPDRH);
  469. }
  470. void dm9000_write_srom_word(int offset, u16 val)
  471. {
  472. DM9000_iow(DM9000_EPAR, offset);
  473. DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff));
  474. DM9000_iow(DM9000_EPDRL, (val & 0xff));
  475. DM9000_iow(DM9000_EPCR, 0x12);
  476. udelay(8000);
  477. DM9000_iow(DM9000_EPCR, 0);
  478. }
  479. #endif
  480. /*
  481. Read a byte from I/O port
  482. */
  483. static u8
  484. DM9000_ior(int reg)
  485. {
  486. DM9000_outb(reg, DM9000_IO);
  487. return DM9000_inb(DM9000_DATA);
  488. }
  489. /*
  490. Write a byte to I/O port
  491. */
  492. static void
  493. DM9000_iow(int reg, u8 value)
  494. {
  495. DM9000_outb(reg, DM9000_IO);
  496. DM9000_outb(value, DM9000_DATA);
  497. }
  498. /*
  499. Read a word from phyxcer
  500. */
  501. static u16
  502. phy_read(int reg)
  503. {
  504. u16 val;
  505. /* Fill the phyxcer register into REG_0C */
  506. DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
  507. DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */
  508. udelay(100); /* Wait read complete */
  509. DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */
  510. val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);
  511. /* The read data keeps on REG_0D & REG_0E */
  512. DM9000_DBG("phy_read(0x%x): 0x%x\n", reg, val);
  513. return val;
  514. }
  515. /*
  516. Write a word to phyxcer
  517. */
  518. static void
  519. phy_write(int reg, u16 value)
  520. {
  521. /* Fill the phyxcer register into REG_0C */
  522. DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
  523. /* Fill the written data into REG_0D & REG_0E */
  524. DM9000_iow(DM9000_EPDRL, (value & 0xff));
  525. DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
  526. DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */
  527. udelay(500); /* Wait write complete */
  528. DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */
  529. DM9000_DBG("phy_write(reg:0x%x, value:0x%x)\n", reg, value);
  530. }