ep93xx_eth.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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, net_rx_packets[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)net_rx_packets[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 net_rx_packets[] 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 net_process_received_packet().
  265. */
  266. len = RX_STATUS_FRAME_LEN(priv->rx_sq.current);
  267. net_process_received_packet(
  268. (uchar *)priv->rx_dq.current->word1, len);
  269. debug("reporting %d bytes...\n", len);
  270. } else {
  271. /* Do we have an erroneous packet? */
  272. error("packet rx error, status %08X %08X",
  273. priv->rx_sq.current->word1,
  274. priv->rx_sq.current->word2);
  275. dump_rx_descriptor_queue(dev);
  276. dump_rx_status_queue(dev);
  277. }
  278. /*
  279. * Clear the associated status queue entry, and
  280. * increment our current pointers to the next RX
  281. * descriptor and status queue entries (making sure
  282. * we wrap properly).
  283. */
  284. memset((void *)priv->rx_sq.current, 0,
  285. sizeof(struct rx_status));
  286. priv->rx_sq.current++;
  287. if (priv->rx_sq.current >= priv->rx_sq.end)
  288. priv->rx_sq.current = priv->rx_sq.base;
  289. priv->rx_dq.current++;
  290. if (priv->rx_dq.current >= priv->rx_dq.end)
  291. priv->rx_dq.current = priv->rx_dq.base;
  292. /*
  293. * Finally, return the RX descriptor and status entries
  294. * back to the MAC engine, and loop again, checking for
  295. * more descriptors to process.
  296. */
  297. writel(1, &mac->rxdqenq);
  298. writel(1, &mac->rxstsqenq);
  299. } else {
  300. len = 0;
  301. }
  302. debug("-ep93xx_eth_rcv_packet %d", len);
  303. return len;
  304. }
  305. /**
  306. * Send a block of data via ethernet.
  307. */
  308. static int ep93xx_eth_send_packet(struct eth_device *dev,
  309. void * const packet, int const length)
  310. {
  311. struct mac_regs *mac = GET_REGS(dev);
  312. struct ep93xx_priv *priv = GET_PRIV(dev);
  313. int ret = -1;
  314. debug("+ep93xx_eth_send_packet");
  315. /* Parameter check */
  316. BUG_ON(packet == NULL);
  317. /*
  318. * Initialize the TX descriptor queue with the new packet's info.
  319. * Clear the associated status queue entry. Enqueue the packet
  320. * to the MAC for transmission.
  321. */
  322. /* set buffer address */
  323. priv->tx_dq.current->word1 = (uint32_t)packet;
  324. /* set buffer length and EOF bit */
  325. priv->tx_dq.current->word2 = length | TX_DESC_EOF;
  326. /* clear tx status */
  327. priv->tx_sq.current->word1 = 0;
  328. /* enqueue the TX descriptor */
  329. writel(1, &mac->txdqenq);
  330. /* wait for the frame to become processed */
  331. while (!TX_STATUS_TXFP(priv->tx_sq.current))
  332. ; /* noop */
  333. if (!TX_STATUS_TXWE(priv->tx_sq.current)) {
  334. error("packet tx error, status %08X",
  335. priv->tx_sq.current->word1);
  336. dump_tx_descriptor_queue(dev);
  337. dump_tx_status_queue(dev);
  338. /* TODO: Add better error handling? */
  339. goto eth_send_out;
  340. }
  341. ret = 0;
  342. /* Fall through */
  343. eth_send_out:
  344. debug("-ep93xx_eth_send_packet %d", ret);
  345. return ret;
  346. }
  347. #if defined(CONFIG_MII)
  348. int ep93xx_miiphy_initialize(bd_t * const bd)
  349. {
  350. miiphy_register("ep93xx_eth0", ep93xx_miiphy_read, ep93xx_miiphy_write);
  351. return 0;
  352. }
  353. #endif
  354. /**
  355. * Initialize the EP93xx MAC. The MAC hardware is reset. Buffers are
  356. * allocated, if necessary, for the TX and RX descriptor and status queues,
  357. * as well as for received packets. The EP93XX MAC hardware is initialized.
  358. * Transmit and receive operations are enabled.
  359. */
  360. int ep93xx_eth_initialize(u8 dev_num, int base_addr)
  361. {
  362. int ret = -1;
  363. struct eth_device *dev;
  364. struct ep93xx_priv *priv;
  365. debug("+ep93xx_eth_initialize");
  366. priv = malloc(sizeof(*priv));
  367. if (!priv) {
  368. error("malloc() failed");
  369. goto eth_init_failed_0;
  370. }
  371. memset(priv, 0, sizeof(*priv));
  372. priv->regs = (struct mac_regs *)base_addr;
  373. priv->tx_dq.base = calloc(NUMTXDESC,
  374. sizeof(struct tx_descriptor));
  375. if (priv->tx_dq.base == NULL) {
  376. error("calloc() failed");
  377. goto eth_init_failed_1;
  378. }
  379. priv->tx_sq.base = calloc(NUMTXDESC,
  380. sizeof(struct tx_status));
  381. if (priv->tx_sq.base == NULL) {
  382. error("calloc() failed");
  383. goto eth_init_failed_2;
  384. }
  385. priv->rx_dq.base = calloc(NUMRXDESC,
  386. sizeof(struct rx_descriptor));
  387. if (priv->rx_dq.base == NULL) {
  388. error("calloc() failed");
  389. goto eth_init_failed_3;
  390. }
  391. priv->rx_sq.base = calloc(NUMRXDESC,
  392. sizeof(struct rx_status));
  393. if (priv->rx_sq.base == NULL) {
  394. error("calloc() failed");
  395. goto eth_init_failed_4;
  396. }
  397. dev = malloc(sizeof *dev);
  398. if (dev == NULL) {
  399. error("malloc() failed");
  400. goto eth_init_failed_5;
  401. }
  402. memset(dev, 0, sizeof *dev);
  403. dev->iobase = base_addr;
  404. dev->priv = priv;
  405. dev->init = ep93xx_eth_open;
  406. dev->halt = ep93xx_eth_close;
  407. dev->send = ep93xx_eth_send_packet;
  408. dev->recv = ep93xx_eth_rcv_packet;
  409. sprintf(dev->name, "ep93xx_eth-%hu", dev_num);
  410. eth_register(dev);
  411. /* Done! */
  412. ret = 1;
  413. goto eth_init_done;
  414. eth_init_failed_5:
  415. free(priv->rx_sq.base);
  416. /* Fall through */
  417. eth_init_failed_4:
  418. free(priv->rx_dq.base);
  419. /* Fall through */
  420. eth_init_failed_3:
  421. free(priv->tx_sq.base);
  422. /* Fall through */
  423. eth_init_failed_2:
  424. free(priv->tx_dq.base);
  425. /* Fall through */
  426. eth_init_failed_1:
  427. free(priv);
  428. /* Fall through */
  429. eth_init_failed_0:
  430. /* Fall through */
  431. eth_init_done:
  432. debug("-ep93xx_eth_initialize %d", ret);
  433. return ret;
  434. }
  435. #if defined(CONFIG_MII)
  436. /**
  437. * Maximum MII address we support
  438. */
  439. #define MII_ADDRESS_MAX 31
  440. /**
  441. * Maximum MII register address we support
  442. */
  443. #define MII_REGISTER_MAX 31
  444. /**
  445. * Read a 16-bit value from an MII register.
  446. */
  447. static int ep93xx_miiphy_read(const char * const dev, unsigned char const addr,
  448. unsigned char const reg, unsigned short * const value)
  449. {
  450. struct mac_regs *mac = (struct mac_regs *)MAC_BASE;
  451. int ret = -1;
  452. uint32_t self_ctl;
  453. debug("+ep93xx_miiphy_read");
  454. /* Parameter checks */
  455. BUG_ON(dev == NULL);
  456. BUG_ON(addr > MII_ADDRESS_MAX);
  457. BUG_ON(reg > MII_REGISTER_MAX);
  458. BUG_ON(value == NULL);
  459. /*
  460. * Save the current SelfCTL register value. Set MAC to suppress
  461. * preamble bits. Wait for any previous MII command to complete
  462. * before issuing the new command.
  463. */
  464. self_ctl = readl(&mac->selfctl);
  465. #if defined(CONFIG_MII_SUPPRESS_PREAMBLE)
  466. writel(self_ctl & ~(1 << 8), &mac->selfctl);
  467. #endif /* defined(CONFIG_MII_SUPPRESS_PREAMBLE) */
  468. while (readl(&mac->miists) & MIISTS_BUSY)
  469. ; /* noop */
  470. /*
  471. * Issue the MII 'read' command. Wait for the command to complete.
  472. * Read the MII data value.
  473. */
  474. writel(MIICMD_OPCODE_READ | ((uint32_t)addr << 5) | (uint32_t)reg,
  475. &mac->miicmd);
  476. while (readl(&mac->miists) & MIISTS_BUSY)
  477. ; /* noop */
  478. *value = (unsigned short)readl(&mac->miidata);
  479. /* Restore the saved SelfCTL value and return. */
  480. writel(self_ctl, &mac->selfctl);
  481. ret = 0;
  482. /* Fall through */
  483. debug("-ep93xx_miiphy_read");
  484. return ret;
  485. }
  486. /**
  487. * Write a 16-bit value to an MII register.
  488. */
  489. static int ep93xx_miiphy_write(const char * const dev, unsigned char const addr,
  490. unsigned char const reg, unsigned short const value)
  491. {
  492. struct mac_regs *mac = (struct mac_regs *)MAC_BASE;
  493. int ret = -1;
  494. uint32_t self_ctl;
  495. debug("+ep93xx_miiphy_write");
  496. /* Parameter checks */
  497. BUG_ON(dev == NULL);
  498. BUG_ON(addr > MII_ADDRESS_MAX);
  499. BUG_ON(reg > MII_REGISTER_MAX);
  500. /*
  501. * Save the current SelfCTL register value. Set MAC to suppress
  502. * preamble bits. Wait for any previous MII command to complete
  503. * before issuing the new command.
  504. */
  505. self_ctl = readl(&mac->selfctl);
  506. #if defined(CONFIG_MII_SUPPRESS_PREAMBLE)
  507. writel(self_ctl & ~(1 << 8), &mac->selfctl);
  508. #endif /* defined(CONFIG_MII_SUPPRESS_PREAMBLE) */
  509. while (readl(&mac->miists) & MIISTS_BUSY)
  510. ; /* noop */
  511. /* Issue the MII 'write' command. Wait for the command to complete. */
  512. writel((uint32_t)value, &mac->miidata);
  513. writel(MIICMD_OPCODE_WRITE | ((uint32_t)addr << 5) | (uint32_t)reg,
  514. &mac->miicmd);
  515. while (readl(&mac->miists) & MIISTS_BUSY)
  516. ; /* noop */
  517. /* Restore the saved SelfCTL value and return. */
  518. writel(self_ctl, &mac->selfctl);
  519. ret = 0;
  520. /* Fall through */
  521. debug("-ep93xx_miiphy_write");
  522. return ret;
  523. }
  524. #endif /* defined(CONFIG_MII) */