blob: 9bad424fb72de22292566f1f508dbce1560c18a6 [file] [log] [blame]
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +02001/*
2 * Copyright (c) 2017-2018, Renesas Electronics Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef QOS_COMMON_H
8#define QOS_COMMON_H
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +02009
10#define RCAR_REF_DEFAULT (0U)
11
Marek Vasut48cc6932018-12-12 16:35:00 +010012/* define used for get_refperiod. */
13/* REFPERIOD_CYCLE need smaller than QOSWT_WTSET0_CYCLEs */
14/* refere to plat/renesas/rcar/ddr/ddr_a/ddr_init_e3.h for E3. */
15#if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF default */
16#define REFPERIOD_CYCLE ((126 * BASE_SUB_SLOT_NUM * 1000U)/400) /* unit:ns */
17#else /* REF option */
18#define REFPERIOD_CYCLE ((252 * BASE_SUB_SLOT_NUM * 1000U)/400) /* unit:ns */
19#endif
20
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020021#if (RCAR_LSI == RCAR_E3)
22/* define used for E3 */
23#if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 3.9usec */
24#define SUB_SLOT_CYCLE_E3 (0xAFU) /* 175 */
25#else /* REF 7.8usec */
26#define SUB_SLOT_CYCLE_E3 (0x15EU) /* 350 */
27#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
28
29#define OPERATING_FREQ_E3 (266U) /* MHz */
30#define SL_INIT_SSLOTCLK_E3 (SUB_SLOT_CYCLE_E3 -1U)
Marek Vasut48cc6932018-12-12 16:35:00 +010031/* #define QOSWT_WTSET0_CYCLE_E3 ((SUB_SLOT_CYCLE_E3 * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ_E3) */ /* unit:ns */
Jorge Ramirez-Ortiz47503d22018-09-23 09:36:52 +020032#endif
33
34#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N)
35/* define used for M3N */
36#if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
37#define SUB_SLOT_CYCLE_M3N (0x84U) /* 132 */
38#else /* REF 3.9usec */
39#define SUB_SLOT_CYCLE_M3N (0x108U) /* 264 */
40#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
41
42#define SL_INIT_SSLOTCLK_M3N (SUB_SLOT_CYCLE_M3N -1U)
43#define QOSWT_WTSET0_CYCLE_M3N ((SUB_SLOT_CYCLE_M3N * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ) /* unit:ns */
44#endif
45
46#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3)
47/* define used for H3 */
48#if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
49#define SUB_SLOT_CYCLE_H3_20 (0x84U) /* 132 */
50#else /* REF 3.9usec */
51#define SUB_SLOT_CYCLE_H3_20 (0x108U) /* 264 */
52#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
53
54#define SL_INIT_SSLOTCLK_H3_20 (SUB_SLOT_CYCLE_H3_20 -1U)
55#define QOSWT_WTSET0_CYCLE_H3_20 ((SUB_SLOT_CYCLE_H3_20 * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ) /* unit:ns */
56
57/* define used for H3 Cut 30 */
58#define SUB_SLOT_CYCLE_H3_30 (SUB_SLOT_CYCLE_H3_20) /* same as H3 Cut 20 */
59#define SL_INIT_SSLOTCLK_H3_30 (SUB_SLOT_CYCLE_H3_30 -1U)
60#define QOSWT_WTSET0_CYCLE_H3_30 ((SUB_SLOT_CYCLE_H3_30 * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ) /* unit:ns */
61
62#endif
63
64#if (RCAR_LSI == RCAR_H3N)
65/* define used for H3N */
66#if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
67#define SUB_SLOT_CYCLE_H3N (0x84U) /* 132 */
68#else /* REF 3.9usec */
69#define SUB_SLOT_CYCLE_H3N (0x108U) /* 264 */
70#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
71
72#define SL_INIT_SSLOTCLK_H3N (SUB_SLOT_CYCLE_H3N -1U)
73#define QOSWT_WTSET0_CYCLE_H3N ((SUB_SLOT_CYCLE_H3N * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ) /* unit:ns */
74
75#endif
76
77#if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3)
78/* define used for M3 */
79#if (RCAR_REF_INT == RCAR_REF_DEFAULT) /* REF 1.95usec */
80#define SUB_SLOT_CYCLE_M3_11 (0x84U) /* 132 */
81#else /* REF 3.9usec */
82#define SUB_SLOT_CYCLE_M3_11 (0x108U) /* 264 */
83#endif /* (RCAR_REF_INT == RCAR_REF_DEFAULT) */
84
85#define SL_INIT_SSLOTCLK_M3_11 (SUB_SLOT_CYCLE_M3_11 -1U)
86#define QOSWT_WTSET0_CYCLE_M3_11 ((SUB_SLOT_CYCLE_M3_11 * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ) /* unit:ns */
87#endif
88
89#define OPERATING_FREQ (400U) /* MHz */
90#define BASE_SUB_SLOT_NUM (0x6U)
91#define SUB_SLOT_CYCLE (0x7EU) /* 126 */
92
93#define QOSWT_WTSET0_CYCLE ((SUB_SLOT_CYCLE * BASE_SUB_SLOT_NUM * 1000U)/OPERATING_FREQ) /* unit:ns */
94
95#define SL_INIT_REFFSSLOT (0x3U << 24U)
96#define SL_INIT_SLOTSSLOT ((BASE_SUB_SLOT_NUM - 1U) << 16U)
97#define SL_INIT_SSLOTCLK (SUB_SLOT_CYCLE -1U)
98
99static inline void io_write_32(uintptr_t addr, uint32_t value)
100{
101 *(volatile uint32_t *)addr = value;
102}
103
104static inline uint32_t io_read_32(uintptr_t addr)
105{
106 return *(volatile uint32_t *)addr;
107}
108
109static inline void io_write_64(uintptr_t addr, uint64_t value)
110{
111 *(volatile uint64_t *)addr = value;
112}
113
114typedef struct {
115 uintptr_t addr;
116 uint64_t value;
117} mstat_slot_t;
118
119extern uint32_t qos_init_ddr_ch;
120extern uint8_t qos_init_ddr_phyvalid;
121
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000122#endif /* QOS_COMMON_H */