davinci_emac.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /*
  2. * Ethernet driver for TI TMS320DM644x (DaVinci) chips.
  3. *
  4. * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
  5. *
  6. * Parts shamelessly stolen from TI's dm644x_emac.c. Original copyright
  7. * follows:
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * dm644x_emac.c
  12. *
  13. * TI DaVinci (DM644X) EMAC peripheral driver source for DV-EVM
  14. *
  15. * Copyright (C) 2005 Texas Instruments.
  16. *
  17. * ----------------------------------------------------------------------------
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License as published by
  21. * the Free Software Foundation; either version 2 of the License, or
  22. * (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. * ----------------------------------------------------------------------------
  33. * Modifications:
  34. * ver. 1.0: Sep 2005, Anant Gole - Created EMAC version for uBoot.
  35. * ver 1.1: Nov 2005, Anant Gole - Extended the RX logic for multiple descriptors
  36. *
  37. */
  38. #include <common.h>
  39. #include <command.h>
  40. #include <net.h>
  41. #include <miiphy.h>
  42. #include <asm/arch/emac_defs.h>
  43. unsigned int emac_dbg = 0;
  44. #define debug_emac(fmt,args...) if (emac_dbg) printf(fmt,##args)
  45. /* Internal static functions */
  46. static int davinci_eth_hw_init (void);
  47. static int davinci_eth_open (void);
  48. static int davinci_eth_close (void);
  49. static int davinci_eth_send_packet (volatile void *packet, int length);
  50. static int davinci_eth_rcv_packet (void);
  51. static void davinci_eth_mdio_enable(void);
  52. static int gen_init_phy(int phy_addr);
  53. static int gen_is_phy_connected(int phy_addr);
  54. static int gen_get_link_speed(int phy_addr);
  55. static int gen_auto_negotiate(int phy_addr);
  56. /* Wrappers exported to the U-Boot proper */
  57. int eth_hw_init(void)
  58. {
  59. return(davinci_eth_hw_init());
  60. }
  61. int eth_init(bd_t * bd)
  62. {
  63. return(davinci_eth_open());
  64. }
  65. void eth_halt(void)
  66. {
  67. davinci_eth_close();
  68. }
  69. int eth_send(volatile void *packet, int length)
  70. {
  71. return(davinci_eth_send_packet(packet, length));
  72. }
  73. int eth_rx(void)
  74. {
  75. return(davinci_eth_rcv_packet());
  76. }
  77. void eth_mdio_enable(void)
  78. {
  79. davinci_eth_mdio_enable();
  80. }
  81. /* End of wrappers */
  82. static u_int8_t davinci_eth_mac_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  83. /*
  84. * This function must be called before emac_open() if you want to override
  85. * the default mac address.
  86. */
  87. void davinci_eth_set_mac_addr(const u_int8_t *addr)
  88. {
  89. int i;
  90. for (i = 0; i < sizeof (davinci_eth_mac_addr); i++) {
  91. davinci_eth_mac_addr[i] = addr[i];
  92. }
  93. }
  94. /* EMAC Addresses */
  95. static volatile emac_regs *adap_emac = (emac_regs *)EMAC_BASE_ADDR;
  96. static volatile ewrap_regs *adap_ewrap = (ewrap_regs *)EMAC_WRAPPER_BASE_ADDR;
  97. static volatile mdio_regs *adap_mdio = (mdio_regs *)EMAC_MDIO_BASE_ADDR;
  98. /* EMAC descriptors */
  99. static volatile emac_desc *emac_rx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_RX_DESC_BASE);
  100. static volatile emac_desc *emac_tx_desc = (emac_desc *)(EMAC_WRAPPER_RAM_ADDR + EMAC_TX_DESC_BASE);
  101. static volatile emac_desc *emac_rx_active_head = 0;
  102. static volatile emac_desc *emac_rx_active_tail = 0;
  103. static int emac_rx_queue_active = 0;
  104. /* Receive packet buffers */
  105. static unsigned char emac_rx_buffers[EMAC_MAX_RX_BUFFERS * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
  106. /* PHY address for a discovered PHY (0xff - not found) */
  107. static volatile u_int8_t active_phy_addr = 0xff;
  108. phy_t phy;
  109. static void davinci_eth_mdio_enable(void)
  110. {
  111. u_int32_t clkdiv;
  112. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  113. adap_mdio->CONTROL = (clkdiv & 0xff) |
  114. MDIO_CONTROL_ENABLE |
  115. MDIO_CONTROL_FAULT |
  116. MDIO_CONTROL_FAULT_ENABLE;
  117. while (adap_mdio->CONTROL & MDIO_CONTROL_IDLE) {;}
  118. }
  119. /*
  120. * Tries to find an active connected PHY. Returns 1 if address if found.
  121. * If no active PHY (or more than one PHY) found returns 0.
  122. * Sets active_phy_addr variable.
  123. */
  124. static int davinci_eth_phy_detect(void)
  125. {
  126. u_int32_t phy_act_state;
  127. int i;
  128. active_phy_addr = 0xff;
  129. if ((phy_act_state = adap_mdio->ALIVE) == 0)
  130. return(0); /* No active PHYs */
  131. debug_emac("davinci_eth_phy_detect(), ALIVE = 0x%08x\n", phy_act_state);
  132. for (i = 0; i < 32; i++) {
  133. if (phy_act_state & (1 << i)) {
  134. if (phy_act_state & ~(1 << i))
  135. return(0); /* More than one PHY */
  136. else {
  137. active_phy_addr = i;
  138. return(1);
  139. }
  140. }
  141. }
  142. return(0); /* Just to make GCC happy */
  143. }
  144. /* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise */
  145. int davinci_eth_phy_read(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t *data)
  146. {
  147. int tmp;
  148. while (adap_mdio->USERACCESS0 & MDIO_USERACCESS0_GO) {;}
  149. adap_mdio->USERACCESS0 = MDIO_USERACCESS0_GO |
  150. MDIO_USERACCESS0_WRITE_READ |
  151. ((reg_num & 0x1f) << 21) |
  152. ((phy_addr & 0x1f) << 16);
  153. /* Wait for command to complete */
  154. while ((tmp = adap_mdio->USERACCESS0) & MDIO_USERACCESS0_GO) {;}
  155. if (tmp & MDIO_USERACCESS0_ACK) {
  156. *data = tmp & 0xffff;
  157. return(1);
  158. }
  159. *data = -1;
  160. return(0);
  161. }
  162. /* Write to a PHY register via MDIO inteface. Blocks until operation is complete. */
  163. int davinci_eth_phy_write(u_int8_t phy_addr, u_int8_t reg_num, u_int16_t data)
  164. {
  165. while (adap_mdio->USERACCESS0 & MDIO_USERACCESS0_GO) {;}
  166. adap_mdio->USERACCESS0 = MDIO_USERACCESS0_GO |
  167. MDIO_USERACCESS0_WRITE_WRITE |
  168. ((reg_num & 0x1f) << 21) |
  169. ((phy_addr & 0x1f) << 16) |
  170. (data & 0xffff);
  171. /* Wait for command to complete */
  172. while (adap_mdio->USERACCESS0 & MDIO_USERACCESS0_GO) {;}
  173. return(1);
  174. }
  175. /* PHY functions for a generic PHY */
  176. static int gen_init_phy(int phy_addr)
  177. {
  178. int ret = 1;
  179. if (gen_get_link_speed(phy_addr)) {
  180. /* Try another time */
  181. ret = gen_get_link_speed(phy_addr);
  182. }
  183. return(ret);
  184. }
  185. static int gen_is_phy_connected(int phy_addr)
  186. {
  187. u_int16_t dummy;
  188. return(davinci_eth_phy_read(phy_addr, PHY_PHYIDR1, &dummy));
  189. }
  190. static int gen_get_link_speed(int phy_addr)
  191. {
  192. u_int16_t tmp;
  193. if (davinci_eth_phy_read(phy_addr, MII_STATUS_REG, &tmp) && (tmp & 0x04))
  194. return(1);
  195. return(0);
  196. }
  197. static int gen_auto_negotiate(int phy_addr)
  198. {
  199. u_int16_t tmp;
  200. if (!davinci_eth_phy_read(phy_addr, PHY_BMCR, &tmp))
  201. return(0);
  202. /* Restart Auto_negotiation */
  203. tmp |= PHY_BMCR_AUTON;
  204. davinci_eth_phy_write(phy_addr, PHY_BMCR, tmp);
  205. /*check AutoNegotiate complete */
  206. udelay (10000);
  207. if (!davinci_eth_phy_read(phy_addr, PHY_BMSR, &tmp))
  208. return(0);
  209. if (!(tmp & PHY_BMSR_AUTN_COMP))
  210. return(0);
  211. return(gen_get_link_speed(phy_addr));
  212. }
  213. /* End of generic PHY functions */
  214. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  215. static int davinci_mii_phy_read(char *devname, unsigned char addr, unsigned char reg, unsigned short *value)
  216. {
  217. return(davinci_eth_phy_read(addr, reg, value) ? 0 : 1);
  218. }
  219. static int davinci_mii_phy_write(char *devname, unsigned char addr, unsigned char reg, unsigned short value)
  220. {
  221. return(davinci_eth_phy_write(addr, reg, value) ? 0 : 1);
  222. }
  223. int davinci_eth_miiphy_initialize(bd_t *bis)
  224. {
  225. miiphy_register(phy.name, davinci_mii_phy_read, davinci_mii_phy_write);
  226. return(1);
  227. }
  228. #endif
  229. /* Eth device open */
  230. static int davinci_eth_open(void)
  231. {
  232. dv_reg_p addr;
  233. u_int32_t clkdiv, cnt;
  234. volatile emac_desc *rx_desc;
  235. debug_emac("+ emac_open\n");
  236. /* Reset EMAC module and disable interrupts in wrapper */
  237. adap_emac->SOFTRESET = 1;
  238. while (adap_emac->SOFTRESET != 0) {;}
  239. adap_ewrap->EWCTL = 0;
  240. for (cnt = 0; cnt < 5; cnt++) {
  241. clkdiv = adap_ewrap->EWCTL;
  242. }
  243. rx_desc = emac_rx_desc;
  244. adap_emac->TXCONTROL = 0x01;
  245. adap_emac->RXCONTROL = 0x01;
  246. /* Set MAC Addresses & Init multicast Hash to 0 (disable any multicast receive) */
  247. /* Using channel 0 only - other channels are disabled */
  248. adap_emac->MACINDEX = 0;
  249. adap_emac->MACADDRHI =
  250. (davinci_eth_mac_addr[3] << 24) |
  251. (davinci_eth_mac_addr[2] << 16) |
  252. (davinci_eth_mac_addr[1] << 8) |
  253. (davinci_eth_mac_addr[0]);
  254. adap_emac->MACADDRLO =
  255. (davinci_eth_mac_addr[5] << 8) |
  256. (davinci_eth_mac_addr[4]);
  257. adap_emac->MACHASH1 = 0;
  258. adap_emac->MACHASH2 = 0;
  259. /* Set source MAC address - REQUIRED */
  260. adap_emac->MACSRCADDRHI =
  261. (davinci_eth_mac_addr[3] << 24) |
  262. (davinci_eth_mac_addr[2] << 16) |
  263. (davinci_eth_mac_addr[1] << 8) |
  264. (davinci_eth_mac_addr[0]);
  265. adap_emac->MACSRCADDRLO =
  266. (davinci_eth_mac_addr[4] << 8) |
  267. (davinci_eth_mac_addr[5]);
  268. /* Set DMA 8 TX / 8 RX Head pointers to 0 */
  269. addr = &adap_emac->TX0HDP;
  270. for(cnt = 0; cnt < 16; cnt++)
  271. *addr++ = 0;
  272. addr = &adap_emac->RX0HDP;
  273. for(cnt = 0; cnt < 16; cnt++)
  274. *addr++ = 0;
  275. /* Clear Statistics (do this before setting MacControl register) */
  276. addr = &adap_emac->RXGOODFRAMES;
  277. for(cnt = 0; cnt < EMAC_NUM_STATS; cnt++)
  278. *addr++ = 0;
  279. /* No multicast addressing */
  280. adap_emac->MACHASH1 = 0;
  281. adap_emac->MACHASH2 = 0;
  282. /* Create RX queue and set receive process in place */
  283. emac_rx_active_head = emac_rx_desc;
  284. for (cnt = 0; cnt < EMAC_MAX_RX_BUFFERS; cnt++) {
  285. rx_desc->next = (u_int32_t)(rx_desc + 1);
  286. rx_desc->buffer = &emac_rx_buffers[cnt * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)];
  287. rx_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
  288. rx_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
  289. rx_desc++;
  290. }
  291. /* Set the last descriptor's "next" parameter to 0 to end the RX desc list */
  292. rx_desc--;
  293. rx_desc->next = 0;
  294. emac_rx_active_tail = rx_desc;
  295. emac_rx_queue_active = 1;
  296. /* Enable TX/RX */
  297. adap_emac->RXMAXLEN = EMAC_MAX_ETHERNET_PKT_SIZE;
  298. adap_emac->RXBUFFEROFFSET = 0;
  299. /* No fancy configs - Use this for promiscous for debug - EMAC_RXMBPENABLE_RXCAFEN_ENABLE */
  300. adap_emac->RXMBPENABLE = EMAC_RXMBPENABLE_RXBROADEN;
  301. /* Enable ch 0 only */
  302. adap_emac->RXUNICASTSET = 0x01;
  303. /* Enable MII interface and Full duplex mode */
  304. adap_emac->MACCONTROL = (EMAC_MACCONTROL_MIIEN_ENABLE | EMAC_MACCONTROL_FULLDUPLEX_ENABLE);
  305. /* Init MDIO & get link state */
  306. clkdiv = (EMAC_MDIO_BUS_FREQ / EMAC_MDIO_CLOCK_FREQ) - 1;
  307. adap_mdio->CONTROL = ((clkdiv & 0xff) | MDIO_CONTROL_ENABLE | MDIO_CONTROL_FAULT);
  308. if (!phy.get_link_speed(active_phy_addr))
  309. return(0);
  310. /* Start receive process */
  311. adap_emac->RX0HDP = (u_int32_t)emac_rx_desc;
  312. debug_emac("- emac_open\n");
  313. return(1);
  314. }
  315. /* EMAC Channel Teardown */
  316. static void davinci_eth_ch_teardown(int ch)
  317. {
  318. dv_reg dly = 0xff;
  319. dv_reg cnt;
  320. debug_emac("+ emac_ch_teardown\n");
  321. if (ch == EMAC_CH_TX) {
  322. /* Init TX channel teardown */
  323. adap_emac->TXTEARDOWN = 1;
  324. for(cnt = 0; cnt != 0xfffffffc; cnt = adap_emac->TX0CP) {
  325. /* Wait here for Tx teardown completion interrupt to occur
  326. * Note: A task delay can be called here to pend rather than
  327. * occupying CPU cycles - anyway it has been found that teardown
  328. * takes very few cpu cycles and does not affect functionality */
  329. dly--;
  330. udelay(1);
  331. if (dly == 0)
  332. break;
  333. }
  334. adap_emac->TX0CP = cnt;
  335. adap_emac->TX0HDP = 0;
  336. } else {
  337. /* Init RX channel teardown */
  338. adap_emac->RXTEARDOWN = 1;
  339. for(cnt = 0; cnt != 0xfffffffc; cnt = adap_emac->RX0CP) {
  340. /* Wait here for Rx teardown completion interrupt to occur
  341. * Note: A task delay can be called here to pend rather than
  342. * occupying CPU cycles - anyway it has been found that teardown
  343. * takes very few cpu cycles and does not affect functionality */
  344. dly--;
  345. udelay(1);
  346. if (dly == 0)
  347. break;
  348. }
  349. adap_emac->RX0CP = cnt;
  350. adap_emac->RX0HDP = 0;
  351. }
  352. debug_emac("- emac_ch_teardown\n");
  353. }
  354. /* Eth device close */
  355. static int davinci_eth_close(void)
  356. {
  357. debug_emac("+ emac_close\n");
  358. davinci_eth_ch_teardown(EMAC_CH_TX); /* TX Channel teardown */
  359. davinci_eth_ch_teardown(EMAC_CH_RX); /* RX Channel teardown */
  360. /* Reset EMAC module and disable interrupts in wrapper */
  361. adap_emac->SOFTRESET = 1;
  362. adap_ewrap->EWCTL = 0;
  363. debug_emac("- emac_close\n");
  364. return(1);
  365. }
  366. static int tx_send_loop = 0;
  367. /*
  368. * This function sends a single packet on the network and returns
  369. * positive number (number of bytes transmitted) or negative for error
  370. */
  371. static int davinci_eth_send_packet (volatile void *packet, int length)
  372. {
  373. int ret_status = -1;
  374. tx_send_loop = 0;
  375. /* Return error if no link */
  376. if (!phy.get_link_speed (active_phy_addr)) {
  377. printf ("WARN: emac_send_packet: No link\n");
  378. return (ret_status);
  379. }
  380. /* Check packet size and if < EMAC_MIN_ETHERNET_PKT_SIZE, pad it up */
  381. if (length < EMAC_MIN_ETHERNET_PKT_SIZE) {
  382. length = EMAC_MIN_ETHERNET_PKT_SIZE;
  383. }
  384. /* Populate the TX descriptor */
  385. emac_tx_desc->next = 0;
  386. emac_tx_desc->buffer = (u_int8_t *) packet;
  387. emac_tx_desc->buff_off_len = (length & 0xffff);
  388. emac_tx_desc->pkt_flag_len = ((length & 0xffff) |
  389. EMAC_CPPI_SOP_BIT |
  390. EMAC_CPPI_OWNERSHIP_BIT |
  391. EMAC_CPPI_EOP_BIT);
  392. /* Send the packet */
  393. adap_emac->TX0HDP = (unsigned int) emac_tx_desc;
  394. /* Wait for packet to complete or link down */
  395. while (1) {
  396. if (!phy.get_link_speed (active_phy_addr)) {
  397. davinci_eth_ch_teardown (EMAC_CH_TX);
  398. return (ret_status);
  399. }
  400. if (adap_emac->TXINTSTATRAW & 0x01) {
  401. ret_status = length;
  402. break;
  403. }
  404. tx_send_loop++;
  405. }
  406. return (ret_status);
  407. }
  408. /*
  409. * This function handles receipt of a packet from the network
  410. */
  411. static int davinci_eth_rcv_packet (void)
  412. {
  413. volatile emac_desc *rx_curr_desc;
  414. volatile emac_desc *curr_desc;
  415. volatile emac_desc *tail_desc;
  416. int status, ret = -1;
  417. rx_curr_desc = emac_rx_active_head;
  418. status = rx_curr_desc->pkt_flag_len;
  419. if ((rx_curr_desc) && ((status & EMAC_CPPI_OWNERSHIP_BIT) == 0)) {
  420. if (status & EMAC_CPPI_RX_ERROR_FRAME) {
  421. /* Error in packet - discard it and requeue desc */
  422. printf ("WARN: emac_rcv_pkt: Error in packet\n");
  423. } else {
  424. NetReceive (rx_curr_desc->buffer,
  425. (rx_curr_desc->buff_off_len & 0xffff));
  426. ret = rx_curr_desc->buff_off_len & 0xffff;
  427. }
  428. /* Ack received packet descriptor */
  429. adap_emac->RX0CP = (unsigned int) rx_curr_desc;
  430. curr_desc = rx_curr_desc;
  431. emac_rx_active_head =
  432. (volatile emac_desc *) rx_curr_desc->next;
  433. if (status & EMAC_CPPI_EOQ_BIT) {
  434. if (emac_rx_active_head) {
  435. adap_emac->RX0HDP =
  436. (unsigned int) emac_rx_active_head;
  437. } else {
  438. emac_rx_queue_active = 0;
  439. printf ("INFO:emac_rcv_packet: RX Queue not active\n");
  440. }
  441. }
  442. /* Recycle RX descriptor */
  443. rx_curr_desc->buff_off_len = EMAC_MAX_ETHERNET_PKT_SIZE;
  444. rx_curr_desc->pkt_flag_len = EMAC_CPPI_OWNERSHIP_BIT;
  445. rx_curr_desc->next = 0;
  446. if (emac_rx_active_head == 0) {
  447. printf ("INFO: emac_rcv_pkt: active queue head = 0\n");
  448. emac_rx_active_head = curr_desc;
  449. emac_rx_active_tail = curr_desc;
  450. if (emac_rx_queue_active != 0) {
  451. adap_emac->RX0HDP =
  452. (unsigned int) emac_rx_active_head;
  453. printf ("INFO: emac_rcv_pkt: active queue head = 0, HDP fired\n");
  454. emac_rx_queue_active = 1;
  455. }
  456. } else {
  457. tail_desc = emac_rx_active_tail;
  458. emac_rx_active_tail = curr_desc;
  459. tail_desc->next = (unsigned int) curr_desc;
  460. status = tail_desc->pkt_flag_len;
  461. if (status & EMAC_CPPI_EOQ_BIT) {
  462. adap_emac->RX0HDP = (unsigned int) curr_desc;
  463. status &= ~EMAC_CPPI_EOQ_BIT;
  464. tail_desc->pkt_flag_len = status;
  465. }
  466. }
  467. return (ret);
  468. }
  469. return (0);
  470. }
  471. /*
  472. * This function initializes the emac hardware. It does NOT initialize
  473. * EMAC modules power or pin multiplexors, that is done by board_init()
  474. * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  475. */
  476. static int davinci_eth_hw_init(void)
  477. {
  478. u_int32_t phy_id;
  479. u_int16_t tmp;
  480. int i;
  481. davinci_eth_mdio_enable();
  482. for (i = 0; i < 256; i++) {
  483. if (adap_mdio->ALIVE)
  484. break;
  485. udelay(10);
  486. }
  487. if (i >= 256) {
  488. printf("No ETH PHY detected!!!\n");
  489. return(0);
  490. }
  491. /* Find if a PHY is connected and get it's address */
  492. if (!davinci_eth_phy_detect())
  493. return(0);
  494. /* Get PHY ID and initialize phy_ops for a detected PHY */
  495. if (!davinci_eth_phy_read(active_phy_addr, PHY_PHYIDR1, &tmp)) {
  496. active_phy_addr = 0xff;
  497. return(0);
  498. }
  499. phy_id = (tmp << 16) & 0xffff0000;
  500. if (!davinci_eth_phy_read(active_phy_addr, PHY_PHYIDR2, &tmp)) {
  501. active_phy_addr = 0xff;
  502. return(0);
  503. }
  504. phy_id |= tmp & 0x0000ffff;
  505. switch (phy_id) {
  506. case PHY_LXT972:
  507. sprintf(phy.name, "LXT972 @ 0x%02x", active_phy_addr);
  508. phy.init = lxt972_init_phy;
  509. phy.is_phy_connected = lxt972_is_phy_connected;
  510. phy.get_link_speed = lxt972_get_link_speed;
  511. phy.auto_negotiate = lxt972_auto_negotiate;
  512. break;
  513. case PHY_DP83848:
  514. sprintf(phy.name, "DP83848 @ 0x%02x", active_phy_addr);
  515. phy.init = dp83848_init_phy;
  516. phy.is_phy_connected = dp83848_is_phy_connected;
  517. phy.get_link_speed = dp83848_get_link_speed;
  518. phy.auto_negotiate = dp83848_auto_negotiate;
  519. break;
  520. default:
  521. sprintf(phy.name, "GENERIC @ 0x%02x", active_phy_addr);
  522. phy.init = gen_init_phy;
  523. phy.is_phy_connected = gen_is_phy_connected;
  524. phy.get_link_speed = gen_get_link_speed;
  525. phy.auto_negotiate = gen_auto_negotiate;
  526. }
  527. printf("Ethernet PHY: %s\n", phy.name);
  528. return(1);
  529. }