blob: a0aa4808d6542818a36b726cf248ab0dfdaaacc7 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
Toshiyuki Ogasahara77626582020-11-30 20:39:21 +09002 * Copyright (c) 2018-2021, Renesas Electronics Corporation. All rights reserved.
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <lib/mmio.h>
8
Toshiyuki Ogasahara77626582020-11-30 20:39:21 +09009#include "cpg_registers.h"
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020010#include "rcar_private.h"
11
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020012#if IMAGE_BL31
Biju Das9a8f0ee2020-12-13 20:17:01 +000013void __attribute__ ((section(".system_ram"))) cpg_write(uintptr_t regadr, uint32_t regval)
14#else
15void cpg_write(uintptr_t regadr, uint32_t regval)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020016#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020017{
Biju Das9a8f0ee2020-12-13 20:17:01 +000018 uint32_t value = regval;
19
Toshiyuki Ogasahara77626582020-11-30 20:39:21 +090020 mmio_write_32(CPG_CPGWPR, ~value);
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020021 mmio_write_32(regadr, value);
22}
23
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020024#if IMAGE_BL31
Biju Das9a8f0ee2020-12-13 20:17:01 +000025void __attribute__ ((section(".system_ram"))) mstpcr_write(uint32_t mstpcr, uint32_t mstpsr,
26 uint32_t target_bit)
27#else
28void mstpcr_write(uint32_t mstpcr, uint32_t mstpsr, uint32_t target_bit)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020029#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020030{
31 uint32_t reg;
Biju Das9a8f0ee2020-12-13 20:17:01 +000032
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020033 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}