eth_p4080.c 12 KB

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