ARM: Remove non DM/DTS esdhc3 code from HSC|DDC board related files
[oweals/u-boot.git] / board / k+p / kp_imx53 / kp_imx53.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018
4  * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
5  */
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>
16 #include <power/pmic.h>
17 #include <fsl_pmic.h>
18 #include "kp_id_rev.h"
19
20 #define VBUS_PWR_EN IMX_GPIO_NR(7, 8)
21 #define BOOSTER_OFF IMX_GPIO_NR(2, 23)
22 #define LCD_BACKLIGHT IMX_GPIO_NR(1, 1)
23 #define KEY1 IMX_GPIO_NR(2, 26)
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 int 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
37 int 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
45 #ifdef CONFIG_USB_EHCI_MX5
46 int board_ehci_hcd_init(int port)
47 {
48         gpio_request(VBUS_PWR_EN, "VBUS_PWR_EN");
49         gpio_direction_output(VBUS_PWR_EN, 1);
50         return 0;
51 }
52 #endif
53
54 static int power_init(void)
55 {
56         struct udevice *dev;
57         int ret;
58
59         ret = pmic_get("mc34708", &dev);
60         if (ret) {
61                 printf("%s: mc34708 not found !\n", __func__);
62                 return ret;
63         }
64
65         /* Set VDDGP to 1.110V for 800 MHz on SW1 */
66         pmic_clrsetbits(dev, REG_SW_0, SWx_VOLT_MASK_MC34708,
67                         SWx_1_110V_MC34708);
68
69         /* Set VCC as 1.30V on SW2 */
70         pmic_clrsetbits(dev, REG_SW_1, SWx_VOLT_MASK_MC34708,
71                         SWx_1_300V_MC34708);
72
73         /* Set global reset timer to 4s */
74         pmic_clrsetbits(dev, REG_POWER_CTL2, TIMER_MASK_MC34708,
75                         TIMER_4S_MC34708);
76
77         return ret;
78 }
79
80 static void setup_clocks(void)
81 {
82         int ret;
83         u32 ref_clk = MXC_HCLK;
84         /*
85          * CPU clock set to 800MHz and DDR to 400MHz
86          */
87         ret = mxc_set_clock(ref_clk, 800, MXC_ARM_CLK);
88         if (ret)
89                 printf("CPU:   Switch CPU clock to 800MHZ failed\n");
90
91         ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
92         ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
93         if (ret)
94                 printf("CPU:   Switch DDR clock to 400MHz failed\n");
95 }
96
97 static void setup_ups(void)
98 {
99         gpio_request(BOOSTER_OFF, "BOOSTER_OFF");
100         gpio_direction_output(BOOSTER_OFF, 0);
101 }
102
103 int board_early_init_f(void)
104 {
105         return 0;
106 }
107
108 /*
109  * Do not overwrite the console
110  * Use always serial for U-Boot console
111  */
112 int overwrite_console(void)
113 {
114         return 1;
115 }
116
117 int board_init(void)
118 {
119         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
120
121         return 0;
122 }
123
124 void board_disable_display(void)
125 {
126         gpio_request(LCD_BACKLIGHT, "LCD_BACKLIGHT");
127         gpio_direction_output(LCD_BACKLIGHT, 0);
128 }
129
130 void board_misc_setup(void)
131 {
132         gpio_request(KEY1, "KEY1_GPIO");
133         gpio_direction_input(KEY1);
134
135         if (gpio_get_value(KEY1))
136                 env_set("key1", "off");
137         else
138                 env_set("key1", "on");
139 }
140
141 int board_late_init(void)
142 {
143         int ret = 0;
144
145         board_disable_display();
146         setup_ups();
147
148         if (!power_init())
149                 setup_clocks();
150
151         ret = read_eeprom();
152         if (ret)
153                 printf("Error %d reading EEPROM content!\n", ret);
154
155         show_eeprom();
156         read_board_id();
157
158         board_misc_setup();
159
160         return ret;
161 }