eth_p4080.c 12 KB

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