davinci_emac.c 16 KB

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