mx53cx9020.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Beckhoff Automation GmbH & Co. KG
  4. * Patrick Bruenn <p.bruenn@beckhoff.com>
  5. *
  6. * Based on <u-boot>/board/freescale/mx53loco/mx53loco.c
  7. * Copyright (C) 2011 Freescale Semiconductor, Inc.
  8. */
  9. #include <common.h>
  10. #include <dm.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/mach-imx/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 <input.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. u32 get_board_rev(void)
  56. {
  57. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  58. struct fuse_bank *bank = &iim->bank[0];
  59. struct fuse_bank0_regs *fuse =
  60. (struct fuse_bank0_regs *)bank->fuse_regs;
  61. int rev = readl(&fuse->gp[6]);
  62. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  63. }
  64. /*
  65. * Set CCAT mode
  66. * @mode: use CCAT_MODE_CONFIG or CCAT_MODE_RUN
  67. */
  68. void weim_cs0_settings(u32 mode)
  69. {
  70. struct weim *weim_regs = (struct weim *)WEIM_BASE_ADDR;
  71. writel(0x0, &weim_regs->cs0gcr1);
  72. writel(mode, &weim_regs->cs0gcr1);
  73. writel(0x00001002, &weim_regs->cs0gcr2);
  74. writel(0x04000000, &weim_regs->cs0rcr1);
  75. writel(0x00000000, &weim_regs->cs0rcr2);
  76. writel(0x04000000, &weim_regs->cs0wcr1);
  77. writel(0x00000000, &weim_regs->cs0wcr2);
  78. }
  79. static void setup_gpio_eim(void)
  80. {
  81. gpio_direction_input(GPIO_C3_STATUS);
  82. gpio_direction_input(GPIO_C3_DONE);
  83. gpio_direction_output(GPIO_C3_CONFIG, 1);
  84. weim_cs0_settings(CCAT_MODE_RUN);
  85. }
  86. static void setup_gpio_sups(void)
  87. {
  88. gpio_direction_input(GPIO_SUPS_INT);
  89. static const int BLINK_INTERVALL = 50000;
  90. int status = 1;
  91. while (gpio_get_value(GPIO_SUPS_INT)) {
  92. /* signal "CX SUPS power fail" */
  93. gpio_set_value(GPIO_LED_PWR_R,
  94. (++status / BLINK_INTERVALL) % 2);
  95. }
  96. /* signal "CX power up" */
  97. gpio_set_value(GPIO_LED_PWR_R, 1);
  98. }
  99. static void setup_gpio_leds(void)
  100. {
  101. gpio_direction_output(GPIO_LED_SD2_R, 0);
  102. gpio_direction_output(GPIO_LED_SD2_B, 0);
  103. gpio_direction_output(GPIO_LED_SD2_G, 0);
  104. gpio_direction_output(GPIO_LED_SD1_R, 0);
  105. gpio_direction_output(GPIO_LED_SD1_B, 0);
  106. gpio_direction_output(GPIO_LED_SD1_G, 0);
  107. gpio_direction_output(GPIO_LED_PWR_R, 0);
  108. gpio_direction_output(GPIO_LED_PWR_B, 0);
  109. gpio_direction_output(GPIO_LED_PWR_G, 0);
  110. }
  111. #ifdef CONFIG_USB_EHCI_MX5
  112. int board_ehci_hcd_init(int port)
  113. {
  114. /* request VBUS power enable pin, GPIO7_8 */
  115. gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
  116. return 0;
  117. }
  118. #endif
  119. #ifdef CONFIG_FSL_ESDHC
  120. struct fsl_esdhc_cfg esdhc_cfg[2] = {
  121. {MMC_SDHC1_BASE_ADDR},
  122. {MMC_SDHC2_BASE_ADDR},
  123. };
  124. int board_mmc_getcd(struct mmc *mmc)
  125. {
  126. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  127. int ret;
  128. gpio_direction_input(GPIO_SD1_CD);
  129. gpio_direction_input(GPIO_SD2_CD);
  130. if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
  131. ret = !gpio_get_value(GPIO_SD1_CD);
  132. else
  133. ret = !gpio_get_value(GPIO_SD2_CD);
  134. return ret;
  135. }
  136. int board_mmc_init(bd_t *bis)
  137. {
  138. u32 index;
  139. int ret;
  140. esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  141. esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
  142. for (index = 0; index < CONFIG_SYS_FSL_ESDHC_NUM; index++) {
  143. switch (index) {
  144. case 0:
  145. break;
  146. case 1:
  147. break;
  148. default:
  149. printf("Warning: you configured more ESDHC controller(%d) as supported by the board(2)\n",
  150. CONFIG_SYS_FSL_ESDHC_NUM);
  151. return -EINVAL;
  152. }
  153. ret = fsl_esdhc_initialize(bis, &esdhc_cfg[index]);
  154. if (ret)
  155. return ret;
  156. }
  157. return 0;
  158. }
  159. #endif
  160. static int power_init(void)
  161. {
  162. /* nothing to do on CX9020 */
  163. return 0;
  164. }
  165. static void clock_1GHz(void)
  166. {
  167. int ret;
  168. u32 ref_clk = MXC_HCLK;
  169. /*
  170. * After increasing voltage to 1.25V, we can switch
  171. * CPU clock to 1GHz and DDR to 400MHz safely
  172. */
  173. ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
  174. if (ret)
  175. printf("CPU: Switch CPU clock to 1GHZ failed\n");
  176. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  177. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  178. if (ret)
  179. printf("CPU: Switch DDR clock to 400MHz failed\n");
  180. }
  181. int board_early_init_f(void)
  182. {
  183. setup_gpio_leds();
  184. setup_gpio_sups();
  185. setup_gpio_eim();
  186. setup_iomux_lcd();
  187. return 0;
  188. }
  189. /*
  190. * Do not overwrite the console
  191. * Use always serial for U-Boot console
  192. */
  193. int overwrite_console(void)
  194. {
  195. return 1;
  196. }
  197. int board_init(void)
  198. {
  199. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  200. mxc_set_sata_internal_clock();
  201. return 0;
  202. }
  203. int checkboard(void)
  204. {
  205. puts("Board: Beckhoff CX9020\n");
  206. return 0;
  207. }
  208. static int ccat_config_fn(int assert_config, int flush, int cookie)
  209. {
  210. /* prepare FPGA for programming */
  211. weim_cs0_settings(CCAT_MODE_CONFIG);
  212. gpio_set_value(GPIO_C3_CONFIG, 0);
  213. udelay(1);
  214. gpio_set_value(GPIO_C3_CONFIG, 1);
  215. udelay(230);
  216. return FPGA_SUCCESS;
  217. }
  218. static int ccat_status_fn(int cookie)
  219. {
  220. return FPGA_FAIL;
  221. }
  222. static int ccat_write_fn(const void *buf, size_t buf_len, int flush, int cookie)
  223. {
  224. const uint8_t *const buffer = buf;
  225. /* program CCAT */
  226. int i;
  227. for (i = 0; i < buf_len; ++i)
  228. writeb(buffer[i], CCAT_BASE_ADDR);
  229. writeb(0xff, CCAT_BASE_ADDR);
  230. writeb(0xff, CCAT_BASE_ADDR);
  231. return FPGA_SUCCESS;
  232. }
  233. static int ccat_done_fn(int cookie)
  234. {
  235. /* programming complete? */
  236. return gpio_get_value(GPIO_C3_DONE);
  237. }
  238. static int ccat_post_fn(int cookie)
  239. {
  240. /* switch to FPGA run mode */
  241. weim_cs0_settings(CCAT_MODE_RUN);
  242. invalidate_dcache_range((ulong) CCAT_BASE_ADDR, (ulong) CCAT_END_ADDR);
  243. if (memcmp(CCAT_SIGN_ADDR, CCAT_SIGNATURE, sizeof(CCAT_SIGNATURE))) {
  244. printf("Verifing CCAT firmware failed, signature not found\n");
  245. return FPGA_FAIL;
  246. }
  247. /* signal "CX booting OS" */
  248. gpio_set_value(GPIO_LED_PWR_R, 1);
  249. gpio_set_value(GPIO_LED_PWR_G, 1);
  250. gpio_set_value(GPIO_LED_PWR_B, 0);
  251. return FPGA_SUCCESS;
  252. }
  253. static Altera_CYC2_Passive_Serial_fns ccat_fns = {
  254. .config = ccat_config_fn,
  255. .status = ccat_status_fn,
  256. .done = ccat_done_fn,
  257. .write = ccat_write_fn,
  258. .abort = ccat_post_fn,
  259. .post = ccat_post_fn,
  260. };
  261. static Altera_desc ccat_fpga = {
  262. .family = Altera_CYC2,
  263. .iface = passive_serial,
  264. .size = CCAT_SIZE,
  265. .iface_fns = &ccat_fns,
  266. .base = CCAT_BASE_ADDR,
  267. };
  268. int board_late_init(void)
  269. {
  270. if (!power_init())
  271. clock_1GHz();
  272. fpga_init();
  273. fpga_add(fpga_altera, &ccat_fpga);
  274. return 0;
  275. }