ep93xx_eth.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * Cirrus Logic EP93xx ethernet MAC / MII driver.
  3. *
  4. * Copyright (C) 2010, 2009
  5. * Matthias Kaehlcke <matthias@kaehlcke.net>
  6. *
  7. * Copyright (C) 2004, 2005
  8. * Cory T. Tusar, Videon Central, Inc., <ctusar@videon-central.com>
  9. *
  10. * Based on the original eth.[ch] Cirrus Logic EP93xx Rev D. Ethernet Driver,
  11. * which is
  12. *
  13. * (C) Copyright 2002 2003
  14. * Adam Bezanson, Network Audio Technologies, Inc.
  15. * <bezanson@netaudiotech.com>
  16. *
  17. * SPDX-License-Identifier: GPL-2.0+
  18. */
  19. #include <command.h>
  20. #include <common.h>
  21. #include <asm/arch/ep93xx.h>
  22. #include <asm/io.h>
  23. #include <malloc.h>
  24. #include <miiphy.h>
  25. #include <linux/types.h>
  26. #include "ep93xx_eth.h"
  27. #define GET_PRIV(eth_dev) ((struct ep93xx_priv *)(eth_dev)->priv)
  28. #define GET_REGS(eth_dev) (GET_PRIV(eth_dev)->regs)
  29. /* ep93xx_miiphy ops forward declarations */
  30. static int ep93xx_miiphy_read(const char * const dev, unsigned char const addr,
  31. unsigned char const reg, unsigned short * const value);
  32. static int ep93xx_miiphy_write(const char * const dev, unsigned char const addr,
  33. unsigned char const reg, unsigned short const value);
  34. #if defined(EP93XX_MAC_DEBUG)
  35. /**
  36. * Dump ep93xx_mac values to the terminal.
  37. */
  38. static void dump_dev(struct eth_device *dev)
  39. {
  40. struct ep93xx_priv *priv = GET_PRIV(dev);
  41. int i;
  42. printf("\ndump_dev()\n");
  43. printf(" rx_dq.base %p\n", priv->rx_dq.base);
  44. printf(" rx_dq.current %p\n", priv->rx_dq.current);
  45. printf(" rx_dq.end %p\n", priv->rx_dq.end);
  46. printf(" rx_sq.base %p\n", priv->rx_sq.base);
  47. printf(" rx_sq.current %p\n", priv->rx_sq.current);
  48. printf(" rx_sq.end %p\n", priv->rx_sq.end);
  49. for (i = 0; i < NUMRXDESC; i++)
  50. printf(" rx_buffer[%2.d] %p\n", i, NetRxPackets[i]);
  51. printf(" tx_dq.base %p\n", priv->tx_dq.base);
  52. printf(" tx_dq.current %p\n", priv->tx_dq.current);
  53. printf(" tx_dq.end %p\n", priv->tx_dq.end);
  54. printf(" tx_sq.base %p\n", priv->tx_sq.base);
  55. printf(" tx_sq.current %p\n", priv->tx_sq.current);
  56. printf(" tx_sq.end %p\n", priv->tx_sq.end);
  57. }
  58. /**
  59. * Dump all RX status queue entries to the terminal.
  60. */
  61. static void dump_rx_status_queue(struct eth_device *dev)
  62. {
  63. struct ep93xx_priv *priv = GET_PRIV(dev);
  64. int i;
  65. printf("\ndump_rx_status_queue()\n");
  66. printf(" descriptor address word1 word2\n");
  67. for (i = 0; i < NUMRXDESC; i++) {
  68. printf(" [ %p ] %08X %08X\n",
  69. priv->rx_sq.base + i,
  70. (priv->rx_sq.base + i)->word1,
  71. (priv->rx_sq.base + i)->word2);
  72. }
  73. }
  74. /**
  75. * Dump all RX descriptor queue entries to the terminal.
  76. */
  77. static void dump_rx_descriptor_queue(struct eth_device *dev)
  78. {
  79. struct ep93xx_priv *priv = GET_PRIV(dev);
  80. int i;
  81. printf("\ndump_rx_descriptor_queue()\n");
  82. printf(" descriptor address word1 word2\n");
  83. for (i = 0; i < NUMRXDESC; i++) {
  84. printf(" [ %p ] %08X %08X\n",
  85. priv->rx_dq.base + i,
  86. (priv->rx_dq.base + i)->word1,
  87. (priv->rx_dq.base + i)->word2);
  88. }
  89. }
  90. /**
  91. * Dump all TX descriptor queue entries to the terminal.
  92. */
  93. static void dump_tx_descriptor_queue(struct eth_device *dev)
  94. {
  95. struct ep93xx_priv *priv = GET_PRIV(dev);
  96. int i;
  97. printf("\ndump_tx_descriptor_queue()\n");
  98. printf(" descriptor address word1 word2\n");
  99. for (i = 0; i < NUMTXDESC; i++) {
  100. printf(" [ %p ] %08X %08X\n",
  101. priv->tx_dq.base + i,
  102. (priv->tx_dq.base + i)->word1,
  103. (priv->tx_dq.base + i)->word2);
  104. }
  105. }
  106. /**
  107. * Dump all TX status queue entries to the terminal.
  108. */
  109. static void dump_tx_status_queue(struct eth_device *dev)
  110. {
  111. struct ep93xx_priv *priv = GET_PRIV(dev);
  112. int i;
  113. printf("\ndump_tx_status_queue()\n");
  114. printf(" descriptor address word1\n");
  115. for (i = 0; i < NUMTXDESC; i++) {
  116. printf(" [ %p ] %08X\n",
  117. priv->rx_sq.base + i,
  118. (priv->rx_sq.base + i)->word1);
  119. }
  120. }
  121. #else
  122. #define dump_dev(x)
  123. #define dump_rx_descriptor_queue(x)
  124. #define dump_rx_status_queue(x)
  125. #define dump_tx_descriptor_queue(x)
  126. #define dump_tx_status_queue(x)
  127. #endif /* defined(EP93XX_MAC_DEBUG) */
  128. /**
  129. * Reset the EP93xx MAC by twiddling the soft reset bit and spinning until
  130. * it's cleared.
  131. */
  132. static void ep93xx_mac_reset(struct eth_device *dev)
  133. {
  134. struct mac_regs *mac = GET_REGS(dev);
  135. uint32_t value;
  136. debug("+ep93xx_mac_reset");
  137. value = readl(&mac->selfctl);
  138. value |= SELFCTL_RESET;
  139. writel(value, &mac->selfctl);
  140. while (readl(&mac->selfctl) & SELFCTL_RESET)
  141. ; /* noop */
  142. debug("-ep93xx_mac_reset");
  143. }
  144. /* Eth device open */
  145. static int ep93xx_eth_open(struct eth_device *dev, bd_t *bd)
  146. {
  147. struct ep93xx_priv *priv = GET_PRIV(dev);
  148. struct mac_regs *mac = GET_REGS(dev);
  149. uchar *mac_addr = dev->enetaddr;
  150. int i;
  151. debug("+ep93xx_eth_open");
  152. /* Reset the MAC */
  153. ep93xx_mac_reset(dev);
  154. /* Reset the descriptor queues' current and end address values */
  155. priv->tx_dq.current = priv->tx_dq.base;
  156. priv->tx_dq.end = (priv->tx_dq.base + NUMTXDESC);
  157. priv->tx_sq.current = priv->tx_sq.base;
  158. priv->tx_sq.end = (priv->tx_sq.base + NUMTXDESC);
  159. priv->rx_dq.current = priv->rx_dq.base;
  160. priv->rx_dq.end = (priv->rx_dq.base + NUMRXDESC);
  161. priv->rx_sq.current = priv->rx_sq.base;
  162. priv->rx_sq.end = (priv->rx_sq.base + NUMRXDESC);
  163. /*
  164. * Set the transmit descriptor and status queues' base address,
  165. * current address, and length registers. Set the maximum frame
  166. * length and threshold. Enable the transmit descriptor processor.
  167. */
  168. writel((uint32_t)priv->tx_dq.base, &mac->txdq.badd);
  169. writel((uint32_t)priv->tx_dq.base, &mac->txdq.curadd);
  170. writel(sizeof(struct tx_descriptor) * NUMTXDESC, &mac->txdq.blen);
  171. writel((uint32_t)priv->tx_sq.base, &mac->txstsq.badd);
  172. writel((uint32_t)priv->tx_sq.base, &mac->txstsq.curadd);
  173. writel(sizeof(struct tx_status) * NUMTXDESC, &mac->txstsq.blen);
  174. writel(0x00040000, &mac->txdthrshld);
  175. writel(0x00040000, &mac->txststhrshld);
  176. writel((TXSTARTMAX << 0) | (PKTSIZE_ALIGN << 16), &mac->maxfrmlen);
  177. writel(BMCTL_TXEN, &mac->bmctl);
  178. /*
  179. * Set the receive descriptor and status queues' base address,
  180. * current address, and length registers. Enable the receive
  181. * descriptor processor.
  182. */
  183. writel((uint32_t)priv->rx_dq.base, &mac->rxdq.badd);
  184. writel((uint32_t)priv->rx_dq.base, &mac->rxdq.curadd);
  185. writel(sizeof(struct rx_descriptor) * NUMRXDESC, &mac->rxdq.blen);
  186. writel((uint32_t)priv->rx_sq.base, &mac->rxstsq.badd);
  187. writel((uint32_t)priv->rx_sq.base, &mac->rxstsq.curadd);
  188. writel(sizeof(struct rx_status) * NUMRXDESC, &mac->rxstsq.blen);
  189. writel(0x00040000, &mac->rxdthrshld);
  190. writel(BMCTL_RXEN, &mac->bmctl);
  191. writel(0x00040000, &mac->rxststhrshld);
  192. /* Wait until the receive descriptor processor is active */
  193. while (!(readl(&mac->bmsts) & BMSTS_RXACT))
  194. ; /* noop */
  195. /*
  196. * Initialize the RX descriptor queue. Clear the TX descriptor queue.
  197. * Clear the RX and TX status queues. Enqueue the RX descriptor and
  198. * status entries to the MAC.
  199. */
  200. for (i = 0; i < NUMRXDESC; i++) {
  201. /* set buffer address */
  202. (priv->rx_dq.base + i)->word1 = (uint32_t)NetRxPackets[i];
  203. /* set buffer length, clear buffer index and NSOF */
  204. (priv->rx_dq.base + i)->word2 = PKTSIZE_ALIGN;
  205. }
  206. memset(priv->tx_dq.base, 0,
  207. (sizeof(struct tx_descriptor) * NUMTXDESC));
  208. memset(priv->rx_sq.base, 0,
  209. (sizeof(struct rx_status) * NUMRXDESC));
  210. memset(priv->tx_sq.base, 0,
  211. (sizeof(struct tx_status) * NUMTXDESC));
  212. writel(NUMRXDESC, &mac->rxdqenq);
  213. writel(NUMRXDESC, &mac->rxstsqenq);
  214. /* Set the primary MAC address */
  215. writel(AFP_IAPRIMARY, &mac->afp);
  216. writel(mac_addr[0] | (mac_addr[1] << 8) |
  217. (mac_addr[2] << 16) | (mac_addr[3] << 24),
  218. &mac->indad);
  219. writel(mac_addr[4] | (mac_addr[5] << 8), &mac->indad_upper);
  220. /* Turn on RX and TX */
  221. writel(RXCTL_IA0 | RXCTL_BA | RXCTL_SRXON |
  222. RXCTL_RCRCA | RXCTL_MA, &mac->rxctl);
  223. writel(TXCTL_STXON, &mac->txctl);
  224. /* Dump data structures if we're debugging */
  225. dump_dev(dev);
  226. dump_rx_descriptor_queue(dev);
  227. dump_rx_status_queue(dev);
  228. dump_tx_descriptor_queue(dev);
  229. dump_tx_status_queue(dev);
  230. debug("-ep93xx_eth_open");
  231. return 1;
  232. }
  233. /**
  234. * Halt EP93xx MAC transmit and receive by clearing the TxCTL and RxCTL
  235. * registers.
  236. */
  237. static void ep93xx_eth_close(struct eth_device *dev)
  238. {
  239. struct mac_regs *mac = GET_REGS(dev);
  240. debug("+ep93xx_eth_close");
  241. writel(0x00000000, &mac->rxctl);
  242. writel(0x00000000, &mac->txctl);
  243. debug("-ep93xx_eth_close");
  244. }
  245. /**
  246. * Copy a frame of data from the MAC into the protocol layer for further
  247. * processing.
  248. */
  249. static int ep93xx_eth_rcv_packet(struct eth_device *dev)
  250. {
  251. struct mac_regs *mac = GET_REGS(dev);
  252. struct ep93xx_priv *priv = GET_PRIV(dev);
  253. int len = -1;
  254. debug("+ep93xx_eth_rcv_packet");
  255. if (RX_STATUS_RFP(priv->rx_sq.current)) {
  256. if (RX_STATUS_RWE(priv->rx_sq.current)) {
  257. /*
  258. * We have a good frame. Extract the frame's length
  259. * from the current rx_status_queue entry, and copy
  260. * the frame's data into NetRxPackets[] of the
  261. * protocol stack. We track the total number of
  262. * bytes in the frame (nbytes_frame) which will be
  263. * used when we pass the data off to the protocol
  264. * layer via NetReceive().
  265. */
  266. len = RX_STATUS_FRAME_LEN(priv->rx_sq.current);
  267. NetReceive((uchar *)priv->rx_dq.current->word1, len);
  268. debug("reporting %d bytes...\n", len);
  269. } else {
  270. /* Do we have an erroneous packet? */
  271. error("packet rx error, status %08X %08X",
  272. priv->rx_sq.current->word1,
  273. priv->rx_sq.current->word2);
  274. dump_rx_descriptor_queue(dev);
  275. dump_rx_status_queue(dev);
  276. }
  277. /*
  278. * Clear the associated status queue entry, and
  279. * increment our current pointers to the next RX
  280. * descriptor and status queue entries (making sure
  281. * we wrap properly).
  282. */
  283. memset((void *)priv->rx_sq.current, 0,
  284. sizeof(struct rx_status));
  285. priv->rx_sq.current++;
  286. if (priv->rx_sq.current >= priv->rx_sq.end)
  287. priv->rx_sq.current = priv->rx_sq.base;
  288. priv->rx_dq.current++;
  289. if (priv->rx_dq.current >= priv->rx_dq.end)
  290. priv->rx_dq.current = priv->rx_dq.base;
  291. /*
  292. * Finally, return the RX descriptor and status entries
  293. * back to the MAC engine, and loop again, checking for
  294. * more descriptors to process.
  295. */
  296. writel(1, &mac->rxdqenq);
  297. writel(1, &mac->rxstsqenq);
  298. } else {
  299. len = 0;
  300. }
  301. debug("-ep93xx_eth_rcv_packet %d", len);
  302. return len;
  303. }
  304. /**
  305. * Send a block of data via ethernet.
  306. */
  307. static int ep93xx_eth_send_packet(struct eth_device *dev,
  308. void * const packet, int const length)
  309. {
  310. struct mac_regs *mac = GET_REGS(dev);
  311. struct ep93xx_priv *priv = GET_PRIV(dev);
  312. int ret = -1;
  313. debug("+ep93xx_eth_send_packet");
  314. /* Parameter check */
  315. BUG_ON(packet == NULL);
  316. /*
  317. * Initialize the TX descriptor queue with the new packet's info.
  318. * Clear the associated status queue entry. Enqueue the packet
  319. * to the MAC for transmission.
  320. */
  321. /* set buffer address */
  322. priv->tx_dq.current->word1 = (uint32_t)packet;
  323. /* set buffer length and EOF bit */
  324. priv->tx_dq.current->word2 = length | TX_DESC_EOF;
  325. /* clear tx status */
  326. priv->tx_sq.current->word1 = 0;
  327. /* enqueue the TX descriptor */
  328. writel(1, &mac->txdqenq);
  329. /* wait for the frame to become processed */
  330. while (!TX_STATUS_TXFP(priv->tx_sq.current))
  331. ; /* noop */
  332. if (!TX_STATUS_TXWE(priv->tx_sq.current)) {
  333. error("packet tx error, status %08X",
  334. priv->tx_sq.current->word1);
  335. dump_tx_descriptor_queue(dev);
  336. dump_tx_status_queue(dev);
  337. /* TODO: Add better error handling? */
  338. goto eth_send_out;
  339. }
  340. ret = 0;
  341. /* Fall through */
  342. eth_send_out:
  343. debug("-ep93xx_eth_send_packet %d", ret);
  344. return ret;
  345. }
  346. #if defined(CONFIG_MII)
  347. int ep93xx_miiphy_initialize(bd_t * const bd)
  348. {
  349. miiphy_register("ep93xx_eth0", ep93xx_miiphy_read, ep93xx_miiphy_write);
  350. return 0;
  351. }
  352. #endif
  353. /**
  354. * Initialize the EP93xx MAC. The MAC hardware is reset. Buffers are
  355. * allocated, if necessary, for the TX and RX descriptor and status queues,
  356. * as well as for received packets. The EP93XX MAC hardware is initialized.
  357. * Transmit and receive operations are enabled.
  358. */
  359. int ep93xx_eth_initialize(u8 dev_num, int base_addr)
  360. {
  361. int ret = -1;
  362. struct eth_device *dev;
  363. struct ep93xx_priv *priv;
  364. debug("+ep93xx_eth_initialize");
  365. priv = malloc(sizeof(*priv));
  366. if (!priv) {
  367. error("malloc() failed");
  368. goto eth_init_failed_0;
  369. }
  370. memset(priv, 0, sizeof(*priv));
  371. priv->regs = (struct mac_regs *)base_addr;
  372. priv->tx_dq.base = calloc(NUMTXDESC,
  373. sizeof(struct tx_descriptor));
  374. if (priv->tx_dq.base == NULL) {
  375. error("calloc() failed");
  376. goto eth_init_failed_1;
  377. }
  378. priv->tx_sq.base = calloc(NUMTXDESC,
  379. sizeof(struct tx_status));
  380. if (priv->tx_sq.base == NULL) {
  381. error("calloc() failed");
  382. goto eth_init_failed_2;
  383. }
  384. priv->rx_dq.base = calloc(NUMRXDESC,
  385. sizeof(struct rx_descriptor));
  386. if (priv->rx_dq.base == NULL) {
  387. error("calloc() failed");
  388. goto eth_init_failed_3;
  389. }
  390. priv->rx_sq.base = calloc(NUMRXDESC,
  391. sizeof(struct rx_status));
  392. if (priv->rx_sq.base == NULL) {
  393. error("calloc() failed");
  394. goto eth_init_failed_4;
  395. }
  396. dev = malloc(sizeof *dev);
  397. if (dev == NULL) {
  398. error("malloc() failed");
  399. goto eth_init_failed_5;
  400. }
  401. memset(dev, 0, sizeof *dev);
  402. dev->iobase = base_addr;
  403. dev->priv = priv;
  404. dev->init = ep93xx_eth_open;
  405. dev->halt = ep93xx_eth_close;
  406. dev->send = ep93xx_eth_send_packet;
  407. dev->recv = ep93xx_eth_rcv_packet;
  408. sprintf(dev->name, "ep93xx_eth-%hu", dev_num);
  409. eth_register(dev);
  410. /* Done! */
  411. ret = 1;
  412. goto eth_init_done;
  413. eth_init_failed_5:
  414. free(priv->rx_sq.base);
  415. /* Fall through */
  416. eth_init_failed_4:
  417. free(priv->rx_dq.base);
  418. /* Fall through */
  419. eth_init_failed_3:
  420. free(priv->tx_sq.base);
  421. /* Fall through */
  422. eth_init_failed_2:
  423. free(priv->tx_dq.base);
  424. /* Fall through */
  425. eth_init_failed_1:
  426. free(priv);
  427. /* Fall through */
  428. eth_init_failed_0:
  429. /* Fall through */
  430. eth_init_done:
  431. debug("-ep93xx_eth_initialize %d", ret);
  432. return ret;
  433. }
  434. #if defined(CONFIG_MII)
  435. /**
  436. * Maximum MII address we support
  437. */
  438. #define MII_ADDRESS_MAX 31
  439. /**
  440. * Maximum MII register address we support
  441. */
  442. #define MII_REGISTER_MAX 31
  443. /**
  444. * Read a 16-bit value from an MII register.
  445. */
  446. static int ep93xx_miiphy_read(const char * const dev, unsigned char const addr,
  447. unsigned char const reg, unsigned short * const value)
  448. {
  449. struct mac_regs *mac = (struct mac_regs *)MAC_BASE;
  450. int ret = -1;
  451. uint32_t self_ctl;
  452. debug("+ep93xx_miiphy_read");
  453. /* Parameter checks */
  454. BUG_ON(dev == NULL);
  455. BUG_ON(addr > MII_ADDRESS_MAX);
  456. BUG_ON(reg > MII_REGISTER_MAX);
  457. BUG_ON(value == NULL);
  458. /*
  459. * Save the current SelfCTL register value. Set MAC to suppress
  460. * preamble bits. Wait for any previous MII command to complete
  461. * before issuing the new command.
  462. */
  463. self_ctl = readl(&mac->selfctl);
  464. #if defined(CONFIG_MII_SUPPRESS_PREAMBLE)
  465. writel(self_ctl & ~(1 << 8), &mac->selfctl);
  466. #endif /* defined(CONFIG_MII_SUPPRESS_PREAMBLE) */
  467. while (readl(&mac->miists) & MIISTS_BUSY)
  468. ; /* noop */
  469. /*
  470. * Issue the MII 'read' command. Wait for the command to complete.
  471. * Read the MII data value.
  472. */
  473. writel(MIICMD_OPCODE_READ | ((uint32_t)addr << 5) | (uint32_t)reg,
  474. &mac->miicmd);
  475. while (readl(&mac->miists) & MIISTS_BUSY)
  476. ; /* noop */
  477. *value = (unsigned short)readl(&mac->miidata);
  478. /* Restore the saved SelfCTL value and return. */
  479. writel(self_ctl, &mac->selfctl);
  480. ret = 0;
  481. /* Fall through */
  482. debug("-ep93xx_miiphy_read");
  483. return ret;
  484. }
  485. /**
  486. * Write a 16-bit value to an MII register.
  487. */
  488. static int ep93xx_miiphy_write(const char * const dev, unsigned char const addr,
  489. unsigned char const reg, unsigned short const value)
  490. {
  491. struct mac_regs *mac = (struct mac_regs *)MAC_BASE;
  492. int ret = -1;
  493. uint32_t self_ctl;
  494. debug("+ep93xx_miiphy_write");
  495. /* Parameter checks */
  496. BUG_ON(dev == NULL);
  497. BUG_ON(addr > MII_ADDRESS_MAX);
  498. BUG_ON(reg > MII_REGISTER_MAX);
  499. /*
  500. * Save the current SelfCTL register value. Set MAC to suppress
  501. * preamble bits. Wait for any previous MII command to complete
  502. * before issuing the new command.
  503. */
  504. self_ctl = readl(&mac->selfctl);
  505. #if defined(CONFIG_MII_SUPPRESS_PREAMBLE)
  506. writel(self_ctl & ~(1 << 8), &mac->selfctl);
  507. #endif /* defined(CONFIG_MII_SUPPRESS_PREAMBLE) */
  508. while (readl(&mac->miists) & MIISTS_BUSY)
  509. ; /* noop */
  510. /* Issue the MII 'write' command. Wait for the command to complete. */
  511. writel((uint32_t)value, &mac->miidata);
  512. writel(MIICMD_OPCODE_WRITE | ((uint32_t)addr << 5) | (uint32_t)reg,
  513. &mac->miicmd);
  514. while (readl(&mac->miists) & MIISTS_BUSY)
  515. ; /* noop */
  516. /* Restore the saved SelfCTL value and return. */
  517. writel(self_ctl, &mac->selfctl);
  518. ret = 0;
  519. /* Fall through */
  520. debug("-ep93xx_miiphy_write");
  521. return ret;
  522. }
  523. #endif /* defined(CONFIG_MII) */