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 | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 309 | case CLK_TYPE_FF: |
Marek Vasut | 1bd2521 | 2023-01-26 21:02:05 +0100 | [diff] [blame] | 310 | return gen3_clk_get_rate64_pll_mul_reg(priv, &parent, |
Marek Vasut | 8f56786 | 2021-04-27 19:36:39 +0200 | [diff] [blame] | 311 | 0, core->mult, core->div, |
| 312 | "FIXED"); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 313 | |
Marek Vasut | 7841483 | 2019-03-04 21:38:10 +0100 | [diff] [blame] | 314 | case CLK_TYPE_GEN3_MDSEL: |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 315 | shift = priv->cpg_mode & BIT(core->offset) ? 16 : 0; |
| 316 | div = (core->div >> shift) & 0xffff; |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 317 | rate = gen3_clk_get_rate64(&parent) / div; |
| 318 | debug("%s[%i] PE clk: parent=%i div=%u => rate=%llu\n", |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 319 | __func__, __LINE__, (core->parent >> shift) & 0xffff, |
Marek Vasut | 69459b2 | 2018-05-31 19:47:42 +0200 | [diff] [blame] | 320 | div, rate); |
| 321 | return rate; |
| 322 | |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 323 | case CLK_TYPE_GEN4_SDSRC: |
| 324 | div = ((readl(priv->base + SD0CKCR1) >> 29) & 0x03) + 4; |
| 325 | rate = gen3_clk_get_rate64(&parent) / div; |
| 326 | debug("%s[%i] SDSRC clk: parent=%i div=%u => rate=%llu\n", |
| 327 | __func__, __LINE__, core->parent, div, rate); |
| 328 | return rate; |
| 329 | |
Hai Pham | 0985e0e | 2023-01-26 21:01:49 +0100 | [diff] [blame] | 330 | case CLK_TYPE_GEN3_SDH: /* Fixed factor 1:1 */ |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 331 | fallthrough; |
| 332 | case CLK_TYPE_GEN4_SDH: /* Fixed factor 1:1 */ |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 333 | return rcar_clk_get_rate64_sdh(core->parent, |
| 334 | gen3_clk_get_rate64(&parent), |
| 335 | priv->base + core->offset); |
Hai Pham | 0985e0e | 2023-01-26 21:01:49 +0100 | [diff] [blame] | 336 | |
Hai Pham | 6811b57 | 2023-01-26 21:06:06 +0100 | [diff] [blame] | 337 | case CLK_TYPE_R8A77970_SD0H: |
| 338 | return rcar_clk_get_rate64_div_table(core->parent, |
| 339 | gen3_clk_get_rate64(&parent), |
| 340 | priv->base + core->offset, |
| 341 | CPG_SDCKCR_SDHFC_MASK, |
| 342 | r8a77970_cpg_sd0h_div_table, "SDH"); |
| 343 | |
Hai Pham | 4dae076 | 2023-01-29 02:50:22 +0100 | [diff] [blame] | 344 | case CLK_TYPE_GEN3_SD: |
Marek Vasut | 0fbb8a7 | 2021-04-27 19:52:53 +0200 | [diff] [blame] | 345 | fallthrough; |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 346 | case CLK_TYPE_GEN4_SD: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 347 | return rcar_clk_get_rate64_sd(core->parent, |
| 348 | gen3_clk_get_rate64(&parent), |
| 349 | priv->base + core->offset); |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 350 | |
Hai Pham | 6811b57 | 2023-01-26 21:06:06 +0100 | [diff] [blame] | 351 | case CLK_TYPE_R8A77970_SD0: |
| 352 | return rcar_clk_get_rate64_div_table(core->parent, |
| 353 | gen3_clk_get_rate64(&parent), |
| 354 | priv->base + core->offset, |
| 355 | CPG_SDCKCR_SD0FC_MASK, |
| 356 | r8a77970_cpg_sd0_div_table, "SD"); |
| 357 | |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 358 | case CLK_TYPE_GEN3_RPCSRC: |
| 359 | return rcar_clk_get_rate64_div_table(core->parent, |
| 360 | gen3_clk_get_rate64(&parent), |
| 361 | priv->base + CPG_RPCCKCR, |
| 362 | CPG_RPCCKCR_DIV_POST_MASK, |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 363 | gen3_cpg_rpcsrc_div_table, |
| 364 | "RPCSRC"); |
| 365 | |
| 366 | case CLK_TYPE_GEN4_RPCSRC: |
| 367 | return rcar_clk_get_rate64_div_table(core->parent, |
| 368 | gen3_clk_get_rate64(&parent), |
| 369 | priv->base + CPG_RPCCKCR, |
| 370 | CPG_RPCCKCR_DIV_POST_MASK, |
| 371 | gen4_cpg_rpcsrc_div_table, |
| 372 | "RPCSRC"); |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 373 | |
Hai Pham | 85e691e | 2023-01-26 21:06:04 +0100 | [diff] [blame] | 374 | case CLK_TYPE_GEN3_D3_RPCSRC: |
| 375 | case CLK_TYPE_GEN3_E3_RPCSRC: |
| 376 | /* |
| 377 | * Register RPCSRC as fixed factor clock based on the |
| 378 | * MD[4:1] pins and CPG_RPCCKCR[4:3] register value for |
| 379 | * which has been set prior to booting the kernel. |
| 380 | */ |
| 381 | value = (readl(priv->base + CPG_RPCCKCR) & GENMASK(4, 3)) >> 3; |
| 382 | |
| 383 | switch (value) { |
| 384 | case 0: |
| 385 | div = 5; |
| 386 | break; |
| 387 | case 1: |
| 388 | div = 3; |
| 389 | break; |
| 390 | case 2: |
| 391 | div = core->div; |
| 392 | break; |
| 393 | case 3: |
| 394 | default: |
| 395 | div = 2; |
| 396 | break; |
| 397 | } |
| 398 | |
| 399 | rate = gen3_clk_get_rate64(&parent) / div; |
| 400 | debug("%s[%i] E3/D3 RPCSRC clk: parent=%i div=%u => rate=%llu\n", |
| 401 | __func__, __LINE__, (core->parent >> 16) & 0xffff, div, rate); |
| 402 | |
| 403 | return rate; |
| 404 | |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 405 | case CLK_TYPE_GEN3_RPC: |
Marek Vasut | 569acef | 2023-01-26 21:01:56 +0100 | [diff] [blame] | 406 | case CLK_TYPE_GEN4_RPC: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 407 | return rcar_clk_get_rate64_rpc(core->parent, |
| 408 | gen3_clk_get_rate64(&parent), |
| 409 | priv->base + CPG_RPCCKCR); |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 410 | |
Hai Pham | e83700a | 2023-01-26 21:06:03 +0100 | [diff] [blame] | 411 | case CLK_TYPE_GEN3_RPCD2: |
| 412 | case CLK_TYPE_GEN4_RPCD2: |
Hai Pham | 06d8f97 | 2023-01-26 21:06:07 +0100 | [diff] [blame] | 413 | return rcar_clk_get_rate64_rpcd2(core->parent, |
| 414 | gen3_clk_get_rate64(&parent)); |
Marek Vasut | c1aee32 | 2017-09-15 21:10:29 +0200 | [diff] [blame] | 415 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | printf("%s[%i] unknown fail\n", __func__, __LINE__); |
| 419 | |
| 420 | return -ENOENT; |
| 421 | } |
| 422 | |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 423 | static ulong gen3_clk_get_rate(struct clk *clk) |
| 424 | { |
| 425 | return gen3_clk_get_rate64(clk); |
| 426 | } |
| 427 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 428 | static ulong gen3_clk_set_rate(struct clk *clk, ulong rate) |
| 429 | { |
Marek Vasut | 414dbbe | 2018-01-11 16:28:31 +0100 | [diff] [blame] | 430 | /* Force correct SD-IF divider configuration if applicable */ |
Marek Vasut | c26bf89 | 2018-10-30 17:54:20 +0100 | [diff] [blame] | 431 | gen3_clk_setup_sdif_div(clk, rate); |
Marek Vasut | 7571ac4 | 2018-05-31 19:06:02 +0200 | [diff] [blame] | 432 | return gen3_clk_get_rate64(clk); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static int gen3_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
| 436 | { |
| 437 | if (args->args_count != 2) { |
Sean Anderson | a1b654b | 2021-12-01 14:26:53 -0500 | [diff] [blame] | 438 | debug("Invalid args_count: %d\n", args->args_count); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 439 | return -EINVAL; |
| 440 | } |
| 441 | |
| 442 | clk->id = (args->args[0] << 16) | args->args[1]; |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 447 | const struct clk_ops gen3_clk_ops = { |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 448 | .enable = gen3_clk_enable, |
| 449 | .disable = gen3_clk_disable, |
| 450 | .get_rate = gen3_clk_get_rate, |
| 451 | .set_rate = gen3_clk_set_rate, |
| 452 | .of_xlate = gen3_clk_of_xlate, |
| 453 | }; |
| 454 | |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 455 | static int gen3_clk_probe(struct udevice *dev) |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 456 | { |
| 457 | struct gen3_clk_priv *priv = dev_get_priv(dev); |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 458 | struct cpg_mssr_info *info = |
| 459 | (struct cpg_mssr_info *)dev_get_driver_data(dev); |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 460 | const void *pll_config; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 461 | fdt_addr_t rst_base; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 462 | int ret; |
| 463 | |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 464 | priv->base = dev_read_addr_ptr(dev); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 465 | if (!priv->base) |
| 466 | return -EINVAL; |
| 467 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 468 | priv->info = info; |
| 469 | ret = fdt_node_offset_by_compatible(gd->fdt_blob, -1, info->reset_node); |
| 470 | if (ret < 0) |
| 471 | return ret; |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 472 | |
| 473 | rst_base = fdtdec_get_addr(gd->fdt_blob, ret, "reg"); |
| 474 | if (rst_base == FDT_ADDR_T_NONE) |
| 475 | return -EINVAL; |
| 476 | |
Marek Vasut | ea8505e | 2023-02-28 07:25:11 +0100 | [diff] [blame] | 477 | priv->cpg_mode = readl(rst_base + info->reset_modemr_offset); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 478 | |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 479 | pll_config = info->get_pll_config(priv->cpg_mode); |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 480 | |
Hai Pham | 9480346 | 2020-11-05 22:30:37 +0700 | [diff] [blame] | 481 | if (info->reg_layout == CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3) { |
| 482 | priv->info->status_regs = mstpsr; |
| 483 | priv->info->control_regs = smstpcr; |
| 484 | priv->info->reset_regs = srcr; |
| 485 | priv->info->reset_clear_regs = srstclr; |
Marek Vasut | ba2c7d2 | 2023-02-28 22:34:38 +0100 | [diff] [blame] | 486 | priv->gen3_cpg_pll_config = pll_config; |
| 487 | if (!priv->gen3_cpg_pll_config->extal_div) |
| 488 | return -EINVAL; |
| 489 | } else if (info->reg_layout == CLK_REG_LAYOUT_RCAR_GEN4) { |
| 490 | priv->info->status_regs = mstpsr_for_gen4; |
| 491 | priv->info->control_regs = mstpcr_for_gen4; |
| 492 | priv->info->reset_regs = srcr_for_gen4; |
| 493 | priv->info->reset_clear_regs = srstclr_for_gen4; |
| 494 | priv->gen4_cpg_pll_config = pll_config; |
| 495 | if (!priv->gen4_cpg_pll_config->extal_div) |
| 496 | return -EINVAL; |
Hai Pham | 9480346 | 2020-11-05 22:30:37 +0700 | [diff] [blame] | 497 | } else { |
| 498 | return -EINVAL; |
| 499 | } |
| 500 | |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 501 | ret = clk_get_by_name(dev, "extal", &priv->clk_extal); |
| 502 | if (ret < 0) |
| 503 | return ret; |
| 504 | |
Marek Vasut | 4eb4e6e | 2018-01-08 14:01:40 +0100 | [diff] [blame] | 505 | if (info->extalr_node) { |
| 506 | ret = clk_get_by_name(dev, info->extalr_node, &priv->clk_extalr); |
Marek Vasut | fb0aa29 | 2017-10-08 21:09:15 +0200 | [diff] [blame] | 507 | if (ret < 0) |
| 508 | return ret; |
| 509 | } |
Marek Vasut | f3b8bf7 | 2017-07-21 23:18:03 +0200 | [diff] [blame] | 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 514 | static int gen3_clk_remove(struct udevice *dev) |
Marek Vasut | df6a114 | 2017-11-25 22:08:55 +0100 | [diff] [blame] | 515 | { |
| 516 | struct gen3_clk_priv *priv = dev_get_priv(dev); |
Marek Vasut | df6a114 | 2017-11-25 22:08:55 +0100 | [diff] [blame] | 517 | |
Marek Vasut | e11008b | 2018-01-15 16:44:39 +0100 | [diff] [blame] | 518 | return renesas_clk_remove(priv->base, priv->info); |
Marek Vasut | df6a114 | 2017-11-25 22:08:55 +0100 | [diff] [blame] | 519 | } |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 520 | |
| 521 | U_BOOT_DRIVER(clk_gen3) = { |
| 522 | .name = "clk_gen3", |
| 523 | .id = UCLASS_CLK, |
| 524 | .priv_auto = sizeof(struct gen3_clk_priv), |
| 525 | .ops = &gen3_clk_ops, |
| 526 | .probe = gen3_clk_probe, |
| 527 | .remove = gen3_clk_remove, |
Marek Vasut | 5ab7ef0 | 2020-04-25 14:57:55 +0200 | [diff] [blame] | 528 | .flags = DM_FLAG_OS_PREPARE | DM_FLAG_VITAL, |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | static int gen3_reset_assert(struct reset_ctl *reset_ctl) |
| 532 | { |
| 533 | struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev); |
| 534 | struct gen3_clk_priv *priv = dev_get_priv(cdev); |
Marek Vasut | ef5c0b1 | 2023-03-18 12:30:53 +0100 | [diff] [blame] | 535 | unsigned int packed_id = MOD_CLK_PACK(reset_ctl->id); |
| 536 | unsigned int reg = packed_id / 32; |
| 537 | unsigned int bit = packed_id % 32; |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 538 | u32 bitmask = BIT(bit); |
| 539 | |
| 540 | writel(bitmask, priv->base + priv->info->reset_regs[reg]); |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int gen3_reset_deassert(struct reset_ctl *reset_ctl) |
| 546 | { |
| 547 | struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev); |
| 548 | struct gen3_clk_priv *priv = dev_get_priv(cdev); |
Marek Vasut | ef5c0b1 | 2023-03-18 12:30:53 +0100 | [diff] [blame] | 549 | unsigned int packed_id = MOD_CLK_PACK(reset_ctl->id); |
| 550 | unsigned int reg = packed_id / 32; |
| 551 | unsigned int bit = packed_id % 32; |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 552 | u32 bitmask = BIT(bit); |
| 553 | |
| 554 | writel(bitmask, priv->base + priv->info->reset_clear_regs[reg]); |
| 555 | |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | static const struct reset_ops rst_gen3_ops = { |
| 560 | .rst_assert = gen3_reset_assert, |
| 561 | .rst_deassert = gen3_reset_deassert, |
| 562 | }; |
| 563 | |
| 564 | U_BOOT_DRIVER(rst_gen3) = { |
| 565 | .name = "rst_gen3", |
| 566 | .id = UCLASS_RESET, |
| 567 | .ops = &rst_gen3_ops, |
Marek Vasut | 5ab7ef0 | 2020-04-25 14:57:55 +0200 | [diff] [blame] | 568 | .flags = DM_FLAG_OS_PREPARE | DM_FLAG_VITAL, |
Marek Vasut | f6b3202 | 2023-01-26 21:02:03 +0100 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | int gen3_cpg_bind(struct udevice *parent) |
| 572 | { |
| 573 | struct cpg_mssr_info *info = |
| 574 | (struct cpg_mssr_info *)dev_get_driver_data(parent); |
| 575 | struct udevice *cdev, *rdev; |
| 576 | struct driver *drv; |
| 577 | int ret; |
| 578 | |
| 579 | drv = lists_driver_lookup_name("clk_gen3"); |
| 580 | if (!drv) |
| 581 | return -ENOENT; |
| 582 | |
| 583 | ret = device_bind_with_driver_data(parent, drv, "clk_gen3", (ulong)info, |
| 584 | dev_ofnode(parent), &cdev); |
| 585 | if (ret) |
| 586 | return ret; |
| 587 | |
| 588 | drv = lists_driver_lookup_name("rst_gen3"); |
| 589 | if (!drv) |
| 590 | return -ENOENT; |
| 591 | |
| 592 | ret = device_bind_with_driver_data(parent, drv, "rst_gen3", (ulong)cdev, |
| 593 | dev_ofnode(parent), &rdev); |
| 594 | if (ret) |
| 595 | device_unbind(cdev); |
| 596 | |
| 597 | return ret; |
| 598 | } |