Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 2 | * Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
6 | |||||
Antonio Nino Diaz | f13d09a | 2019-01-23 21:50:09 +0000 | [diff] [blame] | 7 | #include <drivers/arm/fvp/fvp_pwrc.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <lib/bakery_lock.h> |
9 | #include <lib/mmio.h> | ||||
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 10 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | a320ecd | 2019-01-15 14:19:50 +0000 | [diff] [blame] | 11 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 13 | #define FVP_PWRC_ID_MASK U(0x00FFFFFF) |
14 | |||||
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 15 | /* |
16 | * TODO: Someday there will be a generic power controller api. At the moment | ||||
17 | * each platform has its own pwrc so just exporting functions is fine. | ||||
18 | */ | ||||
Jeenu Viswambharan | 749d25b | 2017-08-23 14:12:59 +0100 | [diff] [blame] | 19 | ARM_INSTANTIATE_LOCK; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 20 | |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 21 | /* |
22 | * Core ID field is 24 bits wide and extracted from MPIDR. | ||||
23 | * Bits[23:16] represent Affinity Level 2 | ||||
24 | * Bits[15:8] represent Affinity Level 1 | ||||
25 | * Bits[7:0] represent Affinity Level 0 | ||||
26 | */ | ||||
27 | static unsigned int fvp_pwrc_core_id(u_register_t mpidr) | ||||
28 | { | ||||
29 | return (unsigned int)(mpidr & FVP_PWRC_ID_MASK); | ||||
30 | } | ||||
31 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 32 | unsigned int fvp_pwrc_get_cpu_wkr(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 33 | { |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 34 | unsigned int id = fvp_pwrc_core_id(mpidr); |
35 | |||||
36 | return PSYSR_WK(fvp_pwrc_read_psysr(id)); | ||||
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 37 | } |
38 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 39 | unsigned int fvp_pwrc_read_psysr(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 40 | { |
Andrew Thoelke | 958cc02 | 2014-06-09 12:54:15 +0100 | [diff] [blame] | 41 | unsigned int rc; |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 42 | unsigned int id = fvp_pwrc_core_id(mpidr); |
43 | |||||
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 44 | arm_lock_get(); |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 45 | mmio_write_32(PWRC_BASE + PSYSR_OFF, id); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 46 | rc = mmio_read_32(PWRC_BASE + PSYSR_OFF); |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 47 | arm_lock_release(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 48 | return rc; |
49 | } | ||||
50 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 51 | void fvp_pwrc_write_pponr(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 52 | { |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 53 | unsigned int id = fvp_pwrc_core_id(mpidr); |
54 | |||||
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 55 | arm_lock_get(); |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 56 | mmio_write_32(PWRC_BASE + PPONR_OFF, id); |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 57 | arm_lock_release(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 58 | } |
59 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 60 | void fvp_pwrc_write_ppoffr(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 61 | { |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 62 | unsigned int id = fvp_pwrc_core_id(mpidr); |
63 | |||||
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 64 | arm_lock_get(); |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 65 | mmio_write_32(PWRC_BASE + PPOFFR_OFF, id); |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 66 | arm_lock_release(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 67 | } |
68 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 69 | void fvp_pwrc_set_wen(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 70 | { |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 71 | unsigned int id = fvp_pwrc_core_id(mpidr); |
72 | |||||
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 73 | arm_lock_get(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 74 | mmio_write_32(PWRC_BASE + PWKUPR_OFF, |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 75 | (unsigned int) (PWKUPR_WEN | id)); |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 76 | arm_lock_release(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 77 | } |
78 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 79 | void fvp_pwrc_clr_wen(u_register_t mpidr) |
Achin Gupta | b127cdb | 2013-11-12 16:40:00 +0000 | [diff] [blame] | 80 | { |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 81 | unsigned int id = fvp_pwrc_core_id(mpidr); |
82 | |||||
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 83 | arm_lock_get(); |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 84 | mmio_write_32(PWRC_BASE + PWKUPR_OFF, id); |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 85 | arm_lock_release(); |
Achin Gupta | b127cdb | 2013-11-12 16:40:00 +0000 | [diff] [blame] | 86 | } |
87 | |||||
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 88 | void fvp_pwrc_write_pcoffr(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 89 | { |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 90 | unsigned int id = fvp_pwrc_core_id(mpidr); |
91 | |||||
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 92 | arm_lock_get(); |
Madhukar Pappireddy | 15926e7 | 2023-07-31 23:22:02 -0500 | [diff] [blame] | 93 | mmio_write_32(PWRC_BASE + PCOFFR_OFF, id); |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 94 | arm_lock_release(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 95 | } |
96 | |||||
97 | /* Nothing else to do here apart from initializing the lock */ | ||||
Daniel Boulby | f45a4bb | 2018-09-18 13:26:03 +0100 | [diff] [blame] | 98 | void __init plat_arm_pwrc_setup(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 99 | { |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 100 | arm_lock_init(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 101 | } |
102 | |||||
103 | |||||
104 |