qos_common.h 4.4 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2019, Renesas Electronics Corporation. All rights reserved.
3
4
5
6
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

7
8
#ifndef QOS_COMMON_H
#define QOS_COMMON_H
9

10
#define RCAR_REF_DEFAULT		0U
11

12
13
14
15
/* define used for get_refperiod. */
/* REFPERIOD_CYCLE need smaller than QOSWT_WTSET0_CYCLEs */
/* refere to plat/renesas/rcar/ddr/ddr_a/ddr_init_e3.h for E3. */
#if (RCAR_REF_INT == RCAR_REF_DEFAULT)	/* REF default */
16
17
#define REFPERIOD_CYCLE		/* unit:ns */	\
	((126 * BASE_SUB_SLOT_NUM * 1000U) / 400)
18
#else					/* REF option */
19
20
#define REFPERIOD_CYCLE		/* unit:ns */	\
	((252 * BASE_SUB_SLOT_NUM * 1000U) / 400)
21
22
#endif

23
24
25
#if (RCAR_LSI == RCAR_E3)
/* define used for E3 */
#if (RCAR_REF_INT == RCAR_REF_DEFAULT)	/* REF 3.9usec */
26
#define SUB_SLOT_CYCLE_E3		0xAFU	/* 175 */
27
#else /* REF 7.8usec */
28
#define SUB_SLOT_CYCLE_E3		0x15EU	/* 350 */
29
30
#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */

31
32
#define OPERATING_FREQ_E3		266U	/* MHz */
#define SL_INIT_SSLOTCLK_E3		(SUB_SLOT_CYCLE_E3 - 1U)
33
34
35
36
37
#endif

#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N)
/* define used for M3N */
#if (RCAR_REF_INT == RCAR_REF_DEFAULT)	/* REF 1.95usec */
38
#define SUB_SLOT_CYCLE_M3N		0x7EU	/* 126 */
39
#else /* REF 3.9usec */
40
#define SUB_SLOT_CYCLE_M3N		0xFCU	/* 252 */
41
42
#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */

43
44
45
#define SL_INIT_SSLOTCLK_M3N		(SUB_SLOT_CYCLE_M3N - 1U)
#define QOSWT_WTSET0_CYCLE_M3N		/* unit:ns */	\
	((SUB_SLOT_CYCLE_M3N * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
46
47
48
49
50
#endif

#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3)
/* define used for H3 */
#if (RCAR_REF_INT == RCAR_REF_DEFAULT)	/* REF 1.95usec */
51
#define SUB_SLOT_CYCLE_H3_20		0x7EU	/* 126 */
52
#else /* REF 3.9usec */
53
#define SUB_SLOT_CYCLE_H3_20		0xFCU	/* 252 */
54
55
#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */

56
57
58
#define SL_INIT_SSLOTCLK_H3_20		(SUB_SLOT_CYCLE_H3_20 - 1U)
#define QOSWT_WTSET0_CYCLE_H3_20	/* unit:ns */	\
	((SUB_SLOT_CYCLE_H3_20 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
59
60
61

/* define used for H3 Cut 30 */
#define SUB_SLOT_CYCLE_H3_30		(SUB_SLOT_CYCLE_H3_20)	/* same as H3 Cut 20 */
62
63
64
#define SL_INIT_SSLOTCLK_H3_30		(SUB_SLOT_CYCLE_H3_30 - 1U)
#define QOSWT_WTSET0_CYCLE_H3_30	/* unit:ns */	\
	((SUB_SLOT_CYCLE_H3_30 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
65
66
67
68
69
70

#endif

#if (RCAR_LSI == RCAR_H3N)
/* define used for H3N */
#if (RCAR_REF_INT == RCAR_REF_DEFAULT)	/* REF 1.95usec */
71
#define SUB_SLOT_CYCLE_H3N		0x7EU	/* 126 */
72
#else /* REF 3.9usec */
73
#define SUB_SLOT_CYCLE_H3N		0xFCU	/* 252 */
74
75
#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */

76
77
78
#define SL_INIT_SSLOTCLK_H3N		(SUB_SLOT_CYCLE_H3N - 1U)
#define QOSWT_WTSET0_CYCLE_H3N		/* unit:ns */	\
	((SUB_SLOT_CYCLE_H3N * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
79
80
81
82
83
84

#endif

#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3)
/* define used for M3 */
#if (RCAR_REF_INT == RCAR_REF_DEFAULT)	/* REF 1.95usec */
85
86
#define SUB_SLOT_CYCLE_M3_11		0x7EU	/* 126 */
#define SUB_SLOT_CYCLE_M3_30		0x7EU	/* 126 */
87
#else /* REF 3.9usec */
88
89
#define SUB_SLOT_CYCLE_M3_11		0xFCU	/* 252 */
#define SUB_SLOT_CYCLE_M3_30		0xFCU	/* 252 */
90
91
#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */

92
93
94
95
96
97
#define SL_INIT_SSLOTCLK_M3_11		(SUB_SLOT_CYCLE_M3_11 - 1U)
#define SL_INIT_SSLOTCLK_M3_30		(SUB_SLOT_CYCLE_M3_30 - 1U)
#define QOSWT_WTSET0_CYCLE_M3_11	/* unit:ns */	\
	((SUB_SLOT_CYCLE_M3_11 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
#define QOSWT_WTSET0_CYCLE_M3_30	/* unit:ns */	\
	((SUB_SLOT_CYCLE_M3_30 * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
98
99
#endif

100
101
102
#define OPERATING_FREQ			400U	/* MHz */
#define BASE_SUB_SLOT_NUM		0x6U
#define SUB_SLOT_CYCLE			0x7EU	/* 126 */
103

104
105
#define QOSWT_WTSET0_CYCLE		/* unit:ns */	\
	((SUB_SLOT_CYCLE * BASE_SUB_SLOT_NUM * 1000U) / OPERATING_FREQ)
106
107
108

#define SL_INIT_REFFSSLOT		(0x3U << 24U)
#define SL_INIT_SLOTSSLOT		((BASE_SUB_SLOT_NUM - 1U) << 16U)
109
#define SL_INIT_SSLOTCLK		(SUB_SLOT_CYCLE - 1U)
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

static inline void io_write_32(uintptr_t addr, uint32_t value)
{
	*(volatile uint32_t *)addr = value;
}

static inline uint32_t io_read_32(uintptr_t addr)
{
	return *(volatile uint32_t *)addr;
}

static inline void io_write_64(uintptr_t addr, uint64_t value)
{
	*(volatile uint64_t *)addr = value;
}

typedef struct {
	uintptr_t addr;
	uint64_t value;
} mstat_slot_t;

131
132
133
134
135
struct rcar_gen3_dbsc_qos_settings {
	uint32_t	reg;
	uint32_t	val;
};

136
137
138
extern uint32_t qos_init_ddr_ch;
extern uint8_t qos_init_ddr_phyvalid;

139
140
141
void rcar_qos_dbsc_setting(struct rcar_gen3_dbsc_qos_settings *qos,
			   unsigned int qos_size, bool dbsc_wren);

142
#endif /* QOS_COMMON_H */