strider.c 11 KB

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