warp7.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 NXP Semiconductors
  4. * Author: Fabio Estevam <fabio.estevam@nxp.com>
  5. */
  6. #include <asm/arch/clock.h>
  7. #include <asm/arch/imx-regs.h>
  8. #include <asm/arch/mx7-pins.h>
  9. #include <asm/arch/sys_proto.h>
  10. #include <asm/gpio.h>
  11. #include <asm/mach-imx/hab.h>
  12. #include <asm/mach-imx/iomux-v3.h>
  13. #include <asm/mach-imx/mxc_i2c.h>
  14. #include <asm/io.h>
  15. #include <common.h>
  16. #include <fsl_esdhc.h>
  17. #include <i2c.h>
  18. #include <mmc.h>
  19. #include <asm/arch/crm_regs.h>
  20. #include <usb.h>
  21. #include <netdev.h>
  22. #include <power/pmic.h>
  23. #include <power/pfuze3000_pmic.h>
  24. #include "../freescale/common/pfuze.h"
  25. #include <asm/setup.h>
  26. #include <asm/bootm.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. #define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \
  29. PAD_CTL_HYS)
  30. #define USDHC_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
  31. PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU47KOHM)
  32. #define I2C_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \
  33. PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU100KOHM)
  34. #ifdef CONFIG_SYS_I2C_MXC
  35. #define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
  36. /* I2C1 for PMIC */
  37. static struct i2c_pads_info i2c_pad_info1 = {
  38. .scl = {
  39. .i2c_mode = MX7D_PAD_I2C1_SCL__I2C1_SCL | PC,
  40. .gpio_mode = MX7D_PAD_I2C1_SCL__GPIO4_IO8 | PC,
  41. .gp = IMX_GPIO_NR(4, 8),
  42. },
  43. .sda = {
  44. .i2c_mode = MX7D_PAD_I2C1_SDA__I2C1_SDA | PC,
  45. .gpio_mode = MX7D_PAD_I2C1_SDA__GPIO4_IO9 | PC,
  46. .gp = IMX_GPIO_NR(4, 9),
  47. },
  48. };
  49. #endif
  50. int dram_init(void)
  51. {
  52. gd->ram_size = PHYS_SDRAM_SIZE;
  53. /* Subtract the defined OPTEE runtime firmware length */
  54. #ifdef CONFIG_OPTEE_TZDRAM_SIZE
  55. gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
  56. #endif
  57. return 0;
  58. }
  59. static iomux_v3_cfg_t const wdog_pads[] = {
  60. MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
  61. };
  62. static iomux_v3_cfg_t const uart1_pads[] = {
  63. MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
  64. MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
  65. };
  66. static iomux_v3_cfg_t const usdhc3_pads[] = {
  67. MX7D_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  68. MX7D_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  69. MX7D_PAD_SD3_DATA0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  70. MX7D_PAD_SD3_DATA1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  71. MX7D_PAD_SD3_DATA2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  72. MX7D_PAD_SD3_DATA3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  73. MX7D_PAD_SD3_DATA4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  74. MX7D_PAD_SD3_DATA5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  75. MX7D_PAD_SD3_DATA6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  76. MX7D_PAD_SD3_DATA7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  77. MX7D_PAD_SD3_RESET_B__SD3_RESET_B | MUX_PAD_CTRL(USDHC_PAD_CTRL),
  78. };
  79. static void setup_iomux_uart(void)
  80. {
  81. imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
  82. };
  83. static struct fsl_esdhc_cfg usdhc_cfg[1] = {
  84. {USDHC3_BASE_ADDR},
  85. };
  86. int board_mmc_getcd(struct mmc *mmc)
  87. {
  88. /* Assume uSDHC3 emmc is always present */
  89. return 1;
  90. }
  91. int board_mmc_init(bd_t *bis)
  92. {
  93. imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
  94. usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
  95. return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
  96. }
  97. int board_early_init_f(void)
  98. {
  99. setup_iomux_uart();
  100. return 0;
  101. }
  102. #ifdef CONFIG_POWER
  103. #define I2C_PMIC 0
  104. static struct pmic *pfuze;
  105. int power_init_board(void)
  106. {
  107. int ret;
  108. unsigned int reg, rev_id;
  109. ret = power_pfuze3000_init(I2C_PMIC);
  110. if (ret)
  111. return ret;
  112. pfuze = pmic_get("PFUZE3000");
  113. ret = pmic_probe(pfuze);
  114. if (ret)
  115. return ret;
  116. pmic_reg_read(pfuze, PFUZE3000_DEVICEID, &reg);
  117. pmic_reg_read(pfuze, PFUZE3000_REVID, &rev_id);
  118. printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", reg, rev_id);
  119. /* disable Low Power Mode during standby mode */
  120. pmic_reg_write(pfuze, PFUZE3000_LDOGCTL, 0x1);
  121. return 0;
  122. }
  123. #endif
  124. int board_eth_init(bd_t *bis)
  125. {
  126. int ret = 0;
  127. #ifdef CONFIG_USB_ETHER
  128. ret = usb_eth_initialize(bis);
  129. if (ret < 0)
  130. printf("Error %d registering USB ether.\n", ret);
  131. #endif
  132. return ret;
  133. }
  134. int board_init(void)
  135. {
  136. /* address of boot parameters */
  137. gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
  138. #ifdef CONFIG_SYS_I2C_MXC
  139. setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
  140. #endif
  141. return 0;
  142. }
  143. int checkboard(void)
  144. {
  145. char *mode;
  146. if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
  147. mode = "secure";
  148. else
  149. mode = "non-secure";
  150. #ifdef CONFIG_OPTEE_TZDRAM_SIZE
  151. unsigned long optee_start, optee_end;
  152. optee_end = PHYS_SDRAM + PHYS_SDRAM_SIZE;
  153. optee_start = optee_end - CONFIG_OPTEE_TZDRAM_SIZE;
  154. printf("Board: WARP7 in %s mode OPTEE DRAM 0x%08lx-0x%08lx\n",
  155. mode, optee_start, optee_end);
  156. #else
  157. printf("Board: WARP7 in %s mode\n", mode);
  158. #endif
  159. return 0;
  160. }
  161. int board_usb_phy_mode(int port)
  162. {
  163. return USB_INIT_DEVICE;
  164. }
  165. int board_late_init(void)
  166. {
  167. struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
  168. #ifdef CONFIG_SERIAL_TAG
  169. struct tag_serialnr serialnr;
  170. char serial_string[0x20];
  171. #endif
  172. imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
  173. set_wdog_reset(wdog);
  174. /*
  175. * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
  176. * since we use PMIC_PWRON to reset the board.
  177. */
  178. clrsetbits_le16(&wdog->wcr, 0, 0x10);
  179. #ifdef CONFIG_SECURE_BOOT
  180. /* Determine HAB state */
  181. env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
  182. #else
  183. env_set_ulong(HAB_ENABLED_ENVNAME, 0);
  184. #endif
  185. #ifdef CONFIG_SERIAL_TAG
  186. /* Set serial# standard environment variable based on OTP settings */
  187. get_board_serial(&serialnr);
  188. snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%08x%08x",
  189. serialnr.low, serialnr.high);
  190. env_set("serial#", serial_string);
  191. #endif
  192. return 0;
  193. }