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