eth_p4080.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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->config)
  88. phydev->drv->config(phydev);
  89. if (phydev->drv->uid == PHY_UID_TN2020) {
  90. unsigned long timeout = 1 * 1000; /* 1 seconds */
  91. enum srds_prtcl device;
  92. /*
  93. * Wait for the XAUI to come out of reset. This is when it
  94. * starts transmitting alignment signals.
  95. */
  96. while (--timeout) {
  97. int reg = phy_read(phydev, MDIO_MMD_PHYXS, MDIO_CTRL1);
  98. if (reg < 0) {
  99. printf("TN2020: Error reading from PHY at "
  100. "address %u\n", phydev->addr);
  101. break;
  102. }
  103. /*
  104. * Note that we've never actually seen
  105. * MDIO_CTRL1_RESET set to 1.
  106. */
  107. if ((reg & MDIO_CTRL1_RESET) == 0)
  108. break;
  109. udelay(1000);
  110. }
  111. if (!timeout) {
  112. printf("TN2020: Timeout waiting for PHY at address %u "
  113. " to reset.\n", phydev->addr);
  114. }
  115. switch (phydev->addr) {
  116. case CONFIG_SYS_FM1_10GEC1_PHY_ADDR:
  117. device = XAUI_FM1;
  118. break;
  119. case CONFIG_SYS_FM2_10GEC1_PHY_ADDR:
  120. device = XAUI_FM2;
  121. break;
  122. default:
  123. device = NONE;
  124. }
  125. serdes_reset_rx(device);
  126. }
  127. return 0;
  128. }
  129. #endif
  130. struct p4080ds_mdio {
  131. u32 muxval;
  132. struct mii_dev *realbus;
  133. };
  134. static void p4080ds_mux_mdio(u32 muxval)
  135. {
  136. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  137. uint gpioval = in_be32(&pgpio->gpdat) & ~(EMI_MASK);
  138. gpioval |= muxval;
  139. out_be32(&pgpio->gpdat, gpioval);
  140. }
  141. static int p4080ds_mdio_read(struct mii_dev *bus, int addr, int devad,
  142. int regnum)
  143. {
  144. struct p4080ds_mdio *priv = bus->priv;
  145. p4080ds_mux_mdio(priv->muxval);
  146. return priv->realbus->read(priv->realbus, addr, devad, regnum);
  147. }
  148. static int p4080ds_mdio_write(struct mii_dev *bus, int addr, int devad,
  149. int regnum, u16 value)
  150. {
  151. struct p4080ds_mdio *priv = bus->priv;
  152. p4080ds_mux_mdio(priv->muxval);
  153. return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
  154. }
  155. static int p4080ds_mdio_reset(struct mii_dev *bus)
  156. {
  157. struct p4080ds_mdio *priv = bus->priv;
  158. return priv->realbus->reset(priv->realbus);
  159. }
  160. static int p4080ds_mdio_init(char *realbusname, u32 muxval)
  161. {
  162. struct p4080ds_mdio *pmdio;
  163. struct mii_dev *bus = mdio_alloc();
  164. if (!bus) {
  165. printf("Failed to allocate P4080DS MDIO bus\n");
  166. return -1;
  167. }
  168. pmdio = malloc(sizeof(*pmdio));
  169. if (!pmdio) {
  170. printf("Failed to allocate P4080DS private data\n");
  171. free(bus);
  172. return -1;
  173. }
  174. bus->read = p4080ds_mdio_read;
  175. bus->write = p4080ds_mdio_write;
  176. bus->reset = p4080ds_mdio_reset;
  177. sprintf(bus->name, p4080ds_mdio_name_for_muxval(muxval));
  178. pmdio->realbus = miiphy_get_dev_by_name(realbusname);
  179. if (!pmdio->realbus) {
  180. printf("No bus with name %s\n", realbusname);
  181. free(bus);
  182. free(pmdio);
  183. return -1;
  184. }
  185. pmdio->muxval = muxval;
  186. bus->priv = pmdio;
  187. return mdio_register(bus);
  188. }
  189. void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
  190. enum fm_port port, int offset)
  191. {
  192. if (mdio_mux[port] == EMI1_RGMII)
  193. fdt_set_phy_handle(blob, prop, pa, "phy_rgmii");
  194. if (mdio_mux[port] == EMI1_SLOT3) {
  195. int idx = port - FM2_DTSEC1 + 5;
  196. char phy[16];
  197. sprintf(phy, "phy%d_slot3", idx);
  198. fdt_set_phy_handle(blob, prop, pa, phy);
  199. }
  200. }
  201. void fdt_fixup_board_enet(void *fdt)
  202. {
  203. int i;
  204. /*
  205. * P4080DS can be configured in many different ways, supporting a number
  206. * of combinations of ethernet devices and phy types. In order to
  207. * have just one device tree for all of those configurations, we fix up
  208. * the tree here. By default, the device tree configures FM1 and FM2
  209. * for SGMII, and configures XAUI on both 10G interfaces. So we have
  210. * a number of different variables to track:
  211. *
  212. * 1) Whether the device is configured at all. Whichever devices are
  213. * not enabled should be disabled by setting the "status" property
  214. * to "disabled".
  215. * 2) What the PHY interface is. If this is an RGMII connection,
  216. * we should change the "phy-connection-type" property to
  217. * "rgmii"
  218. * 3) Which PHY is being used. Because the MDIO buses are muxed,
  219. * we need to redirect the "phy-handle" property to point at the
  220. * PHY on the right slot/bus.
  221. */
  222. /* We've got six MDIO nodes that may or may not need to exist */
  223. fdt_status_disabled_by_alias(fdt, "emi1_slot3");
  224. fdt_status_disabled_by_alias(fdt, "emi1_slot4");
  225. fdt_status_disabled_by_alias(fdt, "emi1_slot5");
  226. fdt_status_disabled_by_alias(fdt, "emi2_slot4");
  227. fdt_status_disabled_by_alias(fdt, "emi2_slot5");
  228. for (i = 0; i < NUM_FM_PORTS; i++) {
  229. switch (mdio_mux[i]) {
  230. case EMI1_SLOT3:
  231. fdt_status_okay_by_alias(fdt, "emi1_slot3");
  232. break;
  233. case EMI1_SLOT4:
  234. fdt_status_okay_by_alias(fdt, "emi1_slot4");
  235. break;
  236. case EMI1_SLOT5:
  237. fdt_status_okay_by_alias(fdt, "emi1_slot5");
  238. break;
  239. case EMI2_SLOT4:
  240. fdt_status_okay_by_alias(fdt, "emi2_slot4");
  241. break;
  242. case EMI2_SLOT5:
  243. fdt_status_okay_by_alias(fdt, "emi2_slot5");
  244. break;
  245. }
  246. }
  247. }
  248. enum board_slots {
  249. SLOT1 = 1,
  250. SLOT2,
  251. SLOT3,
  252. SLOT4,
  253. SLOT5,
  254. SLOT6,
  255. };
  256. int board_eth_init(bd_t *bis)
  257. {
  258. #ifdef CONFIG_FMAN_ENET
  259. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  260. int i;
  261. struct fsl_pq_mdio_info dtsec_mdio_info;
  262. struct tgec_mdio_info tgec_mdio_info;
  263. u8 lane_to_slot[] = {
  264. SLOT1, /* 0 - Bank 1:A */
  265. SLOT1, /* 1 - Bank 1:B */
  266. SLOT2, /* 2 - Bank 1:C */
  267. SLOT2, /* 3 - Bank 1:D */
  268. SLOT3, /* 4 - Bank 1:E */
  269. SLOT3, /* 5 - Bank 1:F */
  270. SLOT3, /* 6 - Bank 1:G */
  271. SLOT3, /* 7 - Bank 1:H */
  272. SLOT6, /* 8 - Bank 1:I */
  273. SLOT6, /* 9 - Bank 1:J */
  274. SLOT4, /* 10 - Bank 2:A */
  275. SLOT4, /* 11 - Bank 2:B */
  276. SLOT4, /* 12 - Bank 2:C */
  277. SLOT4, /* 13 - Bank 2:D */
  278. SLOT5, /* 14 - Bank 3:A */
  279. SLOT5, /* 15 - Bank 3:B */
  280. SLOT5, /* 16 - Bank 3:C */
  281. SLOT5, /* 17 - Bank 3:D */
  282. };
  283. /* Initialize the mdio_mux array so we can recognize empty elements */
  284. for (i = 0; i < NUM_FM_PORTS; i++)
  285. mdio_mux[i] = EMI_NONE;
  286. /* The first 4 GPIOs are outputs to control MDIO bus muxing */
  287. out_be32(&pgpio->gpdir, EMI_MASK);
  288. dtsec_mdio_info.regs =
  289. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  290. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  291. /* Register the 1G MDIO bus */
  292. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  293. tgec_mdio_info.regs =
  294. (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  295. tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  296. /* Register the 10G MDIO bus */
  297. fm_tgec_mdio_init(bis, &tgec_mdio_info);
  298. /* Register the 6 muxing front-ends to the MDIO buses */
  299. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII);
  300. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
  301. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
  302. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
  303. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT4);
  304. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT5);
  305. fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  306. fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  307. fm_info_set_phy_address(FM1_DTSEC3, CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
  308. fm_info_set_phy_address(FM1_DTSEC4, CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
  309. fm_info_set_phy_address(FM1_10GEC1, CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  310. #if (CONFIG_SYS_NUM_FMAN == 2)
  311. fm_info_set_phy_address(FM2_DTSEC1, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
  312. fm_info_set_phy_address(FM2_DTSEC2, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
  313. fm_info_set_phy_address(FM2_DTSEC3, CONFIG_SYS_FM2_DTSEC3_PHY_ADDR);
  314. fm_info_set_phy_address(FM2_DTSEC4, CONFIG_SYS_FM2_DTSEC4_PHY_ADDR);
  315. fm_info_set_phy_address(FM2_10GEC1, CONFIG_SYS_FM2_10GEC1_PHY_ADDR);
  316. #endif
  317. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  318. int idx = i - FM1_DTSEC1, lane, slot;
  319. switch (fm_info_get_enet_if(i)) {
  320. case PHY_INTERFACE_MODE_SGMII:
  321. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  322. if (lane < 0)
  323. break;
  324. slot = lane_to_slot[lane];
  325. switch (slot) {
  326. case SLOT3:
  327. mdio_mux[i] = EMI1_SLOT3;
  328. fm_info_set_mdio(i,
  329. mii_dev_for_muxval(mdio_mux[i]));
  330. break;
  331. case SLOT4:
  332. mdio_mux[i] = EMI1_SLOT4;
  333. fm_info_set_mdio(i,
  334. mii_dev_for_muxval(mdio_mux[i]));
  335. break;
  336. case SLOT5:
  337. mdio_mux[i] = EMI1_SLOT5;
  338. fm_info_set_mdio(i,
  339. mii_dev_for_muxval(mdio_mux[i]));
  340. break;
  341. };
  342. break;
  343. case PHY_INTERFACE_MODE_RGMII:
  344. fm_info_set_phy_address(i, 0);
  345. mdio_mux[i] = EMI1_RGMII;
  346. fm_info_set_mdio(i,
  347. mii_dev_for_muxval(mdio_mux[i]));
  348. break;
  349. default:
  350. break;
  351. }
  352. }
  353. for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
  354. int idx = i - FM1_10GEC1, lane, slot;
  355. switch (fm_info_get_enet_if(i)) {
  356. case PHY_INTERFACE_MODE_XGMII:
  357. lane = serdes_get_first_lane(XAUI_FM1 + idx);
  358. if (lane < 0)
  359. break;
  360. slot = lane_to_slot[lane];
  361. switch (slot) {
  362. case SLOT4:
  363. mdio_mux[i] = EMI2_SLOT4;
  364. fm_info_set_mdio(i,
  365. mii_dev_for_muxval(mdio_mux[i]));
  366. break;
  367. case SLOT5:
  368. mdio_mux[i] = EMI2_SLOT5;
  369. fm_info_set_mdio(i,
  370. mii_dev_for_muxval(mdio_mux[i]));
  371. break;
  372. };
  373. break;
  374. default:
  375. break;
  376. }
  377. }
  378. #if (CONFIG_SYS_NUM_FMAN == 2)
  379. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  380. int idx = i - FM2_DTSEC1, lane, slot;
  381. switch (fm_info_get_enet_if(i)) {
  382. case PHY_INTERFACE_MODE_SGMII:
  383. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  384. if (lane < 0)
  385. break;
  386. slot = lane_to_slot[lane];
  387. switch (slot) {
  388. case SLOT3:
  389. mdio_mux[i] = EMI1_SLOT3;
  390. fm_info_set_mdio(i,
  391. mii_dev_for_muxval(mdio_mux[i]));
  392. break;
  393. case SLOT4:
  394. mdio_mux[i] = EMI1_SLOT4;
  395. fm_info_set_mdio(i,
  396. mii_dev_for_muxval(mdio_mux[i]));
  397. break;
  398. case SLOT5:
  399. mdio_mux[i] = EMI1_SLOT5;
  400. fm_info_set_mdio(i,
  401. mii_dev_for_muxval(mdio_mux[i]));
  402. break;
  403. };
  404. break;
  405. case PHY_INTERFACE_MODE_RGMII:
  406. fm_info_set_phy_address(i, 0);
  407. mdio_mux[i] = EMI1_RGMII;
  408. fm_info_set_mdio(i,
  409. mii_dev_for_muxval(mdio_mux[i]));
  410. break;
  411. default:
  412. break;
  413. }
  414. }
  415. for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
  416. int idx = i - FM2_10GEC1, lane, slot;
  417. switch (fm_info_get_enet_if(i)) {
  418. case PHY_INTERFACE_MODE_XGMII:
  419. lane = serdes_get_first_lane(XAUI_FM2 + idx);
  420. if (lane < 0)
  421. break;
  422. slot = lane_to_slot[lane];
  423. switch (slot) {
  424. case SLOT4:
  425. mdio_mux[i] = EMI2_SLOT4;
  426. fm_info_set_mdio(i,
  427. mii_dev_for_muxval(mdio_mux[i]));
  428. break;
  429. case SLOT5:
  430. mdio_mux[i] = EMI2_SLOT5;
  431. fm_info_set_mdio(i,
  432. mii_dev_for_muxval(mdio_mux[i]));
  433. break;
  434. };
  435. break;
  436. default:
  437. break;
  438. }
  439. }
  440. #endif
  441. cpu_eth_init(bis);
  442. #endif /* CONFIG_FMAN_ENET */
  443. return pci_eth_init(bis);
  444. }