blob: 9b7c1eb16c148f1396c8bb7438bada69918b93f2 [file] [log] [blame]
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02001/*
Biju Das9a8f0ee2020-12-13 20:17:01 +00002 * Copyright (c) 2018-2020, 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
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +02009#include "rcar_private.h"
10
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020011#if IMAGE_BL31
Biju Das9a8f0ee2020-12-13 20:17:01 +000012void __attribute__ ((section(".system_ram"))) cpg_write(uintptr_t regadr, uint32_t regval)
13#else
14void cpg_write(uintptr_t regadr, uint32_t regval)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020015#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020016{
Biju Das9a8f0ee2020-12-13 20:17:01 +000017 uint32_t value = regval;
18
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020019 mmio_write_32((uintptr_t) RCAR_CPGWPR, ~value);
20 mmio_write_32(regadr, value);
21}
22
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020023#if IMAGE_BL31
Biju Das9a8f0ee2020-12-13 20:17:01 +000024void __attribute__ ((section(".system_ram"))) mstpcr_write(uint32_t mstpcr, uint32_t mstpsr,
25 uint32_t target_bit)
26#else
27void mstpcr_write(uint32_t mstpcr, uint32_t mstpsr, uint32_t target_bit)
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020028#endif
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020029{
30 uint32_t reg;
Biju Das9a8f0ee2020-12-13 20:17:01 +000031
Jorge Ramirez-Ortizbf084dc2018-09-23 09:36:13 +020032 reg = mmio_read_32(mstpcr);
33 reg &= ~target_bit;
34 cpg_write(mstpcr, reg);
35 while ((mmio_read_32(mstpsr) & target_bit) != 0U) {
36 }
37}