Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: starfive: jh7110-sys: Add PLL clocks source from DTS

Modify PLL clocks source to be got from DTS or
the fixed factor clocks.

Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com>
Reviewed-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>

authored by

Xingyu Wu and committed by
Conor Dooley
a013e981 616bc1de

+43 -20
+1
drivers/clk/starfive/Kconfig
··· 35 35 select AUXILIARY_BUS 36 36 select CLK_STARFIVE_JH71X0 37 37 select RESET_STARFIVE_JH7110 if RESET_CONTROLLER 38 + select CLK_STARFIVE_JH7110_PLL 38 39 default ARCH_STARFIVE 39 40 help 40 41 Say yes here to support the system clock controller on the
+42 -20
drivers/clk/starfive/clk-starfive-jh7110-sys.c
··· 7 7 */ 8 8 9 9 #include <linux/auxiliary_bus.h> 10 + #include <linux/clk.h> 10 11 #include <linux/clk-provider.h> 11 12 #include <linux/init.h> 12 13 #include <linux/io.h> ··· 390 389 struct jh71x0_clk_priv *priv; 391 390 unsigned int idx; 392 391 int ret; 392 + struct clk *pllclk; 393 393 394 394 priv = devm_kzalloc(&pdev->dev, 395 395 struct_size(priv, reg, JH7110_SYSCLK_END), ··· 404 402 if (IS_ERR(priv->base)) 405 403 return PTR_ERR(priv->base); 406 404 407 - /* 408 - * These PLL clocks are not actually fixed factor clocks and can be 409 - * controlled by the syscon registers of JH7110. They will be dropped 410 - * and registered in the PLL clock driver instead. 411 - */ 412 - /* 24MHz -> 1000.0MHz */ 413 - priv->pll[0] = devm_clk_hw_register_fixed_factor(priv->dev, "pll0_out", 414 - "osc", 0, 125, 3); 415 - if (IS_ERR(priv->pll[0])) 416 - return PTR_ERR(priv->pll[0]); 405 + /* Use fixed factor clocks if can not get the PLL clocks from DTS */ 406 + pllclk = clk_get(priv->dev, "pll0_out"); 407 + if (IS_ERR(pllclk)) { 408 + /* 24MHz -> 1000.0MHz */ 409 + priv->pll[0] = devm_clk_hw_register_fixed_factor(priv->dev, "pll0_out", 410 + "osc", 0, 125, 3); 411 + if (IS_ERR(priv->pll[0])) 412 + return PTR_ERR(priv->pll[0]); 413 + } else { 414 + clk_put(pllclk); 415 + priv->pll[0] = NULL; 416 + } 417 417 418 - /* 24MHz -> 1066.0MHz */ 419 - priv->pll[1] = devm_clk_hw_register_fixed_factor(priv->dev, "pll1_out", 420 - "osc", 0, 533, 12); 421 - if (IS_ERR(priv->pll[1])) 422 - return PTR_ERR(priv->pll[1]); 418 + pllclk = clk_get(priv->dev, "pll1_out"); 419 + if (IS_ERR(pllclk)) { 420 + /* 24MHz -> 1066.0MHz */ 421 + priv->pll[1] = devm_clk_hw_register_fixed_factor(priv->dev, "pll1_out", 422 + "osc", 0, 533, 12); 423 + if (IS_ERR(priv->pll[1])) 424 + return PTR_ERR(priv->pll[1]); 425 + } else { 426 + clk_put(pllclk); 427 + priv->pll[1] = NULL; 428 + } 423 429 424 - /* 24MHz -> 1188.0MHz */ 425 - priv->pll[2] = devm_clk_hw_register_fixed_factor(priv->dev, "pll2_out", 426 - "osc", 0, 99, 2); 427 - if (IS_ERR(priv->pll[2])) 428 - return PTR_ERR(priv->pll[2]); 430 + pllclk = clk_get(priv->dev, "pll2_out"); 431 + if (IS_ERR(pllclk)) { 432 + /* 24MHz -> 1188.0MHz */ 433 + priv->pll[2] = devm_clk_hw_register_fixed_factor(priv->dev, "pll2_out", 434 + "osc", 0, 99, 2); 435 + if (IS_ERR(priv->pll[2])) 436 + return PTR_ERR(priv->pll[2]); 437 + } else { 438 + clk_put(pllclk); 439 + priv->pll[2] = NULL; 440 + } 429 441 430 442 for (idx = 0; idx < JH7110_SYSCLK_END; idx++) { 431 443 u32 max = jh7110_sysclk_data[idx].max; ··· 478 462 parents[i].fw_name = "tdm_ext"; 479 463 else if (pidx == JH7110_SYSCLK_MCLK_EXT) 480 464 parents[i].fw_name = "mclk_ext"; 465 + else if (pidx == JH7110_SYSCLK_PLL0_OUT && !priv->pll[0]) 466 + parents[i].fw_name = "pll0_out"; 467 + else if (pidx == JH7110_SYSCLK_PLL1_OUT && !priv->pll[1]) 468 + parents[i].fw_name = "pll1_out"; 469 + else if (pidx == JH7110_SYSCLK_PLL2_OUT && !priv->pll[2]) 470 + parents[i].fw_name = "pll2_out"; 481 471 else 482 472 parents[i].hw = priv->pll[pidx - JH7110_SYSCLK_PLL0_OUT]; 483 473 }