1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * PLL clock driver for the Mobileye EyeQ5, EyeQ6L and EyeQ6H platforms. 4 * 5 * This controller handles read-only PLLs, all derived from the same main 6 * crystal clock. It also exposes divider clocks, those are children to PLLs. 7 * Parent clock is expected to be constant. This driver's registers live in 8 * a shared region called OLB. Some PLLs are initialised early by of_clk_init(); 9 * if so, two clk providers are registered. 10 * 11 * We use eqc_ as prefix, as-in "EyeQ Clock", but way shorter. 12 * 13 * Copyright (C) 2024 Mobileye Vision Technologies Ltd. 14 */ 15 16 /* 17 * Set pr_fmt() for printing from eqc_early_init(). 18 * It is called at of_clk_init() stage (read: really early). 19 */ 20 #define pr_fmt(fmt) "clk-eyeq: " fmt 21 22 #include <linux/array_size.h> 23 #include <linux/auxiliary_bus.h> 24 #include <linux/bitfield.h> 25 #include <linux/bits.h> 26 #include <linux/clk-provider.h> 27 #include <linux/device.h> 28 #include <linux/err.h> 29 #include <linux/errno.h> 30 #include <linux/init.h> 31 #include <linux/io-64-nonatomic-hi-lo.h> 32 #include <linux/io.h> 33 #include <linux/mod_devicetable.h> 34 #include <linux/module.h> 35 #include <linux/of.h> 36 #include <linux/of_address.h> 37 #include <linux/overflow.h> 38 #include <linux/platform_device.h> 39 #include <linux/printk.h> 40 #include <linux/slab.h> 41 #include <linux/spinlock.h> 42 #include <linux/types.h> 43 44 #include <dt-bindings/clock/mobileye,eyeq5-clk.h> 45 46 /* In frac mode, it enables fractional noise canceling DAC. Else, no function. */ 47 #define PCSR0_DAC_EN BIT(0) 48 /* Fractional or integer mode */ 49 #define PCSR0_DSM_EN BIT(1) 50 #define PCSR0_PLL_EN BIT(2) 51 /* All clocks output held at 0 */ 52 #define PCSR0_FOUTPOSTDIV_EN BIT(3) 53 #define PCSR0_POST_DIV1 GENMASK(6, 4) 54 #define PCSR0_POST_DIV2 GENMASK(9, 7) 55 #define PCSR0_REF_DIV GENMASK(15, 10) 56 #define PCSR0_INTIN GENMASK(27, 16) 57 #define PCSR0_BYPASS BIT(28) 58 /* Bits 30..29 are reserved */ 59 #define PCSR0_PLL_LOCKED BIT(31) 60 61 #define PCSR1_RESET BIT(0) 62 #define PCSR1_SSGC_DIV GENMASK(4, 1) 63 /* Spread amplitude (% = 0.1 * SPREAD[4:0]) */ 64 #define PCSR1_SPREAD GENMASK(9, 5) 65 #define PCSR1_DIS_SSCG BIT(10) 66 /* Down-spread or center-spread */ 67 #define PCSR1_DOWN_SPREAD BIT(11) 68 #define PCSR1_FRAC_IN GENMASK(31, 12) 69 70 struct eqc_pll { 71 unsigned int index; 72 const char *name; 73 unsigned int reg64; 74 }; 75 76 /* 77 * Divider clock. Divider is 2*(v+1), with v the register value. 78 * Min divider is 2, max is 2*(2^width). 79 */ 80 struct eqc_div { 81 unsigned int index; 82 const char *name; 83 unsigned int parent; 84 unsigned int reg; 85 u8 shift; 86 u8 width; 87 }; 88 89 struct eqc_match_data { 90 unsigned int pll_count; 91 const struct eqc_pll *plls; 92 93 unsigned int div_count; 94 const struct eqc_div *divs; 95 96 const char *reset_auxdev_name; 97 const char *pinctrl_auxdev_name; 98 99 unsigned int early_clk_count; 100 }; 101 102 struct eqc_early_match_data { 103 unsigned int early_pll_count; 104 const struct eqc_pll *early_plls; 105 106 /* 107 * We want our of_xlate callback to EPROBE_DEFER instead of dev_err() 108 * and EINVAL. For that, we must know the total clock count. 109 */ 110 unsigned int late_clk_count; 111 }; 112 113 /* 114 * Both factors (mult and div) must fit in 32 bits. When an operation overflows, 115 * this function throws away low bits so that factors still fit in 32 bits. 116 * 117 * Precision loss depends on amplitude of mult and div. Worst theorical 118 * loss is: (UINT_MAX+1) / UINT_MAX - 1 = 2.3e-10. 119 * This is 1Hz every 4.3GHz. 120 */ 121 static void eqc_pll_downshift_factors(unsigned long *mult, unsigned long *div) 122 { 123 unsigned long biggest; 124 unsigned int shift; 125 126 /* This function can be removed if mult/div switch to unsigned long. */ 127 static_assert(sizeof_field(struct clk_fixed_factor, mult) == sizeof(unsigned int)); 128 static_assert(sizeof_field(struct clk_fixed_factor, div) == sizeof(unsigned int)); 129 130 /* No overflow, nothing to be done. */ 131 if (*mult <= UINT_MAX && *div <= UINT_MAX) 132 return; 133 134 /* 135 * Compute the shift required to bring the biggest factor into unsigned 136 * int range. That is, shift its highest set bit to the unsigned int 137 * most significant bit. 138 */ 139 biggest = max(*mult, *div); 140 shift = __fls(biggest) - (BITS_PER_BYTE * sizeof(unsigned int)) + 1; 141 142 *mult >>= shift; 143 *div >>= shift; 144 } 145 146 static int eqc_pll_parse_registers(u32 r0, u32 r1, unsigned long *mult, 147 unsigned long *div, unsigned long *acc) 148 { 149 u32 spread; 150 151 if (r0 & PCSR0_BYPASS) { 152 *mult = 1; 153 *div = 1; 154 *acc = 0; 155 return 0; 156 } 157 158 if (!(r0 & PCSR0_PLL_LOCKED)) 159 return -EINVAL; 160 161 *mult = FIELD_GET(PCSR0_INTIN, r0); 162 *div = FIELD_GET(PCSR0_REF_DIV, r0); 163 if (r0 & PCSR0_FOUTPOSTDIV_EN) 164 *div *= FIELD_GET(PCSR0_POST_DIV1, r0) * FIELD_GET(PCSR0_POST_DIV2, r0); 165 166 /* Fractional mode, in 2^20 (0x100000) parts. */ 167 if (r0 & PCSR0_DSM_EN) { 168 *div *= (1ULL << 20); 169 *mult = *mult * (1ULL << 20) + FIELD_GET(PCSR1_FRAC_IN, r1); 170 } 171 172 if (!*mult || !*div) 173 return -EINVAL; 174 175 if (r1 & (PCSR1_RESET | PCSR1_DIS_SSCG)) { 176 *acc = 0; 177 return 0; 178 } 179 180 /* 181 * Spread spectrum. 182 * 183 * Spread is 1/1000 parts of frequency, accuracy is half of 184 * that. To get accuracy, convert to ppb (parts per billion). 185 * 186 * acc = spread * 1e6 / 2 187 * with acc in parts per billion and, 188 * spread in parts per thousand. 189 */ 190 spread = FIELD_GET(PCSR1_SPREAD, r1); 191 *acc = spread * 500000; 192 193 if (r1 & PCSR1_DOWN_SPREAD) { 194 /* 195 * Downspreading: the central frequency is half a 196 * spread lower. 197 */ 198 *mult *= 2000 - spread; 199 *div *= 2000; 200 201 /* 202 * Previous operation might overflow 32 bits. If it 203 * does, throw away the least amount of low bits. 204 */ 205 eqc_pll_downshift_factors(mult, div); 206 } 207 208 return 0; 209 } 210 211 static void eqc_probe_init_plls(struct device *dev, const struct eqc_match_data *data, 212 void __iomem *base, struct clk_hw_onecell_data *cells) 213 { 214 unsigned long mult, div, acc; 215 const struct eqc_pll *pll; 216 struct clk_hw *hw; 217 unsigned int i; 218 u32 r0, r1; 219 u64 val; 220 int ret; 221 222 for (i = 0; i < data->pll_count; i++) { 223 pll = &data->plls[i]; 224 225 val = readq(base + pll->reg64); 226 r0 = val; 227 r1 = val >> 32; 228 229 ret = eqc_pll_parse_registers(r0, r1, &mult, &div, &acc); 230 if (ret) { 231 dev_warn(dev, "failed parsing state of %s\n", pll->name); 232 cells->hws[pll->index] = ERR_PTR(ret); 233 continue; 234 } 235 236 hw = clk_hw_register_fixed_factor_with_accuracy_fwname(dev, 237 dev->of_node, pll->name, "ref", 0, mult, div, acc); 238 cells->hws[pll->index] = hw; 239 if (IS_ERR(hw)) 240 dev_warn(dev, "failed registering %s: %pe\n", pll->name, hw); 241 } 242 } 243 244 static void eqc_probe_init_divs(struct device *dev, const struct eqc_match_data *data, 245 void __iomem *base, struct clk_hw_onecell_data *cells) 246 { 247 struct clk_parent_data parent_data = { }; 248 const struct eqc_div *div; 249 struct clk_hw *parent; 250 void __iomem *reg; 251 struct clk_hw *hw; 252 unsigned int i; 253 254 for (i = 0; i < data->div_count; i++) { 255 div = &data->divs[i]; 256 reg = base + div->reg; 257 parent = cells->hws[div->parent]; 258 259 if (IS_ERR(parent)) { 260 /* Parent is in early clk provider. */ 261 parent_data.index = div->parent; 262 parent_data.hw = NULL; 263 } else { 264 /* Avoid clock lookup when we already have the hw reference. */ 265 parent_data.index = 0; 266 parent_data.hw = parent; 267 } 268 269 hw = clk_hw_register_divider_table_parent_data(dev, div->name, 270 &parent_data, 0, reg, div->shift, div->width, 271 CLK_DIVIDER_EVEN_INTEGERS, NULL, NULL); 272 cells->hws[div->index] = hw; 273 if (IS_ERR(hw)) 274 dev_warn(dev, "failed registering %s: %pe\n", 275 div->name, hw); 276 } 277 } 278 279 static void eqc_auxdev_release(struct device *dev) 280 { 281 struct auxiliary_device *adev = to_auxiliary_dev(dev); 282 283 kfree(adev); 284 } 285 286 static int eqc_auxdev_create(struct device *dev, void __iomem *base, 287 const char *name, u32 id) 288 { 289 struct auxiliary_device *adev; 290 int ret; 291 292 adev = kzalloc(sizeof(*adev), GFP_KERNEL); 293 if (!adev) 294 return -ENOMEM; 295 296 adev->name = name; 297 adev->dev.parent = dev; 298 adev->dev.platform_data = (void __force *)base; 299 adev->dev.release = eqc_auxdev_release; 300 adev->id = id; 301 302 ret = auxiliary_device_init(adev); 303 if (ret) 304 return ret; 305 306 ret = auxiliary_device_add(adev); 307 if (ret) 308 auxiliary_device_uninit(adev); 309 310 return ret; 311 } 312 313 static int eqc_probe(struct platform_device *pdev) 314 { 315 struct device *dev = &pdev->dev; 316 struct device_node *np = dev->of_node; 317 const struct eqc_match_data *data; 318 struct clk_hw_onecell_data *cells; 319 unsigned int i, clk_count; 320 struct resource *res; 321 void __iomem *base; 322 int ret; 323 324 data = device_get_match_data(dev); 325 if (!data) 326 return 0; /* No clocks nor auxdevs, we are done. */ 327 328 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 329 if (!res) 330 return -ENODEV; 331 332 base = ioremap(res->start, resource_size(res)); 333 if (!base) 334 return -ENOMEM; 335 336 /* Init optional reset auxiliary device. */ 337 if (data->reset_auxdev_name) { 338 ret = eqc_auxdev_create(dev, base, data->reset_auxdev_name, 0); 339 if (ret) 340 dev_warn(dev, "failed creating auxiliary device %s.%s: %d\n", 341 KBUILD_MODNAME, data->reset_auxdev_name, ret); 342 } 343 344 /* Init optional pinctrl auxiliary device. */ 345 if (data->pinctrl_auxdev_name) { 346 ret = eqc_auxdev_create(dev, base, data->pinctrl_auxdev_name, 0); 347 if (ret) 348 dev_warn(dev, "failed creating auxiliary device %s.%s: %d\n", 349 KBUILD_MODNAME, data->pinctrl_auxdev_name, ret); 350 } 351 352 if (data->pll_count + data->div_count == 0) 353 return 0; /* Zero clocks, we are done. */ 354 355 clk_count = data->pll_count + data->div_count + data->early_clk_count; 356 cells = kzalloc(struct_size(cells, hws, clk_count), GFP_KERNEL); 357 if (!cells) 358 return -ENOMEM; 359 360 cells->num = clk_count; 361 362 /* Early PLLs are marked as errors: the early provider will get queried. */ 363 for (i = 0; i < clk_count; i++) 364 cells->hws[i] = ERR_PTR(-EINVAL); 365 366 eqc_probe_init_plls(dev, data, base, cells); 367 368 eqc_probe_init_divs(dev, data, base, cells); 369 370 /* When providing a single clock, require no cell. */ 371 if (clk_count == 1) 372 return of_clk_add_hw_provider(np, of_clk_hw_simple_get, cells->hws[0]); 373 else 374 return of_clk_add_hw_provider(np, of_clk_hw_onecell_get, cells); 375 } 376 377 /* Required early for GIC timer (pll-cpu) and UARTs (pll-per). */ 378 static const struct eqc_pll eqc_eyeq5_early_plls[] = { 379 { .index = EQ5C_PLL_CPU, .name = "pll-cpu", .reg64 = 0x02C }, 380 { .index = EQ5C_PLL_PER, .name = "pll-per", .reg64 = 0x05C }, 381 }; 382 383 static const struct eqc_pll eqc_eyeq5_plls[] = { 384 { .index = EQ5C_PLL_VMP, .name = "pll-vmp", .reg64 = 0x034 }, 385 { .index = EQ5C_PLL_PMA, .name = "pll-pma", .reg64 = 0x03C }, 386 { .index = EQ5C_PLL_VDI, .name = "pll-vdi", .reg64 = 0x044 }, 387 { .index = EQ5C_PLL_DDR0, .name = "pll-ddr0", .reg64 = 0x04C }, 388 { .index = EQ5C_PLL_PCI, .name = "pll-pci", .reg64 = 0x054 }, 389 { .index = EQ5C_PLL_PMAC, .name = "pll-pmac", .reg64 = 0x064 }, 390 { .index = EQ5C_PLL_MPC, .name = "pll-mpc", .reg64 = 0x06C }, 391 { .index = EQ5C_PLL_DDR1, .name = "pll-ddr1", .reg64 = 0x074 }, 392 }; 393 394 static const struct eqc_div eqc_eyeq5_divs[] = { 395 { 396 .index = EQ5C_DIV_OSPI, 397 .name = "div-ospi", 398 .parent = EQ5C_PLL_PER, 399 .reg = 0x11C, 400 .shift = 0, 401 .width = 4, 402 }, 403 }; 404 405 static const struct eqc_early_match_data eqc_eyeq5_early_match_data __initconst = { 406 .early_pll_count = ARRAY_SIZE(eqc_eyeq5_early_plls), 407 .early_plls = eqc_eyeq5_early_plls, 408 409 .late_clk_count = ARRAY_SIZE(eqc_eyeq5_plls) + ARRAY_SIZE(eqc_eyeq5_divs), 410 }; 411 412 static const struct eqc_match_data eqc_eyeq5_match_data = { 413 .pll_count = ARRAY_SIZE(eqc_eyeq5_plls), 414 .plls = eqc_eyeq5_plls, 415 416 .div_count = ARRAY_SIZE(eqc_eyeq5_divs), 417 .divs = eqc_eyeq5_divs, 418 419 .reset_auxdev_name = "reset", 420 .pinctrl_auxdev_name = "pinctrl", 421 422 .early_clk_count = ARRAY_SIZE(eqc_eyeq5_early_plls), 423 }; 424 425 static const struct eqc_pll eqc_eyeq6l_plls[] = { 426 { .index = EQ6LC_PLL_DDR, .name = "pll-ddr", .reg64 = 0x02C }, 427 { .index = EQ6LC_PLL_CPU, .name = "pll-cpu", .reg64 = 0x034 }, /* also acc */ 428 { .index = EQ6LC_PLL_PER, .name = "pll-per", .reg64 = 0x03C }, 429 { .index = EQ6LC_PLL_VDI, .name = "pll-vdi", .reg64 = 0x044 }, 430 }; 431 432 static const struct eqc_match_data eqc_eyeq6l_match_data = { 433 .pll_count = ARRAY_SIZE(eqc_eyeq6l_plls), 434 .plls = eqc_eyeq6l_plls, 435 436 .reset_auxdev_name = "reset", 437 }; 438 439 static const struct eqc_match_data eqc_eyeq6h_west_match_data = { 440 .reset_auxdev_name = "reset_west", 441 }; 442 443 static const struct eqc_pll eqc_eyeq6h_east_plls[] = { 444 { .index = 0, .name = "pll-east", .reg64 = 0x074 }, 445 }; 446 447 static const struct eqc_match_data eqc_eyeq6h_east_match_data = { 448 .pll_count = ARRAY_SIZE(eqc_eyeq6h_east_plls), 449 .plls = eqc_eyeq6h_east_plls, 450 451 .reset_auxdev_name = "reset_east", 452 }; 453 454 static const struct eqc_pll eqc_eyeq6h_south_plls[] = { 455 { .index = EQ6HC_SOUTH_PLL_VDI, .name = "pll-vdi", .reg64 = 0x000 }, 456 { .index = EQ6HC_SOUTH_PLL_PCIE, .name = "pll-pcie", .reg64 = 0x008 }, 457 { .index = EQ6HC_SOUTH_PLL_PER, .name = "pll-per", .reg64 = 0x010 }, 458 { .index = EQ6HC_SOUTH_PLL_ISP, .name = "pll-isp", .reg64 = 0x018 }, 459 }; 460 461 static const struct eqc_div eqc_eyeq6h_south_divs[] = { 462 { 463 .index = EQ6HC_SOUTH_DIV_EMMC, 464 .name = "div-emmc", 465 .parent = EQ6HC_SOUTH_PLL_PER, 466 .reg = 0x070, 467 .shift = 4, 468 .width = 4, 469 }, 470 { 471 .index = EQ6HC_SOUTH_DIV_OSPI_REF, 472 .name = "div-ospi-ref", 473 .parent = EQ6HC_SOUTH_PLL_PER, 474 .reg = 0x090, 475 .shift = 4, 476 .width = 4, 477 }, 478 { 479 .index = EQ6HC_SOUTH_DIV_OSPI_SYS, 480 .name = "div-ospi-sys", 481 .parent = EQ6HC_SOUTH_PLL_PER, 482 .reg = 0x090, 483 .shift = 8, 484 .width = 1, 485 }, 486 { 487 .index = EQ6HC_SOUTH_DIV_TSU, 488 .name = "div-tsu", 489 .parent = EQ6HC_SOUTH_PLL_PCIE, 490 .reg = 0x098, 491 .shift = 4, 492 .width = 8, 493 }, 494 }; 495 496 static const struct eqc_match_data eqc_eyeq6h_south_match_data = { 497 .pll_count = ARRAY_SIZE(eqc_eyeq6h_south_plls), 498 .plls = eqc_eyeq6h_south_plls, 499 500 .div_count = ARRAY_SIZE(eqc_eyeq6h_south_divs), 501 .divs = eqc_eyeq6h_south_divs, 502 }; 503 504 static const struct eqc_pll eqc_eyeq6h_ddr0_plls[] = { 505 { .index = 0, .name = "pll-ddr0", .reg64 = 0x074 }, 506 }; 507 508 static const struct eqc_match_data eqc_eyeq6h_ddr0_match_data = { 509 .pll_count = ARRAY_SIZE(eqc_eyeq6h_ddr0_plls), 510 .plls = eqc_eyeq6h_ddr0_plls, 511 }; 512 513 static const struct eqc_pll eqc_eyeq6h_ddr1_plls[] = { 514 { .index = 0, .name = "pll-ddr1", .reg64 = 0x074 }, 515 }; 516 517 static const struct eqc_match_data eqc_eyeq6h_ddr1_match_data = { 518 .pll_count = ARRAY_SIZE(eqc_eyeq6h_ddr1_plls), 519 .plls = eqc_eyeq6h_ddr1_plls, 520 }; 521 522 static const struct eqc_pll eqc_eyeq6h_acc_plls[] = { 523 { .index = EQ6HC_ACC_PLL_XNN, .name = "pll-xnn", .reg64 = 0x040 }, 524 { .index = EQ6HC_ACC_PLL_VMP, .name = "pll-vmp", .reg64 = 0x050 }, 525 { .index = EQ6HC_ACC_PLL_PMA, .name = "pll-pma", .reg64 = 0x05C }, 526 { .index = EQ6HC_ACC_PLL_MPC, .name = "pll-mpc", .reg64 = 0x068 }, 527 { .index = EQ6HC_ACC_PLL_NOC, .name = "pll-noc", .reg64 = 0x070 }, 528 }; 529 530 static const struct eqc_match_data eqc_eyeq6h_acc_match_data = { 531 .pll_count = ARRAY_SIZE(eqc_eyeq6h_acc_plls), 532 .plls = eqc_eyeq6h_acc_plls, 533 534 .reset_auxdev_name = "reset_acc", 535 }; 536 537 static const struct of_device_id eqc_match_table[] = { 538 { .compatible = "mobileye,eyeq5-olb", .data = &eqc_eyeq5_match_data }, 539 { .compatible = "mobileye,eyeq6l-olb", .data = &eqc_eyeq6l_match_data }, 540 { .compatible = "mobileye,eyeq6h-west-olb", .data = &eqc_eyeq6h_west_match_data }, 541 { .compatible = "mobileye,eyeq6h-east-olb", .data = &eqc_eyeq6h_east_match_data }, 542 { .compatible = "mobileye,eyeq6h-south-olb", .data = &eqc_eyeq6h_south_match_data }, 543 { .compatible = "mobileye,eyeq6h-ddr0-olb", .data = &eqc_eyeq6h_ddr0_match_data }, 544 { .compatible = "mobileye,eyeq6h-ddr1-olb", .data = &eqc_eyeq6h_ddr1_match_data }, 545 { .compatible = "mobileye,eyeq6h-acc-olb", .data = &eqc_eyeq6h_acc_match_data }, 546 {} 547 }; 548 549 static struct platform_driver eqc_driver = { 550 .probe = eqc_probe, 551 .driver = { 552 .name = "clk-eyeq", 553 .of_match_table = eqc_match_table, 554 .suppress_bind_attrs = true, 555 }, 556 }; 557 builtin_platform_driver(eqc_driver); 558 559 /* Required early for GIC timer. */ 560 static const struct eqc_pll eqc_eyeq6h_central_early_plls[] = { 561 { .index = 0, .name = "pll-cpu", .reg64 = 0x02C }, 562 }; 563 564 static const struct eqc_early_match_data eqc_eyeq6h_central_early_match_data __initconst = { 565 .early_pll_count = ARRAY_SIZE(eqc_eyeq6h_central_early_plls), 566 .early_plls = eqc_eyeq6h_central_early_plls, 567 }; 568 569 /* Required early for UART. */ 570 static const struct eqc_pll eqc_eyeq6h_west_early_plls[] = { 571 { .index = 0, .name = "pll-west", .reg64 = 0x074 }, 572 }; 573 574 static const struct eqc_early_match_data eqc_eyeq6h_west_early_match_data __initconst = { 575 .early_pll_count = ARRAY_SIZE(eqc_eyeq6h_west_early_plls), 576 .early_plls = eqc_eyeq6h_west_early_plls, 577 }; 578 579 static void __init eqc_early_init(struct device_node *np, 580 const struct eqc_early_match_data *early_data) 581 { 582 struct clk_hw_onecell_data *cells; 583 unsigned int i, clk_count; 584 void __iomem *base; 585 int ret; 586 587 clk_count = early_data->early_pll_count + early_data->late_clk_count; 588 cells = kzalloc(struct_size(cells, hws, clk_count), GFP_KERNEL); 589 if (!cells) { 590 ret = -ENOMEM; 591 goto err; 592 } 593 594 cells->num = clk_count; 595 596 /* 597 * Mark all clocks as deferred; some are registered here, the rest at 598 * platform device probe. 599 * 600 * Once the platform device is probed, its provider will take priority 601 * when looking up clocks. 602 */ 603 for (i = 0; i < clk_count; i++) 604 cells->hws[i] = ERR_PTR(-EPROBE_DEFER); 605 606 /* Offsets (reg64) of early PLLs are relative to OLB block. */ 607 base = of_iomap(np, 0); 608 if (!base) { 609 ret = -ENODEV; 610 goto err; 611 } 612 613 for (i = 0; i < early_data->early_pll_count; i++) { 614 const struct eqc_pll *pll = &early_data->early_plls[i]; 615 unsigned long mult, div, acc; 616 struct clk_hw *hw; 617 u32 r0, r1; 618 u64 val; 619 620 val = readq(base + pll->reg64); 621 r0 = val; 622 r1 = val >> 32; 623 624 ret = eqc_pll_parse_registers(r0, r1, &mult, &div, &acc); 625 if (ret) { 626 pr_err("failed parsing state of %s\n", pll->name); 627 goto err; 628 } 629 630 hw = clk_hw_register_fixed_factor_with_accuracy_fwname(NULL, 631 np, pll->name, "ref", 0, mult, div, acc); 632 cells->hws[pll->index] = hw; 633 if (IS_ERR(hw)) { 634 pr_err("failed registering %s: %pe\n", pll->name, hw); 635 ret = PTR_ERR(hw); 636 goto err; 637 } 638 } 639 640 /* When providing a single clock, require no cell. */ 641 if (clk_count == 1) 642 ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, cells->hws[0]); 643 else 644 ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, cells); 645 if (ret) { 646 pr_err("failed registering clk provider: %d\n", ret); 647 goto err; 648 } 649 650 return; 651 652 err: 653 /* 654 * We are doomed. The system will not be able to boot. 655 * 656 * Let's still try to be good citizens by freeing resources and print 657 * a last error message that might help debugging. 658 */ 659 660 pr_err("failed clk init: %d\n", ret); 661 662 if (cells) { 663 of_clk_del_provider(np); 664 665 for (i = 0; i < early_data->early_pll_count; i++) { 666 const struct eqc_pll *pll = &early_data->early_plls[i]; 667 struct clk_hw *hw = cells->hws[pll->index]; 668 669 if (!IS_ERR_OR_NULL(hw)) 670 clk_hw_unregister_fixed_factor(hw); 671 } 672 673 kfree(cells); 674 } 675 } 676 677 static void __init eqc_eyeq5_early_init(struct device_node *np) 678 { 679 eqc_early_init(np, &eqc_eyeq5_early_match_data); 680 } 681 CLK_OF_DECLARE_DRIVER(eqc_eyeq5, "mobileye,eyeq5-olb", eqc_eyeq5_early_init); 682 683 static void __init eqc_eyeq6h_central_early_init(struct device_node *np) 684 { 685 eqc_early_init(np, &eqc_eyeq6h_central_early_match_data); 686 } 687 CLK_OF_DECLARE_DRIVER(eqc_eyeq6h_central, "mobileye,eyeq6h-central-olb", 688 eqc_eyeq6h_central_early_init); 689 690 static void __init eqc_eyeq6h_west_early_init(struct device_node *np) 691 { 692 eqc_early_init(np, &eqc_eyeq6h_west_early_match_data); 693 } 694 CLK_OF_DECLARE_DRIVER(eqc_eyeq6h_west, "mobileye,eyeq6h-west-olb", 695 eqc_eyeq6h_west_early_init); 696