mx53loco.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2011 Freescale Semiconductor, Inc.
  4. * Jason Liu <r64343@freescale.com>
  5. */
  6. #include <common.h>
  7. #include <init.h>
  8. #include <log.h>
  9. #include <asm/global_data.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/imx-regs.h>
  12. #include <asm/arch/sys_proto.h>
  13. #include <asm/arch/crm_regs.h>
  14. #include <asm/arch/clock.h>
  15. #include <asm/arch/iomux-mx53.h>
  16. #include <asm/arch/clock.h>
  17. #include <env.h>
  18. #include <linux/errno.h>
  19. #include <asm/mach-imx/mx5_video.h>
  20. #include <i2c.h>
  21. #include <input.h>
  22. #include <fsl_esdhc_imx.h>
  23. #include <asm/gpio.h>
  24. #include <power/pmic.h>
  25. #include <dialog_pmic.h>
  26. #include <fsl_pmic.h>
  27. #include <linux/fb.h>
  28. #include <ipu_pixfmt.h>
  29. #define MX53LOCO_LCD_POWER IMX_GPIO_NR(3, 24)
  30. DECLARE_GLOBAL_DATA_PTR;
  31. u32 get_board_rev(void)
  32. {
  33. struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
  34. struct fuse_bank *bank = &iim->bank[0];
  35. struct fuse_bank0_regs *fuse =
  36. (struct fuse_bank0_regs *)bank->fuse_regs;
  37. int rev = readl(&fuse->gp[6]);
  38. if (!i2c_probe(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR))
  39. rev = 0;
  40. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  41. }
  42. #define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_DSE_HIGH | \
  43. PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
  44. static void setup_iomux_uart(void)
  45. {
  46. static const iomux_v3_cfg_t uart_pads[] = {
  47. NEW_PAD_CTRL(MX53_PAD_CSI0_DAT11__UART1_RXD_MUX, UART_PAD_CTRL),
  48. NEW_PAD_CTRL(MX53_PAD_CSI0_DAT10__UART1_TXD_MUX, UART_PAD_CTRL),
  49. };
  50. imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
  51. }
  52. #define I2C_PAD_CTRL (PAD_CTL_SRE_FAST | PAD_CTL_DSE_HIGH | \
  53. PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
  54. static void setup_iomux_i2c(void)
  55. {
  56. static const iomux_v3_cfg_t i2c1_pads[] = {
  57. NEW_PAD_CTRL(MX53_PAD_CSI0_DAT8__I2C1_SDA, I2C_PAD_CTRL),
  58. NEW_PAD_CTRL(MX53_PAD_CSI0_DAT9__I2C1_SCL, I2C_PAD_CTRL),
  59. };
  60. imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads));
  61. }
  62. static int power_init(void)
  63. {
  64. unsigned int val;
  65. int ret;
  66. struct pmic *p;
  67. if (!i2c_probe(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR)) {
  68. ret = pmic_dialog_init(I2C_PMIC);
  69. if (ret)
  70. return ret;
  71. p = pmic_get("DIALOG_PMIC");
  72. if (!p)
  73. return -ENODEV;
  74. env_set("fdt_file", "imx53-qsb.dtb");
  75. /* Set VDDA to 1.25V */
  76. val = DA9052_BUCKCORE_BCOREEN | DA_BUCKCORE_VBCORE_1_250V;
  77. ret = pmic_reg_write(p, DA9053_BUCKCORE_REG, val);
  78. if (ret) {
  79. printf("Writing to BUCKCORE_REG failed: %d\n", ret);
  80. return ret;
  81. }
  82. pmic_reg_read(p, DA9053_SUPPLY_REG, &val);
  83. val |= DA9052_SUPPLY_VBCOREGO;
  84. ret = pmic_reg_write(p, DA9053_SUPPLY_REG, val);
  85. if (ret) {
  86. printf("Writing to SUPPLY_REG failed: %d\n", ret);
  87. return ret;
  88. }
  89. /* Set Vcc peripheral to 1.30V */
  90. ret = pmic_reg_write(p, DA9053_BUCKPRO_REG, 0x62);
  91. if (ret) {
  92. printf("Writing to BUCKPRO_REG failed: %d\n", ret);
  93. return ret;
  94. }
  95. ret = pmic_reg_write(p, DA9053_SUPPLY_REG, 0x62);
  96. if (ret) {
  97. printf("Writing to SUPPLY_REG failed: %d\n", ret);
  98. return ret;
  99. }
  100. return ret;
  101. }
  102. if (!i2c_probe(CONFIG_SYS_FSL_PMIC_I2C_ADDR)) {
  103. ret = pmic_init(I2C_0);
  104. if (ret)
  105. return ret;
  106. p = pmic_get("FSL_PMIC");
  107. if (!p)
  108. return -ENODEV;
  109. env_set("fdt_file", "imx53-qsrb.dtb");
  110. /* Set VDDGP to 1.25V for 1GHz on SW1 */
  111. pmic_reg_read(p, REG_SW_0, &val);
  112. val = (val & ~SWx_VOLT_MASK_MC34708) | SWx_1_250V_MC34708;
  113. ret = pmic_reg_write(p, REG_SW_0, val);
  114. if (ret) {
  115. printf("Writing to REG_SW_0 failed: %d\n", ret);
  116. return ret;
  117. }
  118. /* Set VCC as 1.30V on SW2 */
  119. pmic_reg_read(p, REG_SW_1, &val);
  120. val = (val & ~SWx_VOLT_MASK_MC34708) | SWx_1_300V_MC34708;
  121. ret = pmic_reg_write(p, REG_SW_1, val);
  122. if (ret) {
  123. printf("Writing to REG_SW_1 failed: %d\n", ret);
  124. return ret;
  125. }
  126. /* Set global reset timer to 4s */
  127. pmic_reg_read(p, REG_POWER_CTL2, &val);
  128. val = (val & ~TIMER_MASK_MC34708) | TIMER_4S_MC34708;
  129. ret = pmic_reg_write(p, REG_POWER_CTL2, val);
  130. if (ret) {
  131. printf("Writing to REG_POWER_CTL2 failed: %d\n", ret);
  132. return ret;
  133. }
  134. /* Set VUSBSEL and VUSBEN for USB PHY supply*/
  135. pmic_reg_read(p, REG_MODE_0, &val);
  136. val |= (VUSBSEL_MC34708 | VUSBEN_MC34708);
  137. ret = pmic_reg_write(p, REG_MODE_0, val);
  138. if (ret) {
  139. printf("Writing to REG_MODE_0 failed: %d\n", ret);
  140. return ret;
  141. }
  142. /* Set SWBST to 5V in auto mode */
  143. val = SWBST_AUTO;
  144. ret = pmic_reg_write(p, SWBST_CTRL, val);
  145. if (ret) {
  146. printf("Writing to SWBST_CTRL failed: %d\n", ret);
  147. return ret;
  148. }
  149. return ret;
  150. }
  151. return -1;
  152. }
  153. static void clock_1GHz(void)
  154. {
  155. int ret;
  156. u32 ref_clk = MXC_HCLK;
  157. /*
  158. * After increasing voltage to 1.25V, we can switch
  159. * CPU clock to 1GHz and DDR to 400MHz safely
  160. */
  161. ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
  162. if (ret)
  163. printf("CPU: Switch CPU clock to 1GHZ failed\n");
  164. ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
  165. ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
  166. if (ret)
  167. printf("CPU: Switch DDR clock to 400MHz failed\n");
  168. }
  169. int board_early_init_f(void)
  170. {
  171. setup_iomux_uart();
  172. setup_iomux_lcd();
  173. return 0;
  174. }
  175. /*
  176. * Do not overwrite the console
  177. * Use always serial for U-Boot console
  178. */
  179. int overwrite_console(void)
  180. {
  181. return 1;
  182. }
  183. int board_init(void)
  184. {
  185. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  186. mxc_set_sata_internal_clock();
  187. setup_iomux_i2c();
  188. return 0;
  189. }
  190. int board_late_init(void)
  191. {
  192. if (!power_init())
  193. clock_1GHz();
  194. return 0;
  195. }
  196. int checkboard(void)
  197. {
  198. puts("Board: MX53 LOCO\n");
  199. return 0;
  200. }