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