1 /* SPDX-License-Identifier: GPL-2.0 */
3 * RZ/G2L Clock Pulse Generator
5 * Copyright (C) 2021 Renesas Electronics Corp.
9 #ifndef __RENESAS_RZG2L_CPG_H__
10 #define __RENESAS_RZG2L_CPG_H__
12 #define CPG_PL2_DDIV (0x204)
13 #define CPG_PL3A_DDIV (0x208)
14 #define CPG_PL2SDHI_DSEL (0x218)
15 #define CPG_CLKSTATUS (0x280)
16 #define CPG_PL3_SSEL (0x408)
17 #define CPG_PL6_ETH_SSEL (0x418)
19 #define CPG_CLKSTATUS_SELSDHI0_STS BIT(28)
20 #define CPG_CLKSTATUS_SELSDHI1_STS BIT(29)
22 #define CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US 20000
24 /* n = 0/1/2 for PLL1/4/6 */
25 #define CPG_SAMPLL_CLK1(n) (0x04 + (16 * n))
26 #define CPG_SAMPLL_CLK2(n) (0x08 + (16 * n))
28 #define PLL146_CONF(n) (CPG_SAMPLL_CLK1(n) << 22 | CPG_SAMPLL_CLK2(n) << 12)
30 #define DDIV_PACK(offset, bitpos, size) \
31 (((offset) << 20) | ((bitpos) << 12) | ((size) << 8))
32 #define DIVPL2A DDIV_PACK(CPG_PL2_DDIV, 0, 3)
33 #define DIVPL3A DDIV_PACK(CPG_PL3A_DDIV, 0, 3)
34 #define DIVPL3B DDIV_PACK(CPG_PL3A_DDIV, 4, 3)
35 #define DIVPL3C DDIV_PACK(CPG_PL3A_DDIV, 8, 3)
37 #define SEL_PLL_PACK(offset, bitpos, size) \
38 (((offset) << 20) | ((bitpos) << 12) | ((size) << 8))
40 #define SEL_PLL3_3 SEL_PLL_PACK(CPG_PL3_SSEL, 8, 1)
41 #define SEL_PLL6_2 SEL_PLL_PACK(CPG_PL6_ETH_SSEL, 0, 1)
43 #define SEL_SDHI0 DDIV_PACK(CPG_PL2SDHI_DSEL, 0, 2)
44 #define SEL_SDHI1 DDIV_PACK(CPG_PL2SDHI_DSEL, 4, 2)
47 * Definitions of CPG Core Clocks
50 * - Clock outputs exported to DT
51 * - External input clocks
52 * - Internal CPG clocks
62 const struct clk_div_table *dtable;
63 const char * const *parent_names;
71 CLK_TYPE_IN, /* External Clock Input */
72 CLK_TYPE_FF, /* Fixed Factor Clock */
75 /* Clock with divider */
78 /* Clock with clock source selector */
81 /* Clock with SD clock source selector */
85 #define DEF_TYPE(_name, _id, _type...) \
86 { .name = _name, .id = _id, .type = _type }
87 #define DEF_BASE(_name, _id, _type, _parent...) \
88 DEF_TYPE(_name, _id, _type, .parent = _parent)
89 #define DEF_SAMPLL(_name, _id, _parent, _conf) \
90 DEF_TYPE(_name, _id, CLK_TYPE_SAM_PLL, .parent = _parent, .conf = _conf)
91 #define DEF_INPUT(_name, _id) \
92 DEF_TYPE(_name, _id, CLK_TYPE_IN)
93 #define DEF_FIXED(_name, _id, _parent, _mult, _div) \
94 DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
95 #define DEF_DIV(_name, _id, _parent, _conf, _dtable, _flag) \
96 DEF_TYPE(_name, _id, CLK_TYPE_DIV, .conf = _conf, \
97 .parent = _parent, .dtable = _dtable, .flag = _flag)
98 #define DEF_MUX(_name, _id, _conf, _parent_names, _num_parents, _flag, \
100 DEF_TYPE(_name, _id, CLK_TYPE_MUX, .conf = _conf, \
101 .parent_names = _parent_names, .num_parents = _num_parents, \
102 .flag = _flag, .mux_flags = _mux_flags)
103 #define DEF_SD_MUX(_name, _id, _conf, _parent_names, _num_parents) \
104 DEF_TYPE(_name, _id, CLK_TYPE_SD_MUX, .conf = _conf, \
105 .parent_names = _parent_names, .num_parents = _num_parents)
108 * struct rzg2l_mod_clk - Module Clocks definitions
110 * @name: handle between common and hardware-specific interfaces
111 * @id: clock index in array containing all Core and Module Clocks
112 * @parent: id of parent clock
113 * @off: register offset
115 * @is_coupled: flag to indicate coupled clock
117 struct rzg2l_mod_clk {
126 #define DEF_MOD_BASE(_name, _id, _parent, _off, _bit, _is_coupled) \
129 .id = MOD_CLK_BASE + (_id), \
130 .parent = (_parent), \
133 .is_coupled = (_is_coupled), \
136 #define DEF_MOD(_name, _id, _parent, _off, _bit) \
137 DEF_MOD_BASE(_name, _id, _parent, _off, _bit, false)
139 #define DEF_COUPLED(_name, _id, _parent, _off, _bit) \
140 DEF_MOD_BASE(_name, _id, _parent, _off, _bit, true)
143 * struct rzg2l_reset - Reset definitions
145 * @off: register offset
153 #define DEF_RST(_id, _off, _bit) \
160 * struct rzg2l_cpg_info - SoC-specific CPG Description
162 * @core_clks: Array of Core Clock definitions
163 * @num_core_clks: Number of entries in core_clks[]
164 * @last_dt_core_clk: ID of the last Core Clock exported to DT
165 * @num_total_core_clks: Total number of Core Clocks (exported + internal)
167 * @mod_clks: Array of Module Clock definitions
168 * @num_mod_clks: Number of entries in mod_clks[]
169 * @num_hw_mod_clks: Number of Module Clocks supported by the hardware
171 * @crit_mod_clks: Array with Module Clock IDs of critical clocks that
172 * should not be disabled without a knowledgeable driver
173 * @num_crit_mod_clks: Number of entries in crit_mod_clks[]
175 struct rzg2l_cpg_info {
177 const struct cpg_core_clk *core_clks;
178 unsigned int num_core_clks;
179 unsigned int last_dt_core_clk;
180 unsigned int num_total_core_clks;
183 const struct rzg2l_mod_clk *mod_clks;
184 unsigned int num_mod_clks;
185 unsigned int num_hw_mod_clks;
188 const struct rzg2l_reset *resets;
189 unsigned int num_resets;
191 /* Critical Module Clocks that should not be disabled */
192 const unsigned int *crit_mod_clks;
193 unsigned int num_crit_mod_clks;
196 extern const struct rzg2l_cpg_info r9a07g044_cpg_info;