blob: aaa7006d3b2df3196d4d333f430885d523ae97db [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevam47173482016-02-29 09:33:22 -03002/*
3 * Copyright (C) 2016 NXP Semiconductors
4 * Author: Fabio Estevam <fabio.estevam@nxp.com>
Fabio Estevam47173482016-02-29 09:33:22 -03005 */
6
Simon Glass52559322019-11-14 12:57:46 -07007#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -06008#include <net.h>
Fabio Estevam47173482016-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>
13#include <asm/gpio.h>
Bryan O'Donoghuea2accd82018-04-24 18:46:33 +010014#include <asm/mach-imx/hab.h>
Stefano Babic552a8482017-06-29 10:16:06 +020015#include <asm/mach-imx/iomux-v3.h>
Fabio Estevam47173482016-02-29 09:33:22 -030016#include <asm/io.h>
17#include <common.h>
Simon Glass168068f2019-08-01 09:46:47 -060018#include <env.h>
Fabio Estevam47173482016-02-29 09:33:22 -030019#include <asm/arch/crm_regs.h>
Kevin Hilman25aaebd2016-12-16 13:08:10 -080020#include <netdev.h>
Vanessa Maegima7d301a52016-08-19 10:21:36 -030021#include <power/pmic.h>
22#include <power/pfuze3000_pmic.h>
23#include "../freescale/common/pfuze.h"
Bryan O'Donoghue852cc542018-03-26 15:27:34 +010024#include <asm/setup.h>
25#include <asm/bootm.h>
Fabio Estevam47173482016-02-29 09:33:22 -030026
27DECLARE_GLOBAL_DATA_PTR;
28
29#define UART_PAD_CTRL (PAD_CTL_DSE_3P3V_49OHM | PAD_CTL_PUS_PU100KOHM | \
30 PAD_CTL_HYS)
Fabio Estevam47173482016-02-29 09:33:22 -030031
32int dram_init(void)
33{
34 gd->ram_size = PHYS_SDRAM_SIZE;
35
Bryan O'Donoghue7175ef42018-04-24 18:46:35 +010036 /* Subtract the defined OPTEE runtime firmware length */
37#ifdef CONFIG_OPTEE_TZDRAM_SIZE
38 gd->ram_size -= CONFIG_OPTEE_TZDRAM_SIZE;
39#endif
40
Fabio Estevam47173482016-02-29 09:33:22 -030041 return 0;
42}
43
Marco Franchi0a35cc92016-06-10 14:45:28 -030044static iomux_v3_cfg_t const wdog_pads[] = {
45 MX7D_PAD_GPIO1_IO00__WDOG1_WDOG_B | MUX_PAD_CTRL(NO_PAD_CTRL),
46};
47
Fabio Estevam47173482016-02-29 09:33:22 -030048static iomux_v3_cfg_t const uart1_pads[] = {
49 MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
50 MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
51};
52
Fabio Estevam47173482016-02-29 09:33:22 -030053static void setup_iomux_uart(void)
54{
55 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
56};
57
Fabio Estevam47173482016-02-29 09:33:22 -030058int board_early_init_f(void)
59{
60 setup_iomux_uart();
61
62 return 0;
63}
64
Bryan O'Donoghue8ba37732019-01-18 17:40:14 +000065#ifdef CONFIG_DM_PMIC
Vanessa Maegima7d301a52016-08-19 10:21:36 -030066int power_init_board(void)
67{
Bryan O'Donoghue8ba37732019-01-18 17:40:14 +000068 struct udevice *dev;
69 int ret, dev_id, rev_id;
Vanessa Maegima7d301a52016-08-19 10:21:36 -030070
Joris Offouga80dae362020-01-29 22:05:58 +010071 ret = pmic_get("pfuze3000@8", &dev);
Bryan O'Donoghue8ba37732019-01-18 17:40:14 +000072 if (ret == -ENODEV)
73 return 0;
74 if (ret != 0)
Vanessa Maegima7d301a52016-08-19 10:21:36 -030075 return ret;
76
Bryan O'Donoghue8ba37732019-01-18 17:40:14 +000077 dev_id = pmic_reg_read(dev, PFUZE3000_DEVICEID);
78 rev_id = pmic_reg_read(dev, PFUZE3000_REVID);
79 printf("PMIC: PFUZE3000 DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
Vanessa Maegima7d301a52016-08-19 10:21:36 -030080
81 /* disable Low Power Mode during standby mode */
Fabio Estevame077b3b2019-02-14 11:37:51 -020082 pmic_reg_write(dev, PFUZE3000_LDOGCTL, 1);
Vanessa Maegima7d301a52016-08-19 10:21:36 -030083
84 return 0;
85}
86#endif
87
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +090088int board_eth_init(struct bd_info *bis)
Kevin Hilman25aaebd2016-12-16 13:08:10 -080089{
90 int ret = 0;
91
92#ifdef CONFIG_USB_ETHER
93 ret = usb_eth_initialize(bis);
94 if (ret < 0)
95 printf("Error %d registering USB ether.\n", ret);
96#endif
97
98 return ret;
99}
100
Fabio Estevam47173482016-02-29 09:33:22 -0300101int board_init(void)
102{
103 /* address of boot parameters */
104 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
105
106 return 0;
107}
108
109int checkboard(void)
110{
Fabio Estevamd4ee5042016-08-25 21:07:20 -0300111 char *mode;
112
113 if (IS_ENABLED(CONFIG_ARMV7_BOOT_SEC_DEFAULT))
114 mode = "secure";
115 else
116 mode = "non-secure";
117
Bryan O'Donoghuefbbf44a2018-04-24 18:46:36 +0100118#ifdef CONFIG_OPTEE_TZDRAM_SIZE
119 unsigned long optee_start, optee_end;
120
121 optee_end = PHYS_SDRAM + PHYS_SDRAM_SIZE;
122 optee_start = optee_end - CONFIG_OPTEE_TZDRAM_SIZE;
123
124 printf("Board: WARP7 in %s mode OPTEE DRAM 0x%08lx-0x%08lx\n",
125 mode, optee_start, optee_end);
126#else
Fabio Estevamd4ee5042016-08-25 21:07:20 -0300127 printf("Board: WARP7 in %s mode\n", mode);
Bryan O'Donoghuefbbf44a2018-04-24 18:46:36 +0100128#endif
Fabio Estevam47173482016-02-29 09:33:22 -0300129
130 return 0;
131}
132
Marco Franchi0a35cc92016-06-10 14:45:28 -0300133int board_late_init(void)
134{
135 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
Bryan O'Donoghue852cc542018-03-26 15:27:34 +0100136#ifdef CONFIG_SERIAL_TAG
137 struct tag_serialnr serialnr;
138 char serial_string[0x20];
139#endif
Marco Franchi0a35cc92016-06-10 14:45:28 -0300140
141 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
142
143 set_wdog_reset(wdog);
144
145 /*
146 * Do not assert internal WDOG_RESET_B_DEB(controlled by bit 4),
147 * since we use PMIC_PWRON to reset the board.
148 */
149 clrsetbits_le16(&wdog->wcr, 0, 0x10);
150
Stefano Babicd714a752019-09-20 08:47:53 +0200151#ifdef CONFIG_IMX_HAB
Bryan O'Donoghuea2accd82018-04-24 18:46:33 +0100152 /* Determine HAB state */
153 env_set_ulong(HAB_ENABLED_ENVNAME, imx_hab_is_enabled());
154#else
155 env_set_ulong(HAB_ENABLED_ENVNAME, 0);
156#endif
157
Bryan O'Donoghue852cc542018-03-26 15:27:34 +0100158#ifdef CONFIG_SERIAL_TAG
159 /* Set serial# standard environment variable based on OTP settings */
160 get_board_serial(&serialnr);
161 snprintf(serial_string, sizeof(serial_string), "WaRP7-0x%08x%08x",
162 serialnr.low, serialnr.high);
163 env_set("serial#", serial_string);
164#endif
165
Marco Franchi0a35cc92016-06-10 14:45:28 -0300166 return 0;
167}