Prepare v2023.10
[platform/kernel/u-boot.git] / board / freescale / mx53loco / mx53loco.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2011 Freescale Semiconductor, Inc.
4  * Jason Liu <r64343@freescale.com>
5  */
6
7 #include <common.h>
8 #include <init.h>
9 #include <log.h>
10 #include <asm/global_data.h>
11 #include <asm/io.h>
12 #include <asm/arch/imx-regs.h>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/arch/crm_regs.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/iomux-mx53.h>
17 #include <asm/arch/clock.h>
18 #include <env.h>
19 #include <linux/errno.h>
20 #include <asm/mach-imx/mx5_video.h>
21 #include <i2c.h>
22 #include <input.h>
23 #include <fsl_esdhc_imx.h>
24 #include <asm/gpio.h>
25 #include <power/pmic.h>
26 #include <dialog_pmic.h>
27 #include <fsl_pmic.h>
28 #include <linux/fb.h>
29 #include <ipu_pixfmt.h>
30 #include <dm/uclass.h>
31 #include <dm/device.h>
32
33 #define MX53LOCO_LCD_POWER              IMX_GPIO_NR(3, 24)
34
35 DECLARE_GLOBAL_DATA_PTR;
36
37 #ifdef CONFIG_REVISION_TAG
38 u32 get_board_rev(void)
39 {
40         struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
41         struct fuse_bank *bank = &iim->bank[0];
42         struct fuse_bank0_regs *fuse =
43                 (struct fuse_bank0_regs *)bank->fuse_regs;
44         struct udevice *bus;
45         struct udevice *dev;
46
47         int rev = readl(&fuse->gp[6]);
48
49         ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
50         if (ret)
51                 return ret;
52
53         if (!dm_i2c_probe(bus, CFG_SYS_DIALOG_PMIC_I2C_ADDR, 0, &dev))
54                 rev = 0;
55
56         return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
57 }
58 #endif
59
60 #define UART_PAD_CTRL   (PAD_CTL_HYS | PAD_CTL_DSE_HIGH | \
61                          PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
62
63 static void setup_iomux_uart(void)
64 {
65         static const iomux_v3_cfg_t uart_pads[] = {
66                 NEW_PAD_CTRL(MX53_PAD_CSI0_DAT11__UART1_RXD_MUX, UART_PAD_CTRL),
67                 NEW_PAD_CTRL(MX53_PAD_CSI0_DAT10__UART1_TXD_MUX, UART_PAD_CTRL),
68         };
69
70         imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
71 }
72
73 static int power_init(void)
74 {
75         unsigned int val;
76         int ret;
77         struct pmic *p;
78         struct udevice *bus;
79         struct udevice *dev;
80
81         ret = uclass_get_device_by_seq(UCLASS_I2C, 0, &bus);
82         if (ret)
83                 return ret;
84
85         if (!dm_i2c_probe(bus, CFG_SYS_DIALOG_PMIC_I2C_ADDR, 0, &dev)) {
86                 ret = pmic_dialog_init(I2C_PMIC);
87                 if (ret)
88                         return ret;
89
90                 p = pmic_get("DIALOG_PMIC");
91                 if (!p)
92                         return -ENODEV;
93
94                 env_set("fdt_file", "imx53-qsb.dtb");
95
96                 /* Set VDDA to 1.25V */
97                 val = DA9052_BUCKCORE_BCOREEN | DA_BUCKCORE_VBCORE_1_250V;
98                 ret = pmic_reg_write(p, DA9053_BUCKCORE_REG, val);
99                 if (ret) {
100                         printf("Writing to BUCKCORE_REG failed: %d\n", ret);
101                         return ret;
102                 }
103
104                 pmic_reg_read(p, DA9053_SUPPLY_REG, &val);
105                 val |= DA9052_SUPPLY_VBCOREGO;
106                 ret = pmic_reg_write(p, DA9053_SUPPLY_REG, val);
107                 if (ret) {
108                         printf("Writing to SUPPLY_REG failed: %d\n", ret);
109                         return ret;
110                 }
111
112                 /* Set Vcc peripheral to 1.30V */
113                 ret = pmic_reg_write(p, DA9053_BUCKPRO_REG, 0x62);
114                 if (ret) {
115                         printf("Writing to BUCKPRO_REG failed: %d\n", ret);
116                         return ret;
117                 }
118
119                 ret = pmic_reg_write(p, DA9053_SUPPLY_REG, 0x62);
120                 if (ret) {
121                         printf("Writing to SUPPLY_REG failed: %d\n", ret);
122                         return ret;
123                 }
124
125                 return ret;
126         }
127
128         if (!dm_i2c_probe(bus, CFG_SYS_FSL_PMIC_I2C_ADDR, 0, &dev)) {
129                 ret = pmic_init(0);
130                 if (ret)
131                         return ret;
132
133                 p = pmic_get("FSL_PMIC");
134                 if (!p)
135                         return -ENODEV;
136
137                 env_set("fdt_file", "imx53-qsrb.dtb");
138
139                 /* Set VDDGP to 1.25V for 1GHz on SW1 */
140                 pmic_reg_read(p, REG_SW_0, &val);
141                 val = (val & ~SWx_VOLT_MASK_MC34708) | SWx_1_250V_MC34708;
142                 ret = pmic_reg_write(p, REG_SW_0, val);
143                 if (ret) {
144                         printf("Writing to REG_SW_0 failed: %d\n", ret);
145                         return ret;
146                 }
147
148                 /* Set VCC as 1.30V on SW2 */
149                 pmic_reg_read(p, REG_SW_1, &val);
150                 val = (val & ~SWx_VOLT_MASK_MC34708) | SWx_1_300V_MC34708;
151                 ret = pmic_reg_write(p, REG_SW_1, val);
152                 if (ret) {
153                         printf("Writing to REG_SW_1 failed: %d\n", ret);
154                         return ret;
155                 }
156
157                 /* Set global reset timer to 4s */
158                 pmic_reg_read(p, REG_POWER_CTL2, &val);
159                 val = (val & ~TIMER_MASK_MC34708) | TIMER_4S_MC34708;
160                 ret = pmic_reg_write(p, REG_POWER_CTL2, val);
161                 if (ret) {
162                         printf("Writing to REG_POWER_CTL2 failed: %d\n", ret);
163                         return ret;
164                 }
165
166                 /* Set VUSBSEL and VUSBEN for USB PHY supply*/
167                 pmic_reg_read(p, REG_MODE_0, &val);
168                 val |= (VUSBSEL_MC34708 | VUSBEN_MC34708);
169                 ret = pmic_reg_write(p, REG_MODE_0, val);
170                 if (ret) {
171                         printf("Writing to REG_MODE_0 failed: %d\n", ret);
172                         return ret;
173                 }
174
175                 /* Set SWBST to 5V in auto mode */
176                 val = SWBST_AUTO;
177                 ret = pmic_reg_write(p, SWBST_CTRL, val);
178                 if (ret) {
179                         printf("Writing to SWBST_CTRL failed: %d\n", ret);
180                         return ret;
181                 }
182
183                 return ret;
184         }
185
186         return -1;
187 }
188
189 static void clock_1GHz(void)
190 {
191         int ret;
192         u32 ref_clk = MXC_HCLK;
193         /*
194          * After increasing voltage to 1.25V, we can switch
195          * CPU clock to 1GHz and DDR to 400MHz safely
196          */
197         ret = mxc_set_clock(ref_clk, 1000, MXC_ARM_CLK);
198         if (ret)
199                 printf("CPU:   Switch CPU clock to 1GHZ failed\n");
200
201         ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK);
202         ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK);
203         if (ret)
204                 printf("CPU:   Switch DDR clock to 400MHz failed\n");
205 }
206
207 int board_early_init_f(void)
208 {
209         setup_iomux_uart();
210         setup_iomux_lcd();
211
212         return 0;
213 }
214
215 /*
216  * Do not overwrite the console
217  * Use always serial for U-Boot console
218  */
219 int overwrite_console(void)
220 {
221         return 1;
222 }
223
224 int board_init(void)
225 {
226         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
227
228         mxc_set_sata_internal_clock();
229
230         return 0;
231 }
232
233 int board_late_init(void)
234 {
235         if (!power_init())
236                 clock_1GHz();
237
238         return 0;
239 }
240
241 int checkboard(void)
242 {
243         puts("Board: MX53 LOCO\n");
244
245         return 0;
246 }