liu hao | e3aafef | 2019-10-31 07:51:08 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 |
| 4 | * shuyiqi <shuyiqi@phytium.com.cn> |
| 5 | * liuhao <liuhao@phytium.com.cn> |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <command.h> |
Simon Glass | 9a3b4ce | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 11 | #include <event.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
liu hao | e3aafef | 2019-10-31 07:51:08 +0000 | [diff] [blame] | 14 | #include <asm/armv8/mmu.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
liu hao | e3aafef | 2019-10-31 07:51:08 +0000 | [diff] [blame] | 17 | #include <asm/system.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <linux/arm-smccc.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <scsi.h> |
| 22 | #include "cpu.h" |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | int dram_init(void) |
| 27 | { |
| 28 | gd->mem_clk = 0; |
| 29 | gd->ram_size = PHYS_SDRAM_1_SIZE; |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | int dram_init_banksize(void) |
| 34 | { |
| 35 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 36 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int board_init(void) |
| 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
Harald Seiler | 35b65dd | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 46 | void reset_cpu(void) |
liu hao | e3aafef | 2019-10-31 07:51:08 +0000 | [diff] [blame] | 47 | { |
| 48 | struct arm_smccc_res res; |
| 49 | |
| 50 | arm_smccc_smc(0x84000009, 0, 0, 0, 0, 0, 0, 0, &res); |
| 51 | debug("reset cpu error, %lx\n", res.a0); |
| 52 | } |
| 53 | |
| 54 | static struct mm_region durian_mem_map[] = { |
| 55 | { |
| 56 | .virt = 0x0UL, |
| 57 | .phys = 0x0UL, |
| 58 | .size = 0x80000000UL, |
| 59 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 60 | PTE_BLOCK_NON_SHARE | |
| 61 | PTE_BLOCK_PXN | |
| 62 | PTE_BLOCK_UXN |
| 63 | }, |
| 64 | { |
| 65 | .virt = (u64)PHYS_SDRAM_1, |
| 66 | .phys = (u64)PHYS_SDRAM_1, |
| 67 | .size = (u64)PHYS_SDRAM_1_SIZE, |
| 68 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 69 | PTE_BLOCK_NS | |
| 70 | PTE_BLOCK_INNER_SHARE |
| 71 | }, |
| 72 | { |
| 73 | 0, |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | struct mm_region *mem_map = durian_mem_map; |
| 78 | |
| 79 | int print_cpuinfo(void) |
| 80 | { |
| 81 | printf("CPU: Phytium ft2004 %ld MHz\n", gd->cpu_clk); |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | int __asm_flush_l3_dcache(void) |
| 86 | { |
| 87 | int i, pstate; |
| 88 | |
| 89 | for (i = 0; i < HNF_COUNT; i++) |
| 90 | writeq(HNF_PSTATE_SFONLY, HNF_PSTATE_REQ + i * HNF_STRIDE); |
| 91 | for (i = 0; i < HNF_COUNT; i++) { |
| 92 | do { |
| 93 | pstate = readq(HNF_PSTATE_STAT + i * HNF_STRIDE); |
| 94 | } while ((pstate & 0xf) != (HNF_PSTATE_SFONLY << 2)); |
| 95 | } |
| 96 | |
| 97 | for (i = 0; i < HNF_COUNT; i++) |
| 98 | writeq(HNF_PSTATE_FULL, HNF_PSTATE_REQ + i * HNF_STRIDE); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 103 | static int last_stage_init(void) |
liu hao | e3aafef | 2019-10-31 07:51:08 +0000 | [diff] [blame] | 104 | { |
| 105 | int ret; |
| 106 | |
| 107 | /* pci e */ |
| 108 | pci_init(); |
| 109 | /* scsi scan */ |
| 110 | ret = scsi_scan(true); |
| 111 | if (ret) { |
| 112 | printf("scsi scan failed\n"); |
| 113 | return CMD_RET_FAILURE; |
| 114 | } |
| 115 | return ret; |
| 116 | } |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 117 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |