1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Freescale Semiconductor, Inc.
4  */
5 
6 #include <common.h>
7 #include <fdt_support.h>
8 #include <init.h>
9 #include <asm/global_data.h>
10 #include <asm/io.h>
11 #include <asm/arch/sys_proto.h>
12 #include <asm/arch/mx7ulp-pins.h>
13 #include <asm/arch/iomux.h>
14 #include <asm/mach-imx/boot_mode.h>
15 
16 DECLARE_GLOBAL_DATA_PTR;
17 
18 #define UART_PAD_CTRL	(PAD_CTL_PUS_UP)
19 
dram_init(void)20 int dram_init(void)
21 {
22 	gd->ram_size = imx_ddr_size();
23 
24 	return 0;
25 }
26 
27 static iomux_cfg_t const lpuart4_pads[] = {
28 	MX7ULP_PAD_PTC3__LPUART4_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
29 	MX7ULP_PAD_PTC2__LPUART4_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
30 };
31 
setup_iomux_uart(void)32 static void setup_iomux_uart(void)
33 {
34 	mx7ulp_iomux_setup_multiple_pads(lpuart4_pads,
35 					 ARRAY_SIZE(lpuart4_pads));
36 }
37 
board_early_init_f(void)38 int board_early_init_f(void)
39 {
40 	setup_iomux_uart();
41 
42 	return 0;
43 }
44 
board_init(void)45 int board_init(void)
46 {
47 	/* address of boot parameters */
48 	gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
49 
50 	return 0;
51 }
52 
53 #if IS_ENABLED(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,struct bd_info * bd)54 int ft_board_setup(void *blob, struct bd_info *bd)
55 {
56 	const char *path;
57 	int rc, nodeoff;
58 
59 	if (get_boot_device() == USB_BOOT) {
60 		path = fdt_get_alias(blob, "mmc0");
61 		if (!path) {
62 			puts("Not found mmc0\n");
63 			return 0;
64 		}
65 
66 		nodeoff = fdt_path_offset(blob, path);
67 		if (nodeoff < 0)
68 			return 0;
69 
70 		printf("Found usdhc0 node\n");
71 		if (fdt_get_property(blob, nodeoff, "vqmmc-supply",
72 		    NULL) != NULL) {
73 			rc = fdt_delprop(blob, nodeoff, "vqmmc-supply");
74 			if (!rc) {
75 				puts("Removed vqmmc-supply property\n");
76 add:
77 				rc = fdt_setprop(blob, nodeoff,
78 						 "no-1-8-v", NULL, 0);
79 				if (rc == -FDT_ERR_NOSPACE) {
80 					rc = fdt_increase_size(blob, 32);
81 					if (!rc)
82 						goto add;
83 				} else if (rc) {
84 					printf("Failed to add no-1-8-v property, %d\n", rc);
85 				} else {
86 					puts("Added no-1-8-v property\n");
87 				}
88 			} else {
89 				printf("Failed to remove vqmmc-supply property, %d\n", rc);
90 			}
91 		}
92 	}
93 
94 	return 0;
95 }
96 #endif
97