sh_eth.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * sh_eth.c - Driver for Renesas SH7763's ethernet controler.
  3. *
  4. * Copyright (C) 2008, 2011 Renesas Solutions Corp.
  5. * Copyright (c) 2008, 2011 Nobuhiro Iwamatsu
  6. * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <config.h>
  23. #include <common.h>
  24. #include <malloc.h>
  25. #include <net.h>
  26. #include <netdev.h>
  27. #include <miiphy.h>
  28. #include <asm/errno.h>
  29. #include <asm/io.h>
  30. #include "sh_eth.h"
  31. #ifndef CONFIG_SH_ETHER_USE_PORT
  32. # error "Please define CONFIG_SH_ETHER_USE_PORT"
  33. #endif
  34. #ifndef CONFIG_SH_ETHER_PHY_ADDR
  35. # error "Please define CONFIG_SH_ETHER_PHY_ADDR"
  36. #endif
  37. #ifdef CONFIG_SH_ETHER_CACHE_WRITEBACK
  38. #define flush_cache_wback(addr, len) \
  39. dcache_wback_range((u32)addr, (u32)(addr + len - 1))
  40. #else
  41. #define flush_cache_wback(...)
  42. #endif
  43. #define TIMEOUT_CNT 1000
  44. int sh_eth_send(struct eth_device *dev, volatile void *packet, int len)
  45. {
  46. struct sh_eth_dev *eth = dev->priv;
  47. int port = eth->port, ret = 0, timeout;
  48. struct sh_eth_info *port_info = &eth->port_info[port];
  49. if (!packet || len > 0xffff) {
  50. printf(SHETHER_NAME ": %s: Invalid argument\n", __func__);
  51. ret = -EINVAL;
  52. goto err;
  53. }
  54. /* packet must be a 4 byte boundary */
  55. if ((int)packet & (4 - 1)) {
  56. printf(SHETHER_NAME ": %s: packet not 4 byte alligned\n", __func__);
  57. ret = -EFAULT;
  58. goto err;
  59. }
  60. /* Update tx descriptor */
  61. flush_cache_wback(packet, len);
  62. port_info->tx_desc_cur->td2 = ADDR_TO_PHY(packet);
  63. port_info->tx_desc_cur->td1 = len << 16;
  64. /* Must preserve the end of descriptor list indication */
  65. if (port_info->tx_desc_cur->td0 & TD_TDLE)
  66. port_info->tx_desc_cur->td0 = TD_TACT | TD_TFP | TD_TDLE;
  67. else
  68. port_info->tx_desc_cur->td0 = TD_TACT | TD_TFP;
  69. /* Restart the transmitter if disabled */
  70. if (!(inl(EDTRR(port)) & EDTRR_TRNS))
  71. outl(EDTRR_TRNS, EDTRR(port));
  72. /* Wait until packet is transmitted */
  73. timeout = TIMEOUT_CNT;
  74. while (port_info->tx_desc_cur->td0 & TD_TACT && timeout--)
  75. udelay(100);
  76. if (timeout < 0) {
  77. printf(SHETHER_NAME ": transmit timeout\n");
  78. ret = -ETIMEDOUT;
  79. goto err;
  80. }
  81. port_info->tx_desc_cur++;
  82. if (port_info->tx_desc_cur >= port_info->tx_desc_base + NUM_TX_DESC)
  83. port_info->tx_desc_cur = port_info->tx_desc_base;
  84. return ret;
  85. err:
  86. return ret;
  87. }
  88. int sh_eth_recv(struct eth_device *dev)
  89. {
  90. struct sh_eth_dev *eth = dev->priv;
  91. int port = eth->port, len = 0;
  92. struct sh_eth_info *port_info = &eth->port_info[port];
  93. volatile u8 *packet;
  94. /* Check if the rx descriptor is ready */
  95. if (!(port_info->rx_desc_cur->rd0 & RD_RACT)) {
  96. /* Check for errors */
  97. if (!(port_info->rx_desc_cur->rd0 & RD_RFE)) {
  98. len = port_info->rx_desc_cur->rd1 & 0xffff;
  99. packet = (volatile u8 *)
  100. ADDR_TO_P2(port_info->rx_desc_cur->rd2);
  101. NetReceive(packet, len);
  102. }
  103. /* Make current descriptor available again */
  104. if (port_info->rx_desc_cur->rd0 & RD_RDLE)
  105. port_info->rx_desc_cur->rd0 = RD_RACT | RD_RDLE;
  106. else
  107. port_info->rx_desc_cur->rd0 = RD_RACT;
  108. /* Point to the next descriptor */
  109. port_info->rx_desc_cur++;
  110. if (port_info->rx_desc_cur >=
  111. port_info->rx_desc_base + NUM_RX_DESC)
  112. port_info->rx_desc_cur = port_info->rx_desc_base;
  113. }
  114. /* Restart the receiver if disabled */
  115. if (!(inl(EDRRR(port)) & EDRRR_R))
  116. outl(EDRRR_R, EDRRR(port));
  117. return len;
  118. }
  119. static int sh_eth_reset(struct sh_eth_dev *eth)
  120. {
  121. int port = eth->port;
  122. #if defined(CONFIG_CPU_SH7763)
  123. int ret = 0, i;
  124. /* Start e-dmac transmitter and receiver */
  125. outl(EDSR_ENALL, EDSR(port));
  126. /* Perform a software reset and wait for it to complete */
  127. outl(EDMR_SRST, EDMR(port));
  128. for (i = 0; i < TIMEOUT_CNT ; i++) {
  129. if (!(inl(EDMR(port)) & EDMR_SRST))
  130. break;
  131. udelay(1000);
  132. }
  133. if (i == TIMEOUT_CNT) {
  134. printf(SHETHER_NAME ": Software reset timeout\n");
  135. ret = -EIO;
  136. }
  137. return ret;
  138. #else
  139. outl(inl(EDMR(port)) | EDMR_SRST, EDMR(port));
  140. udelay(3000);
  141. outl(inl(EDMR(port)) & ~EDMR_SRST, EDMR(port));
  142. return 0;
  143. #endif
  144. }
  145. static int sh_eth_tx_desc_init(struct sh_eth_dev *eth)
  146. {
  147. int port = eth->port, i, ret = 0;
  148. u32 tmp_addr;
  149. struct sh_eth_info *port_info = &eth->port_info[port];
  150. struct tx_desc_s *cur_tx_desc;
  151. /*
  152. * Allocate tx descriptors. They must be TX_DESC_SIZE bytes aligned
  153. */
  154. port_info->tx_desc_malloc = malloc(NUM_TX_DESC *
  155. sizeof(struct tx_desc_s) +
  156. TX_DESC_SIZE - 1);
  157. if (!port_info->tx_desc_malloc) {
  158. printf(SHETHER_NAME ": malloc failed\n");
  159. ret = -ENOMEM;
  160. goto err;
  161. }
  162. tmp_addr = (u32) (((int)port_info->tx_desc_malloc + TX_DESC_SIZE - 1) &
  163. ~(TX_DESC_SIZE - 1));
  164. flush_cache_wback(tmp_addr, NUM_TX_DESC * sizeof(struct tx_desc_s));
  165. /* Make sure we use a P2 address (non-cacheable) */
  166. port_info->tx_desc_base = (struct tx_desc_s *)ADDR_TO_P2(tmp_addr);
  167. port_info->tx_desc_cur = port_info->tx_desc_base;
  168. /* Initialize all descriptors */
  169. for (cur_tx_desc = port_info->tx_desc_base, i = 0; i < NUM_TX_DESC;
  170. cur_tx_desc++, i++) {
  171. cur_tx_desc->td0 = 0x00;
  172. cur_tx_desc->td1 = 0x00;
  173. cur_tx_desc->td2 = 0x00;
  174. }
  175. /* Mark the end of the descriptors */
  176. cur_tx_desc--;
  177. cur_tx_desc->td0 |= TD_TDLE;
  178. /* Point the controller to the tx descriptor list. Must use physical
  179. addresses */
  180. outl(ADDR_TO_PHY(port_info->tx_desc_base), TDLAR(port));
  181. #if defined(CONFIG_CPU_SH7763)
  182. outl(ADDR_TO_PHY(port_info->tx_desc_base), TDFAR(port));
  183. outl(ADDR_TO_PHY(cur_tx_desc), TDFXR(port));
  184. outl(0x01, TDFFR(port));/* Last discriptor bit */
  185. #endif
  186. err:
  187. return ret;
  188. }
  189. static int sh_eth_rx_desc_init(struct sh_eth_dev *eth)
  190. {
  191. int port = eth->port, i , ret = 0;
  192. struct sh_eth_info *port_info = &eth->port_info[port];
  193. struct rx_desc_s *cur_rx_desc;
  194. u32 tmp_addr;
  195. u8 *rx_buf;
  196. /*
  197. * Allocate rx descriptors. They must be RX_DESC_SIZE bytes aligned
  198. */
  199. port_info->rx_desc_malloc = malloc(NUM_RX_DESC *
  200. sizeof(struct rx_desc_s) +
  201. RX_DESC_SIZE - 1);
  202. if (!port_info->rx_desc_malloc) {
  203. printf(SHETHER_NAME ": malloc failed\n");
  204. ret = -ENOMEM;
  205. goto err;
  206. }
  207. tmp_addr = (u32) (((int)port_info->rx_desc_malloc + RX_DESC_SIZE - 1) &
  208. ~(RX_DESC_SIZE - 1));
  209. flush_cache_wback(tmp_addr, NUM_RX_DESC * sizeof(struct rx_desc_s));
  210. /* Make sure we use a P2 address (non-cacheable) */
  211. port_info->rx_desc_base = (struct rx_desc_s *)ADDR_TO_P2(tmp_addr);
  212. port_info->rx_desc_cur = port_info->rx_desc_base;
  213. /*
  214. * Allocate rx data buffers. They must be 32 bytes aligned and in
  215. * P2 area
  216. */
  217. port_info->rx_buf_malloc = malloc(NUM_RX_DESC * MAX_BUF_SIZE + 31);
  218. if (!port_info->rx_buf_malloc) {
  219. printf(SHETHER_NAME ": malloc failed\n");
  220. ret = -ENOMEM;
  221. goto err_buf_malloc;
  222. }
  223. tmp_addr = (u32)(((int)port_info->rx_buf_malloc + (32 - 1)) &
  224. ~(32 - 1));
  225. port_info->rx_buf_base = (u8 *)ADDR_TO_P2(tmp_addr);
  226. /* Initialize all descriptors */
  227. for (cur_rx_desc = port_info->rx_desc_base,
  228. rx_buf = port_info->rx_buf_base, i = 0;
  229. i < NUM_RX_DESC; cur_rx_desc++, rx_buf += MAX_BUF_SIZE, i++) {
  230. cur_rx_desc->rd0 = RD_RACT;
  231. cur_rx_desc->rd1 = MAX_BUF_SIZE << 16;
  232. cur_rx_desc->rd2 = (u32) ADDR_TO_PHY(rx_buf);
  233. }
  234. /* Mark the end of the descriptors */
  235. cur_rx_desc--;
  236. cur_rx_desc->rd0 |= RD_RDLE;
  237. /* Point the controller to the rx descriptor list */
  238. outl(ADDR_TO_PHY(port_info->rx_desc_base), RDLAR(port));
  239. #if defined(CONFIG_CPU_SH7763)
  240. outl(ADDR_TO_PHY(port_info->rx_desc_base), RDFAR(port));
  241. outl(ADDR_TO_PHY(cur_rx_desc), RDFXR(port));
  242. outl(RDFFR_RDLF, RDFFR(port));
  243. #endif
  244. return ret;
  245. err_buf_malloc:
  246. free(port_info->rx_desc_malloc);
  247. port_info->rx_desc_malloc = NULL;
  248. err:
  249. return ret;
  250. }
  251. static void sh_eth_tx_desc_free(struct sh_eth_dev *eth)
  252. {
  253. int port = eth->port;
  254. struct sh_eth_info *port_info = &eth->port_info[port];
  255. if (port_info->tx_desc_malloc) {
  256. free(port_info->tx_desc_malloc);
  257. port_info->tx_desc_malloc = NULL;
  258. }
  259. }
  260. static void sh_eth_rx_desc_free(struct sh_eth_dev *eth)
  261. {
  262. int port = eth->port;
  263. struct sh_eth_info *port_info = &eth->port_info[port];
  264. if (port_info->rx_desc_malloc) {
  265. free(port_info->rx_desc_malloc);
  266. port_info->rx_desc_malloc = NULL;
  267. }
  268. if (port_info->rx_buf_malloc) {
  269. free(port_info->rx_buf_malloc);
  270. port_info->rx_buf_malloc = NULL;
  271. }
  272. }
  273. static int sh_eth_desc_init(struct sh_eth_dev *eth)
  274. {
  275. int ret = 0;
  276. ret = sh_eth_tx_desc_init(eth);
  277. if (ret)
  278. goto err_tx_init;
  279. ret = sh_eth_rx_desc_init(eth);
  280. if (ret)
  281. goto err_rx_init;
  282. return ret;
  283. err_rx_init:
  284. sh_eth_tx_desc_free(eth);
  285. err_tx_init:
  286. return ret;
  287. }
  288. static int sh_eth_phy_config(struct sh_eth_dev *eth)
  289. {
  290. int port = eth->port, ret = 0;
  291. struct sh_eth_info *port_info = &eth->port_info[port];
  292. struct eth_device *dev = port_info->dev;
  293. struct phy_device *phydev;
  294. phydev = phy_connect(miiphy_get_dev_by_name(dev->name),
  295. port_info->phy_addr, dev, PHY_INTERFACE_MODE_MII);
  296. port_info->phydev = phydev;
  297. phy_config(phydev);
  298. return ret;
  299. }
  300. static int sh_eth_config(struct sh_eth_dev *eth, bd_t *bd)
  301. {
  302. int port = eth->port, ret = 0;
  303. u32 val;
  304. struct sh_eth_info *port_info = &eth->port_info[port];
  305. struct eth_device *dev = port_info->dev;
  306. struct phy_device *phy;
  307. /* Configure e-dmac registers */
  308. outl((inl(EDMR(port)) & ~EMDR_DESC_R) | EDMR_EL, EDMR(port));
  309. outl(0, EESIPR(port));
  310. outl(0, TRSCER(port));
  311. outl(0, TFTR(port));
  312. outl((FIFO_SIZE_T | FIFO_SIZE_R), FDR(port));
  313. outl(RMCR_RST, RMCR(port));
  314. #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724)
  315. outl(0, RPADIR(port));
  316. #endif
  317. outl((FIFO_F_D_RFF | FIFO_F_D_RFD), FCFTR(port));
  318. /* Configure e-mac registers */
  319. #if defined(CONFIG_CPU_SH7757)
  320. outl(ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP |
  321. ECSIPR_MPDIP | ECSIPR_ICDIP, ECSIPR(port));
  322. #else
  323. outl(0, ECSIPR(port));
  324. #endif
  325. /* Set Mac address */
  326. val = dev->enetaddr[0] << 24 | dev->enetaddr[1] << 16 |
  327. dev->enetaddr[2] << 8 | dev->enetaddr[3];
  328. outl(val, MAHR(port));
  329. val = dev->enetaddr[4] << 8 | dev->enetaddr[5];
  330. outl(val, MALR(port));
  331. outl(RFLR_RFL_MIN, RFLR(port));
  332. #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724)
  333. outl(0, PIPR(port));
  334. #endif
  335. #if !defined(CONFIG_CPU_SH7724)
  336. outl(APR_AP, APR(port));
  337. outl(MPR_MP, MPR(port));
  338. #endif
  339. #if defined(CONFIG_CPU_SH7763)
  340. outl(TPAUSER_TPAUSE, TPAUSER(port));
  341. #elif defined(CONFIG_CPU_SH7757)
  342. outl(TPAUSER_UNLIMITED, TPAUSER(port));
  343. #endif
  344. /* Configure phy */
  345. ret = sh_eth_phy_config(eth);
  346. if (ret) {
  347. printf(SHETHER_NAME ": phy config timeout\n");
  348. goto err_phy_cfg;
  349. }
  350. phy = port_info->phydev;
  351. phy_startup(phy);
  352. val = 0;
  353. /* Set the transfer speed */
  354. if (phy->speed == 100) {
  355. printf(SHETHER_NAME ": 100Base/");
  356. #ifdef CONFIG_CPU_SH7763
  357. outl(GECMR_100B, GECMR(port));
  358. #elif defined(CONFIG_CPU_SH7757)
  359. outl(1, RTRATE(port));
  360. #elif defined(CONFIG_CPU_SH7724)
  361. val = ECMR_RTM;
  362. #endif
  363. } else if (phy->speed == 10) {
  364. printf(SHETHER_NAME ": 10Base/");
  365. #ifdef CONFIG_CPU_SH7763
  366. outl(GECMR_10B, GECMR(port));
  367. #elif defined(CONFIG_CPU_SH7757)
  368. outl(0, RTRATE(port));
  369. #endif
  370. }
  371. /* Check if full duplex mode is supported by the phy */
  372. if (phy->duplex) {
  373. printf("Full\n");
  374. outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE|ECMR_DM), ECMR(port));
  375. } else {
  376. printf("Half\n");
  377. outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE), ECMR(port));
  378. }
  379. return ret;
  380. err_phy_cfg:
  381. return ret;
  382. }
  383. static void sh_eth_start(struct sh_eth_dev *eth)
  384. {
  385. /*
  386. * Enable the e-dmac receiver only. The transmitter will be enabled when
  387. * we have something to transmit
  388. */
  389. outl(EDRRR_R, EDRRR(eth->port));
  390. }
  391. static void sh_eth_stop(struct sh_eth_dev *eth)
  392. {
  393. outl(~EDRRR_R, EDRRR(eth->port));
  394. }
  395. int sh_eth_init(struct eth_device *dev, bd_t *bd)
  396. {
  397. int ret = 0;
  398. struct sh_eth_dev *eth = dev->priv;
  399. ret = sh_eth_reset(eth);
  400. if (ret)
  401. goto err;
  402. ret = sh_eth_desc_init(eth);
  403. if (ret)
  404. goto err;
  405. ret = sh_eth_config(eth, bd);
  406. if (ret)
  407. goto err_config;
  408. sh_eth_start(eth);
  409. return ret;
  410. err_config:
  411. sh_eth_tx_desc_free(eth);
  412. sh_eth_rx_desc_free(eth);
  413. err:
  414. return ret;
  415. }
  416. void sh_eth_halt(struct eth_device *dev)
  417. {
  418. struct sh_eth_dev *eth = dev->priv;
  419. sh_eth_stop(eth);
  420. }
  421. int sh_eth_initialize(bd_t *bd)
  422. {
  423. int ret = 0;
  424. struct sh_eth_dev *eth = NULL;
  425. struct eth_device *dev = NULL;
  426. eth = (struct sh_eth_dev *)malloc(sizeof(struct sh_eth_dev));
  427. if (!eth) {
  428. printf(SHETHER_NAME ": %s: malloc failed\n", __func__);
  429. ret = -ENOMEM;
  430. goto err;
  431. }
  432. dev = (struct eth_device *)malloc(sizeof(struct eth_device));
  433. if (!dev) {
  434. printf(SHETHER_NAME ": %s: malloc failed\n", __func__);
  435. ret = -ENOMEM;
  436. goto err;
  437. }
  438. memset(dev, 0, sizeof(struct eth_device));
  439. memset(eth, 0, sizeof(struct sh_eth_dev));
  440. eth->port = CONFIG_SH_ETHER_USE_PORT;
  441. eth->port_info[eth->port].phy_addr = CONFIG_SH_ETHER_PHY_ADDR;
  442. dev->priv = (void *)eth;
  443. dev->iobase = 0;
  444. dev->init = sh_eth_init;
  445. dev->halt = sh_eth_halt;
  446. dev->send = sh_eth_send;
  447. dev->recv = sh_eth_recv;
  448. eth->port_info[eth->port].dev = dev;
  449. sprintf(dev->name, SHETHER_NAME);
  450. /* Register Device to EtherNet subsystem */
  451. eth_register(dev);
  452. bb_miiphy_buses[0].priv = eth;
  453. miiphy_register(dev->name, bb_miiphy_read, bb_miiphy_write);
  454. if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr))
  455. puts("Please set MAC address\n");
  456. return ret;
  457. err:
  458. if (dev)
  459. free(dev);
  460. if (eth)
  461. free(eth);
  462. printf(SHETHER_NAME ": Failed\n");
  463. return ret;
  464. }
  465. /******* for bb_miiphy *******/
  466. static int sh_eth_bb_init(struct bb_miiphy_bus *bus)
  467. {
  468. return 0;
  469. }
  470. static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus)
  471. {
  472. struct sh_eth_dev *eth = bus->priv;
  473. int port = eth->port;
  474. outl(inl(PIR(port)) | PIR_MMD, PIR(port));
  475. return 0;
  476. }
  477. static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus)
  478. {
  479. struct sh_eth_dev *eth = bus->priv;
  480. int port = eth->port;
  481. outl(inl(PIR(port)) & ~PIR_MMD, PIR(port));
  482. return 0;
  483. }
  484. static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
  485. {
  486. struct sh_eth_dev *eth = bus->priv;
  487. int port = eth->port;
  488. if (v)
  489. outl(inl(PIR(port)) | PIR_MDO, PIR(port));
  490. else
  491. outl(inl(PIR(port)) & ~PIR_MDO, PIR(port));
  492. return 0;
  493. }
  494. static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
  495. {
  496. struct sh_eth_dev *eth = bus->priv;
  497. int port = eth->port;
  498. *v = (inl(PIR(port)) & PIR_MDI) >> 3;
  499. return 0;
  500. }
  501. static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
  502. {
  503. struct sh_eth_dev *eth = bus->priv;
  504. int port = eth->port;
  505. if (v)
  506. outl(inl(PIR(port)) | PIR_MDC, PIR(port));
  507. else
  508. outl(inl(PIR(port)) & ~PIR_MDC, PIR(port));
  509. return 0;
  510. }
  511. static int sh_eth_bb_delay(struct bb_miiphy_bus *bus)
  512. {
  513. udelay(10);
  514. return 0;
  515. }
  516. struct bb_miiphy_bus bb_miiphy_buses[] = {
  517. {
  518. .name = "sh_eth",
  519. .init = sh_eth_bb_init,
  520. .mdio_active = sh_eth_bb_mdio_active,
  521. .mdio_tristate = sh_eth_bb_mdio_tristate,
  522. .set_mdio = sh_eth_bb_set_mdio,
  523. .get_mdio = sh_eth_bb_get_mdio,
  524. .set_mdc = sh_eth_bb_set_mdc,
  525. .delay = sh_eth_bb_delay,
  526. }
  527. };
  528. int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);