blob: 41a30c569c7a26bf51227253ae4dc7fc87945d35 [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,
Marek Vasut7ef12c22018-01-08 17:09:45 +010021 CLK_TYPE_GEN3_SD,
Marek Vasut7ef12c22018-01-08 17:09:45 +010022 CLK_TYPE_GEN3_R,
Marek Vasut78414832019-03-04 21:38:10 +010023 CLK_TYPE_GEN3_MDSEL, /* Select parent/divider using mode pin */
24 CLK_TYPE_GEN3_Z,
Marek Vasut78414832019-03-04 21:38:10 +010025 CLK_TYPE_GEN3_OSC, /* OSC EXTAL predivider and fixed divider */
26 CLK_TYPE_GEN3_RCKSEL, /* Select parent/divider using RCKCR.CKSEL */
27 CLK_TYPE_GEN3_RPCSRC,
Marek Vasutd1ff7e02023-01-26 21:01:55 +010028 CLK_TYPE_GEN3_D3_RPCSRC,
Marek Vasut0e8dcb72021-04-25 21:10:40 +020029 CLK_TYPE_GEN3_E3_RPCSRC,
Marek Vasut78414832019-03-04 21:38:10 +010030 CLK_TYPE_GEN3_RPC,
31 CLK_TYPE_GEN3_RPCD2,
Hai Pham86d59f32020-08-11 10:46:34 +070032
Marek Vasut569acef2023-01-26 21:01:56 +010033 CLK_TYPE_GEN4_MAIN,
34 CLK_TYPE_GEN4_PLL1,
35 CLK_TYPE_GEN4_PLL2X_3X, /* PLL[23][01] */
36 CLK_TYPE_GEN4_PLL5,
37 CLK_TYPE_GEN4_SDH,
38 CLK_TYPE_GEN4_SD,
39 CLK_TYPE_GEN4_MDSEL, /* Select parent/divider using mode pin */
40 CLK_TYPE_GEN4_Z,
41 CLK_TYPE_GEN4_OSC, /* OSC EXTAL predivider and fixed divider */
42 CLK_TYPE_GEN4_RPCSRC,
43 CLK_TYPE_GEN4_RPC,
44 CLK_TYPE_GEN4_RPCD2,
Marek Vasut78414832019-03-04 21:38:10 +010045
46 /* SoC specific definitions start here */
47 CLK_TYPE_GEN3_SOC_BASE,
Marek Vasut7ef12c22018-01-08 17:09:45 +010048};
49
Hai Pham0985e0e2023-01-26 21:01:49 +010050#define DEF_GEN3_SDH(_name, _id, _parent, _offset) \
51 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SDH, _parent, .offset = _offset)
52
Marek Vasut7ef12c22018-01-08 17:09:45 +010053#define DEF_GEN3_SD(_name, _id, _parent, _offset) \
54 DEF_BASE(_name, _id, CLK_TYPE_GEN3_SD, _parent, .offset = _offset)
Marek Vasut78414832019-03-04 21:38:10 +010055
Marek Vasut78414832019-03-04 21:38:10 +010056#define DEF_GEN3_MDSEL(_name, _id, _md, _parent0, _div0, _parent1, _div1) \
57 DEF_BASE(_name, _id, CLK_TYPE_GEN3_MDSEL, \
58 (_parent0) << 16 | (_parent1), \
59 .div = (_div0) << 16 | (_div1), .offset = _md)
60
Marek Vasut7ef12c22018-01-08 17:09:45 +010061#define DEF_GEN3_PE(_name, _id, _parent_sscg, _div_sscg, _parent_clean, \
62 _div_clean) \
Marek Vasut78414832019-03-04 21:38:10 +010063 DEF_GEN3_MDSEL(_name, _id, 12, _parent_sscg, _div_sscg, \
64 _parent_clean, _div_clean)
65
66#define DEF_GEN3_OSC(_name, _id, _parent, _div) \
67 DEF_BASE(_name, _id, CLK_TYPE_GEN3_OSC, _parent, .div = _div)
68
69#define DEF_GEN3_RCKSEL(_name, _id, _parent0, _div0, _parent1, _div1) \
70 DEF_BASE(_name, _id, CLK_TYPE_GEN3_RCKSEL, \
71 (_parent0) << 16 | (_parent1), .div = (_div0) << 16 | (_div1))
72
Adam Ford06c4f9b2020-06-30 09:30:08 -050073#define DEF_GEN3_Z(_name, _id, _type, _parent, _div, _offset) \
74 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
Marek Vasut7ef12c22018-01-08 17:09:45 +010075
Marek Vasutd1ff7e02023-01-26 21:01:55 +010076#define DEF_FIXED_RPCSRC_D3(_name, _id, _parent0, _parent1) \
77 DEF_BASE(_name, _id, CLK_TYPE_GEN3_D3_RPCSRC, \
78 (_parent0) << 16 | (_parent1), .div = 5)
79
Marek Vasut0e8dcb72021-04-25 21:10:40 +020080#define DEF_FIXED_RPCSRC_E3(_name, _id, _parent0, _parent1) \
81 DEF_BASE(_name, _id, CLK_TYPE_GEN3_E3_RPCSRC, \
82 (_parent0) << 16 | (_parent1), .div = 8)
83
Marek Vasut569acef2023-01-26 21:01:56 +010084#define DEF_GEN4_SDH(_name, _id, _parent, _offset) \
85 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SDH, _parent, .offset = _offset)
86
87#define DEF_GEN4_SD(_name, _id, _parent, _offset) \
88 DEF_BASE(_name, _id, CLK_TYPE_GEN4_SD, _parent, .offset = _offset)
89
90#define DEF_GEN4_MDSEL(_name, _id, _md, _parent0, _div0, _parent1, _div1) \
91 DEF_BASE(_name, _id, CLK_TYPE_GEN4_MDSEL, \
92 (_parent0) << 16 | (_parent1), \
93 .div = (_div0) << 16 | (_div1), .offset = _md)
94
95#define DEF_GEN4_OSC(_name, _id, _parent, _div) \
96 DEF_BASE(_name, _id, CLK_TYPE_GEN4_OSC, _parent, .div = _div)
97
98#define DEF_GEN4_Z(_name, _id, _type, _parent, _div, _offset) \
99 DEF_BASE(_name, _id, _type, _parent, .div = _div, .offset = _offset)
100
Marek Vasut7ef12c22018-01-08 17:09:45 +0100101struct rcar_gen3_cpg_pll_config {
102 u8 extal_div;
103 u8 pll1_mult;
104 u8 pll1_div;
105 u8 pll3_mult;
106 u8 pll3_div;
Marek Vasut78414832019-03-04 21:38:10 +0100107 u8 osc_prediv;
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200108 u8 pll5_mult;
109 u8 pll5_div;
Marek Vasut7ef12c22018-01-08 17:09:45 +0100110};
111
Marek Vasut814217e2021-04-25 21:53:05 +0200112#define CPG_RST_MODEMR 0x060
113
Marek Vasut78414832019-03-04 21:38:10 +0100114#define CPG_RPCCKCR 0x238
Hai Phame83700a2023-01-26 21:06:03 +0100115#define CPG_RPCCKCR_DIV_POST_MASK GENMASK(4, 3)
116#define CPG_RPCCKCR_DIV_PRE_MASK GENMASK(2, 0)
117
Marek Vasut7ef12c22018-01-08 17:09:45 +0100118#define CPG_RCKCR 0x240
119
120struct gen3_clk_priv {
121 void __iomem *base;
122 struct cpg_mssr_info *info;
123 struct clk clk_extal;
124 struct clk clk_extalr;
Marek Vasut69459b22018-05-31 19:47:42 +0200125 bool sscg;
Marek Vasut7ef12c22018-01-08 17:09:45 +0100126 const struct rcar_gen3_cpg_pll_config *cpg_pll_config;
127};
128
Marek Vasutf6b32022023-01-26 21:02:03 +0100129int gen3_cpg_bind(struct udevice *parent);
Marek Vasut7ef12c22018-01-08 17:09:45 +0100130
131extern const struct clk_ops gen3_clk_ops;
132
133#endif