ep93xx_eth.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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(struct mii_dev *bus, int addr, int devad,
  31. int reg);
  32. static int ep93xx_miiphy_write(struct mii_dev *bus, int addr, int devad,
  33. int reg, u16 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. int retval;
  351. struct mii_dev *mdiodev = mdio_alloc();
  352. if (!mdiodev)
  353. return -ENOMEM;
  354. strncpy(mdiodev->name, "ep93xx_eth0", MDIO_NAME_LEN);
  355. mdiodev->read = ep93xx_miiphy_read;
  356. mdiodev->write = ep93xx_miiphy_write;
  357. retval = mdio_register(mdiodev);
  358. if (retval < 0)
  359. return retval;
  360. return 0;
  361. }
  362. #endif
  363. /**
  364. * Initialize the EP93xx MAC. The MAC hardware is reset. Buffers are
  365. * allocated, if necessary, for the TX and RX descriptor and status queues,
  366. * as well as for received packets. The EP93XX MAC hardware is initialized.
  367. * Transmit and receive operations are enabled.
  368. */
  369. int ep93xx_eth_initialize(u8 dev_num, int base_addr)
  370. {
  371. int ret = -1;
  372. struct eth_device *dev;
  373. struct ep93xx_priv *priv;
  374. debug("+ep93xx_eth_initialize");
  375. priv = malloc(sizeof(*priv));
  376. if (!priv) {
  377. error("malloc() failed");
  378. goto eth_init_failed_0;
  379. }
  380. memset(priv, 0, sizeof(*priv));
  381. priv->regs = (struct mac_regs *)base_addr;
  382. priv->tx_dq.base = calloc(NUMTXDESC,
  383. sizeof(struct tx_descriptor));
  384. if (priv->tx_dq.base == NULL) {
  385. error("calloc() failed");
  386. goto eth_init_failed_1;
  387. }
  388. priv->tx_sq.base = calloc(NUMTXDESC,
  389. sizeof(struct tx_status));
  390. if (priv->tx_sq.base == NULL) {
  391. error("calloc() failed");
  392. goto eth_init_failed_2;
  393. }
  394. priv->rx_dq.base = calloc(NUMRXDESC,
  395. sizeof(struct rx_descriptor));
  396. if (priv->rx_dq.base == NULL) {
  397. error("calloc() failed");
  398. goto eth_init_failed_3;
  399. }
  400. priv->rx_sq.base = calloc(NUMRXDESC,
  401. sizeof(struct rx_status));
  402. if (priv->rx_sq.base == NULL) {
  403. error("calloc() failed");
  404. goto eth_init_failed_4;
  405. }
  406. dev = malloc(sizeof *dev);
  407. if (dev == NULL) {
  408. error("malloc() failed");
  409. goto eth_init_failed_5;
  410. }
  411. memset(dev, 0, sizeof *dev);
  412. dev->iobase = base_addr;
  413. dev->priv = priv;
  414. dev->init = ep93xx_eth_open;
  415. dev->halt = ep93xx_eth_close;
  416. dev->send = ep93xx_eth_send_packet;
  417. dev->recv = ep93xx_eth_rcv_packet;
  418. sprintf(dev->name, "ep93xx_eth-%hu", dev_num);
  419. eth_register(dev);
  420. /* Done! */
  421. ret = 1;
  422. goto eth_init_done;
  423. eth_init_failed_5:
  424. free(priv->rx_sq.base);
  425. /* Fall through */
  426. eth_init_failed_4:
  427. free(priv->rx_dq.base);
  428. /* Fall through */
  429. eth_init_failed_3:
  430. free(priv->tx_sq.base);
  431. /* Fall through */
  432. eth_init_failed_2:
  433. free(priv->tx_dq.base);
  434. /* Fall through */
  435. eth_init_failed_1:
  436. free(priv);
  437. /* Fall through */
  438. eth_init_failed_0:
  439. /* Fall through */
  440. eth_init_done:
  441. debug("-ep93xx_eth_initialize %d", ret);
  442. return ret;
  443. }
  444. #if defined(CONFIG_MII)
  445. /**
  446. * Maximum MII address we support
  447. */
  448. #define MII_ADDRESS_MAX 31
  449. /**
  450. * Maximum MII register address we support
  451. */
  452. #define MII_REGISTER_MAX 31
  453. /**
  454. * Read a 16-bit value from an MII register.
  455. */
  456. static int ep93xx_miiphy_read(struct mii_dev *bus, int addr, int devad,
  457. int reg)
  458. {
  459. unsigned short value = 0;
  460. struct mac_regs *mac = (struct mac_regs *)MAC_BASE;
  461. int ret = -1;
  462. uint32_t self_ctl;
  463. debug("+ep93xx_miiphy_read");
  464. /* Parameter checks */
  465. BUG_ON(bus->name == NULL);
  466. BUG_ON(addr > MII_ADDRESS_MAX);
  467. BUG_ON(reg > MII_REGISTER_MAX);
  468. /*
  469. * Save the current SelfCTL register value. Set MAC to suppress
  470. * preamble bits. Wait for any previous MII command to complete
  471. * before issuing the new command.
  472. */
  473. self_ctl = readl(&mac->selfctl);
  474. #if defined(CONFIG_MII_SUPPRESS_PREAMBLE)
  475. writel(self_ctl & ~(1 << 8), &mac->selfctl);
  476. #endif /* defined(CONFIG_MII_SUPPRESS_PREAMBLE) */
  477. while (readl(&mac->miists) & MIISTS_BUSY)
  478. ; /* noop */
  479. /*
  480. * Issue the MII 'read' command. Wait for the command to complete.
  481. * Read the MII data value.
  482. */
  483. writel(MIICMD_OPCODE_READ | ((uint32_t)addr << 5) | (uint32_t)reg,
  484. &mac->miicmd);
  485. while (readl(&mac->miists) & MIISTS_BUSY)
  486. ; /* noop */
  487. value = (unsigned short)readl(&mac->miidata);
  488. /* Restore the saved SelfCTL value and return. */
  489. writel(self_ctl, &mac->selfctl);
  490. ret = 0;
  491. /* Fall through */
  492. debug("-ep93xx_miiphy_read");
  493. if (ret < 0)
  494. return ret;
  495. return value;
  496. }
  497. /**
  498. * Write a 16-bit value to an MII register.
  499. */
  500. static int ep93xx_miiphy_write(struct mii_dev *bus, int addr, int devad,
  501. int reg, u16 value)
  502. {
  503. struct mac_regs *mac = (struct mac_regs *)MAC_BASE;
  504. int ret = -1;
  505. uint32_t self_ctl;
  506. debug("+ep93xx_miiphy_write");
  507. /* Parameter checks */
  508. BUG_ON(bus->name == NULL);
  509. BUG_ON(addr > MII_ADDRESS_MAX);
  510. BUG_ON(reg > MII_REGISTER_MAX);
  511. /*
  512. * Save the current SelfCTL register value. Set MAC to suppress
  513. * preamble bits. Wait for any previous MII command to complete
  514. * before issuing the new command.
  515. */
  516. self_ctl = readl(&mac->selfctl);
  517. #if defined(CONFIG_MII_SUPPRESS_PREAMBLE)
  518. writel(self_ctl & ~(1 << 8), &mac->selfctl);
  519. #endif /* defined(CONFIG_MII_SUPPRESS_PREAMBLE) */
  520. while (readl(&mac->miists) & MIISTS_BUSY)
  521. ; /* noop */
  522. /* Issue the MII 'write' command. Wait for the command to complete. */
  523. writel((uint32_t)value, &mac->miidata);
  524. writel(MIICMD_OPCODE_WRITE | ((uint32_t)addr << 5) | (uint32_t)reg,
  525. &mac->miicmd);
  526. while (readl(&mac->miists) & MIISTS_BUSY)
  527. ; /* noop */
  528. /* Restore the saved SelfCTL value and return. */
  529. writel(self_ctl, &mac->selfctl);
  530. ret = 0;
  531. /* Fall through */
  532. debug("-ep93xx_miiphy_write");
  533. return ret;
  534. }
  535. #endif /* defined(CONFIG_MII) */