blob: eb5b67d1e622dc9945cc0a3fa306808e1705b584 [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>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.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>
20#include "kp_id_rev.h"
21
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020022#define BOOSTER_OFF IMX_GPIO_NR(2, 23)
Lukasz Majewski618d4b62018-05-20 08:33:14 +020023#define LCD_BACKLIGHT IMX_GPIO_NR(1, 1)
Lukasz Majewski097cfe32018-05-20 08:33:16 +020024#define KEY1 IMX_GPIO_NR(2, 26)
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020025
26DECLARE_GLOBAL_DATA_PTR;
27
28int dram_init(void)
29{
30 u32 size;
31
32 size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
33 gd->ram_size = size;
34
35 return 0;
36}
37
38int dram_init_banksize(void)
39{
40 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
41 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
42
43 return 0;
44}
45
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020046static int power_init(void)
47{
48 struct udevice *dev;
49 int ret;
50
Lukasz Majewski744e4e02020-02-26 12:37:02 +010051 ret = pmic_get("mc34708@8", &dev);
Lukasz Majewski7515a6f2018-04-26 15:07:18 +020052 if (ret) {
53 printf("%s: mc34708 not found !\n", __func__);
54 return ret;
55 }
56
57 /* Set VDDGP to 1.110V for 800 MHz on SW1 */
58 pmic_clrsetbits(dev, REG_SW_0, SWx_VOLT_MASK_MC34708,
59 SWx_1_110V_MC34708);
60
61 /* Set VCC as 1.30V on SW2 */
62 pmic_clrsetbits(dev, REG_SW_1, SWx_VOLT_MASK_MC34708,
63 SWx_1_300V_MC34708);
64
65 /* Set global reset timer to 4s */
66 pmic_clrsetbits(dev, REG_POWER_CTL2, TIMER_MASK_MC34708,
67 TIMER_4S_MC34708);
68
69 return ret;
70}
71
72static void setup_clocks(void)
73{
74 int ret;
75 u32 ref_clk = MXC_HCLK;
76 /*
77 * CPU clock set to 800MHz and DDR to 400MHz
78 */
79 ret = mxc_set_clock(ref_clk, 800, MXC_ARM_CLK);
80 if (ret)
81 printf("CPU: Switch CPU clock to 800MHZ failed\n");
82
83 ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
84 ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
85 if (ret)
86 printf("CPU: Switch DDR clock to 400MHz failed\n");
87}
88
89static void setup_ups(void)
90{
91 gpio_request(BOOSTER_OFF, "BOOSTER_OFF");
92 gpio_direction_output(BOOSTER_OFF, 0);
93}
94
95int board_early_init_f(void)
96{
97 return 0;
98}
99
100/*
101 * Do not overwrite the console
102 * Use always serial for U-Boot console
103 */
104int overwrite_console(void)
105{
106 return 1;
107}
108
109int board_init(void)
110{
111 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
112
113 return 0;
114}
115
Lukasz Majewski618d4b62018-05-20 08:33:14 +0200116void board_disable_display(void)
117{
118 gpio_request(LCD_BACKLIGHT, "LCD_BACKLIGHT");
119 gpio_direction_output(LCD_BACKLIGHT, 0);
120}
121
Lukasz Majewski097cfe32018-05-20 08:33:16 +0200122void board_misc_setup(void)
123{
124 gpio_request(KEY1, "KEY1_GPIO");
125 gpio_direction_input(KEY1);
126
127 if (gpio_get_value(KEY1))
128 env_set("key1", "off");
129 else
130 env_set("key1", "on");
131}
132
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200133int board_late_init(void)
134{
135 int ret = 0;
136
Lukasz Majewski618d4b62018-05-20 08:33:14 +0200137 board_disable_display();
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200138 setup_ups();
139
140 if (!power_init())
141 setup_clocks();
142
143 ret = read_eeprom();
144 if (ret)
145 printf("Error %d reading EEPROM content!\n", ret);
146
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200147 show_eeprom();
148 read_board_id();
149
Lukasz Majewski097cfe32018-05-20 08:33:16 +0200150 board_misc_setup();
151
Lukasz Majewski7515a6f2018-04-26 15:07:18 +0200152 return ret;
153}