Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2020 - Cortina Access Inc. |
| 4 | * |
| 5 | */ |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 6 | #include <config.h> |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 7 | #include <event.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 9 | #include <malloc.h> |
| 10 | #include <errno.h> |
| 11 | #include <netdev.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 13 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 15 | #include <linux/compiler.h> |
| 16 | #include <configs/presidio_asic.h> |
| 17 | #include <linux/psci.h> |
| 18 | #include <asm/psci.h> |
| 19 | #include <cpu_func.h> |
| 20 | #include <asm/armv8/mmu.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | #define CA_PERIPH_BASE 0xE0000000UL |
| 25 | #define CA_PERIPH_SIZE 0x20000000UL |
| 26 | #define CA_GLOBAL_BASE 0xf4320000 |
| 27 | #define CA_GLOBAL_JTAG_ID 0xf4320000 |
| 28 | #define CA_GLOBAL_BLOCK_RESET 0xf4320004 |
| 29 | #define CA_GLOBAL_BLOCK_RESET_RESET_DMA BIT(16) |
| 30 | #define CA_DMA_SEC_SSP_BAUDRATE_CTRL 0xf7001b94 |
| 31 | #define CA_DMA_SEC_SSP_ID 0xf7001b80 |
| 32 | |
| 33 | int print_cpuinfo(void) |
| 34 | { |
| 35 | printf("CPU: Cortina Presidio G3\n"); |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | static struct mm_region presidio_mem_map[] = { |
| 40 | { |
| 41 | .virt = DDR_BASE, |
| 42 | .phys = DDR_BASE, |
| 43 | .size = PHYS_SDRAM_1_SIZE, |
| 44 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 45 | PTE_BLOCK_OUTER_SHARE |
| 46 | }, |
| 47 | { |
| 48 | .virt = CA_PERIPH_BASE, |
| 49 | .phys = CA_PERIPH_BASE, |
| 50 | .size = CA_PERIPH_SIZE, |
| 51 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 52 | PTE_BLOCK_NON_SHARE |
| 53 | }, |
| 54 | { |
| 55 | /* List terminator */ |
| 56 | 0, |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | struct mm_region *mem_map = presidio_mem_map; |
| 61 | |
| 62 | static noinline int invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1, |
| 63 | u64 arg2) |
| 64 | { |
| 65 | asm volatile("mov x0, %0\n" |
| 66 | "mov x1, %1\n" |
| 67 | "mov x2, %2\n" |
| 68 | "mov x3, %3\n" |
| 69 | "smc #0\n" |
| 70 | : "+r" (function_id) |
| 71 | : "r" (arg0), "r" (arg1), "r" (arg2) |
| 72 | ); |
| 73 | |
| 74 | return function_id; |
| 75 | } |
| 76 | |
| 77 | int board_early_init_r(void) |
| 78 | { |
| 79 | dcache_disable(); |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | int board_init(void) |
| 84 | { |
| 85 | unsigned int reg_data, jtag_id; |
| 86 | |
| 87 | /* Enable timer */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 88 | writel(1, CFG_SYS_TIMER_BASE); |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 89 | |
| 90 | /* Enable snoop in CCI400 slave port#4 */ |
| 91 | writel(3, 0xF5595000); |
| 92 | |
| 93 | jtag_id = readl(CA_GLOBAL_JTAG_ID); |
| 94 | |
| 95 | /* If this is HGU variant then do not use |
| 96 | * the Saturn daughter card ref. clk |
| 97 | */ |
| 98 | if (jtag_id == 0x1010D8F3) { |
| 99 | reg_data = readl(0xF3100064); |
| 100 | /* change multifunc. REF CLK pin to |
| 101 | * a simple GPIO pin |
| 102 | */ |
| 103 | reg_data |= (1 << 1); |
| 104 | writel(reg_data, 0xf3100064); |
| 105 | } |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int dram_init(void) |
| 111 | { |
| 112 | unsigned int ddr_size; |
| 113 | |
| 114 | ddr_size = readl(0x111100c); |
| 115 | gd->ram_size = ddr_size * 0x100000; |
| 116 | return 0; |
| 117 | } |
| 118 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 119 | void reset_cpu(void) |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 120 | { |
| 121 | invoke_psci_fn_smc(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); |
| 122 | } |
| 123 | |
| 124 | #ifdef CONFIG_LAST_STAGE_INIT |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 125 | static int last_stage_init(void) |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 126 | { |
| 127 | u32 val; |
| 128 | |
| 129 | val = readl(CA_GLOBAL_BLOCK_RESET); |
| 130 | val &= ~CA_GLOBAL_BLOCK_RESET_RESET_DMA; |
| 131 | writel(val, CA_GLOBAL_BLOCK_RESET); |
| 132 | |
| 133 | /* reduce output pclk ~3.7Hz to save power consumption */ |
| 134 | writel(0x000000FF, CA_DMA_SEC_SSP_BAUDRATE_CTRL); |
| 135 | |
| 136 | return 0; |
| 137 | } |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 138 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |
Alex Nemirovsky | 1ecad07 | 2020-01-30 12:34:59 -0800 | [diff] [blame] | 139 | #endif |