eth_p4080.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /*
  2. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <netdev.h>
  25. #include <asm/mmu.h>
  26. #include <asm/processor.h>
  27. #include <asm/cache.h>
  28. #include <asm/immap_85xx.h>
  29. #include <asm/fsl_law.h>
  30. #include <asm/fsl_ddr_sdram.h>
  31. #include <asm/fsl_serdes.h>
  32. #include <asm/fsl_portals.h>
  33. #include <asm/fsl_liodn.h>
  34. #include <malloc.h>
  35. #include <fm_eth.h>
  36. #include <fsl_mdio.h>
  37. #include <miiphy.h>
  38. #include <phy.h>
  39. #include "../common/ngpixis.h"
  40. #include "../common/fman.h"
  41. #include <asm/fsl_dtsec.h>
  42. #define EMI_NONE 0xffffffff
  43. #define EMI_MASK 0xf0000000
  44. #define EMI1_RGMII 0x0
  45. #define EMI1_SLOT3 0x80000000 /* bank1 EFGH */
  46. #define EMI1_SLOT4 0x40000000 /* bank2 ABCD */
  47. #define EMI1_SLOT5 0xc0000000 /* bank3 ABCD */
  48. #define EMI2_SLOT4 0x10000000 /* bank2 ABCD */
  49. #define EMI2_SLOT5 0x30000000 /* bank3 ABCD */
  50. #define EMI1_MASK 0xc0000000
  51. #define EMI2_MASK 0x30000000
  52. static int mdio_mux[NUM_FM_PORTS];
  53. static char *mdio_names[16] = {
  54. "P4080DS_MDIO0",
  55. "P4080DS_MDIO1",
  56. NULL,
  57. "P4080DS_MDIO3",
  58. "P4080DS_MDIO4",
  59. NULL, NULL, NULL,
  60. "P4080DS_MDIO8",
  61. NULL, NULL, NULL,
  62. "P4080DS_MDIO12",
  63. NULL, NULL, NULL,
  64. };
  65. static char *p4080ds_mdio_name_for_muxval(u32 muxval)
  66. {
  67. return mdio_names[(muxval & EMI_MASK) >> 28];
  68. }
  69. struct mii_dev *mii_dev_for_muxval(u32 muxval)
  70. {
  71. struct mii_dev *bus;
  72. char *name = p4080ds_mdio_name_for_muxval(muxval);
  73. if (!name) {
  74. printf("No bus for muxval %x\n", muxval);
  75. return NULL;
  76. }
  77. bus = miiphy_get_dev_by_name(name);
  78. if (!bus) {
  79. printf("No bus by name %s\n", name);
  80. return NULL;
  81. }
  82. return bus;
  83. }
  84. #if defined(CONFIG_SYS_P4080_ERRATUM_SERDES9) && defined(CONFIG_PHY_TERANETICS)
  85. int board_phy_config(struct phy_device *phydev)
  86. {
  87. if (phydev->drv->uid == PHY_UID_TN2020) {
  88. unsigned long timeout = 1 * 1000; /* 1 seconds */
  89. enum srds_prtcl device;
  90. /*
  91. * Wait for the XAUI to come out of reset. This is when it
  92. * starts transmitting alignment signals.
  93. */
  94. while (--timeout) {
  95. int reg = phy_read(phydev, MDIO_MMD_PHYXS, MDIO_CTRL1);
  96. if (reg < 0) {
  97. printf("TN2020: Error reading from PHY at "
  98. "address %u\n", phydev->addr);
  99. break;
  100. }
  101. /*
  102. * Note that we've never actually seen
  103. * MDIO_CTRL1_RESET set to 1.
  104. */
  105. if ((reg & MDIO_CTRL1_RESET) == 0)
  106. break;
  107. udelay(1000);
  108. }
  109. if (!timeout) {
  110. printf("TN2020: Timeout waiting for PHY at address %u "
  111. " to reset.\n", phydev->addr);
  112. }
  113. switch (phydev->addr) {
  114. case CONFIG_SYS_FM1_10GEC1_PHY_ADDR:
  115. device = XAUI_FM1;
  116. break;
  117. case CONFIG_SYS_FM2_10GEC1_PHY_ADDR:
  118. device = XAUI_FM2;
  119. break;
  120. default:
  121. device = NONE;
  122. }
  123. serdes_reset_rx(device);
  124. }
  125. return 0;
  126. }
  127. #endif
  128. struct p4080ds_mdio {
  129. u32 muxval;
  130. struct mii_dev *realbus;
  131. };
  132. static void p4080ds_mux_mdio(u32 muxval)
  133. {
  134. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  135. uint gpioval = in_be32(&pgpio->gpdat) & ~(EMI_MASK);
  136. gpioval |= muxval;
  137. out_be32(&pgpio->gpdat, gpioval);
  138. }
  139. static int p4080ds_mdio_read(struct mii_dev *bus, int addr, int devad,
  140. int regnum)
  141. {
  142. struct p4080ds_mdio *priv = bus->priv;
  143. p4080ds_mux_mdio(priv->muxval);
  144. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  145. }
  146. static int p4080ds_mdio_write(struct mii_dev *bus, int addr, int devad,
  147. int regnum, u16 value)
  148. {
  149. struct p4080ds_mdio *priv = bus->priv;
  150. p4080ds_mux_mdio(priv->muxval);
  151. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  152. }
  153. static int p4080ds_mdio_reset(struct mii_dev *bus)
  154. {
  155. struct p4080ds_mdio *priv = bus->priv;
  156. return priv->realbus->reset(priv->realbus);
  157. }
  158. static int p4080ds_mdio_init(char *realbusname, u32 muxval)
  159. {
  160. struct p4080ds_mdio *pmdio;
  161. struct mii_dev *bus = mdio_alloc();
  162. if (!bus) {
  163. printf("Failed to allocate P4080DS MDIO bus\n");
  164. return -1;
  165. }
  166. pmdio = malloc(sizeof(*pmdio));
  167. if (!pmdio) {
  168. printf("Failed to allocate P4080DS private data\n");
  169. free(bus);
  170. return -1;
  171. }
  172. bus->read = p4080ds_mdio_read;
  173. bus->write = p4080ds_mdio_write;
  174. bus->reset = p4080ds_mdio_reset;
  175. sprintf(bus->name, p4080ds_mdio_name_for_muxval(muxval));
  176. pmdio->realbus = miiphy_get_dev_by_name(realbusname);
  177. if (!pmdio->realbus) {
  178. printf("No bus with name %s\n", realbusname);
  179. free(bus);
  180. free(pmdio);
  181. return -1;
  182. }
  183. pmdio->muxval = muxval;
  184. bus->priv = pmdio;
  185. return mdio_register(bus);
  186. }
  187. void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
  188. enum fm_port port, int offset)
  189. {
  190. if (mdio_mux[port] == EMI1_RGMII)
  191. fdt_set_phy_handle(blob, prop, pa, "phy_rgmii");
  192. if (mdio_mux[port] == EMI1_SLOT3) {
  193. int idx = port - FM2_DTSEC1 + 5;
  194. char phy[16];
  195. sprintf(phy, "phy%d_slot3", idx);
  196. fdt_set_phy_handle(blob, prop, pa, phy);
  197. }
  198. }
  199. void fdt_fixup_board_enet(void *fdt)
  200. {
  201. int i;
  202. /*
  203. * P4080DS can be configured in many different ways, supporting a number
  204. * of combinations of ethernet devices and phy types. In order to
  205. * have just one device tree for all of those configurations, we fix up
  206. * the tree here. By default, the device tree configures FM1 and FM2
  207. * for SGMII, and configures XAUI on both 10G interfaces. So we have
  208. * a number of different variables to track:
  209. *
  210. * 1) Whether the device is configured at all. Whichever devices are
  211. * not enabled should be disabled by setting the "status" property
  212. * to "disabled".
  213. * 2) What the PHY interface is. If this is an RGMII connection,
  214. * we should change the "phy-connection-type" property to
  215. * "rgmii"
  216. * 3) Which PHY is being used. Because the MDIO buses are muxed,
  217. * we need to redirect the "phy-handle" property to point at the
  218. * PHY on the right slot/bus.
  219. */
  220. /* We've got six MDIO nodes that may or may not need to exist */
  221. fdt_status_disabled_by_alias(fdt, "emi1_slot3");
  222. fdt_status_disabled_by_alias(fdt, "emi1_slot4");
  223. fdt_status_disabled_by_alias(fdt, "emi1_slot5");
  224. fdt_status_disabled_by_alias(fdt, "emi2_slot4");
  225. fdt_status_disabled_by_alias(fdt, "emi2_slot5");
  226. for (i = 0; i < NUM_FM_PORTS; i++) {
  227. switch (mdio_mux[i]) {
  228. case EMI1_SLOT3:
  229. fdt_status_okay_by_alias(fdt, "emi1_slot3");
  230. break;
  231. case EMI1_SLOT4:
  232. fdt_status_okay_by_alias(fdt, "emi1_slot4");
  233. break;
  234. case EMI1_SLOT5:
  235. fdt_status_okay_by_alias(fdt, "emi1_slot5");
  236. break;
  237. case EMI2_SLOT4:
  238. fdt_status_okay_by_alias(fdt, "emi2_slot4");
  239. break;
  240. case EMI2_SLOT5:
  241. fdt_status_okay_by_alias(fdt, "emi2_slot5");
  242. break;
  243. }
  244. }
  245. }
  246. enum board_slots {
  247. SLOT1 = 1,
  248. SLOT2,
  249. SLOT3,
  250. SLOT4,
  251. SLOT5,
  252. SLOT6,
  253. };
  254. int board_eth_init(bd_t *bis)
  255. {
  256. #ifdef CONFIG_FMAN_ENET
  257. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  258. struct dtsec *tsec = (void *)CONFIG_SYS_FSL_FM1_DTSEC1_ADDR;
  259. int i;
  260. struct fsl_pq_mdio_info dtsec_mdio_info;
  261. struct tgec_mdio_info tgec_mdio_info;
  262. u8 lane_to_slot[] = {
  263. SLOT1, /* 0 - Bank 1:A */
  264. SLOT1, /* 1 - Bank 1:B */
  265. SLOT2, /* 2 - Bank 1:C */
  266. SLOT2, /* 3 - Bank 1:D */
  267. SLOT3, /* 4 - Bank 1:E */
  268. SLOT3, /* 5 - Bank 1:F */
  269. SLOT3, /* 6 - Bank 1:G */
  270. SLOT3, /* 7 - Bank 1:H */
  271. SLOT6, /* 8 - Bank 1:I */
  272. SLOT6, /* 9 - Bank 1:J */
  273. SLOT4, /* 10 - Bank 2:A */
  274. SLOT4, /* 11 - Bank 2:B */
  275. SLOT4, /* 12 - Bank 2:C */
  276. SLOT4, /* 13 - Bank 2:D */
  277. SLOT5, /* 14 - Bank 3:A */
  278. SLOT5, /* 15 - Bank 3:B */
  279. SLOT5, /* 16 - Bank 3:C */
  280. SLOT5, /* 17 - Bank 3:D */
  281. };
  282. /*
  283. * Set TBIPA on FM1@DTSEC1. This is needed for configurations
  284. * where FM1@DTSEC1 isn't used directly, since it provides
  285. * MDIO for other ports.
  286. */
  287. out_be32(&tsec->tbipa, CONFIG_SYS_TBIPA_VALUE);
  288. /* Initialize the mdio_mux array so we can recognize empty elements */
  289. for (i = 0; i < NUM_FM_PORTS; i++)
  290. mdio_mux[i] = EMI_NONE;
  291. /* The first 4 GPIOs are outputs to control MDIO bus muxing */
  292. out_be32(&pgpio->gpdir, EMI_MASK);
  293. dtsec_mdio_info.regs =
  294. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  295. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  296. /* Register the 1G MDIO bus */
  297. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  298. tgec_mdio_info.regs =
  299. (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  300. tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  301. /* Register the 10G MDIO bus */
  302. fm_tgec_mdio_init(bis, &tgec_mdio_info);
  303. /* Register the 6 muxing front-ends to the MDIO buses */
  304. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII);
  305. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
  306. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
  307. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
  308. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT4);
  309. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT5);
  310. fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  311. fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  312. fm_info_set_phy_address(FM1_DTSEC3, CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
  313. fm_info_set_phy_address(FM1_DTSEC4, CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
  314. fm_info_set_phy_address(FM1_10GEC1, CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  315. #if (CONFIG_SYS_NUM_FMAN == 2)
  316. fm_info_set_phy_address(FM2_DTSEC1, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
  317. fm_info_set_phy_address(FM2_DTSEC2, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
  318. fm_info_set_phy_address(FM2_DTSEC3, CONFIG_SYS_FM2_DTSEC3_PHY_ADDR);
  319. fm_info_set_phy_address(FM2_DTSEC4, CONFIG_SYS_FM2_DTSEC4_PHY_ADDR);
  320. fm_info_set_phy_address(FM2_10GEC1, CONFIG_SYS_FM2_10GEC1_PHY_ADDR);
  321. #endif
  322. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  323. int idx = i - FM1_DTSEC1, lane, slot;
  324. switch (fm_info_get_enet_if(i)) {
  325. case PHY_INTERFACE_MODE_SGMII:
  326. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  327. if (lane < 0)
  328. break;
  329. slot = lane_to_slot[lane];
  330. switch (slot) {
  331. case SLOT3:
  332. mdio_mux[i] = EMI1_SLOT3;
  333. fm_info_set_mdio(i,
  334. mii_dev_for_muxval(mdio_mux[i]));
  335. break;
  336. case SLOT4:
  337. mdio_mux[i] = EMI1_SLOT4;
  338. fm_info_set_mdio(i,
  339. mii_dev_for_muxval(mdio_mux[i]));
  340. break;
  341. case SLOT5:
  342. mdio_mux[i] = EMI1_SLOT5;
  343. fm_info_set_mdio(i,
  344. mii_dev_for_muxval(mdio_mux[i]));
  345. break;
  346. };
  347. break;
  348. case PHY_INTERFACE_MODE_RGMII:
  349. fm_info_set_phy_address(i, 0);
  350. mdio_mux[i] = EMI1_RGMII;
  351. fm_info_set_mdio(i,
  352. mii_dev_for_muxval(mdio_mux[i]));
  353. break;
  354. default:
  355. break;
  356. }
  357. }
  358. for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
  359. int idx = i - FM1_10GEC1, lane, slot;
  360. switch (fm_info_get_enet_if(i)) {
  361. case PHY_INTERFACE_MODE_XGMII:
  362. lane = serdes_get_first_lane(XAUI_FM1 + idx);
  363. if (lane < 0)
  364. break;
  365. slot = lane_to_slot[lane];
  366. switch (slot) {
  367. case SLOT4:
  368. mdio_mux[i] = EMI2_SLOT4;
  369. fm_info_set_mdio(i,
  370. mii_dev_for_muxval(mdio_mux[i]));
  371. break;
  372. case SLOT5:
  373. mdio_mux[i] = EMI2_SLOT5;
  374. fm_info_set_mdio(i,
  375. mii_dev_for_muxval(mdio_mux[i]));
  376. break;
  377. };
  378. break;
  379. default:
  380. break;
  381. }
  382. }
  383. #if (CONFIG_SYS_NUM_FMAN == 2)
  384. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  385. int idx = i - FM2_DTSEC1, lane, slot;
  386. switch (fm_info_get_enet_if(i)) {
  387. case PHY_INTERFACE_MODE_SGMII:
  388. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  389. if (lane < 0)
  390. break;
  391. slot = lane_to_slot[lane];
  392. switch (slot) {
  393. case SLOT3:
  394. mdio_mux[i] = EMI1_SLOT3;
  395. fm_info_set_mdio(i,
  396. mii_dev_for_muxval(mdio_mux[i]));
  397. break;
  398. case SLOT4:
  399. mdio_mux[i] = EMI1_SLOT4;
  400. fm_info_set_mdio(i,
  401. mii_dev_for_muxval(mdio_mux[i]));
  402. break;
  403. case SLOT5:
  404. mdio_mux[i] = EMI1_SLOT5;
  405. fm_info_set_mdio(i,
  406. mii_dev_for_muxval(mdio_mux[i]));
  407. break;
  408. };
  409. break;
  410. case PHY_INTERFACE_MODE_RGMII:
  411. fm_info_set_phy_address(i, 0);
  412. mdio_mux[i] = EMI1_RGMII;
  413. fm_info_set_mdio(i,
  414. mii_dev_for_muxval(mdio_mux[i]));
  415. break;
  416. default:
  417. break;
  418. }
  419. }
  420. for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
  421. int idx = i - FM2_10GEC1, lane, slot;
  422. switch (fm_info_get_enet_if(i)) {
  423. case PHY_INTERFACE_MODE_XGMII:
  424. lane = serdes_get_first_lane(XAUI_FM2 + idx);
  425. if (lane < 0)
  426. break;
  427. slot = lane_to_slot[lane];
  428. switch (slot) {
  429. case SLOT4:
  430. mdio_mux[i] = EMI2_SLOT4;
  431. fm_info_set_mdio(i,
  432. mii_dev_for_muxval(mdio_mux[i]));
  433. break;
  434. case SLOT5:
  435. mdio_mux[i] = EMI2_SLOT5;
  436. fm_info_set_mdio(i,
  437. mii_dev_for_muxval(mdio_mux[i]));
  438. break;
  439. };
  440. break;
  441. default:
  442. break;
  443. }
  444. }
  445. #endif
  446. cpu_eth_init(bis);
  447. #endif /* CONFIG_FMAN_ENET */
  448. return pci_eth_init(bis);
  449. }