blob: efb7b49cbe081d43987fab6b7db30bedf1510b3b [file] [log] [blame]
Tom Riniaf489482018-05-18 17:54:39 -04001// SPDX-License-Identifier: GPL-2.0+
Lukasz Majewski7515a6f2018-04-26 15:07:18 +02002/*
3 * Copyright (C) 2018
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
Lukasz Majewski7515a6f2018-04-26 15:07:18 +02005 */
6
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Lukasz Majewski7515a6f2018-04-26 15:07:18 +02009#include <asm/io.h>
10#include <asm/arch/imx-regs.h>
11#include <asm/arch/sys_proto.h>
12#include <asm/arch/crm_regs.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/iomux-mx53.h>
15#include <asm/arch/clock.h>
16#include <asm/gpio.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060017#include <env.h>
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020018#include <power/pmic.h>
19#include <fsl_pmic.h>
Lukasz Majewski67d4ce82020-09-25 17:13:09 +020020#include <bootstage.h>
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020021#include "kp_id_rev.h"
22
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020023#define BOOSTER_OFF IMX_GPIO_NR(2, 23)
Lukasz Majewski618d4b62018-05-20 08:33:14 +020024#define LCD_BACKLIGHT IMX_GPIO_NR(1, 1)
Lukasz Majewski097cfe32018-05-20 08:33:16 +020025#define KEY1 IMX_GPIO_NR(2, 26)
Lukasz Majewski67d4ce82020-09-25 17:13:09 +020026#define LED_RED IMX_GPIO_NR(3, 28)
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020027
28DECLARE_GLOBAL_DATA_PTR;
29
30int dram_init(void)
31{
32 u32 size;
33
34 size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
35 gd->ram_size = size;
36
37 return 0;
38}
39
40int dram_init_banksize(void)
41{
42 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
43 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
44
45 return 0;
46}
47
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020048static int power_init(void)
49{
50 struct udevice *dev;
51 int ret;
52
Lukasz Majewski744e4e02020-02-26 12:37:02 +010053 ret = pmic_get("mc34708@8", &dev);
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020054 if (ret) {
55 printf("%s: mc34708 not found !\n", __func__);
56 return ret;
57 }
58
59 /* Set VDDGP to 1.110V for 800 MHz on SW1 */
60 pmic_clrsetbits(dev, REG_SW_0, SWx_VOLT_MASK_MC34708,
61 SWx_1_110V_MC34708);
62
63 /* Set VCC as 1.30V on SW2 */
64 pmic_clrsetbits(dev, REG_SW_1, SWx_VOLT_MASK_MC34708,
65 SWx_1_300V_MC34708);
66
67 /* Set global reset timer to 4s */
68 pmic_clrsetbits(dev, REG_POWER_CTL2, TIMER_MASK_MC34708,
69 TIMER_4S_MC34708);
70
71 return ret;
72}
73
74static void setup_clocks(void)
75{
76 int ret;
77 u32 ref_clk = MXC_HCLK;
78 /*
79 * CPU clock set to 800MHz and DDR to 400MHz
80 */
81 ret = mxc_set_clock(ref_clk, 800, MXC_ARM_CLK);
82 if (ret)
83 printf("CPU: Switch CPU clock to 800MHZ failed\n");
84
85 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
86 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
87 if (ret)
88 printf("CPU: Switch DDR clock to 400MHz failed\n");
89}
90
91static void setup_ups(void)
92{
93 gpio_request(BOOSTER_OFF, "BOOSTER_OFF");
94 gpio_direction_output(BOOSTER_OFF, 0);
95}
96
97int board_early_init_f(void)
98{
99 return 0;
100}
101
102/*
103 * Do not overwrite the console
104 * Use always serial for U-Boot console
105 */
106int overwrite_console(void)
107{
108 return 1;
109}
110
111int board_init(void)
112{
113 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
114
115 return 0;
116}
117
Lukasz Majewski618d4b62018-05-20 08:33:14 +0200118void board_disable_display(void)
119{
120 gpio_request(LCD_BACKLIGHT, "LCD_BACKLIGHT");
121 gpio_direction_output(LCD_BACKLIGHT, 0);
122}
123
Lukasz Majewski097cfe32018-05-20 08:33:16 +0200124void board_misc_setup(void)
125{
126 gpio_request(KEY1, "KEY1_GPIO");
127 gpio_direction_input(KEY1);
128
129 if (gpio_get_value(KEY1))
130 env_set("key1", "off");
131 else
132 env_set("key1", "on");
133}
134
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200135int board_late_init(void)
136{
137 int ret = 0;
138
Lukasz Majewski618d4b62018-05-20 08:33:14 +0200139 board_disable_display();
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200140 setup_ups();
141
142 if (!power_init())
143 setup_clocks();
144
145 ret = read_eeprom();
146 if (ret)
147 printf("Error %d reading EEPROM content!\n", ret);
148
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200149 show_eeprom();
150 read_board_id();
151
Lukasz Majewski097cfe32018-05-20 08:33:16 +0200152 board_misc_setup();
153
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200154 return ret;
155}
Lukasz Majewski67d4ce82020-09-25 17:13:09 +0200156
Tom Rinia9765d02021-05-03 16:48:58 -0400157#if CONFIG_IS_ENABLED(BOOTSTAGE)
Lukasz Majewski67d4ce82020-09-25 17:13:09 +0200158#define GPIO_DR 0x0
159#define GPIO_GDIR 0x4
160#define GPIO_ALT1 0x1
161#define GPIO5_BASE 0x53FDC000
162#define IOMUXC_EIM_WAIT 0x53FA81E4
163/* Green LED: GPIO5_0 */
164#define GPIO_GREEN BIT(0)
165
166void show_boot_progress(int status)
167{
168 /*
169 * This BOOTSTAGE_ID is called at very early stage of execution. DM gpio
170 * is not yet initialized.
171 */
172 if (status == BOOTSTAGE_ID_START_UBOOT_F) {
173 /*
174 * After ROM execution the EIM_WAIT PAD is set as ALT0
175 * (according to RM it shall be ALT1 after reset). To use it as
176 * GPIO we need to set it to ALT1.
177 */
178 setbits_le32(((uint32_t *)(IOMUXC_EIM_WAIT)), GPIO_ALT1);
179
180 /* Configure green LED GPIO pin direction */
181 setbits_le32(((uint32_t *)(GPIO5_BASE + GPIO_GDIR)),
182 GPIO_GREEN);
183 /* Turn on green LED */
184 setbits_le32(((uint32_t *)(GPIO5_BASE + GPIO_DR)), GPIO_GREEN);
185 }
186
187 /*
188 * This BOOTSTAGE_ID is called just before handling execution to kernel
189 * - i.e. gpio subsystem is already initialized
190 */
191 if (status == BOOTSTAGE_ID_BOOTM_HANDOFF) {
192 /*
193 * Off green LED - the same approach - i.e. non dm gpio
194 * (*bits_le32) is used as in the very early stage.
195 */
196 clrbits_le32(((uint32_t *)(GPIO5_BASE + GPIO_DR)),
197 GPIO_GREEN);
198
199 /*
200 * On red LED
201 */
202 gpio_request(LED_RED, "LED_RED_ERROR");
203 gpio_direction_output(LED_RED, 1);
204 }
205}
Tom Rinia9765d02021-05-03 16:48:58 -0400206#endif