kp_imx53.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018
  4. * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
  5. */
  6. #include <common.h>
  7. #include <init.h>
  8. #include <asm/global_data.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/imx-regs.h>
  11. #include <asm/arch/sys_proto.h>
  12. #include <asm/arch/crm_regs.h>
  13. #include <asm/arch/clock.h>
  14. #include <asm/arch/iomux-mx53.h>
  15. #include <asm/arch/clock.h>
  16. #include <asm/gpio.h>
  17. #include <env.h>
  18. #include <power/pmic.h>
  19. #include <fsl_pmic.h>
  20. #include <bootstage.h>
  21. #include "kp_id_rev.h"
  22. #define BOOSTER_OFF IMX_GPIO_NR(2, 23)
  23. #define LCD_BACKLIGHT IMX_GPIO_NR(1, 1)
  24. #define KEY1 IMX_GPIO_NR(2, 26)
  25. #define LED_RED IMX_GPIO_NR(3, 28)
  26. DECLARE_GLOBAL_DATA_PTR;
  27. int dram_init(void)
  28. {
  29. u32 size;
  30. size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
  31. gd->ram_size = size;
  32. return 0;
  33. }
  34. int dram_init_banksize(void)
  35. {
  36. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  37. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  38. return 0;
  39. }
  40. static int power_init(void)
  41. {
  42. struct udevice *dev;
  43. int ret;
  44. ret = pmic_get("mc34708@8", &dev);
  45. if (ret) {
  46. printf("%s: mc34708 not found !\n", __func__);
  47. return ret;
  48. }
  49. /* Set VDDGP to 1.110V for 800 MHz on SW1 */
  50. pmic_clrsetbits(dev, REG_SW_0, SWx_VOLT_MASK_MC34708,
  51. SWx_1_110V_MC34708);
  52. /* Set VCC as 1.30V on SW2 */
  53. pmic_clrsetbits(dev, REG_SW_1, SWx_VOLT_MASK_MC34708,
  54. SWx_1_300V_MC34708);
  55. /* Set global reset timer to 4s */
  56. pmic_clrsetbits(dev, REG_POWER_CTL2, TIMER_MASK_MC34708,
  57. TIMER_4S_MC34708);
  58. return ret;
  59. }
  60. static void setup_clocks(void)
  61. {
  62. int ret;
  63. u32 ref_clk = MXC_HCLK;
  64. /*
  65. * CPU clock set to 800MHz and DDR to 400MHz
  66. */
  67. ret = mxc_set_clock(ref_clk, 800, MXC_ARM_CLK);
  68. if (ret)
  69. printf("CPU: Switch CPU clock to 800MHZ failed\n");
  70. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  71. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  72. if (ret)
  73. printf("CPU: Switch DDR clock to 400MHz failed\n");
  74. }
  75. static void setup_ups(void)
  76. {
  77. gpio_request(BOOSTER_OFF, "BOOSTER_OFF");
  78. gpio_direction_output(BOOSTER_OFF, 0);
  79. }
  80. int board_early_init_f(void)
  81. {
  82. return 0;
  83. }
  84. /*
  85. * Do not overwrite the console
  86. * Use always serial for U-Boot console
  87. */
  88. int overwrite_console(void)
  89. {
  90. return 1;
  91. }
  92. int board_init(void)
  93. {
  94. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  95. return 0;
  96. }
  97. void board_disable_display(void)
  98. {
  99. gpio_request(LCD_BACKLIGHT, "LCD_BACKLIGHT");
  100. gpio_direction_output(LCD_BACKLIGHT, 0);
  101. }
  102. void board_misc_setup(void)
  103. {
  104. gpio_request(KEY1, "KEY1_GPIO");
  105. gpio_direction_input(KEY1);
  106. if (gpio_get_value(KEY1))
  107. env_set("key1", "off");
  108. else
  109. env_set("key1", "on");
  110. }
  111. int board_late_init(void)
  112. {
  113. int ret = 0;
  114. board_disable_display();
  115. setup_ups();
  116. if (!power_init())
  117. setup_clocks();
  118. ret = read_eeprom();
  119. if (ret)
  120. printf("Error %d reading EEPROM content!\n", ret);
  121. show_eeprom();
  122. read_board_id();
  123. board_misc_setup();
  124. return ret;
  125. }
  126. #if CONFIG_IS_ENABLED(BOOTSTAGE)
  127. #define GPIO_DR 0x0
  128. #define GPIO_GDIR 0x4
  129. #define GPIO_ALT1 0x1
  130. #define GPIO5_BASE 0x53FDC000
  131. #define IOMUXC_EIM_WAIT 0x53FA81E4
  132. /* Green LED: GPIO5_0 */
  133. #define GPIO_GREEN BIT(0)
  134. void show_boot_progress(int status)
  135. {
  136. /*
  137. * This BOOTSTAGE_ID is called at very early stage of execution. DM gpio
  138. * is not yet initialized.
  139. */
  140. if (status == BOOTSTAGE_ID_START_UBOOT_F) {
  141. /*
  142. * After ROM execution the EIM_WAIT PAD is set as ALT0
  143. * (according to RM it shall be ALT1 after reset). To use it as
  144. * GPIO we need to set it to ALT1.
  145. */
  146. setbits_le32(((uint32_t *)(IOMUXC_EIM_WAIT)), GPIO_ALT1);
  147. /* Configure green LED GPIO pin direction */
  148. setbits_le32(((uint32_t *)(GPIO5_BASE + GPIO_GDIR)),
  149. GPIO_GREEN);
  150. /* Turn on green LED */
  151. setbits_le32(((uint32_t *)(GPIO5_BASE + GPIO_DR)), GPIO_GREEN);
  152. }
  153. /*
  154. * This BOOTSTAGE_ID is called just before handling execution to kernel
  155. * - i.e. gpio subsystem is already initialized
  156. */
  157. if (status == BOOTSTAGE_ID_BOOTM_HANDOFF) {
  158. /*
  159. * Off green LED - the same approach - i.e. non dm gpio
  160. * (*bits_le32) is used as in the very early stage.
  161. */
  162. clrbits_le32(((uint32_t *)(GPIO5_BASE + GPIO_DR)),
  163. GPIO_GREEN);
  164. /*
  165. * On red LED
  166. */
  167. gpio_request(LED_RED, "LED_RED_ERROR");
  168. gpio_direction_output(LED_RED, 1);
  169. }
  170. }
  171. #endif