Manivannan Sadhasivam | c62c7ef | 2019-08-02 20:40:09 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Linaro |
| 4 | * Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9a3b4ce | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Manivannan Sadhasivam | c62c7ef | 2019-08-02 20:40:09 +0530 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <errno.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/hi3660.h> |
| 13 | #include <asm/armv8/mmu.h> |
| 14 | #include <asm/psci.h> |
| 15 | #include <linux/arm-smccc.h> |
| 16 | #include <linux/psci.h> |
| 17 | |
| 18 | #define PMIC_REG_TO_BUS_ADDR(x) (x << 2) |
| 19 | #define PMIC_VSEL_MASK 0x7 |
| 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
| 24 | #include <dm/platform_data/serial_pl01x.h> |
| 25 | |
| 26 | static const struct pl01x_serial_platdata serial_platdata = { |
| 27 | .base = HI3660_UART6_BASE, |
| 28 | .type = TYPE_PL011, |
| 29 | .clock = 19200000 |
| 30 | }; |
| 31 | |
| 32 | U_BOOT_DEVICE(hikey960_serial0) = { |
| 33 | .name = "serial_pl01x", |
| 34 | .platdata = &serial_platdata, |
| 35 | }; |
| 36 | #endif |
| 37 | |
| 38 | static struct mm_region hikey_mem_map[] = { |
| 39 | { |
| 40 | .virt = 0x0UL, /* DDR */ |
| 41 | .phys = 0x0UL, |
| 42 | .size = 0xC0000000UL, |
| 43 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 44 | PTE_BLOCK_INNER_SHARE |
| 45 | }, { |
| 46 | .virt = 0xE0000000UL, /* Peripheral block */ |
| 47 | .phys = 0xE0000000UL, |
| 48 | .size = 0x20000000UL, |
| 49 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 50 | PTE_BLOCK_NON_SHARE | |
| 51 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 52 | }, { |
| 53 | /* List terminator */ |
| 54 | 0, |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | struct mm_region *mem_map = hikey_mem_map; |
| 59 | |
| 60 | int board_early_init_f(void) |
| 61 | { |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | int misc_init_r(void) |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | int dram_init(void) |
| 71 | { |
| 72 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | int dram_init_banksize(void) |
| 78 | { |
| 79 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 80 | gd->bd->bi_dram[0].size = gd->ram_size; |
| 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | void hikey960_sd_init(void) |
| 86 | { |
| 87 | u32 data; |
| 88 | |
| 89 | /* Enable FPLL0 */ |
| 90 | data = readl(SCTRL_SCFPLLCTRL0); |
| 91 | data |= SCTRL_SCFPLLCTRL0_FPLL0_EN; |
| 92 | writel(data, SCTRL_SCFPLLCTRL0); |
| 93 | |
| 94 | /* Configure LDO16 */ |
| 95 | data = readl(PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x79)) & |
| 96 | PMIC_VSEL_MASK; |
| 97 | data |= 6; |
| 98 | writel(data, PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x79)); |
| 99 | |
| 100 | data = readl(PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x78)); |
| 101 | data |= 2; |
| 102 | writel(data, PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x78)); |
| 103 | |
| 104 | udelay(100); |
| 105 | |
| 106 | /* Configure LDO9 */ |
| 107 | data = readl(PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x6b)) & |
| 108 | PMIC_VSEL_MASK; |
| 109 | data |= 5; |
| 110 | writel(data, PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x6b)); |
| 111 | |
| 112 | data = readl(PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x6a)); |
| 113 | data |= 2; |
| 114 | writel(data, PMU_REG_BASE + PMIC_REG_TO_BUS_ADDR(0x6a)); |
| 115 | |
| 116 | udelay(100); |
| 117 | |
| 118 | /* GPIO CD */ |
| 119 | writel(0, PINMUX4_SDDET); |
| 120 | |
| 121 | /* SD Pinconf */ |
| 122 | writel(15 << 4, PINCONF3_SDCLK); |
| 123 | writel((1 << 0) | (8 << 4), PINCONF3_SDCMD); |
| 124 | writel((1 << 0) | (8 << 4), PINCONF3_SDDATA0); |
| 125 | writel((1 << 0) | (8 << 4), PINCONF3_SDDATA1); |
| 126 | writel((1 << 0) | (8 << 4), PINCONF3_SDDATA2); |
| 127 | writel((1 << 0) | (8 << 4), PINCONF3_SDDATA3); |
| 128 | |
| 129 | /* Set SD clock mux */ |
| 130 | do { |
| 131 | data = readl(CRG_REG_BASE + 0xb8); |
| 132 | data |= ((1 << 6) | (1 << 6 << 16) | (0 << 4) | (3 << 4 << 16)); |
| 133 | writel(data, CRG_REG_BASE + 0xb8); |
| 134 | |
| 135 | data = readl(CRG_REG_BASE + 0xb8); |
| 136 | } while ((data & ((1 << 6) | (3 << 4))) != ((1 << 6) | (0 << 4))); |
| 137 | |
| 138 | /* Take SD out of reset */ |
| 139 | writel(1 << 18, CRG_PERRSTDIS4); |
| 140 | do { |
| 141 | data = readl(CRG_PERRSTSTAT4); |
| 142 | } while ((data & (1 << 18)) == (1 << 18)); |
| 143 | |
| 144 | /* Enable hclk_gate_sd */ |
| 145 | data = readl(CRG_REG_BASE + 0); |
| 146 | data |= (1 << 30); |
| 147 | writel(data, CRG_REG_BASE + 0); |
| 148 | |
| 149 | /* Enable clk_andgt_mmc */ |
| 150 | data = readl(CRG_REG_BASE + 0xf4); |
| 151 | data |= ((1 << 3) | (1 << 3 << 16)); |
| 152 | writel(data, CRG_REG_BASE + 0xf4); |
| 153 | |
| 154 | /* Enable clk_gate_sd */ |
| 155 | data = readl(CRG_PEREN4); |
| 156 | data |= (1 << 17); |
| 157 | writel(data, CRG_PEREN4); |
| 158 | do { |
| 159 | data = readl(CRG_PERCLKEN4); |
| 160 | } while ((data & (1 << 17)) != (1 << 17)); |
| 161 | } |
| 162 | |
| 163 | static void show_psci_version(void) |
| 164 | { |
| 165 | struct arm_smccc_res res; |
| 166 | |
| 167 | arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res); |
| 168 | |
| 169 | printf("PSCI: v%ld.%ld\n", |
| 170 | PSCI_VERSION_MAJOR(res.a0), |
| 171 | PSCI_VERSION_MINOR(res.a0)); |
| 172 | } |
| 173 | |
| 174 | int board_init(void) |
| 175 | { |
| 176 | /* Init SD */ |
| 177 | hikey960_sd_init(); |
| 178 | |
| 179 | show_psci_version(); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | void reset_cpu(ulong addr) |
| 185 | { |
| 186 | psci_system_reset(); |
| 187 | } |