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