ep93xx_eth.c 16 KB

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