Skip to content

Commit 306d2f5

Browse files
ziyao233mmind
authored andcommitted
clk: rockchip: rk3528: Add SD/SDIO tuning clocks in GRF region
These clocks locate in VO and VPU GRF, serving for SD/SDIO controller tuning purpose. Add their definitions and register them in driver if corresponding GRF is available. GRFs are looked up by compatible to simplify devicetree binding. Signed-off-by: Yao Zi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Stuebner <[email protected]>
1 parent 621ba4d commit 306d2f5

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

drivers/clk/rockchip/clk-rk3528.c

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <linux/of.h>
1111
#include <linux/of_device.h>
1212
#include <linux/platform_device.h>
13+
#include <linux/mfd/syscon.h>
14+
#include <linux/minmax.h>
1315

1416
#include <dt-bindings/clock/rockchip,rk3528-cru.h>
1517

@@ -1061,23 +1063,65 @@ static struct rockchip_clk_branch rk3528_clk_branches[] __initdata = {
10611063
0, 1, 1),
10621064
};
10631065

1066+
static struct rockchip_clk_branch rk3528_vo_clk_branches[] __initdata = {
1067+
MMC_GRF(SCLK_SDMMC_DRV, "sdmmc_drv", "cclk_src_sdmmc0",
1068+
RK3528_SDMMC_CON(0), 1, grf_type_vo),
1069+
MMC_GRF(SCLK_SDMMC_SAMPLE, "sdmmc_sample", "cclk_src_sdmmc0",
1070+
RK3528_SDMMC_CON(1), 1, grf_type_vo),
1071+
};
1072+
1073+
static struct rockchip_clk_branch rk3528_vpu_clk_branches[] __initdata = {
1074+
MMC_GRF(SCLK_SDIO0_DRV, "sdio0_drv", "cclk_src_sdio0",
1075+
RK3528_SDIO0_CON(0), 1, grf_type_vpu),
1076+
MMC_GRF(SCLK_SDIO0_SAMPLE, "sdio0_sample", "cclk_src_sdio0",
1077+
RK3528_SDIO0_CON(1), 1, grf_type_vpu),
1078+
MMC_GRF(SCLK_SDIO1_DRV, "sdio1_drv", "cclk_src_sdio1",
1079+
RK3528_SDIO1_CON(0), 1, grf_type_vpu),
1080+
MMC_GRF(SCLK_SDIO1_SAMPLE, "sdio1_sample", "cclk_src_sdio1",
1081+
RK3528_SDIO1_CON(1), 1, grf_type_vpu),
1082+
};
1083+
10641084
static int __init clk_rk3528_probe(struct platform_device *pdev)
10651085
{
1066-
struct rockchip_clk_provider *ctx;
1086+
unsigned long nr_vpu_branches = ARRAY_SIZE(rk3528_vpu_clk_branches);
1087+
unsigned long nr_vo_branches = ARRAY_SIZE(rk3528_vo_clk_branches);
1088+
unsigned long nr_branches = ARRAY_SIZE(rk3528_clk_branches);
1089+
unsigned long nr_clks, nr_vo_clks, nr_vpu_clks;
1090+
struct rockchip_aux_grf *vo_grf_e, *vpu_grf_e;
1091+
struct regmap *vo_grf, *vpu_grf;
10671092
struct device *dev = &pdev->dev;
10681093
struct device_node *np = dev->of_node;
1069-
unsigned long nr_branches = ARRAY_SIZE(rk3528_clk_branches);
1070-
unsigned long nr_clks;
1094+
struct rockchip_clk_provider *ctx;
10711095
void __iomem *reg_base;
10721096

1073-
nr_clks = rockchip_clk_find_max_clk_id(rk3528_clk_branches,
1074-
nr_branches) + 1;
1075-
10761097
reg_base = devm_platform_ioremap_resource(pdev, 0);
10771098
if (IS_ERR(reg_base))
10781099
return dev_err_probe(dev, PTR_ERR(reg_base),
10791100
"could not map cru region");
10801101

1102+
nr_clks = rockchip_clk_find_max_clk_id(rk3528_clk_branches,
1103+
nr_branches) + 1;
1104+
1105+
vo_grf = syscon_regmap_lookup_by_compatible("rockchip,rk3528-vo-grf");
1106+
if (!IS_ERR(vo_grf)) {
1107+
nr_vo_clks = rockchip_clk_find_max_clk_id(rk3528_vo_clk_branches,
1108+
nr_vo_branches) + 1;
1109+
nr_clks = max(nr_clks, nr_vo_clks);
1110+
} else if (PTR_ERR(vo_grf) != -ENODEV) {
1111+
return dev_err_probe(dev, PTR_ERR(vo_grf),
1112+
"failed to look up VO GRF\n");
1113+
}
1114+
1115+
vpu_grf = syscon_regmap_lookup_by_compatible("rockchip,rk3528-vpu-grf");
1116+
if (!IS_ERR(vpu_grf)) {
1117+
nr_vpu_clks = rockchip_clk_find_max_clk_id(rk3528_vpu_clk_branches,
1118+
nr_vpu_branches) + 1;
1119+
nr_clks = max(nr_clks, nr_vpu_clks);
1120+
} else if (PTR_ERR(vpu_grf) != -ENODEV) {
1121+
return dev_err_probe(dev, PTR_ERR(vpu_grf),
1122+
"failed to look up VPU GRF\n");
1123+
}
1124+
10811125
ctx = rockchip_clk_init(np, reg_base, nr_clks);
10821126
if (IS_ERR(ctx))
10831127
return dev_err_probe(dev, PTR_ERR(ctx),
@@ -1092,6 +1136,32 @@ static int __init clk_rk3528_probe(struct platform_device *pdev)
10921136
ARRAY_SIZE(rk3528_cpuclk_rates));
10931137
rockchip_clk_register_branches(ctx, rk3528_clk_branches, nr_branches);
10941138

1139+
if (!IS_ERR(vo_grf)) {
1140+
vo_grf_e = devm_kzalloc(dev, sizeof(*vo_grf_e), GFP_KERNEL);
1141+
if (!vo_grf_e)
1142+
return -ENOMEM;
1143+
1144+
vo_grf_e->grf = vo_grf;
1145+
vo_grf_e->type = grf_type_vo;
1146+
hash_add(ctx->aux_grf_table, &vo_grf_e->node, grf_type_vo);
1147+
1148+
rockchip_clk_register_branches(ctx, rk3528_vo_clk_branches,
1149+
nr_vo_branches);
1150+
}
1151+
1152+
if (!IS_ERR(vpu_grf)) {
1153+
vpu_grf_e = devm_kzalloc(dev, sizeof(*vpu_grf_e), GFP_KERNEL);
1154+
if (!vpu_grf_e)
1155+
return -ENOMEM;
1156+
1157+
vpu_grf_e->grf = vpu_grf;
1158+
vpu_grf_e->type = grf_type_vpu;
1159+
hash_add(ctx->aux_grf_table, &vpu_grf_e->node, grf_type_vpu);
1160+
1161+
rockchip_clk_register_branches(ctx, rk3528_vpu_clk_branches,
1162+
nr_vpu_branches);
1163+
}
1164+
10951165
rk3528_rst_init(np, reg_base);
10961166

10971167
rockchip_register_restart_notifier(ctx, RK3528_GLB_SRST_FST, NULL);

drivers/clk/rockchip/clk.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ struct clk;
218218
#define RK3528_CLKSEL_CON(x) ((x) * 0x4 + 0x300)
219219
#define RK3528_CLKGATE_CON(x) ((x) * 0x4 + 0x800)
220220
#define RK3528_SOFTRST_CON(x) ((x) * 0x4 + 0xa00)
221+
#define RK3528_SDMMC_CON(x) ((x) * 0x4 + 0x24)
222+
#define RK3528_SDIO0_CON(x) ((x) * 0x4 + 0x4)
223+
#define RK3528_SDIO1_CON(x) ((x) * 0x4 + 0xc)
221224
#define RK3528_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x300 + RK3528_PMU_CRU_BASE)
222225
#define RK3528_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x800 + RK3528_PMU_CRU_BASE)
223226
#define RK3528_PCIE_CLKSEL_CON(x) ((x) * 0x4 + 0x300 + RK3528_PCIE_CRU_BASE)
@@ -446,6 +449,8 @@ enum rockchip_grf_type {
446449
grf_type_pmu0,
447450
grf_type_pmu1,
448451
grf_type_ioc,
452+
grf_type_vo,
453+
grf_type_vpu,
449454
};
450455

451456
/* ceil(sqrt(enums in rockchip_grf_type - 1)) */

0 commit comments

Comments
 (0)