Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2022-23 StarFive Technology Co., Ltd. |
| 4 | * |
| 5 | * Author: Yanhong Wang <yanhong.wang@starfivetech.com> |
Xingyu Wu | 751e440 | 2023-07-07 18:50:07 +0800 | [diff] [blame] | 6 | * Xingyu Wu <xingyu.wu@starfivetech.com> |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <clk.h> |
| 11 | #include <clk-uclass.h> |
| 12 | #include <dm.h> |
| 13 | #include <dm/device.h> |
| 14 | #include <dm/devres.h> |
| 15 | #include <dm/lists.h> |
| 16 | #include <dt-bindings/clock/starfive,jh7110-crg.h> |
| 17 | #include <log.h> |
| 18 | #include <linux/clk-provider.h> |
| 19 | |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 20 | #include "clk.h" |
| 21 | |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 22 | #define STARFIVE_CLK_ENABLE_SHIFT 31 /* [31] */ |
| 23 | #define STARFIVE_CLK_INVERT_SHIFT 30 /* [30] */ |
| 24 | #define STARFIVE_CLK_MUX_SHIFT 24 /* [29:24] */ |
| 25 | #define STARFIVE_CLK_DIV_SHIFT 0 /* [23:0] */ |
| 26 | |
| 27 | #define OFFSET(id) ((id) * 4) |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 28 | |
| 29 | #define JH7110_SYS_ID_TRANS(id) ((id) + JH7110_PLLCLK_END + JH7110_EXTCLK_END) |
| 30 | #define JH7110_AON_ID_TRANS(id) ((id) + JH7110_SYS_ID_TRANS(JH7110_SYSCLK_END)) |
| 31 | #define JH7110_STG_ID_TRANS(id) ((id) + JH7110_AON_ID_TRANS(JH7110_AONCLK_END)) |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 32 | |
| 33 | typedef int (*jh1710_init_fn)(struct udevice *dev); |
| 34 | |
| 35 | struct jh7110_clk_priv { |
| 36 | void __iomem *reg; |
| 37 | jh1710_init_fn init; |
| 38 | }; |
| 39 | |
| 40 | static const char *cpu_root_sels[2] = { |
| 41 | [0] = "oscillator", |
| 42 | [1] = "pll0_out", |
| 43 | }; |
| 44 | |
| 45 | static const char *perh_root_sels[2] = { |
| 46 | [0] = "pll0_out", |
| 47 | [1] = "pll2_out", |
| 48 | }; |
| 49 | |
| 50 | static const char *bus_root_sels[2] = { |
| 51 | [0] = "oscillator", |
| 52 | [1] = "pll2_out", |
| 53 | }; |
| 54 | |
| 55 | static const char *qspi_ref_sels[2] = { |
| 56 | [0] = "oscillator", |
| 57 | [1] = "qspi_ref_src", |
| 58 | }; |
| 59 | |
| 60 | static const char *gmac1_tx_sels[2] = { |
| 61 | [0] = "gmac1_gtxclk", |
| 62 | [1] = "gmac1_rmii_rtx", |
| 63 | }; |
| 64 | |
| 65 | static const char *gmac0_tx_sels[2] = { |
| 66 | [0] = "gmac0_gtxclk", |
| 67 | [1] = "gmac0_rmii_rtx", |
| 68 | }; |
| 69 | |
| 70 | static const char *apb_func_sels[2] = { |
| 71 | [0] = "osc_div4", |
| 72 | [1] = "oscillator", |
| 73 | }; |
| 74 | |
| 75 | static const char *gmac1_rx_sels[2] = { |
| 76 | [0] = "gmac1-rgmii-rxin-clock", |
| 77 | [1] = "gmac1_rmii_rtx", |
| 78 | }; |
| 79 | |
| 80 | static struct clk *starfive_clk_mux(void __iomem *reg, |
| 81 | const char *name, |
| 82 | unsigned int offset, |
| 83 | u8 width, |
| 84 | const char * const *parent_names, |
| 85 | u8 num_parents) |
| 86 | { |
| 87 | return clk_register_mux(NULL, name, parent_names, num_parents, 0, |
| 88 | reg + offset, STARFIVE_CLK_MUX_SHIFT, |
| 89 | width, 0); |
| 90 | } |
| 91 | |
| 92 | static struct clk *starfive_clk_gate(void __iomem *reg, |
| 93 | const char *name, |
| 94 | const char *parent_name, |
| 95 | unsigned int offset) |
| 96 | { |
| 97 | return clk_register_gate(NULL, name, parent_name, 0, reg + offset, |
| 98 | STARFIVE_CLK_ENABLE_SHIFT, 0, NULL); |
| 99 | } |
| 100 | |
| 101 | static struct clk *starfive_clk_inv(void __iomem *reg, |
| 102 | const char *name, |
| 103 | const char *parent_name, |
| 104 | unsigned int offset) |
| 105 | { |
| 106 | return clk_register_gate(NULL, name, parent_name, 0, reg + offset, |
| 107 | STARFIVE_CLK_INVERT_SHIFT, 0, NULL); |
| 108 | } |
| 109 | |
| 110 | static struct clk *starfive_clk_divider(void __iomem *reg, |
| 111 | const char *name, |
| 112 | const char *parent_name, |
| 113 | unsigned int offset, |
| 114 | u8 width) |
| 115 | { |
| 116 | return clk_register_divider(NULL, name, parent_name, 0, reg + offset, |
| 117 | 0, width, CLK_DIVIDER_ONE_BASED); |
| 118 | } |
| 119 | |
| 120 | static struct clk *starfive_clk_composite(void __iomem *reg, |
| 121 | const char *name, |
| 122 | const char * const *parent_names, |
| 123 | unsigned int num_parents, |
| 124 | unsigned int offset, |
| 125 | unsigned int mux_width, |
| 126 | unsigned int gate_width, |
| 127 | unsigned int div_width) |
| 128 | { |
| 129 | struct clk *clk = ERR_PTR(-ENOMEM); |
| 130 | struct clk_divider *div = NULL; |
| 131 | struct clk_gate *gate = NULL; |
| 132 | struct clk_mux *mux = NULL; |
| 133 | int mask_arry[4] = {0x1, 0x3, 0x7, 0xF}; |
| 134 | int mask; |
| 135 | |
| 136 | if (mux_width) { |
| 137 | if (mux_width > 4) |
| 138 | goto fail; |
| 139 | else |
| 140 | mask = mask_arry[mux_width - 1]; |
| 141 | |
| 142 | mux = kzalloc(sizeof(*mux), GFP_KERNEL); |
| 143 | if (!mux) |
| 144 | goto fail; |
| 145 | |
| 146 | mux->reg = reg + offset; |
| 147 | mux->mask = mask; |
| 148 | mux->shift = STARFIVE_CLK_MUX_SHIFT; |
| 149 | mux->num_parents = num_parents; |
| 150 | mux->flags = 0; |
| 151 | mux->parent_names = parent_names; |
| 152 | } |
| 153 | |
| 154 | if (gate_width) { |
| 155 | gate = kzalloc(sizeof(*gate), GFP_KERNEL); |
| 156 | |
| 157 | if (!gate) |
| 158 | goto fail; |
| 159 | |
| 160 | gate->reg = reg + offset; |
| 161 | gate->bit_idx = STARFIVE_CLK_ENABLE_SHIFT; |
| 162 | gate->flags = 0; |
| 163 | } |
| 164 | |
| 165 | if (div_width) { |
| 166 | div = kzalloc(sizeof(*div), GFP_KERNEL); |
| 167 | if (!div) |
| 168 | goto fail; |
| 169 | |
| 170 | div->reg = reg + offset; |
| 171 | |
| 172 | if (offset == OFFSET(JH7110_SYSCLK_UART3_CORE) || |
| 173 | offset == OFFSET(JH7110_SYSCLK_UART4_CORE) || |
| 174 | offset == OFFSET(JH7110_SYSCLK_UART5_CORE)) { |
| 175 | div->shift = 8; |
| 176 | div->width = 8; |
| 177 | } else { |
| 178 | div->shift = STARFIVE_CLK_DIV_SHIFT; |
| 179 | div->width = div_width; |
| 180 | } |
| 181 | div->flags = CLK_DIVIDER_ONE_BASED; |
| 182 | div->table = NULL; |
| 183 | } |
| 184 | |
| 185 | clk = clk_register_composite(NULL, name, |
| 186 | parent_names, num_parents, |
| 187 | &mux->clk, &clk_mux_ops, |
| 188 | &div->clk, &clk_divider_ops, |
| 189 | &gate->clk, &clk_gate_ops, 0); |
| 190 | |
| 191 | if (IS_ERR(clk)) |
| 192 | goto fail; |
| 193 | |
| 194 | return clk; |
| 195 | |
| 196 | fail: |
| 197 | kfree(gate); |
| 198 | kfree(div); |
| 199 | kfree(mux); |
| 200 | return ERR_CAST(clk); |
| 201 | } |
| 202 | |
| 203 | static struct clk *starfive_clk_fix_parent_composite(void __iomem *reg, |
| 204 | const char *name, |
| 205 | const char *parent_names, |
| 206 | unsigned int offset, |
| 207 | unsigned int mux_width, |
| 208 | unsigned int gate_width, |
| 209 | unsigned int div_width) |
| 210 | { |
| 211 | const char * const *parents; |
| 212 | |
| 213 | parents = &parent_names; |
| 214 | |
| 215 | return starfive_clk_composite(reg, name, parents, 1, offset, |
| 216 | mux_width, gate_width, div_width); |
| 217 | } |
| 218 | |
| 219 | static struct clk *starfive_clk_gate_divider(void __iomem *reg, |
| 220 | const char *name, |
| 221 | const char *parent, |
| 222 | unsigned int offset, |
| 223 | unsigned int width) |
| 224 | { |
| 225 | const char * const *parent_names; |
| 226 | |
| 227 | parent_names = &parent; |
| 228 | |
| 229 | return starfive_clk_composite(reg, name, parent_names, 1, |
| 230 | offset, 0, 1, width); |
| 231 | } |
| 232 | |
| 233 | static int jh7110_syscrg_init(struct udevice *dev) |
| 234 | { |
| 235 | struct jh7110_clk_priv *priv = dev_get_priv(dev); |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 236 | struct clk *pclk; |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 237 | |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 238 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_CPU_ROOT), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 239 | starfive_clk_mux(priv->reg, "cpu_root", |
| 240 | OFFSET(JH7110_SYSCLK_CPU_ROOT), 1, |
| 241 | cpu_root_sels, ARRAY_SIZE(cpu_root_sels))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 242 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_CPU_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 243 | starfive_clk_divider(priv->reg, |
| 244 | "cpu_core", "cpu_root", |
| 245 | OFFSET(JH7110_SYSCLK_CPU_CORE), 3)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 246 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_CPU_BUS), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 247 | starfive_clk_divider(priv->reg, |
| 248 | "cpu_bus", "cpu_core", |
| 249 | OFFSET(JH7110_SYSCLK_CPU_BUS), 2)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 250 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_PERH_ROOT), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 251 | starfive_clk_composite(priv->reg, |
| 252 | "perh_root", |
| 253 | perh_root_sels, ARRAY_SIZE(perh_root_sels), |
| 254 | OFFSET(JH7110_SYSCLK_PERH_ROOT), 1, 0, 2)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 255 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_BUS_ROOT), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 256 | starfive_clk_mux(priv->reg, "bus_root", |
| 257 | OFFSET(JH7110_SYSCLK_BUS_ROOT), 1, |
| 258 | bus_root_sels, ARRAY_SIZE(bus_root_sels))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 259 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_NOCSTG_BUS), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 260 | starfive_clk_divider(priv->reg, |
| 261 | "nocstg_bus", "bus_root", |
| 262 | OFFSET(JH7110_SYSCLK_NOCSTG_BUS), 3)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 263 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_AXI_CFG0), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 264 | starfive_clk_divider(priv->reg, |
| 265 | "axi_cfg0", "bus_root", |
| 266 | OFFSET(JH7110_SYSCLK_AXI_CFG0), 2)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 267 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_STG_AXIAHB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 268 | starfive_clk_divider(priv->reg, |
| 269 | "stg_axiahb", "axi_cfg0", |
| 270 | OFFSET(JH7110_SYSCLK_STG_AXIAHB), 2)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 271 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_AHB0), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 272 | starfive_clk_gate(priv->reg, |
| 273 | "ahb0", "stg_axiahb", |
| 274 | OFFSET(JH7110_SYSCLK_AHB0))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 275 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_AHB1), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 276 | starfive_clk_gate(priv->reg, |
| 277 | "ahb1", "stg_axiahb", |
| 278 | OFFSET(JH7110_SYSCLK_AHB1))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 279 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_APB_BUS), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 280 | starfive_clk_divider(priv->reg, |
| 281 | "apb_bus", "stg_axiahb", |
| 282 | OFFSET(JH7110_SYSCLK_APB_BUS), 4)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 283 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_APB0), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 284 | starfive_clk_gate(priv->reg, |
| 285 | "apb0", "apb_bus", |
| 286 | OFFSET(JH7110_SYSCLK_APB0))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 287 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_QSPI_AHB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 288 | starfive_clk_gate(priv->reg, |
| 289 | "qspi_ahb", "ahb1", |
| 290 | OFFSET(JH7110_SYSCLK_QSPI_AHB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 291 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_QSPI_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 292 | starfive_clk_gate(priv->reg, |
| 293 | "qspi_apb", "apb_bus", |
| 294 | OFFSET(JH7110_SYSCLK_QSPI_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 295 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_QSPI_REF_SRC), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 296 | starfive_clk_divider(priv->reg, |
| 297 | "qspi_ref_src", "pll0_out", |
| 298 | OFFSET(JH7110_SYSCLK_QSPI_REF_SRC), 5)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 299 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_QSPI_REF), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 300 | starfive_clk_composite(priv->reg, |
| 301 | "qspi_ref", |
| 302 | qspi_ref_sels, ARRAY_SIZE(qspi_ref_sels), |
| 303 | OFFSET(JH7110_SYSCLK_QSPI_REF), 1, 1, 0)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 304 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_SDIO0_AHB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 305 | starfive_clk_gate(priv->reg, |
| 306 | "sdio0_ahb", "ahb0", |
| 307 | OFFSET(JH7110_SYSCLK_SDIO0_AHB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 308 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_SDIO1_AHB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 309 | starfive_clk_gate(priv->reg, |
| 310 | "sdio1_ahb", "ahb0", |
| 311 | OFFSET(JH7110_SYSCLK_SDIO1_AHB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 312 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_SDIO0_SDCARD), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 313 | starfive_clk_fix_parent_composite(priv->reg, |
| 314 | "sdio0_sdcard", "axi_cfg0", |
| 315 | OFFSET(JH7110_SYSCLK_SDIO0_SDCARD), 0, 1, 4)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 316 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_SDIO1_SDCARD), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 317 | starfive_clk_fix_parent_composite(priv->reg, |
| 318 | "sdio1_sdcard", "axi_cfg0", |
| 319 | OFFSET(JH7110_SYSCLK_SDIO1_SDCARD), 0, 1, 4)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 320 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_USB_125M), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 321 | starfive_clk_divider(priv->reg, |
| 322 | "usb_125m", "pll0_out", |
| 323 | OFFSET(JH7110_SYSCLK_USB_125M), 4)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 324 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_NOC_BUS_STG_AXI), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 325 | starfive_clk_gate(priv->reg, |
| 326 | "noc_bus_stg_axi", "nocstg_bus", |
| 327 | OFFSET(JH7110_SYSCLK_NOC_BUS_STG_AXI))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 328 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_AHB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 329 | starfive_clk_gate(priv->reg, |
| 330 | "gmac1_ahb", "ahb0", |
| 331 | OFFSET(JH7110_SYSCLK_GMAC1_AHB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 332 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_AXI), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 333 | starfive_clk_gate(priv->reg, |
| 334 | "gmac1_axi", "stg_axiahb", |
| 335 | OFFSET(JH7110_SYSCLK_GMAC1_AXI))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 336 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC_SRC), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 337 | starfive_clk_divider(priv->reg, |
| 338 | "gmac_src", "pll0_out", |
| 339 | OFFSET(JH7110_SYSCLK_GMAC_SRC), 3)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 340 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_GTXCLK), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 341 | starfive_clk_divider(priv->reg, |
| 342 | "gmac1_gtxclk", "pll0_out", |
| 343 | OFFSET(JH7110_SYSCLK_GMAC1_GTXCLK), 4)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 344 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_GTXC), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 345 | starfive_clk_gate(priv->reg, |
| 346 | "gmac1_gtxc", "gmac1_gtxclk", |
| 347 | OFFSET(JH7110_SYSCLK_GMAC1_GTXC))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 348 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_RMII_RTX), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 349 | starfive_clk_divider(priv->reg, |
| 350 | "gmac1_rmii_rtx", "gmac1-rmii-refin-clock", |
| 351 | OFFSET(JH7110_SYSCLK_GMAC1_RMII_RTX), 5)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 352 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_PTP), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 353 | starfive_clk_gate_divider(priv->reg, |
| 354 | "gmac1_ptp", "gmac_src", |
| 355 | OFFSET(JH7110_SYSCLK_GMAC1_PTP), 5)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 356 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_RX), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 357 | starfive_clk_mux(priv->reg, "gmac1_rx", |
| 358 | OFFSET(JH7110_SYSCLK_GMAC1_RX), 1, |
| 359 | gmac1_rx_sels, ARRAY_SIZE(gmac1_rx_sels))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 360 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_TX), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 361 | starfive_clk_composite(priv->reg, |
| 362 | "gmac1_tx", |
| 363 | gmac1_tx_sels, ARRAY_SIZE(gmac1_tx_sels), |
| 364 | OFFSET(JH7110_SYSCLK_GMAC1_TX), 1, 1, 0)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 365 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC1_TX_INV), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 366 | starfive_clk_inv(priv->reg, |
| 367 | "gmac1_tx_inv", "gmac1_tx", |
| 368 | OFFSET(JH7110_SYSCLK_GMAC1_TX_INV))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 369 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC0_GTXCLK), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 370 | starfive_clk_gate_divider(priv->reg, |
| 371 | "gmac0_gtxclk", "pll0_out", |
| 372 | OFFSET(JH7110_SYSCLK_GMAC0_GTXCLK), 4)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 373 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC0_PTP), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 374 | starfive_clk_gate_divider(priv->reg, |
| 375 | "gmac0_ptp", "gmac_src", |
| 376 | OFFSET(JH7110_SYSCLK_GMAC0_PTP), 5)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 377 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_GMAC0_GTXC), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 378 | starfive_clk_gate(priv->reg, |
| 379 | "gmac0_gtxc", "gmac0_gtxclk", |
| 380 | OFFSET(JH7110_SYSCLK_GMAC0_GTXC))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 381 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART0_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 382 | starfive_clk_gate(priv->reg, |
| 383 | "uart0_apb", "apb0", |
| 384 | OFFSET(JH7110_SYSCLK_UART0_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 385 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART0_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 386 | starfive_clk_gate(priv->reg, |
| 387 | "uart0_core", "oscillator", |
| 388 | OFFSET(JH7110_SYSCLK_UART0_CORE))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 389 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART1_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 390 | starfive_clk_gate(priv->reg, |
| 391 | "uart1_apb", "apb0", |
| 392 | OFFSET(JH7110_SYSCLK_UART1_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 393 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART1_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 394 | starfive_clk_gate(priv->reg, |
| 395 | "uart1_core", "oscillator", |
| 396 | OFFSET(JH7110_SYSCLK_UART1_CORE))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 397 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART2_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 398 | starfive_clk_gate(priv->reg, |
| 399 | "uart2_apb", "apb0", |
| 400 | OFFSET(JH7110_SYSCLK_UART2_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 401 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART2_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 402 | starfive_clk_gate(priv->reg, |
| 403 | "uart2_core", "oscillator", |
| 404 | OFFSET(JH7110_SYSCLK_UART2_CORE))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 405 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART3_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 406 | starfive_clk_gate(priv->reg, |
| 407 | "uart3_apb", "apb0", |
| 408 | OFFSET(JH7110_SYSCLK_UART3_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 409 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART3_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 410 | starfive_clk_gate_divider(priv->reg, |
| 411 | "uart3_core", "perh_root", |
| 412 | OFFSET(JH7110_SYSCLK_UART3_CORE), 8)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 413 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART4_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 414 | starfive_clk_gate(priv->reg, |
| 415 | "uart4_apb", "apb0", |
| 416 | OFFSET(JH7110_SYSCLK_UART4_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 417 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART4_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 418 | starfive_clk_gate_divider(priv->reg, |
| 419 | "uart4_core", "perh_root", |
| 420 | OFFSET(JH7110_SYSCLK_UART4_CORE), 8)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 421 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART5_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 422 | starfive_clk_gate(priv->reg, |
| 423 | "uart5_apb", "apb0", |
| 424 | OFFSET(JH7110_SYSCLK_UART5_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 425 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_UART5_CORE), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 426 | starfive_clk_gate_divider(priv->reg, |
| 427 | "uart5_core", "perh_root", |
| 428 | OFFSET(JH7110_SYSCLK_UART5_CORE), 8)); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 429 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_I2C2_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 430 | starfive_clk_gate(priv->reg, |
| 431 | "i2c2_apb", "apb0", |
| 432 | OFFSET(JH7110_SYSCLK_I2C2_APB))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 433 | clk_dm(JH7110_SYS_ID_TRANS(JH7110_SYSCLK_I2C5_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 434 | starfive_clk_gate(priv->reg, |
| 435 | "i2c5_apb", "apb0", |
| 436 | OFFSET(JH7110_SYSCLK_I2C5_APB))); |
| 437 | |
| 438 | /* enable noc_bus_stg_axi clock */ |
| 439 | if (!clk_get_by_id(JH7110_SYSCLK_NOC_BUS_STG_AXI, &pclk)) |
| 440 | clk_enable(pclk); |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int jh7110_aoncrg_init(struct udevice *dev) |
| 446 | { |
| 447 | struct jh7110_clk_priv *priv = dev_get_priv(dev); |
| 448 | |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 449 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_OSC_DIV4), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 450 | starfive_clk_divider(priv->reg, |
| 451 | "osc_div4", "oscillator", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 452 | OFFSET(JH7110_AONCLK_OSC_DIV4), 5)); |
| 453 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_APB_FUNC), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 454 | starfive_clk_mux(priv->reg, "apb_func", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 455 | OFFSET(JH7110_AONCLK_APB_FUNC), 1, |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 456 | apb_func_sels, ARRAY_SIZE(apb_func_sels))); |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 457 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_GMAC0_AHB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 458 | starfive_clk_gate(priv->reg, |
| 459 | "gmac0_ahb", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 460 | OFFSET(JH7110_AONCLK_GMAC0_AHB))); |
| 461 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_GMAC0_AXI), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 462 | starfive_clk_gate(priv->reg, |
| 463 | "gmac0_axi", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 464 | OFFSET(JH7110_AONCLK_GMAC0_AXI))); |
| 465 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_GMAC0_RMII_RTX), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 466 | starfive_clk_divider(priv->reg, |
| 467 | "gmac0_rmii_rtx", "gmac0-rmii-refin-clock", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 468 | OFFSET(JH7110_AONCLK_GMAC0_RMII_RTX), 5)); |
| 469 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_GMAC0_TX), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 470 | starfive_clk_composite(priv->reg, |
| 471 | "gmac0_tx", gmac0_tx_sels, |
| 472 | ARRAY_SIZE(gmac0_tx_sels), |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 473 | OFFSET(JH7110_AONCLK_GMAC0_TX), 1, 1, 0)); |
| 474 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_GMAC0_TX_INV), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 475 | starfive_clk_inv(priv->reg, |
| 476 | "gmac0_tx_inv", "gmac0_tx", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 477 | OFFSET(JH7110_AONCLK_GMAC0_TX_INV))); |
| 478 | clk_dm(JH7110_AON_ID_TRANS(JH7110_AONCLK_OTPC_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 479 | starfive_clk_gate(priv->reg, |
| 480 | "otpc_apb", "apb_bus", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 481 | OFFSET(JH7110_AONCLK_OTPC_APB))); |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static int jh7110_stgcrg_init(struct udevice *dev) |
| 487 | { |
| 488 | struct jh7110_clk_priv *priv = dev_get_priv(dev); |
| 489 | |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 490 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 491 | starfive_clk_gate(priv->reg, |
| 492 | "usb_apb", "apb_bus", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 493 | OFFSET(JH7110_STGCLK_USB_APB))); |
| 494 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_UTMI_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 495 | starfive_clk_gate(priv->reg, |
| 496 | "usb_utmi_apb", "apb_bus", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 497 | OFFSET(JH7110_STGCLK_USB_UTMI_APB))); |
| 498 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_AXI), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 499 | starfive_clk_gate(priv->reg, |
| 500 | "usb_axi", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 501 | OFFSET(JH7110_STGCLK_USB_AXI))); |
| 502 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_LPM), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 503 | starfive_clk_gate_divider(priv->reg, |
| 504 | "usb_lpm", "oscillator", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 505 | OFFSET(JH7110_STGCLK_USB_LPM), 2)); |
| 506 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_STB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 507 | starfive_clk_gate_divider(priv->reg, |
| 508 | "usb_stb", "oscillator", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 509 | OFFSET(JH7110_STGCLK_USB_STB), 3)); |
| 510 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_APP_125), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 511 | starfive_clk_gate(priv->reg, |
| 512 | "usb_app_125", "usb_125m", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 513 | OFFSET(JH7110_STGCLK_USB_APP_125))); |
| 514 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_USB_REFCLK), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 515 | starfive_clk_divider(priv->reg, "usb_refclk", "oscillator", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 516 | OFFSET(JH7110_STGCLK_USB_REFCLK), 2)); |
| 517 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_PCIE0_AXI), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 518 | starfive_clk_gate(priv->reg, |
| 519 | "pcie0_axi", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 520 | OFFSET(JH7110_STGCLK_PCIE0_AXI))); |
| 521 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_PCIE0_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 522 | starfive_clk_gate(priv->reg, |
| 523 | "pcie0_apb", "apb_bus", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 524 | OFFSET(JH7110_STGCLK_PCIE0_APB))); |
| 525 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_PCIE0_TL), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 526 | starfive_clk_gate(priv->reg, |
| 527 | "pcie0_tl", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 528 | OFFSET(JH7110_STGCLK_PCIE0_TL))); |
| 529 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_PCIE1_AXI), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 530 | starfive_clk_gate(priv->reg, |
| 531 | "pcie1_axi", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 532 | OFFSET(JH7110_STGCLK_PCIE1_AXI))); |
| 533 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_PCIE1_APB), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 534 | starfive_clk_gate(priv->reg, |
| 535 | "pcie1_apb", "apb_bus", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 536 | OFFSET(JH7110_STGCLK_PCIE1_APB))); |
| 537 | clk_dm(JH7110_STG_ID_TRANS(JH7110_STGCLK_PCIE1_TL), |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 538 | starfive_clk_gate(priv->reg, |
| 539 | "pcie1_tl", "stg_axiahb", |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 540 | OFFSET(JH7110_STGCLK_PCIE1_TL))); |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int jh7110_clk_probe(struct udevice *dev) |
| 546 | { |
| 547 | struct jh7110_clk_priv *priv = dev_get_priv(dev); |
| 548 | |
| 549 | priv->init = (jh1710_init_fn)dev_get_driver_data(dev); |
| 550 | priv->reg = (void __iomem *)dev_read_addr_ptr(dev); |
| 551 | |
| 552 | if (priv->init) |
| 553 | return priv->init(dev); |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | static int jh7110_clk_bind(struct udevice *dev) |
| 559 | { |
| 560 | /* The reset driver does not have a device node, so bind it here */ |
| 561 | return device_bind_driver_to_node(dev, "jh7110_reset", dev->name, |
| 562 | dev_ofnode(dev), NULL); |
| 563 | } |
| 564 | |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 565 | static int jh7110_sys_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
| 566 | { |
| 567 | if (args->args_count > 1) { |
| 568 | debug("Invalid args_count: %d\n", args->args_count); |
| 569 | return -EINVAL; |
| 570 | } |
| 571 | |
| 572 | if (args->args_count) |
| 573 | clk->id = JH7110_SYS_ID_TRANS(args->args[0]); |
| 574 | else |
| 575 | clk->id = 0; |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static int jh7110_aon_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
| 581 | { |
| 582 | if (args->args_count > 1) { |
| 583 | debug("Invalid args_count: %d\n", args->args_count); |
| 584 | return -EINVAL; |
| 585 | } |
| 586 | |
| 587 | if (args->args_count) |
| 588 | clk->id = JH7110_AON_ID_TRANS(args->args[0]); |
| 589 | else |
| 590 | clk->id = 0; |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | static int jh7110_stg_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args) |
| 596 | { |
| 597 | if (args->args_count > 1) { |
| 598 | debug("Invalid args_count: %d\n", args->args_count); |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | |
| 602 | if (args->args_count) |
| 603 | clk->id = JH7110_STG_ID_TRANS(args->args[0]); |
| 604 | else |
| 605 | clk->id = 0; |
| 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | static const struct udevice_id jh7110_sys_clk_of_match[] = { |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 611 | { .compatible = "starfive,jh7110-syscrg", |
| 612 | .data = (ulong)&jh7110_syscrg_init |
| 613 | }, |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 614 | { } |
| 615 | }; |
| 616 | |
| 617 | JH7110_CLK_OPS(sys); |
| 618 | |
| 619 | U_BOOT_DRIVER(jh7110_sys_clk) = { |
| 620 | .name = "jh7110_sys_clk", |
| 621 | .id = UCLASS_CLK, |
| 622 | .of_match = jh7110_sys_clk_of_match, |
| 623 | .probe = jh7110_clk_probe, |
| 624 | .ops = &jh7110_sys_clk_ops, |
| 625 | .priv_auto = sizeof(struct jh7110_clk_priv), |
| 626 | .bind = jh7110_clk_bind, |
| 627 | }; |
| 628 | |
| 629 | static const struct udevice_id jh7110_aon_clk_of_match[] = { |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 630 | { .compatible = "starfive,jh7110-aoncrg", |
| 631 | .data = (ulong)&jh7110_aoncrg_init |
| 632 | }, |
| 633 | { } |
| 634 | }; |
| 635 | |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 636 | JH7110_CLK_OPS(aon); |
| 637 | |
| 638 | U_BOOT_DRIVER(jh7110_aon_clk) = { |
| 639 | .name = "jh7110_aon_clk", |
| 640 | .id = UCLASS_CLK, |
| 641 | .of_match = jh7110_aon_clk_of_match, |
| 642 | .probe = jh7110_clk_probe, |
| 643 | .ops = &jh7110_aon_clk_ops, |
| 644 | .priv_auto = sizeof(struct jh7110_clk_priv), |
| 645 | .bind = jh7110_clk_bind, |
| 646 | }; |
| 647 | |
| 648 | static const struct udevice_id jh7110_stg_clk_of_match[] = { |
| 649 | { .compatible = "starfive,jh7110-stgcrg", |
| 650 | .data = (ulong)&jh7110_stgcrg_init |
| 651 | }, |
| 652 | { } |
| 653 | }; |
| 654 | |
| 655 | JH7110_CLK_OPS(stg); |
| 656 | |
| 657 | U_BOOT_DRIVER(jh7110_stg_clk) = { |
| 658 | .name = "jh7110_stg_clk", |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 659 | .id = UCLASS_CLK, |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 660 | .of_match = jh7110_stg_clk_of_match, |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 661 | .probe = jh7110_clk_probe, |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 662 | .ops = &jh7110_stg_clk_ops, |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 663 | .priv_auto = sizeof(struct jh7110_clk_priv), |
Xingyu Wu | a3897e6 | 2023-07-07 18:50:11 +0800 | [diff] [blame] | 664 | .bind = jh7110_clk_bind, |
Yanhong Wang | 5a85d05 | 2023-03-29 11:42:13 +0800 | [diff] [blame] | 665 | }; |