mx53ppd.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 General Electric Company
  4. *
  5. * Based on board/freescale/mx53loco/mx53loco.c:
  6. *
  7. * Copyright (C) 2011 Freescale Semiconductor, Inc.
  8. * Jason Liu <r64343@freescale.com>
  9. */
  10. #include <common.h>
  11. #include <init.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 <env.h>
  20. #include <linux/errno.h>
  21. #include <linux/libfdt.h>
  22. #include <asm/mach-imx/mxc_i2c.h>
  23. #include <asm/mach-imx/mx5_video.h>
  24. #include <netdev.h>
  25. #include <i2c.h>
  26. #include <mmc.h>
  27. #include <fsl_esdhc_imx.h>
  28. #include <asm/gpio.h>
  29. #include <power/pmic.h>
  30. #include <dialog_pmic.h>
  31. #include <fsl_pmic.h>
  32. #include <linux/fb.h>
  33. #include <ipu_pixfmt.h>
  34. #include <version.h>
  35. #include <watchdog.h>
  36. #include "ppd_gpio.h"
  37. #include <stdlib.h>
  38. #include "../../ge/common/ge_common.h"
  39. #include "../../ge/common/vpd_reader.h"
  40. DECLARE_GLOBAL_DATA_PTR;
  41. static u32 mx53_dram_size[2];
  42. phys_size_t get_effective_memsize(void)
  43. {
  44. /*
  45. * WARNING: We must override get_effective_memsize() function here
  46. * to report only the size of the first DRAM bank. This is to make
  47. * U-Boot relocator place U-Boot into valid memory, that is, at the
  48. * end of the first DRAM bank. If we did not override this function
  49. * like so, U-Boot would be placed at the address of the first DRAM
  50. * bank + total DRAM size - sizeof(uboot), which in the setup where
  51. * each DRAM bank contains 512MiB of DRAM would result in placing
  52. * U-Boot into invalid memory area close to the end of the first
  53. * DRAM bank.
  54. */
  55. return mx53_dram_size[0];
  56. }
  57. int dram_init(void)
  58. {
  59. mx53_dram_size[0] = get_ram_size((void *)PHYS_SDRAM_1, 1 << 30);
  60. mx53_dram_size[1] = get_ram_size((void *)PHYS_SDRAM_2, 1 << 30);
  61. gd->ram_size = mx53_dram_size[0] + mx53_dram_size[1];
  62. return 0;
  63. }
  64. int dram_init_banksize(void)
  65. {
  66. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  67. gd->bd->bi_dram[0].size = mx53_dram_size[0];
  68. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  69. gd->bd->bi_dram[1].size = mx53_dram_size[1];
  70. return 0;
  71. }
  72. u32 get_board_rev(void)
  73. {
  74. return get_cpu_rev() & ~(0xF << 8);
  75. }
  76. #ifdef CONFIG_USB_EHCI_MX5
  77. int board_ehci_hcd_init(int port)
  78. {
  79. /* request VBUS power enable pin, GPIO7_8 */
  80. imx_iomux_v3_setup_pad(MX53_PAD_PATA_DA_2__GPIO7_8);
  81. gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
  82. return 0;
  83. }
  84. #endif
  85. static int clock_1GHz(void)
  86. {
  87. int ret;
  88. u32 ref_clk = MXC_HCLK;
  89. /*
  90. * After increasing voltage to 1.25V, we can switch
  91. * CPU clock to 1GHz and DDR to 400MHz safely
  92. */
  93. ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
  94. if (ret) {
  95. printf("CPU: Switch CPU clock to 1GHZ failed\n");
  96. return -1;
  97. }
  98. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  99. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  100. if (ret) {
  101. printf("CPU: Switch DDR clock to 400MHz failed\n");
  102. return -1;
  103. }
  104. return 0;
  105. }
  106. void ppd_gpio_init(void)
  107. {
  108. int i;
  109. imx_iomux_v3_setup_multiple_pads(ppd_pads, ARRAY_SIZE(ppd_pads));
  110. for (i = 0; i < ARRAY_SIZE(ppd_gpios); ++i) {
  111. gpio_request(ppd_gpios[i].gpio, "request");
  112. gpio_direction_output(ppd_gpios[i].gpio, ppd_gpios[i].value);
  113. }
  114. }
  115. int board_early_init_f(void)
  116. {
  117. ppd_gpio_init();
  118. return 0;
  119. }
  120. /*
  121. * Do not overwrite the console
  122. * Use always serial for U-Boot console
  123. */
  124. int overwrite_console(void)
  125. {
  126. return 1;
  127. }
  128. #define VPD_TYPE_INVALID 0x00
  129. #define VPD_BLOCK_NETWORK 0x20
  130. #define VPD_BLOCK_HWID 0x44
  131. #define VPD_PRODUCT_PPD 4
  132. #define VPD_HAS_MAC1 0x1
  133. #define VPD_MAC_ADDRESS_LENGTH 6
  134. struct vpd_cache {
  135. u8 product_id;
  136. u8 has;
  137. unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
  138. };
  139. /*
  140. * Extracts MAC and product information from the VPD.
  141. */
  142. static int vpd_callback(struct vpd_cache *userdata, u8 id, u8 version,
  143. u8 type, size_t size, u8 const *data)
  144. {
  145. struct vpd_cache *vpd = userdata;
  146. if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
  147. size >= 1) {
  148. vpd->product_id = data[0];
  149. } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
  150. type != VPD_TYPE_INVALID) {
  151. if (size >= 6) {
  152. vpd->has |= VPD_HAS_MAC1;
  153. memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
  154. }
  155. }
  156. return 0;
  157. }
  158. static void process_vpd(struct vpd_cache *vpd)
  159. {
  160. int fec_index = -1;
  161. if (vpd->product_id == VPD_PRODUCT_PPD)
  162. fec_index = 0;
  163. if (fec_index >= 0 && (vpd->has & VPD_HAS_MAC1))
  164. eth_env_set_enetaddr("ethaddr", vpd->mac1);
  165. }
  166. int board_init(void)
  167. {
  168. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  169. mxc_set_sata_internal_clock();
  170. return 0;
  171. }
  172. int misc_init_r(void)
  173. {
  174. const char *cause;
  175. /* We care about WDOG only, treating everything else as
  176. * a power-on-reset.
  177. */
  178. if (get_imx_reset_cause() & 0x0010)
  179. cause = "WDOG";
  180. else
  181. cause = "POR";
  182. env_set("bootcause", cause);
  183. return 0;
  184. }
  185. int board_late_init(void)
  186. {
  187. int res;
  188. struct vpd_cache vpd;
  189. memset(&vpd, 0, sizeof(vpd));
  190. res = read_vpd(&vpd, vpd_callback);
  191. if (!res)
  192. process_vpd(&vpd);
  193. else
  194. printf("Can't read VPD");
  195. res = clock_1GHz();
  196. if (res != 0)
  197. return res;
  198. print_cpuinfo();
  199. check_time();
  200. return 0;
  201. }
  202. int checkboard(void)
  203. {
  204. puts("Board: GE PPD\n");
  205. return 0;
  206. }
  207. #ifdef CONFIG_OF_BOARD_SETUP
  208. int ft_board_setup(void *blob, struct bd_info *bd)
  209. {
  210. char *rtc_status = env_get("rtc_status");
  211. fdt_setprop(blob, 0, "ge,boot-ver", version_string,
  212. strlen(version_string) + 1);
  213. fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
  214. strlen(rtc_status) + 1);
  215. return 0;
  216. }
  217. #endif