dram.c 2.4 KB
Newer Older
1
2
3
/*
 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
#include <dram_regs.h>
8
#include <m0_param.h>
9
10
11
#include <pmu_bits.h>
#include <pmu_regs.h>
#include "misc_regs.h"
12
13
#include "rk3399_mcu.h"

14
static uint32_t gatedis_con0;
15

16
17
static void idle_port(void)
{
18
19
20
	gatedis_con0 = mmio_read_32(PMUCRU_BASE + PMU_CRU_GATEDIS_CON0);
	mmio_write_32(PMUCRU_BASE + PMU_CRU_GATEDIS_CON0, 0x3fffffff);

21
	mmio_setbits_32(PMU_BASE + PMU_BUS_IDLE_REQ,
22
			(1 << PMU_IDLE_REQ_MSCH0) | (1 << PMU_IDLE_REQ_MSCH1));
23
	while ((mmio_read_32(PMU_BASE + PMU_BUS_IDLE_ST) &
24
25
		((1 << PMU_IDLE_ST_MSCH1) | (1 << PMU_IDLE_ST_MSCH0))) !=
		((1 << PMU_IDLE_ST_MSCH1) | (1 << PMU_IDLE_ST_MSCH0)))
26
27
28
29
30
31
		continue;
}

static void deidle_port(void)
{
	mmio_clrbits_32(PMU_BASE + PMU_BUS_IDLE_REQ,
32
			(1 << PMU_IDLE_REQ_MSCH0) | (1 << PMU_IDLE_REQ_MSCH1));
33
	while (mmio_read_32(PMU_BASE + PMU_BUS_IDLE_ST) &
34
	       ((1 << PMU_IDLE_ST_MSCH1) | (1 << PMU_IDLE_ST_MSCH0)))
35
		continue;
36
37

	/* document is wrong, PMU_CRU_GATEDIS_CON0 do not need set MASK BIT */
38
	mmio_write_32(PMUCRU_BASE + PMU_CRU_GATEDIS_CON0, gatedis_con0);
39
40
41
42
}

static void ddr_set_pll(void)
{
43
	mmio_write_32(CRU_BASE + CRU_DPLL_CON3, PLL_MODE(PLL_SLOW_MODE));
44

45
46
	mmio_write_32(CRU_BASE + CRU_DPLL_CON3, PLL_POWER_DOWN(1));
	mmio_write_32(CRU_BASE + CRU_DPLL_CON0,
47
		      mmio_read_32(PARAM_ADDR + PARAM_DPLL_CON0));
48
	mmio_write_32(CRU_BASE + CRU_DPLL_CON1,
49
		      mmio_read_32(PARAM_ADDR + PARAM_DPLL_CON1));
50
	mmio_write_32(CRU_BASE + CRU_DPLL_CON3, PLL_POWER_DOWN(0));
51

52
	while ((mmio_read_32(CRU_BASE + CRU_DPLL_CON2) & (1u << 31)) == 0)
53
54
		continue;

55
	mmio_write_32(CRU_BASE + CRU_DPLL_CON3, PLL_MODE(PLL_NORMAL_MODE));
56
57
}

58
__attribute__((noreturn)) void m0_main(void)
59
{
60
61
	mmio_setbits_32(PHY_REG(0, 927), (1 << 22));
	mmio_setbits_32(PHY_REG(1, 927), (1 << 22));
62
63
	idle_port();

64
	mmio_write_32(CIC_BASE + CIC_CTRL0,
65
66
67
		      (((0x3 << 4) | (1 << 2) | 1) << 16) |
		      (1 << 2) | 1 |
		      mmio_read_32(PARAM_ADDR + PARAM_FREQ_SELECT));
68
	while ((mmio_read_32(CIC_BASE + CIC_STATUS0) & (1 << 2)) == 0)
69
70
71
		continue;

	ddr_set_pll();
72
73
	mmio_write_32(CIC_BASE + CIC_CTRL0, 0x20002);
	while ((mmio_read_32(CIC_BASE + CIC_STATUS0) & (1 << 0)) == 0)
74
75
76
		continue;

	deidle_port();
77
78
	mmio_clrbits_32(PHY_REG(0, 927), (1 << 22));
	mmio_clrbits_32(PHY_REG(1, 927), (1 << 22));
79
80
81
82
83

	mmio_write_32(PARAM_ADDR + PARAM_M0_DONE, M0_DONE_FLAG);

	for (;;)
		__asm__ volatile ("wfi");
84
}