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