blob: 6174125e728a23f2d0e4435b353ebc12db9f92a8 [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>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000014#include <asm/io.h>
15#include <asm/arch/imx-regs.h>
16#include <asm/arch/sys_proto.h>
17#include <asm/arch/crm_regs.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/iomux-mx53.h>
20#include <asm/arch/clock.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060021#include <env.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000022#include <linux/errno.h>
Ian Ray61c4c2b2019-01-31 16:21:18 +020023#include <linux/libfdt.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000024#include <asm/mach-imx/mxc_i2c.h>
25#include <asm/mach-imx/mx5_video.h>
26#include <netdev.h>
27#include <i2c.h>
28#include <mmc.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080029#include <fsl_esdhc_imx.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000030#include <asm/gpio.h>
31#include <power/pmic.h>
32#include <dialog_pmic.h>
33#include <fsl_pmic.h>
34#include <linux/fb.h>
35#include <ipu_pixfmt.h>
Ian Ray61c4c2b2019-01-31 16:21:18 +020036#include <version.h>
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000037#include <watchdog.h>
38#include "ppd_gpio.h"
39#include <stdlib.h>
Sebastian Reichel36e3e7d2020-09-02 19:31:43 +020040#include "../../ge/common/ge_rtc.h"
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000041#include "../../ge/common/vpd_reader.h"
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000042
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000043DECLARE_GLOBAL_DATA_PTR;
44
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000045static u32 mx53_dram_size[2];
46
47phys_size_t get_effective_memsize(void)
48{
49 /*
50 * WARNING: We must override get_effective_memsize() function here
51 * to report only the size of the first DRAM bank. This is to make
52 * U-Boot relocator place U-Boot into valid memory, that is, at the
53 * end of the first DRAM bank. If we did not override this function
54 * like so, U-Boot would be placed at the address of the first DRAM
55 * bank + total DRAM size - sizeof(uboot), which in the setup where
56 * each DRAM bank contains 512MiB of DRAM would result in placing
57 * U-Boot into invalid memory area close to the end of the first
58 * DRAM bank.
59 */
60 return mx53_dram_size[0];
61}
62
63int dram_init(void)
64{
65 mx53_dram_size[0] = get_ram_size((void *)PHYS_SDRAM_1, 1 << 30);
66 mx53_dram_size[1] = get_ram_size((void *)PHYS_SDRAM_2, 1 << 30);
67
68 gd->ram_size = mx53_dram_size[0] + mx53_dram_size[1];
69
70 return 0;
71}
72
73int dram_init_banksize(void)
74{
75 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
76 gd->bd->bi_dram[0].size = mx53_dram_size[0];
77
78 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
79 gd->bd->bi_dram[1].size = mx53_dram_size[1];
80
81 return 0;
82}
83
84u32 get_board_rev(void)
85{
86 return get_cpu_rev() & ~(0xF << 8);
87}
88
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000089#ifdef CONFIG_USB_EHCI_MX5
90int board_ehci_hcd_init(int port)
91{
92 /* request VBUS power enable pin, GPIO7_8 */
93 imx_iomux_v3_setup_pad(MX53_PAD_PATA_DA_2__GPIO7_8);
94 gpio_direction_output(IMX_GPIO_NR(7, 8), 1);
95 return 0;
96}
97#endif
98
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +000099static int clock_1GHz(void)
100{
101 int ret;
102 u32 ref_clk = MXC_HCLK;
103 /*
104 * After increasing voltage to 1.25V, we can switch
105 * CPU clock to 1GHz and DDR to 400MHz safely
106 */
107 ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
108 if (ret) {
109 printf("CPU: Switch CPU clock to 1GHZ failed\n");
110 return -1;
111 }
112
113 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
114 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
115 if (ret) {
116 printf("CPU: Switch DDR clock to 400MHz failed\n");
117 return -1;
118 }
119
120 return 0;
121}
122
123void ppd_gpio_init(void)
124{
125 int i;
126
127 imx_iomux_v3_setup_multiple_pads(ppd_pads, ARRAY_SIZE(ppd_pads));
Robert Beckett1dec7fa2020-01-31 15:07:54 +0200128 for (i = 0; i < ARRAY_SIZE(ppd_gpios); ++i) {
129 gpio_request(ppd_gpios[i].gpio, "request");
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000130 gpio_direction_output(ppd_gpios[i].gpio, ppd_gpios[i].value);
Robert Beckett1dec7fa2020-01-31 15:07:54 +0200131 }
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000132}
133
134int board_early_init_f(void)
135{
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000136 ppd_gpio_init();
137
138 return 0;
139}
140
141/*
142 * Do not overwrite the console
143 * Use always serial for U-Boot console
144 */
145int overwrite_console(void)
146{
147 return 1;
148}
149
150#define VPD_TYPE_INVALID 0x00
151#define VPD_BLOCK_NETWORK 0x20
152#define VPD_BLOCK_HWID 0x44
153#define VPD_PRODUCT_PPD 4
154#define VPD_HAS_MAC1 0x1
155#define VPD_MAC_ADDRESS_LENGTH 6
156
157struct vpd_cache {
158 u8 product_id;
159 u8 has;
160 unsigned char mac1[VPD_MAC_ADDRESS_LENGTH];
161};
162
163/*
164 * Extracts MAC and product information from the VPD.
165 */
Peng Fanf026c1d2018-12-09 11:45:02 +0000166static int vpd_callback(struct vpd_cache *userdata, u8 id, u8 version,
167 u8 type, size_t size, u8 const *data)
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000168{
Peng Fanf026c1d2018-12-09 11:45:02 +0000169 struct vpd_cache *vpd = userdata;
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000170
171 if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
172 size >= 1) {
173 vpd->product_id = data[0];
174
175 } else if (id == VPD_BLOCK_NETWORK && version == 1 &&
176 type != VPD_TYPE_INVALID) {
177 if (size >= 6) {
178 vpd->has |= VPD_HAS_MAC1;
179 memcpy(vpd->mac1, data, VPD_MAC_ADDRESS_LENGTH);
180 }
181 }
182
183 return 0;
184}
185
186static void process_vpd(struct vpd_cache *vpd)
187{
188 int fec_index = -1;
189
190 if (vpd->product_id == VPD_PRODUCT_PPD)
191 fec_index = 0;
192
193 if (fec_index >= 0 && (vpd->has & VPD_HAS_MAC1))
194 eth_env_set_enetaddr("ethaddr", vpd->mac1);
195}
196
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000197int board_init(void)
198{
199 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
200
201 mxc_set_sata_internal_clock();
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000202
203 return 0;
204}
205
206int misc_init_r(void)
207{
208 const char *cause;
209
210 /* We care about WDOG only, treating everything else as
211 * a power-on-reset.
212 */
213 if (get_imx_reset_cause() & 0x0010)
214 cause = "WDOG";
215 else
216 cause = "POR";
217
218 env_set("bootcause", cause);
219
220 return 0;
221}
222
223int board_late_init(void)
224{
225 int res;
Denis Zalevskiy4dcbccf2018-10-17 10:33:30 +0200226 struct vpd_cache vpd;
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000227
Denis Zalevskiy4dcbccf2018-10-17 10:33:30 +0200228 memset(&vpd, 0, sizeof(vpd));
Sebastian Reicheldef6f532020-09-02 19:31:45 +0200229 res = read_i2c_vpd(&vpd, vpd_callback);
Denis Zalevskiy4dcbccf2018-10-17 10:33:30 +0200230 if (!res)
231 process_vpd(&vpd);
232 else
233 printf("Can't read VPD");
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000234
235 res = clock_1GHz();
236 if (res != 0)
237 return res;
238
239 print_cpuinfo();
Peter Senna Tschudin6b0071c2017-11-06 19:14:11 +0000240
241 check_time();
242
243 return 0;
244}
245
246int checkboard(void)
247{
248 puts("Board: GE PPD\n");
249
250 return 0;
251}
Ian Ray61c4c2b2019-01-31 16:21:18 +0200252
253#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900254int ft_board_setup(void *blob, struct bd_info *bd)
Ian Ray61c4c2b2019-01-31 16:21:18 +0200255{
Ian Rayb186cfa2019-11-12 19:15:18 +0000256 char *rtc_status = env_get("rtc_status");
257
Ian Ray61c4c2b2019-01-31 16:21:18 +0200258 fdt_setprop(blob, 0, "ge,boot-ver", version_string,
Ian Rayb186cfa2019-11-12 19:15:18 +0000259 strlen(version_string) + 1);
260
261 fdt_setprop(blob, 0, "ge,rtc-status", rtc_status,
262 strlen(rtc_status) + 1);
Ian Ray61c4c2b2019-01-31 16:21:18 +0200263 return 0;
264}
265#endif