rpc_driver.c 1.27 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2019, Renesas Electronics Corporation. All rights reserved.
3
4
5
6
7
8
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>
#include <string.h>
9
10
11
12

#include <common/debug.h>
#include <lib/mmio.h>

13
#include "cpg_registers.h"
14
#include "rcar_def.h"
15
#include "rcar_private.h"
16
#include "rpc_registers.h"
17
18
19

#define MSTPSR9_RPC_BIT		(0x00020000U)
#define RPC_CMNCR_MD_BIT	(0x80000000U)
20
21
22
#define RPC_PHYCNT_CAL		BIT(31)
#define RPC_PHYCNT_STRTIM_M3V1	(0x6 << 15UL)
#define RPC_PHYCNT_STRTIM	(0x7 << 15UL)
23
24
25
26
27
28
29
30
31

static void rpc_enable(void)
{
	/* Enable clock supply to RPC. */
	mstpcr_write(CPG_SMSTPCR9, CPG_MSTPSR9, MSTPSR9_RPC_BIT);
}

static void rpc_setup(void)
{
32
33
	uint32_t product, cut, reg, phy_strtim;

34
35
	if (mmio_read_32(RPC_CMNCR) & RPC_CMNCR_MD_BIT)
		mmio_clrbits_32(RPC_CMNCR, RPC_CMNCR_MD_BIT);
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

	product = mmio_read_32(RCAR_PRR) & RCAR_PRODUCT_MASK;
	cut = mmio_read_32(RCAR_PRR) & RCAR_CUT_MASK;

	if ((product ==  RCAR_PRODUCT_M3) && (cut < RCAR_CUT_VER30))
		phy_strtim = RPC_PHYCNT_STRTIM_M3V1;
	else
		phy_strtim = RPC_PHYCNT_STRTIM;

	reg = mmio_read_32(RPC_PHYCNT);
	reg &= ~RPC_PHYCNT_STRTIM;
	reg |= phy_strtim;
	mmio_write_32(RPC_PHYCNT, reg);
	reg |= RPC_PHYCNT_CAL;
	mmio_write_32(RPC_PHYCNT, reg);
51
52
53
54
55
56
57
}

void rcar_rpc_init(void)
{
	rpc_enable();
	rpc_setup();
}