mx53cx9020.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * Copyright (C) 2015 Beckhoff Automation GmbH & Co. KG
  3. * Patrick Bruenn <p.bruenn@beckhoff.com>
  4. *
  5. * Based on <u-boot>/board/freescale/mx53loco/mx53loco.c
  6. * Copyright (C) 2011 Freescale Semiconductor, Inc.
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <dm.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/imx-regs.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/arch/crm_regs.h>
  16. #include <asm/arch/clock.h>
  17. #include <asm/arch/iomux-mx53.h>
  18. #include <asm/arch/clock.h>
  19. #include <asm/mach-imx/mx5_video.h>
  20. #include <ACEX1K.h>
  21. #include <netdev.h>
  22. #include <i2c.h>
  23. #include <mmc.h>
  24. #include <fsl_esdhc.h>
  25. #include <asm/gpio.h>
  26. #include <linux/fb.h>
  27. #include <ipu_pixfmt.h>
  28. #include <fs.h>
  29. #include <dm/platform_data/serial_mxc.h>
  30. enum LED_GPIOS {
  31. GPIO_SD1_CD = IMX_GPIO_NR(1, 1),
  32. GPIO_SD2_CD = IMX_GPIO_NR(1, 4),
  33. GPIO_LED_SD2_R = IMX_GPIO_NR(3, 16),
  34. GPIO_LED_SD2_B = IMX_GPIO_NR(3, 17),
  35. GPIO_LED_SD2_G = IMX_GPIO_NR(3, 18),
  36. GPIO_LED_SD1_R = IMX_GPIO_NR(3, 19),
  37. GPIO_LED_SD1_B = IMX_GPIO_NR(3, 20),
  38. GPIO_LED_SD1_G = IMX_GPIO_NR(3, 21),
  39. GPIO_LED_PWR_R = IMX_GPIO_NR(3, 22),
  40. GPIO_LED_PWR_B = IMX_GPIO_NR(3, 23),
  41. GPIO_LED_PWR_G = IMX_GPIO_NR(3, 24),
  42. GPIO_SUPS_INT = IMX_GPIO_NR(3, 31),
  43. GPIO_C3_CONFIG = IMX_GPIO_NR(6, 8),
  44. GPIO_C3_STATUS = IMX_GPIO_NR(6, 7),
  45. GPIO_C3_DONE = IMX_GPIO_NR(6, 9),
  46. };
  47. #define CCAT_BASE_ADDR ((void *)0xf0000000)
  48. #define CCAT_END_ADDR (CCAT_BASE_ADDR + (1024 * 1024 * 32))
  49. #define CCAT_SIZE 1191788
  50. #define CCAT_SIGN_ADDR (CCAT_BASE_ADDR + 12)
  51. static const char CCAT_SIGNATURE[] = "CCAT";
  52. static const u32 CCAT_MODE_CONFIG = 0x0024DC81;
  53. static const u32 CCAT_MODE_RUN = 0x0033DC8F;
  54. DECLARE_GLOBAL_DATA_PTR;
  55. static uint32_t mx53_dram_size[2];
  56. phys_size_t get_effective_memsize(void)
  57. {
  58. /*
  59. * WARNING: We must override get_effective_memsize() function here
  60. * to report only the size of the first DRAM bank. This is to make
  61. * U-Boot relocator place U-Boot into valid memory, that is, at the
  62. * end of the first DRAM bank. If we did not override this function
  63. * like so, U-Boot would be placed at the address of the first DRAM
  64. * bank + total DRAM size - sizeof(uboot), which in the setup where
  65. * each DRAM bank contains 512MiB of DRAM would result in placing
  66. * U-Boot into invalid memory area close to the end of the first
  67. * DRAM bank.
  68. */
  69. return mx53_dram_size[0];
  70. }
  71. int dram_init(void)
  72. {
  73. mx53_dram_size[0] = get_ram_size((void *)PHYS_SDRAM_1, 1 << 30);
  74. mx53_dram_size[1] = get_ram_size((void *)PHYS_SDRAM_2, 1 << 30);
  75. gd->ram_size = mx53_dram_size[0] + mx53_dram_size[1];
  76. return 0;
  77. }
  78. int dram_init_banksize(void)
  79. {
  80. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  81. gd->bd->bi_dram[0].size = mx53_dram_size[0];
  82. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  83. gd->bd->bi_dram[1].size = mx53_dram_size[1];
  84. return 0;
  85. }
  86. u32 get_board_rev(void)
  87. {
  88. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  89. struct fuse_bank *bank = &iim->bank[0];
  90. struct fuse_bank0_regs *fuse =
  91. (struct fuse_bank0_regs *)bank->fuse_regs;
  92. int rev = readl(&fuse->gp[6]);
  93. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  94. }
  95. /*
  96. * Set CCAT mode
  97. * @mode: use CCAT_MODE_CONFIG or CCAT_MODE_RUN
  98. */
  99. void weim_cs0_settings(u32 mode)
  100. {
  101. struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
  102. writel(0x0, &weim_regs->cs0gcr1);
  103. writel(mode, &weim_regs->cs0gcr1);
  104. writel(0x00001002, &weim_regs->cs0gcr2);
  105. writel(0x04000000, &weim_regs->cs0rcr1);
  106. writel(0x00000000, &weim_regs->cs0rcr2);
  107. writel(0x04000000, &weim_regs->cs0wcr1);
  108. writel(0x00000000, &weim_regs->cs0wcr2);
  109. }
  110. static void setup_gpio_eim(void)
  111. {
  112. gpio_direction_input(GPIO_C3_STATUS);
  113. gpio_direction_input(GPIO_C3_DONE);
  114. gpio_direction_output(GPIO_C3_CONFIG, 1);
  115. weim_cs0_settings(CCAT_MODE_RUN);
  116. }
  117. static void setup_gpio_sups(void)
  118. {
  119. gpio_direction_input(GPIO_SUPS_INT);
  120. static const int BLINK_INTERVALL = 50000;
  121. int status = 1;
  122. while (gpio_get_value(GPIO_SUPS_INT)) {
  123. /* signal "CX SUPS power fail" */
  124. gpio_set_value(GPIO_LED_PWR_R,
  125. (++status / BLINK_INTERVALL) % 2);
  126. }
  127. /* signal "CX power up" */
  128. gpio_set_value(GPIO_LED_PWR_R, 1);
  129. }
  130. static void setup_gpio_leds(void)
  131. {
  132. gpio_direction_output(GPIO_LED_SD2_R, 0);
  133. gpio_direction_output(GPIO_LED_SD2_B, 0);
  134. gpio_direction_output(GPIO_LED_SD2_G, 0);
  135. gpio_direction_output(GPIO_LED_SD1_R, 0);
  136. gpio_direction_output(GPIO_LED_SD1_B, 0);
  137. gpio_direction_output(GPIO_LED_SD1_G, 0);
  138. gpio_direction_output(GPIO_LED_PWR_R, 0);
  139. gpio_direction_output(GPIO_LED_PWR_B, 0);
  140. gpio_direction_output(GPIO_LED_PWR_G, 0);
  141. }
  142. #ifdef CONFIG_USB_EHCI_MX5
  143. int board_ehci_hcd_init(int port)
  144. {
  145. /* request VBUS power enable pin, GPIO7_8 */
  146. gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
  147. return 0;
  148. }
  149. #endif
  150. #ifdef CONFIG_FSL_ESDHC
  151. struct fsl_esdhc_cfg esdhc_cfg[2] = {
  152. {MMC_SDHC1_BASE_ADDR},
  153. {MMC_SDHC2_BASE_ADDR},
  154. };
  155. int board_mmc_getcd(struct mmc *mmc)
  156. {
  157. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  158. int ret;
  159. gpio_direction_input(GPIO_SD1_CD);
  160. gpio_direction_input(GPIO_SD2_CD);
  161. if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
  162. ret = !gpio_get_value(GPIO_SD1_CD);
  163. else
  164. ret = !gpio_get_value(GPIO_SD2_CD);
  165. return ret;
  166. }
  167. int board_mmc_init(bd_t *bis)
  168. {
  169. u32 index;
  170. int ret;
  171. esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  172. esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
  173. for (index = 0; index < CONFIG_SYS_FSL_ESDHC_NUM; index++) {
  174. switch (index) {
  175. case 0:
  176. break;
  177. case 1:
  178. break;
  179. default:
  180. printf("Warning: you configured more ESDHC controller(%d) as supported by the board(2)\n",
  181. CONFIG_SYS_FSL_ESDHC_NUM);
  182. return -EINVAL;
  183. }
  184. ret = fsl_esdhc_initialize(bis, &esdhc_cfg[index]);
  185. if (ret)
  186. return ret;
  187. }
  188. return 0;
  189. }
  190. #endif
  191. static int power_init(void)
  192. {
  193. /* nothing to do on CX9020 */
  194. return 0;
  195. }
  196. static void clock_1GHz(void)
  197. {
  198. int ret;
  199. u32 ref_clk = MXC_HCLK;
  200. /*
  201. * After increasing voltage to 1.25V, we can switch
  202. * CPU clock to 1GHz and DDR to 400MHz safely
  203. */
  204. ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
  205. if (ret)
  206. printf("CPU: Switch CPU clock to 1GHZ failed\n");
  207. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  208. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  209. if (ret)
  210. printf("CPU: Switch DDR clock to 400MHz failed\n");
  211. }
  212. int board_early_init_f(void)
  213. {
  214. setup_gpio_leds();
  215. setup_gpio_sups();
  216. setup_gpio_eim();
  217. setup_iomux_lcd();
  218. return 0;
  219. }
  220. /*
  221. * Do not overwrite the console
  222. * Use always serial for U-Boot console
  223. */
  224. int overwrite_console(void)
  225. {
  226. return 1;
  227. }
  228. int board_init(void)
  229. {
  230. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  231. mxc_set_sata_internal_clock();
  232. return 0;
  233. }
  234. int checkboard(void)
  235. {
  236. puts("Board: Beckhoff CX9020\n");
  237. return 0;
  238. }
  239. static int ccat_config_fn(int assert_config, int flush, int cookie)
  240. {
  241. /* prepare FPGA for programming */
  242. weim_cs0_settings(CCAT_MODE_CONFIG);
  243. gpio_set_value(GPIO_C3_CONFIG, 0);
  244. udelay(1);
  245. gpio_set_value(GPIO_C3_CONFIG, 1);
  246. udelay(230);
  247. return FPGA_SUCCESS;
  248. }
  249. static int ccat_status_fn(int cookie)
  250. {
  251. return FPGA_FAIL;
  252. }
  253. static int ccat_write_fn(const void *buf, size_t buf_len, int flush, int cookie)
  254. {
  255. const uint8_t *const buffer = buf;
  256. /* program CCAT */
  257. int i;
  258. for (i = 0; i < buf_len; ++i)
  259. writeb(buffer[i], CCAT_BASE_ADDR);
  260. writeb(0xff, CCAT_BASE_ADDR);
  261. writeb(0xff, CCAT_BASE_ADDR);
  262. return FPGA_SUCCESS;
  263. }
  264. static int ccat_done_fn(int cookie)
  265. {
  266. /* programming complete? */
  267. return gpio_get_value(GPIO_C3_DONE);
  268. }
  269. static int ccat_post_fn(int cookie)
  270. {
  271. /* switch to FPGA run mode */
  272. weim_cs0_settings(CCAT_MODE_RUN);
  273. invalidate_dcache_range((ulong) CCAT_BASE_ADDR, (ulong) CCAT_END_ADDR);
  274. if (memcmp(CCAT_SIGN_ADDR, CCAT_SIGNATURE, sizeof(CCAT_SIGNATURE))) {
  275. printf("Verifing CCAT firmware failed, signature not found\n");
  276. return FPGA_FAIL;
  277. }
  278. /* signal "CX booting OS" */
  279. gpio_set_value(GPIO_LED_PWR_R, 1);
  280. gpio_set_value(GPIO_LED_PWR_G, 1);
  281. gpio_set_value(GPIO_LED_PWR_B, 0);
  282. return FPGA_SUCCESS;
  283. }
  284. static Altera_CYC2_Passive_Serial_fns ccat_fns = {
  285. .config = ccat_config_fn,
  286. .status = ccat_status_fn,
  287. .done = ccat_done_fn,
  288. .write = ccat_write_fn,
  289. .abort = ccat_post_fn,
  290. .post = ccat_post_fn,
  291. };
  292. static Altera_desc ccat_fpga = {
  293. .family = Altera_CYC2,
  294. .iface = passive_serial,
  295. .size = CCAT_SIZE,
  296. .iface_fns = &ccat_fns,
  297. .base = CCAT_BASE_ADDR,
  298. };
  299. int board_late_init(void)
  300. {
  301. if (!power_init())
  302. clock_1GHz();
  303. fpga_init();
  304. fpga_add(fpga_altera, &ccat_fpga);
  305. return 0;
  306. }