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. #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. /*
  168. * Sets the specified node's status to the value contained in "status"
  169. * If the first character of the specified path is "/" then we use
  170. * alias as a path. Otherwise, we look for an alias of that name
  171. */
  172. static void fdt_set_node_status(void *fdt, const char *alias,
  173. const char *status)
  174. {
  175. const char *path = fdt_get_alias(fdt, alias);
  176. if (!path)
  177. path = alias;
  178. do_fixup_by_path(fdt, path, "status", status, strlen(status) + 1, 1);
  179. }
  180. void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
  181. enum fm_port port, int offset)
  182. {
  183. if (mdio_mux[port] == EMI1_RGMII)
  184. fdt_set_phy_handle(blob, prop, pa, "phy_rgmii");
  185. if (mdio_mux[port] == EMI1_SLOT3) {
  186. int idx = port - FM2_DTSEC1 + 5;
  187. char phy[16];
  188. sprintf(phy, "phy%d_slot3", idx);
  189. fdt_set_phy_handle(blob, prop, pa, phy);
  190. }
  191. }
  192. void fdt_fixup_board_enet(void *fdt)
  193. {
  194. int i;
  195. /*
  196. * P4080DS can be configured in many different ways, supporting a number
  197. * of combinations of ethernet devices and phy types. In order to
  198. * have just one device tree for all of those configurations, we fix up
  199. * the tree here. By default, the device tree configures FM1 and FM2
  200. * for SGMII, and configures XAUI on both 10G interfaces. So we have
  201. * a number of different variables to track:
  202. *
  203. * 1) Whether the device is configured at all. Whichever devices are
  204. * not enabled should be disabled by setting the "status" property
  205. * to "disabled".
  206. * 2) What the PHY interface is. If this is an RGMII connection,
  207. * we should change the "phy-connection-type" property to
  208. * "rgmii"
  209. * 3) Which PHY is being used. Because the MDIO buses are muxed,
  210. * we need to redirect the "phy-handle" property to point at the
  211. * PHY on the right slot/bus.
  212. */
  213. /* We've got six MDIO nodes that may or may not need to exist */
  214. fdt_set_node_status(fdt, "emi1_slot3", "disabled");
  215. fdt_set_node_status(fdt, "emi1_slot4", "disabled");
  216. fdt_set_node_status(fdt, "emi1_slot5", "disabled");
  217. fdt_set_node_status(fdt, "emi2_slot4", "disabled");
  218. fdt_set_node_status(fdt, "emi2_slot5", "disabled");
  219. for (i = 0; i < NUM_FM_PORTS; i++) {
  220. switch (mdio_mux[i]) {
  221. case EMI1_SLOT3:
  222. fdt_set_node_status(fdt, "emi1_slot3", "okay");
  223. break;
  224. case EMI1_SLOT4:
  225. fdt_set_node_status(fdt, "emi1_slot4", "okay");
  226. break;
  227. case EMI1_SLOT5:
  228. fdt_set_node_status(fdt, "emi1_slot5", "okay");
  229. break;
  230. case EMI2_SLOT4:
  231. fdt_set_node_status(fdt, "emi2_slot4", "okay");
  232. break;
  233. case EMI2_SLOT5:
  234. fdt_set_node_status(fdt, "emi2_slot5", "okay");
  235. break;
  236. }
  237. }
  238. }
  239. enum board_slots {
  240. SLOT1 = 1,
  241. SLOT2,
  242. SLOT3,
  243. SLOT4,
  244. SLOT5,
  245. SLOT6,
  246. };
  247. int board_eth_init(bd_t *bis)
  248. {
  249. #ifdef CONFIG_FMAN_ENET
  250. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  251. struct dtsec *tsec = (void *)CONFIG_SYS_FSL_FM1_DTSEC1_ADDR;
  252. int i;
  253. struct fsl_pq_mdio_info dtsec_mdio_info;
  254. struct tgec_mdio_info tgec_mdio_info;
  255. u8 lane_to_slot[] = {
  256. SLOT1, /* 0 - Bank 1:A */
  257. SLOT1, /* 1 - Bank 1:B */
  258. SLOT2, /* 2 - Bank 1:C */
  259. SLOT2, /* 3 - Bank 1:D */
  260. SLOT3, /* 4 - Bank 1:E */
  261. SLOT3, /* 5 - Bank 1:F */
  262. SLOT3, /* 6 - Bank 1:G */
  263. SLOT3, /* 7 - Bank 1:H */
  264. SLOT6, /* 8 - Bank 1:I */
  265. SLOT6, /* 9 - Bank 1:J */
  266. SLOT4, /* 10 - Bank 2:A */
  267. SLOT4, /* 11 - Bank 2:B */
  268. SLOT4, /* 12 - Bank 2:C */
  269. SLOT4, /* 13 - Bank 2:D */
  270. SLOT5, /* 14 - Bank 3:A */
  271. SLOT5, /* 15 - Bank 3:B */
  272. SLOT5, /* 16 - Bank 3:C */
  273. SLOT5, /* 17 - Bank 3:D */
  274. };
  275. /*
  276. * Set TBIPA on FM1@DTSEC1. This is needed for configurations
  277. * where FM1@DTSEC1 isn't used directly, since it provides
  278. * MDIO for other ports.
  279. */
  280. out_be32(&tsec->tbipa, CONFIG_SYS_TBIPA_VALUE);
  281. /* Initialize the mdio_mux array so we can recognize empty elements */
  282. for (i = 0; i < NUM_FM_PORTS; i++)
  283. mdio_mux[i] = EMI_NONE;
  284. /* The first 4 GPIOs are outputs to control MDIO bus muxing */
  285. out_be32(&pgpio->gpdir, EMI_MASK);
  286. dtsec_mdio_info.regs =
  287. (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
  288. dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
  289. /* Register the 1G MDIO bus */
  290. fsl_pq_mdio_init(bis, &dtsec_mdio_info);
  291. tgec_mdio_info.regs =
  292. (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
  293. tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
  294. /* Register the 10G MDIO bus */
  295. fm_tgec_mdio_init(bis, &tgec_mdio_info);
  296. /* Register the 6 muxing front-ends to the MDIO buses */
  297. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII);
  298. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
  299. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
  300. p4080ds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
  301. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT4);
  302. p4080ds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2_SLOT5);
  303. fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
  304. fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
  305. fm_info_set_phy_address(FM1_DTSEC3, CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
  306. fm_info_set_phy_address(FM1_DTSEC4, CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
  307. fm_info_set_phy_address(FM1_10GEC1, CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
  308. #if (CONFIG_SYS_NUM_FMAN == 2)
  309. fm_info_set_phy_address(FM2_DTSEC1, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
  310. fm_info_set_phy_address(FM2_DTSEC2, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
  311. fm_info_set_phy_address(FM2_DTSEC3, CONFIG_SYS_FM2_DTSEC3_PHY_ADDR);
  312. fm_info_set_phy_address(FM2_DTSEC4, CONFIG_SYS_FM2_DTSEC4_PHY_ADDR);
  313. fm_info_set_phy_address(FM2_10GEC1, CONFIG_SYS_FM2_10GEC1_PHY_ADDR);
  314. #endif
  315. for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
  316. int idx = i - FM1_DTSEC1, lane, slot;
  317. switch (fm_info_get_enet_if(i)) {
  318. case PHY_INTERFACE_MODE_SGMII:
  319. lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
  320. if (lane < 0)
  321. break;
  322. slot = lane_to_slot[lane];
  323. switch (slot) {
  324. case SLOT3:
  325. mdio_mux[i] = EMI1_SLOT3;
  326. fm_info_set_mdio(i,
  327. mii_dev_for_muxval(mdio_mux[i]));
  328. break;
  329. case SLOT4:
  330. mdio_mux[i] = EMI1_SLOT4;
  331. fm_info_set_mdio(i,
  332. mii_dev_for_muxval(mdio_mux[i]));
  333. break;
  334. case SLOT5:
  335. mdio_mux[i] = EMI1_SLOT5;
  336. fm_info_set_mdio(i,
  337. mii_dev_for_muxval(mdio_mux[i]));
  338. break;
  339. };
  340. break;
  341. case PHY_INTERFACE_MODE_RGMII:
  342. fm_info_set_phy_address(i, 0);
  343. mdio_mux[i] = EMI1_RGMII;
  344. fm_info_set_mdio(i,
  345. mii_dev_for_muxval(mdio_mux[i]));
  346. break;
  347. default:
  348. break;
  349. }
  350. }
  351. for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
  352. int idx = i - FM1_10GEC1, lane, slot;
  353. switch (fm_info_get_enet_if(i)) {
  354. case PHY_INTERFACE_MODE_XGMII:
  355. lane = serdes_get_first_lane(XAUI_FM1 + idx);
  356. if (lane < 0)
  357. break;
  358. slot = lane_to_slot[lane];
  359. switch (slot) {
  360. case SLOT4:
  361. mdio_mux[i] = EMI2_SLOT4;
  362. fm_info_set_mdio(i,
  363. mii_dev_for_muxval(mdio_mux[i]));
  364. break;
  365. case SLOT5:
  366. mdio_mux[i] = EMI2_SLOT5;
  367. fm_info_set_mdio(i,
  368. mii_dev_for_muxval(mdio_mux[i]));
  369. break;
  370. };
  371. break;
  372. default:
  373. break;
  374. }
  375. }
  376. #if (CONFIG_SYS_NUM_FMAN == 2)
  377. for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
  378. int idx = i - FM2_DTSEC1, lane, slot;
  379. switch (fm_info_get_enet_if(i)) {
  380. case PHY_INTERFACE_MODE_SGMII:
  381. lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
  382. if (lane < 0)
  383. break;
  384. slot = lane_to_slot[lane];
  385. switch (slot) {
  386. case SLOT3:
  387. mdio_mux[i] = EMI1_SLOT3;
  388. fm_info_set_mdio(i,
  389. mii_dev_for_muxval(mdio_mux[i]));
  390. break;
  391. case SLOT4:
  392. mdio_mux[i] = EMI1_SLOT4;
  393. fm_info_set_mdio(i,
  394. mii_dev_for_muxval(mdio_mux[i]));
  395. break;
  396. case SLOT5:
  397. mdio_mux[i] = EMI1_SLOT5;
  398. fm_info_set_mdio(i,
  399. mii_dev_for_muxval(mdio_mux[i]));
  400. break;
  401. };
  402. break;
  403. case PHY_INTERFACE_MODE_RGMII:
  404. fm_info_set_phy_address(i, 0);
  405. mdio_mux[i] = EMI1_RGMII;
  406. fm_info_set_mdio(i,
  407. mii_dev_for_muxval(mdio_mux[i]));
  408. break;
  409. default:
  410. break;
  411. }
  412. }
  413. for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
  414. int idx = i - FM2_10GEC1, lane, slot;
  415. switch (fm_info_get_enet_if(i)) {
  416. case PHY_INTERFACE_MODE_XGMII:
  417. lane = serdes_get_first_lane(XAUI_FM2 + idx);
  418. if (lane < 0)
  419. break;
  420. slot = lane_to_slot[lane];
  421. switch (slot) {
  422. case SLOT4:
  423. mdio_mux[i] = EMI2_SLOT4;
  424. fm_info_set_mdio(i,
  425. mii_dev_for_muxval(mdio_mux[i]));
  426. break;
  427. case SLOT5:
  428. mdio_mux[i] = EMI2_SLOT5;
  429. fm_info_set_mdio(i,
  430. mii_dev_for_muxval(mdio_mux[i]));
  431. break;
  432. };
  433. break;
  434. default:
  435. break;
  436. }
  437. }
  438. #endif
  439. cpu_eth_init(bis);
  440. #endif /* CONFIG_FMAN_ENET */
  441. return pci_eth_init(bis);
  442. }