mx53cx9020.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 <asm/io.h>
  12. #include <asm/arch/imx-regs.h>
  13. #include <asm/arch/sys_proto.h>
  14. #include <asm/arch/crm_regs.h>
  15. #include <asm/arch/clock.h>
  16. #include <asm/arch/iomux-mx53.h>
  17. #include <asm/arch/clock.h>
  18. #include <asm/imx-common/mx5_video.h>
  19. #include <ACEX1K.h>
  20. #include <netdev.h>
  21. #include <i2c.h>
  22. #include <mmc.h>
  23. #include <fsl_esdhc.h>
  24. #include <asm/gpio.h>
  25. #include <linux/fb.h>
  26. #include <ipu_pixfmt.h>
  27. #include <fs.h>
  28. #include <dm/platdata.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. void 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. }
  85. u32 get_board_rev(void)
  86. {
  87. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  88. struct fuse_bank *bank = &iim->bank[0];
  89. struct fuse_bank0_regs *fuse =
  90. (struct fuse_bank0_regs *)bank->fuse_regs;
  91. int rev = readl(&fuse->gp[6]);
  92. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  93. }
  94. /*
  95. * Set CCAT mode
  96. * @mode: use CCAT_MODE_CONFIG or CCAT_MODE_RUN
  97. */
  98. void weim_cs0_settings(u32 mode)
  99. {
  100. struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
  101. writel(0x0, &weim_regs->cs0gcr1);
  102. writel(mode, &weim_regs->cs0gcr1);
  103. writel(0x00001002, &weim_regs->cs0gcr2);
  104. writel(0x04000000, &weim_regs->cs0rcr1);
  105. writel(0x00000000, &weim_regs->cs0rcr2);
  106. writel(0x04000000, &weim_regs->cs0wcr1);
  107. writel(0x00000000, &weim_regs->cs0wcr2);
  108. }
  109. static void setup_gpio_eim(void)
  110. {
  111. gpio_direction_input(GPIO_C3_STATUS);
  112. gpio_direction_input(GPIO_C3_DONE);
  113. gpio_direction_output(GPIO_C3_CONFIG, 1);
  114. weim_cs0_settings(CCAT_MODE_RUN);
  115. }
  116. static void setup_gpio_sups(void)
  117. {
  118. gpio_direction_input(GPIO_SUPS_INT);
  119. static const int BLINK_INTERVALL = 50000;
  120. int status = 1;
  121. while (gpio_get_value(GPIO_SUPS_INT)) {
  122. /* signal "CX SUPS power fail" */
  123. gpio_set_value(GPIO_LED_PWR_R,
  124. (++status / BLINK_INTERVALL) % 2);
  125. }
  126. /* signal "CX power up" */
  127. gpio_set_value(GPIO_LED_PWR_R, 1);
  128. }
  129. static void setup_gpio_leds(void)
  130. {
  131. gpio_direction_output(GPIO_LED_SD2_R, 0);
  132. gpio_direction_output(GPIO_LED_SD2_B, 0);
  133. gpio_direction_output(GPIO_LED_SD2_G, 0);
  134. gpio_direction_output(GPIO_LED_SD1_R, 0);
  135. gpio_direction_output(GPIO_LED_SD1_B, 0);
  136. gpio_direction_output(GPIO_LED_SD1_G, 0);
  137. gpio_direction_output(GPIO_LED_PWR_R, 0);
  138. gpio_direction_output(GPIO_LED_PWR_B, 0);
  139. gpio_direction_output(GPIO_LED_PWR_G, 0);
  140. }
  141. #ifdef CONFIG_USB_EHCI_MX5
  142. int board_ehci_hcd_init(int port)
  143. {
  144. /* request VBUS power enable pin, GPIO7_8 */
  145. gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
  146. return 0;
  147. }
  148. #endif
  149. #ifdef CONFIG_FSL_ESDHC
  150. struct fsl_esdhc_cfg esdhc_cfg[2] = {
  151. {MMC_SDHC1_BASE_ADDR},
  152. {MMC_SDHC2_BASE_ADDR},
  153. };
  154. int board_mmc_getcd(struct mmc *mmc)
  155. {
  156. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  157. int ret;
  158. gpio_direction_input(GPIO_SD1_CD);
  159. gpio_direction_input(GPIO_SD2_CD);
  160. if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
  161. ret = !gpio_get_value(GPIO_SD1_CD);
  162. else
  163. ret = !gpio_get_value(GPIO_SD2_CD);
  164. return ret;
  165. }
  166. int board_mmc_init(bd_t *bis)
  167. {
  168. u32 index;
  169. int ret;
  170. esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  171. esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
  172. for (index = 0; index < CONFIG_SYS_FSL_ESDHC_NUM; index++) {
  173. switch (index) {
  174. case 0:
  175. break;
  176. case 1:
  177. break;
  178. default:
  179. printf("Warning: you configured more ESDHC controller(%d) as supported by the board(2)\n",
  180. CONFIG_SYS_FSL_ESDHC_NUM);
  181. return -EINVAL;
  182. }
  183. ret = fsl_esdhc_initialize(bis, &esdhc_cfg[index]);
  184. if (ret)
  185. return ret;
  186. }
  187. return 0;
  188. }
  189. #endif
  190. static int power_init(void)
  191. {
  192. /* nothing to do on CX9020 */
  193. return 0;
  194. }
  195. static void clock_1GHz(void)
  196. {
  197. int ret;
  198. u32 ref_clk = MXC_HCLK;
  199. /*
  200. * After increasing voltage to 1.25V, we can switch
  201. * CPU clock to 1GHz and DDR to 400MHz safely
  202. */
  203. ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
  204. if (ret)
  205. printf("CPU: Switch CPU clock to 1GHZ failed\n");
  206. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  207. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  208. if (ret)
  209. printf("CPU: Switch DDR clock to 400MHz failed\n");
  210. }
  211. int board_early_init_f(void)
  212. {
  213. setup_gpio_leds();
  214. setup_gpio_sups();
  215. setup_gpio_eim();
  216. setup_iomux_lcd();
  217. return 0;
  218. }
  219. /*
  220. * Do not overwrite the console
  221. * Use always serial for U-Boot console
  222. */
  223. int overwrite_console(void)
  224. {
  225. return 1;
  226. }
  227. int board_init(void)
  228. {
  229. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  230. mxc_set_sata_internal_clock();
  231. return 0;
  232. }
  233. int checkboard(void)
  234. {
  235. puts("Board: Beckhoff CX9020\n");
  236. return 0;
  237. }
  238. static int ccat_config_fn(int assert_config, int flush, int cookie)
  239. {
  240. /* prepare FPGA for programming */
  241. weim_cs0_settings(CCAT_MODE_CONFIG);
  242. gpio_set_value(GPIO_C3_CONFIG, 0);
  243. udelay(1);
  244. gpio_set_value(GPIO_C3_CONFIG, 1);
  245. udelay(230);
  246. return FPGA_SUCCESS;
  247. }
  248. static int ccat_status_fn(int cookie)
  249. {
  250. return FPGA_FAIL;
  251. }
  252. static int ccat_write_fn(const void *buf, size_t buf_len, int flush, int cookie)
  253. {
  254. const uint8_t *const buffer = buf;
  255. /* program CCAT */
  256. int i;
  257. for (i = 0; i < buf_len; ++i)
  258. writeb(buffer[i], CCAT_BASE_ADDR);
  259. writeb(0xff, CCAT_BASE_ADDR);
  260. writeb(0xff, CCAT_BASE_ADDR);
  261. return FPGA_SUCCESS;
  262. }
  263. static int ccat_done_fn(int cookie)
  264. {
  265. /* programming complete? */
  266. return gpio_get_value(GPIO_C3_DONE);
  267. }
  268. static int ccat_post_fn(int cookie)
  269. {
  270. /* switch to FPGA run mode */
  271. weim_cs0_settings(CCAT_MODE_RUN);
  272. invalidate_dcache_range((ulong) CCAT_BASE_ADDR, (ulong) CCAT_END_ADDR);
  273. if (memcmp(CCAT_SIGN_ADDR, CCAT_SIGNATURE, sizeof(CCAT_SIGNATURE))) {
  274. printf("Verifing CCAT firmware failed, signature not found\n");
  275. return FPGA_FAIL;
  276. }
  277. /* signal "CX booting OS" */
  278. gpio_set_value(GPIO_LED_PWR_R, 1);
  279. gpio_set_value(GPIO_LED_PWR_G, 1);
  280. gpio_set_value(GPIO_LED_PWR_B, 0);
  281. return FPGA_SUCCESS;
  282. }
  283. static Altera_CYC2_Passive_Serial_fns ccat_fns = {
  284. .config = ccat_config_fn,
  285. .status = ccat_status_fn,
  286. .done = ccat_done_fn,
  287. .write = ccat_write_fn,
  288. .abort = ccat_post_fn,
  289. .post = ccat_post_fn,
  290. };
  291. static Altera_desc ccat_fpga = {
  292. .family = Altera_CYC2,
  293. .iface = passive_serial,
  294. .size = CCAT_SIZE,
  295. .iface_fns = &ccat_fns,
  296. .base = CCAT_BASE_ADDR,
  297. };
  298. int board_late_init(void)
  299. {
  300. if (!power_init())
  301. clock_1GHz();
  302. fpga_init();
  303. fpga_add(fpga_altera, &ccat_fpga);
  304. return 0;
  305. }