Skip to content

Commit aab58ac

Browse files
committed
Merge tag 'v5.9-rockchip-clk1' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind/linux-rockchip into clk-rockchip
Pull Rockchip clk driver updates from Heiko Stuebner: Use poll_timeout functions for pll lock-waiting and move the rk3036 to use the available lock-status in pll-registers instead of reading it from the General Register Files. Handle the clock variants on the rk3288w, revert the mmc sample shift change on rk3328 and make the mac_lbtest clock critical on rk3188. * tag 'v5.9-rockchip-clk1' of git://git.kernel.org/pub/scm/linux/kernel/git/mmind/linux-rockchip: clk: rockchip: add sclk_mac_lbtest to rk3188_critical_clocks clk: rockchip: Revert "fix wrong mmc sample phase shift for rk3328" clk: rockchip: use separate compatibles for rk3288w-cru dt-bindings: clocks: add rk3288w variant compatible clk: rockchip: Handle clock tree for rk3288w variant clk: rockchip: convert rk3036 pll type to use internal lock status clk: rockchip: convert basic pll lock_wait to use regmap_read_poll_timeout clk: rockchip: convert rk3399 pll type to use readl_relaxed_poll_timeout
2 parents b3a9e3b + ef990bc commit aab58ac

File tree

5 files changed

+89
-37
lines changed

5 files changed

+89
-37
lines changed

Documentation/devicetree/bindings/clock/rockchip,rk3288-cru.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ The RK3288 clock controller generates and supplies clock to various
44
controllers within the SoC and also implements a reset controller for SoC
55
peripherals.
66

7+
A revision of this SoC is available: rk3288w. The clock tree is a bit
8+
different so another dt-compatible is available. Noticed that it is only
9+
setting the difference but there is no automatic revision detection. This
10+
should be performed by bootloaders.
11+
712
Required Properties:
813

9-
- compatible: should be "rockchip,rk3288-cru"
14+
- compatible: should be "rockchip,rk3288-cru" or "rockchip,rk3288w-cru" in
15+
case of this revision of Rockchip rk3288.
1016
- reg: physical base address of the controller and length of memory mapped
1117
region.
1218
- #clock-cells: should be 1.

drivers/clk/rockchip/clk-pll.c

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/io.h>
1313
#include <linux/delay.h>
1414
#include <linux/clk-provider.h>
15+
#include <linux/iopoll.h>
1516
#include <linux/regmap.h>
1617
#include <linux/clk.h>
1718
#include "clk.h"
@@ -86,23 +87,14 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
8687
{
8788
struct regmap *grf = pll->ctx->grf;
8889
unsigned int val;
89-
int delay = 24000000, ret;
90-
91-
while (delay > 0) {
92-
ret = regmap_read(grf, pll->lock_offset, &val);
93-
if (ret) {
94-
pr_err("%s: failed to read pll lock status: %d\n",
95-
__func__, ret);
96-
return ret;
97-
}
90+
int ret;
9891

99-
if (val & BIT(pll->lock_shift))
100-
return 0;
101-
delay--;
102-
}
92+
ret = regmap_read_poll_timeout(grf, pll->lock_offset, val,
93+
val & BIT(pll->lock_shift), 0, 1000);
94+
if (ret)
95+
pr_err("%s: timeout waiting for pll to lock\n", __func__);
10396

104-
pr_err("%s: timeout waiting for pll to lock\n", __func__);
105-
return -ETIMEDOUT;
97+
return ret;
10698
}
10799

108100
/**
@@ -118,12 +110,31 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
118110
#define RK3036_PLLCON1_REFDIV_SHIFT 0
119111
#define RK3036_PLLCON1_POSTDIV2_MASK 0x7
120112
#define RK3036_PLLCON1_POSTDIV2_SHIFT 6
113+
#define RK3036_PLLCON1_LOCK_STATUS BIT(10)
121114
#define RK3036_PLLCON1_DSMPD_MASK 0x1
122115
#define RK3036_PLLCON1_DSMPD_SHIFT 12
116+
#define RK3036_PLLCON1_PWRDOWN BIT(13)
123117
#define RK3036_PLLCON2_FRAC_MASK 0xffffff
124118
#define RK3036_PLLCON2_FRAC_SHIFT 0
125119

126-
#define RK3036_PLLCON1_PWRDOWN (1 << 13)
120+
static int rockchip_rk3036_pll_wait_lock(struct rockchip_clk_pll *pll)
121+
{
122+
u32 pllcon;
123+
int ret;
124+
125+
/*
126+
* Lock time typical 250, max 500 input clock cycles @24MHz
127+
* So define a very safe maximum of 1000us, meaning 24000 cycles.
128+
*/
129+
ret = readl_relaxed_poll_timeout(pll->reg_base + RK3036_PLLCON(1),
130+
pllcon,
131+
pllcon & RK3036_PLLCON1_LOCK_STATUS,
132+
0, 1000);
133+
if (ret)
134+
pr_err("%s: timeout waiting for pll to lock\n", __func__);
135+
136+
return ret;
137+
}
127138

