sh_eth.c 15 KB

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