Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 |
| 4 | * Gabriel Huau <contact@huau-gabriel.fr> |
| 5 | * |
| 6 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 970b61e | 2019-11-14 12:57:09 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 11 | #include <asm/io.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 12 | #include <linux/errno.h> |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/arch/imx-regs.h> |
| 15 | |
| 16 | #define MAX_CPUS 4 |
| 17 | static struct src *src = (struct src *)SRC_BASE_ADDR; |
| 18 | |
| 19 | static uint32_t cpu_reset_mask[MAX_CPUS] = { |
| 20 | 0, /* We don't really want to modify the cpu0 */ |
| 21 | SRC_SCR_CORE_1_RESET_MASK, |
| 22 | SRC_SCR_CORE_2_RESET_MASK, |
| 23 | SRC_SCR_CORE_3_RESET_MASK |
| 24 | }; |
| 25 | |
| 26 | static uint32_t cpu_ctrl_mask[MAX_CPUS] = { |
| 27 | 0, /* We don't really want to modify the cpu0 */ |
| 28 | SRC_SCR_CORE_1_ENABLE_MASK, |
| 29 | SRC_SCR_CORE_2_ENABLE_MASK, |
| 30 | SRC_SCR_CORE_3_ENABLE_MASK |
| 31 | }; |
| 32 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 33 | int cpu_reset(u32 nr) |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 34 | { |
| 35 | /* Software reset of the CPU N */ |
| 36 | src->scr |= cpu_reset_mask[nr]; |
| 37 | return 0; |
| 38 | } |
| 39 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 40 | int cpu_status(u32 nr) |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 41 | { |
| 42 | printf("core %d => %d\n", nr, !!(src->scr & cpu_ctrl_mask[nr])); |
| 43 | return 0; |
| 44 | } |
| 45 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 46 | int cpu_release(u32 nr, int argc, char *const argv[]) |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 47 | { |
| 48 | uint32_t boot_addr; |
| 49 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 50 | boot_addr = hextoul(argv[0], NULL); |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 51 | |
| 52 | switch (nr) { |
| 53 | case 1: |
| 54 | src->gpr3 = boot_addr; |
| 55 | break; |
| 56 | case 2: |
| 57 | src->gpr5 = boot_addr; |
| 58 | break; |
| 59 | case 3: |
| 60 | src->gpr7 = boot_addr; |
| 61 | break; |
| 62 | default: |
| 63 | return 1; |
| 64 | } |
| 65 | |
| 66 | /* CPU N is ready to start */ |
| 67 | src->scr |= cpu_ctrl_mask[nr]; |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | int is_core_valid(unsigned int core) |
| 73 | { |
| 74 | uint32_t nr_cores = get_nr_cpus(); |
| 75 | |
| 76 | if (core > nr_cores) |
| 77 | return 0; |
| 78 | |
| 79 | return 1; |
| 80 | } |
| 81 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 82 | int cpu_disable(u32 nr) |
Gabriel Huau | 170ceaf | 2014-07-26 11:35:43 -0700 | [diff] [blame] | 83 | { |
| 84 | /* Disable the CPU N */ |
| 85 | src->scr &= ~cpu_ctrl_mask[nr]; |
| 86 | return 0; |
| 87 | } |