mx53ppd.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.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. u32 get_board_rev(void)
  74. {
  75. return get_cpu_rev() & ~(0xF << 8);
  76. }
  77. #ifdef CONFIG_USB_EHCI_MX5
  78. int board_ehci_hcd_init(int port)
  79. {
  80. /* request VBUS power enable pin, GPIO7_8 */
  81. imx_iomux_v3_setup_pad(MX53_PAD_PATA_DA_2__GPIO7_8);
  82. gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
  83. return 0;
  84. }
  85. #endif
  86. static int clock_1GHz(void)
  87. {
  88. int ret;
  89. u32 ref_clk = MXC_HCLK;
  90. /*
  91. * After increasing voltage to 1.25V, we can switch
  92. * CPU clock to 1GHz and DDR to 400MHz safely
  93. */
  94. ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
  95. if (ret) {
  96. printf("CPU: Switch CPU clock to 1GHZ failed\n");
  97. return -1;
  98. }
  99. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  100. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  101. if (ret) {
  102. printf("CPU: Switch DDR clock to 400MHz failed\n");
  103. return -1;
  104. }
  105. return 0;
  106. }
  107. void ppd_gpio_init(void)
  108. {
  109. int i;
  110. imx_iomux_v3_setup_multiple_pads(ppd_pads, ARRAY_SIZE(ppd_pads));
  111. for (i = 0; i < ARRAY_SIZE(ppd_gpios); ++i) {
  112. gpio_request(ppd_gpios[i].gpio, "request");
  113. gpio_direction_output(ppd_gpios[i].gpio, ppd_gpios[i].value);
  114. }
  115. }
  116. int board_early_init_f(void)
  117. {
  118. ppd_gpio_init();
  119. return 0;
  120. }
  121. /*
  122. * Do not overwrite the console
  123. * Use always serial for U-Boot console
  124. */
  125. int overwrite_console(void)
  126. {
  127. return 1;
  128. }
  129. #define VPD_TYPE_INVALID 0x00
  130. #define VPD_BLOCK_NETWORK 0x20
  131. #define VPD_BLOCK_HWID 0x44
  132. #define VPD_PRODUCT_PPD 4
  133. #define VPD_HAS_MAC1 0x1
  134. #define VPD_MAC_ADDRESS_LENGTH 6
  135. struct vpd_cache {
  136. u8 product_id;
  137. u8 has;
  138. unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
  139. };
  140. /*
  141. * Extracts MAC and product information from the VPD.
  142. */
  143. static int vpd_callback(struct vpd_cache *userdata, u8 id, u8 version,
  144. u8 type, size_t size, u8 const *data)
  145. {
  146. struct vpd_cache *vpd = userdata;
  147. if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
  148. size >= 1) {
  149. vpd->product_id = data[0];
  150. } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
  151. type != VPD_TYPE_INVALID) {
  152. if (size >= 6) {
  153. vpd->has |= VPD_HAS_MAC1;
  154. memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
  155. }
  156. }
  157. return 0;
  158. }
  159. static void process_vpd(struct vpd_cache *vpd)
  160. {
  161. int fec_index = -1;
  162. if (vpd->product_id == VPD_PRODUCT_PPD)
  163. fec_index = 0;
  164. if (fec_index >= 0 && (vpd->has & VPD_HAS_MAC1))
  165. eth_env_set_enetaddr("ethaddr", vpd->mac1);
  166. }
  167. int board_init(void)
  168. {
  169. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  170. mxc_set_sata_internal_clock();
  171. return 0;
  172. }
  173. int misc_init_r(void)
  174. {
  175. const char *cause;
  176. /* We care about WDOG only, treating everything else as
  177. * a power-on-reset.
  178. */
  179. if (get_imx_reset_cause() & 0x0010)
  180. cause = "WDOG";
  181. else
  182. cause = "POR";
  183. env_set("bootcause", cause);
  184. return 0;
  185. }
  186. int board_late_init(void)
  187. {
  188. int res;
  189. struct vpd_cache vpd;
  190. memset(&vpd, 0, sizeof(vpd));
  191. res = read_i2c_vpd(&vpd, vpd_callback);
  192. if (!res)
  193. process_vpd(&vpd);
  194. else
  195. printf("Can't read VPD");
  196. res = clock_1GHz();
  197. if (res != 0)
  198. return res;
  199. print_cpuinfo();
  200. check_time();
  201. return 0;
  202. }
  203. int checkboard(void)
  204. {
  205. puts("Board: GE PPD\n");
  206. return 0;
  207. }
  208. #ifdef CONFIG_OF_BOARD_SETUP
  209. int ft_board_setup(void *blob, struct bd_info *bd)
  210. {
  211. char *rtc_status = env_get("rtc_status");
  212. fdt_setprop(blob, 0, "ge,boot-ver", version_string,
  213. strlen(version_string) + 1);
  214. fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
  215. strlen(rtc_status) + 1);
  216. return 0;
  217. }
  218. #endif