blob: 200e4adb90655d542875e4729990ab080945b79f [file] [log] [blame]
Marek Vasutf7b4e4c2021-04-25 21:10:40 +02001/* SPDX-License-Identifier: GPL-2.0 */
Marek Vasut58f17882018-01-08 17:09:45 +01002/*
3 * R-Car Gen3 Clock Pulse Generator
4 *
Marek Vasutf7b4e4c2021-04-25 21:10:40 +02005 * Copyright (C) 2015-2018 Glider bvba
6 * Copyright (C) 2018 Renesas Electronics Corp.
Marek Vasut58f17882018-01-08 17:09:45 +01007 *
Marek Vasut58f17882018-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 Phamc206dfd2023-01-26 21:01:49 +010020 CLK_TYPE_GEN3_SDH,
Hai Phamd8132ae2023-01-26 21:06:06 +010021 CLK_TYPE_R8A77970_SD0H,
Marek Vasut58f17882018-01-08 17:09:45 +010022 CLK_TYPE_GEN3_SD,
Hai Phamd8132ae2023-01-26 21:06:06 +010023 CLK_TYPE_R8A77970_SD0,
Marek Vasut58f17882018-01-08 17:09:45 +010024 CLK_TYPE_GEN3_R,
Marek Vasut72242e52019-03-04 21:38:10 +010025 CLK_TYPE_GEN3_MDSEL, /* Select parent/divider using mode pin */
26 CLK_TYPE_GEN3_Z,
Marek Vasut72242e52019-03-04 21:38:10 +010027 CLK_TYPE_GEN3_OSC, /* OSC EXTAL predivider and fixed divider */
28 CLK_TYPE_GEN3_RCKSEL, /* Select parent/divider using RCKCR.CKSEL */
29 CLK_TYPE_GEN3_RPCSRC,
Marek Vasut4fc053f2023-01-26 21:01:55 +010030 CLK_TYPE_GEN3_D3_RPCSRC,
Marek Vasutf7b4e4c2021-04-25 21:10:40 +020031 CLK_TYPE_GEN3_E3_RPCSRC,
Marek Vasut72242e52019-03-04 21:38:10 +010032 CLK_TYPE_GEN3_RPC,
33 CLK_TYPE_GEN3_RPCD2,
Hai Phamb092f962020-08-11 10:46:34 +070034
Marek Vasut733da622023-01-26 21:01:56 +010035 CLK_TYPE_GEN4_MAIN,
36 CLK_TYPE_GEN4_PLL1,
37 CLK_TYPE_GEN4_PLL2X_3X, /* PLL[23][01] */
38 CLK_TYPE_GEN4_PLL5,
39 CLK_TYPE_GEN4_SDH,
40 CLK_TYPE_GEN4_SD,
41 CLK_TYPE_GEN4_MDSEL, /* Select parent/divider using mode pin */
42 CLK_TYPE_GEN4_Z,
43 CLK_TYPE_GEN4_OSC, /* OSC EXTAL predivider and fixed divider */
44 CLK_TYPE_GEN4_RPCSRC,
45 CLK_TYPE_GEN4_RPC,
46 CLK_TYPE_GEN4_RPCD2,
Marek Vasut72242e52019-03-04 21:38:10 +010047
48 /* SoC specific definitions start here */
49 CLK_TYPE_GEN3_SOC_BASE,
Marek Vasut58f17882018-01-08 17:09:45 +010050};
51
Hai Phamc206dfd2023-01-26 21:01:49 +010052#define DEF_GEN3_SDH(_name, _id, _parent, _offset) \
53 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SDH, _parent, .offset = _offset)
54
Marek Vasut58f17882018-01-08 17:09:45 +010055#define DEF_GEN3_SD(_name, _id, _parent, _offset) \
56 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SD, _parent, .offset = _offset)
Marek Vasut72242e52019-03-04 21:38:10 +010057
Marek Vasut72242e52019-03-04 21:38:10 +010058#define DEF_GEN3_MDSEL(_name, _id, _md, _parent0, _div0, _parent1, _div1) \
59 DEF_BASE(_name, _id, CLK_TYPE_GEN3_MDSEL, \
60 (_parent0) << 16 | (_parent1), \
61 .div = (_div0) << 16 | (_div1), .offset = _md)
62
Marek Vasut58f17882018-01-08 17:09:45 +010063#define DEF_GEN3_PE(_name, _id, _parent_sscg, _div_sscg, _parent_clean, \
64 _div_clean) \
Marek Vasut72242e52019-03-04 21:38:10 +010065 DEF_GEN3_MDSEL(_name, _id, 12, _parent_sscg, _div_sscg, \
66 _parent_clean, _div_clean)
67
68#define DEF_GEN3_OSC(_name, _id, _parent, _div) \
69 DEF_BASE(_name, _id, CLK_TYPE_GEN3_OSC, _parent, .div = _div)
70
71#define DEF_GEN3_RCKSEL(_name, _id, _parent0, _div0, _parent1, _div1) \
72 DEF_BASE(_name, _id, CLK_TYPE_GEN3_RCKSEL, \
73 (_parent0) << 16 | (_parent1), .div = (_div0) << 16 | (_div1))
74
Adam Forde9a52c42020-06-30 09:30:08 -050075#define DEF_GEN3_Z(_name, _id, _type, _parent, _div, _offset) \
76 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
Marek Vasut58f17882018-01-08 17:09:45 +010077
Marek Vasut4fc053f2023-01-26 21:01:55 +010078#define DEF_FIXED_RPCSRC_D3(_name, _id, _parent0, _parent1) \
79 DEF_BASE(_name, _id, CLK_TYPE_GEN3_D3_RPCSRC, \
80 (_parent0) << 16 | (_parent1), .div = 5)
81
Marek Vasutf7b4e4c2021-04-25 21:10:40 +020082#define DEF_FIXED_RPCSRC_E3(_name, _id, _parent0, _parent1) \
83 DEF_BASE(_name, _id, CLK_TYPE_GEN3_E3_RPCSRC, \
84 (_parent0) << 16 | (_parent1), .div = 8)
85
Marek Vasut733da622023-01-26 21:01:56 +010086#define DEF_GEN4_SDH(_name, _id, _parent, _offset) \
87 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SDH, _parent, .offset = _offset)
88
89#define DEF_GEN4_SD(_name, _id, _parent, _offset) \
90 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SD, _parent, .offset = _offset)
91
92#define DEF_GEN4_MDSEL(_name, _id, _md, _parent0, _div0, _parent1, _div1) \
93 DEF_BASE(_name, _id, CLK_TYPE_GEN4_MDSEL, \
94 (_parent0) << 16 | (_parent1), \
95 .div = (_div0) << 16 | (_div1), .offset = _md)
96
97#define DEF_GEN4_OSC(_name, _id, _parent, _div) \
98 DEF_BASE(_name, _id, CLK_TYPE_GEN4_OSC, _parent, .div = _div)
99
100#define DEF_GEN4_Z(_name, _id, _type, _parent, _div, _offset) \
101 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
102
Marek Vasut58f17882018-01-08 17:09:45 +0100103struct rcar_gen3_cpg_pll_config {
104 u8 extal_div;
105 u8 pll1_mult;
106 u8 pll1_div;
107 u8 pll3_mult;
108 u8 pll3_div;
Marek Vasut72242e52019-03-04 21:38:10 +0100109 u8 osc_prediv;
Marek Vasut44c78aa2021-04-27 19:52:53 +0200110 u8 pll5_mult;
111 u8 pll5_div;
Marek Vasut58f17882018-01-08 17:09:45 +0100112};
113
Marek Vasute9354092021-04-25 21:53:05 +0200114#define CPG_RST_MODEMR 0x060
115
Hai Pham4dbbc3f2023-01-29 02:50:22 +0100116#define CPG_SDCKCR_STPnHCK BIT(9)
117#define CPG_SDCKCR_STPnCK BIT(8)
118#define CPG_SDCKCR_SRCFC_MASK GENMASK(4, 2)
119#define CPG_SDCKCR_FC_MASK GENMASK(1, 0)
Hai Phamd8132ae2023-01-26 21:06:06 +0100120/* V3M specifics */
121#define CPG_SDCKCR_SDHFC_MASK GENMASK(11, 8)
122#define CPG_SDCKCR_SD0FC_MASK GENMASK(7, 4)
Hai Pham4dbbc3f2023-01-29 02:50:22 +0100123
Marek Vasut72242e52019-03-04 21:38:10 +0100124#define CPG_RPCCKCR 0x238
Hai Phama1ec0bb2023-01-26 21:06:03 +0100125#define CPG_RPCCKCR_DIV_POST_MASK GENMASK(4, 3)
126#define CPG_RPCCKCR_DIV_PRE_MASK GENMASK(2, 0)
127
Marek Vasut58f17882018-01-08 17:09:45 +0100128#define CPG_RCKCR 0x240
129
130struct gen3_clk_priv {
131 void __iomem *base;
132 struct cpg_mssr_info *info;
133 struct clk clk_extal;
134 struct clk clk_extalr;
Marek Vasut716d7752018-05-31 19:47:42 +0200135 bool sscg;
Marek Vasut58f17882018-01-08 17:09:45 +0100136 const struct rcar_gen3_cpg_pll_config *cpg_pll_config;
137};
138
Marek Vasut326e05c2023-01-26 21:02:03 +0100139int gen3_cpg_bind(struct udevice *parent);
Marek Vasut58f17882018-01-08 17:09:45 +0100140
141extern const struct clk_ops gen3_clk_ops;
142
143#endif