blob: 84cddd489490f0d299990388bd391cf0b27c9a6b [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
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/sys_proto.h>
11#include <asm/arch/crm_regs.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/iomux-mx53.h>
14#include <asm/arch/clock.h>
15#include <asm/gpio.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020017#include <power/pmic.h>
18#include <fsl_pmic.h>
19#include "kp_id_rev.h"
20
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020021#define BOOSTER_OFF IMX_GPIO_NR(2, 23)
Lukasz Majewski618d4b62018-05-20 08:33:14 +020022#define LCD_BACKLIGHT IMX_GPIO_NR(1, 1)
Lukasz Majewski097cfe32018-05-20 08:33:16 +020023#define KEY1 IMX_GPIO_NR(2, 26)
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020024
25DECLARE_GLOBAL_DATA_PTR;
26
27int dram_init(void)
28{
29 u32 size;
30
31 size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
32 gd->ram_size = size;
33
34 return 0;
35}
36
37int dram_init_banksize(void)
38{
39 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
40 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
41
42 return 0;
43}
44
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020045static int power_init(void)
46{
47 struct udevice *dev;
48 int ret;
49
50 ret = pmic_get("mc34708", &dev);
51 if (ret) {
52 printf("%s: mc34708 not found !\n", __func__);
53 return ret;
54 }
55
56 /* Set VDDGP to 1.110V for 800 MHz on SW1 */
57 pmic_clrsetbits(dev, REG_SW_0, SWx_VOLT_MASK_MC34708,
58 SWx_1_110V_MC34708);
59
60 /* Set VCC as 1.30V on SW2 */
61 pmic_clrsetbits(dev, REG_SW_1, SWx_VOLT_MASK_MC34708,
62 SWx_1_300V_MC34708);
63
64 /* Set global reset timer to 4s */
65 pmic_clrsetbits(dev, REG_POWER_CTL2, TIMER_MASK_MC34708,
66 TIMER_4S_MC34708);
67
68 return ret;
69}
70
71static void setup_clocks(void)
72{
73 int ret;
74 u32 ref_clk = MXC_HCLK;
75 /*
76 * CPU clock set to 800MHz and DDR to 400MHz
77 */
78 ret = mxc_set_clock(ref_clk, 800, MXC_ARM_CLK);
79 if (ret)
80 printf("CPU: Switch CPU clock to 800MHZ failed\n");
81
82 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
83 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
84 if (ret)
85 printf("CPU: Switch DDR clock to 400MHz failed\n");
86}
87
88static void setup_ups(void)
89{
90 gpio_request(BOOSTER_OFF, "BOOSTER_OFF");
91 gpio_direction_output(BOOSTER_OFF, 0);
92}
93
94int board_early_init_f(void)
95{
96 return 0;
97}
98
99/*
100 * Do not overwrite the console
101 * Use always serial for U-Boot console
102 */
103int overwrite_console(void)
104{
105 return 1;
106}
107
108int board_init(void)
109{
110 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
111
112 return 0;
113}
114
Lukasz Majewski618d4b62018-05-20 08:33:14 +0200115void board_disable_display(void)
116{
117 gpio_request(LCD_BACKLIGHT, "LCD_BACKLIGHT");
118 gpio_direction_output(LCD_BACKLIGHT, 0);
119}
120
Lukasz Majewski097cfe32018-05-20 08:33:16 +0200121void board_misc_setup(void)
122{
123 gpio_request(KEY1, "KEY1_GPIO");
124 gpio_direction_input(KEY1);
125
126 if (gpio_get_value(KEY1))
127 env_set("key1", "off");
128 else
129 env_set("key1", "on");
130}
131
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200132int board_late_init(void)
133{
134 int ret = 0;
135
Lukasz Majewski618d4b62018-05-20 08:33:14 +0200136 board_disable_display();
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200137 setup_ups();
138
139 if (!power_init())
140 setup_clocks();
141
142 ret = read_eeprom();
143 if (ret)
144 printf("Error %d reading EEPROM content!\n", ret);
145
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200146 show_eeprom();
147 read_board_id();
148
Lukasz Majewski097cfe32018-05-20 08:33:16 +0200149 board_misc_setup();
150
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200151 return ret;
152}