128139
static void rockchip_rk3036_pll_get_params(struct rockchip_clk_pll *pll,
129140
struct rockchip_pll_rate_table *rate)
@@ -221,7 +232,7 @@ static int rockchip_rk3036_pll_set_params(struct rockchip_clk_pll *pll,
221232
writel_relaxed(pllcon, pll->reg_base + RK3036_PLLCON(2));
222233

223234
/* wait for the pll to lock */
224-
ret = rockchip_pll_wait_lock(pll);
235+
ret = rockchip_rk3036_pll_wait_lock(pll);
225236
if (ret) {
226237
pr_warn("%s: pll update unsuccessful, trying to restore old params\n",
227238
__func__);
@@ -260,7 +271,7 @@ static int rockchip_rk3036_pll_enable(struct clk_hw *hw)
260271

261272
writel(HIWORD_UPDATE(0, RK3036_PLLCON1_PWRDOWN, 0),
262273
pll->reg_base + RK3036_PLLCON(1));
263-
rockchip_pll_wait_lock(pll);
274+
rockchip_rk3036_pll_wait_lock(pll);
264275

265276
return 0;
266277
}
@@ -589,19 +600,20 @@ static const struct clk_ops rockchip_rk3066_pll_clk_ops = {
589600
static int rockchip_rk3399_pll_wait_lock(struct rockchip_clk_pll *pll)
590601
{
591602
u32 pllcon;
592-
int delay = 24000000;
593-
594-
/* poll check the lock status in rk3399 xPLLCON2 */
595-
while (delay > 0) {
596-
pllcon = readl_relaxed(pll->reg_base + RK3399_PLLCON(2));
597-
if (pllcon & RK3399_PLLCON2_LOCK_STATUS)
598-
return 0;
603+
int ret;
599604

600-
delay--;
601-
}
605+
/*
606+
* Lock time typical 250, max 500 input clock cycles @24MHz
607+
* So define a very safe maximum of 1000us, meaning 24000 cycles.
608+
*/
609+
ret = readl_relaxed_poll_timeout(pll->reg_base + RK3399_PLLCON(2),
610+
pllcon,
611+
pllcon & RK3399_PLLCON2_LOCK_STATUS,
612+
0, 1000);
613+
if (ret)
614+
pr_err("%s: timeout waiting for pll to lock\n", __func__);
602615

603-
pr_err("%s: timeout waiting for pll to lock\n", __func__);
604-
return -ETIMEDOUT;
616+
return ret;
605617
}
606618

607619
static void rockchip_rk3399_pll_get_params(struct rockchip_clk_pll *pll,

drivers/clk/rockchip/clk-rk3188.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ static const char *const rk3188_critical_clocks[] __initconst = {
751751
"pclk_peri",
752752
"hclk_cpubus",
753753
"hclk_vio_bus",
754+
"sclk_mac_lbtest",
754755
};
755756

756757
static struct rockchip_clk_provider *__init rk3188_common_clk_init(struct device_node *np)

drivers/clk/rockchip/clk-rk3288.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#define RK3288_GRF_SOC_CON(x) (0x244 + x * 4)
1616
#define RK3288_GRF_SOC_STATUS1 0x284
1717

18+
enum rk3288_variant {
19+
RK3288_CRU,
20+
RK3288W_CRU,
21+
};
22+
1823
enum rk3288_plls {
1924
apll, dpll, cpll, gpll, npll,
2025
};
@@ -425,8 +430,6 @@ static struct rockchip_clk_branch rk3288_clk_branches[] __initdata = {
425430
COMPOSITE(0, "aclk_vio0", mux_pll_src_cpll_gpll_usb480m_p, CLK_IGNORE_UNUSED,
426431
RK3288_CLKSEL_CON(31), 6, 2, MFLAGS, 0, 5, DFLAGS,
427432
RK3288_CLKGATE_CON(3), 0, GFLAGS),
428-
DIV(0, "hclk_vio", "aclk_vio0", 0,
429-
RK3288_CLKSEL_CON(28), 8, 5, DFLAGS),
430433
COMPOSITE(0, "aclk_vio1", mux_pll_src_cpll_gpll_usb480m_p, CLK_IGNORE_UNUSED,
431434
RK3288_CLKSEL_CON(31), 14, 2, MFLAGS, 8, 5, DFLAGS,
432435
RK3288_CLKGATE_CON(3), 2, GFLAGS),
@@ -819,6 +822,16 @@ static struct rockchip_clk_branch rk3288_clk_branches[] __initdata = {
819822
INVERTER(0, "pclk_isp", "pclk_isp_in", RK3288_CLKSEL_CON(29), 3, IFLAGS),
820823
};
821824

825+
static struct rockchip_clk_branch rk3288w_hclkvio_branch[] __initdata = {
826+
DIV(0, "hclk_vio", "aclk_vio1", 0,
827+
RK3288_CLKSEL_CON(28), 8, 5, DFLAGS),
828+
};
829+
830+
static struct rockchip_clk_branch rk3288_hclkvio_branch[] __initdata = {
831+
DIV(0, "hclk_vio", "aclk_vio0", 0,
832+
RK3288_CLKSEL_CON(28), 8, 5, DFLAGS),
833+
};
834+
822835
static const char *const rk3288_critical_clocks[] __initconst = {
823836
"aclk_cpu",
824837
"aclk_peri",
@@ -914,7 +927,8 @@ static struct syscore_ops rk3288_clk_syscore_ops = {
914927
.resume = rk3288_clk_resume,
915928
};
916929

917-
static void __init rk3288_clk_init(struct device_node *np)
930+
static void __init rk3288_common_init(struct device_node *np,
931+
enum rk3288_variant soc)
918932
{
919933
struct rockchip_clk_provider *ctx;
920934

@@ -936,6 +950,14 @@ static void __init rk3288_clk_init(struct device_node *np)
936950
RK3288_GRF_SOC_STATUS1);
937951
rockchip_clk_register_branches(ctx, rk3288_clk_branches,
938952
ARRAY_SIZE(rk3288_clk_branches));
953+
954+
if (soc == RK3288W_CRU)
955+
rockchip_clk_register_branches(ctx, rk3288w_hclkvio_branch,
956+
ARRAY_SIZE(rk3288w_hclkvio_branch));
957+
else
958+
rockchip_clk_register_branches(ctx, rk3288_hclkvio_branch,
959+
ARRAY_SIZE(rk3288_hclkvio_branch));
960+
939961
rockchip_clk_protect_critical(rk3288_critical_clocks,
940962
ARRAY_SIZE(rk3288_critical_clocks));
941963

@@ -954,4 +976,15 @@ static void __init rk3288_clk_init(struct device_node *np)
954976

955977
rockchip_clk_of_add_provider(np, ctx);
956978
}
979+
980+
static void __init rk3288_clk_init(struct device_node *np)
981+
{
982+
rk3288_common_init(np, RK3288_CRU);
983+
}
957984
CLK_OF_DECLARE(rk3288_cru, "rockchip,rk3288-cru", rk3288_clk_init);
985+
986+
static void __init rk3288w_clk_init(struct device_node *np)
987+
{
988+
rk3288_common_init(np, RK3288W_CRU);
989+
}
990+
CLK_OF_DECLARE(rk3288w_cru, "rockchip,rk3288w-cru", rk3288w_clk_init);

drivers/clk/rockchip/clk-rk3328.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -808,22 +808,22 @@ static struct rockchip_clk_branch rk3328_clk_branches[] __initdata = {
808808
MMC(SCLK_SDMMC_DRV, "sdmmc_drv", "clk_sdmmc",
809809
RK3328_SDMMC_CON0, 1),
810810
MMC(SCLK_SDMMC_SAMPLE, "sdmmc_sample", "clk_sdmmc",
811-
RK3328_SDMMC_CON1, 0),
811+
RK3328_SDMMC_CON1, 1),
812812

813813
MMC(SCLK_SDIO_DRV, "sdio_drv", "clk_sdio",
814814
RK3328_SDIO_CON0, 1),
815815
MMC(SCLK_SDIO_SAMPLE, "sdio_sample", "clk_sdio",
816-
RK3328_SDIO_CON1, 0),
816+
RK3328_SDIO_CON1, 1),
817817

818818
MMC(SCLK_EMMC_DRV, "emmc_drv", "clk_emmc",
819819
RK3328_EMMC_CON0, 1),
820820
MMC(SCLK_EMMC_SAMPLE, "emmc_sample", "clk_emmc",
821-
RK3328_EMMC_CON1, 0),
821+
RK3328_EMMC_CON1, 1),
822822

823823
MMC(SCLK_SDMMC_EXT_DRV, "sdmmc_ext_drv", "clk_sdmmc_ext",
824824
RK3328_SDMMC_EXT_CON0, 1),
825825
MMC(SCLK_SDMMC_EXT_SAMPLE, "sdmmc_ext_sample", "clk_sdmmc_ext",
826-
RK3328_SDMMC_EXT_CON1, 0),
826+
RK3328_SDMMC_EXT_CON1, 1),
827827
};
828828

829829
static const char *const rk3328_critical_clocks[] __initconst = {

0 commit comments

Comments
 (0)