rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2012 Corey Tabaka |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files |
| 6 | * (the "Software"), to deal in the Software without restriction, |
| 7 | * including without limitation the rights to use, copy, modify, merge, |
| 8 | * publish, distribute, sublicense, and/or sell copies of the Software, |
| 9 | * and to permit persons to whom the Software is furnished to do so, |
| 10 | * subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 21 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | #include <err.h> |
| 24 | #include <reg.h> |
| 25 | #include <debug.h> |
| 26 | #include <sys/types.h> |
| 27 | #include <arch/arm/mmu.h> |
| 28 | #include <kernel/vm.h> |
| 29 | #include <platform.h> |
| 30 | #include "platform_p.h" |
| 31 | #include <dev/uart.h> |
| 32 | |
| 33 | #include <hw_control_AM335x.h> |
| 34 | #include <soc_AM335x.h> |
| 35 | #include <hw_cm_wkup.h> |
| 36 | #include <hw_cm_per.h> |
| 37 | #include <hw_types.h> |
| 38 | |
| 39 | #warning Add proper memory map |
| 40 | |
| 41 | /* initial memory mappings. parsed by start.S */ |
| 42 | struct mmu_initial_mapping mmu_initial_mappings[] = { |
| 43 | // XXX needs to be filled in |
| 44 | |
| 45 | /* null entry to terminate the list */ |
| 46 | { 0 } |
| 47 | }; |
| 48 | |
| 49 | #if 0 |
| 50 | void platform_init_mmu_mappings(void) |
| 51 | { |
| 52 | /* do some memory map initialization */ |
| 53 | addr_t addr; |
| 54 | |
| 55 | arm_mmu_map_section(SDRAM_BASE, 0, |
| 56 | MMU_MEMORY_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE | |
| 57 | MMU_MEMORY_L1_AP_P_NA_U_NA); |
| 58 | |
| 59 | for (addr=SDRAM_BASE; addr < SDRAM_BASE + SDRAM_SIZE; addr += (1024*1024)) { |
| 60 | arm_mmu_map_section(addr, addr, |
| 61 | MMU_MEMORY_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE | |
| 62 | MMU_MEMORY_L1_AP_P_RW_U_NA); |
| 63 | } |
| 64 | |
| 65 | for (addr=0x40000000; addr < 0x40000000 + (512*1024*1024); addr += (1024*1024)) { |
| 66 | arm_mmu_map_section(addr, addr, |
| 67 | MMU_MEMORY_L1_TYPE_STRONGLY_ORDERED | |
| 68 | MMU_MEMORY_L1_AP_P_RW_U_NA); |
| 69 | } |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | static void wait_field(addr_t base, uint32_t reg, uint32_t mask, uint32_t val) |
| 74 | { |
| 75 | while ((*REG32(base + reg) & mask) != val); |
| 76 | } |
| 77 | |
| 78 | static void set_field(addr_t base, uint32_t reg, uint32_t mask, uint32_t bits) |
| 79 | { |
| 80 | uint32_t val; |
| 81 | |
| 82 | val = *REG32(base + reg) & ~mask; |
| 83 | *REG32(base + reg) = val | bits; |
| 84 | |
| 85 | wait_field(base, reg, mask, bits); |
| 86 | } |
| 87 | |
| 88 | void per_L3_config(void) |
| 89 | { |
| 90 | vaddr_t base = SOC_CM_PER_REGS; |
| 91 | |
| 92 | /* configure L3 interface clocks. */ |
| 93 | set_field(base, CM_PER_L3_CLKCTRL, |
| 94 | CM_PER_L3_CLKCTRL_MODULEMODE, |
| 95 | CM_PER_L3_CLKCTRL_MODULEMODE_ENABLE); |
| 96 | |
| 97 | set_field(base, CM_PER_L3_INSTR_CLKCTRL, |
| 98 | CM_PER_L3_INSTR_CLKCTRL_MODULEMODE, |
| 99 | CM_PER_L3_INSTR_CLKCTRL_MODULEMODE_ENABLE); |
| 100 | |
| 101 | set_field(base, CM_PER_OCPWP_CLKCTRL, |
| 102 | CM_PER_OCPWP_CLKCTRL_MODULEMODE, |
| 103 | CM_PER_OCPWP_CLKCTRL_MODULEMODE_ENABLE); |
| 104 | |
| 105 | set_field(base, CM_PER_L3_CLKSTCTRL, |
| 106 | CM_PER_L3_CLKSTCTRL_CLKTRCTRL, |
| 107 | CM_PER_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP); |
| 108 | |
| 109 | set_field(base, CM_PER_L3S_CLKSTCTRL, |
| 110 | CM_PER_L3S_CLKSTCTRL_CLKTRCTRL, |
| 111 | CM_PER_L3S_CLKSTCTRL_CLKTRCTRL_SW_WKUP); |
| 112 | |
| 113 | set_field(base, CM_PER_OCPWP_L3_CLKSTCTRL, |
| 114 | CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL, |
| 115 | CM_PER_OCPWP_L3_CLKSTCTRL_CLKTRCTRL_SW_WKUP); |
| 116 | |
| 117 | /* wait for completion */ |
| 118 | wait_field(base, CM_PER_L3_CLKCTRL, |
| 119 | CM_PER_L3_CLKCTRL_IDLEST, |
| 120 | CM_PER_L3_CLKCTRL_IDLEST_FUNC << CM_PER_L3_CLKCTRL_IDLEST_SHIFT); |
| 121 | |
| 122 | wait_field(base, CM_PER_L3_INSTR_CLKCTRL, |
| 123 | CM_PER_L3_INSTR_CLKCTRL_IDLEST, |
| 124 | CM_PER_L3_INSTR_CLKCTRL_IDLEST_FUNC << CM_PER_L3_INSTR_CLKCTRL_IDLEST_SHIFT); |
| 125 | |
| 126 | wait_field(base, CM_PER_OCPWP_CLKCTRL, |
| 127 | CM_PER_OCPWP_CLKCTRL_IDLEST, |
| 128 | CM_PER_OCPWP_CLKCTRL_IDLEST_FUNC << CM_PER_OCPWP_CLKCTRL_IDLEST_SHIFT); |
| 129 | |
| 130 | wait_field(base, CM_PER_L3_CLKSTCTRL, |
| 131 | CM_PER_L3_CLKSTCTRL_CLKACTIVITY_L3_GCLK, |
| 132 | CM_PER_L3_CLKSTCTRL_CLKACTIVITY_L3_GCLK); |
| 133 | |
| 134 | wait_field(base, CM_PER_OCPWP_L3_CLKSTCTRL, |
| 135 | CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L3_GCLK, |
| 136 | CM_PER_OCPWP_L3_CLKSTCTRL_CLKACTIVITY_OCPWP_L3_GCLK); |
| 137 | |
| 138 | wait_field(base, CM_PER_L3S_CLKSTCTRL, |
| 139 | CM_PER_L3S_CLKSTCTRL_CLKACTIVITY_L3S_GCLK, |
| 140 | CM_PER_L3S_CLKSTCTRL_CLKACTIVITY_L3S_GCLK); |
| 141 | } |
| 142 | |
| 143 | void per_L4_config(void) |
| 144 | { |
| 145 | vaddr_t base = SOC_CM_PER_REGS; |
| 146 | |
| 147 | /* configure L4 interface clocks. */ |
| 148 | set_field(base, CM_PER_L4LS_CLKCTRL, |
| 149 | CM_PER_L4LS_CLKCTRL_MODULEMODE, |
| 150 | CM_PER_L4LS_CLKCTRL_MODULEMODE_ENABLE); |
| 151 | |
| 152 | set_field(base, CM_PER_L4LS_CLKSTCTRL, |
| 153 | CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL, |
| 154 | CM_PER_L4LS_CLKSTCTRL_CLKTRCTRL_SW_WKUP); |
| 155 | |
| 156 | wait_field(base, CM_PER_L4LS_CLKCTRL, |
| 157 | CM_PER_L4LS_CLKCTRL_IDLEST, |
| 158 | CM_PER_L4LS_CLKCTRL_IDLEST_FUNC << CM_PER_L4LS_CLKCTRL_IDLEST_SHIFT); |
| 159 | |
| 160 | wait_field(base, CM_PER_L4LS_CLKSTCTRL, |
| 161 | CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_L4LS_GCLK, |
| 162 | CM_PER_L4LS_CLKSTCTRL_CLKACTIVITY_L4LS_GCLK); |
| 163 | } |
| 164 | |
| 165 | void wkup_clk_config(void) |
| 166 | { |
| 167 | vaddr_t base = SOC_CM_WKUP_REGS; |
| 168 | |
| 169 | /* configure wkup domain */ |
| 170 | set_field(base, CM_WKUP_CONTROL_CLKCTRL, |
| 171 | CM_WKUP_CONTROL_CLKCTRL_MODULEMODE, |
| 172 | CM_WKUP_CONTROL_CLKCTRL_MODULEMODE_ENABLE); |
| 173 | |
| 174 | set_field(base, CM_WKUP_CLKSTCTRL, |
| 175 | CM_WKUP_CLKSTCTRL_CLKTRCTRL, |
| 176 | CM_WKUP_CLKSTCTRL_CLKTRCTRL_SW_WKUP); |
| 177 | |
| 178 | set_field(base, CM_WKUP_CM_L3_AON_CLKSTCTRL, |
| 179 | CM_WKUP_CM_L3_AON_CLKSTCTRL_CLKTRCTRL, |
| 180 | CM_WKUP_CM_L3_AON_CLKSTCTRL_CLKTRCTRL_SW_WKUP); |
| 181 | |
| 182 | wait_field(base, CM_WKUP_CONTROL_CLKCTRL, |
| 183 | CM_WKUP_CONTROL_CLKCTRL_IDLEST, |
| 184 | CM_WKUP_CONTROL_CLKCTRL_IDLEST_FUNC << CM_WKUP_CONTROL_CLKCTRL_IDLEST_SHIFT); |
| 185 | |
| 186 | wait_field(base, CM_WKUP_CM_L3_AON_CLKSTCTRL, |
| 187 | CM_WKUP_CM_L3_AON_CLKSTCTRL_CLKACTIVITY_L3_AON_GCLK, |
| 188 | CM_WKUP_CM_L3_AON_CLKSTCTRL_CLKACTIVITY_L3_AON_GCLK); |
| 189 | |
| 190 | wait_field(base, CM_WKUP_L4WKUP_CLKCTRL, |
| 191 | CM_WKUP_L4WKUP_CLKCTRL_IDLEST, |
| 192 | CM_WKUP_L4WKUP_CLKCTRL_IDLEST_FUNC << CM_WKUP_L4WKUP_CLKCTRL_IDLEST_SHIFT); |
| 193 | |
| 194 | wait_field(base, CM_WKUP_CLKSTCTRL, |
| 195 | CM_WKUP_CLKSTCTRL_CLKACTIVITY_L4_WKUP_GCLK, |
| 196 | CM_WKUP_CLKSTCTRL_CLKACTIVITY_L4_WKUP_GCLK); |
| 197 | |
| 198 | wait_field(base, CM_WKUP_CM_L4_WKUP_AON_CLKSTCTRL, |
| 199 | CM_WKUP_CM_L4_WKUP_AON_CLKSTCTRL_CLKACTIVITY_L4_WKUP_AON_GCLK, |
| 200 | CM_WKUP_CM_L4_WKUP_AON_CLKSTCTRL_CLKACTIVITY_L4_WKUP_AON_GCLK); |
| 201 | } |
| 202 | |
| 203 | void platform_early_init(void) |
| 204 | { |
| 205 | /* initialize the basic clocks */ |
| 206 | per_L3_config(); |
| 207 | per_L4_config(); |
| 208 | wkup_clk_config(); |
| 209 | |
| 210 | /* initialize the tx half of the debug uart */ |
| 211 | platform_init_debug(); |
| 212 | |
| 213 | /* initialize the interrupt controller */ |
| 214 | platform_init_interrupts(); |
| 215 | |
| 216 | /* initialize the timer */ |
| 217 | platform_init_timer(); |
| 218 | } |
| 219 | |
| 220 | void platform_init(void) |
| 221 | { |
| 222 | /* initialize the rest of the debug uart */ |
| 223 | uart_init(); |
| 224 | } |
| 225 | |