mx53ppd.c 5.4 KB

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