sh_eth.c 16 KB

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