Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Fabio Estevam | 4717348 | 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 | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 7 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 8 | #include <net.h> |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 9 | #include <asm/arch/clock.h> |
| 10 | #include <asm/arch/imx-regs.h> |
| 11 | #include <asm/arch/mx7-pins.h> |
| 12 | #include <asm/arch/sys_proto.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 14 | #include <asm/gpio.h> |
Bryan O'Donoghue | a2accd8 | 2018-04-24 18:46:33 +0100 | [diff] [blame] | 15 | #include <asm/mach-imx/hab.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 16 | #include <asm/mach-imx/iomux-v3.h> |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 17 | #include <asm/io.h> |
| 18 | #include <common.h> |
Simon Glass | 168068f | 2019-08-01 09:46:47 -0600 | [diff] [blame] | 19 | #include <env.h> |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 20 | #include <asm/arch/crm_regs.h> |
Kevin Hilman | 25aaebd | 2016-12-16 13:08:10 -0800 | [diff] [blame] | 21 | #include <netdev.h> |
Vanessa Maegima | 7d301a5 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 22 | #include <power/pmic.h> |
| 23 | #include <power/pfuze3000_pmic.h> |
| 24 | #include "../freescale/common/pfuze.h" |
Bryan O'Donoghue | 852cc54 | 2018-03-26 15:27:34 +0100 | [diff] [blame] | 25 | #include <asm/setup.h> |
| 26 | #include <asm/bootm.h> |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 30 | int dram_init(void) |
| 31 | { |
| 32 | gd->ram_size = PHYS_SDRAM_SIZE; |
| 33 | |
Bryan O'Donoghue | 7175ef4 | 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 | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Marco Franchi | 0a35cc9 | 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 | |
Bryan O'Donoghue | 8ba3773 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 46 | #ifdef CONFIG_DM_PMIC |
Vanessa Maegima | 7d301a5 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 47 | int power_init_board(void) |
| 48 | { |
Bryan O'Donoghue | 8ba3773 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 49 | struct udevice *dev; |
| 50 | int ret, dev_id, rev_id; |
Vanessa Maegima | 7d301a5 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 51 | |
Joris Offouga | 80dae36 | 2020-01-29 22:05:58 +0100 | [diff] [blame] | 52 | ret = pmic_get("pfuze3000@8", &dev); |
Bryan O'Donoghue | 8ba3773 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 53 | if (ret == -ENODEV) |
| 54 | return 0; |
| 55 | if (ret != 0) |
Vanessa Maegima | 7d301a5 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 56 | return ret; |
| 57 | |
Bryan O'Donoghue | 8ba3773 | 2019-01-18 17:40:14 +0000 | [diff] [blame] | 58 | dev_id = pmic_reg_read(dev, PFUZE3000_DEVICEID); |
| 59 | rev_id = pmic_reg_read(dev, PFUZE3000_REVID); |
| 60 | printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id); |
Vanessa Maegima | 7d301a5 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 61 | |
| 62 | /* disable Low Power Mode during standby mode */ |
Fabio Estevam | e077b3b | 2019-02-14 11:37:51 -0200 | [diff] [blame] | 63 | pmic_reg_write(dev, PFUZE3000_LDOGCTL, 1); |
Vanessa Maegima | 7d301a5 | 2016-08-19 10:21:36 -0300 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | #endif |
| 68 | |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 69 | int board_init(void) |
| 70 | { |
| 71 | /* address of boot parameters */ |
| 72 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int checkboard(void) |
| 78 | { |
Fabio Estevam | d4ee504 | 2016-08-25 21:07:20 -0300 | [diff] [blame] | 79 | char *mode; |
| 80 | |
| 81 | if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT)) |
| 82 | mode = "secure"; |
| 83 | else |
| 84 | mode = "non-secure"; |
| 85 | |
Bryan O'Donoghue | fbbf44a | 2018-04-24 18:46:36 +0100 | [diff] [blame] | 86 | #ifdef CONFIG_OPTEE_TZDRAM_SIZE |
| 87 | unsigned long optee_start, optee_end; |
| 88 | |
| 89 | optee_end = PHYS_SDRAM + PHYS_SDRAM_SIZE; |
| 90 | optee_start = optee_end - CONFIG_OPTEE_TZDRAM_SIZE; |
| 91 | |
| 92 | printf("Board: WARP7 in %s mode OPTEE DRAM 0x%08lx-0x%08lx\n", |
| 93 | mode, optee_start, optee_end); |
| 94 | #else |
Fabio Estevam | d4ee504 | 2016-08-25 21:07:20 -0300 | [diff] [blame] | 95 | printf("Board: WARP7 in %s mode\n", mode); |
Bryan O'Donoghue | fbbf44a | 2018-04-24 18:46:36 +0100 | [diff] [blame] | 96 | #endif |
Fabio Estevam | 4717348 | 2016-02-29 09:33:22 -0300 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Marco Franchi | 0a35cc9 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 101 | int board_late_init(void) |
| 102 | { |
| 103 | struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR; |
Tom Rini | b9d66a0 | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 104 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Bryan O'Donoghue | 852cc54 | 2018-03-26 15:27:34 +0100 | [diff] [blame] | 105 | struct tag_serialnr serialnr; |
| 106 | char serial_string[0x20]; |
| 107 | #endif |
Marco Franchi | 0a35cc9 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 108 | |
| 109 | imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads)); |
| 110 | |
| 111 | set_wdog_reset(wdog); |
| 112 | |
| 113 | /* |
| 114 | * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4), |
| 115 | * since we use PMIC_PWRON to reset the board. |
| 116 | */ |
| 117 | clrsetbits_le16(&wdog->wcr, 0, 0x10); |
| 118 | |
Stefano Babic | d714a75 | 2019-09-20 08:47:53 +0200 | [diff] [blame] | 119 | #ifdef CONFIG_IMX_HAB |
Bryan O'Donoghue | a2accd8 | 2018-04-24 18:46:33 +0100 | [diff] [blame] | 120 | /* Determine HAB state */ |
| 121 | env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled()); |
| 122 | #else |
| 123 | env_set_ulong(HAB_ENABLED_ENVNAME, 0); |
| 124 | #endif |
| 125 | |
Tom Rini | b9d66a0 | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 126 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Bryan O'Donoghue | 852cc54 | 2018-03-26 15:27:34 +0100 | [diff] [blame] | 127 | /* Set serial# standard environment variable based on OTP settings */ |
| 128 | get_board_serial(&serialnr); |
| 129 | snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%08x%08x", |
| 130 | serialnr.low, serialnr.high); |
| 131 | env_set("serial#", serial_string); |
| 132 | #endif |
| 133 | |
Marco Franchi | 0a35cc9 | 2016-06-10 14:45:28 -0300 | [diff] [blame] | 134 | return 0; |
| 135 | } |