Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 2 | /* |
Marek Vasut | 3f1a3a1 | 2017-10-09 20:52:33 +0200 | [diff] [blame] | 3 | * Renesas RCar Gen3 CPG MSSR driver |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 4 | * |
| 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 Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 13 | #include <clk-uclass.h> |
| 14 | #include <dm.h> |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 15 | #include <dm/device-internal.h> |
| 16 | #include <dm/lists.h> |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 17 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 18 | #include <log.h> |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 19 | #include <wait_bit.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 21 | #include <asm/io.h> |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 22 | #include <linux/bitfield.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 23 | #include <linux/bitops.h> |
Marek Vasut | b2970fd | 2023-01-26 21:06:02 +0100 | [diff] [blame] | 24 | #include <linux/clk-provider.h> |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 25 | #include <reset-uclass.h> |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 26 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 27 | #include <dt-bindings/clock/renesas-cpg-mssr.h> |
| 28 | |
| 29 | #include "renesas-cpg-mssr.h" |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 30 | #include "rcar-gen3-cpg.h" |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 31 | #include "rcar-cpg-lib.h" |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 32 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 33 | #define CPG_PLL0CR 0x00d8 |
| 34 | #define CPG_PLL2CR 0x002c |
| 35 | #define CPG_PLL4CR 0x01f4 |
| 36 | |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 37 | #define SD0CKCR1 0x08a4 |
| 38 | |
| 39 | static const struct clk_div_table gen3_cpg_rpcsrc_div_table[] = { |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 40 | { 2, 5 }, { 3, 6 }, { 0, 0 }, |
| 41 | }; |
| 42 | |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 43 | static const struct clk_div_table gen4_cpg_rpcsrc_div_table[] = { |
| 44 | { 0, 4 }, { 1, 6 }, { 2, 5 }, { 3, 6 }, { 0, 0 }, |
| 45 | }; |
| 46 | |
Hai Pham | 6811b57 | 2023-01-26 21:06:06 +0100 | [diff] [blame] | 47 | static const struct clk_div_table r8a77970_cpg_sd0h_div_table[] = { |
| 48 | { 0, 2 }, { 1, 3 }, { 2, 4 }, { 3, 6 }, |
| 49 | { 4, 8 }, { 5, 12 }, { 6, 16 }, { 7, 18 }, |
| 50 | { 8, 24 }, { 10, 36 }, { 11, 48 }, { 0, 0 }, |
| 51 | }; |
| 52 | |
| 53 | static const struct clk_div_table r8a77970_cpg_sd0_div_table[] = { |
| 54 | { 4, 8 }, { 5, 12 }, { 6, 16 }, { 7, 18 }, |
| 55 | { 8, 24 }, { 10, 36 }, { 11, 48 }, { 12, 10 }, |
| 56 | { 0, 0 }, |
| 57 | }; |
| 58 | |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 59 | static int gen3_clk_get_parent(struct gen3_clk_priv *priv, struct clk *clk, |
| 60 | struct cpg_mssr_info *info, struct clk *parent) |
| 61 | { |
| 62 | const struct cpg_core_clk *core; |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 63 | u8 shift; |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 64 | int ret; |
| 65 | |
| 66 | if (!renesas_clk_is_mod(clk)) { |
| 67 | ret = renesas_clk_get_core(clk, info, &core); |
| 68 | if (ret) |
| 69 | return ret; |
| 70 | |
Marek Vasut | 7841483 | 2019-03-04 21:38:10 +0100 | [diff] [blame] | 71 | if (core->type == CLK_TYPE_GEN3_MDSEL) { |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 72 | shift = priv->cpg_mode & BIT(core->offset) ? 16 : 0; |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 73 | parent->dev = clk->dev; |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 74 | parent->id = core->parent >> shift; |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 75 | parent->id &= 0xffff; |
| 76 | return 0; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return renesas_clk_get_parent(clk, info, parent); |
| 81 | } |
| 82 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 83 | static int gen3_clk_enable(struct clk *clk) |
| 84 | { |
| 85 | struct gen3_clk_priv *priv = dev_get_priv(clk->dev); |
| 86 | |
| 87 | return renesas_clk_endisable(clk, priv->base, priv->info, true); |
| 88 | } |
| 89 | |
| 90 | static int gen3_clk_disable(struct clk *clk) |
| 91 | { |
| 92 | struct gen3_clk_priv *priv = dev_get_priv(clk->dev); |
| 93 | |
| 94 | return renesas_clk_endisable(clk, priv->base, priv->info, false); |
| 95 | } |
| 96 | |
| 97 | static u64 gen3_clk_get_rate64(struct clk *clk); |
| 98 | |
Marek Vasut | c26bf89 | 2018-10-30 17:54:20 +0100 | [diff] [blame] | 99 | static int gen3_clk_setup_sdif_div(struct clk *clk, ulong rate) |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 100 | { |
| 101 | struct gen3_clk_priv *priv = dev_get_priv(clk->dev); |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 102 | struct cpg_mssr_info *info = priv->info; |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 103 | const struct cpg_core_clk *core; |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 104 | struct clk parent, grandparent; |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 105 | int ret; |
| 106 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 107 | /* |
| 108 | * The clk may be either CPG_MOD or core clock, in case this is MOD |
| 109 | * clock, use core clock one level up, otherwise use the clock as-is. |
| 110 | * Note that parent clock here always represents core clock. Also note |
| 111 | * that grandparent clock are the parent clock of the core clock here. |
| 112 | */ |
| 113 | if (renesas_clk_is_mod(clk)) { |
| 114 | ret = gen3_clk_get_parent(priv, clk, info, &parent); |
| 115 | if (ret) { |
| 116 | printf("%s[%i] parent fail, ret=%i\n", __func__, __LINE__, ret); |
| 117 | return ret; |
| 118 | } |
| 119 | } else { |
| 120 | parent = *clk; |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 123 | if (renesas_clk_is_mod(&parent)) |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 124 | return 0; |
| 125 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 126 | ret = renesas_clk_get_core(&parent, info, &core); |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 127 | if (ret) |
| 128 | return ret; |
| 129 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 130 | ret = renesas_clk_get_parent(&parent, info, &grandparent); |
| 131 | if (ret) { |
| 132 | printf("%s[%i] grandparent fail, ret=%i\n", __func__, __LINE__, ret); |
| 133 | return ret; |
| 134 | } |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 135 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 136 | switch (core->type) { |
| 137 | case CLK_TYPE_GEN3_SDH: |
| 138 | fallthrough; |
| 139 | case CLK_TYPE_GEN4_SDH: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 140 | return rcar_clk_set_rate64_sdh(core->parent, |
| 141 | gen3_clk_get_rate64(&grandparent), |
| 142 | rate, priv->base + core->offset); |
Marek Vasut | 5a51be5 | 2017-09-15 21:10:08 +0200 | [diff] [blame] | 143 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 144 | case CLK_TYPE_GEN3_SD: |
| 145 | fallthrough; |
| 146 | case CLK_TYPE_GEN4_SD: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 147 | return rcar_clk_set_rate64_sd(core->parent, |
| 148 | gen3_clk_get_rate64(&grandparent), |
| 149 | rate, priv->base + core->offset); |
Hai Pham | 6811b57 | 2023-01-26 21:06:06 +0100 | [diff] [blame] | 150 | |
| 151 | case CLK_TYPE_R8A77970_SD0: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 152 | return rcar_clk_set_rate64_div_table(core->parent, |
| 153 | gen3_clk_get_rate64(&grandparent), |
| 154 | rate, priv->base + core->offset, |
| 155 | CPG_SDCKCR_SD0FC_MASK, |
| 156 | r8a77970_cpg_sd0_div_table, "SD"); |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 157 | } |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 158 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 159 | return 0; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 162 | static u64 gen3_clk_get_rate64_pll_mul_reg(struct gen3_clk_priv *priv, |
| 163 | struct clk *parent, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 164 | u32 mul_reg, u32 mult, u32 div, |
| 165 | char *name) |
| 166 | { |
| 167 | u32 value; |
| 168 | u64 rate; |
| 169 | |
| 170 | if (mul_reg) { |
| 171 | value = readl(priv->base + mul_reg); |
| 172 | mult = (((value >> 24) & 0x7f) + 1) * 2; |
| 173 | div = 1; |
| 174 | } |
| 175 | |
| 176 | rate = (gen3_clk_get_rate64(parent) * mult) / div; |
| 177 | |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 178 | debug("%s[%i] %s clk: mult=%u div=%u => rate=%llu\n", |
| 179 | __func__, __LINE__, name, mult, div, rate); |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 180 | return rate; |
| 181 | } |
| 182 | |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 183 | static u64 gen3_clk_get_rate64(struct clk *clk) |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 184 | { |
| 185 | struct gen3_clk_priv *priv = dev_get_priv(clk->dev); |
Marek Vasut | b923419 | 2018-01-08 16:05:28 +0100 | [diff] [blame] | 186 | struct cpg_mssr_info *info = priv->info; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 187 | struct clk parent; |
| 188 | const struct cpg_core_clk *core; |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 189 | const struct rcar_gen3_cpg_pll_config *gen3_pll_config = |
| 190 | priv->gen3_cpg_pll_config; |
| 191 | const struct rcar_gen4_cpg_pll_config *gen4_pll_config = |
| 192 | priv->gen4_cpg_pll_config; |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 193 | u32 value, div; |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 194 | u64 rate = 0; |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 195 | u8 shift; |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 196 | int ret; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 197 | |
| 198 | debug("%s[%i] Clock: id=%lu\n", __func__, __LINE__, clk->id); |
| 199 | |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 200 | ret = gen3_clk_get_parent(priv, clk, info, &parent); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 201 | if (ret) { |
| 202 | printf("%s[%i] parent fail, ret=%i\n", __func__, __LINE__, ret); |
| 203 | return ret; |
| 204 | } |
| 205 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 206 | if (renesas_clk_is_mod(clk)) { |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 207 | rate = gen3_clk_get_rate64(&parent); |
| 208 | debug("%s[%i] MOD clk: parent=%lu => rate=%llu\n", |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 209 | __func__, __LINE__, parent.id, rate); |
| 210 | return rate; |
| 211 | } |
| 212 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 213 | ret = renesas_clk_get_core(clk, info, &core); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 214 | if (ret) |
| 215 | return ret; |
| 216 | |
| 217 | switch (core->type) { |
| 218 | case CLK_TYPE_IN: |
Marek Vasut | b923419 | 2018-01-08 16:05:28 +0100 | [diff] [blame] | 219 | if (core->id == info->clk_extal_id) { |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 220 | rate = clk_get_rate(&priv->clk_extal); |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 221 | debug("%s[%i] EXTAL clk: rate=%llu\n", |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 222 | __func__, __LINE__, rate); |
| 223 | return rate; |
| 224 | } |
| 225 | |
Marek Vasut | b923419 | 2018-01-08 16:05:28 +0100 | [diff] [blame] | 226 | if (core->id == info->clk_extalr_id) { |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 227 | rate = clk_get_rate(&priv->clk_extalr); |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 228 | debug("%s[%i] EXTALR clk: rate=%llu\n", |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 229 | __func__, __LINE__, rate); |
| 230 | return rate; |
| 231 | } |
| 232 | |
| 233 | return -EINVAL; |
| 234 | |
| 235 | case CLK_TYPE_GEN3_MAIN: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 236 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 237 | 0, 1, gen3_pll_config->extal_div, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 238 | "MAIN"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 239 | |
| 240 | case CLK_TYPE_GEN3_PLL0: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 241 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 242 | CPG_PLL0CR, 0, 0, "PLL0"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 243 | |
| 244 | case CLK_TYPE_GEN3_PLL1: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 245 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 246 | 0, gen3_pll_config->pll1_mult, |
| 247 | gen3_pll_config->pll1_div, |
| 248 | "PLL1"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 249 | |
| 250 | case CLK_TYPE_GEN3_PLL2: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 251 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 252 | CPG_PLL2CR, 0, 0, "PLL2"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 253 | |
| 254 | case CLK_TYPE_GEN3_PLL3: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 255 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 256 | 0, gen3_pll_config->pll3_mult, |
| 257 | gen3_pll_config->pll3_div, |
| 258 | "PLL3"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 259 | |
| 260 | case CLK_TYPE_GEN3_PLL4: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 261 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 262 | CPG_PLL4CR, 0, 0, "PLL4"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 263 | |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 264 | case CLK_TYPE_GEN4_MAIN: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 265 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 266 | 0, 1, gen4_pll_config->extal_div, |
| 267 | "MAIN"); |
Marek Vasut | 0fbb8a7 | 2021-04-27 19:52:53 +0200 | [diff] [blame] | 268 | |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 269 | case CLK_TYPE_GEN4_PLL1: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 270 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 271 | 0, gen4_pll_config->pll1_mult, |
| 272 | gen4_pll_config->pll1_div, |
| 273 | "PLL1"); |
| 274 | |
| 275 | case CLK_TYPE_GEN4_PLL2: |
| 276 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
| 277 | 0, gen4_pll_config->pll2_mult, |
| 278 | gen4_pll_config->pll2_div, |
| 279 | "PLL2"); |
Marek Vasut | 0fbb8a7 | 2021-04-27 19:52:53 +0200 | [diff] [blame] | 280 | |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 281 | case CLK_TYPE_GEN4_PLL2X_3X: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 282 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 283 | core->offset, 0, 0, "PLL2X_3X"); |
| 284 | |
| 285 | case CLK_TYPE_GEN4_PLL3: |
| 286 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
| 287 | 0, gen4_pll_config->pll3_mult, |
| 288 | gen4_pll_config->pll3_div, |
| 289 | "PLL3"); |
| 290 | |
| 291 | case CLK_TYPE_GEN4_PLL4: |
| 292 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
| 293 | 0, gen4_pll_config->pll4_mult, |
| 294 | gen4_pll_config->pll4_div, |
| 295 | "PLL4"); |
Marek Vasut | 0fbb8a7 | 2021-04-27 19:52:53 +0200 | [diff] [blame] | 296 | |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 297 | case CLK_TYPE_GEN4_PLL5: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 298 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 299 | 0, gen4_pll_config->pll5_mult, |
| 300 | gen4_pll_config->pll5_div, |
| 301 | "PLL5"); |
| 302 | |
| 303 | case CLK_TYPE_GEN4_PLL6: |
| 304 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
| 305 | 0, gen4_pll_config->pll6_mult, |
| 306 | gen4_pll_config->pll6_div, |
| 307 | "PLL6"); |
Marek Vasut | 0fbb8a7 | 2021-04-27 19:52:53 +0200 | [diff] [blame] | 308 | |
Marek Vasut | 55f0826 | 2024-01-28 16:52:02 +0100 | [diff] [blame] | 309 | case CLK_TYPE_GEN4_PLL7: |
| 310 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
| 311 | 0, gen4_pll_config->pll7_mult, |
| 312 | gen4_pll_config->pll7_div, |
| 313 | "PLL7"); |
| 314 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 315 | case CLK_TYPE_FF: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 316 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 317 | 0, core->mult, core->div, |
| 318 | "FIXED"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 319 | |
Marek Vasut | 7841483 | 2019-03-04 21:38:10 +0100 | [diff] [blame] | 320 | case CLK_TYPE_GEN3_MDSEL: |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 321 | shift = priv->cpg_mode & BIT(core->offset) ? 16 : 0; |
| 322 | div = (core->div >> shift) & 0xffff; |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 323 | rate = gen3_clk_get_rate64(&parent) / div; |
| 324 | debug("%s[%i] PE clk: parent=%i div=%u => rate=%llu\n", |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 325 | __func__, __LINE__, (core->parent >> shift) & 0xffff, |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 326 | div, rate); |
| 327 | return rate; |
| 328 | |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 329 | case CLK_TYPE_GEN4_SDSRC: |
| 330 | div = ((readl(priv->base + SD0CKCR1) >> 29) & 0x03) + 4; |
| 331 | rate = gen3_clk_get_rate64(&parent) / div; |
| 332 | debug("%s[%i] SDSRC clk: parent=%i div=%u => rate=%llu\n", |
| 333 | __func__, __LINE__, core->parent, div, rate); |
| 334 | return rate; |
| 335 | |
Hai Pham | 0985e0e | 2023-01-26 21:01:49 +0100 | [diff] [blame] | 336 | case CLK_TYPE_GEN3_SDH: /* Fixed factor 1:1 */ |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 337 | fallthrough; |
| 338 | case CLK_TYPE_GEN4_SDH: /* Fixed factor 1:1 */ |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 339 | return rcar_clk_get_rate64_sdh(core->parent, |
| 340 | gen3_clk_get_rate64(&parent), |
| 341 | priv->base + core->offset); |
Hai Pham | 0985e0e | 2023-01-26 21:01:49 +0100 | [diff] [blame] | 342 | |
Hai Pham | 6811b57 | 2023-01-26 21:06:06 +0100 | [diff] [blame] | 343 | case CLK_TYPE_R8A77970_SD0H: |
| 344 | return rcar_clk_get_rate64_div_table(core->parent, |
| 345 | gen3_clk_get_rate64(&parent), |
| 346 | priv->base + core->offset, |
| 347 | CPG_SDCKCR_SDHFC_MASK, |
| 348 | r8a77970_cpg_sd0h_div_table, "SDH"); |
| 349 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 350 | case CLK_TYPE_GEN3_SD: |
Marek Vasut | 0fbb8a7 | 2021-04-27 19:52:53 +0200 | [diff] [blame] | 351 | fallthrough; |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 352 | case CLK_TYPE_GEN4_SD: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 353 | return rcar_clk_get_rate64_sd(core->parent, |
| 354 | gen3_clk_get_rate64(&parent), |
| 355 | priv->base + core->offset); |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 356 | |
Hai Pham | 6811b57 | 2023-01-26 21:06:06 +0100 | [diff] [blame] | 357 | case CLK_TYPE_R8A77970_SD0: |
| 358 | return rcar_clk_get_rate64_div_table(core->parent, |
| 359 | gen3_clk_get_rate64(&parent), |
| 360 | priv->base + core->offset, |
| 361 | CPG_SDCKCR_SD0FC_MASK, |
| 362 | r8a77970_cpg_sd0_div_table, "SD"); |
| 363 | |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 364 | case CLK_TYPE_GEN3_RPCSRC: |
| 365 | return rcar_clk_get_rate64_div_table(core->parent, |
| 366 | gen3_clk_get_rate64(&parent), |
| 367 | priv->base + CPG_RPCCKCR, |
| 368 | CPG_RPCCKCR_DIV_POST_MASK, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 369 | gen3_cpg_rpcsrc_div_table, |
| 370 | "RPCSRC"); |
| 371 | |
| 372 | case CLK_TYPE_GEN4_RPCSRC: |
| 373 | return rcar_clk_get_rate64_div_table(core->parent, |
| 374 | gen3_clk_get_rate64(&parent), |
| 375 | priv->base + CPG_RPCCKCR, |
| 376 | CPG_RPCCKCR_DIV_POST_MASK, |
| 377 | gen4_cpg_rpcsrc_div_table, |
| 378 | "RPCSRC"); |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 379 | |
Hai Pham | 85e691e | 2023-01-26 21:06:04 +0100 | [diff] [blame] | 380 | case CLK_TYPE_GEN3_D3_RPCSRC: |
| 381 | case CLK_TYPE_GEN3_E3_RPCSRC: |
| 382 | /* |
| 383 | * Register RPCSRC as fixed factor clock based on the |
| 384 | * MD[4:1] pins and CPG_RPCCKCR[4:3] register value for |
| 385 | * which has been set prior to booting the kernel. |
| 386 | */ |
| 387 | value = (readl(priv->base + CPG_RPCCKCR) & GENMASK(4, 3)) >> 3; |
| 388 | |
| 389 | switch (value) { |
| 390 | case 0: |
| 391 | div = 5; |
| 392 | break; |
| 393 | case 1: |
| 394 | div = 3; |
| 395 | break; |
| 396 | case 2: |
| 397 | div = core->div; |
| 398 | break; |
| 399 | case 3: |
| 400 | default: |
| 401 | div = 2; |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | rate = gen3_clk_get_rate64(&parent) / div; |
| 406 | debug("%s[%i] E3/D3 RPCSRC clk: parent=%i div=%u => rate=%llu\n", |
| 407 | __func__, __LINE__, (core->parent >> 16) & 0xffff, div, rate); |
| 408 | |
| 409 | return rate; |
| 410 | |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 411 | case CLK_TYPE_GEN3_RPC: |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 412 | case CLK_TYPE_GEN4_RPC: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 413 | return rcar_clk_get_rate64_rpc(core->parent, |
| 414 | gen3_clk_get_rate64(&parent), |
| 415 | priv->base + CPG_RPCCKCR); |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 416 | |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 417 | case CLK_TYPE_GEN3_RPCD2: |
| 418 | case CLK_TYPE_GEN4_RPCD2: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 419 | return rcar_clk_get_rate64_rpcd2(core->parent, |
| 420 | gen3_clk_get_rate64(&parent)); |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 421 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | printf("%s[%i] unknown fail\n", __func__, __LINE__); |
| 425 | |
| 426 | return -ENOENT; |
| 427 | } |
| 428 | |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 429 | static ulong gen3_clk_get_rate(struct clk *clk) |
| 430 | { |
| 431 | return gen3_clk_get_rate64(clk); |
| 432 | } |
| 433 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 434 | static ulong gen3_clk_set_rate(struct clk *clk, ulong rate) |
| 435 | { |
Marek Vasut | 414dbbe | 2018-01-11 16:28:31 +0100 | [diff] [blame] | 436 | /* Force correct SD-IF divider configuration if applicable */ |
Marek Vasut | c26bf89 | 2018-10-30 17:54:20 +0100 | [diff] [blame] | 437 | gen3_clk_setup_sdif_div(clk, rate); |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 438 | return gen3_clk_get_rate64(clk); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static int gen3_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
| 442 | { |
| 443 | if (args->args_count != 2) { |
Sean Anderson | a1b654b | 2021-12-01 14:26:53 -0500 | [diff] [blame] | 444 | debug("Invalid args_count: %d\n", args->args_count); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 445 | return -EINVAL; |
| 446 | } |
| 447 | |
| 448 | clk->id = (args->args[0] << 16) | args->args[1]; |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 453 | const struct clk_ops gen3_clk_ops = { |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 454 | .enable = gen3_clk_enable, |
| 455 | .disable = gen3_clk_disable, |
| 456 | .get_rate = gen3_clk_get_rate, |
| 457 | .set_rate = gen3_clk_set_rate, |
| 458 | .of_xlate = gen3_clk_of_xlate, |
| 459 | }; |
| 460 | |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 461 | static int gen3_clk_probe(struct udevice *dev) |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 462 | { |
| 463 | struct gen3_clk_priv *priv = dev_get_priv(dev); |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 464 | struct cpg_mssr_info *info = |
| 465 | (struct cpg_mssr_info *)dev_get_driver_data(dev); |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 466 | const void *pll_config; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 467 | fdt_addr_t rst_base; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 468 | int ret; |
| 469 | |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 470 | priv->base = dev_read_addr_ptr(dev); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 471 | if (!priv->base) |
| 472 | return -EINVAL; |
| 473 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 474 | priv->info = info; |
| 475 | ret = fdt_node_offset_by_compatible(gd->fdt_blob, -1, info->reset_node); |
| 476 | if (ret < 0) |
| 477 | return ret; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 478 | |
| 479 | rst_base = fdtdec_get_addr(gd->fdt_blob, ret, "reg"); |
| 480 | if (rst_base == FDT_ADDR_T_NONE) |
| 481 | return -EINVAL; |
| 482 | |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 483 | priv->cpg_mode = readl(rst_base + info->reset_modemr_offset); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 484 | |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 485 | pll_config = info->get_pll_config(priv->cpg_mode); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 486 | |
Hai Pham | 9480346 | 2020-11-05 22:30:37 +0700 | [diff] [blame] | 487 | if (info->reg_layout == CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3) { |
| 488 | priv->info->status_regs = mstpsr; |
| 489 | priv->info->control_regs = smstpcr; |
| 490 | priv->info->reset_regs = srcr; |
| 491 | priv->info->reset_clear_regs = srstclr; |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 492 | priv->gen3_cpg_pll_config = pll_config; |
| 493 | if (!priv->gen3_cpg_pll_config->extal_div) |
| 494 | return -EINVAL; |
| 495 | } else if (info->reg_layout == CLK_REG_LAYOUT_RCAR_GEN4) { |
| 496 | priv->info->status_regs = mstpsr_for_gen4; |
| 497 | priv->info->control_regs = mstpcr_for_gen4; |
| 498 | priv->info->reset_regs = srcr_for_gen4; |
| 499 | priv->info->reset_clear_regs = srstclr_for_gen4; |
| 500 | priv->gen4_cpg_pll_config = pll_config; |
| 501 | if (!priv->gen4_cpg_pll_config->extal_div) |
| 502 | return -EINVAL; |
Hai Pham | 9480346 | 2020-11-05 22:30:37 +0700 | [diff] [blame] | 503 | } else { |
| 504 | return -EINVAL; |
| 505 | } |
| 506 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 507 | ret = clk_get_by_name(dev, "extal", &priv->clk_extal); |
| 508 | if (ret < 0) |
| 509 | return ret; |
| 510 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 511 | if (info->extalr_node) { |
| 512 | ret = clk_get_by_name(dev, info->extalr_node, &priv->clk_extalr); |
Marek Vasut | fb0aa29 | 2017-10-08 21:09:15 +0200 | [diff] [blame] | 513 | if (ret < 0) |
| 514 | return ret; |
| 515 | } |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 520 | static int gen3_clk_remove(struct udevice *dev) |
Marek Vasut | df6a114 | 2017-11-25 22:08:55 +0100 | [diff] [blame] | 521 | { |
| 522 | struct gen3_clk_priv *priv = dev_get_priv(dev); |
Marek Vasut | df6a114 | 2017-11-25 22:08:55 +0100 | [diff] [blame] | 523 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 524 | return renesas_clk_remove(priv->base, priv->info); |
Marek Vasut | df6a114 | 2017-11-25 22:08:55 +0100 | [diff] [blame] | 525 | } |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 526 | |
| 527 | U_BOOT_DRIVER(clk_gen3) = { |
| 528 | .name = "clk_gen3", |
| 529 | .id = UCLASS_CLK, |
| 530 | .priv_auto = sizeof(struct gen3_clk_priv), |
| 531 | .ops = &gen3_clk_ops, |
| 532 | .probe = gen3_clk_probe, |
| 533 | .remove = gen3_clk_remove, |
Marek Vasut | 5ab7ef0 | 2020-04-25 14:57:55 +0200 | [diff] [blame] | 534 | .flags = DM_FLAG_OS_PREPARE | DM_FLAG_VITAL, |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 535 | }; |
| 536 | |
| 537 | static int gen3_reset_assert(struct reset_ctl *reset_ctl) |
| 538 | { |
| 539 | struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev); |
| 540 | struct gen3_clk_priv *priv = dev_get_priv(cdev); |
Marek Vasut | ef5c0b1 | 2023-03-18 12:30:53 +0100 | [diff] [blame] | 541 | unsigned int packed_id = MOD_CLK_PACK(reset_ctl->id); |
| 542 | unsigned int reg = packed_id / 32; |
| 543 | unsigned int bit = packed_id % 32; |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 544 | u32 bitmask = BIT(bit); |
| 545 | |
| 546 | writel(bitmask, priv->base + priv->info->reset_regs[reg]); |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static int gen3_reset_deassert(struct reset_ctl *reset_ctl) |
| 552 | { |
| 553 | struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev); |
| 554 | struct gen3_clk_priv *priv = dev_get_priv(cdev); |
Marek Vasut | ef5c0b1 | 2023-03-18 12:30:53 +0100 | [diff] [blame] | 555 | unsigned int packed_id = MOD_CLK_PACK(reset_ctl->id); |
| 556 | unsigned int reg = packed_id / 32; |
| 557 | unsigned int bit = packed_id % 32; |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 558 | u32 bitmask = BIT(bit); |
| 559 | |
| 560 | writel(bitmask, priv->base + priv->info->reset_clear_regs[reg]); |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static const struct reset_ops rst_gen3_ops = { |
| 566 | .rst_assert = gen3_reset_assert, |
| 567 | .rst_deassert = gen3_reset_deassert, |
| 568 | }; |
| 569 | |
| 570 | U_BOOT_DRIVER(rst_gen3) = { |
| 571 | .name = "rst_gen3", |
| 572 | .id = UCLASS_RESET, |
| 573 | .ops = &rst_gen3_ops, |
Marek Vasut | 5ab7ef0 | 2020-04-25 14:57:55 +0200 | [diff] [blame] | 574 | .flags = DM_FLAG_OS_PREPARE | DM_FLAG_VITAL, |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | int gen3_cpg_bind(struct udevice *parent) |
| 578 | { |
| 579 | struct cpg_mssr_info *info = |
| 580 | (struct cpg_mssr_info *)dev_get_driver_data(parent); |
| 581 | struct udevice *cdev, *rdev; |
| 582 | struct driver *drv; |
| 583 | int ret; |
| 584 | |
| 585 | drv = lists_driver_lookup_name("clk_gen3"); |
| 586 | if (!drv) |
| 587 | return -ENOENT; |
| 588 | |
| 589 | ret = device_bind_with_driver_data(parent, drv, "clk_gen3", (ulong)info, |
| 590 | dev_ofnode(parent), &cdev); |
| 591 | if (ret) |
| 592 | return ret; |
| 593 | |
| 594 | drv = lists_driver_lookup_name("rst_gen3"); |
| 595 | if (!drv) |
| 596 | return -ENOENT; |
| 597 | |
| 598 | ret = device_bind_with_driver_data(parent, drv, "rst_gen3", (ulong)cdev, |
| 599 | dev_ofnode(parent), &rdev); |
| 600 | if (ret) |
| 601 | device_unbind(cdev); |
| 602 | |
| 603 | return ret; |
| 604 | } |