aboutsummaryrefslogtreecommitdiff
path: root/plat/mediatek/mt8183/plat_dcm.c
blob: 8ee77f10803764ca9ba2da2c4a9f4919225e3de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright (c) 2019, MediaTek Inc. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <lib/bakery_lock.h>
#include <drivers/console.h>
#include <common/debug.h>
#include <lib/mmio.h>
#include <plat_dcm.h>
#include <plat_private.h>
#include <plat_dcm.h>
#include <plat/common/platform.h>
#include <platform_def.h>
#include <mtk_plat_common.h>

#define PWR_STATUS                     (SPM_BASE + 0x180)

uint64_t plat_dcm_mcsi_a_addr;
uint32_t plat_dcm_mcsi_a_val;
static int plat_dcm_init_type;
static unsigned int dcm_big_core_cnt;
int plat_dcm_initiated;

#define PWR_STA_BIG_MP_MASK	(0x1 << 15)

DEFINE_BAKERY_LOCK(dcm_lock);

void dcm_lock_init(void)
{
	bakery_lock_init(&dcm_lock);
}

void dcm_lock_get(void)
{
	bakery_lock_get(&dcm_lock);
}

void dcm_lock_release(void)
{
	bakery_lock_release(&dcm_lock);
}

void plat_dcm_mcsi_a_backup(void)
{
}

void plat_dcm_mcsi_a_restore(void)
{
}

void plat_dcm_rgu_enable(void)
{
}

void plat_dcm_big_core_sync(short on)
{
	/* Check if Big cluster power is existed */
	if (!(mmio_read_32(PWR_STATUS) & PWR_STA_BIG_MP_MASK))
		return;

	if (on) {
		mmio_write_32(MP2_SYNC_DCM,
			      (mmio_read_32(MP2_SYNC_DCM) & ~MP2_SYNC_DCM_MASK)
			      | MP2_SYNC_DCM_ON);
		dcm_big_core_cnt++;
	} else
		mmio_write_32(MP2_SYNC_DCM,
			      (mmio_read_32(MP2_SYNC_DCM) & ~MP2_SYNC_DCM_MASK)
			      | MP2_SYNC_DCM_OFF);
}

void plat_dcm_restore_cluster_on(unsigned long mpidr)
{
	unsigned long cluster_id =
		(mpidr & MPIDR_CLUSTER_MASK) >> MPIDR_AFFINITY_BITS;

	switch (cluster_id) {
	case 0x1:
		dcm_lock_get();
		if (plat_dcm_init_type & BIG_CORE_DCM_TYPE)
			plat_dcm_big_core_sync(1);
		else
			plat_dcm_big_core_sync(0);
		dcm_lock_release();
		break;
	default:
		break;
	}
}

void plat_dcm_msg_handler(uint64_t x1)
{
	plat_dcm_init_type = x1 & ALL_DCM_TYPE;
}

unsigned long plat_dcm_get_enabled_cnt(uint64_t type)
{
	switch (type) {
	case BIG_CORE_DCM_TYPE:
		return dcm_big_core_cnt;
	default:
		return 0;
	}
}

void plat_dcm_init(void)
{
	dcm_lock_init();
}