| 1 |
/* |
| 2 |
* Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <stdint.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
#include <common/debug.h> |
| 11 |
#include <lib/mmio.h> |
| 12 |
|
| 13 |
#include "cpg_registers.h" |
| 14 |
#include "rcar_def.h" |
| 15 |
#include "rcar_private.h" |
| 16 |
#include "rpc_registers.h" |
| 17 |
|
| 18 |
#define MSTPSR9_RPC_BIT (0x00020000U) |
| 19 |
#define RPC_CMNCR_MD_BIT (0x80000000U) |
| 20 |
#define RPC_PHYCNT_CAL BIT(31) |
| 21 |
#define RPC_PHYCNT_STRTIM_M3V1 (0x6 << 15UL) |
| 22 |
#define RPC_PHYCNT_STRTIM (0x7 << 15UL) |
| 23 |
|
| 24 |
static void rpc_enable(void) |
| 25 |
{ |
| 26 |
/* Enable clock supply to RPC. */ |
| 27 |
mstpcr_write(CPG_SMSTPCR9, CPG_MSTPSR9, MSTPSR9_RPC_BIT); |
| 28 |
} |
| 29 |
|
| 30 |
static void rpc_setup(void) |
| 31 |
{ |
| 32 |
uint32_t product, cut, reg, phy_strtim; |
| 33 |
|
| 34 |
if (mmio_read_32(RPC_CMNCR) & RPC_CMNCR_MD_BIT) |
| 35 |
mmio_clrbits_32(RPC_CMNCR, RPC_CMNCR_MD_BIT); |
| 36 |
|
| 37 |
product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK; |
| 38 |
cut = mmio_read_32(RCAR_PRR) & PRR_CUT_MASK; |
| 39 |
|
| 40 |
if ((product == PRR_PRODUCT_M3) && (cut < PRR_PRODUCT_30)) |
| 41 |
phy_strtim = RPC_PHYCNT_STRTIM_M3V1; |
| 42 |
else |
| 43 |
phy_strtim = RPC_PHYCNT_STRTIM; |
| 44 |
|
| 45 |
reg = mmio_read_32(RPC_PHYCNT); |
| 46 |
reg &= ~RPC_PHYCNT_STRTIM; |
| 47 |
reg |= phy_strtim; |
| 48 |
mmio_write_32(RPC_PHYCNT, reg); |
| 49 |
reg |= RPC_PHYCNT_CAL; |
| 50 |
mmio_write_32(RPC_PHYCNT, reg); |
| 51 |
} |
| 52 |
|
| 53 |
void rcar_rpc_init(void) |
| 54 |
{ |
| 55 |
rpc_enable(); |
| 56 |
rpc_setup(); |
| 57 |
} |