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