sh_eth.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 SH_ETH_PHY_DELAY 50000
  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 = 1000;
  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. #define EDMR_INIT_CNT 1000
  120. static int sh_eth_reset(struct sh_eth_dev *eth)
  121. {
  122. int port = eth->port;
  123. #if defined(CONFIG_CPU_SH7763)
  124. int ret = 0, i;
  125. /* Start e-dmac transmitter and receiver */
  126. outl(EDSR_ENALL, EDSR(port));
  127. /* Perform a software reset and wait for it to complete */
  128. outl(EDMR_SRST, EDMR(port));
  129. for (i = 0; i < EDMR_INIT_CNT; i++) {
  130. if (!(inl(EDMR(port)) & EDMR_SRST))
  131. break;
  132. udelay(1000);
  133. }
  134. if (i == EDMR_INIT_CNT) {
  135. printf(SHETHER_NAME ": Software reset timeout\n");
  136. ret = -EIO;
  137. }
  138. return ret;
  139. #else
  140. outl(inl(EDMR(port)) | EDMR_SRST, EDMR(port));
  141. udelay(3000);
  142. outl(inl(EDMR(port)) & ~EDMR_SRST, EDMR(port));
  143. return 0;
  144. #endif
  145. }
  146. static int sh_eth_tx_desc_init(struct sh_eth_dev *eth)
  147. {
  148. int port = eth->port, i, ret = 0;
  149. u32 tmp_addr;
  150. struct sh_eth_info *port_info = &eth->port_info[port];
  151. struct tx_desc_s *cur_tx_desc;
  152. /*
  153. * Allocate tx descriptors. They must be TX_DESC_SIZE bytes aligned
  154. */
  155. port_info->tx_desc_malloc = malloc(NUM_TX_DESC *
  156. sizeof(struct tx_desc_s) +
  157. TX_DESC_SIZE - 1);
  158. if (!port_info->tx_desc_malloc) {
  159. printf(SHETHER_NAME ": malloc failed\n");
  160. ret = -ENOMEM;
  161. goto err;
  162. }
  163. tmp_addr = (u32) (((int)port_info->tx_desc_malloc + TX_DESC_SIZE - 1) &
  164. ~(TX_DESC_SIZE - 1));
  165. flush_cache_wback(tmp_addr, NUM_TX_DESC * sizeof(struct tx_desc_s));
  166. /* Make sure we use a P2 address (non-cacheable) */
  167. port_info->tx_desc_base = (struct tx_desc_s *)ADDR_TO_P2(tmp_addr);
  168. port_info->tx_desc_cur = port_info->tx_desc_base;
  169. /* Initialize all descriptors */
  170. for (cur_tx_desc = port_info->tx_desc_base, i = 0; i < NUM_TX_DESC;
  171. cur_tx_desc++, i++) {
  172. cur_tx_desc->td0 = 0x00;
  173. cur_tx_desc->td1 = 0x00;
  174. cur_tx_desc->td2 = 0x00;
  175. }
  176. /* Mark the end of the descriptors */
  177. cur_tx_desc--;
  178. cur_tx_desc->td0 |= TD_TDLE;
  179. /* Point the controller to the tx descriptor list. Must use physical
  180. addresses */
  181. outl(ADDR_TO_PHY(port_info->tx_desc_base), TDLAR(port));
  182. #if defined(CONFIG_CPU_SH7763)
  183. outl(ADDR_TO_PHY(port_info->tx_desc_base), TDFAR(port));
  184. outl(ADDR_TO_PHY(cur_tx_desc), TDFXR(port));
  185. outl(0x01, TDFFR(port));/* Last discriptor bit */
  186. #endif
  187. err:
  188. return ret;
  189. }
  190. static int sh_eth_rx_desc_init(struct sh_eth_dev *eth)
  191. {
  192. int port = eth->port, i , ret = 0;
  193. struct sh_eth_info *port_info = &eth->port_info[port];
  194. struct rx_desc_s *cur_rx_desc;
  195. u32 tmp_addr;
  196. u8 *rx_buf;
  197. /*
  198. * Allocate rx descriptors. They must be RX_DESC_SIZE bytes aligned
  199. */
  200. port_info->rx_desc_malloc = malloc(NUM_RX_DESC *
  201. sizeof(struct rx_desc_s) +
  202. RX_DESC_SIZE - 1);
  203. if (!port_info->rx_desc_malloc) {
  204. printf(SHETHER_NAME ": malloc failed\n");
  205. ret = -ENOMEM;
  206. goto err;
  207. }
  208. tmp_addr = (u32) (((int)port_info->rx_desc_malloc + RX_DESC_SIZE - 1) &
  209. ~(RX_DESC_SIZE - 1));
  210. flush_cache_wback(tmp_addr, NUM_RX_DESC * sizeof(struct rx_desc_s));
  211. /* Make sure we use a P2 address (non-cacheable) */
  212. port_info->rx_desc_base = (struct rx_desc_s *)ADDR_TO_P2(tmp_addr);
  213. port_info->rx_desc_cur = port_info->rx_desc_base;
  214. /*
  215. * Allocate rx data buffers. They must be 32 bytes aligned and in
  216. * P2 area
  217. */
  218. port_info->rx_buf_malloc = malloc(NUM_RX_DESC * MAX_BUF_SIZE + 31);
  219. if (!port_info->rx_buf_malloc) {
  220. printf(SHETHER_NAME ": malloc failed\n");
  221. ret = -ENOMEM;
  222. goto err_buf_malloc;
  223. }
  224. tmp_addr = (u32)(((int)port_info->rx_buf_malloc + (32 - 1)) &
  225. ~(32 - 1));
  226. port_info->rx_buf_base = (u8 *)ADDR_TO_P2(tmp_addr);
  227. /* Initialize all descriptors */
  228. for (cur_rx_desc = port_info->rx_desc_base,
  229. rx_buf = port_info->rx_buf_base, i = 0;
  230. i < NUM_RX_DESC; cur_rx_desc++, rx_buf += MAX_BUF_SIZE, i++) {
  231. cur_rx_desc->rd0 = RD_RACT;
  232. cur_rx_desc->rd1 = MAX_BUF_SIZE << 16;
  233. cur_rx_desc->rd2 = (u32) ADDR_TO_PHY(rx_buf);
  234. }
  235. /* Mark the end of the descriptors */
  236. cur_rx_desc--;
  237. cur_rx_desc->rd0 |= RD_RDLE;
  238. /* Point the controller to the rx descriptor list */
  239. outl(ADDR_TO_PHY(port_info->rx_desc_base), RDLAR(port));
  240. #if defined(CONFIG_CPU_SH7763)
  241. outl(ADDR_TO_PHY(port_info->rx_desc_base), RDFAR(port));
  242. outl(ADDR_TO_PHY(cur_rx_desc), RDFXR(port));
  243. outl(RDFFR_RDLF, RDFFR(port));
  244. #endif
  245. return ret;
  246. err_buf_malloc:
  247. free(port_info->rx_desc_malloc);
  248. port_info->rx_desc_malloc = NULL;
  249. err:
  250. return ret;
  251. }
  252. static void sh_eth_tx_desc_free(struct sh_eth_dev *eth)
  253. {
  254. int port = eth->port;
  255. struct sh_eth_info *port_info = &eth->port_info[port];
  256. if (port_info->tx_desc_malloc) {
  257. free(port_info->tx_desc_malloc);
  258. port_info->tx_desc_malloc = NULL;
  259. }
  260. }
  261. static void sh_eth_rx_desc_free(struct sh_eth_dev *eth)
  262. {
  263. int port = eth->port;
  264. struct sh_eth_info *port_info = &eth->port_info[port];
  265. if (port_info->rx_desc_malloc) {
  266. free(port_info->rx_desc_malloc);
  267. port_info->rx_desc_malloc = NULL;
  268. }
  269. if (port_info->rx_buf_malloc) {
  270. free(port_info->rx_buf_malloc);
  271. port_info->rx_buf_malloc = NULL;
  272. }
  273. }
  274. static int sh_eth_desc_init(struct sh_eth_dev *eth)
  275. {
  276. int ret = 0;
  277. ret = sh_eth_tx_desc_init(eth);
  278. if (ret)
  279. goto err_tx_init;
  280. ret = sh_eth_rx_desc_init(eth);
  281. if (ret)
  282. goto err_rx_init;
  283. return ret;
  284. err_rx_init:
  285. sh_eth_tx_desc_free(eth);
  286. err_tx_init:
  287. return ret;
  288. }
  289. static int sh_eth_phy_config(struct sh_eth_dev *eth)
  290. {
  291. int port = eth->port, ret = 0;
  292. struct sh_eth_info *port_info = &eth->port_info[port];
  293. struct eth_device *dev = port_info->dev;
  294. struct phy_device *phydev;
  295. phydev = phy_connect(miiphy_get_dev_by_name(dev->name),
  296. port_info->phy_addr, dev, PHY_INTERFACE_MODE_MII);
  297. port_info->phydev = phydev;
  298. phy_config(phydev);
  299. return ret;
  300. }
  301. static int sh_eth_config(struct sh_eth_dev *eth, bd_t *bd)
  302. {
  303. int port = eth->port, ret = 0;
  304. u32 val;
  305. struct sh_eth_info *port_info = &eth->port_info[port];
  306. struct eth_device *dev = port_info->dev;
  307. struct phy_device *phy;
  308. /* Configure e-dmac registers */
  309. outl((inl(EDMR(port)) & ~EMDR_DESC_R) | EDMR_EL, EDMR(port));
  310. outl(0, EESIPR(port));
  311. outl(0, TRSCER(port));
  312. outl(0, TFTR(port));
  313. outl((FIFO_SIZE_T | FIFO_SIZE_R), FDR(port));
  314. outl(RMCR_RST, RMCR(port));
  315. #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724)
  316. outl(0, RPADIR(port));
  317. #endif
  318. outl((FIFO_F_D_RFF | FIFO_F_D_RFD), FCFTR(port));
  319. /* Configure e-mac registers */
  320. #if defined(CONFIG_CPU_SH7757)
  321. outl(ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP |
  322. ECSIPR_MPDIP | ECSIPR_ICDIP, ECSIPR(port));
  323. #else
  324. outl(0, ECSIPR(port));
  325. #endif
  326. /* Set Mac address */
  327. val = dev->enetaddr[0] << 24 | dev->enetaddr[1] << 16 |
  328. dev->enetaddr[2] << 8 | dev->enetaddr[3];
  329. outl(val, MAHR(port));
  330. val = dev->enetaddr[4] << 8 | dev->enetaddr[5];
  331. outl(val, MALR(port));
  332. outl(RFLR_RFL_MIN, RFLR(port));
  333. #if !defined(CONFIG_CPU_SH7757) && !defined(CONFIG_CPU_SH7724)
  334. outl(0, PIPR(port));
  335. #endif
  336. #if !defined(CONFIG_CPU_SH7724)
  337. outl(APR_AP, APR(port));
  338. outl(MPR_MP, MPR(port));
  339. #endif
  340. #if defined(CONFIG_CPU_SH7763)
  341. outl(TPAUSER_TPAUSE, TPAUSER(port));
  342. #elif defined(CONFIG_CPU_SH7757)
  343. outl(TPAUSER_UNLIMITED, TPAUSER(port));
  344. #endif
  345. /* Configure phy */
  346. ret = sh_eth_phy_config(eth);
  347. if (ret) {
  348. printf(SHETHER_NAME ": phy config timeout\n");
  349. goto err_phy_cfg;
  350. }
  351. phy = port_info->phydev;
  352. phy_startup(phy);
  353. val = 0;
  354. /* Set the transfer speed */
  355. if (phy->speed == 100) {
  356. printf(SHETHER_NAME ": 100Base/");
  357. #ifdef CONFIG_CPU_SH7763
  358. outl(GECMR_100B, GECMR(port));
  359. #elif defined(CONFIG_CPU_SH7757)
  360. outl(1, RTRATE(port));
  361. #elif defined(CONFIG_CPU_SH7724)
  362. val = ECMR_RTM;
  363. #endif
  364. } else if (phy->speed == 10) {
  365. printf(SHETHER_NAME ": 10Base/");
  366. #ifdef CONFIG_CPU_SH7763
  367. outl(GECMR_10B, GECMR(port));
  368. #elif defined(CONFIG_CPU_SH7757)
  369. outl(0, RTRATE(port));
  370. #endif
  371. }
  372. /* Check if full duplex mode is supported by the phy */
  373. if (phy->duplex) {
  374. printf("Full\n");
  375. outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE|ECMR_DM), ECMR(port));
  376. } else {
  377. printf("Half\n");
  378. outl(val | (ECMR_CHG_DM|ECMR_RE|ECMR_TE), ECMR(port));
  379. }
  380. return ret;
  381. err_phy_cfg:
  382. return ret;
  383. }
  384. static void sh_eth_start(struct sh_eth_dev *eth)
  385. {
  386. /*
  387. * Enable the e-dmac receiver only. The transmitter will be enabled when
  388. * we have something to transmit
  389. */
  390. outl(EDRRR_R, EDRRR(eth->port));
  391. }
  392. static void sh_eth_stop(struct sh_eth_dev *eth)
  393. {
  394. outl(~EDRRR_R, EDRRR(eth->port));
  395. }
  396. int sh_eth_init(struct eth_device *dev, bd_t *bd)
  397. {
  398. int ret = 0;
  399. struct sh_eth_dev *eth = dev->priv;
  400. ret = sh_eth_reset(eth);
  401. if (ret)
  402. goto err;
  403. ret = sh_eth_desc_init(eth);
  404. if (ret)
  405. goto err;
  406. ret = sh_eth_config(eth, bd);
  407. if (ret)
  408. goto err_config;
  409. sh_eth_start(eth);
  410. return ret;
  411. err_config:
  412. sh_eth_tx_desc_free(eth);
  413. sh_eth_rx_desc_free(eth);
  414. err:
  415. return ret;
  416. }
  417. void sh_eth_halt(struct eth_device *dev)
  418. {
  419. struct sh_eth_dev *eth = dev->priv;
  420. sh_eth_stop(eth);
  421. }
  422. int sh_eth_initialize(bd_t *bd)
  423. {
  424. int ret = 0;
  425. struct sh_eth_dev *eth = NULL;
  426. struct eth_device *dev = NULL;
  427. eth = (struct sh_eth_dev *)malloc(sizeof(struct sh_eth_dev));
  428. if (!eth) {
  429. printf(SHETHER_NAME ": %s: malloc failed\n", __func__);
  430. ret = -ENOMEM;
  431. goto err;
  432. }
  433. dev = (struct eth_device *)malloc(sizeof(struct eth_device));
  434. if (!dev) {
  435. printf(SHETHER_NAME ": %s: malloc failed\n", __func__);
  436. ret = -ENOMEM;
  437. goto err;
  438. }
  439. memset(dev, 0, sizeof(struct eth_device));
  440. memset(eth, 0, sizeof(struct sh_eth_dev));
  441. eth->port = CONFIG_SH_ETHER_USE_PORT;
  442. eth->port_info[eth->port].phy_addr = CONFIG_SH_ETHER_PHY_ADDR;
  443. dev->priv = (void *)eth;
  444. dev->iobase = 0;
  445. dev->init = sh_eth_init;
  446. dev->halt = sh_eth_halt;
  447. dev->send = sh_eth_send;
  448. dev->recv = sh_eth_recv;
  449. eth->port_info[eth->port].dev = dev;
  450. sprintf(dev->name, SHETHER_NAME);
  451. /* Register Device to EtherNet subsystem */
  452. eth_register(dev);
  453. bb_miiphy_buses[0].priv = eth;
  454. miiphy_register(dev->name, bb_miiphy_read, bb_miiphy_write);
  455. if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr))
  456. puts("Please set MAC address\n");
  457. return ret;
  458. err:
  459. if (dev)
  460. free(dev);
  461. if (eth)
  462. free(eth);
  463. printf(SHETHER_NAME ": Failed\n");
  464. return ret;
  465. }
  466. /******* for bb_miiphy *******/
  467. static int sh_eth_bb_init(struct bb_miiphy_bus *bus)
  468. {
  469. return 0;
  470. }
  471. static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus)
  472. {
  473. struct sh_eth_dev *eth = bus->priv;
  474. int port = eth->port;
  475. outl(inl(PIR(port)) | PIR_MMD, PIR(port));
  476. return 0;
  477. }
  478. static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus)
  479. {
  480. struct sh_eth_dev *eth = bus->priv;
  481. int port = eth->port;
  482. outl(inl(PIR(port)) & ~PIR_MMD, PIR(port));
  483. return 0;
  484. }
  485. static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
  486. {
  487. struct sh_eth_dev *eth = bus->priv;
  488. int port = eth->port;
  489. if (v)
  490. outl(inl(PIR(port)) | PIR_MDO, PIR(port));
  491. else
  492. outl(inl(PIR(port)) & ~PIR_MDO, PIR(port));
  493. return 0;
  494. }
  495. static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
  496. {
  497. struct sh_eth_dev *eth = bus->priv;
  498. int port = eth->port;
  499. *v = (inl(PIR(port)) & PIR_MDI) >> 3;
  500. return 0;
  501. }
  502. static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
  503. {
  504. struct sh_eth_dev *eth = bus->priv;
  505. int port = eth->port;
  506. if (v)
  507. outl(inl(PIR(port)) | PIR_MDC, PIR(port));
  508. else
  509. outl(inl(PIR(port)) & ~PIR_MDC, PIR(port));
  510. return 0;
  511. }
  512. static int sh_eth_bb_delay(struct bb_miiphy_bus *bus)
  513. {
  514. udelay(10);
  515. return 0;
  516. }
  517. struct bb_miiphy_bus bb_miiphy_buses[] = {
  518. {
  519. .name = "sh_eth",
  520. .init = sh_eth_bb_init,
  521. .mdio_active = sh_eth_bb_mdio_active,
  522. .mdio_tristate = sh_eth_bb_mdio_tristate,
  523. .set_mdio = sh_eth_bb_set_mdio,
  524. .get_mdio = sh_eth_bb_get_mdio,
  525. .set_mdc = sh_eth_bb_set_mdc,
  526. .delay = sh_eth_bb_delay,
  527. }
  528. };
  529. int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);