Runmin Wang | dc8e973 | 2016-10-06 11:14:08 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved. |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 20 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 25 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform.h> |
| 31 | #include <qgic.h> |
| 32 | #include <qtimer.h> |
| 33 | #include <board.h> |
Sridhar Parasuram | 673c6bb | 2014-12-29 13:39:35 -0800 | [diff] [blame] | 34 | #include <boot_device.h> |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 35 | #include <mmu.h> |
| 36 | #include <arch/arm/mmu.h> |
| 37 | #include <platform/iomap.h> |
Sridhar Parasuram | 673c6bb | 2014-12-29 13:39:35 -0800 | [diff] [blame] | 38 | #include <platform/clock.h> |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 39 | #include <smem.h> |
| 40 | #include <reg.h> |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 41 | #include <qpic_nand.h> |
| 42 | #include <target.h> |
| 43 | |
| 44 | extern struct smem_ram_ptable* target_smem_ram_ptable_init(); |
| 45 | |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 46 | #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB) |
| 47 | |
| 48 | /* LK memory - Strongly ordered, executable */ |
| 49 | #define LK_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
| 50 | MMU_MEMORY_AP_READ_WRITE) |
| 51 | /* Scratch memory - Strongly ordered, non-executable */ |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 52 | #define SCRATCH_MEMORY (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \ |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 53 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 54 | /* Peripherals - shared device */ |
| 55 | #define IOMAP_MEMORY (MMU_MEMORY_TYPE_DEVICE_SHARED | \ |
| 56 | MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN) |
| 57 | |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 58 | /* Map all the accesssible memory according to the following rules: |
| 59 | * 1. Map 1MB from MSM_SHARED_BASE with 1 -1 mapping. |
| 60 | * 2. Map MEMBASE - MEMSIZE with 1 -1 mapping. |
| 61 | * 3. Map all the scratch regions immediately after Appsbl memory. |
| 62 | * Virtual addresses start right after Appsbl Virtual address. |
| 63 | * 4. Map all the IOMAP space with 1 - 1 mapping. |
| 64 | * 5. Map all the rest of the SDRAM/ IMEM regions as 1 -1. |
| 65 | */ |
| 66 | mmu_section_t mmu_section_table[] = { |
| 67 | /* Physical addr, Virtual addr, Size (in MB), Flags */ |
| 68 | {MSM_SHARED_BASE, MSM_SHARED_BASE, 1, SCRATCH_MEMORY}, |
| 69 | {MEMBASE, MEMBASE, MEMSIZE / MB, LK_MEMORY}, |
| 70 | {MSM_IOMAP_BASE, MSM_IOMAP_BASE, MSM_IOMAP_SIZE, IOMAP_MEMORY}, |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 71 | {SCRATCH_REGION1, SCRATCH_REGION1, SCRATCH_REGION1_SIZE / MB, SCRATCH_MEMORY}, |
| 72 | {SCRATCH_REGION2, SCRATCH_REGION2, SCRATCH_REGION2_SIZE / MB, SCRATCH_MEMORY}, |
| 73 | {KERNEL_REGION, KERNEL_REGION, KERNEL_REGION_SIZE / MB, SCRATCH_MEMORY}, |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | void platform_early_init(void) |
| 77 | { |
Channagoud Kadabi | f3e5059 | 2015-06-02 16:19:24 -0700 | [diff] [blame] | 78 | /* Initialize board identifier data */ |
| 79 | board_init(); |
| 80 | |
Channagoud Kadabi | d23379d | 2014-10-13 11:33:50 -0700 | [diff] [blame] | 81 | /* Read boot config for identifying boot device */ |
| 82 | platform_read_boot_config(); |
| 83 | |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 84 | |
| 85 | /* Initialize clock driver */ |
| 86 | platform_clock_init(); |
| 87 | |
| 88 | /* Initialize interrupt controller */ |
| 89 | qgic_init(); |
| 90 | |
| 91 | /* timer */ |
| 92 | qtimer_init(); |
| 93 | } |
| 94 | |
| 95 | void platform_init(void) |
| 96 | { |
| 97 | dprintf(INFO, "platform_init()\n"); |
| 98 | } |
| 99 | |
| 100 | void platform_uninit(void) |
| 101 | { |
| 102 | qtimer_uninit(); |
| 103 | if (!platform_boot_dev_isemmc()) |
| 104 | qpic_nand_uninit(); |
| 105 | } |
| 106 | |
| 107 | /* Do not use default identitiy mappings. */ |
| 108 | int platform_use_identity_mmu_mappings(void) |
| 109 | { |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | uint32_t platform_get_sclk_count(void) |
| 114 | { |
| 115 | return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL); |
| 116 | } |
| 117 | |
| 118 | addr_t get_bs_info_addr() |
| 119 | { |
| 120 | return ((addr_t)BS_INFO_ADDR); |
| 121 | } |
| 122 | |
| 123 | /* Setup memory for this platform */ |
| 124 | void platform_init_mmu_mappings(void) |
| 125 | { |
| 126 | uint32_t i; |
| 127 | uint32_t sections; |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 128 | uint32_t table_size = ARRAY_SIZE(mmu_section_table); |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 129 | |
| 130 | /* Configure the MMU page entries for memory read from the |
| 131 | mmu_section_table */ |
| 132 | for (i = 0; i < table_size; i++) |
| 133 | { |
| 134 | sections = mmu_section_table[i].num_of_sections; |
| 135 | |
| 136 | while (sections--) |
| 137 | { |
| 138 | arm_mmu_map_section(mmu_section_table[i].paddress + |
| 139 | sections * MB, |
| 140 | mmu_section_table[i].vaddress + |
| 141 | sections * MB, |
| 142 | mmu_section_table[i].flags); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | addr_t platform_get_virt_to_phys_mapping(addr_t virt_addr) |
| 148 | { |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 149 | /* Fixed 1-1 mapping */ |
| 150 | return virt_addr; |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | addr_t platform_get_phys_to_virt_mapping(addr_t phys_addr) |
| 154 | { |
Channagoud Kadabi | 1b69e48 | 2014-09-23 15:20:22 -0700 | [diff] [blame] | 155 | /* Fixed 1-1 mapping */ |
| 156 | return phys_addr; |
Joonwoo Park | 451dca3 | 2014-04-02 11:47:03 -0700 | [diff] [blame] | 157 | } |
Channagoud Kadabi | 6cf2862 | 2015-05-28 15:12:43 -0700 | [diff] [blame] | 158 | |
Channagoud Kadabi | fdfee23 | 2015-10-07 11:55:47 -0700 | [diff] [blame] | 159 | |
| 160 | bool platform_is_mdmcalifornium() |
| 161 | { |
| 162 | uint32_t platform_id = board_platform_id(); |
| 163 | bool ret; |
| 164 | |
| 165 | switch(platform_id) |
| 166 | { |
| 167 | case MDMCALIFORNIUM1: |
| 168 | case MDMCALIFORNIUM2: |
| 169 | case MDMCALIFORNIUM3: |
| 170 | case MDMCALIFORNIUM4: |
| 171 | ret = true; |
| 172 | break; |
| 173 | default: |
| 174 | ret = false; |
| 175 | }; |
| 176 | |
| 177 | return ret; |
| 178 | } |
| 179 | |
Runmin Wang | dc8e973 | 2016-10-06 11:14:08 -0700 | [diff] [blame] | 180 | bool platform_is_sdxhedgehog() |
| 181 | { |
| 182 | uint32_t platform_id = board_platform_id(); |
| 183 | bool ret; |
| 184 | |
| 185 | switch(platform_id) |
| 186 | { |
| 187 | case SDXHEDGEHOG: |
| 188 | ret = true; |
| 189 | break; |
| 190 | default: |
| 191 | ret = false; |
| 192 | }; |
| 193 | |
| 194 | return ret; |
| 195 | } |
| 196 | |
Channagoud Kadabi | 6cf2862 | 2015-05-28 15:12:43 -0700 | [diff] [blame] | 197 | uint32_t platform_boot_config() |
| 198 | { |
| 199 | uint32_t boot_config; |
| 200 | |
Runmin Wang | dc8e973 | 2016-10-06 11:14:08 -0700 | [diff] [blame] | 201 | if (platform_is_mdmcalifornium() || platform_is_sdxhedgehog()) |
Channagoud Kadabi | fdfee23 | 2015-10-07 11:55:47 -0700 | [diff] [blame] | 202 | boot_config = BOOT_CONFIG_REG_V2; |
| 203 | /* Else the platform is 9x45 */ |
| 204 | else if (board_soc_version() >= 0x20000) |
Channagoud Kadabi | 6cf2862 | 2015-05-28 15:12:43 -0700 | [diff] [blame] | 205 | boot_config = BOOT_CONFIG_REG_V2; |
| 206 | else |
| 207 | boot_config = BOOT_CONFIG_REG_V1; |
| 208 | |
| 209 | return boot_config; |
| 210 | } |
Channagoud Kadabi | fdfee23 | 2015-10-07 11:55:47 -0700 | [diff] [blame] | 211 | |
| 212 | uint32_t platform_get_qmp_rev() |
| 213 | { |
| 214 | return readl(USB3_PHY_REVISION_ID3) << 24 | readl(USB3_PHY_REVISION_ID2) << 16 | |
| 215 | readl(USB3_PHY_REVISION_ID1) << 8 | readl(USB3_PHY_REVISION_ID0); |
| 216 | } |
| 217 | |