Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <clk.h> |
| 8 | #include <dm.h> |
| 9 | #include <dm/device-internal.h> |
| 10 | #include <dm/lists.h> |
| 11 | #include <dm/uclass.h> |
| 12 | #include <errno.h> |
| 13 | #include <asm/arch/sci/sci.h> |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 14 | #include <asm/arch/sys_proto.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 15 | #include <asm/arch-imx/cpu.h> |
| 16 | #include <asm/armv8/cpu.h> |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 17 | #include <asm/mach-imx/boot_mode.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | u32 get_cpu_rev(void) |
| 22 | { |
| 23 | u32 id = 0, rev = 0; |
| 24 | int ret; |
| 25 | |
| 26 | ret = sc_misc_get_control(-1, SC_R_SYSTEM, SC_C_ID, &id); |
| 27 | if (ret) |
| 28 | return 0; |
| 29 | |
| 30 | rev = (id >> 5) & 0xf; |
| 31 | id = (id & 0x1f) + MXC_SOC_IMX8; /* Dummy ID for chip */ |
| 32 | |
| 33 | return (id << 12) | rev; |
| 34 | } |
| 35 | |
| 36 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 37 | const char *get_imx8_type(u32 imxtype) |
| 38 | { |
| 39 | switch (imxtype) { |
| 40 | case MXC_CPU_IMX8QXP: |
| 41 | return "8QXP"; |
| 42 | default: |
| 43 | return "??"; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | const char *get_imx8_rev(u32 rev) |
| 48 | { |
| 49 | switch (rev) { |
| 50 | case CHIP_REV_A: |
| 51 | return "A"; |
| 52 | case CHIP_REV_B: |
| 53 | return "B"; |
| 54 | default: |
| 55 | return "?"; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | const char *get_core_name(void) |
| 60 | { |
| 61 | if (is_cortex_a35()) |
| 62 | return "A35"; |
| 63 | else |
| 64 | return "?"; |
| 65 | } |
| 66 | |
| 67 | int print_cpuinfo(void) |
| 68 | { |
| 69 | struct udevice *dev; |
| 70 | struct clk cpu_clk; |
| 71 | int ret; |
| 72 | |
| 73 | ret = uclass_get_device(UCLASS_CPU, 0, &dev); |
| 74 | if (ret) |
| 75 | return 0; |
| 76 | |
| 77 | ret = clk_get_by_index(dev, 0, &cpu_clk); |
| 78 | if (ret) { |
| 79 | dev_err(dev, "failed to clk\n"); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | u32 cpurev; |
| 84 | |
| 85 | cpurev = get_cpu_rev(); |
| 86 | |
| 87 | printf("CPU: Freescale i.MX%s rev%s %s at %ld MHz\n", |
| 88 | get_imx8_type((cpurev & 0xFF000) >> 12), |
| 89 | get_imx8_rev((cpurev & 0xFFF)), |
| 90 | get_core_name(), |
| 91 | clk_get_rate(&cpu_clk) / 1000000); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | #endif |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 96 | |
| 97 | int print_bootinfo(void) |
| 98 | { |
| 99 | enum boot_device bt_dev = get_boot_device(); |
| 100 | |
| 101 | puts("Boot: "); |
| 102 | switch (bt_dev) { |
| 103 | case SD1_BOOT: |
| 104 | puts("SD0\n"); |
| 105 | break; |
| 106 | case SD2_BOOT: |
| 107 | puts("SD1\n"); |
| 108 | break; |
| 109 | case SD3_BOOT: |
| 110 | puts("SD2\n"); |
| 111 | break; |
| 112 | case MMC1_BOOT: |
| 113 | puts("MMC0\n"); |
| 114 | break; |
| 115 | case MMC2_BOOT: |
| 116 | puts("MMC1\n"); |
| 117 | break; |
| 118 | case MMC3_BOOT: |
| 119 | puts("MMC2\n"); |
| 120 | break; |
| 121 | case FLEXSPI_BOOT: |
| 122 | puts("FLEXSPI\n"); |
| 123 | break; |
| 124 | case SATA_BOOT: |
| 125 | puts("SATA\n"); |
| 126 | break; |
| 127 | case NAND_BOOT: |
| 128 | puts("NAND\n"); |
| 129 | break; |
| 130 | case USB_BOOT: |
| 131 | puts("USB\n"); |
| 132 | break; |
| 133 | default: |
| 134 | printf("Unknown device %u\n", bt_dev); |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | enum boot_device get_boot_device(void) |
| 142 | { |
| 143 | enum boot_device boot_dev = SD1_BOOT; |
| 144 | |
| 145 | sc_rsrc_t dev_rsrc; |
| 146 | |
| 147 | sc_misc_get_boot_dev(-1, &dev_rsrc); |
| 148 | |
| 149 | switch (dev_rsrc) { |
| 150 | case SC_R_SDHC_0: |
| 151 | boot_dev = MMC1_BOOT; |
| 152 | break; |
| 153 | case SC_R_SDHC_1: |
| 154 | boot_dev = SD2_BOOT; |
| 155 | break; |
| 156 | case SC_R_SDHC_2: |
| 157 | boot_dev = SD3_BOOT; |
| 158 | break; |
| 159 | case SC_R_NAND: |
| 160 | boot_dev = NAND_BOOT; |
| 161 | break; |
| 162 | case SC_R_FSPI_0: |
| 163 | boot_dev = FLEXSPI_BOOT; |
| 164 | break; |
| 165 | case SC_R_SATA_0: |
| 166 | boot_dev = SATA_BOOT; |
| 167 | break; |
| 168 | case SC_R_USB_0: |
| 169 | case SC_R_USB_1: |
| 170 | case SC_R_USB_2: |
| 171 | boot_dev = USB_BOOT; |
| 172 | break; |
| 173 | default: |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | return boot_dev; |
| 178 | } |
Peng Fan | 93b6cfd | 2018-10-18 14:28:20 +0200 | [diff] [blame^] | 179 | |
| 180 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 181 | __weak int board_mmc_get_env_dev(int devno) |
| 182 | { |
| 183 | return CONFIG_SYS_MMC_ENV_DEV; |
| 184 | } |
| 185 | |
| 186 | int mmc_get_env_dev(void) |
| 187 | { |
| 188 | sc_rsrc_t dev_rsrc; |
| 189 | int devno; |
| 190 | |
| 191 | sc_misc_get_boot_dev(-1, &dev_rsrc); |
| 192 | |
| 193 | switch (dev_rsrc) { |
| 194 | case SC_R_SDHC_0: |
| 195 | devno = 0; |
| 196 | break; |
| 197 | case SC_R_SDHC_1: |
| 198 | devno = 1; |
| 199 | break; |
| 200 | case SC_R_SDHC_2: |
| 201 | devno = 2; |
| 202 | break; |
| 203 | default: |
| 204 | /* If not boot from sd/mmc, use default value */ |
| 205 | return CONFIG_SYS_MMC_ENV_DEV; |
| 206 | } |
| 207 | |
| 208 | return board_mmc_get_env_dev(devno); |
| 209 | } |
| 210 | #endif |