Merge branch 'master' of git://git.denx.de/u-boot-sh
[oweals/u-boot.git] / board / engicam / common / board.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Amarula Solutions B.V.
4  * Copyright (C) 2016 Engicam S.r.l.
5  * Author: Jagan Teki <jagan@amarulasolutions.com>
6  */
7
8 #include <common.h>
9 #include <mmc.h>
10 #include <asm/arch/sys_proto.h>
11 #include <watchdog.h>
12
13 #include "board.h"
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 #ifdef CONFIG_ENV_IS_IN_MMC
18 static void mmc_late_init(void)
19 {
20         char cmd[32];
21         char mmcblk[32];
22         u32 dev_no = mmc_get_env_dev();
23
24         env_set_ulong("mmcdev", dev_no);
25
26         /* Set mmcblk env */
27         sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
28         env_set("mmcroot", mmcblk);
29
30         sprintf(cmd, "mmc dev %d", dev_no);
31         run_command(cmd, 0);
32 }
33 #endif
34
35 static void setenv_fdt_file(void)
36 {
37         const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE;
38
39         if (!strcmp(cmp_dtb, "imx6q-icore")) {
40                 if (is_mx6dq())
41                         env_set("fdt_file", "imx6q-icore.dtb");
42                 else if (is_mx6dl() || is_mx6solo())
43                         env_set("fdt_file", "imx6dl-icore.dtb");
44         } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
45                 if (is_mx6dq())
46                         env_set("fdt_file", "imx6q-icore-mipi.dtb");
47                 else if (is_mx6dl() || is_mx6solo())
48                         env_set("fdt_file", "imx6dl-icore-mipi.dtb");
49         } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
50                 if (is_mx6dq())
51                         env_set("fdt_file", "imx6q-icore-rqs.dtb");
52                 else if (is_mx6dl() || is_mx6solo())
53                         env_set("fdt_file", "imx6dl-icore-rqs.dtb");
54         } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
55                 env_set("fdt_file", "imx6ul-geam.dtb");
56         else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
57                 env_set("fdt_file", "imx6ul-isiot-emmc.dtb");
58         else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
59                 env_set("fdt_file", "imx6ul-isiot-nand.dtb");
60 }
61
62 int board_late_init(void)
63 {
64         switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
65                         IMX6_BMODE_SHIFT) {
66         case IMX6_BMODE_SD:
67         case IMX6_BMODE_ESD:
68         case IMX6_BMODE_MMC:
69         case IMX6_BMODE_EMMC:
70 #ifdef CONFIG_ENV_IS_IN_MMC
71                 mmc_late_init();
72 #endif
73                 env_set("modeboot", "mmcboot");
74                 break;
75         case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
76                 env_set("modeboot", "nandboot");
77                 break;
78         default:
79                 env_set("modeboot", "");
80                 break;
81         }
82
83         if (is_mx6ul())
84                 env_set("console", "ttymxc0");
85         else
86                 env_set("console", "ttymxc3");
87
88         setenv_fdt_file();
89
90 #ifdef CONFIG_HW_WATCHDOG
91         hw_watchdog_init();
92 #endif
93
94         return 0;
95 }
96
97 int board_init(void)
98 {
99         /* Address of boot parameters */
100         gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
101
102 #ifdef CONFIG_NAND_MXS
103         setup_gpmi_nand();
104 #endif
105
106 #ifdef CONFIG_VIDEO_IPUV3
107         setup_display();
108 #endif
109
110         return 0;
111 }
112
113 int dram_init(void)
114 {
115         gd->ram_size = imx_ddr_size();
116
117         return 0;
118 }