1 /* SPDX-License-Identifier: GPL-2.0 */
3 * R-Car Gen3 Clock Pulse Generator
5 * Copyright (C) 2015-2018 Glider bvba
6 * Copyright (C) 2018 Renesas Electronics Corp.
10 #ifndef __CLK_RENESAS_RCAR_GEN3_CPG_H__
11 #define __CLK_RENESAS_RCAR_GEN3_CPG_H__
13 enum rcar_gen3_clk_types {
14 CLK_TYPE_GEN3_MAIN = CLK_TYPE_CUSTOM,
21 CLK_TYPE_R8A77970_SD0H,
23 CLK_TYPE_R8A77970_SD0,
25 CLK_TYPE_GEN3_MDSEL, /* Select parent/divider using mode pin */
28 CLK_TYPE_GEN3_OSC, /* OSC EXTAL predivider and fixed divider */
29 CLK_TYPE_GEN3_RCKSEL, /* Select parent/divider using RCKCR.CKSEL */
31 CLK_TYPE_GEN3_D3_RPCSRC,
32 CLK_TYPE_GEN3_E3_RPCSRC,
39 CLK_TYPE_GEN4_PLL2X_3X, /* R8A779A0 only */
48 CLK_TYPE_GEN4_MDSEL, /* Select parent/divider using mode pin */
50 CLK_TYPE_GEN4_OSC, /* OSC EXTAL predivider and fixed divider */
55 /* SoC specific definitions start here */
56 CLK_TYPE_GEN3_SOC_BASE,
59 #define DEF_GEN3_SDH(_name, _id, _parent, _offset) \
60 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SDH, _parent, .offset = _offset)
62 #define DEF_GEN3_SD(_name, _id, _parent, _offset) \
63 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SD, _parent, .offset = _offset)
65 #define DEF_GEN3_MDSEL(_name, _id, _md, _parent0, _div0, _parent1, _div1) \
66 DEF_BASE(_name, _id, CLK_TYPE_GEN3_MDSEL, \
67 (_parent0) << 16 | (_parent1), \
68 .div = (_div0) << 16 | (_div1), .offset = _md)
70 #define DEF_GEN3_PE(_name, _id, _parent_sscg, _div_sscg, _parent_clean, \
72 DEF_GEN3_MDSEL(_name, _id, 12, _parent_sscg, _div_sscg, \
73 _parent_clean, _div_clean)
75 #define DEF_GEN3_OSC(_name, _id, _parent, _div) \
76 DEF_BASE(_name, _id, CLK_TYPE_GEN3_OSC, _parent, .div = _div)
78 #define DEF_GEN3_RCKSEL(_name, _id, _parent0, _div0, _parent1, _div1) \
79 DEF_BASE(_name, _id, CLK_TYPE_GEN3_RCKSEL, \
80 (_parent0) << 16 | (_parent1), .div = (_div0) << 16 | (_div1))
82 #define DEF_GEN3_Z(_name, _id, _type, _parent, _div, _offset) \
83 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
85 #define DEF_FIXED_RPCSRC_D3(_name, _id, _parent0, _parent1) \
86 DEF_BASE(_name, _id, CLK_TYPE_GEN3_D3_RPCSRC, \
87 (_parent0) << 16 | (_parent1), .div = 5)
89 #define DEF_FIXED_RPCSRC_E3(_name, _id, _parent0, _parent1) \
90 DEF_BASE(_name, _id, CLK_TYPE_GEN3_E3_RPCSRC, \
91 (_parent0) << 16 | (_parent1), .div = 8)
93 #define DEF_GEN4_SDH(_name, _id, _parent, _offset) \
94 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SDH, _parent, .offset = _offset)
96 #define DEF_GEN4_SD(_name, _id, _parent, _offset) \
97 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SD, _parent, .offset = _offset)
99 #define DEF_GEN4_MDSEL(_name, _id, _md, _parent0, _div0, _parent1, _div1) \
100 DEF_BASE(_name, _id, CLK_TYPE_GEN4_MDSEL, \
101 (_parent0) << 16 | (_parent1), \
102 .div = (_div0) << 16 | (_div1), .offset = _md)
104 #define DEF_GEN4_OSC(_name, _id, _parent, _div) \
105 DEF_BASE(_name, _id, CLK_TYPE_GEN4_OSC, _parent, .div = _div)
107 #define DEF_GEN4_Z(_name, _id, _type, _parent, _div, _offset) \
108 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
110 struct rcar_gen3_cpg_pll_config {
119 struct rcar_gen4_cpg_pll_config {
138 #define CPG_RST_MODEMR 0x060
139 #define CPG_RST_MODEMR0 0x000
141 #define CPG_SDCKCR_STPnHCK BIT(9)
142 #define CPG_SDCKCR_STPnCK BIT(8)
143 #define CPG_SDCKCR_SRCFC_MASK GENMASK(4, 2)
144 #define CPG_SDCKCR_FC_MASK GENMASK(1, 0)
146 #define CPG_SDCKCR_SDHFC_MASK GENMASK(11, 8)
147 #define CPG_SDCKCR_SD0FC_MASK GENMASK(7, 4)
149 #define CPG_RPCCKCR 0x238
150 #define CPG_RPCCKCR_DIV_POST_MASK GENMASK(4, 3)
151 #define CPG_RPCCKCR_DIV_PRE_MASK GENMASK(2, 0)
153 #define CPG_RCKCR 0x240
155 struct gen3_clk_priv {
157 struct cpg_mssr_info *info;
158 struct clk clk_extal;
159 struct clk clk_extalr;
162 const struct rcar_gen3_cpg_pll_config *gen3_cpg_pll_config;
163 const struct rcar_gen4_cpg_pll_config *gen4_cpg_pll_config;
167 int gen3_cpg_bind(struct udevice *parent);
169 extern const struct clk_ops gen3_clk_ops;