dm9000x.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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("%s: length: %d\n", func, 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 dm9000_phy_read(int);
  94. static void dm9000_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. #ifndef CONFIG_DM9000_BYTE_SWAPPED
  99. #define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r))
  100. #define DM9000_outw(d,r) writew(d, (volatile u16 *)(r))
  101. #define DM9000_outl(d,r) writel(d, (volatile u32 *)(r))
  102. #define DM9000_inb(r) readb((volatile u8 *)(r))
  103. #define DM9000_inw(r) readw((volatile u16 *)(r))
  104. #define DM9000_inl(r) readl((volatile u32 *)(r))
  105. #else
  106. #define DM9000_outb(d, r) __raw_writeb(d, r)
  107. #define DM9000_outw(d, r) __raw_writew(d, r)
  108. #define DM9000_outl(d, r) __raw_writel(d, r)
  109. #define DM9000_inb(r) __raw_readb(r)
  110. #define DM9000_inw(r) __raw_readw(r)
  111. #define DM9000_inl(r) __raw_readl(r)
  112. #endif
  113. #ifdef CONFIG_DM9000_DEBUG
  114. static void
  115. dump_regs(void)
  116. {
  117. DM9000_DBG("\n");
  118. DM9000_DBG("NCR (0x00): %02x\n", DM9000_ior(0));
  119. DM9000_DBG("NSR (0x01): %02x\n", DM9000_ior(1));
  120. DM9000_DBG("TCR (0x02): %02x\n", DM9000_ior(2));
  121. DM9000_DBG("TSRI (0x03): %02x\n", DM9000_ior(3));
  122. DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4));
  123. DM9000_DBG("RCR (0x05): %02x\n", DM9000_ior(5));
  124. DM9000_DBG("RSR (0x06): %02x\n", DM9000_ior(6));
  125. DM9000_DBG("ISR (0xFE): %02x\n", DM9000_ior(DM9000_ISR));
  126. DM9000_DBG("\n");
  127. }
  128. #endif
  129. static void dm9000_outblk_8bit(volatile void *data_ptr, int count)
  130. {
  131. int i;
  132. for (i = 0; i < count; i++)
  133. DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA);
  134. }
  135. static void dm9000_outblk_16bit(volatile void *data_ptr, int count)
  136. {
  137. int i;
  138. u32 tmplen = (count + 1) / 2;
  139. for (i = 0; i < tmplen; i++)
  140. DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA);
  141. }
  142. static void dm9000_outblk_32bit(volatile void *data_ptr, int count)
  143. {
  144. int i;
  145. u32 tmplen = (count + 3) / 4;
  146. for (i = 0; i < tmplen; i++)
  147. DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA);
  148. }
  149. static void dm9000_inblk_8bit(void *data_ptr, int count)
  150. {
  151. int i;
  152. for (i = 0; i < count; i++)
  153. ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA);
  154. }
  155. static void dm9000_inblk_16bit(void *data_ptr, int count)
  156. {
  157. int i;
  158. u32 tmplen = (count + 1) / 2;
  159. for (i = 0; i < tmplen; i++)
  160. ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA);
  161. }
  162. static void dm9000_inblk_32bit(void *data_ptr, int count)
  163. {
  164. int i;
  165. u32 tmplen = (count + 3) / 4;
  166. for (i = 0; i < tmplen; i++)
  167. ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA);
  168. }
  169. static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen)
  170. {
  171. u32 tmpdata;
  172. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  173. tmpdata = DM9000_inl(DM9000_DATA);
  174. *RxStatus = __le16_to_cpu(tmpdata);
  175. *RxLen = __le16_to_cpu(tmpdata >> 16);
  176. }
  177. static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen)
  178. {
  179. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  180. *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA));
  181. *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA));
  182. }
  183. static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen)
  184. {
  185. DM9000_outb(DM9000_MRCMD, DM9000_IO);
  186. *RxStatus =
  187. __le16_to_cpu(DM9000_inb(DM9000_DATA) +
  188. (DM9000_inb(DM9000_DATA) << 8));
  189. *RxLen =
  190. __le16_to_cpu(DM9000_inb(DM9000_DATA) +
  191. (DM9000_inb(DM9000_DATA) << 8));
  192. }
  193. /*
  194. Search DM9000 board, allocate space and register it
  195. */
  196. int
  197. dm9000_probe(void)
  198. {
  199. u32 id_val;
  200. id_val = DM9000_ior(DM9000_VIDL);
  201. id_val |= DM9000_ior(DM9000_VIDH) << 8;
  202. id_val |= DM9000_ior(DM9000_PIDL) << 16;
  203. id_val |= DM9000_ior(DM9000_PIDH) << 24;
  204. if (id_val == DM9000_ID) {
  205. printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE,
  206. id_val);
  207. return 0;
  208. } else {
  209. printf("dm9000 not found at 0x%08x id: 0x%08x\n",
  210. CONFIG_DM9000_BASE, id_val);
  211. return -1;
  212. }
  213. }
  214. /* General Purpose dm9000 reset routine */
  215. static void
  216. dm9000_reset(void)
  217. {
  218. DM9000_DBG("resetting DM9000\n");
  219. /* Reset DM9000,
  220. see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */
  221. /* DEBUG: Make all GPIO0 outputs, all others inputs */
  222. DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT);
  223. /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */
  224. DM9000_iow(DM9000_GPR, 0);
  225. /* Step 2: Software reset */
  226. DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST));
  227. do {
  228. DM9000_DBG("resetting the DM9000, 1st reset\n");
  229. udelay(25); /* Wait at least 20 us */
  230. } while (DM9000_ior(DM9000_NCR) & 1);
  231. DM9000_iow(DM9000_NCR, 0);
  232. DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */
  233. do {
  234. DM9000_DBG("resetting the DM9000, 2nd reset\n");
  235. udelay(25); /* Wait at least 20 us */
  236. } while (DM9000_ior(DM9000_NCR) & 1);
  237. /* Check whether the ethernet controller is present */
  238. if ((DM9000_ior(DM9000_PIDL) != 0x0) ||
  239. (DM9000_ior(DM9000_PIDH) != 0x90))
  240. printf("ERROR: resetting DM9000 -> not responding\n");
  241. }
  242. /* Initialize dm9000 board
  243. */
  244. static int dm9000_init(struct eth_device *dev, bd_t *bd)
  245. {
  246. int i, oft, lnk;
  247. u8 io_mode;
  248. struct board_info *db = &dm9000_info;
  249. DM9000_DBG("%s\n", __func__);
  250. /* RESET device */
  251. dm9000_reset();
  252. if (dm9000_probe() < 0)
  253. return -1;
  254. /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */
  255. io_mode = DM9000_ior(DM9000_ISR) >> 6;
  256. switch (io_mode) {
  257. case 0x0: /* 16-bit mode */
  258. printf("DM9000: running in 16 bit mode\n");
  259. db->outblk = dm9000_outblk_16bit;
  260. db->inblk = dm9000_inblk_16bit;
  261. db->rx_status = dm9000_rx_status_16bit;
  262. break;
  263. case 0x01: /* 32-bit mode */
  264. printf("DM9000: running in 32 bit mode\n");
  265. db->outblk = dm9000_outblk_32bit;
  266. db->inblk = dm9000_inblk_32bit;
  267. db->rx_status = dm9000_rx_status_32bit;
  268. break;
  269. case 0x02: /* 8 bit mode */
  270. printf("DM9000: running in 8 bit mode\n");
  271. db->outblk = dm9000_outblk_8bit;
  272. db->inblk = dm9000_inblk_8bit;
  273. db->rx_status = dm9000_rx_status_8bit;
  274. break;
  275. default:
  276. /* Assume 8 bit mode, will probably not work anyway */
  277. printf("DM9000: Undefined IO-mode:0x%x\n", io_mode);
  278. db->outblk = dm9000_outblk_8bit;
  279. db->inblk = dm9000_inblk_8bit;
  280. db->rx_status = dm9000_rx_status_8bit;
  281. break;
  282. }
  283. /* Program operating register, only internal phy supported */
  284. DM9000_iow(DM9000_NCR, 0x0);
  285. /* TX Polling clear */
  286. DM9000_iow(DM9000_TCR, 0);
  287. /* Less 3Kb, 200us */
  288. DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US);
  289. /* Flow Control : High/Low Water */
  290. DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8));
  291. /* SH FIXME: This looks strange! Flow Control */
  292. DM9000_iow(DM9000_FCR, 0x0);
  293. /* Special Mode */
  294. DM9000_iow(DM9000_SMCR, 0);
  295. /* clear TX status */
  296. DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END);
  297. /* Clear interrupt status */
  298. DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS);
  299. printf("MAC: %pM\n", dev->enetaddr);
  300. /* fill device MAC address registers */
  301. for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
  302. DM9000_iow(oft, dev->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 (!(dm9000_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 = dm9000_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. dm9000_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. static void dm9000_get_enetaddr(struct eth_device *dev)
  475. {
  476. #if !defined(CONFIG_DM9000_NO_SROM)
  477. int i;
  478. for (i = 0; i < 3; i++)
  479. dm9000_read_srom_word(i, dev->enetaddr + (2 * i));
  480. #endif
  481. }
  482. /*
  483. Read a byte from I/O port
  484. */
  485. static u8
  486. DM9000_ior(int reg)
  487. {
  488. DM9000_outb(reg, DM9000_IO);
  489. return DM9000_inb(DM9000_DATA);
  490. }
  491. /*
  492. Write a byte to I/O port
  493. */
  494. static void
  495. DM9000_iow(int reg, u8 value)
  496. {
  497. DM9000_outb(reg, DM9000_IO);
  498. DM9000_outb(value, DM9000_DATA);
  499. }
  500. /*
  501. Read a word from phyxcer
  502. */
  503. static u16
  504. dm9000_phy_read(int reg)
  505. {
  506. u16 val;
  507. /* Fill the phyxcer register into REG_0C */
  508. DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
  509. DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */
  510. udelay(100); /* Wait read complete */
  511. DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */
  512. val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);
  513. /* The read data keeps on REG_0D & REG_0E */
  514. DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val);
  515. return val;
  516. }
  517. /*
  518. Write a word to phyxcer
  519. */
  520. static void
  521. dm9000_phy_write(int reg, u16 value)
  522. {
  523. /* Fill the phyxcer register into REG_0C */
  524. DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
  525. /* Fill the written data into REG_0D & REG_0E */
  526. DM9000_iow(DM9000_EPDRL, (value & 0xff));
  527. DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
  528. DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */
  529. udelay(500); /* Wait write complete */
  530. DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */
  531. DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value);
  532. }
  533. int dm9000_initialize(bd_t *bis)
  534. {
  535. struct eth_device *dev = &(dm9000_info.netdev);
  536. /* Load MAC address from EEPROM */
  537. dm9000_get_enetaddr(dev);
  538. dev->init = dm9000_init;
  539. dev->halt = dm9000_halt;
  540. dev->send = dm9000_send;
  541. dev->recv = dm9000_rx;
  542. sprintf(dev->name, "dm9000");
  543. eth_register(dev);
  544. return 0;
  545. }