Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 1 | /* |
Toshiyuki Ogasahara | 7762658 | 2020-11-30 20:39:21 +0900 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, Renesas Electronics Corporation. All rights reserved. |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <lib/mmio.h> |
| 8 | |
Toshiyuki Ogasahara | 7762658 | 2020-11-30 20:39:21 +0900 | [diff] [blame] | 9 | #include "cpg_registers.h" |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 10 | #include "rcar_private.h" |
| 11 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 12 | #if IMAGE_BL31 |
Biju Das | 9a8f0ee | 2020-12-13 20:17:01 +0000 | [diff] [blame] | 13 | void __attribute__ ((section(".system_ram"))) cpg_write(uintptr_t regadr, uint32_t regval) |
| 14 | #else |
| 15 | void cpg_write(uintptr_t regadr, uint32_t regval) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 16 | #endif |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 17 | { |
Biju Das | 9a8f0ee | 2020-12-13 20:17:01 +0000 | [diff] [blame] | 18 | uint32_t value = regval; |
| 19 | |
Toshiyuki Ogasahara | 7762658 | 2020-11-30 20:39:21 +0900 | [diff] [blame] | 20 | mmio_write_32(CPG_CPGWPR, ~value); |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 21 | mmio_write_32(regadr, value); |
| 22 | } |
| 23 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 24 | #if IMAGE_BL31 |
Biju Das | 9a8f0ee | 2020-12-13 20:17:01 +0000 | [diff] [blame] | 25 | void __attribute__ ((section(".system_ram"))) mstpcr_write(uint32_t mstpcr, uint32_t mstpsr, |
| 26 | uint32_t target_bit) |
| 27 | #else |
| 28 | void mstpcr_write(uint32_t mstpcr, uint32_t mstpsr, uint32_t target_bit) |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 29 | #endif |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 30 | { |
| 31 | uint32_t reg; |
Biju Das | 9a8f0ee | 2020-12-13 20:17:01 +0000 | [diff] [blame] | 32 | |
Jorge Ramirez-Ortiz | bf084dc | 2018-09-23 09:36:13 +0200 | [diff] [blame] | 33 | reg = mmio_read_32(mstpcr); |
| 34 | reg &= ~target_bit; |
| 35 | cpg_write(mstpcr, reg); |
| 36 | while ((mmio_read_32(mstpsr) & target_bit) != 0U) { |
| 37 | } |
| 38 | } |