blob: 94715bb00ce4f9f216f917a2c1af18923248d257 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutf3b8bf72017-07-21 23:18:03 +02002/*
Marek Vasut3f1a3a12017-10-09 20:52:33 +02003 * Renesas RCar Gen3 CPG MSSR driver
Marek Vasutf3b8bf72017-07-21 23:18:03 +02004 *
5 * Copyright (C) 2017 Marek Vasut <marek.vasut@gmail.com>
6 *
7 * Based on the following driver from Linux kernel:
8 * r8a7796 Clock Pulse Generator / Module Standby and Software Reset
9 *
10 * Copyright (C) 2016 Glider bvba
Marek Vasutf3b8bf72017-07-21 23:18:03 +020011 */
12
13#include <common.h>
14#include <clk-uclass.h>
15#include <dm.h>
16#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060017#include <log.h>
Marek Vasutf3b8bf72017-07-21 23:18:03 +020018#include <wait_bit.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Marek Vasutf3b8bf72017-07-21 23:18:03 +020020#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060021#include <linux/bitops.h>
Marek Vasutf3b8bf72017-07-21 23:18:03 +020022
Marek Vasut4eb4e6e2018-01-08 14:01:40 +010023#include <dt-bindings/clock/renesas-cpg-mssr.h>
24
25#include "renesas-cpg-mssr.h"
Marek Vasute11008b2018-01-15 16:44:39 +010026#include "rcar-gen3-cpg.h"
Marek Vasutf3b8bf72017-07-21 23:18:03 +020027
Marek Vasutf3b8bf72017-07-21 23:18:03 +020028#define CPG_PLL0CR 0x00d8
29#define CPG_PLL2CR 0x002c
30#define CPG_PLL4CR 0x01f4
31
Marek Vasutc1aee322017-09-15 21:10:29 +020032#define CPG_RPC_PREDIV_MASK 0x3
33#define CPG_RPC_PREDIV_OFFSET 3
34#define CPG_RPC_POSTDIV_MASK 0x7
35#define CPG_RPC_POSTDIV_OFFSET 0
36
Marek Vasutf3b8bf72017-07-21 23:18:03 +020037/*
Marek Vasutf3b8bf72017-07-21 23:18:03 +020038 * SDn Clock
39 */
40#define CPG_SD_STP_HCK BIT(9)
41#define CPG_SD_STP_CK BIT(8)
42
43#define CPG_SD_STP_MASK (CPG_SD_STP_HCK | CPG_SD_STP_CK)
44#define CPG_SD_FC_MASK (0x7 << 2 | 0x3 << 0)
45
46#define CPG_SD_DIV_TABLE_DATA(stp_hck, stp_ck, sd_srcfc, sd_fc, sd_div) \
47{ \
48 .val = ((stp_hck) ? CPG_SD_STP_HCK : 0) | \
49 ((stp_ck) ? CPG_SD_STP_CK : 0) | \
50 ((sd_srcfc) << 2) | \
51 ((sd_fc) << 0), \
52 .div = (sd_div), \
53}
54
55struct sd_div_table {
56 u32 val;
57 unsigned int div;
58};
59
60/* SDn divider
61 * sd_srcfc sd_fc div
62 * stp_hck stp_ck (div) (div) = sd_srcfc x sd_fc
63 *-------------------------------------------------------------------
64 * 0 0 0 (1) 1 (4) 4
65 * 0 0 1 (2) 1 (4) 8
66 * 1 0 2 (4) 1 (4) 16
67 * 1 0 3 (8) 1 (4) 32
68 * 1 0 4 (16) 1 (4) 64
69 * 0 0 0 (1) 0 (2) 2
70 * 0 0 1 (2) 0 (2) 4
71 * 1 0 2 (4) 0 (2) 8
72 * 1 0 3 (8) 0 (2) 16
73 * 1 0 4 (16) 0 (2) 32
74 */
75static const struct sd_div_table cpg_sd_div_table[] = {
76/* CPG_SD_DIV_TABLE_DATA(stp_hck, stp_ck, sd_srcfc, sd_fc, sd_div) */
77 CPG_SD_DIV_TABLE_DATA(0, 0, 0, 1, 4),
78 CPG_SD_DIV_TABLE_DATA(0, 0, 1, 1, 8),
79 CPG_SD_DIV_TABLE_DATA(1, 0, 2, 1, 16),
80 CPG_SD_DIV_TABLE_DATA(1, 0, 3, 1, 32),
81 CPG_SD_DIV_TABLE_DATA(1, 0, 4, 1, 64),
82 CPG_SD_DIV_TABLE_DATA(0, 0, 0, 0, 2),
83 CPG_SD_DIV_TABLE_DATA(0, 0, 1, 0, 4),
84 CPG_SD_DIV_TABLE_DATA(1, 0, 2, 0, 8),
85 CPG_SD_DIV_TABLE_DATA(1, 0, 3, 0, 16),
86 CPG_SD_DIV_TABLE_DATA(1, 0, 4, 0, 32),
87};
88
Marek Vasut69459b22018-05-31 19:47:42 +020089static int gen3_clk_get_parent(struct gen3_clk_priv *priv, struct clk *clk,
90 struct cpg_mssr_info *info, struct clk *parent)
91{
92 const struct cpg_core_clk *core;
93 int ret;
94
95 if (!renesas_clk_is_mod(clk)) {
96 ret = renesas_clk_get_core(clk, info, &core);
97 if (ret)
98 return ret;
99
Marek Vasut78414832019-03-04 21:38:10 +0100100 if (core->type == CLK_TYPE_GEN3_MDSEL) {
Marek Vasut69459b22018-05-31 19:47:42 +0200101 parent->dev = clk->dev;
102 parent->id = core->parent >> (priv->sscg ? 16 : 0);
103 parent->id &= 0xffff;
104 return 0;
105 }
106 }
107
108 return renesas_clk_get_parent(clk, info, parent);
109}
110
Marek Vasutc26bf892018-10-30 17:54:20 +0100111static int gen3_clk_setup_sdif_div(struct clk *clk, ulong rate)
Marek Vasut5a51be52017-09-15 21:10:08 +0200112{
113 struct gen3_clk_priv *priv = dev_get_priv(clk->dev);
Marek Vasute11008b2018-01-15 16:44:39 +0100114 struct cpg_mssr_info *info = priv->info;
Marek Vasut5a51be52017-09-15 21:10:08 +0200115 const struct cpg_core_clk *core;
116 struct clk parent;
117 int ret;
118
Marek Vasut69459b22018-05-31 19:47:42 +0200119 ret = gen3_clk_get_parent(priv, clk, info, &parent);
Marek Vasut5a51be52017-09-15 21:10:08 +0200120 if (ret) {
121 printf("%s[%i] parent fail, ret=%i\n", __func__, __LINE__, ret);
122 return ret;
123 }
124
Marek Vasute11008b2018-01-15 16:44:39 +0100125 if (renesas_clk_is_mod(&parent))
Marek Vasut5a51be52017-09-15 21:10:08 +0200126 return 0;
127
Marek Vasute11008b2018-01-15 16:44:39 +0100128 ret = renesas_clk_get_core(&parent, info, &core);
Marek Vasut5a51be52017-09-15 21:10:08 +0200129 if (ret)
130 return ret;
131
132 if (core->type != CLK_TYPE_GEN3_SD)
133 return 0;
134
135 debug("%s[%i] SDIF offset=%x\n", __func__, __LINE__, core->offset);
136
Marek Vasutc26bf892018-10-30 17:54:20 +0100137 writel((rate == 400000000) ? 0x4 : 0x1, priv->base + core->offset);
Marek Vasut5a51be52017-09-15 21:10:08 +0200138
139 return 0;
140}
141
Marek Vasute11008b2018-01-15 16:44:39 +0100142static int gen3_clk_enable(struct clk *clk)
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200143{
144 struct gen3_clk_priv *priv = dev_get_priv(clk->dev);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200145
Hai Pham5460ee02020-05-22 10:39:04 +0700146 return renesas_clk_endisable(clk, priv->base, priv->info, true);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200147}
148
149static int gen3_clk_disable(struct clk *clk)
150{
Marek Vasute11008b2018-01-15 16:44:39 +0100151 struct gen3_clk_priv *priv = dev_get_priv(clk->dev);
152
Hai Pham5460ee02020-05-22 10:39:04 +0700153 return renesas_clk_endisable(clk, priv->base, priv->info, false);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200154}
155
Marek Vasut8f567862021-04-27 19:36:39 +0200156static u64 gen3_clk_get_rate64(struct clk *clk);
157
158static u64 gen3_clk_get_rate64_pll_mul_reg(struct gen3_clk_priv *priv,
159 struct clk *parent,
160 const struct cpg_core_clk *core,
161 u32 mul_reg, u32 mult, u32 div,
162 char *name)
163{
164 u32 value;
165 u64 rate;
166
167 if (mul_reg) {
168 value = readl(priv->base + mul_reg);
169 mult = (((value >> 24) & 0x7f) + 1) * 2;
170 div = 1;
171 }
172
173 rate = (gen3_clk_get_rate64(parent) * mult) / div;
174
175 debug("%s[%i] %s clk: parent=%i mult=%u div=%u => rate=%llu\n",
176 __func__, __LINE__, name, core->parent, mult, div, rate);
177 return rate;
178}
179
Marek Vasut7571ac42018-05-31 19:06:02 +0200180static u64 gen3_clk_get_rate64(struct clk *clk)
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200181{
182 struct gen3_clk_priv *priv = dev_get_priv(clk->dev);
Marek Vasutb9234192018-01-08 16:05:28 +0100183 struct cpg_mssr_info *info = priv->info;
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200184 struct clk parent;
185 const struct cpg_core_clk *core;
186 const struct rcar_gen3_cpg_pll_config *pll_config =
187 priv->cpg_pll_config;
Marek Vasut8f567862021-04-27 19:36:39 +0200188 u32 value, div, prediv, postdiv;
Marek Vasut7571ac42018-05-31 19:06:02 +0200189 u64 rate = 0;
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200190 int i, ret;
191
192 debug("%s[%i] Clock: id=%lu\n", __func__, __LINE__, clk->id);
193
Marek Vasut69459b22018-05-31 19:47:42 +0200194 ret = gen3_clk_get_parent(priv, clk, info, &parent);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200195 if (ret) {
196 printf("%s[%i] parent fail, ret=%i\n", __func__, __LINE__, ret);
197 return ret;
198 }
199
Marek Vasute11008b2018-01-15 16:44:39 +0100200 if (renesas_clk_is_mod(clk)) {
Marek Vasut7571ac42018-05-31 19:06:02 +0200201 rate = gen3_clk_get_rate64(&parent);
202 debug("%s[%i] MOD clk: parent=%lu => rate=%llu\n",
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200203 __func__, __LINE__, parent.id, rate);
204 return rate;
205 }
206
Marek Vasute11008b2018-01-15 16:44:39 +0100207 ret = renesas_clk_get_core(clk, info, &core);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200208 if (ret)
209 return ret;
210
211 switch (core->type) {
212 case CLK_TYPE_IN:
Marek Vasutb9234192018-01-08 16:05:28 +0100213 if (core->id == info->clk_extal_id) {
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200214 rate = clk_get_rate(&priv->clk_extal);
Marek Vasut7571ac42018-05-31 19:06:02 +0200215 debug("%s[%i] EXTAL clk: rate=%llu\n",
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200216 __func__, __LINE__, rate);
217 return rate;
218 }
219
Marek Vasutb9234192018-01-08 16:05:28 +0100220 if (core->id == info->clk_extalr_id) {
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200221 rate = clk_get_rate(&priv->clk_extalr);
Marek Vasut7571ac42018-05-31 19:06:02 +0200222 debug("%s[%i] EXTALR clk: rate=%llu\n",
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200223 __func__, __LINE__, rate);
224 return rate;
225 }
226
227 return -EINVAL;
228
229 case CLK_TYPE_GEN3_MAIN:
Marek Vasut8f567862021-04-27 19:36:39 +0200230 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
231 0, 1, pll_config->extal_div,
232 "MAIN");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200233
234 case CLK_TYPE_GEN3_PLL0:
Marek Vasut8f567862021-04-27 19:36:39 +0200235 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
236 CPG_PLL0CR, 0, 0, "PLL0");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200237
238 case CLK_TYPE_GEN3_PLL1:
Marek Vasut8f567862021-04-27 19:36:39 +0200239 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
240 0, pll_config->pll1_mult,
241 pll_config->pll1_div, "PLL1");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200242
243 case CLK_TYPE_GEN3_PLL2:
Marek Vasut8f567862021-04-27 19:36:39 +0200244 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
245 CPG_PLL2CR, 0, 0, "PLL2");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200246
247 case CLK_TYPE_GEN3_PLL3:
Marek Vasut8f567862021-04-27 19:36:39 +0200248 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
249 0, pll_config->pll3_mult,
250 pll_config->pll3_div, "PLL3");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200251
252 case CLK_TYPE_GEN3_PLL4:
Marek Vasut8f567862021-04-27 19:36:39 +0200253 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
254 CPG_PLL4CR, 0, 0, "PLL4");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200255
Marek Vasut569acef2023-01-26 21:01:56 +0100256 case CLK_TYPE_GEN4_MAIN:
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200257 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
258 0, 1, pll_config->extal_div,
259 "V3U_MAIN");
260
Marek Vasut569acef2023-01-26 21:01:56 +0100261 case CLK_TYPE_GEN4_PLL1:
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200262 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
263 0, pll_config->pll1_mult,
264 pll_config->pll1_div,
265 "V3U_PLL1");
266
Marek Vasut569acef2023-01-26 21:01:56 +0100267 case CLK_TYPE_GEN4_PLL2X_3X:
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200268 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
269 core->offset, 0, 0,
270 "V3U_PLL2X_3X");
271
Marek Vasut569acef2023-01-26 21:01:56 +0100272 case CLK_TYPE_GEN4_PLL5:
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200273 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
274 0, pll_config->pll5_mult,
275 pll_config->pll5_div,
276 "V3U_PLL5");
277
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200278 case CLK_TYPE_FF:
Marek Vasut8f567862021-04-27 19:36:39 +0200279 return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, core,
280 0, core->mult, core->div,
281 "FIXED");
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200282
Marek Vasut78414832019-03-04 21:38:10 +0100283 case CLK_TYPE_GEN3_MDSEL:
Marek Vasut69459b22018-05-31 19:47:42 +0200284 div = (core->div >> (priv->sscg ? 16 : 0)) & 0xffff;
285 rate = gen3_clk_get_rate64(&parent) / div;
286 debug("%s[%i] PE clk: parent=%i div=%u => rate=%llu\n",
287 __func__, __LINE__,
288 (core->parent >> (priv->sscg ? 16 : 0)) & 0xffff,
289 div, rate);
290 return rate;
291
Hai Pham0985e0e2023-01-26 21:01:49 +0100292 case CLK_TYPE_GEN3_SDH: /* Fixed factor 1:1 */
Marek Vasut569acef2023-01-26 21:01:56 +0100293 fallthrough;
294 case CLK_TYPE_GEN4_SDH: /* Fixed factor 1:1 */
Hai Pham0985e0e2023-01-26 21:01:49 +0100295 return gen3_clk_get_rate64(&parent);
296
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200297 case CLK_TYPE_GEN3_SD: /* FIXME */
Marek Vasut0fbb8a72021-04-27 19:52:53 +0200298 fallthrough;
Marek Vasut569acef2023-01-26 21:01:56 +0100299 case CLK_TYPE_GEN4_SD:
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200300 value = readl(priv->base + core->offset);
301 value &= CPG_SD_STP_MASK | CPG_SD_FC_MASK;
302
303 for (i = 0; i < ARRAY_SIZE(cpg_sd_div_table); i++) {
304 if (cpg_sd_div_table[i].val != value)
305 continue;
306
Marek Vasut7571ac42018-05-31 19:06:02 +0200307 rate = gen3_clk_get_rate64(&parent) /
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200308 cpg_sd_div_table[i].div;
Marek Vasut7571ac42018-05-31 19:06:02 +0200309 debug("%s[%i] SD clk: parent=%i div=%i => rate=%llu\n",
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200310 __func__, __LINE__,
311 core->parent, cpg_sd_div_table[i].div, rate);
312
313 return rate;
314 }
315
316 return -EINVAL;
Marek Vasutc1aee322017-09-15 21:10:29 +0200317
318 case CLK_TYPE_GEN3_RPC:
Hai Pham215de2b2020-08-11 10:25:28 +0700319 case CLK_TYPE_GEN3_RPCD2:
Marek Vasut569acef2023-01-26 21:01:56 +0100320 case CLK_TYPE_GEN4_RPC:
321 case CLK_TYPE_GEN4_RPCD2:
Marek Vasut7571ac42018-05-31 19:06:02 +0200322 rate = gen3_clk_get_rate64(&parent);
Marek Vasutc1aee322017-09-15 21:10:29 +0200323
324 value = readl(priv->base + core->offset);
325
326 prediv = (value >> CPG_RPC_PREDIV_OFFSET) &
327 CPG_RPC_PREDIV_MASK;
328 if (prediv == 2)
329 rate /= 5;
330 else if (prediv == 3)
331 rate /= 6;
332 else
333 return -EINVAL;
334
335 postdiv = (value >> CPG_RPC_POSTDIV_OFFSET) &
336 CPG_RPC_POSTDIV_MASK;
Marek Vasutc1aee322017-09-15 21:10:29 +0200337
Hai Pham215de2b2020-08-11 10:25:28 +0700338 if (postdiv % 2 != 0) {
339 rate /= postdiv + 1;
340
341 if (core->type == CLK_TYPE_GEN3_RPCD2)
342 rate /= 2;
343
344 debug("%s[%i] RPC clk: parent=%i prediv=%i postdiv=%i => rate=%llu\n",
345 __func__, __LINE__,
346 core->parent, prediv, postdiv, rate);
347
348 return rate;
349 }
Marek Vasutc1aee322017-09-15 21:10:29 +0200350
Hai Pham215de2b2020-08-11 10:25:28 +0700351 return -EINVAL;
Marek Vasutc1aee322017-09-15 21:10:29 +0200352
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200353 }
354
355 printf("%s[%i] unknown fail\n", __func__, __LINE__);
356
357 return -ENOENT;
358}
359
Marek Vasut7571ac42018-05-31 19:06:02 +0200360static ulong gen3_clk_get_rate(struct clk *clk)
361{
362 return gen3_clk_get_rate64(clk);
363}
364
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200365static ulong gen3_clk_set_rate(struct clk *clk, ulong rate)
366{
Marek Vasut414dbbe2018-01-11 16:28:31 +0100367 /* Force correct SD-IF divider configuration if applicable */
Marek Vasutc26bf892018-10-30 17:54:20 +0100368 gen3_clk_setup_sdif_div(clk, rate);
Marek Vasut7571ac42018-05-31 19:06:02 +0200369 return gen3_clk_get_rate64(clk);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200370}
371
372static int gen3_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args)
373{
374 if (args->args_count != 2) {
Sean Andersona1b654b2021-12-01 14:26:53 -0500375 debug("Invalid args_count: %d\n", args->args_count);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200376 return -EINVAL;
377 }
378
379 clk->id = (args->args[0] << 16) | args->args[1];
380
381 return 0;
382}
383
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100384const struct clk_ops gen3_clk_ops = {
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200385 .enable = gen3_clk_enable,
386 .disable = gen3_clk_disable,
387 .get_rate = gen3_clk_get_rate,
388 .set_rate = gen3_clk_set_rate,
389 .of_xlate = gen3_clk_of_xlate,
390};
391
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100392int gen3_clk_probe(struct udevice *dev)
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200393{
394 struct gen3_clk_priv *priv = dev_get_priv(dev);
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100395 struct cpg_mssr_info *info =
396 (struct cpg_mssr_info *)dev_get_driver_data(dev);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200397 fdt_addr_t rst_base;
398 u32 cpg_mode;
399 int ret;
400
Masahiro Yamada1096ae12020-07-17 14:36:46 +0900401 priv->base = dev_read_addr_ptr(dev);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200402 if (!priv->base)
403 return -EINVAL;
404
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100405 priv->info = info;
406 ret = fdt_node_offset_by_compatible(gd->fdt_blob, -1, info->reset_node);
407 if (ret < 0)
408 return ret;
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200409
410 rst_base = fdtdec_get_addr(gd->fdt_blob, ret, "reg");
411 if (rst_base == FDT_ADDR_T_NONE)
412 return -EINVAL;
413
Marek Vasut814217e2021-04-25 21:53:05 +0200414 cpg_mode = readl(rst_base + info->reset_modemr_offset);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200415
Marek Vasut28f90042018-01-16 19:23:17 +0100416 priv->cpg_pll_config =
417 (struct rcar_gen3_cpg_pll_config *)info->get_pll_config(cpg_mode);
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200418 if (!priv->cpg_pll_config->extal_div)
419 return -EINVAL;
420
Marek Vasut69459b22018-05-31 19:47:42 +0200421 priv->sscg = !(cpg_mode & BIT(12));
422
Hai Pham94803462020-11-05 22:30:37 +0700423 if (info->reg_layout == CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3) {
424 priv->info->status_regs = mstpsr;
425 priv->info->control_regs = smstpcr;
426 priv->info->reset_regs = srcr;
427 priv->info->reset_clear_regs = srstclr;
Hai Pham86d59f32020-08-11 10:46:34 +0700428 } else if (info->reg_layout == CLK_REG_LAYOUT_RCAR_V3U) {
429 priv->info->status_regs = mstpsr_for_v3u;
430 priv->info->control_regs = mstpcr_for_v3u;
431 priv->info->reset_regs = srcr_for_v3u;
432 priv->info->reset_clear_regs = srstclr_for_v3u;
Hai Pham94803462020-11-05 22:30:37 +0700433 } else {
434 return -EINVAL;
435 }
436
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200437 ret = clk_get_by_name(dev, "extal", &priv->clk_extal);
438 if (ret < 0)
439 return ret;
440
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100441 if (info->extalr_node) {
442 ret = clk_get_by_name(dev, info->extalr_node, &priv->clk_extalr);
Marek Vasutfb0aa292017-10-08 21:09:15 +0200443 if (ret < 0)
444 return ret;
445 }
Marek Vasutf3b8bf72017-07-21 23:18:03 +0200446
447 return 0;
448}
449
Marek Vasut4eb4e6e2018-01-08 14:01:40 +0100450int gen3_clk_remove(struct udevice *dev)
Marek Vasutdf6a1142017-11-25 22:08:55 +0100451{
452 struct gen3_clk_priv *priv = dev_get_priv(dev);
Marek Vasutdf6a1142017-11-25 22:08:55 +0100453
Marek Vasute11008b2018-01-15 16:44:39 +0100454 return renesas_clk_remove(priv->base, priv->info);
Marek Vasutdf6a1142017-11-25 22:08:55 +0100455}