| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* Copyright (C) 2023 Jisheng Zhang <[email protected]> |
| 4 |
* Copyright (C) 2023 Vivo Communication Technology Co. Ltd. |
| 5 |
* Authors: Yangtao Li <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#include <dt-bindings/clock/thead,th1520-clk-ap.h> |
| 9 |
#include <linux/bitfield.h> |
| 10 |
#include <linux/clk.h> |
| 11 |
#include <linux/clk-provider.h> |
| 12 |
#include <linux/delay.h> |
| 13 |
#include <linux/device.h> |
| 14 |
#include <linux/minmax.h> |
| 15 |
#include <linux/module.h> |
| 16 |
#include <linux/platform_device.h> |
| 17 |
#include <linux/regmap.h> |
| 18 |
|
| 19 |
#define TH1520_PLL_STS 0x80 |
| 20 |
|
| 21 |
#define TH1520_PLL_POSTDIV2 GENMASK(26, 24) |
| 22 |
#define TH1520_PLL_POSTDIV1 GENMASK(22, 20) |
| 23 |
#define TH1520_PLL_FBDIV GENMASK(19, 8) |
| 24 |
#define TH1520_PLL_REFDIV GENMASK(5, 0) |
| 25 |
#define TH1520_PLL_BYPASS BIT(30) |
| 26 |
#define TH1520_PLL_VCO_RST BIT(29) |
| 27 |
#define TH1520_PLL_DACPD BIT(25) |
| 28 |
#define TH1520_PLL_DSMPD BIT(24) |
| 29 |
#define TH1520_PLL_FRAC GENMASK(23, 0) |
| 30 |
#define TH1520_PLL_FRAC_BITS 24 |
| 31 |
|
| 32 |
/* |
| 33 |
* All PLLs in TH1520 take 21250ns at maximum to lock, let's take its double |
| 34 |
* for safety. |
| 35 |
*/ |
| 36 |
#define TH1520_PLL_LOCK_TIMEOUT_US 44 |
| 37 |
#define TH1520_PLL_STABLE_DELAY_US 30 |
| 38 |
|
| 39 |
/* c910_bus_clk must be kept below 750MHz for stability */ |
| 40 |
#define TH1520_C910_BUS_MAX_RATE (750 * 1000 * 1000) |
| 41 |
|
| 42 |
struct ccu_internal { |
| 43 |
u8 shift; |
| 44 |
u8 width; |
| 45 |
}; |
| 46 |
|
| 47 |
struct ccu_div_internal { |
| 48 |
u8 shift; |
| 49 |
u8 width; |
| 50 |
u32 flags; |
| 51 |
}; |
| 52 |
|
| 53 |
struct ccu_common { |
| 54 |
int clkid; |
| 55 |
struct regmap *map; |
| 56 |
u16 cfg0; |
| 57 |
u16 cfg1; |
| 58 |
struct clk_hw hw; |
| 59 |
}; |
| 60 |
|
| 61 |
struct ccu_mux { |
| 62 |
int clkid; |
| 63 |
u32 reg; |
| 64 |
struct clk_mux mux; |
| 65 |
}; |
| 66 |
|
| 67 |
struct ccu_gate { |
| 68 |
int clkid; |
| 69 |
u32 reg; |
| 70 |
struct clk_gate gate; |
| 71 |
}; |
| 72 |
|
| 73 |
struct ccu_div { |
| 74 |
u32 enable; |
| 75 |
u32 div_en; |
| 76 |
struct ccu_div_internal div; |
| 77 |
struct ccu_internal mux; |
| 78 |
struct ccu_common common; |
| 79 |
}; |
| 80 |
|
| 81 |
struct ccu_pll_cfg { |
| 82 |
unsigned long freq; |
| 83 |
u32 fbdiv; |
| 84 |
u32 frac; |
| 85 |
u32 postdiv1; |
| 86 |
u32 postdiv2; |
| 87 |
}; |
| 88 |
|
| 89 |
struct ccu_pll { |
| 90 |
struct ccu_common common; |
| 91 |
u32 lock_sts_mask; |
| 92 |
int cfgnum; |
| 93 |
const struct ccu_pll_cfg *cfgs; |
| 94 |
}; |
| 95 |
|
| 96 |
#define TH_CCU_ARG(_shift, _width) \ |
| 97 |
{ \ |
| 98 |
.shift = _shift, \ |
| 99 |
.width = _width, \ |
| 100 |
} |
| 101 |
|
| 102 |
#define TH_CCU_DIV_FLAGS(_shift, _width, _flags) \ |
| 103 |
{ \ |
| 104 |
.shift = _shift, \ |
| 105 |
.width = _width, \ |
| 106 |
.flags = _flags, \ |
| 107 |
} |
| 108 |
|
| 109 |
#define TH_CCU_MUX_FLAGS(_name, _parents, _shift, _width, _flags, \ |
| 110 |
_mux_flags) \ |
| 111 |
{ \ |
| 112 |
.mask = GENMASK(_width - 1, 0), \ |
| 113 |
.shift = _shift, \ |
| 114 |
.flags = _mux_flags, \ |
| 115 |
.hw.init = CLK_HW_INIT_PARENTS_DATA( \ |
| 116 |
_name, \ |
| 117 |
_parents, \ |
| 118 |
&clk_mux_ops, \ |
| 119 |
_flags), \ |
| 120 |
} |
| 121 |
|
| 122 |
#define TH_CCU_MUX(_name, _parents, _shift, _width) \ |
| 123 |
TH_CCU_MUX_FLAGS(_name, _parents, _shift, _width, 0, 0) |
| 124 |
|
| 125 |
#define CCU_GATE(_clkid, _struct, _name, _parent, _reg, _bit, _flags) \ |
| 126 |
struct ccu_gate _struct = { \ |
| 127 |
.clkid = _clkid, \ |
| 128 |
.reg = _reg, \ |
| 129 |
.gate = { \ |
| 130 |
.bit_idx = _bit, \ |
| 131 |
.hw.init = CLK_HW_INIT_PARENTS_DATA( \ |
| 132 |
_name, \ |
| 133 |
_parent, \ |
| 134 |
&clk_gate_ops, \ |
| 135 |
_flags), \ |
| 136 |
} \ |
| 137 |
} |
| 138 |
|
| 139 |
static inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw) |
| 140 |
{ |
| 141 |
return container_of(hw, struct ccu_common, hw); |
| 142 |
} |
| 143 |
|
| 144 |
static inline struct ccu_pll *hw_to_ccu_pll(struct clk_hw *hw) |
| 145 |
{ |
| 146 |
struct ccu_common *common = hw_to_ccu_common(hw); |
| 147 |
|
| 148 |
return container_of(common, struct ccu_pll, common); |
| 149 |
} |
| 150 |
|
| 151 |
static inline struct ccu_div *hw_to_ccu_div(struct clk_hw *hw) |
| 152 |
{ |
| 153 |
struct ccu_common *common = hw_to_ccu_common(hw); |
| 154 |
|
| 155 |
return container_of(common, struct ccu_div, common); |
| 156 |
} |
| 157 |
|
| 158 |
static u8 ccu_get_parent_helper(struct ccu_common *common, |
| 159 |
struct ccu_internal *mux) |
| 160 |
{ |
| 161 |
unsigned int val; |
| 162 |
u8 parent; |
| 163 |
|
| 164 |
regmap_read(common->map, common->cfg0, &val); |
| 165 |
parent = val >> mux->shift; |
| 166 |
parent &= GENMASK(mux->width - 1, 0); |
| 167 |
|
| 168 |
return parent; |
| 169 |
} |
| 170 |
|
| 171 |
static int ccu_set_parent_helper(struct ccu_common *common, |
| 172 |
struct ccu_internal *mux, |
| 173 |
u8 index) |
| 174 |
{ |
| 175 |
return regmap_update_bits(common->map, common->cfg0, |
| 176 |
GENMASK(mux->width - 1, 0) << mux->shift, |
| 177 |
index << mux->shift); |
| 178 |
} |
| 179 |
|
| 180 |
static void ccu_disable_helper(struct ccu_common *common, u32 gate) |
| 181 |
{ |
| 182 |
if (!gate) |
| 183 |
return; |
| 184 |
regmap_update_bits(common->map, common->cfg0, |
| 185 |
gate, ~gate); |
| 186 |
} |
| 187 |
|
| 188 |
static int ccu_enable_helper(struct ccu_common *common, u32 gate) |
| 189 |
{ |
| 190 |
unsigned int val; |
| 191 |
int ret; |
| 192 |
|
| 193 |
if (!gate) |
| 194 |
return 0; |
| 195 |
|
| 196 |
ret = regmap_update_bits(common->map, common->cfg0, gate, gate); |
| 197 |
regmap_read(common->map, common->cfg0, &val); |
| 198 |
return ret; |
| 199 |
} |
| 200 |
|
| 201 |
static int ccu_is_enabled_helper(struct ccu_common *common, u32 gate) |
| 202 |
{ |
| 203 |
unsigned int val; |
| 204 |
|
| 205 |
if (!gate) |
| 206 |
return true; |
| 207 |
|
| 208 |
regmap_read(common->map, common->cfg0, &val); |
| 209 |
return val & gate; |
| 210 |
} |
| 211 |
|
| 212 |
static unsigned long ccu_div_recalc_rate(struct clk_hw *hw, |
| 213 |
unsigned long parent_rate) |
| 214 |
{ |
| 215 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 216 |
unsigned long rate; |
| 217 |
unsigned int val; |
| 218 |
|
| 219 |
regmap_read(cd->common.map, cd->common.cfg0, &val); |
| 220 |
val = val >> cd->div.shift; |
| 221 |
val &= GENMASK(cd->div.width - 1, 0); |
| 222 |
rate = divider_recalc_rate(hw, parent_rate, val, NULL, |
| 223 |
cd->div.flags, cd->div.width); |
| 224 |
|
| 225 |
return rate; |
| 226 |
} |
| 227 |
|
| 228 |
static int ccu_div_determine_rate(struct clk_hw *hw, |
| 229 |
struct clk_rate_request *req) |
| 230 |
{ |
| 231 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 232 |
unsigned int val; |
| 233 |
|
| 234 |
if (cd->div_en) |
| 235 |
return divider_determine_rate(hw, req, NULL, |
| 236 |
cd->div.width, cd->div.flags); |
| 237 |
|
| 238 |
regmap_read(cd->common.map, cd->common.cfg0, &val); |
| 239 |
val = val >> cd->div.shift; |
| 240 |
val &= GENMASK(cd->div.width - 1, 0); |
| 241 |
return divider_ro_determine_rate(hw, req, NULL, cd->div.width, |
| 242 |
cd->div.flags, val); |
| 243 |
} |
| 244 |
|
| 245 |
static int ccu_div_set_rate(struct clk_hw *hw, unsigned long rate, |
| 246 |
unsigned long parent_rate) |
| 247 |
{ |
| 248 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 249 |
int val = divider_get_val(rate, parent_rate, NULL, |
| 250 |
cd->div.width, cd->div.flags); |
| 251 |
unsigned int curr_val, reg_val; |
| 252 |
|
| 253 |
if (val < 0) |
| 254 |
return val; |
| 255 |
|
| 256 |
regmap_read(cd->common.map, cd->common.cfg0, ®_val); |
| 257 |
curr_val = reg_val >> cd->div.shift; |
| 258 |
curr_val &= GENMASK(cd->div.width - 1, 0); |
| 259 |
|
| 260 |
if (!cd->div_en && curr_val != val) |
| 261 |
return -EINVAL; |
| 262 |
|
| 263 |
reg_val &= ~cd->div_en; |
| 264 |
regmap_write(cd->common.map, cd->common.cfg0, reg_val); |
| 265 |
udelay(1); |
| 266 |
|
| 267 |
reg_val &= ~GENMASK(cd->div.width + cd->div.shift - 1, cd->div.shift); |
| 268 |
reg_val |= val << cd->div.shift; |
| 269 |
regmap_write(cd->common.map, cd->common.cfg0, reg_val); |
| 270 |
|
| 271 |
reg_val |= cd->div_en; |
| 272 |
regmap_write(cd->common.map, cd->common.cfg0, reg_val); |
| 273 |
|
| 274 |
return 0; |
| 275 |
} |
| 276 |
|
| 277 |
static u8 ccu_div_get_parent(struct clk_hw *hw) |
| 278 |
{ |
| 279 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 280 |
|
| 281 |
return ccu_get_parent_helper(&cd->common, &cd->mux); |
| 282 |
} |
| 283 |
|
| 284 |
static int ccu_div_set_parent(struct clk_hw *hw, u8 index) |
| 285 |
{ |
| 286 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 287 |
|
| 288 |
return ccu_set_parent_helper(&cd->common, &cd->mux, index); |
| 289 |
} |
| 290 |
|
| 291 |
static void ccu_div_disable(struct clk_hw *hw) |
| 292 |
{ |
| 293 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 294 |
|
| 295 |
ccu_disable_helper(&cd->common, cd->enable); |
| 296 |
} |
| 297 |
|
| 298 |
static int ccu_div_enable(struct clk_hw *hw) |
| 299 |
{ |
| 300 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 301 |
|
| 302 |
return ccu_enable_helper(&cd->common, cd->enable); |
| 303 |
} |
| 304 |
|
| 305 |
static int ccu_div_is_enabled(struct clk_hw *hw) |
| 306 |
{ |
| 307 |
struct ccu_div *cd = hw_to_ccu_div(hw); |
| 308 |
|
| 309 |
return ccu_is_enabled_helper(&cd->common, cd->enable); |
| 310 |
} |
| 311 |
|
| 312 |
static const struct clk_ops ccu_div_ops = { |
| 313 |
.disable = ccu_div_disable, |
| 314 |
.enable = ccu_div_enable, |
| 315 |
.is_enabled = ccu_div_is_enabled, |
| 316 |
.get_parent = ccu_div_get_parent, |
| 317 |
.set_parent = ccu_div_set_parent, |
| 318 |
.recalc_rate = ccu_div_recalc_rate, |
| 319 |
.set_rate = ccu_div_set_rate, |
| 320 |
.determine_rate = ccu_div_determine_rate, |
| 321 |
}; |
| 322 |
|
| 323 |
static void ccu_pll_disable(struct clk_hw *hw) |
| 324 |
{ |
| 325 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 326 |
|
| 327 |
regmap_set_bits(pll->common.map, pll->common.cfg1, |
| 328 |
TH1520_PLL_VCO_RST); |
| 329 |
} |
| 330 |
|
| 331 |
static int ccu_pll_enable(struct clk_hw *hw) |
| 332 |
{ |
| 333 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 334 |
u32 reg; |
| 335 |
int ret; |
| 336 |
|
| 337 |
regmap_clear_bits(pll->common.map, pll->common.cfg1, |
| 338 |
TH1520_PLL_VCO_RST); |
| 339 |
|
| 340 |
ret = regmap_read_poll_timeout_atomic(pll->common.map, TH1520_PLL_STS, |
| 341 |
reg, reg & pll->lock_sts_mask, |
| 342 |
5, TH1520_PLL_LOCK_TIMEOUT_US); |
| 343 |
if (ret) |
| 344 |
return ret; |
| 345 |
|
| 346 |
udelay(TH1520_PLL_STABLE_DELAY_US); |
| 347 |
|
| 348 |
return 0; |
| 349 |
} |
| 350 |
|
| 351 |
static int ccu_pll_is_enabled(struct clk_hw *hw) |
| 352 |
{ |
| 353 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 354 |
|
| 355 |
return !regmap_test_bits(pll->common.map, pll->common.cfg1, |
| 356 |
TH1520_PLL_VCO_RST); |
| 357 |
} |
| 358 |
|
| 359 |
static unsigned long th1520_pll_vco_recalc_rate(struct clk_hw *hw, |
| 360 |
unsigned long parent_rate) |
| 361 |
{ |
| 362 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 363 |
unsigned long div, mul, frac; |
| 364 |
unsigned int cfg0, cfg1; |
| 365 |
u64 rate = parent_rate; |
| 366 |
|
| 367 |
regmap_read(pll->common.map, pll->common.cfg0, &cfg0); |
| 368 |
regmap_read(pll->common.map, pll->common.cfg1, &cfg1); |
| 369 |
|
| 370 |
mul = FIELD_GET(TH1520_PLL_FBDIV, cfg0); |
| 371 |
div = FIELD_GET(TH1520_PLL_REFDIV, cfg0); |
| 372 |
if (!(cfg1 & TH1520_PLL_DSMPD)) { |
| 373 |
mul <<= TH1520_PLL_FRAC_BITS; |
| 374 |
frac = FIELD_GET(TH1520_PLL_FRAC, cfg1); |
| 375 |
mul += frac; |
| 376 |
div <<= TH1520_PLL_FRAC_BITS; |
| 377 |
} |
| 378 |
rate = parent_rate * mul; |
| 379 |
rate = rate / div; |
| 380 |
return rate; |
| 381 |
} |
| 382 |
|
| 383 |
static unsigned long th1520_pll_postdiv_recalc_rate(struct clk_hw *hw, |
| 384 |
unsigned long parent_rate) |
| 385 |
{ |
| 386 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 387 |
unsigned long div, rate = parent_rate; |
| 388 |
unsigned int cfg0, cfg1; |
| 389 |
|
| 390 |
regmap_read(pll->common.map, pll->common.cfg0, &cfg0); |
| 391 |
regmap_read(pll->common.map, pll->common.cfg1, &cfg1); |
| 392 |
|
| 393 |
if (cfg1 & TH1520_PLL_BYPASS) |
| 394 |
return rate; |
| 395 |
|
| 396 |
div = FIELD_GET(TH1520_PLL_POSTDIV1, cfg0) * |
| 397 |
FIELD_GET(TH1520_PLL_POSTDIV2, cfg0); |
| 398 |
|
| 399 |
rate = rate / div; |
| 400 |
|
| 401 |
return rate; |
| 402 |
} |
| 403 |
|
| 404 |
static unsigned long ccu_pll_recalc_rate(struct clk_hw *hw, |
| 405 |
unsigned long parent_rate) |
| 406 |
{ |
| 407 |
unsigned long rate = parent_rate; |
| 408 |
|
| 409 |
rate = th1520_pll_vco_recalc_rate(hw, rate); |
| 410 |
rate = th1520_pll_postdiv_recalc_rate(hw, rate); |
| 411 |
|
| 412 |
return rate; |
| 413 |
} |
| 414 |
|
| 415 |
static const struct ccu_pll_cfg *ccu_pll_lookup_best_cfg(struct ccu_pll *pll, |
| 416 |
unsigned long rate) |
| 417 |
{ |
| 418 |
unsigned long best_delta = ULONG_MAX; |
| 419 |
const struct ccu_pll_cfg *best_cfg; |
| 420 |
int i; |
| 421 |
|
| 422 |
for (i = 0; i < pll->cfgnum; i++) { |
| 423 |
const struct ccu_pll_cfg *cfg = &pll->cfgs[i]; |
| 424 |
unsigned long delta; |
| 425 |
|
| 426 |
delta = abs_diff(cfg->freq, rate); |
| 427 |
if (delta < best_delta) { |
| 428 |
best_delta = delta; |
| 429 |
best_cfg = cfg; |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
return best_cfg; |
| 434 |
} |
| 435 |
|
| 436 |
static int ccu_pll_determine_rate(struct clk_hw *hw, |
| 437 |
struct clk_rate_request *req) |
| 438 |
{ |
| 439 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 440 |
|
| 441 |
req->rate = ccu_pll_lookup_best_cfg(pll, req->rate)->freq; |
| 442 |
|
| 443 |
return 0; |
| 444 |
} |
| 445 |
|
| 446 |
static int ccu_pll_set_rate(struct clk_hw *hw, unsigned long rate, |
| 447 |
unsigned long parent_rate) |
| 448 |
{ |
| 449 |
struct ccu_pll *pll = hw_to_ccu_pll(hw); |
| 450 |
const struct ccu_pll_cfg *cfg; |
| 451 |
|
| 452 |
cfg = ccu_pll_lookup_best_cfg(pll, rate); |
| 453 |
|
| 454 |
ccu_pll_disable(hw); |
| 455 |
|
| 456 |
regmap_write(pll->common.map, pll->common.cfg0, |
| 457 |
FIELD_PREP(TH1520_PLL_REFDIV, 1) | |
| 458 |
FIELD_PREP(TH1520_PLL_FBDIV, cfg->fbdiv) | |
| 459 |
FIELD_PREP(TH1520_PLL_POSTDIV1, cfg->postdiv1) | |
| 460 |
FIELD_PREP(TH1520_PLL_POSTDIV2, cfg->postdiv2)); |
| 461 |
|
| 462 |
regmap_update_bits(pll->common.map, pll->common.cfg1, |
| 463 |
TH1520_PLL_DACPD | TH1520_PLL_DSMPD | |
| 464 |
TH1520_PLL_FRAC, |
| 465 |
cfg->frac ? cfg->frac : |
| 466 |
TH1520_PLL_DACPD | TH1520_PLL_DSMPD); |
| 467 |
|
| 468 |
return ccu_pll_enable(hw); |
| 469 |
} |
| 470 |
|
| 471 |
static const struct clk_ops clk_pll_ops = { |
| 472 |
.disable = ccu_pll_disable, |
| 473 |
.enable = ccu_pll_enable, |
| 474 |
.is_enabled = ccu_pll_is_enabled, |
| 475 |
.recalc_rate = ccu_pll_recalc_rate, |
| 476 |
.determine_rate = ccu_pll_determine_rate, |
| 477 |
.set_rate = ccu_pll_set_rate, |
| 478 |
}; |
| 479 |
|
| 480 |
/* |
| 481 |
* c910_clk could be reparented glitchlessly for DVFS. There are two parents, |
| 482 |
* - c910_i0_clk, derived from cpu_pll0_clk or osc_24m. |
| 483 |
* - cpu_pll1_clk, which provides the exact same set of rates as cpu_pll0_clk. |
| 484 |
* |
| 485 |
* During rate setting, always forward the request to the unused parent, and |
| 486 |
* then switch c910_clk to it to avoid glitch. |
| 487 |
*/ |
| 488 |
static u8 c910_clk_get_parent(struct clk_hw *hw) |
| 489 |
{ |
| 490 |
return clk_mux_ops.get_parent(hw); |
| 491 |
} |
| 492 |
|
| 493 |
static int c910_clk_set_parent(struct clk_hw *hw, u8 index) |
| 494 |
{ |
| 495 |
return clk_mux_ops.set_parent(hw, index); |
| 496 |
} |
| 497 |
|
| 498 |
static unsigned long c910_clk_recalc_rate(struct clk_hw *hw, |
| 499 |
unsigned long parent_rate) |
| 500 |
{ |
| 501 |
return parent_rate; |
| 502 |
} |
| 503 |
|
| 504 |
static int c910_clk_determine_rate(struct clk_hw *hw, |
| 505 |
struct clk_rate_request *req) |
| 506 |
{ |
| 507 |
u8 alt_parent_index = !c910_clk_get_parent(hw); |
| 508 |
struct clk_hw *alt_parent; |
| 509 |
|
| 510 |
alt_parent = clk_hw_get_parent_by_index(hw, alt_parent_index); |
| 511 |
|
| 512 |
req->rate = clk_hw_round_rate(alt_parent, req->rate); |
| 513 |
req->best_parent_hw = alt_parent; |
| 514 |
req->best_parent_rate = req->rate; |
| 515 |
|
| 516 |
return 0; |
| 517 |
} |
| 518 |
|
| 519 |
static int c910_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 520 |
unsigned long parent_rate) |
| 521 |
{ |
| 522 |
return -EOPNOTSUPP; |
| 523 |
} |
| 524 |
|
| 525 |
static int c910_clk_set_rate_and_parent(struct clk_hw *hw, unsigned long rate, |
| 526 |
unsigned long parent_rate, u8 index) |
| 527 |
{ |
| 528 |
struct clk_hw *parent = clk_hw_get_parent_by_index(hw, index); |
| 529 |
|
| 530 |
clk_set_rate(parent->clk, parent_rate); |
| 531 |
|
| 532 |
c910_clk_set_parent(hw, index); |
| 533 |
|
| 534 |
return 0; |
| 535 |
} |
| 536 |
|
| 537 |
static const struct clk_ops c910_clk_ops = { |
| 538 |
.get_parent = c910_clk_get_parent, |
| 539 |
.set_parent = c910_clk_set_parent, |
| 540 |
.recalc_rate = c910_clk_recalc_rate, |
| 541 |
.determine_rate = c910_clk_determine_rate, |
| 542 |
.set_rate = c910_clk_set_rate, |
| 543 |
.set_rate_and_parent = c910_clk_set_rate_and_parent, |
| 544 |
}; |
| 545 |
|
| 546 |
static const struct clk_parent_data osc_24m_clk[] = { |
| 547 |
{ .index = 0 } |
| 548 |
}; |
| 549 |
|
| 550 |
static const struct ccu_pll_cfg cpu_pll_cfgs[] = { |
| 551 |
{ 125000000, 125, 0, 6, 4 }, |
| 552 |
{ 200000000, 125, 0, 5, 3 }, |
| 553 |
{ 300000000, 125, 0, 5, 2 }, |
| 554 |
{ 400000000, 100, 0, 3, 2 }, |
| 555 |
{ 500000000, 125, 0, 6, 1 }, |
| 556 |
{ 600000000, 125, 0, 5, 1 }, |
| 557 |
{ 702000000, 117, 0, 4, 1 }, |
| 558 |
{ 800000000, 100, 0, 3, 1 }, |
| 559 |
{ 900000000, 75, 0, 2, 1 }, |
| 560 |
{ 1000000000, 125, 0, 3, 1 }, |
| 561 |
{ 1104000000, 92, 0, 2, 1 }, |
| 562 |
{ 1200000000, 100, 0, 2, 1 }, |
| 563 |
{ 1296000000, 108, 0, 2, 1 }, |
| 564 |
{ 1404000000, 117, 0, 2, 1 }, |
| 565 |
{ 1500000000, 125, 0, 2, 1 }, |
| 566 |
{ 1608000000, 67, 0, 1, 1 }, |
| 567 |
{ 1704000000, 71, 0, 1, 1 }, |
| 568 |
{ 1800000000, 75, 0, 1, 1 }, |
| 569 |
{ 1896000000, 79, 0, 1, 1 }, |
| 570 |
{ 1992000000, 83, 0, 1, 1 }, |
| 571 |
{ 2112000000, 88, 0, 1, 1 }, |
| 572 |
{ 2208000000, 92, 0, 1, 1 }, |
| 573 |
{ 2304000000, 96, 0, 1, 1 }, |
| 574 |
{ 2400000000, 100, 0, 1, 1 }, |
| 575 |
}; |
| 576 |
|
| 577 |
static struct ccu_pll cpu_pll0_clk = { |
| 578 |
.common = { |
| 579 |
.clkid = CLK_CPU_PLL0, |
| 580 |
.cfg0 = 0x000, |
| 581 |
.cfg1 = 0x004, |
| 582 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("cpu-pll0", |
| 583 |
osc_24m_clk, |
| 584 |
&clk_pll_ops, |
| 585 |
CLK_IS_CRITICAL), |
| 586 |
}, |
| 587 |
.lock_sts_mask = BIT(1), |
| 588 |
.cfgnum = ARRAY_SIZE(cpu_pll_cfgs), |
| 589 |
.cfgs = cpu_pll_cfgs, |
| 590 |
}; |
| 591 |
|
| 592 |
static struct ccu_pll cpu_pll1_clk = { |
| 593 |
.common = { |
| 594 |
.clkid = CLK_CPU_PLL1, |
| 595 |
.cfg0 = 0x010, |
| 596 |
.cfg1 = 0x014, |
| 597 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("cpu-pll1", |
| 598 |
osc_24m_clk, |
| 599 |
&clk_pll_ops, |
| 600 |
CLK_IS_CRITICAL), |
| 601 |
}, |
| 602 |
.lock_sts_mask = BIT(4), |
| 603 |
.cfgnum = ARRAY_SIZE(cpu_pll_cfgs), |
| 604 |
.cfgs = cpu_pll_cfgs, |
| 605 |
}; |
| 606 |
|
| 607 |
static const struct ccu_pll_cfg gmac_pll_cfg = { |
| 608 |
.freq = 1000000000, |
| 609 |
.fbdiv = 125, |
| 610 |
.frac = 0, |
| 611 |
.postdiv1 = 3, |
| 612 |
.postdiv2 = 1, |
| 613 |
}; |
| 614 |
|
| 615 |
static struct ccu_pll gmac_pll_clk = { |
| 616 |
.common = { |
| 617 |
.clkid = CLK_GMAC_PLL, |
| 618 |
.cfg0 = 0x020, |
| 619 |
.cfg1 = 0x024, |
| 620 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("gmac-pll", |
| 621 |
osc_24m_clk, |
| 622 |
&clk_pll_ops, |
| 623 |
CLK_IS_CRITICAL), |
| 624 |
}, |
| 625 |
.lock_sts_mask = BIT(3), |
| 626 |
.cfgnum = 1, |
| 627 |
.cfgs = &gmac_pll_cfg, |
| 628 |
}; |
| 629 |
|
| 630 |
static const struct clk_hw *gmac_pll_clk_parent[] = { |
| 631 |
&gmac_pll_clk.common.hw |
| 632 |
}; |
| 633 |
|
| 634 |
static const struct clk_parent_data gmac_pll_clk_pd[] = { |
| 635 |
{ .hw = &gmac_pll_clk.common.hw } |
| 636 |
}; |
| 637 |
|
| 638 |
static const struct ccu_pll_cfg video_pll_cfg = { |
| 639 |
.freq = 792000000, |
| 640 |
.fbdiv = 99, |
| 641 |
.frac = 0, |
| 642 |
.postdiv1 = 3, |
| 643 |
.postdiv2 = 1, |
| 644 |
}; |
| 645 |
|
| 646 |
static struct ccu_pll video_pll_clk = { |
| 647 |
.common = { |
| 648 |
.clkid = CLK_VIDEO_PLL, |
| 649 |
.cfg0 = 0x030, |
| 650 |
.cfg1 = 0x034, |
| 651 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("video-pll", |
| 652 |
osc_24m_clk, |
| 653 |
&clk_pll_ops, |
| 654 |
CLK_IS_CRITICAL), |
| 655 |
}, |
| 656 |
.lock_sts_mask = BIT(7), |
| 657 |
.cfgnum = 1, |
| 658 |
.cfgs = &video_pll_cfg, |
| 659 |
}; |
| 660 |
|
| 661 |
static const struct clk_hw *video_pll_clk_parent[] = { |
| 662 |
&video_pll_clk.common.hw |
| 663 |
}; |
| 664 |
|
| 665 |
static const struct clk_parent_data video_pll_clk_pd[] = { |
| 666 |
{ .hw = &video_pll_clk.common.hw } |
| 667 |
}; |
| 668 |
|
| 669 |
static const struct ccu_pll_cfg dpu_pll_cfg = { |
| 670 |
.freq = 1188000000, |
| 671 |
.fbdiv = 99, |
| 672 |
.frac = 0, |
| 673 |
.postdiv1 = 2, |
| 674 |
.postdiv2 = 1, |
| 675 |
}; |
| 676 |
|
| 677 |
static struct ccu_pll dpu0_pll_clk = { |
| 678 |
.common = { |
| 679 |
.clkid = CLK_DPU0_PLL, |
| 680 |
.cfg0 = 0x040, |
| 681 |
.cfg1 = 0x044, |
| 682 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("dpu0-pll", |
| 683 |
osc_24m_clk, |
| 684 |
&clk_pll_ops, |
| 685 |
0), |
| 686 |
}, |
| 687 |
.lock_sts_mask = BIT(8), |
| 688 |
.cfgnum = 1, |
| 689 |
.cfgs = &dpu_pll_cfg, |
| 690 |
}; |
| 691 |
|
| 692 |
static const struct clk_hw *dpu0_pll_clk_parent[] = { |
| 693 |
&dpu0_pll_clk.common.hw |
| 694 |
}; |
| 695 |
|
| 696 |
static struct ccu_pll dpu1_pll_clk = { |
| 697 |
.common = { |
| 698 |
.clkid = CLK_DPU1_PLL, |
| 699 |
.cfg0 = 0x050, |
| 700 |
.cfg1 = 0x054, |
| 701 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("dpu1-pll", |
| 702 |
osc_24m_clk, |
| 703 |
&clk_pll_ops, |
| 704 |
0), |
| 705 |
}, |
| 706 |
.lock_sts_mask = BIT(9), |
| 707 |
.cfgnum = 1, |
| 708 |
.cfgs = &dpu_pll_cfg, |
| 709 |
}; |
| 710 |
|
| 711 |
static const struct clk_hw *dpu1_pll_clk_parent[] = { |
| 712 |
&dpu1_pll_clk.common.hw |
| 713 |
}; |
| 714 |
|
| 715 |
static const struct ccu_pll_cfg tee_pll_cfg = { |
| 716 |
.freq = 792000000, |
| 717 |
.fbdiv = 99, |
| 718 |
.frac = 0, |
| 719 |
.postdiv1 = 3, |
| 720 |
.postdiv2 = 1, |
| 721 |
}; |
| 722 |
|
| 723 |
static struct ccu_pll tee_pll_clk = { |
| 724 |
.common = { |
| 725 |
.clkid = CLK_TEE_PLL, |
| 726 |
.cfg0 = 0x060, |
| 727 |
.cfg1 = 0x064, |
| 728 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("tee-pll", |
| 729 |
osc_24m_clk, |
| 730 |
&clk_pll_ops, |
| 731 |
CLK_IS_CRITICAL), |
| 732 |
}, |
| 733 |
.lock_sts_mask = BIT(10), |
| 734 |
.cfgnum = 1, |
| 735 |
.cfgs = &tee_pll_cfg, |
| 736 |
}; |
| 737 |
|
| 738 |
static const struct clk_parent_data c910_i0_parents[] = { |
| 739 |
{ .hw = &cpu_pll0_clk.common.hw }, |
| 740 |
{ .index = 0 } |
| 741 |
}; |
| 742 |
|
| 743 |
static struct ccu_mux c910_i0_clk = { |
| 744 |
.clkid = CLK_C910_I0, |
| 745 |
.reg = 0x100, |
| 746 |
.mux = TH_CCU_MUX_FLAGS("c910-i0", c910_i0_parents, 1, 1, |
| 747 |
CLK_SET_RATE_PARENT, CLK_MUX_ROUND_CLOSEST), |
| 748 |
}; |
| 749 |
|
| 750 |
static const struct clk_parent_data c910_parents[] = { |
| 751 |
{ .hw = &c910_i0_clk.mux.hw }, |
| 752 |
{ .hw = &cpu_pll1_clk.common.hw } |
| 753 |
}; |
| 754 |
|
| 755 |
static struct ccu_mux c910_clk = { |
| 756 |
.clkid = CLK_C910, |
| 757 |
.reg = 0x100, |
| 758 |
.mux = { |
| 759 |
.mask = BIT(0), |
| 760 |
.shift = 0, |
| 761 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("c910", |
| 762 |
c910_parents, |
| 763 |
&c910_clk_ops, |
| 764 |
CLK_SET_RATE_PARENT), |
| 765 |
}, |
| 766 |
}; |
| 767 |
|
| 768 |
static struct ccu_div c910_bus_clk = { |
| 769 |
.enable = BIT(7), |
| 770 |
.div_en = BIT(11), |
| 771 |
.div = TH_CCU_DIV_FLAGS(8, 3, 0), |
| 772 |
.common = { |
| 773 |
.clkid = CLK_C910_BUS, |
| 774 |
.cfg0 = 0x100, |
| 775 |
.hw.init = CLK_HW_INIT_HW("c910-bus", |
| 776 |
&c910_clk.mux.hw, |
| 777 |
&ccu_div_ops, |
| 778 |
CLK_IS_CRITICAL), |
| 779 |
}, |
| 780 |
}; |
| 781 |
|
| 782 |
static const struct clk_parent_data ahb2_cpusys_parents[] = { |
| 783 |
{ .hw = &gmac_pll_clk.common.hw }, |
| 784 |
{ .index = 0 } |
| 785 |
}; |
| 786 |
|
| 787 |
static struct ccu_div ahb2_cpusys_hclk = { |
| 788 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 789 |
.mux = TH_CCU_ARG(5, 1), |
| 790 |
.common = { |
| 791 |
.clkid = CLK_AHB2_CPUSYS_HCLK, |
| 792 |
.cfg0 = 0x120, |
| 793 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("ahb2-cpusys-hclk", |
| 794 |
ahb2_cpusys_parents, |
| 795 |
&ccu_div_ops, |
| 796 |
0), |
| 797 |
}, |
| 798 |
}; |
| 799 |
|
| 800 |
static const struct clk_parent_data ahb2_cpusys_hclk_pd[] = { |
| 801 |
{ .hw = &ahb2_cpusys_hclk.common.hw } |
| 802 |
}; |
| 803 |
|
| 804 |
static const struct clk_hw *ahb2_cpusys_hclk_parent[] = { |
| 805 |
&ahb2_cpusys_hclk.common.hw, |
| 806 |
}; |
| 807 |
|
| 808 |
static struct ccu_div apb3_cpusys_pclk = { |
| 809 |
.div = TH_CCU_ARG(0, 3), |
| 810 |
.common = { |
| 811 |
.clkid = CLK_APB3_CPUSYS_PCLK, |
| 812 |
.cfg0 = 0x130, |
| 813 |
.hw.init = CLK_HW_INIT_PARENTS_HW("apb3-cpusys-pclk", |
| 814 |
ahb2_cpusys_hclk_parent, |
| 815 |
&ccu_div_ops, |
| 816 |
0), |
| 817 |
}, |
| 818 |
}; |
| 819 |
|
| 820 |
static const struct clk_parent_data apb3_cpusys_pclk_pd[] = { |
| 821 |
{ .hw = &apb3_cpusys_pclk.common.hw } |
| 822 |
}; |
| 823 |
|
| 824 |
static struct ccu_div axi4_cpusys2_aclk = { |
| 825 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 826 |
.common = { |
| 827 |
.clkid = CLK_AXI4_CPUSYS2_ACLK, |
| 828 |
.cfg0 = 0x134, |
| 829 |
.hw.init = CLK_HW_INIT_PARENTS_HW("axi4-cpusys2-aclk", |
| 830 |
gmac_pll_clk_parent, |
| 831 |
&ccu_div_ops, |
| 832 |
CLK_IS_CRITICAL), |
| 833 |
}, |
| 834 |
}; |
| 835 |
|
| 836 |
static const struct clk_parent_data axi4_cpusys2_aclk_pd[] = { |
| 837 |
{ .hw = &axi4_cpusys2_aclk.common.hw } |
| 838 |
}; |
| 839 |
|
| 840 |
static const struct clk_parent_data axi_parents[] = { |
| 841 |
{ .hw = &video_pll_clk.common.hw }, |
| 842 |
{ .index = 0 } |
| 843 |
}; |
| 844 |
|
| 845 |
static struct ccu_div axi_aclk = { |
| 846 |
.div = TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED), |
| 847 |
.mux = TH_CCU_ARG(5, 1), |
| 848 |
.common = { |
| 849 |
.clkid = CLK_AXI_ACLK, |
| 850 |
.cfg0 = 0x138, |
| 851 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("axi-aclk", |
| 852 |
axi_parents, |
| 853 |
&ccu_div_ops, |
| 854 |
CLK_IS_CRITICAL), |
| 855 |
}, |
| 856 |
}; |
| 857 |
|
| 858 |
static const struct clk_parent_data axi_aclk_pd[] = { |
| 859 |
{ .hw = &axi_aclk.common.hw } |
| 860 |
}; |
| 861 |
|
| 862 |
static const struct clk_parent_data perisys_ahb_hclk_parents[] = { |
| 863 |
{ .hw = &gmac_pll_clk.common.hw }, |
| 864 |
{ .index = 0 }, |
| 865 |
}; |
| 866 |
|
| 867 |
static struct ccu_div perisys_ahb_hclk = { |
| 868 |
.enable = BIT(6), |
| 869 |
.div = TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED), |
| 870 |
.mux = TH_CCU_ARG(5, 1), |
| 871 |
.common = { |
| 872 |
.clkid = CLK_PERI_AHB_HCLK, |
| 873 |
.cfg0 = 0x140, |
| 874 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("perisys-ahb-hclk", |
| 875 |
perisys_ahb_hclk_parents, |
| 876 |
&ccu_div_ops, |
| 877 |
0), |
| 878 |
}, |
| 879 |
}; |
| 880 |
|
| 881 |
static const struct clk_parent_data perisys_ahb_hclk_pd[] = { |
| 882 |
{ .hw = &perisys_ahb_hclk.common.hw } |
| 883 |
}; |
| 884 |
|
| 885 |
static const struct clk_hw *perisys_ahb_hclk_parent[] = { |
| 886 |
&perisys_ahb_hclk.common.hw |
| 887 |
}; |
| 888 |
|
| 889 |
static struct ccu_div perisys_apb_pclk = { |
| 890 |
.div = TH_CCU_ARG(0, 3), |
| 891 |
.common = { |
| 892 |
.clkid = CLK_PERI_APB_PCLK, |
| 893 |
.cfg0 = 0x150, |
| 894 |
.hw.init = CLK_HW_INIT_PARENTS_HW("perisys-apb-pclk", |
| 895 |
perisys_ahb_hclk_parent, |
| 896 |
&ccu_div_ops, |
| 897 |
0), |
| 898 |
}, |
| 899 |
}; |
| 900 |
|
| 901 |
static const struct clk_parent_data perisys_apb_pclk_pd[] = { |
| 902 |
{ .hw = &perisys_apb_pclk.common.hw } |
| 903 |
}; |
| 904 |
|
| 905 |
static struct ccu_div peri2sys_apb_pclk = { |
| 906 |
.div = TH_CCU_DIV_FLAGS(4, 3, CLK_DIVIDER_ONE_BASED), |
| 907 |
.common = { |
| 908 |
.clkid = CLK_PERI2APB_PCLK, |
| 909 |
.cfg0 = 0x150, |
| 910 |
.hw.init = CLK_HW_INIT_PARENTS_HW("peri2sys-apb-pclk", |
| 911 |
gmac_pll_clk_parent, |
| 912 |
&ccu_div_ops, |
| 913 |
0), |
| 914 |
}, |
| 915 |
}; |
| 916 |
|
| 917 |
static const struct clk_parent_data peri2sys_apb_pclk_pd[] = { |
| 918 |
{ .hw = &peri2sys_apb_pclk.common.hw } |
| 919 |
}; |
| 920 |
|
| 921 |
static struct clk_fixed_factor osc12m_clk = { |
| 922 |
.div = 2, |
| 923 |
.mult = 1, |
| 924 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("osc_12m", |
| 925 |
osc_24m_clk, |
| 926 |
&clk_fixed_factor_ops, |
| 927 |
0), |
| 928 |
}; |
| 929 |
|
| 930 |
static const char * const out_parents[] = { "osc_24m", "osc_12m" }; |
| 931 |
|
| 932 |
static struct ccu_div out1_clk = { |
| 933 |
.enable = BIT(5), |
| 934 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 935 |
.mux = TH_CCU_ARG(4, 1), |
| 936 |
.common = { |
| 937 |
.clkid = CLK_OUT1, |
| 938 |
.cfg0 = 0x1b4, |
| 939 |
.hw.init = CLK_HW_INIT_PARENTS("out1", |
| 940 |
out_parents, |
| 941 |
&ccu_div_ops, |
| 942 |
0), |
| 943 |
}, |
| 944 |
}; |
| 945 |
|
| 946 |
static struct ccu_div out2_clk = { |
| 947 |
.enable = BIT(5), |
| 948 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 949 |
.mux = TH_CCU_ARG(4, 1), |
| 950 |
.common = { |
| 951 |
.clkid = CLK_OUT2, |
| 952 |
.cfg0 = 0x1b8, |
| 953 |
.hw.init = CLK_HW_INIT_PARENTS("out2", |
| 954 |
out_parents, |
| 955 |
&ccu_div_ops, |
| 956 |
0), |
| 957 |
}, |
| 958 |
}; |
| 959 |
|
| 960 |
static struct ccu_div out3_clk = { |
| 961 |
.enable = BIT(5), |
| 962 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 963 |
.mux = TH_CCU_ARG(4, 1), |
| 964 |
.common = { |
| 965 |
.clkid = CLK_OUT3, |
| 966 |
.cfg0 = 0x1bc, |
| 967 |
.hw.init = CLK_HW_INIT_PARENTS("out3", |
| 968 |
out_parents, |
| 969 |
&ccu_div_ops, |
| 970 |
0), |
| 971 |
}, |
| 972 |
}; |
| 973 |
|
| 974 |
static struct ccu_div out4_clk = { |
| 975 |
.enable = BIT(5), |
| 976 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 977 |
.mux = TH_CCU_ARG(4, 1), |
| 978 |
.common = { |
| 979 |
.clkid = CLK_OUT4, |
| 980 |
.cfg0 = 0x1c0, |
| 981 |
.hw.init = CLK_HW_INIT_PARENTS("out4", |
| 982 |
out_parents, |
| 983 |
&ccu_div_ops, |
| 984 |
0), |
| 985 |
}, |
| 986 |
}; |
| 987 |
|
| 988 |
static const struct clk_parent_data apb_parents[] = { |
| 989 |
{ .hw = &gmac_pll_clk.common.hw }, |
| 990 |
{ .index = 0 }, |
| 991 |
}; |
| 992 |
|
| 993 |
static struct ccu_div apb_pclk = { |
| 994 |
.enable = BIT(5), |
| 995 |
.div = TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED), |
| 996 |
.mux = TH_CCU_ARG(7, 1), |
| 997 |
.common = { |
| 998 |
.clkid = CLK_APB_PCLK, |
| 999 |
.cfg0 = 0x1c4, |
| 1000 |
.hw.init = CLK_HW_INIT_PARENTS_DATA("apb-pclk", |
| 1001 |
apb_parents, |
| 1002 |
&ccu_div_ops, |
| 1003 |
CLK_IS_CRITICAL), |
| 1004 |
}, |
| 1005 |
}; |
| 1006 |
|
| 1007 |
static const struct clk_hw *npu_parents[] = { |
| 1008 |
&gmac_pll_clk.common.hw, |
| 1009 |
&video_pll_clk.common.hw |
| 1010 |
}; |
| 1011 |
|
| 1012 |
static struct ccu_div npu_clk = { |
| 1013 |
.enable = BIT(4), |
| 1014 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 1015 |
.mux = TH_CCU_ARG(6, 1), |
| 1016 |
.common = { |
| 1017 |
.clkid = CLK_NPU, |
| 1018 |
.cfg0 = 0x1c8, |
| 1019 |
.hw.init = CLK_HW_INIT_PARENTS_HW("npu", |
| 1020 |
npu_parents, |
| 1021 |
&ccu_div_ops, |
| 1022 |
0), |
| 1023 |
}, |
| 1024 |
}; |
| 1025 |
|
| 1026 |
static struct ccu_div vi_clk = { |
| 1027 |
.div = TH_CCU_DIV_FLAGS(16, 4, CLK_DIVIDER_ONE_BASED), |
| 1028 |
.common = { |
| 1029 |
.clkid = CLK_VI, |
| 1030 |
.cfg0 = 0x1d0, |
| 1031 |
.hw.init = CLK_HW_INIT_PARENTS_HW("vi", |
| 1032 |
video_pll_clk_parent, |
| 1033 |
&ccu_div_ops, |
| 1034 |
CLK_IS_CRITICAL), |
| 1035 |
}, |
| 1036 |
}; |
| 1037 |
|
| 1038 |
static struct ccu_div vi_ahb_clk = { |
| 1039 |
.div = TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED), |
| 1040 |
.common = { |
| 1041 |
.clkid = CLK_VI_AHB, |
| 1042 |
.cfg0 = 0x1d0, |
| 1043 |
.hw.init = CLK_HW_INIT_PARENTS_HW("vi-ahb", |
| 1044 |
video_pll_clk_parent, |
| 1045 |
&ccu_div_ops, |
| 1046 |
0), |
| 1047 |
}, |
| 1048 |
}; |
| 1049 |
|
| 1050 |
static struct ccu_div vo_axi_clk = { |
| 1051 |
.enable = BIT(5), |
| 1052 |
.div = TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED), |
| 1053 |
.common = { |
| 1054 |
.clkid = CLK_VO_AXI, |
| 1055 |
.cfg0 = 0x1dc, |
| 1056 |
.hw.init = CLK_HW_INIT_PARENTS_HW("vo-axi", |
| 1057 |
video_pll_clk_parent, |
| 1058 |
&ccu_div_ops, |
| 1059 |
CLK_IS_CRITICAL), |
| 1060 |
}, |
| 1061 |
}; |
| 1062 |
|
| 1063 |
static struct ccu_div vp_apb_clk = { |
| 1064 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 1065 |
.common = { |
| 1066 |
.clkid = CLK_VP_APB, |
| 1067 |
.cfg0 = 0x1e0, |
| 1068 |
.hw.init = CLK_HW_INIT_PARENTS_HW("vp-apb", |
| 1069 |
gmac_pll_clk_parent, |
| 1070 |
&ccu_div_ops, |
| 1071 |
0), |
| 1072 |
}, |
| 1073 |
}; |
| 1074 |
|
| 1075 |
static struct ccu_div vp_axi_clk = { |
| 1076 |
.enable = BIT(15), |
| 1077 |
.div = TH_CCU_DIV_FLAGS(8, 4, CLK_DIVIDER_ONE_BASED), |
| 1078 |
.common = { |
| 1079 |
.clkid = CLK_VP_AXI, |
| 1080 |
.cfg0 = 0x1e0, |
| 1081 |
.hw.init = CLK_HW_INIT_PARENTS_HW("vp-axi", |
| 1082 |
video_pll_clk_parent, |
| 1083 |
&ccu_div_ops, |
| 1084 |
CLK_IS_CRITICAL), |
| 1085 |
}, |
| 1086 |
}; |
| 1087 |
|
| 1088 |
static struct ccu_div venc_clk = { |
| 1089 |
.enable = BIT(5), |
| 1090 |
.div = TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED), |
| 1091 |
.common = { |
| 1092 |
.clkid = CLK_VENC, |
| 1093 |
.cfg0 = 0x1e4, |
| 1094 |
.hw.init = CLK_HW_INIT_PARENTS_HW("venc", |
| 1095 |
gmac_pll_clk_parent, |
| 1096 |
&ccu_div_ops, |
| 1097 |
0), |
| 1098 |
}, |
| 1099 |
}; |
| 1100 |
|
| 1101 |
static struct ccu_div dpu0_clk = { |
| 1102 |
.div_en = BIT(8), |
| 1103 |
.div = TH_CCU_DIV_FLAGS(0, 8, CLK_DIVIDER_ONE_BASED), |
| 1104 |
.common = { |
| 1105 |
.clkid = CLK_DPU0, |
| 1106 |
.cfg0 = 0x1e8, |
| 1107 |
.hw.init = CLK_HW_INIT_PARENTS_HW("dpu0", |
| 1108 |
dpu0_pll_clk_parent, |
| 1109 |
&ccu_div_ops, |
| 1110 |
CLK_SET_RATE_UNGATE), |
| 1111 |
}, |
| 1112 |
}; |
| 1113 |
|
| 1114 |
static const struct clk_parent_data dpu0_clk_pd[] = { |
| 1115 |
{ .hw = &dpu0_clk.common.hw } |
| 1116 |
}; |
| 1117 |
|
| 1118 |
static struct ccu_div dpu1_clk = { |
| 1119 |
.div_en = BIT(8), |
| 1120 |
.div = TH_CCU_DIV_FLAGS(0, 8, CLK_DIVIDER_ONE_BASED), |
| 1121 |
.common = { |
| 1122 |
.clkid = CLK_DPU1, |
| 1123 |
.cfg0 = 0x1ec, |
| 1124 |
.hw.init = CLK_HW_INIT_PARENTS_HW("dpu1", |
| 1125 |
dpu1_pll_clk_parent, |
| 1126 |
&ccu_div_ops, |
| 1127 |
CLK_SET_RATE_UNGATE), |
| 1128 |
}, |
| 1129 |
}; |
| 1130 |
|
| 1131 |
static const struct clk_parent_data dpu1_clk_pd[] = { |
| 1132 |
{ .hw = &dpu1_clk.common.hw } |
| 1133 |
}; |
| 1134 |
|
| 1135 |
static CLK_FIXED_FACTOR_HW(emmc_sdio_ref_clk, "emmc-sdio-ref", |
| 1136 |
&video_pll_clk.common.hw, 4, 1, 0); |
| 1137 |
|
| 1138 |
static const struct clk_parent_data emmc_sdio_ref_clk_pd[] = { |
| 1139 |
{ .hw = &emmc_sdio_ref_clk.hw }, |
| 1140 |
}; |
| 1141 |
|
| 1142 |
static CCU_GATE(CLK_BROM, brom_clk, "brom", ahb2_cpusys_hclk_pd, 0x100, 4, 0); |
| 1143 |
static CCU_GATE(CLK_BMU, bmu_clk, "bmu", axi4_cpusys2_aclk_pd, 0x100, 5, 0); |
| 1144 |
static CCU_GATE(CLK_AON2CPU_A2X, aon2cpu_a2x_clk, "aon2cpu-a2x", axi4_cpusys2_aclk_pd, |
| 1145 |
0x134, 8, CLK_IS_CRITICAL); |
| 1146 |
static CCU_GATE(CLK_X2X_CPUSYS, x2x_cpusys_clk, "x2x-cpusys", axi4_cpusys2_aclk_pd, |
| 1147 |
0x134, 7, CLK_IS_CRITICAL); |
| 1148 |
static CCU_GATE(CLK_CPU2AON_X2H, cpu2aon_x2h_clk, "cpu2aon-x2h", axi_aclk_pd, |
| 1149 |
0x138, 8, CLK_IS_CRITICAL); |
| 1150 |
static CCU_GATE(CLK_CPU2PERI_X2H, cpu2peri_x2h_clk, "cpu2peri-x2h", axi4_cpusys2_aclk_pd, |
| 1151 |
0x140, 9, CLK_IS_CRITICAL); |
| 1152 |
static CCU_GATE(CLK_PERISYS_APB1_HCLK, perisys_apb1_hclk, "perisys-apb1-hclk", perisys_ahb_hclk_pd, |
| 1153 |
0x150, 9, CLK_IS_CRITICAL); |
| 1154 |
static CCU_GATE(CLK_PERISYS_APB2_HCLK, perisys_apb2_hclk, "perisys-apb2-hclk", perisys_ahb_hclk_pd, |
| 1155 |
0x150, 10, CLK_IS_CRITICAL); |
| 1156 |
static CCU_GATE(CLK_PERISYS_APB3_HCLK, perisys_apb3_hclk, "perisys-apb3-hclk", perisys_ahb_hclk_pd, |
| 1157 |
0x150, 11, CLK_IS_CRITICAL); |
| 1158 |
static CCU_GATE(CLK_PERISYS_APB4_HCLK, perisys_apb4_hclk, "perisys-apb4-hclk", perisys_ahb_hclk_pd, |
| 1159 |
0x150, 12, 0); |
| 1160 |
static const struct clk_parent_data perisys_apb4_hclk_pd[] = { |
| 1161 |
{ .hw = &perisys_apb4_hclk.gate.hw }, |
| 1162 |
}; |
| 1163 |
|
| 1164 |
static CCU_GATE(CLK_NPU_AXI, npu_axi_clk, "npu-axi", axi_aclk_pd, 0x1c8, 5, CLK_IS_CRITICAL); |
| 1165 |
static CCU_GATE(CLK_CPU2VP, cpu2vp_clk, "cpu2vp", axi_aclk_pd, 0x1e0, 13, CLK_IS_CRITICAL); |
| 1166 |
static CCU_GATE(CLK_EMMC_SDIO, emmc_sdio_clk, "emmc-sdio", emmc_sdio_ref_clk_pd, 0x204, 30, 0); |
| 1167 |
static CCU_GATE(CLK_GMAC1, gmac1_clk, "gmac1", gmac_pll_clk_pd, 0x204, 26, 0); |
| 1168 |
static CCU_GATE(CLK_PADCTRL1, padctrl1_clk, "padctrl1", perisys_apb_pclk_pd, 0x204, 24, 0); |
| 1169 |
static CCU_GATE(CLK_DSMART, dsmart_clk, "dsmart", perisys_apb_pclk_pd, 0x204, 23, 0); |
| 1170 |
static CCU_GATE(CLK_PADCTRL0, padctrl0_clk, "padctrl0", perisys_apb4_hclk_pd, 0x204, 22, 0); |
| 1171 |
static CCU_GATE(CLK_GMAC_AXI, gmac_axi_clk, "gmac-axi", axi4_cpusys2_aclk_pd, 0x204, 21, 0); |
| 1172 |
static CCU_GATE(CLK_GPIO3, gpio3_clk, "gpio3-clk", peri2sys_apb_pclk_pd, 0x204, 20, 0); |
| 1173 |
static CCU_GATE(CLK_GMAC0, gmac0_clk, "gmac0", gmac_pll_clk_pd, 0x204, 19, 0); |
| 1174 |
static CCU_GATE(CLK_PWM, pwm_clk, "pwm", perisys_apb_pclk_pd, 0x204, 18, 0); |
| 1175 |
static CCU_GATE(CLK_QSPI0, qspi0_clk, "qspi0", video_pll_clk_pd, 0x204, 17, 0); |
| 1176 |
static CCU_GATE(CLK_QSPI1, qspi1_clk, "qspi1", video_pll_clk_pd, 0x204, 16, 0); |
| 1177 |
static CCU_GATE(CLK_SPI, spi_clk, "spi", video_pll_clk_pd, 0x204, 15, 0); |
| 1178 |
static CCU_GATE(CLK_UART0_PCLK, uart0_pclk, "uart0-pclk", perisys_apb_pclk_pd, 0x204, 14, 0); |
| 1179 |
static CCU_GATE(CLK_UART1_PCLK, uart1_pclk, "uart1-pclk", perisys_apb_pclk_pd, 0x204, 13, 0); |
| 1180 |
static CCU_GATE(CLK_UART2_PCLK, uart2_pclk, "uart2-pclk", perisys_apb_pclk_pd, 0x204, 12, 0); |
| 1181 |
static CCU_GATE(CLK_UART3_PCLK, uart3_pclk, "uart3-pclk", perisys_apb_pclk_pd, 0x204, 11, 0); |
| 1182 |
static CCU_GATE(CLK_UART4_PCLK, uart4_pclk, "uart4-pclk", perisys_apb_pclk_pd, 0x204, 10, 0); |
| 1183 |
static CCU_GATE(CLK_UART5_PCLK, uart5_pclk, "uart5-pclk", perisys_apb_pclk_pd, 0x204, 9, 0); |
| 1184 |
static CCU_GATE(CLK_GPIO0, gpio0_clk, "gpio0-clk", perisys_apb_pclk_pd, 0x204, 8, 0); |
| 1185 |
static CCU_GATE(CLK_GPIO1, gpio1_clk, "gpio1-clk", perisys_apb_pclk_pd, 0x204, 7, 0); |
| 1186 |
static CCU_GATE(CLK_GPIO2, gpio2_clk, "gpio2-clk", peri2sys_apb_pclk_pd, 0x204, 6, 0); |
| 1187 |
static CCU_GATE(CLK_I2C0, i2c0_clk, "i2c0", perisys_apb_pclk_pd, 0x204, 5, 0); |
| 1188 |
static CCU_GATE(CLK_I2C1, i2c1_clk, "i2c1", perisys_apb_pclk_pd, 0x204, 4, 0); |
| 1189 |
static CCU_GATE(CLK_I2C2, i2c2_clk, "i2c2", perisys_apb_pclk_pd, 0x204, 3, 0); |
| 1190 |
static CCU_GATE(CLK_I2C3, i2c3_clk, "i2c3", perisys_apb_pclk_pd, 0x204, 2, 0); |
| 1191 |
static CCU_GATE(CLK_I2C4, i2c4_clk, "i2c4", perisys_apb_pclk_pd, 0x204, 1, 0); |
| 1192 |
static CCU_GATE(CLK_I2C5, i2c5_clk, "i2c5", perisys_apb_pclk_pd, 0x204, 0, 0); |
| 1193 |
static CCU_GATE(CLK_SPINLOCK, spinlock_clk, "spinlock", ahb2_cpusys_hclk_pd, 0x208, 10, 0); |
| 1194 |
static CCU_GATE(CLK_DMA, dma_clk, "dma", axi4_cpusys2_aclk_pd, 0x208, 8, 0); |
| 1195 |
static CCU_GATE(CLK_MBOX0, mbox0_clk, "mbox0", apb3_cpusys_pclk_pd, 0x208, 7, 0); |
| 1196 |
static CCU_GATE(CLK_MBOX1, mbox1_clk, "mbox1", apb3_cpusys_pclk_pd, 0x208, 6, 0); |
| 1197 |
static CCU_GATE(CLK_MBOX2, mbox2_clk, "mbox2", apb3_cpusys_pclk_pd, 0x208, 5, 0); |
| 1198 |
static CCU_GATE(CLK_MBOX3, mbox3_clk, "mbox3", apb3_cpusys_pclk_pd, 0x208, 4, 0); |
| 1199 |
static CCU_GATE(CLK_WDT0, wdt0_clk, "wdt0", apb3_cpusys_pclk_pd, 0x208, 3, 0); |
| 1200 |
static CCU_GATE(CLK_WDT1, wdt1_clk, "wdt1", apb3_cpusys_pclk_pd, 0x208, 2, 0); |
| 1201 |
static CCU_GATE(CLK_TIMER0, timer0_clk, "timer0", apb3_cpusys_pclk_pd, 0x208, 1, 0); |
| 1202 |
static CCU_GATE(CLK_TIMER1, timer1_clk, "timer1", apb3_cpusys_pclk_pd, 0x208, 0, 0); |
| 1203 |
static CCU_GATE(CLK_SRAM0, sram0_clk, "sram0", axi_aclk_pd, 0x20c, 4, 0); |
| 1204 |
static CCU_GATE(CLK_SRAM1, sram1_clk, "sram1", axi_aclk_pd, 0x20c, 3, 0); |
| 1205 |
static CCU_GATE(CLK_SRAM2, sram2_clk, "sram2", axi_aclk_pd, 0x20c, 2, 0); |
| 1206 |
static CCU_GATE(CLK_SRAM3, sram3_clk, "sram3", axi_aclk_pd, 0x20c, 1, 0); |
| 1207 |
|
| 1208 |
static CCU_GATE(CLK_AXI4_VO_ACLK, axi4_vo_aclk, "axi4-vo-aclk", |
| 1209 |
video_pll_clk_pd, 0x0, 0, CLK_IS_CRITICAL); |
| 1210 |
static CCU_GATE(CLK_GPU_CORE, gpu_core_clk, "gpu-core-clk", video_pll_clk_pd, |
| 1211 |
0x0, 3, 0); |
| 1212 |
static CCU_GATE(CLK_GPU_CFG_ACLK, gpu_cfg_aclk, "gpu-cfg-aclk", |
| 1213 |
video_pll_clk_pd, 0x0, 4, CLK_IS_CRITICAL); |
| 1214 |
static CCU_GATE(CLK_DPU_PIXELCLK0, dpu0_pixelclk, "dpu0-pixelclk", |
| 1215 |
dpu0_clk_pd, 0x0, 5, CLK_SET_RATE_PARENT); |
| 1216 |
static CCU_GATE(CLK_DPU_PIXELCLK1, dpu1_pixelclk, "dpu1-pixelclk", |
| 1217 |
dpu1_clk_pd, 0x0, 6, CLK_SET_RATE_PARENT); |
| 1218 |
static CCU_GATE(CLK_DPU_HCLK, dpu_hclk, "dpu-hclk", video_pll_clk_pd, 0x0, |
| 1219 |
7, 0); |
| 1220 |
static CCU_GATE(CLK_DPU_ACLK, dpu_aclk, "dpu-aclk", video_pll_clk_pd, 0x0, |
| 1221 |
8, 0); |
| 1222 |
static CCU_GATE(CLK_DPU_CCLK, dpu_cclk, "dpu-cclk", video_pll_clk_pd, 0x0, |
| 1223 |
9, 0); |
| 1224 |
static CCU_GATE(CLK_HDMI_SFR, hdmi_sfr_clk, "hdmi-sfr-clk", video_pll_clk_pd, |
| 1225 |
0x0, 10, 0); |
| 1226 |
static CCU_GATE(CLK_HDMI_PCLK, hdmi_pclk, "hdmi-pclk", video_pll_clk_pd, 0x0, |
| 1227 |
11, 0); |
| 1228 |
static CCU_GATE(CLK_HDMI_CEC, hdmi_cec_clk, "hdmi-cec-clk", video_pll_clk_pd, |
| 1229 |
0x0, 12, 0); |
| 1230 |
static CCU_GATE(CLK_MIPI_DSI0_PCLK, mipi_dsi0_pclk, "mipi-dsi0-pclk", |
| 1231 |
video_pll_clk_pd, 0x0, 13, 0); |
| 1232 |
static CCU_GATE(CLK_MIPI_DSI1_PCLK, mipi_dsi1_pclk, "mipi-dsi1-pclk", |
| 1233 |
video_pll_clk_pd, 0x0, 14, 0); |
| 1234 |
static CCU_GATE(CLK_MIPI_DSI0_CFG, mipi_dsi0_cfg_clk, "mipi-dsi0-cfg-clk", |
| 1235 |
video_pll_clk_pd, 0x0, 15, 0); |
| 1236 |
static CCU_GATE(CLK_MIPI_DSI1_CFG, mipi_dsi1_cfg_clk, "mipi-dsi1-cfg-clk", |
| 1237 |
video_pll_clk_pd, 0x0, 16, 0); |
| 1238 |
static CCU_GATE(CLK_MIPI_DSI0_REFCLK, mipi_dsi0_refclk, "mipi-dsi0-refclk", |
| 1239 |
video_pll_clk_pd, 0x0, 17, 0); |
| 1240 |
static CCU_GATE(CLK_MIPI_DSI1_REFCLK, mipi_dsi1_refclk, "mipi-dsi1-refclk", |
| 1241 |
video_pll_clk_pd, 0x0, 18, 0); |
| 1242 |
static CCU_GATE(CLK_HDMI_I2S, hdmi_i2s_clk, "hdmi-i2s-clk", video_pll_clk_pd, |
| 1243 |
0x0, 19, 0); |
| 1244 |
static CCU_GATE(CLK_X2H_DPU1_ACLK, x2h_dpu1_aclk, "x2h-dpu1-aclk", |
| 1245 |
video_pll_clk_pd, 0x0, 20, CLK_IS_CRITICAL); |
| 1246 |
static CCU_GATE(CLK_X2H_DPU_ACLK, x2h_dpu_aclk, "x2h-dpu-aclk", |
| 1247 |
video_pll_clk_pd, 0x0, 21, CLK_IS_CRITICAL); |
| 1248 |
static CCU_GATE(CLK_AXI4_VO_PCLK, axi4_vo_pclk, "axi4-vo-pclk", |
| 1249 |
video_pll_clk_pd, 0x0, 22, 0); |
| 1250 |
static CCU_GATE(CLK_IOPMP_VOSYS_DPU_PCLK, iopmp_vosys_dpu_pclk, |
| 1251 |
"iopmp-vosys-dpu-pclk", video_pll_clk_pd, 0x0, 23, 0); |
| 1252 |
static CCU_GATE(CLK_IOPMP_VOSYS_DPU1_PCLK, iopmp_vosys_dpu1_pclk, |
| 1253 |
"iopmp-vosys-dpu1-pclk", video_pll_clk_pd, 0x0, 24, 0); |
| 1254 |
static CCU_GATE(CLK_IOPMP_VOSYS_GPU_PCLK, iopmp_vosys_gpu_pclk, |
| 1255 |
"iopmp-vosys-gpu-pclk", video_pll_clk_pd, 0x0, 25, 0); |
| 1256 |
static CCU_GATE(CLK_IOPMP_DPU1_ACLK, iopmp_dpu1_aclk, "iopmp-dpu1-aclk", |
| 1257 |
video_pll_clk_pd, 0x0, 27, CLK_IS_CRITICAL); |
| 1258 |
static CCU_GATE(CLK_IOPMP_DPU_ACLK, iopmp_dpu_aclk, "iopmp-dpu-aclk", |
| 1259 |
video_pll_clk_pd, 0x0, 28, CLK_IS_CRITICAL); |
| 1260 |
static CCU_GATE(CLK_IOPMP_GPU_ACLK, iopmp_gpu_aclk, "iopmp-gpu-aclk", |
| 1261 |
video_pll_clk_pd, 0x0, 29, CLK_IS_CRITICAL); |
| 1262 |
static CCU_GATE(CLK_MIPIDSI0_PIXCLK, mipi_dsi0_pixclk, "mipi-dsi0-pixclk", |
| 1263 |
video_pll_clk_pd, 0x0, 30, 0); |
| 1264 |
static CCU_GATE(CLK_MIPIDSI1_PIXCLK, mipi_dsi1_pixclk, "mipi-dsi1-pixclk", |
| 1265 |
video_pll_clk_pd, 0x0, 31, 0); |
| 1266 |
static CCU_GATE(CLK_HDMI_PIXCLK, hdmi_pixclk, "hdmi-pixclk", video_pll_clk_pd, |
| 1267 |
0x4, 0, 0); |
| 1268 |
|
| 1269 |
static CLK_FIXED_FACTOR_HW(gmac_pll_clk_100m, "gmac-pll-clk-100m", |
| 1270 |
&gmac_pll_clk.common.hw, 10, 1, 0); |
| 1271 |
|
| 1272 |
static const struct clk_parent_data uart_sclk_parents[] = { |
| 1273 |
{ .hw = &gmac_pll_clk_100m.hw }, |
| 1274 |
{ .index = 0 }, |
| 1275 |
}; |
| 1276 |
|
| 1277 |
static struct ccu_mux uart_sclk = { |
| 1278 |
.clkid = CLK_UART_SCLK, |
| 1279 |
.reg = 0x210, |
| 1280 |
.mux = TH_CCU_MUX("uart-sclk", uart_sclk_parents, 0, 1), |
| 1281 |
}; |
| 1282 |
|
| 1283 |
static struct ccu_common *th1520_pll_clks[] = { |
| 1284 |
&cpu_pll0_clk.common, |
| 1285 |
&cpu_pll1_clk.common, |
| 1286 |
&gmac_pll_clk.common, |
| 1287 |
&video_pll_clk.common, |
| 1288 |
&dpu0_pll_clk.common, |
| 1289 |
&dpu1_pll_clk.common, |
| 1290 |
&tee_pll_clk.common, |
| 1291 |
}; |
| 1292 |
|
| 1293 |
static struct ccu_common *th1520_div_clks[] = { |
| 1294 |
&c910_bus_clk.common, |
| 1295 |
&ahb2_cpusys_hclk.common, |
| 1296 |
&apb3_cpusys_pclk.common, |
| 1297 |
&axi4_cpusys2_aclk.common, |
| 1298 |
&perisys_ahb_hclk.common, |
| 1299 |
&perisys_apb_pclk.common, |
| 1300 |
&axi_aclk.common, |
| 1301 |
&peri2sys_apb_pclk.common, |
| 1302 |
&out1_clk.common, |
| 1303 |
&out2_clk.common, |
| 1304 |
&out3_clk.common, |
| 1305 |
&out4_clk.common, |
| 1306 |
&apb_pclk.common, |
| 1307 |
&npu_clk.common, |
| 1308 |
&vi_clk.common, |
| 1309 |
&vi_ahb_clk.common, |
| 1310 |
&vo_axi_clk.common, |
| 1311 |
&vp_apb_clk.common, |
| 1312 |
&vp_axi_clk.common, |
| 1313 |
&venc_clk.common, |
| 1314 |
&dpu0_clk.common, |
| 1315 |
&dpu1_clk.common, |
| 1316 |
}; |
| 1317 |
|
| 1318 |
static struct ccu_mux *th1520_mux_clks[] = { |
| 1319 |
&c910_i0_clk, |
| 1320 |
&c910_clk, |
| 1321 |
&uart_sclk, |
| 1322 |
}; |
| 1323 |
|
| 1324 |
static struct ccu_gate *th1520_gate_clks[] = { |
| 1325 |
&emmc_sdio_clk, |
| 1326 |
&aon2cpu_a2x_clk, |
| 1327 |
&x2x_cpusys_clk, |
| 1328 |
&brom_clk, |
| 1329 |
&bmu_clk, |
| 1330 |
&cpu2aon_x2h_clk, |
| 1331 |
&cpu2peri_x2h_clk, |
| 1332 |
&cpu2vp_clk, |
| 1333 |
&perisys_apb1_hclk, |
| 1334 |
&perisys_apb2_hclk, |
| 1335 |
&perisys_apb3_hclk, |
| 1336 |
&perisys_apb4_hclk, |
| 1337 |
&npu_axi_clk, |
| 1338 |
&gmac1_clk, |
| 1339 |
&padctrl1_clk, |
| 1340 |
&dsmart_clk, |
| 1341 |
&padctrl0_clk, |
| 1342 |
&gmac_axi_clk, |
| 1343 |
&gpio3_clk, |
| 1344 |
&gmac0_clk, |
| 1345 |
&pwm_clk, |
| 1346 |
&qspi0_clk, |
| 1347 |
&qspi1_clk, |
| 1348 |
&spi_clk, |
| 1349 |
&uart0_pclk, |
| 1350 |
&uart1_pclk, |
| 1351 |
&uart2_pclk, |
| 1352 |
&uart3_pclk, |
| 1353 |
&uart4_pclk, |
| 1354 |
&uart5_pclk, |
| 1355 |
&gpio0_clk, |
| 1356 |
&gpio1_clk, |
| 1357 |
&gpio2_clk, |
| 1358 |
&i2c0_clk, |
| 1359 |
&i2c1_clk, |
| 1360 |
&i2c2_clk, |
| 1361 |
&i2c3_clk, |
| 1362 |
&i2c4_clk, |
| 1363 |
&i2c5_clk, |
| 1364 |
&spinlock_clk, |
| 1365 |
&dma_clk, |
| 1366 |
&mbox0_clk, |
| 1367 |
&mbox1_clk, |
| 1368 |
&mbox2_clk, |
| 1369 |
&mbox3_clk, |
| 1370 |
&wdt0_clk, |
| 1371 |
&wdt1_clk, |
| 1372 |
&timer0_clk, |
| 1373 |
&timer1_clk, |
| 1374 |
&sram0_clk, |
| 1375 |
&sram1_clk, |
| 1376 |
&sram2_clk, |
| 1377 |
&sram3_clk, |
| 1378 |
}; |
| 1379 |
|
| 1380 |
static struct ccu_gate *th1520_vo_gate_clks[] = { |
| 1381 |
&axi4_vo_aclk, |
| 1382 |
&gpu_core_clk, |
| 1383 |
&gpu_cfg_aclk, |
| 1384 |
&dpu0_pixelclk, |
| 1385 |
&dpu1_pixelclk, |
| 1386 |
&dpu_hclk, |
| 1387 |
&dpu_aclk, |
| 1388 |
&dpu_cclk, |
| 1389 |
&hdmi_sfr_clk, |
| 1390 |
&hdmi_pclk, |
| 1391 |
&hdmi_cec_clk, |
| 1392 |
&mipi_dsi0_pclk, |
| 1393 |
&mipi_dsi1_pclk, |
| 1394 |
&mipi_dsi0_cfg_clk, |
| 1395 |
&mipi_dsi1_cfg_clk, |
| 1396 |
&mipi_dsi0_refclk, |
| 1397 |
&mipi_dsi1_refclk, |
| 1398 |
&hdmi_i2s_clk, |
| 1399 |
&x2h_dpu1_aclk, |
| 1400 |
&x2h_dpu_aclk, |
| 1401 |
&axi4_vo_pclk, |
| 1402 |
&iopmp_vosys_dpu_pclk, |
| 1403 |
&iopmp_vosys_dpu1_pclk, |
| 1404 |
&iopmp_vosys_gpu_pclk, |
| 1405 |
&iopmp_dpu1_aclk, |
| 1406 |
&iopmp_dpu_aclk, |
| 1407 |
&iopmp_gpu_aclk, |
| 1408 |
&mipi_dsi0_pixclk, |
| 1409 |
&mipi_dsi1_pixclk, |
| 1410 |
&hdmi_pixclk |
| 1411 |
}; |
| 1412 |
|
| 1413 |
static const struct regmap_config th1520_clk_regmap_config = { |
| 1414 |
.reg_bits = 32, |
| 1415 |
.val_bits = 32, |
| 1416 |
.reg_stride = 4, |
| 1417 |
}; |
| 1418 |
|
| 1419 |
struct th1520_plat_data { |
| 1420 |
struct ccu_common **th1520_pll_clks; |
| 1421 |
struct ccu_common **th1520_div_clks; |
| 1422 |
struct ccu_mux **th1520_mux_clks; |
| 1423 |
struct ccu_gate **th1520_gate_clks; |
| 1424 |
|
| 1425 |
int nr_clks; |
| 1426 |
int nr_pll_clks; |
| 1427 |
int nr_div_clks; |
| 1428 |
int nr_mux_clks; |
| 1429 |
int nr_gate_clks; |
| 1430 |
}; |
| 1431 |
|
| 1432 |
static const struct th1520_plat_data th1520_ap_platdata = { |
| 1433 |
.th1520_pll_clks = th1520_pll_clks, |
| 1434 |
.th1520_div_clks = th1520_div_clks, |
| 1435 |
.th1520_mux_clks = th1520_mux_clks, |
| 1436 |
.th1520_gate_clks = th1520_gate_clks, |
| 1437 |
|
| 1438 |
.nr_clks = CLK_C910_BUS + 1, |
| 1439 |
|
| 1440 |
.nr_pll_clks = ARRAY_SIZE(th1520_pll_clks), |
| 1441 |
.nr_div_clks = ARRAY_SIZE(th1520_div_clks), |
| 1442 |
.nr_mux_clks = ARRAY_SIZE(th1520_mux_clks), |
| 1443 |
.nr_gate_clks = ARRAY_SIZE(th1520_gate_clks), |
| 1444 |
}; |
| 1445 |
|
| 1446 |
static const struct th1520_plat_data th1520_vo_platdata = { |
| 1447 |
.th1520_gate_clks = th1520_vo_gate_clks, |
| 1448 |
|
| 1449 |
.nr_clks = CLK_HDMI_PIXCLK + 1, |
| 1450 |
|
| 1451 |
.nr_gate_clks = ARRAY_SIZE(th1520_vo_gate_clks), |
| 1452 |
}; |
| 1453 |
|
| 1454 |
/* |
| 1455 |
* Maintain clock rate of c910_bus_clk below TH1520_C910_BUS_MAX_RATE (750MHz) |
| 1456 |
* when its parent, c910_clk, changes the rate. |
| 1457 |
* |
| 1458 |
* Additionally, TRM is unclear about c910_bus_clk behavior when the divisor is |
| 1459 |
* set below 2, thus we should ensure the new divisor stays in (2, MAXDIVISOR). |
| 1460 |
*/ |
| 1461 |
static unsigned long c910_bus_clk_divisor(struct ccu_div *cd, |
| 1462 |
unsigned long parent_rate) |
| 1463 |
{ |
| 1464 |
return clamp(DIV_ROUND_UP(parent_rate, TH1520_C910_BUS_MAX_RATE), |
| 1465 |
2U, 1U << cd->div.width); |
| 1466 |
} |
| 1467 |
|
| 1468 |
static int c910_clk_notifier_cb(struct notifier_block *nb, |
| 1469 |
unsigned long action, void *data) |
| 1470 |
{ |
| 1471 |
struct clk_notifier_data *cnd = data; |
| 1472 |
unsigned long new_divisor, ref_rate; |
| 1473 |
|
| 1474 |
if (action != PRE_RATE_CHANGE && action != POST_RATE_CHANGE) |
| 1475 |
return NOTIFY_DONE; |
| 1476 |
|
| 1477 |
new_divisor = c910_bus_clk_divisor(&c910_bus_clk, cnd->new_rate); |
| 1478 |
|
| 1479 |
if (cnd->new_rate > cnd->old_rate) { |
| 1480 |
/* |
| 1481 |
* Scaling up. Adjust c910_bus_clk divisor |
| 1482 |
* - before c910_clk rate change to ensure the constraints |
| 1483 |
* aren't broken after scaling to higher rates, |
| 1484 |
* - after c910_clk rate change to keep c910_bus_clk as high as |
| 1485 |
* possible |
| 1486 |
*/ |
| 1487 |
ref_rate = action == PRE_RATE_CHANGE ? |
| 1488 |
cnd->old_rate : cnd->new_rate; |
| 1489 |
clk_set_rate(c910_bus_clk.common.hw.clk, |
| 1490 |
ref_rate / new_divisor); |
| 1491 |
} else if (cnd->new_rate < cnd->old_rate && |
| 1492 |
action == POST_RATE_CHANGE) { |
| 1493 |
/* |
| 1494 |
* Scaling down. Adjust c910_bus_clk divisor only after |
| 1495 |
* c910_clk rate change to keep c910_bus_clk as high as |
| 1496 |
* possible, Scaling down never breaks the constraints. |
| 1497 |
*/ |
| 1498 |
clk_set_rate(c910_bus_clk.common.hw.clk, |
| 1499 |
cnd->new_rate / new_divisor); |
| 1500 |
} else { |
| 1501 |
return NOTIFY_DONE; |
| 1502 |
} |
| 1503 |
|
| 1504 |
return NOTIFY_OK; |
| 1505 |
} |
| 1506 |
|
| 1507 |
static struct notifier_block c910_clk_notifier = { |
| 1508 |
.notifier_call = c910_clk_notifier_cb, |
| 1509 |
}; |
| 1510 |
|
| 1511 |
static int th1520_clk_probe(struct platform_device *pdev) |
| 1512 |
{ |
| 1513 |
const struct th1520_plat_data *plat_data; |
| 1514 |
struct device *dev = &pdev->dev; |
| 1515 |
struct clk_hw_onecell_data *priv; |
| 1516 |
struct clk *notifier_clk; |
| 1517 |
|
| 1518 |
struct regmap *map; |
| 1519 |
void __iomem *base; |
| 1520 |
int ret, i; |
| 1521 |
|
| 1522 |
plat_data = device_get_match_data(&pdev->dev); |
| 1523 |
if (!plat_data) |
| 1524 |
return dev_err_probe(&pdev->dev, -ENODEV, |
| 1525 |
"No device match data found\n"); |
| 1526 |
|
| 1527 |
priv = devm_kzalloc(dev, struct_size(priv, hws, plat_data->nr_clks), GFP_KERNEL); |
| 1528 |
if (!priv) |
| 1529 |
return -ENOMEM; |
| 1530 |
|
| 1531 |
priv->num = plat_data->nr_clks; |
| 1532 |
|
| 1533 |
base = devm_platform_ioremap_resource(pdev, 0); |
| 1534 |
if (IS_ERR(base)) |
| 1535 |
return PTR_ERR(base); |
| 1536 |
|
| 1537 |
map = devm_regmap_init_mmio(dev, base, &th1520_clk_regmap_config); |
| 1538 |
if (IS_ERR(map)) |
| 1539 |
return PTR_ERR(map); |
| 1540 |
|
| 1541 |
for (i = 0; i < plat_data->nr_pll_clks; i++) { |
| 1542 |
struct ccu_pll *cp = hw_to_ccu_pll(&plat_data->th1520_pll_clks[i]->hw); |
| 1543 |
|
| 1544 |
plat_data->th1520_pll_clks[i]->map = map; |
| 1545 |
|
| 1546 |
ret = devm_clk_hw_register(dev, &plat_data->th1520_pll_clks[i]->hw); |
| 1547 |
if (ret) |
| 1548 |
return ret; |
| 1549 |
|
| 1550 |
priv->hws[cp->common.clkid] = &cp->common.hw; |
| 1551 |
} |
| 1552 |
|
| 1553 |
for (i = 0; i < plat_data->nr_div_clks; i++) { |
| 1554 |
struct ccu_div *cd = hw_to_ccu_div(&plat_data->th1520_div_clks[i]->hw); |
| 1555 |
|
| 1556 |
plat_data->th1520_div_clks[i]->map = map; |
| 1557 |
|
| 1558 |
ret = devm_clk_hw_register(dev, &plat_data->th1520_div_clks[i]->hw); |
| 1559 |
if (ret) |
| 1560 |
return ret; |
| 1561 |
|
| 1562 |
priv->hws[cd->common.clkid] = &cd->common.hw; |
| 1563 |
} |
| 1564 |
|
| 1565 |
for (i = 0; i < plat_data->nr_mux_clks; i++) { |
| 1566 |
struct ccu_mux *cm = plat_data->th1520_mux_clks[i]; |
| 1567 |
|
| 1568 |
cm->mux.reg = base + cm->reg; |
| 1569 |
|
| 1570 |
ret = devm_clk_hw_register(dev, &cm->mux.hw); |
| 1571 |
if (ret) |
| 1572 |
return ret; |
| 1573 |
|
| 1574 |
priv->hws[cm->clkid] = &cm->mux.hw; |
| 1575 |
} |
| 1576 |
|
| 1577 |
for (i = 0; i < plat_data->nr_gate_clks; i++) { |
| 1578 |
struct ccu_gate *cg = plat_data->th1520_gate_clks[i]; |
| 1579 |
|
| 1580 |
cg->gate.reg = base + cg->reg; |
| 1581 |
|
| 1582 |
ret = devm_clk_hw_register(dev, &cg->gate.hw); |
| 1583 |
if (ret) |
| 1584 |
return ret; |
| 1585 |
|
| 1586 |
priv->hws[cg->clkid] = &cg->gate.hw; |
| 1587 |
} |
| 1588 |
|
| 1589 |
if (plat_data == &th1520_ap_platdata) { |
| 1590 |
ret = devm_clk_hw_register(dev, &osc12m_clk.hw); |
| 1591 |
if (ret) |
| 1592 |
return ret; |
| 1593 |
priv->hws[CLK_OSC12M] = &osc12m_clk.hw; |
| 1594 |
|
| 1595 |
ret = devm_clk_hw_register(dev, &gmac_pll_clk_100m.hw); |
| 1596 |
if (ret) |
| 1597 |
return ret; |
| 1598 |
priv->hws[CLK_PLL_GMAC_100M] = &gmac_pll_clk_100m.hw; |
| 1599 |
|
| 1600 |
ret = devm_clk_hw_register(dev, &emmc_sdio_ref_clk.hw); |
| 1601 |
if (ret) |
| 1602 |
return ret; |
| 1603 |
|
| 1604 |
notifier_clk = devm_clk_hw_get_clk(dev, &c910_clk.mux.hw, |
| 1605 |
"dvfs"); |
| 1606 |
ret = devm_clk_notifier_register(dev, notifier_clk, |
| 1607 |
&c910_clk_notifier); |
| 1608 |
if (ret) |
| 1609 |
return ret; |
| 1610 |
} |
| 1611 |
|
| 1612 |
ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, priv); |
| 1613 |
if (ret) |
| 1614 |
return ret; |
| 1615 |
|
| 1616 |
return 0; |
| 1617 |
} |
| 1618 |
|
| 1619 |
static const struct of_device_id th1520_clk_match[] = { |
| 1620 |
{ |
| 1621 |
.compatible = "thead,th1520-clk-ap", |
| 1622 |
.data = &th1520_ap_platdata, |
| 1623 |
}, |
| 1624 |
{ |
| 1625 |
.compatible = "thead,th1520-clk-vo", |
| 1626 |
.data = &th1520_vo_platdata, |
| 1627 |
}, |
| 1628 |
{ /* sentinel */ }, |
| 1629 |
}; |
| 1630 |
MODULE_DEVICE_TABLE(of, th1520_clk_match); |
| 1631 |
|
| 1632 |
static struct platform_driver th1520_clk_driver = { |
| 1633 |
.probe = th1520_clk_probe, |
| 1634 |
.driver = { |
| 1635 |
.name = "th1520-clk", |
| 1636 |
.of_match_table = th1520_clk_match, |
| 1637 |
}, |
| 1638 |
}; |
| 1639 |
module_platform_driver(th1520_clk_driver); |
| 1640 |
|
| 1641 |
MODULE_DESCRIPTION("T-HEAD TH1520 AP Clock driver"); |
| 1642 |
MODULE_AUTHOR("Yangtao Li <[email protected]>"); |
| 1643 |
MODULE_AUTHOR("Jisheng Zhang <[email protected]>"); |
| 1644 |
MODULE_LICENSE("GPL"); |