blob: ea3f2170b665e9f2e4bc7a03884148e42837f555 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +00002/*
3 * Copyright 2017 General Electric Company
4 *
5 * Based on board/freescale/mx53loco/mx53loco.c:
6 *
7 * Copyright (C) 2011 Freescale Semiconductor, Inc.
8 * Jason Liu <r64343@freescale.com>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +00009 */
10
11#include <common.h>
Simon Glass52559322019-11-14 12:57:46 -070012#include <init.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000013#include <asm/io.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/arch/crm_regs.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/iomux-mx53.h>
19#include <asm/arch/clock.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060020#include <env.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000021#include <linux/errno.h>
Ian Ray61c4c2b2019-01-31 16:21:18 +020022#include <linux/libfdt.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000023#include <asm/mach-imx/mxc_i2c.h>
24#include <asm/mach-imx/mx5_video.h>
25#include <netdev.h>
26#include <i2c.h>
27#include <mmc.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080028#include <fsl_esdhc_imx.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000029#include <asm/gpio.h>
30#include <power/pmic.h>
31#include <dialog_pmic.h>
32#include <fsl_pmic.h>
33#include <linux/fb.h>
34#include <ipu_pixfmt.h>
Ian Ray61c4c2b2019-01-31 16:21:18 +020035#include <version.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000036#include <watchdog.h>
37#include "ppd_gpio.h"
38#include <stdlib.h>
Martyn Welch647155b2017-11-08 15:59:35 +000039#include "../../ge/common/ge_common.h"
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000040#include "../../ge/common/vpd_reader.h"
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000041
42#define MX53PPD_LCD_POWER IMX_GPIO_NR(3, 24)
43
44DECLARE_GLOBAL_DATA_PTR;
45
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000046static u32 mx53_dram_size[2];
47
48phys_size_t get_effective_memsize(void)
49{
50 /*
51 * WARNING: We must override get_effective_memsize() function here
52 * to report only the size of the first DRAM bank. This is to make
53 * U-Boot relocator place U-Boot into valid memory, that is, at the
54 * end of the first DRAM bank. If we did not override this function
55 * like so, U-Boot would be placed at the address of the first DRAM
56 * bank + total DRAM size - sizeof(uboot), which in the setup where
57 * each DRAM bank contains 512MiB of DRAM would result in placing
58 * U-Boot into invalid memory area close to the end of the first
59 * DRAM bank.
60 */
61 return mx53_dram_size[0];
62}
63
64int dram_init(void)
65{
66 mx53_dram_size[0] = get_ram_size((void *)PHYS_SDRAM_1, 1 << 30);
67 mx53_dram_size[1] = get_ram_size((void *)PHYS_SDRAM_2, 1 << 30);
68
69 gd->ram_size = mx53_dram_size[0] + mx53_dram_size[1];
70
71 return 0;
72}
73
74int dram_init_banksize(void)
75{
76 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
77 gd->bd->bi_dram[0].size = mx53_dram_size[0];
78
79 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
80 gd->bd->bi_dram[1].size = mx53_dram_size[1];
81
82 return 0;
83}
84
85u32 get_board_rev(void)
86{
87 return get_cpu_rev() & ~(0xF << 8);
88}
89
90#define UART_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_DSE_HIGH | \
91 PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
92
93#ifdef CONFIG_USB_EHCI_MX5
94int board_ehci_hcd_init(int port)
95{
96 /* request VBUS power enable pin, GPIO7_8 */
97 imx_iomux_v3_setup_pad(MX53_PAD_PATA_DA_2__GPIO7_8);
98 gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
99 return 0;
100}
101#endif
102
103static void setup_iomux_fec(void)
104{
105 static const iomux_v3_cfg_t fec_pads[] = {
106 NEW_PAD_CTRL(MX53_PAD_FEC_MDIO__FEC_MDIO, PAD_CTL_HYS |
107 PAD_CTL_DSE_HIGH | PAD_CTL_PUS_22K_UP |
108 PAD_CTL_ODE),
109 NEW_PAD_CTRL(MX53_PAD_FEC_MDC__FEC_MDC, PAD_CTL_DSE_HIGH),
110 NEW_PAD_CTRL(MX53_PAD_FEC_RXD1__FEC_RDATA_1,
111 PAD_CTL_HYS | PAD_CTL_PKE),
112 NEW_PAD_CTRL(MX53_PAD_FEC_RXD0__FEC_RDATA_0,
113 PAD_CTL_HYS | PAD_CTL_PKE),
114 NEW_PAD_CTRL(MX53_PAD_FEC_TXD1__FEC_TDATA_1, PAD_CTL_DSE_HIGH),
115 NEW_PAD_CTRL(MX53_PAD_FEC_TXD0__FEC_TDATA_0, PAD_CTL_DSE_HIGH),
116 NEW_PAD_CTRL(MX53_PAD_FEC_TX_EN__FEC_TX_EN, PAD_CTL_DSE_HIGH),
117 NEW_PAD_CTRL(MX53_PAD_FEC_REF_CLK__FEC_TX_CLK,
118 PAD_CTL_HYS | PAD_CTL_PKE),
119 NEW_PAD_CTRL(MX53_PAD_FEC_RX_ER__FEC_RX_ER,
120 PAD_CTL_HYS | PAD_CTL_PKE),
121 NEW_PAD_CTRL(MX53_PAD_FEC_CRS_DV__FEC_RX_DV,
122 PAD_CTL_HYS | PAD_CTL_PKE),
123 };
124
125 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
126}
127
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000128static int clock_1GHz(void)
129{
130 int ret;
131 u32 ref_clk = MXC_HCLK;
132 /*
133 * After increasing voltage to 1.25V, we can switch
134 * CPU clock to 1GHz and DDR to 400MHz safely
135 */
136 ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
137 if (ret) {
138 printf("CPU: Switch CPU clock to 1GHZ failed\n");
139 return -1;
140 }
141
142 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
143 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
144 if (ret) {
145 printf("CPU: Switch DDR clock to 400MHz failed\n");
146 return -1;
147 }
148
149 return 0;
150}
151
152void ppd_gpio_init(void)
153{
154 int i;
155
156 imx_iomux_v3_setup_multiple_pads(ppd_pads, ARRAY_SIZE(ppd_pads));
Robert Beckett1dec7fa2020-01-31 15:07:54 +0200157 for (i = 0; i < ARRAY_SIZE(ppd_gpios); ++i) {
158 gpio_request(ppd_gpios[i].gpio, "request");
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000159 gpio_direction_output(ppd_gpios[i].gpio, ppd_gpios[i].value);
Robert Beckett1dec7fa2020-01-31 15:07:54 +0200160 }
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000161}
162
163int board_early_init_f(void)
164{
165 setup_iomux_fec();
166 setup_iomux_lcd();
167 ppd_gpio_init();
168
169 return 0;
170}
171
172/*
173 * Do not overwrite the console
174 * Use always serial for U-Boot console
175 */
176int overwrite_console(void)
177{
178 return 1;
179}
180
181#define VPD_TYPE_INVALID 0x00
182#define VPD_BLOCK_NETWORK 0x20
183#define VPD_BLOCK_HWID 0x44
184#define VPD_PRODUCT_PPD 4
185#define VPD_HAS_MAC1 0x1
186#define VPD_MAC_ADDRESS_LENGTH 6
187
188struct vpd_cache {
189 u8 product_id;
190 u8 has;
191 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
192};
193
194/*
195 * Extracts MAC and product information from the VPD.
196 */
Peng Fanf026c1d2018-12-09 11:45:02 +0000197static int vpd_callback(struct vpd_cache *userdata, u8 id, u8 version,
198 u8 type, size_t size, u8 const *data)
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000199{
Peng Fanf026c1d2018-12-09 11:45:02 +0000200 struct vpd_cache *vpd = userdata;
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000201
202 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
203 size >= 1) {
204 vpd->product_id = data[0];
205
206 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
207 type != VPD_TYPE_INVALID) {
208 if (size >= 6) {
209 vpd->has |= VPD_HAS_MAC1;
210 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
211 }
212 }
213
214 return 0;
215}
216
217static void process_vpd(struct vpd_cache *vpd)
218{
219 int fec_index = -1;
220
221 if (vpd->product_id == VPD_PRODUCT_PPD)
222 fec_index = 0;
223
224 if (fec_index >= 0 && (vpd->has & VPD_HAS_MAC1))
225 eth_env_set_enetaddr("ethaddr", vpd->mac1);
226}
227
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000228int board_init(void)
229{
230 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
231
232 mxc_set_sata_internal_clock();
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000233
234 return 0;
235}
236
237int misc_init_r(void)
238{
239 const char *cause;
240
241 /* We care about WDOG only, treating everything else as
242 * a power-on-reset.
243 */
244 if (get_imx_reset_cause() & 0x0010)
245 cause = "WDOG";
246 else
247 cause = "POR";
248
249 env_set("bootcause", cause);
250
251 return 0;
252}
253
254int board_late_init(void)
255{
256 int res;
Denis Zalevskiy4dcbccf2018-10-17 10:33:30 +0200257 struct vpd_cache vpd;
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000258
Denis Zalevskiy4dcbccf2018-10-17 10:33:30 +0200259 memset(&vpd, 0, sizeof(vpd));
260 res = read_vpd(&vpd, vpd_callback);
261 if (!res)
262 process_vpd(&vpd);
263 else
264 printf("Can't read VPD");
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000265
266 res = clock_1GHz();
267 if (res != 0)
268 return res;
269
270 print_cpuinfo();
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000271
272 check_time();
273
274 return 0;
275}
276
277int checkboard(void)
278{
279 puts("Board: GE PPD\n");
280
281 return 0;
282}
Ian Ray61c4c2b2019-01-31 16:21:18 +0200283
284#ifdef CONFIG_OF_BOARD_SETUP
285int ft_board_setup(void *blob, bd_t *bd)
286{
Ian Rayb186cfa2019-11-12 19:15:18 +0000287 char *rtc_status = env_get("rtc_status");
288
Ian Ray61c4c2b2019-01-31 16:21:18 +0200289 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
Ian Rayb186cfa2019-11-12 19:15:18 +0000290 strlen(version_string) + 1);
291
292 fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
293 strlen(rtc_status) + 1);
Ian Ray61c4c2b2019-01-31 16:21:18 +0200294 return 0;
295}
296#endif