hrcon.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2014
  4. * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
  5. */
  6. #include <common.h>
  7. #include <hwconfig.h>
  8. #include <i2c.h>
  9. #include <spi.h>
  10. #include <linux/libfdt.h>
  11. #include <fdt_support.h>
  12. #include <pci.h>
  13. #include <mpc83xx.h>
  14. #include <fsl_esdhc.h>
  15. #include <asm/io.h>
  16. #include <asm/fsl_serdes.h>
  17. #include <asm/fsl_mpc83xx_serdes.h>
  18. #include "mpc8308.h"
  19. #include <gdsys_fpga.h>
  20. #include "../common/ioep-fpga.h"
  21. #include "../common/osd.h"
  22. #include "../common/mclink.h"
  23. #include "../common/phy.h"
  24. #include "../common/fanctrl.h"
  25. #include <pca953x.h>
  26. #include <pca9698.h>
  27. #include <miiphy.h>
  28. #define MAX_MUX_CHANNELS 2
  29. enum {
  30. MCFPGA_DONE = 1 << 0,
  31. MCFPGA_INIT_N = 1 << 1,
  32. MCFPGA_PROGRAM_N = 1 << 2,
  33. MCFPGA_UPDATE_ENABLE_N = 1 << 3,
  34. MCFPGA_RESET_N = 1 << 4,
  35. };
  36. enum {
  37. GPIO_MDC = 1 << 14,
  38. GPIO_MDIO = 1 << 15,
  39. };
  40. unsigned int mclink_fpgacount;
  41. struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
  42. struct {
  43. u8 bus;
  44. u8 addr;
  45. } hrcon_fans[] = CONFIG_HRCON_FANS;
  46. int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
  47. {
  48. int res;
  49. switch (fpga) {
  50. case 0:
  51. out_le16(reg, data);
  52. break;
  53. default:
  54. res = mclink_send(fpga - 1, regoff, data);
  55. if (res < 0) {
  56. printf("mclink_send reg %02lx data %04x returned %d\n",
  57. regoff, data, res);
  58. return res;
  59. }
  60. break;
  61. }
  62. return 0;
  63. }
  64. int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
  65. {
  66. int res;
  67. switch (fpga) {
  68. case 0:
  69. *data = in_le16(reg);
  70. break;
  71. default:
  72. if (fpga > mclink_fpgacount)
  73. return -EINVAL;
  74. res = mclink_receive(fpga - 1, regoff, data);
  75. if (res < 0) {
  76. printf("mclink_receive reg %02lx returned %d\n",
  77. regoff, res);
  78. return res;
  79. }
  80. }
  81. return 0;
  82. }
  83. int checkboard(void)
  84. {
  85. char *s = env_get("serial#");
  86. bool hw_type_cat = pca9698_get_value(0x20, 20);
  87. puts("Board: ");
  88. printf("HRCon %s", hw_type_cat ? "CAT" : "Fiber");
  89. if (s != NULL) {
  90. puts(", serial# ");
  91. puts(s);
  92. }
  93. puts("\n");
  94. return 0;
  95. }
  96. int last_stage_init(void)
  97. {
  98. int slaves;
  99. unsigned int k;
  100. unsigned int mux_ch;
  101. unsigned char mclink_controllers[] = { 0x3c, 0x3d, 0x3e };
  102. u16 fpga_features;
  103. bool hw_type_cat = pca9698_get_value(0x20, 20);
  104. bool ch0_rgmii2_present = false;
  105. FPGA_GET_REG(0, fpga_features, &fpga_features);
  106. /* Turn on Parade DP501 */
  107. pca9698_direction_output(0x20, 10, 1);
  108. pca9698_direction_output(0x20, 11, 1);
  109. ch0_rgmii2_present = !pca9698_get_value(0x20, 30);
  110. /* wait for FPGA done, then reset FPGA */
  111. for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) {
  112. unsigned int ctr = 0;
  113. if (i2c_probe(mclink_controllers[k]))
  114. continue;
  115. while (!(pca953x_get_val(mclink_controllers[k])
  116. & MCFPGA_DONE)) {
  117. udelay(100000);
  118. if (ctr++ > 5) {
  119. printf("no done for mclink_controller %d\n", k);
  120. break;
  121. }
  122. }
  123. pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
  124. pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
  125. udelay(10);
  126. pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
  127. MCFPGA_RESET_N);
  128. }
  129. if (hw_type_cat) {
  130. int retval;
  131. struct mii_dev *mdiodev = mdio_alloc();
  132. if (!mdiodev)
  133. return -ENOMEM;
  134. strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
  135. mdiodev->read = bb_miiphy_read;
  136. mdiodev->write = bb_miiphy_write;
  137. retval = mdio_register(mdiodev);
  138. if (retval < 0)
  139. return retval;
  140. for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
  141. if ((mux_ch == 1) && !ch0_rgmii2_present)
  142. continue;
  143. setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
  144. }
  145. }
  146. /* give slave-PLLs and Parade DP501 some time to be up and running */
  147. udelay(500000);
  148. mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
  149. slaves = mclink_probe();
  150. mclink_fpgacount = 0;
  151. ioep_fpga_print_info(0);
  152. osd_probe(0);
  153. #ifdef CONFIG_SYS_OSD_DH
  154. osd_probe(4);
  155. #endif
  156. if (slaves <= 0)
  157. return 0;
  158. mclink_fpgacount = slaves;
  159. for (k = 1; k <= slaves; ++k) {
  160. FPGA_GET_REG(k, fpga_features, &fpga_features);
  161. ioep_fpga_print_info(k);
  162. osd_probe(k);
  163. #ifdef CONFIG_SYS_OSD_DH
  164. osd_probe(k + 4);
  165. #endif
  166. if (hw_type_cat) {
  167. int retval;
  168. struct mii_dev *mdiodev = mdio_alloc();
  169. if (!mdiodev)
  170. return -ENOMEM;
  171. strncpy(mdiodev->name, bb_miiphy_buses[k].name,
  172. MDIO_NAME_LEN);
  173. mdiodev->read = bb_miiphy_read;
  174. mdiodev->write = bb_miiphy_write;
  175. retval = mdio_register(mdiodev);
  176. if (retval < 0)
  177. return retval;
  178. setup_88e1514(bb_miiphy_buses[k].name, 0);
  179. }
  180. }
  181. for (k = 0; k < ARRAY_SIZE(hrcon_fans); ++k) {
  182. i2c_set_bus_num(hrcon_fans[k].bus);
  183. init_fan_controller(hrcon_fans[k].addr);
  184. }
  185. return 0;
  186. }
  187. /*
  188. * provide access to fpga gpios and controls (for I2C bitbang)
  189. * (these may look all too simple but make iocon.h much more readable)
  190. */
  191. void fpga_gpio_set(unsigned int bus, int pin)
  192. {
  193. FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.set, pin);
  194. }
  195. void fpga_gpio_clear(unsigned int bus, int pin)
  196. {
  197. FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.clear, pin);
  198. }
  199. int fpga_gpio_get(unsigned int bus, int pin)
  200. {
  201. u16 val;
  202. FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, gpio.read, &val);
  203. return val & pin;
  204. }
  205. void fpga_control_set(unsigned int bus, int pin)
  206. {
  207. u16 val;
  208. FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
  209. FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val | pin);
  210. }
  211. void fpga_control_clear(unsigned int bus, int pin)
  212. {
  213. u16 val;
  214. FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
  215. FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val & ~pin);
  216. }
  217. void mpc8308_init(void)
  218. {
  219. pca9698_direction_output(0x20, 4, 1);
  220. }
  221. void mpc8308_set_fpga_reset(unsigned state)
  222. {
  223. pca9698_set_value(0x20, 4, state ? 0 : 1);
  224. }
  225. void mpc8308_setup_hw(void)
  226. {
  227. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  228. /*
  229. * set "startup-finished"-gpios
  230. */
  231. setbits_be32(&immr->gpio[0].dir, (1 << (31-11)) | (1 << (31-12)));
  232. setbits_be32(&immr->gpio[0].dat, 1 << (31-12));
  233. }
  234. int mpc8308_get_fpga_done(unsigned fpga)
  235. {
  236. return pca9698_get_value(0x20, 19);
  237. }
  238. #ifdef CONFIG_FSL_ESDHC
  239. int board_mmc_init(bd_t *bd)
  240. {
  241. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  242. sysconf83xx_t *sysconf = &immr->sysconf;
  243. /* Enable cache snooping in eSDHC system configuration register */
  244. out_be32(&sysconf->sdhccr, 0x02000000);
  245. return fsl_esdhc_mmc_init(bd);
  246. }
  247. #endif
  248. static struct pci_region pcie_regions_0[] = {
  249. {
  250. .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
  251. .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
  252. .size = CONFIG_SYS_PCIE1_MEM_SIZE,
  253. .flags = PCI_REGION_MEM,
  254. },
  255. {
  256. .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
  257. .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
  258. .size = CONFIG_SYS_PCIE1_IO_SIZE,
  259. .flags = PCI_REGION_IO,
  260. },
  261. };
  262. void pci_init_board(void)
  263. {
  264. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  265. sysconf83xx_t *sysconf = &immr->sysconf;
  266. law83xx_t *pcie_law = sysconf->pcielaw;
  267. struct pci_region *pcie_reg[] = { pcie_regions_0 };
  268. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
  269. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  270. /* Deassert the resets in the control register */
  271. out_be32(&sysconf->pecr1, 0xE0008000);
  272. udelay(2000);
  273. /* Configure PCI Express Local Access Windows */
  274. out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
  275. out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
  276. mpc83xx_pcie_init(1, pcie_reg);
  277. }
  278. ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
  279. {
  280. info->portwidth = FLASH_CFI_16BIT;
  281. info->chipwidth = FLASH_CFI_BY16;
  282. info->interface = FLASH_CFI_X16;
  283. return 1;
  284. }
  285. #if defined(CONFIG_OF_BOARD_SETUP)
  286. int ft_board_setup(void *blob, bd_t *bd)
  287. {
  288. ft_cpu_setup(blob, bd);
  289. fsl_fdt_fixup_dr_usb(blob, bd);
  290. fdt_fixup_esdhc(blob, bd);
  291. return 0;
  292. }
  293. #endif
  294. /*
  295. * FPGA MII bitbang implementation
  296. */
  297. struct fpga_mii {
  298. unsigned fpga;
  299. int mdio;
  300. } fpga_mii[] = {
  301. { 0, 1},
  302. { 1, 1},
  303. { 2, 1},
  304. { 3, 1},
  305. };
  306. static int mii_dummy_init(struct bb_miiphy_bus *bus)
  307. {
  308. return 0;
  309. }
  310. static int mii_mdio_active(struct bb_miiphy_bus *bus)
  311. {
  312. struct fpga_mii *fpga_mii = bus->priv;
  313. if (fpga_mii->mdio)
  314. FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
  315. else
  316. FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
  317. return 0;
  318. }
  319. static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
  320. {
  321. struct fpga_mii *fpga_mii = bus->priv;
  322. FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
  323. return 0;
  324. }
  325. static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
  326. {
  327. struct fpga_mii *fpga_mii = bus->priv;
  328. if (v)
  329. FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
  330. else
  331. FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
  332. fpga_mii->mdio = v;
  333. return 0;
  334. }
  335. static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
  336. {
  337. u16 gpio;
  338. struct fpga_mii *fpga_mii = bus->priv;
  339. FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
  340. *v = ((gpio & GPIO_MDIO) != 0);
  341. return 0;
  342. }
  343. static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
  344. {
  345. struct fpga_mii *fpga_mii = bus->priv;
  346. if (v)
  347. FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
  348. else
  349. FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
  350. return 0;
  351. }
  352. static int mii_delay(struct bb_miiphy_bus *bus)
  353. {
  354. udelay(1);
  355. return 0;
  356. }
  357. struct bb_miiphy_bus bb_miiphy_buses[] = {
  358. {
  359. .name = "board0",
  360. .init = mii_dummy_init,
  361. .mdio_active = mii_mdio_active,
  362. .mdio_tristate = mii_mdio_tristate,
  363. .set_mdio = mii_set_mdio,
  364. .get_mdio = mii_get_mdio,
  365. .set_mdc = mii_set_mdc,
  366. .delay = mii_delay,
  367. .priv = &fpga_mii[0],
  368. },
  369. {
  370. .name = "board1",
  371. .init = mii_dummy_init,
  372. .mdio_active = mii_mdio_active,
  373. .mdio_tristate = mii_mdio_tristate,
  374. .set_mdio = mii_set_mdio,
  375. .get_mdio = mii_get_mdio,
  376. .set_mdc = mii_set_mdc,
  377. .delay = mii_delay,
  378. .priv = &fpga_mii[1],
  379. },
  380. {
  381. .name = "board2",
  382. .init = mii_dummy_init,
  383. .mdio_active = mii_mdio_active,
  384. .mdio_tristate = mii_mdio_tristate,
  385. .set_mdio = mii_set_mdio,
  386. .get_mdio = mii_get_mdio,
  387. .set_mdc = mii_set_mdc,
  388. .delay = mii_delay,
  389. .priv = &fpga_mii[2],
  390. },
  391. {
  392. .name = "board3",
  393. .init = mii_dummy_init,
  394. .mdio_active = mii_mdio_active,
  395. .mdio_tristate = mii_mdio_tristate,
  396. .set_mdio = mii_set_mdio,
  397. .get_mdio = mii_get_mdio,
  398. .set_mdc = mii_set_mdc,
  399. .delay = mii_delay,
  400. .priv = &fpga_mii[3],
  401. },
  402. };
  403. int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
  404. sizeof(bb_miiphy_buses[0]);