blob: c5c5433048dd708d6c9b9118dcb32465b6206df4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam6cfa7122016-02-29 09:33:22 -03002/*
3 * Copyright (C) 2016 NXP Semiconductors
4 * Author: Fabio Estevam <fabio.estevam@nxp.com>
Fabio Estevam6cfa7122016-02-29 09:33:22 -03005 */
6
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06008#include <net.h>
Fabio Estevam6cfa7122016-02-29 09:33:22 -03009#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 Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Fabio Estevam6cfa7122016-02-29 09:33:22 -030014#include <asm/gpio.h>
Bryan O'Donoghue1b60ee62018-04-24 18:46:33 +010015#include <asm/mach-imx/hab.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020016#include <asm/mach-imx/iomux-v3.h>
Fabio Estevam6cfa7122016-02-29 09:33:22 -030017#include <asm/io.h>
18#include <common.h>
Simon Glass07dc93c2019-08-01 09:46:47 -060019#include <env.h>
Fabio Estevam6cfa7122016-02-29 09:33:22 -030020#include <asm/arch/crm_regs.h>
Kevin Hilman46fdd842016-12-16 13:08:10 -080021#include <netdev.h>
Vanessa Maegima4abedc82016-08-19 10:21:36 -030022#include <power/pmic.h>
23#include <power/pfuze3000_pmic.h>
24#include "../freescale/common/pfuze.h"
Bryan O'Donoghue1936c412018-03-26 15:27:34 +010025#include <asm/setup.h>
26#include <asm/bootm.h>
Fabio Estevam6cfa7122016-02-29 09:33:22 -030027
28DECLARE_GLOBAL_DATA_PTR;
29
30#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \
31 PAD_CTL_HYS)
Fabio Estevam6cfa7122016-02-29 09:33:22 -030032
33int dram_init(void)
34{
35 gd->ram_size = PHYS_SDRAM_SIZE;
36
Bryan O'Donoghue2adfdff2018-04-24 18:46:35 +010037 /* Subtract the defined OPTEE runtime firmware length */
38#ifdef CONFIG_OPTEE_TZDRAM_SIZE
39 gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
40#endif
41
Fabio Estevam6cfa7122016-02-29 09:33:22 -030042 return 0;
43}
44
Marco Franchi3d73f522016-06-10 14:45:28 -030045static iomux_v3_cfg_t const wdog_pads[] = {
46 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
47};
48
Fabio Estevam6cfa7122016-02-29 09:33:22 -030049static iomux_v3_cfg_t const uart1_pads[] = {
50 MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
51 MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
52};
53
Fabio Estevam6cfa7122016-02-29 09:33:22 -030054static void setup_iomux_uart(void)
55{
56 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
57};
58
Fabio Estevam6cfa7122016-02-29 09:33:22 -030059int board_early_init_f(void)
60{
61 setup_iomux_uart();
62
63 return 0;
64}
65
Bryan O'Donoghue6f1eee62019-01-18 17:40:14 +000066#ifdef CONFIG_DM_PMIC
Vanessa Maegima4abedc82016-08-19 10:21:36 -030067int power_init_board(void)
68{
Bryan O'Donoghue6f1eee62019-01-18 17:40:14 +000069 struct udevice *dev;
70 int ret, dev_id, rev_id;
Vanessa Maegima4abedc82016-08-19 10:21:36 -030071
Joris Offougae19e7cc2020-01-29 22:05:58 +010072 ret = pmic_get("pfuze3000@8", &dev);
Bryan O'Donoghue6f1eee62019-01-18 17:40:14 +000073 if (ret == -ENODEV)
74 return 0;
75 if (ret != 0)
Vanessa Maegima4abedc82016-08-19 10:21:36 -030076 return ret;
77
Bryan O'Donoghue6f1eee62019-01-18 17:40:14 +000078 dev_id = pmic_reg_read(dev, PFUZE3000_DEVICEID);
79 rev_id = pmic_reg_read(dev, PFUZE3000_REVID);
80 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
Vanessa Maegima4abedc82016-08-19 10:21:36 -030081
82 /* disable Low Power Mode during standby mode */
Fabio Estevam7ac7b962019-02-14 11:37:51 -020083 pmic_reg_write(dev, PFUZE3000_LDOGCTL, 1);
Vanessa Maegima4abedc82016-08-19 10:21:36 -030084
85 return 0;
86}
87#endif
88
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090089int board_eth_init(struct bd_info *bis)
Kevin Hilman46fdd842016-12-16 13:08:10 -080090{
91 int ret = 0;
92
93#ifdef CONFIG_USB_ETHER
94 ret = usb_eth_initialize(bis);
95 if (ret < 0)
96 printf("Error %d registering USB ether.\n", ret);
97#endif
98
99 return ret;
100}
101
Fabio Estevam6cfa7122016-02-29 09:33:22 -0300102int board_init(void)
103{
104 /* address of boot parameters */
105 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
106
107 return 0;
108}
109
110int checkboard(void)
111{
Fabio Estevamf8f21942016-08-25 21:07:20 -0300112 char *mode;
113
114 if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
115 mode = "secure";
116 else
117 mode = "non-secure";
118
Bryan O'Donoghue446dddd2018-04-24 18:46:36 +0100119#ifdef CONFIG_OPTEE_TZDRAM_SIZE
120 unsigned long optee_start, optee_end;
121
122 optee_end = PHYS_SDRAM + PHYS_SDRAM_SIZE;
123 optee_start = optee_end - CONFIG_OPTEE_TZDRAM_SIZE;
124
125 printf("Board: WARP7 in %s mode OPTEE DRAM 0x%08lx-0x%08lx\n",
126 mode, optee_start, optee_end);
127#else
Fabio Estevamf8f21942016-08-25 21:07:20 -0300128 printf("Board: WARP7 in %s mode\n", mode);
Bryan O'Donoghue446dddd2018-04-24 18:46:36 +0100129#endif
Fabio Estevam6cfa7122016-02-29 09:33:22 -0300130
131 return 0;
132}
133
Marco Franchi3d73f522016-06-10 14:45:28 -0300134int board_late_init(void)
135{
136 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
Tom Riniae21e7f2021-08-30 09:16:29 -0400137#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Bryan O'Donoghue1936c412018-03-26 15:27:34 +0100138 struct tag_serialnr serialnr;
139 char serial_string[0x20];
140#endif
Marco Franchi3d73f522016-06-10 14:45:28 -0300141
142 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
143
144 set_wdog_reset(wdog);
145
146 /*
147 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
148 * since we use PMIC_PWRON to reset the board.
149 */
150 clrsetbits_le16(&wdog->wcr, 0, 0x10);
151
Stefano Babicf8b509b2019-09-20 08:47:53 +0200152#ifdef CONFIG_IMX_HAB
Bryan O'Donoghue1b60ee62018-04-24 18:46:33 +0100153 /* Determine HAB state */
154 env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
155#else
156 env_set_ulong(HAB_ENABLED_ENVNAME, 0);
157#endif
158
Tom Riniae21e7f2021-08-30 09:16:29 -0400159#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Bryan O'Donoghue1936c412018-03-26 15:27:34 +0100160 /* Set serial# standard environment variable based on OTP settings */
161 get_board_serial(&serialnr);
162 snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%08x%08x",
163 serialnr.low, serialnr.high);
164 env_set("serial#", serial_string);
165#endif
166
Marco Franchi3d73f522016-06-10 14:45:28 -0300167 return 0;
168}