ccu-sun8i-v3s.c (26611B)
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Copyright (c) 2016 Icenowy Zheng <icenowy@aosc.xyz> 4 * 5 * Based on ccu-sun8i-h3.c, which is: 6 * Copyright (c) 2016 Maxime Ripard. All rights reserved. 7 */ 8 9#include <linux/clk-provider.h> 10#include <linux/io.h> 11#include <linux/module.h> 12#include <linux/of_device.h> 13#include <linux/platform_device.h> 14 15#include "ccu_common.h" 16#include "ccu_reset.h" 17 18#include "ccu_div.h" 19#include "ccu_gate.h" 20#include "ccu_mp.h" 21#include "ccu_mult.h" 22#include "ccu_nk.h" 23#include "ccu_nkm.h" 24#include "ccu_nkmp.h" 25#include "ccu_nm.h" 26#include "ccu_phase.h" 27 28#include "ccu-sun8i-v3s.h" 29 30static SUNXI_CCU_NKMP_WITH_GATE_LOCK(pll_cpu_clk, "pll-cpu", 31 "osc24M", 0x000, 32 8, 5, /* N */ 33 4, 2, /* K */ 34 0, 2, /* M */ 35 16, 2, /* P */ 36 BIT(31), /* gate */ 37 BIT(28), /* lock */ 38 0); 39 40/* 41 * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from 42 * the base (2x, 4x and 8x), and one variable divider (the one true 43 * pll audio). 44 * 45 * With sigma-delta modulation for fractional-N on the audio PLL, 46 * we have to use specific dividers. This means the variable divider 47 * can no longer be used, as the audio codec requests the exact clock 48 * rates we support through this mechanism. So we now hard code the 49 * variable divider to 1. This means the clock rates will no longer 50 * match the clock names. 51 */ 52#define SUN8I_V3S_PLL_AUDIO_REG 0x008 53 54static struct ccu_sdm_setting pll_audio_sdm_table[] = { 55 { .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 }, 56 { .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 }, 57}; 58 59static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", 60 "osc24M", 0x008, 61 8, 7, /* N */ 62 0, 5, /* M */ 63 pll_audio_sdm_table, BIT(24), 64 0x284, BIT(31), 65 BIT(31), /* gate */ 66 BIT(28), /* lock */ 67 CLK_SET_RATE_UNGATE); 68 69static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video", 70 "osc24M", 0x0010, 71 8, 7, /* N */ 72 0, 4, /* M */ 73 BIT(24), /* frac enable */ 74 BIT(25), /* frac select */ 75 270000000, /* frac rate 0 */ 76 297000000, /* frac rate 1 */ 77 BIT(31), /* gate */ 78 BIT(28), /* lock */ 79 0); 80 81static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", 82 "osc24M", 0x0018, 83 8, 7, /* N */ 84 0, 4, /* M */ 85 BIT(24), /* frac enable */ 86 BIT(25), /* frac select */ 87 270000000, /* frac rate 0 */ 88 297000000, /* frac rate 1 */ 89 BIT(31), /* gate */ 90 BIT(28), /* lock */ 91 0); 92 93static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr0", 94 "osc24M", 0x020, 95 8, 5, /* N */ 96 4, 2, /* K */ 97 0, 2, /* M */ 98 BIT(31), /* gate */ 99 BIT(28), /* lock */ 100 0); 101 102static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph0_clk, "pll-periph0", 103 "osc24M", 0x028, 104 8, 5, /* N */ 105 4, 2, /* K */ 106 BIT(31), /* gate */ 107 BIT(28), /* lock */ 108 2, /* post-div */ 109 0); 110 111static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_isp_clk, "pll-isp", 112 "osc24M", 0x002c, 113 8, 7, /* N */ 114 0, 4, /* M */ 115 BIT(24), /* frac enable */ 116 BIT(25), /* frac select */ 117 270000000, /* frac rate 0 */ 118 297000000, /* frac rate 1 */ 119 BIT(31), /* gate */ 120 BIT(28), /* lock */ 121 0); 122 123static SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph1_clk, "pll-periph1", 124 "osc24M", 0x044, 125 8, 5, /* N */ 126 4, 2, /* K */ 127 BIT(31), /* gate */ 128 BIT(28), /* lock */ 129 2, /* post-div */ 130 0); 131 132static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_ddr1_clk, "pll-ddr1", 133 "osc24M", 0x04c, 134 8, 7, /* N */ 135 0, 2, /* M */ 136 BIT(31), /* gate */ 137 BIT(28), /* lock */ 138 0); 139 140static const char * const cpu_parents[] = { "osc32k", "osc24M", 141 "pll-cpu", "pll-cpu" }; 142static SUNXI_CCU_MUX(cpu_clk, "cpu", cpu_parents, 143 0x050, 16, 2, CLK_IS_CRITICAL); 144 145static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x050, 0, 2, 0); 146 147static const char * const ahb1_parents[] = { "osc32k", "osc24M", 148 "axi", "pll-periph0" }; 149static const struct ccu_mux_var_prediv ahb1_predivs[] = { 150 { .index = 3, .shift = 6, .width = 2 }, 151}; 152static struct ccu_div ahb1_clk = { 153 .div = _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO), 154 155 .mux = { 156 .shift = 12, 157 .width = 2, 158 159 .var_predivs = ahb1_predivs, 160 .n_var_predivs = ARRAY_SIZE(ahb1_predivs), 161 }, 162 163 .common = { 164 .reg = 0x054, 165 .features = CCU_FEATURE_VARIABLE_PREDIV, 166 .hw.init = CLK_HW_INIT_PARENTS("ahb1", 167 ahb1_parents, 168 &ccu_div_ops, 169 0), 170 }, 171}; 172 173static struct clk_div_table apb1_div_table[] = { 174 { .val = 0, .div = 2 }, 175 { .val = 1, .div = 2 }, 176 { .val = 2, .div = 4 }, 177 { .val = 3, .div = 8 }, 178 { /* Sentinel */ }, 179}; 180static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1", 181 0x054, 8, 2, apb1_div_table, 0); 182 183static const char * const apb2_parents[] = { "osc32k", "osc24M", 184 "pll-periph0", "pll-periph0" }; 185static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058, 186 0, 5, /* M */ 187 16, 2, /* P */ 188 24, 2, /* mux */ 189 0); 190 191static const char * const ahb2_parents[] = { "ahb1", "pll-periph0" }; 192static const struct ccu_mux_fixed_prediv ahb2_fixed_predivs[] = { 193 { .index = 1, .div = 2 }, 194}; 195static struct ccu_mux ahb2_clk = { 196 .mux = { 197 .shift = 0, 198 .width = 1, 199 .fixed_predivs = ahb2_fixed_predivs, 200 .n_predivs = ARRAY_SIZE(ahb2_fixed_predivs), 201 }, 202 203 .common = { 204 .reg = 0x05c, 205 .features = CCU_FEATURE_FIXED_PREDIV, 206 .hw.init = CLK_HW_INIT_PARENTS("ahb2", 207 ahb2_parents, 208 &ccu_mux_ops, 209 0), 210 }, 211}; 212 213static SUNXI_CCU_GATE(bus_ce_clk, "bus-ce", "ahb1", 214 0x060, BIT(5), 0); 215static SUNXI_CCU_GATE(bus_dma_clk, "bus-dma", "ahb1", 216 0x060, BIT(6), 0); 217static SUNXI_CCU_GATE(bus_mmc0_clk, "bus-mmc0", "ahb1", 218 0x060, BIT(8), 0); 219static SUNXI_CCU_GATE(bus_mmc1_clk, "bus-mmc1", "ahb1", 220 0x060, BIT(9), 0); 221static SUNXI_CCU_GATE(bus_mmc2_clk, "bus-mmc2", "ahb1", 222 0x060, BIT(10), 0); 223static SUNXI_CCU_GATE(bus_dram_clk, "bus-dram", "ahb1", 224 0x060, BIT(14), 0); 225static SUNXI_CCU_GATE(bus_emac_clk, "bus-emac", "ahb2", 226 0x060, BIT(17), 0); 227static SUNXI_CCU_GATE(bus_hstimer_clk, "bus-hstimer", "ahb1", 228 0x060, BIT(19), 0); 229static SUNXI_CCU_GATE(bus_spi0_clk, "bus-spi0", "ahb1", 230 0x060, BIT(20), 0); 231static SUNXI_CCU_GATE(bus_otg_clk, "bus-otg", "ahb1", 232 0x060, BIT(24), 0); 233static SUNXI_CCU_GATE(bus_ehci0_clk, "bus-ehci0", "ahb1", 234 0x060, BIT(26), 0); 235static SUNXI_CCU_GATE(bus_ohci0_clk, "bus-ohci0", "ahb1", 236 0x060, BIT(29), 0); 237 238static SUNXI_CCU_GATE(bus_ve_clk, "bus-ve", "ahb1", 239 0x064, BIT(0), 0); 240static SUNXI_CCU_GATE(bus_tcon0_clk, "bus-tcon0", "ahb1", 241 0x064, BIT(4), 0); 242static SUNXI_CCU_GATE(bus_csi_clk, "bus-csi", "ahb1", 243 0x064, BIT(8), 0); 244static SUNXI_CCU_GATE(bus_de_clk, "bus-de", "ahb1", 245 0x064, BIT(12), 0); 246 247static SUNXI_CCU_GATE(bus_codec_clk, "bus-codec", "apb1", 248 0x068, BIT(0), 0); 249static SUNXI_CCU_GATE(bus_pio_clk, "bus-pio", "apb1", 250 0x068, BIT(5), 0); 251static SUNXI_CCU_GATE(bus_i2s0_clk, "bus-i2s0", "apb1", 252 0x068, BIT(12), 0); 253 254static SUNXI_CCU_GATE(bus_i2c0_clk, "bus-i2c0", "apb2", 255 0x06c, BIT(0), 0); 256static SUNXI_CCU_GATE(bus_i2c1_clk, "bus-i2c1", "apb2", 257 0x06c, BIT(1), 0); 258static SUNXI_CCU_GATE(bus_uart0_clk, "bus-uart0", "apb2", 259 0x06c, BIT(16), 0); 260static SUNXI_CCU_GATE(bus_uart1_clk, "bus-uart1", "apb2", 261 0x06c, BIT(17), 0); 262static SUNXI_CCU_GATE(bus_uart2_clk, "bus-uart2", "apb2", 263 0x06c, BIT(18), 0); 264 265static SUNXI_CCU_GATE(bus_ephy_clk, "bus-ephy", "ahb1", 266 0x070, BIT(0), 0); 267static SUNXI_CCU_GATE(bus_dbg_clk, "bus-dbg", "ahb1", 268 0x070, BIT(7), 0); 269 270static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0", 271 "pll-periph1" }; 272static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088, 273 0, 4, /* M */ 274 16, 2, /* P */ 275 24, 2, /* mux */ 276 BIT(31), /* gate */ 277 0); 278 279static SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0", 280 0x088, 20, 3, 0); 281static SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0", 282 0x088, 8, 3, 0); 283 284static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c, 285 0, 4, /* M */ 286 16, 2, /* P */ 287 24, 2, /* mux */ 288 BIT(31), /* gate */ 289 0); 290 291static SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1", 292 0x08c, 20, 3, 0); 293static SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1", 294 0x08c, 8, 3, 0); 295 296static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090, 297 0, 4, /* M */ 298 16, 2, /* P */ 299 24, 2, /* mux */ 300 BIT(31), /* gate */ 301 0); 302 303static SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2", 304 0x090, 20, 3, 0); 305static SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2", 306 0x090, 8, 3, 0); 307 308static const char * const ce_parents[] = { "osc24M", "pll-periph0", }; 309 310static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x09c, 311 0, 4, /* M */ 312 16, 2, /* P */ 313 24, 2, /* mux */ 314 BIT(31), /* gate */ 315 0); 316 317static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0, 318 0, 4, /* M */ 319 16, 2, /* P */ 320 24, 2, /* mux */ 321 BIT(31), /* gate */ 322 0); 323 324static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x", 325 "pll-audio-2x", "pll-audio" }; 326static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents, 327 0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT); 328 329static SUNXI_CCU_GATE(usb_phy0_clk, "usb-phy0", "osc24M", 330 0x0cc, BIT(8), 0); 331static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M", 332 0x0cc, BIT(16), 0); 333 334static const char * const dram_parents[] = { "pll-ddr0", "pll-ddr1", 335 "pll-periph0-2x" }; 336static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents, 337 0x0f4, 0, 4, 20, 2, CLK_IS_CRITICAL); 338 339static SUNXI_CCU_GATE(dram_ve_clk, "dram-ve", "dram", 340 0x100, BIT(0), 0); 341static SUNXI_CCU_GATE(dram_csi_clk, "dram-csi", "dram", 342 0x100, BIT(1), 0); 343static SUNXI_CCU_GATE(dram_ehci_clk, "dram-ehci", "dram", 344 0x100, BIT(17), 0); 345static SUNXI_CCU_GATE(dram_ohci_clk, "dram-ohci", "dram", 346 0x100, BIT(18), 0); 347 348static const char * const de_parents[] = { "pll-video", "pll-periph0" }; 349static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents, 350 0x104, 0, 4, 24, 2, BIT(31), 351 CLK_SET_RATE_PARENT); 352 353static const char * const tcon_parents[] = { "pll-video" }; 354static SUNXI_CCU_M_WITH_MUX_GATE(tcon_clk, "tcon", tcon_parents, 355 0x118, 0, 4, 24, 3, BIT(31), 0); 356 357static SUNXI_CCU_GATE(csi_misc_clk, "csi-misc", "osc24M", 358 0x130, BIT(31), 0); 359 360static const char * const csi_mclk_parents[] = { "osc24M", "pll-video", 361 "pll-periph0", "pll-periph1" }; 362static SUNXI_CCU_M_WITH_MUX_GATE(csi0_mclk_clk, "csi0-mclk", csi_mclk_parents, 363 0x130, 0, 5, 8, 3, BIT(15), 0); 364 365static const char * const csi1_sclk_parents[] = { "pll-video", "pll-isp" }; 366static SUNXI_CCU_M_WITH_MUX_GATE(csi1_sclk_clk, "csi-sclk", csi1_sclk_parents, 367 0x134, 16, 4, 24, 3, BIT(31), 0); 368 369static SUNXI_CCU_M_WITH_MUX_GATE(csi1_mclk_clk, "csi-mclk", csi_mclk_parents, 370 0x134, 0, 5, 8, 3, BIT(15), 0); 371 372static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve", 373 0x13c, 16, 3, BIT(31), 0); 374 375static SUNXI_CCU_GATE(ac_dig_clk, "ac-dig", "pll-audio", 376 0x140, BIT(31), CLK_SET_RATE_PARENT); 377static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 378 0x144, BIT(31), 0); 379 380static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x", 381 "pll-ddr" }; 382static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents, 383 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL); 384 385static const char * const mipi_csi_parents[] = { "pll-video", "pll-periph0", 386 "pll-isp" }; 387static SUNXI_CCU_M_WITH_MUX_GATE(mipi_csi_clk, "mipi-csi", mipi_csi_parents, 388 0x16c, 0, 3, 24, 2, BIT(31), 0); 389 390static struct ccu_common *sun8i_v3s_ccu_clks[] = { 391 &pll_cpu_clk.common, 392 &pll_audio_base_clk.common, 393 &pll_video_clk.common, 394 &pll_ve_clk.common, 395 &pll_ddr0_clk.common, 396 &pll_periph0_clk.common, 397 &pll_isp_clk.common, 398 &pll_periph1_clk.common, 399 &pll_ddr1_clk.common, 400 &cpu_clk.common, 401 &axi_clk.common, 402 &ahb1_clk.common, 403 &apb1_clk.common, 404 &apb2_clk.common, 405 &ahb2_clk.common, 406 &bus_ce_clk.common, 407 &bus_dma_clk.common, 408 &bus_mmc0_clk.common, 409 &bus_mmc1_clk.common, 410 &bus_mmc2_clk.common, 411 &bus_dram_clk.common, 412 &bus_emac_clk.common, 413 &bus_hstimer_clk.common, 414 &bus_spi0_clk.common, 415 &bus_otg_clk.common, 416 &bus_ehci0_clk.common, 417 &bus_ohci0_clk.common, 418 &bus_ve_clk.common, 419 &bus_tcon0_clk.common, 420 &bus_csi_clk.common, 421 &bus_de_clk.common, 422 &bus_codec_clk.common, 423 &bus_pio_clk.common, 424 &bus_i2c0_clk.common, 425 &bus_i2c1_clk.common, 426 &bus_uart0_clk.common, 427 &bus_uart1_clk.common, 428 &bus_uart2_clk.common, 429 &bus_ephy_clk.common, 430 &bus_dbg_clk.common, 431 &mmc0_clk.common, 432 &mmc0_sample_clk.common, 433 &mmc0_output_clk.common, 434 &mmc1_clk.common, 435 &mmc1_sample_clk.common, 436 &mmc1_output_clk.common, 437 &mmc2_clk.common, 438 &mmc2_sample_clk.common, 439 &mmc2_output_clk.common, 440 &ce_clk.common, 441 &spi0_clk.common, 442 &usb_phy0_clk.common, 443 &usb_ohci0_clk.common, 444 &dram_clk.common, 445 &dram_ve_clk.common, 446 &dram_csi_clk.common, 447 &dram_ohci_clk.common, 448 &dram_ehci_clk.common, 449 &de_clk.common, 450 &tcon_clk.common, 451 &csi_misc_clk.common, 452 &csi0_mclk_clk.common, 453 &csi1_sclk_clk.common, 454 &csi1_mclk_clk.common, 455 &ve_clk.common, 456 &ac_dig_clk.common, 457 &avs_clk.common, 458 &mbus_clk.common, 459 &mipi_csi_clk.common, 460}; 461 462static const struct clk_hw *clk_parent_pll_audio[] = { 463 &pll_audio_base_clk.common.hw 464}; 465 466static struct ccu_common *sun8i_v3_ccu_clks[] = { 467 &pll_cpu_clk.common, 468 &pll_audio_base_clk.common, 469 &pll_video_clk.common, 470 &pll_ve_clk.common, 471 &pll_ddr0_clk.common, 472 &pll_periph0_clk.common, 473 &pll_isp_clk.common, 474 &pll_periph1_clk.common, 475 &pll_ddr1_clk.common, 476 &cpu_clk.common, 477 &axi_clk.common, 478 &ahb1_clk.common, 479 &apb1_clk.common, 480 &apb2_clk.common, 481 &ahb2_clk.common, 482 &bus_ce_clk.common, 483 &bus_dma_clk.common, 484 &bus_mmc0_clk.common, 485 &bus_mmc1_clk.common, 486 &bus_mmc2_clk.common, 487 &bus_dram_clk.common, 488 &bus_emac_clk.common, 489 &bus_hstimer_clk.common, 490 &bus_spi0_clk.common, 491 &bus_otg_clk.common, 492 &bus_ehci0_clk.common, 493 &bus_ohci0_clk.common, 494 &bus_ve_clk.common, 495 &bus_tcon0_clk.common, 496 &bus_csi_clk.common, 497 &bus_de_clk.common, 498 &bus_codec_clk.common, 499 &bus_pio_clk.common, 500 &bus_i2s0_clk.common, 501 &bus_i2c0_clk.common, 502 &bus_i2c1_clk.common, 503 &bus_uart0_clk.common, 504 &bus_uart1_clk.common, 505 &bus_uart2_clk.common, 506 &bus_ephy_clk.common, 507 &bus_dbg_clk.common, 508 &mmc0_clk.common, 509 &mmc0_sample_clk.common, 510 &mmc0_output_clk.common, 511 &mmc1_clk.common, 512 &mmc1_sample_clk.common, 513 &mmc1_output_clk.common, 514 &mmc2_clk.common, 515 &mmc2_sample_clk.common, 516 &mmc2_output_clk.common, 517 &ce_clk.common, 518 &spi0_clk.common, 519 &i2s0_clk.common, 520 &usb_phy0_clk.common, 521 &usb_ohci0_clk.common, 522 &dram_clk.common, 523 &dram_ve_clk.common, 524 &dram_csi_clk.common, 525 &dram_ohci_clk.common, 526 &dram_ehci_clk.common, 527 &de_clk.common, 528 &tcon_clk.common, 529 &csi_misc_clk.common, 530 &csi0_mclk_clk.common, 531 &csi1_sclk_clk.common, 532 &csi1_mclk_clk.common, 533 &ve_clk.common, 534 &ac_dig_clk.common, 535 &avs_clk.common, 536 &mbus_clk.common, 537 &mipi_csi_clk.common, 538}; 539 540/* We hardcode the divider to 1 for SDM support */ 541static CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio", 542 clk_parent_pll_audio, 543 1, 1, CLK_SET_RATE_PARENT); 544static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x", 545 clk_parent_pll_audio, 546 2, 1, CLK_SET_RATE_PARENT); 547static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x", 548 clk_parent_pll_audio, 549 1, 1, CLK_SET_RATE_PARENT); 550static CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x", 551 clk_parent_pll_audio, 552 1, 2, CLK_SET_RATE_PARENT); 553static CLK_FIXED_FACTOR_HW(pll_periph0_2x_clk, "pll-periph0-2x", 554 &pll_periph0_clk.common.hw, 555 1, 2, 0); 556 557static struct clk_hw_onecell_data sun8i_v3s_hw_clks = { 558 .hws = { 559 [CLK_PLL_CPU] = &pll_cpu_clk.common.hw, 560 [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw, 561 [CLK_PLL_AUDIO] = &pll_audio_clk.hw, 562 [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw, 563 [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw, 564 [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw, 565 [CLK_PLL_VIDEO] = &pll_video_clk.common.hw, 566 [CLK_PLL_VE] = &pll_ve_clk.common.hw, 567 [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw, 568 [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw, 569 [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw, 570 [CLK_PLL_ISP] = &pll_isp_clk.common.hw, 571 [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw, 572 [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw, 573 [CLK_CPU] = &cpu_clk.common.hw, 574 [CLK_AXI] = &axi_clk.common.hw, 575 [CLK_AHB1] = &ahb1_clk.common.hw, 576 [CLK_APB1] = &apb1_clk.common.hw, 577 [CLK_APB2] = &apb2_clk.common.hw, 578 [CLK_AHB2] = &ahb2_clk.common.hw, 579 [CLK_BUS_CE] = &bus_ce_clk.common.hw, 580 [CLK_BUS_DMA] = &bus_dma_clk.common.hw, 581 [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw, 582 [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw, 583 [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw, 584 [CLK_BUS_DRAM] = &bus_dram_clk.common.hw, 585 [CLK_BUS_EMAC] = &bus_emac_clk.common.hw, 586 [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw, 587 [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw, 588 [CLK_BUS_OTG] = &bus_otg_clk.common.hw, 589 [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw, 590 [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw, 591 [CLK_BUS_VE] = &bus_ve_clk.common.hw, 592 [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw, 593 [CLK_BUS_CSI] = &bus_csi_clk.common.hw, 594 [CLK_BUS_DE] = &bus_de_clk.common.hw, 595 [CLK_BUS_CODEC] = &bus_codec_clk.common.hw, 596 [CLK_BUS_PIO] = &bus_pio_clk.common.hw, 597 [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw, 598 [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw, 599 [CLK_BUS_UART0] = &bus_uart0_clk.common.hw, 600 [CLK_BUS_UART1] = &bus_uart1_clk.common.hw, 601 [CLK_BUS_UART2] = &bus_uart2_clk.common.hw, 602 [CLK_BUS_EPHY] = &bus_ephy_clk.common.hw, 603 [CLK_BUS_DBG] = &bus_dbg_clk.common.hw, 604 [CLK_MMC0] = &mmc0_clk.common.hw, 605 [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw, 606 [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw, 607 [CLK_MMC1] = &mmc1_clk.common.hw, 608 [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw, 609 [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw, 610 [CLK_MMC2] = &mmc2_clk.common.hw, 611 [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw, 612 [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw, 613 [CLK_CE] = &ce_clk.common.hw, 614 [CLK_SPI0] = &spi0_clk.common.hw, 615 [CLK_USB_PHY0] = &usb_phy0_clk.common.hw, 616 [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw, 617 [CLK_DRAM] = &dram_clk.common.hw, 618 [CLK_DRAM_VE] = &dram_ve_clk.common.hw, 619 [CLK_DRAM_CSI] = &dram_csi_clk.common.hw, 620 [CLK_DRAM_EHCI] = &dram_ehci_clk.common.hw, 621 [CLK_DRAM_OHCI] = &dram_ohci_clk.common.hw, 622 [CLK_DE] = &de_clk.common.hw, 623 [CLK_TCON0] = &tcon_clk.common.hw, 624 [CLK_CSI_MISC] = &csi_misc_clk.common.hw, 625 [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw, 626 [CLK_CSI1_SCLK] = &csi1_sclk_clk.common.hw, 627 [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw, 628 [CLK_VE] = &ve_clk.common.hw, 629 [CLK_AC_DIG] = &ac_dig_clk.common.hw, 630 [CLK_AVS] = &avs_clk.common.hw, 631 [CLK_MBUS] = &mbus_clk.common.hw, 632 [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw, 633 }, 634 .num = CLK_PLL_DDR1 + 1, 635}; 636 637static struct clk_hw_onecell_data sun8i_v3_hw_clks = { 638 .hws = { 639 [CLK_PLL_CPU] = &pll_cpu_clk.common.hw, 640 [CLK_PLL_AUDIO_BASE] = &pll_audio_base_clk.common.hw, 641 [CLK_PLL_AUDIO] = &pll_audio_clk.hw, 642 [CLK_PLL_AUDIO_2X] = &pll_audio_2x_clk.hw, 643 [CLK_PLL_AUDIO_4X] = &pll_audio_4x_clk.hw, 644 [CLK_PLL_AUDIO_8X] = &pll_audio_8x_clk.hw, 645 [CLK_PLL_VIDEO] = &pll_video_clk.common.hw, 646 [CLK_PLL_VE] = &pll_ve_clk.common.hw, 647 [CLK_PLL_DDR0] = &pll_ddr0_clk.common.hw, 648 [CLK_PLL_PERIPH0] = &pll_periph0_clk.common.hw, 649 [CLK_PLL_PERIPH0_2X] = &pll_periph0_2x_clk.hw, 650 [CLK_PLL_ISP] = &pll_isp_clk.common.hw, 651 [CLK_PLL_PERIPH1] = &pll_periph1_clk.common.hw, 652 [CLK_PLL_DDR1] = &pll_ddr1_clk.common.hw, 653 [CLK_CPU] = &cpu_clk.common.hw, 654 [CLK_AXI] = &axi_clk.common.hw, 655 [CLK_AHB1] = &ahb1_clk.common.hw, 656 [CLK_APB1] = &apb1_clk.common.hw, 657 [CLK_APB2] = &apb2_clk.common.hw, 658 [CLK_AHB2] = &ahb2_clk.common.hw, 659 [CLK_BUS_CE] = &bus_ce_clk.common.hw, 660 [CLK_BUS_DMA] = &bus_dma_clk.common.hw, 661 [CLK_BUS_MMC0] = &bus_mmc0_clk.common.hw, 662 [CLK_BUS_MMC1] = &bus_mmc1_clk.common.hw, 663 [CLK_BUS_MMC2] = &bus_mmc2_clk.common.hw, 664 [CLK_BUS_DRAM] = &bus_dram_clk.common.hw, 665 [CLK_BUS_EMAC] = &bus_emac_clk.common.hw, 666 [CLK_BUS_HSTIMER] = &bus_hstimer_clk.common.hw, 667 [CLK_BUS_SPI0] = &bus_spi0_clk.common.hw, 668 [CLK_BUS_OTG] = &bus_otg_clk.common.hw, 669 [CLK_BUS_EHCI0] = &bus_ehci0_clk.common.hw, 670 [CLK_BUS_OHCI0] = &bus_ohci0_clk.common.hw, 671 [CLK_BUS_VE] = &bus_ve_clk.common.hw, 672 [CLK_BUS_TCON0] = &bus_tcon0_clk.common.hw, 673 [CLK_BUS_CSI] = &bus_csi_clk.common.hw, 674 [CLK_BUS_DE] = &bus_de_clk.common.hw, 675 [CLK_BUS_CODEC] = &bus_codec_clk.common.hw, 676 [CLK_BUS_PIO] = &bus_pio_clk.common.hw, 677 [CLK_BUS_I2S0] = &bus_i2s0_clk.common.hw, 678 [CLK_BUS_I2C0] = &bus_i2c0_clk.common.hw, 679 [CLK_BUS_I2C1] = &bus_i2c1_clk.common.hw, 680 [CLK_BUS_UART0] = &bus_uart0_clk.common.hw, 681 [CLK_BUS_UART1] = &bus_uart1_clk.common.hw, 682 [CLK_BUS_UART2] = &bus_uart2_clk.common.hw, 683 [CLK_BUS_EPHY] = &bus_ephy_clk.common.hw, 684 [CLK_BUS_DBG] = &bus_dbg_clk.common.hw, 685 [CLK_MMC0] = &mmc0_clk.common.hw, 686 [CLK_MMC0_SAMPLE] = &mmc0_sample_clk.common.hw, 687 [CLK_MMC0_OUTPUT] = &mmc0_output_clk.common.hw, 688 [CLK_MMC1] = &mmc1_clk.common.hw, 689 [CLK_MMC1_SAMPLE] = &mmc1_sample_clk.common.hw, 690 [CLK_MMC1_OUTPUT] = &mmc1_output_clk.common.hw, 691 [CLK_MMC2] = &mmc2_clk.common.hw, 692 [CLK_MMC2_SAMPLE] = &mmc2_sample_clk.common.hw, 693 [CLK_MMC2_OUTPUT] = &mmc2_output_clk.common.hw, 694 [CLK_CE] = &ce_clk.common.hw, 695 [CLK_SPI0] = &spi0_clk.common.hw, 696 [CLK_I2S0] = &i2s0_clk.common.hw, 697 [CLK_USB_PHY0] = &usb_phy0_clk.common.hw, 698 [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw, 699 [CLK_DRAM] = &dram_clk.common.hw, 700 [CLK_DRAM_VE] = &dram_ve_clk.common.hw, 701 [CLK_DRAM_CSI] = &dram_csi_clk.common.hw, 702 [CLK_DRAM_EHCI] = &dram_ehci_clk.common.hw, 703 [CLK_DRAM_OHCI] = &dram_ohci_clk.common.hw, 704 [CLK_DE] = &de_clk.common.hw, 705 [CLK_TCON0] = &tcon_clk.common.hw, 706 [CLK_CSI_MISC] = &csi_misc_clk.common.hw, 707 [CLK_CSI0_MCLK] = &csi0_mclk_clk.common.hw, 708 [CLK_CSI1_SCLK] = &csi1_sclk_clk.common.hw, 709 [CLK_CSI1_MCLK] = &csi1_mclk_clk.common.hw, 710 [CLK_VE] = &ve_clk.common.hw, 711 [CLK_AC_DIG] = &ac_dig_clk.common.hw, 712 [CLK_AVS] = &avs_clk.common.hw, 713 [CLK_MBUS] = &mbus_clk.common.hw, 714 [CLK_MIPI_CSI] = &mipi_csi_clk.common.hw, 715 }, 716 .num = CLK_I2S0 + 1, 717}; 718 719static struct ccu_reset_map sun8i_v3s_ccu_resets[] = { 720 [RST_USB_PHY0] = { 0x0cc, BIT(0) }, 721 722 [RST_MBUS] = { 0x0fc, BIT(31) }, 723 724 [RST_BUS_CE] = { 0x2c0, BIT(5) }, 725 [RST_BUS_DMA] = { 0x2c0, BIT(6) }, 726 [RST_BUS_MMC0] = { 0x2c0, BIT(8) }, 727 [RST_BUS_MMC1] = { 0x2c0, BIT(9) }, 728 [RST_BUS_MMC2] = { 0x2c0, BIT(10) }, 729 [RST_BUS_DRAM] = { 0x2c0, BIT(14) }, 730 [RST_BUS_EMAC] = { 0x2c0, BIT(17) }, 731 [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) }, 732 [RST_BUS_SPI0] = { 0x2c0, BIT(20) }, 733 [RST_BUS_OTG] = { 0x2c0, BIT(24) }, 734 [RST_BUS_EHCI0] = { 0x2c0, BIT(26) }, 735 [RST_BUS_OHCI0] = { 0x2c0, BIT(29) }, 736 737 [RST_BUS_VE] = { 0x2c4, BIT(0) }, 738 [RST_BUS_TCON0] = { 0x2c4, BIT(4) }, 739 [RST_BUS_CSI] = { 0x2c4, BIT(8) }, 740 [RST_BUS_DE] = { 0x2c4, BIT(12) }, 741 [RST_BUS_DBG] = { 0x2c4, BIT(31) }, 742 743 [RST_BUS_EPHY] = { 0x2c8, BIT(2) }, 744 745 [RST_BUS_CODEC] = { 0x2d0, BIT(0) }, 746 747 [RST_BUS_I2C0] = { 0x2d8, BIT(0) }, 748 [RST_BUS_I2C1] = { 0x2d8, BIT(1) }, 749 [RST_BUS_UART0] = { 0x2d8, BIT(16) }, 750 [RST_BUS_UART1] = { 0x2d8, BIT(17) }, 751 [RST_BUS_UART2] = { 0x2d8, BIT(18) }, 752}; 753 754static struct ccu_reset_map sun8i_v3_ccu_resets[] = { 755 [RST_USB_PHY0] = { 0x0cc, BIT(0) }, 756 757 [RST_MBUS] = { 0x0fc, BIT(31) }, 758 759 [RST_BUS_CE] = { 0x2c0, BIT(5) }, 760 [RST_BUS_DMA] = { 0x2c0, BIT(6) }, 761 [RST_BUS_MMC0] = { 0x2c0, BIT(8) }, 762 [RST_BUS_MMC1] = { 0x2c0, BIT(9) }, 763 [RST_BUS_MMC2] = { 0x2c0, BIT(10) }, 764 [RST_BUS_DRAM] = { 0x2c0, BIT(14) }, 765 [RST_BUS_EMAC] = { 0x2c0, BIT(17) }, 766 [RST_BUS_HSTIMER] = { 0x2c0, BIT(19) }, 767 [RST_BUS_SPI0] = { 0x2c0, BIT(20) }, 768 [RST_BUS_OTG] = { 0x2c0, BIT(24) }, 769 [RST_BUS_EHCI0] = { 0x2c0, BIT(26) }, 770 [RST_BUS_OHCI0] = { 0x2c0, BIT(29) }, 771 772 [RST_BUS_VE] = { 0x2c4, BIT(0) }, 773 [RST_BUS_TCON0] = { 0x2c4, BIT(4) }, 774 [RST_BUS_CSI] = { 0x2c4, BIT(8) }, 775 [RST_BUS_DE] = { 0x2c4, BIT(12) }, 776 [RST_BUS_DBG] = { 0x2c4, BIT(31) }, 777 778 [RST_BUS_EPHY] = { 0x2c8, BIT(2) }, 779 780 [RST_BUS_CODEC] = { 0x2d0, BIT(0) }, 781 [RST_BUS_I2S0] = { 0x2d0, BIT(12) }, 782 783 [RST_BUS_I2C0] = { 0x2d8, BIT(0) }, 784 [RST_BUS_I2C1] = { 0x2d8, BIT(1) }, 785 [RST_BUS_UART0] = { 0x2d8, BIT(16) }, 786 [RST_BUS_UART1] = { 0x2d8, BIT(17) }, 787 [RST_BUS_UART2] = { 0x2d8, BIT(18) }, 788}; 789 790static const struct sunxi_ccu_desc sun8i_v3s_ccu_desc = { 791 .ccu_clks = sun8i_v3s_ccu_clks, 792 .num_ccu_clks = ARRAY_SIZE(sun8i_v3s_ccu_clks), 793 794 .hw_clks = &sun8i_v3s_hw_clks, 795 796 .resets = sun8i_v3s_ccu_resets, 797 .num_resets = ARRAY_SIZE(sun8i_v3s_ccu_resets), 798}; 799 800static const struct sunxi_ccu_desc sun8i_v3_ccu_desc = { 801 .ccu_clks = sun8i_v3_ccu_clks, 802 .num_ccu_clks = ARRAY_SIZE(sun8i_v3_ccu_clks), 803 804 .hw_clks = &sun8i_v3_hw_clks, 805 806 .resets = sun8i_v3_ccu_resets, 807 .num_resets = ARRAY_SIZE(sun8i_v3_ccu_resets), 808}; 809 810static int sun8i_v3s_ccu_probe(struct platform_device *pdev) 811{ 812 const struct sunxi_ccu_desc *desc; 813 void __iomem *reg; 814 u32 val; 815 816 desc = of_device_get_match_data(&pdev->dev); 817 if (!desc) 818 return -EINVAL; 819 820 reg = devm_platform_ioremap_resource(pdev, 0); 821 if (IS_ERR(reg)) 822 return PTR_ERR(reg); 823 824 /* Force the PLL-Audio-1x divider to 1 */ 825 val = readl(reg + SUN8I_V3S_PLL_AUDIO_REG); 826 val &= ~GENMASK(19, 16); 827 writel(val, reg + SUN8I_V3S_PLL_AUDIO_REG); 828 829 return devm_sunxi_ccu_probe(&pdev->dev, reg, desc); 830} 831 832static const struct of_device_id sun8i_v3s_ccu_ids[] = { 833 { 834 .compatible = "allwinner,sun8i-v3-ccu", 835 .data = &sun8i_v3_ccu_desc, 836 }, 837 { 838 .compatible = "allwinner,sun8i-v3s-ccu", 839 .data = &sun8i_v3s_ccu_desc, 840 }, 841 { } 842}; 843 844static struct platform_driver sun8i_v3s_ccu_driver = { 845 .probe = sun8i_v3s_ccu_probe, 846 .driver = { 847 .name = "sun8i-v3s-ccu", 848 .suppress_bind_attrs = true, 849 .of_match_table = sun8i_v3s_ccu_ids, 850 }, 851}; 852module_platform_driver(sun8i_v3s_ccu_driver); 853 854MODULE_IMPORT_NS(SUNXI_CCU); 855MODULE_LICENSE("GPL");