blob: 4efb9b6ceefd4aa40e077d041fb08f17c92d4a9d [file] [log] [blame]
Marek Vasut0e8dcb72021-04-25 21:10:40 +02001/* SPDX-License-Identifier: GPL-2.0 */
Marek Vasut7ef12c22018-01-08 17:09:45 +01002/*
3 * R-Car Gen3 Clock Pulse Generator
4 *
Marek Vasut0e8dcb72021-04-25 21:10:40 +02005 * Copyright (C) 2015-2018 Glider bvba
6 * Copyright (C) 2018 Renesas Electronics Corp.
Marek Vasut7ef12c22018-01-08 17:09:45 +01007 *
Marek Vasut7ef12c22018-01-08 17:09:45 +01008 */
9
10#ifndef __CLK_RENESAS_RCAR_GEN3_CPG_H__
11#define __CLK_RENESAS_RCAR_GEN3_CPG_H__
12
13enum rcar_gen3_clk_types {
14 CLK_TYPE_GEN3_MAIN = CLK_TYPE_CUSTOM,
15 CLK_TYPE_GEN3_PLL0,
16 CLK_TYPE_GEN3_PLL1,
17 CLK_TYPE_GEN3_PLL2,
18 CLK_TYPE_GEN3_PLL3,
19 CLK_TYPE_GEN3_PLL4,
Hai Pham0985e0e2023-01-26 21:01:49 +010020 CLK_TYPE_GEN3_SDH,
Hai Pham6811b572023-01-26 21:06:06 +010021 CLK_TYPE_R8A77970_SD0H,
Marek Vasut7ef12c22018-01-08 17:09:45 +010022 CLK_TYPE_GEN3_SD,
Hai Pham6811b572023-01-26 21:06:06 +010023 CLK_TYPE_R8A77970_SD0,
Marek Vasut7ef12c22018-01-08 17:09:45 +010024 CLK_TYPE_GEN3_R,
Marek Vasut78414832019-03-04 21:38:10 +010025 CLK_TYPE_GEN3_MDSEL, /* Select parent/divider using mode pin */
26 CLK_TYPE_GEN3_Z,
Marek Vasute1418a02023-12-03 14:15:13 +010027 CLK_TYPE_GEN3_ZG,
Marek Vasut78414832019-03-04 21:38:10 +010028 CLK_TYPE_GEN3_OSC, /* OSC EXTAL predivider and fixed divider */
29 CLK_TYPE_GEN3_RCKSEL, /* Select parent/divider using RCKCR.CKSEL */
30 CLK_TYPE_GEN3_RPCSRC,
Marek Vasutd1ff7e02023-01-26 21:01:55 +010031 CLK_TYPE_GEN3_D3_RPCSRC,
Marek Vasut0e8dcb72021-04-25 21:10:40 +020032 CLK_TYPE_GEN3_E3_RPCSRC,
Marek Vasut78414832019-03-04 21:38:10 +010033 CLK_TYPE_GEN3_RPC,
34 CLK_TYPE_GEN3_RPCD2,
Hai Pham86d59f32020-08-11 10:46:34 +070035
Marek Vasut569acef2023-01-26 21:01:56 +010036 CLK_TYPE_GEN4_MAIN,
37 CLK_TYPE_GEN4_PLL1,
Marek Vasutba2c7d22023-02-28 22:34:38 +010038 CLK_TYPE_GEN4_PLL2,
39 CLK_TYPE_GEN4_PLL2X_3X, /* R8A779A0 only */
40 CLK_TYPE_GEN4_PLL3,
Marek Vasut569acef2023-01-26 21:01:56 +010041 CLK_TYPE_GEN4_PLL5,
Marek Vasutba2c7d22023-02-28 22:34:38 +010042 CLK_TYPE_GEN4_PLL4,
43 CLK_TYPE_GEN4_PLL6,
Hai Pham28028692024-01-28 16:52:01 +010044 CLK_TYPE_GEN4_PLL7,
Marek Vasutba2c7d22023-02-28 22:34:38 +010045 CLK_TYPE_GEN4_SDSRC,
Marek Vasut569acef2023-01-26 21:01:56 +010046 CLK_TYPE_GEN4_SDH,
47 CLK_TYPE_GEN4_SD,
48 CLK_TYPE_GEN4_MDSEL, /* Select parent/divider using mode pin */
49 CLK_TYPE_GEN4_Z,
50 CLK_TYPE_GEN4_OSC, /* OSC EXTAL predivider and fixed divider */
51 CLK_TYPE_GEN4_RPCSRC,
52 CLK_TYPE_GEN4_RPC,
53 CLK_TYPE_GEN4_RPCD2,
Marek Vasut78414832019-03-04 21:38:10 +010054
55 /* SoC specific definitions start here */
56 CLK_TYPE_GEN3_SOC_BASE,
Marek Vasut7ef12c22018-01-08 17:09:45 +010057};
58
Hai Pham0985e0e2023-01-26 21:01:49 +010059#define DEF_GEN3_SDH(_name, _id, _parent, _offset) \
60 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SDH, _parent, .offset = _offset)
61
Marek Vasut7ef12c22018-01-08 17:09:45 +010062#define DEF_GEN3_SD(_name, _id, _parent, _offset) \
63 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SD, _parent, .offset = _offset)
Marek Vasut78414832019-03-04 21:38:10 +010064
Marek Vasut78414832019-03-04 21:38:10 +010065#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)
69
Marek Vasut7ef12c22018-01-08 17:09:45 +010070#define DEF_GEN3_PE(_name, _id, _parent_sscg, _div_sscg, _parent_clean, \
71 _div_clean) \
Marek Vasut78414832019-03-04 21:38:10 +010072 DEF_GEN3_MDSEL(_name, _id, 12, _parent_sscg, _div_sscg, \
73 _parent_clean, _div_clean)
74
75#define DEF_GEN3_OSC(_name, _id, _parent, _div) \
76 DEF_BASE(_name, _id, CLK_TYPE_GEN3_OSC, _parent, .div = _div)
77
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))
81
Adam Ford06c4f9b2020-06-30 09:30:08 -050082#define DEF_GEN3_Z(_name, _id, _type, _parent, _div, _offset) \
83 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
Marek Vasut7ef12c22018-01-08 17:09:45 +010084
Marek Vasutd1ff7e02023-01-26 21:01:55 +010085#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)
88
Marek Vasut0e8dcb72021-04-25 21:10:40 +020089#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)
92
Marek Vasut569acef2023-01-26 21:01:56 +010093#define DEF_GEN4_SDH(_name, _id, _parent, _offset) \
94 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SDH, _parent, .offset = _offset)
95
96#define DEF_GEN4_SD(_name, _id, _parent, _offset) \
97 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SD, _parent, .offset = _offset)
98
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)
103
104#define DEF_GEN4_OSC(_name, _id, _parent, _div) \
105 DEF_BASE(_name, _id, CLK_TYPE_GEN4_OSC, _parent, .div = _div)
106
107#define DEF_GEN4_Z(_name, _id, _type, _parent, _div, _offset) \
108 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
109
Marek Vasut7ef12c22018-01-08 17:09:45 +0100110struct rcar_gen3_cpg_pll_config {
111 u8 extal_div;
112 u8 pll1_mult;
113 u8 pll1_div;
114 u8 pll3_mult;
115 u8 pll3_div;
Marek Vasut78414832019-03-04 21:38:10 +0100116 u8 osc_prediv;
Marek Vasutba2c7d22023-02-28 22:34:38 +0100117};
118
119struct rcar_gen4_cpg_pll_config {
120 u8 extal_div;
121 u8 pll1_mult;
122 u8 pll1_div;
123 u8 pll2_mult;
124 u8 pll2_div;
125 u8 pll3_mult;
126 u8 pll3_div;
127 u8 pll4_mult;
128 u8 pll4_div;
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200129 u8 pll5_mult;
130 u8 pll5_div;
Marek Vasutba2c7d22023-02-28 22:34:38 +0100131 u8 pll6_mult;
132 u8 pll6_div;
133 u8 osc_prediv;
Marek Vasut55f08262024-01-28 16:52:02 +0100134 u8 pll7_mult;
135 u8 pll7_div;
Marek Vasut7ef12c22018-01-08 17:09:45 +0100136};
137
Marek Vasut814217e2021-04-25 21:53:05 +0200138#define CPG_RST_MODEMR 0x060
Marek Vasutba2c7d22023-02-28 22:34:38 +0100139#define CPG_RST_MODEMR0 0x000
Marek Vasut814217e2021-04-25 21:53:05 +0200140
Hai Pham4dae0762023-01-29 02:50:22 +0100141#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)
Hai Pham6811b572023-01-26 21:06:06 +0100145/* V3M specifics */
146#define CPG_SDCKCR_SDHFC_MASK GENMASK(11, 8)
147#define CPG_SDCKCR_SD0FC_MASK GENMASK(7, 4)
Hai Pham4dae0762023-01-29 02:50:22 +0100148
Marek Vasut78414832019-03-04 21:38:10 +0100149#define CPG_RPCCKCR 0x238
Hai Phame83700a2023-01-26 21:06:03 +0100150#define CPG_RPCCKCR_DIV_POST_MASK GENMASK(4, 3)
151#define CPG_RPCCKCR_DIV_PRE_MASK GENMASK(2, 0)
152
Marek Vasut7ef12c22018-01-08 17:09:45 +0100153#define CPG_RCKCR 0x240
154
155struct gen3_clk_priv {
156 void __iomem *base;
157 struct cpg_mssr_info *info;
158 struct clk clk_extal;
159 struct clk clk_extalr;
Marek Vasutea8505e2023-02-28 07:25:11 +0100160 u32 cpg_mode;
Marek Vasutba2c7d22023-02-28 22:34:38 +0100161 union {
162 const struct rcar_gen3_cpg_pll_config *gen3_cpg_pll_config;
163 const struct rcar_gen4_cpg_pll_config *gen4_cpg_pll_config;
164 };
Marek Vasut7ef12c22018-01-08 17:09:45 +0100165};
166
Marek Vasutf6b32022023-01-26 21:02:03 +0100167int gen3_cpg_bind(struct udevice *parent);
Marek Vasut7ef12c22018-01-08 17:09:45 +0100168
169extern const struct clk_ops gen3_clk_ops;
170
171#endif