Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 NXP Semiconductors |
| 4 | * Author: Fabio Estevam <fabio.estevam@nxp.com> |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/imx-regs.h> |
| 9 | #include <asm/arch/mx7-pins.h> |
| 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <asm/gpio.h> |
Bryan O'Donoghue | 1b60ee6 | 2018-04-24 18:46:33 +0100 | [diff] [blame] | 12 | #include <asm/mach-imx/hab.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 13 | #include <asm/mach-imx/iomux-v3.h> |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <common.h> |
Simon Glass | 07dc93c | 2019-08-01 09:46:47 -0600 | [diff] [blame] | 16 | #include <env.h> |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 17 | #include <asm/arch/crm_regs.h> |
Kevin Hilman | 46fdd84 | 2016-12-16 13:08:10 -0800 | [diff] [blame] | 18 | #include <netdev.h> |
Vanessa Maegima | 4abedc8 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 19 | #include <power/pmic.h> |
| 20 | #include <power/pfuze3000_pmic.h> |
| 21 | #include "../freescale/common/pfuze.h" |
Bryan O'Donoghue | 1936c41 | 2018-03-26 15:27:34 +0100 | [diff] [blame] | 22 | #include <asm/setup.h> |
| 23 | #include <asm/bootm.h> |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | #define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \ |
| 28 | PAD_CTL_HYS) |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 29 | |
| 30 | int dram_init(void) |
| 31 | { |
| 32 | gd->ram_size = PHYS_SDRAM_SIZE; |
| 33 | |
Bryan O'Donoghue | 2adfdff | 2018-04-24 18:46:35 +0100 | [diff] [blame] | 34 | /* Subtract the defined OPTEE runtime firmware length */ |
| 35 | #ifdef CONFIG_OPTEE_TZDRAM_SIZE |
| 36 | gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE; |
| 37 | #endif |
| 38 | |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Marco Franchi | 3d73f52 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 42 | static iomux_v3_cfg_t const wdog_pads[] = { |
| 43 | MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 44 | }; |
| 45 | |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 46 | static iomux_v3_cfg_t const uart1_pads[] = { |
| 47 | MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 48 | MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 49 | }; |
| 50 | |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 51 | static void setup_iomux_uart(void) |
| 52 | { |
| 53 | imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); |
| 54 | }; |
| 55 | |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 56 | int board_early_init_f(void) |
| 57 | { |
| 58 | setup_iomux_uart(); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Bryan O'Donoghue | 6f1eee6 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 63 | #ifdef CONFIG_DM_PMIC |
Vanessa Maegima | 4abedc8 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 64 | int power_init_board(void) |
| 65 | { |
Bryan O'Donoghue | 6f1eee6 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 66 | struct udevice *dev; |
| 67 | int ret, dev_id, rev_id; |
Vanessa Maegima | 4abedc8 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 68 | |
Bryan O'Donoghue | 6f1eee6 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 69 | ret = pmic_get("pfuze3000", &dev); |
| 70 | if (ret == -ENODEV) |
| 71 | return 0; |
| 72 | if (ret != 0) |
Vanessa Maegima | 4abedc8 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 73 | return ret; |
| 74 | |
Bryan O'Donoghue | 6f1eee6 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 75 | dev_id = pmic_reg_read(dev, PFUZE3000_DEVICEID); |
| 76 | rev_id = pmic_reg_read(dev, PFUZE3000_REVID); |
| 77 | printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id); |
Vanessa Maegima | 4abedc8 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 78 | |
| 79 | /* disable Low Power Mode during standby mode */ |
Fabio Estevam | 7ac7b96 | 2019-02-14 11:37:51 -0200 | [diff] [blame] | 80 | pmic_reg_write(dev, PFUZE3000_LDOGCTL, 1); |
Vanessa Maegima | 4abedc8 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | #endif |
| 85 | |
Kevin Hilman | 46fdd84 | 2016-12-16 13:08:10 -0800 | [diff] [blame] | 86 | int board_eth_init(bd_t *bis) |
| 87 | { |
| 88 | int ret = 0; |
| 89 | |
| 90 | #ifdef CONFIG_USB_ETHER |
| 91 | ret = usb_eth_initialize(bis); |
| 92 | if (ret < 0) |
| 93 | printf("Error %d registering USB ether.\n", ret); |
| 94 | #endif |
| 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 99 | int board_init(void) |
| 100 | { |
| 101 | /* address of boot parameters */ |
| 102 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | int checkboard(void) |
| 108 | { |
Fabio Estevam | f8f2194 | 2016-08-25 21:07:20 -0300 | [diff] [blame] | 109 | char *mode; |
| 110 | |
| 111 | if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT)) |
| 112 | mode = "secure"; |
| 113 | else |
| 114 | mode = "non-secure"; |
| 115 | |
Bryan O'Donoghue | 446dddd | 2018-04-24 18:46:36 +0100 | [diff] [blame] | 116 | #ifdef CONFIG_OPTEE_TZDRAM_SIZE |
| 117 | unsigned long optee_start, optee_end; |
| 118 | |
| 119 | optee_end = PHYS_SDRAM + PHYS_SDRAM_SIZE; |
| 120 | optee_start = optee_end - CONFIG_OPTEE_TZDRAM_SIZE; |
| 121 | |
| 122 | printf("Board: WARP7 in %s mode OPTEE DRAM 0x%08lx-0x%08lx\n", |
| 123 | mode, optee_start, optee_end); |
| 124 | #else |
Fabio Estevam | f8f2194 | 2016-08-25 21:07:20 -0300 | [diff] [blame] | 125 | printf("Board: WARP7 in %s mode\n", mode); |
Bryan O'Donoghue | 446dddd | 2018-04-24 18:46:36 +0100 | [diff] [blame] | 126 | #endif |
Fabio Estevam | 6cfa712 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Marco Franchi | 3d73f52 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 131 | int board_late_init(void) |
| 132 | { |
| 133 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
Bryan O'Donoghue | 1936c41 | 2018-03-26 15:27:34 +0100 | [diff] [blame] | 134 | #ifdef CONFIG_SERIAL_TAG |
| 135 | struct tag_serialnr serialnr; |
| 136 | char serial_string[0x20]; |
| 137 | #endif |
Marco Franchi | 3d73f52 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 138 | |
| 139 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 140 | |
| 141 | set_wdog_reset(wdog); |
| 142 | |
| 143 | /* |
| 144 | * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4), |
| 145 | * since we use PMIC_PWRON to reset the board. |
| 146 | */ |
| 147 | clrsetbits_le16(&wdog->wcr, 0, 0x10); |
| 148 | |
Stefano Babic | f8b509b | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 149 | #ifdef CONFIG_IMX_HAB |
Bryan O'Donoghue | 1b60ee6 | 2018-04-24 18:46:33 +0100 | [diff] [blame] | 150 | /* Determine HAB state */ |
| 151 | env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled()); |
| 152 | #else |
| 153 | env_set_ulong(HAB_ENABLED_ENVNAME, 0); |
| 154 | #endif |
| 155 | |
Bryan O'Donoghue | 1936c41 | 2018-03-26 15:27:34 +0100 | [diff] [blame] | 156 | #ifdef CONFIG_SERIAL_TAG |
| 157 | /* Set serial# standard environment variable based on OTP settings */ |
| 158 | get_board_serial(&serialnr); |
| 159 | snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%08x%08x", |
| 160 | serialnr.low, serialnr.high); |
| 161 | env_set("serial#", serial_string); |
| 162 | #endif |
| 163 | |
Marco Franchi | 3d73f52 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 164 | return 0; |
| 165 | } |