clk: renesas: Split RCar Gen3 driver
[oweals/u-boot.git] / drivers / clk / renesas / renesas-cpg-mssr.h
1 /*
2  * Renesas RCar Gen3 CPG MSSR driver
3  *
4  * Copyright (C) 2017-2018 Marek Vasut <marek.vasut@gmail.com>
5  *
6  * Based on the following driver from Linux kernel:
7  * r8a7796 Clock Pulse Generator / Module Standby and Software Reset
8  *
9  * Copyright (C) 2016 Glider bvba
10  *
11  * SPDX-License-Identifier:     GPL-2.0+
12  */
13
14 #ifndef __DRIVERS_CLK_RENESAS_CPG_MSSR__
15 #define __DRIVERS_CLK_RENESAS_CPG_MSSR__
16
17 struct cpg_mssr_info {
18         const struct cpg_core_clk       *core_clk;
19         unsigned int                    core_clk_size;
20         const struct mssr_mod_clk       *mod_clk;
21         unsigned int                    mod_clk_size;
22         const struct mstp_stop_table    *mstp_table;
23         unsigned int                    mstp_table_size;
24         const char                      *reset_node;
25         const char                      *extalr_node;
26 };
27
28 struct gen3_clk_priv {
29         void __iomem            *base;
30         struct cpg_mssr_info    *info;
31         struct clk              clk_extal;
32         struct clk              clk_extalr;
33         const struct rcar_gen3_cpg_pll_config *cpg_pll_config;
34 };
35
36 /*
37  * Definitions of CPG Core Clocks
38  *
39  * These include:
40  *   - Clock outputs exported to DT
41  *   - External input clocks
42  *   - Internal CPG clocks
43  */
44 struct cpg_core_clk {
45         /* Common */
46         const char *name;
47         unsigned int id;
48         unsigned int type;
49         /* Depending on type */
50         unsigned int parent;    /* Core Clocks only */
51         unsigned int div;
52         unsigned int mult;
53         unsigned int offset;
54 };
55
56 enum clk_types {
57         /* Generic */
58         CLK_TYPE_IN,            /* External Clock Input */
59         CLK_TYPE_FF,            /* Fixed Factor Clock */
60
61         /* Custom definitions start here */
62         CLK_TYPE_CUSTOM,
63 };
64
65 #define DEF_TYPE(_name, _id, _type...)  \
66         { .name = _name, .id = _id, .type = _type }
67 #define DEF_BASE(_name, _id, _type, _parent...) \
68         DEF_TYPE(_name, _id, _type, .parent = _parent)
69
70 #define DEF_INPUT(_name, _id) \
71         DEF_TYPE(_name, _id, CLK_TYPE_IN)
72 #define DEF_FIXED(_name, _id, _parent, _div, _mult)     \
73         DEF_BASE(_name, _id, CLK_TYPE_FF, _parent, .div = _div, .mult = _mult)
74 #define DEF_GEN3_SD(_name, _id, _parent, _offset)       \
75         DEF_BASE(_name, _id, CLK_TYPE_GEN3_SD, _parent, .offset = _offset)
76 #define DEF_GEN3_RPC(_name, _id, _parent, _offset)      \
77         DEF_BASE(_name, _id, CLK_TYPE_GEN3_RPC, _parent, .offset = _offset)
78 #define DEF_GEN3_PE(_name, _id, _parent_sscg, _div_sscg, _parent_clean, \
79                     _div_clean) \
80         DEF_BASE(_name, _id, CLK_TYPE_FF,                       \
81                  (_parent_clean), .div = (_div_clean), 1)
82
83 /*
84  * Definitions of Module Clocks
85  */
86 struct mssr_mod_clk {
87         const char *name;
88         unsigned int id;
89         unsigned int parent;    /* Add MOD_CLK_BASE for Module Clocks */
90 };
91
92 /* Convert from sparse base-100 to packed index space */
93 #define MOD_CLK_PACK(x) ((x) - ((x) / 100) * (100 - 32))
94
95 #define MOD_CLK_ID(x)   (MOD_CLK_BASE + MOD_CLK_PACK(x))
96
97 #define DEF_MOD(_name, _mod, _parent...)        \
98         { .name = _name, .id = MOD_CLK_ID(_mod), .parent = _parent }
99
100 enum rcar_gen3_clk_types {
101         CLK_TYPE_GEN3_MAIN = CLK_TYPE_CUSTOM,
102         CLK_TYPE_GEN3_PLL0,
103         CLK_TYPE_GEN3_PLL1,
104         CLK_TYPE_GEN3_PLL2,
105         CLK_TYPE_GEN3_PLL3,
106         CLK_TYPE_GEN3_PLL4,
107         CLK_TYPE_GEN3_SD,
108         CLK_TYPE_GEN3_RPC,
109         CLK_TYPE_GEN3_R,
110         CLK_TYPE_GEN3_PE,
111         CLK_TYPE_GEN3_Z2,
112 };
113
114 struct rcar_gen3_cpg_pll_config {
115         unsigned int extal_div;
116         unsigned int pll1_mult;
117         unsigned int pll3_mult;
118 };
119
120 #include <dt-bindings/clock/r8a7796-cpg-mssr.h>
121
122 enum clk_ids {
123         /* Core Clock Outputs exported to DT */
124         LAST_DT_CORE_CLK = R8A7796_CLK_OSC,
125
126         /* External Input Clocks */
127         CLK_EXTAL,
128         CLK_EXTALR,
129
130         /* Internal Core Clocks */
131         CLK_MAIN,
132         CLK_PLL0,
133         CLK_PLL1,
134         CLK_PLL2,
135         CLK_PLL3,
136         CLK_PLL4,
137         CLK_PLL1_DIV2,
138         CLK_PLL1_DIV4,
139         CLK_PLL0D2,
140         CLK_PLL0D3,
141         CLK_PLL0D5,
142         CLK_PLL1D2,
143         CLK_PE,
144         CLK_S0,
145         CLK_S1,
146         CLK_S2,
147         CLK_S3,
148         CLK_SDSRC,
149         CLK_RPCSRC,
150         CLK_SSPSRC,
151         CLK_RINT,
152
153         /* Module Clocks */
154         MOD_CLK_BASE
155 };
156
157 struct mstp_stop_table {
158         u32     dis;
159         u32     en;
160 };
161
162 #define TSTR0           0x04
163 #define TSTR0_STR0      BIT(0)
164
165 int gen3_clk_probe(struct udevice *dev);
166 int gen3_clk_remove(struct udevice *dev);
167
168 extern const struct clk_ops gen3_clk_ops;
169
170 #endif /* __DRIVERS_CLK_RENESAS_CPG_MSSR__ */