Skip to content

Commit 70a114d

Browse files
Nicolas Frattarolimmind
authored andcommitted
clk: rockchip: introduce auxiliary GRFs
The MUXGRF clock branch type depends on having access to some sort of GRF as a regmap to be registered. So far, we could easily get away with only ever having one GRF stowed away in the context. However, newer Rockchip SoCs, such as the RK3576, have several GRFs which are relevant for clock purposes. It already depends on the pmu0 GRF for MUXGRF reasons, but could get away with not refactoring this because it didn't need the sysgrf at all, so could overwrite the pointer in the clock provider to the pmu0 grf regmap handle. In preparation for needing to finally access more than one GRF per SoC, let's untangle this. Introduce an auxiliary GRF hashmap, and a GRF type enum. The hashmap is keyed by the enum, and clock branches now have a struct member to store the value of that enum, which defaults to the system GRF. The SoC-specific _clk_init function can then insert pointers to GRF regmaps into the hashmap based on the grf type. During clock branch registration, we then pick the right GRF for each branch from the hashmap if something other than the sys GRF is requested. The reason for doing it with this grf type indirection in the clock branches is so that we don't need to define the MUXGRF branches in a separate step, just to have a direct pointer to a regmap available already. Signed-off-by: Nicolas Frattaroli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Stuebner <[email protected]>
1 parent 6657acc commit 70a114d

File tree

7 files changed

+72
-18
lines changed

7 files changed

+72
-18
lines changed

drivers/clk/rockchip/clk-rk3288.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ static struct rockchip_clk_branch rk3288_clk_branches[] __initdata = {
418418
RK3288_CLKSEL_CON(32), 14, 2, MFLAGS, 8, 5, DFLAGS,
419419
RK3288_CLKGATE_CON(3), 11, GFLAGS),
420420
MUXGRF(0, "aclk_vcodec_pre", mux_aclk_vcodec_pre_p, CLK_SET_RATE_PARENT,
421-
RK3288_GRF_SOC_CON(0), 7, 1, MFLAGS),
421+
RK3288_GRF_SOC_CON(0), 7, 1, MFLAGS, grf_type_sys),
422422
GATE(ACLK_VCODEC, "aclk_vcodec", "aclk_vcodec_pre", 0,
423423
RK3288_CLKGATE_CON(9), 0, GFLAGS),
424424

drivers/clk/rockchip/clk-rk3328.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,9 @@ static struct rockchip_clk_branch rk3328_clk_branches[] __initdata = {
677677
RK3328_CLKSEL_CON(27), 15, 1, MFLAGS, 8, 5, DFLAGS,
678678
RK3328_CLKGATE_CON(3), 5, GFLAGS),
679679
MUXGRF(SCLK_MAC2IO, "clk_mac2io", mux_mac2io_src_p, CLK_SET_RATE_NO_REPARENT,
680-
RK3328_GRF_MAC_CON1, 10, 1, MFLAGS),
680+
RK3328_GRF_MAC_CON1, 10, 1, MFLAGS, grf_type_sys),
681681
MUXGRF(SCLK_MAC2IO_EXT, "clk_mac2io_ext", mux_mac2io_ext_p, CLK_SET_RATE_NO_REPARENT,
682-
RK3328_GRF_SOC_CON4, 14, 1, MFLAGS),
682+
RK3328_GRF_SOC_CON4, 14, 1, MFLAGS, grf_type_sys),
683683

684684
COMPOSITE(SCLK_MAC2PHY_SRC, "clk_mac2phy_src", mux_2plls_p, 0,
685685
RK3328_CLKSEL_CON(26), 7, 1, MFLAGS, 0, 5, DFLAGS,
@@ -692,7 +692,7 @@ static struct rockchip_clk_branch rk3328_clk_branches[] __initdata = {
692692
RK3328_CLKSEL_CON(26), 8, 2, DFLAGS,
693693
RK3328_CLKGATE_CON(9), 2, GFLAGS),
694694
MUXGRF(SCLK_MAC2PHY, "clk_mac2phy", mux_mac2phy_src_p, CLK_SET_RATE_NO_REPARENT,
695-
RK3328_GRF_MAC_CON2, 10, 1, MFLAGS),
695+
RK3328_GRF_MAC_CON2, 10, 1, MFLAGS, grf_type_sys),
696696

697697
FACTOR(0, "xin12m", "xin24m", 0, 1, 2),
698698

drivers/clk/rockchip/clk-rk3568.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ static struct rockchip_clk_branch rk3568_clk_branches[] __initdata = {
591591
RK3568_CLKSEL_CON(9), 6, 2, MFLAGS, 0, 5, DFLAGS,
592592
RK3568_CLKGATE_CON(4), 0, GFLAGS),
593593
MUXGRF(CLK_DDR1X, "clk_ddr1x", clk_ddr1x_p, CLK_SET_RATE_PARENT,
594-
RK3568_CLKSEL_CON(9), 15, 1, MFLAGS),
594+
RK3568_CLKSEL_CON(9), 15, 1, MFLAGS, grf_type_sys),
595595

596596
COMPOSITE_NOMUX(CLK_MSCH, "clk_msch", "clk_ddr1x", CLK_IGNORE_UNUSED,
597597
RK3568_CLKSEL_CON(10), 0, 2, DFLAGS,

drivers/clk/rockchip/clk-rk3576.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,13 +1676,13 @@ static struct rockchip_clk_branch rk3576_clk_branches[] __initdata = {
16761676

16771677
/* phy ref */
16781678
MUXGRF(CLK_PHY_REF_SRC, "clk_phy_ref_src", clk_phy_ref_src_p, 0,
1679-
RK3576_PMU0_GRF_OSC_CON6, 4, 1, MFLAGS),
1679+
RK3576_PMU0_GRF_OSC_CON6, 4, 1, MFLAGS, grf_type_pmu0),
16801680
MUXGRF(CLK_USBPHY_REF_SRC, "clk_usbphy_ref_src", clk_usbphy_ref_src_p, 0,
1681-
RK3576_PMU0_GRF_OSC_CON6, 2, 1, MFLAGS),
1681+
RK3576_PMU0_GRF_OSC_CON6, 2, 1, MFLAGS, grf_type_pmu0),
16821682
MUXGRF(CLK_CPLL_REF_SRC, "clk_cpll_ref_src", clk_cpll_ref_src_p, 0,
1683-
RK3576_PMU0_GRF_OSC_CON6, 1, 1, MFLAGS),
1683+
RK3576_PMU0_GRF_OSC_CON6, 1, 1, MFLAGS, grf_type_pmu0),
16841684
MUXGRF(CLK_AUPLL_REF_SRC, "clk_aupll_ref_src", clk_aupll_ref_src_p, 0,
1685-
RK3576_PMU0_GRF_OSC_CON6, 0, 1, MFLAGS),
1685+
RK3576_PMU0_GRF_OSC_CON6, 0, 1, MFLAGS, grf_type_pmu0),
16861686

16871687
/* secure ns */
16881688
COMPOSITE_NODIV(ACLK_SECURE_NS, "aclk_secure_ns", mux_350m_175m_116m_24m_p, CLK_IS_CRITICAL,
@@ -1725,13 +1725,14 @@ static void __init rk3576_clk_init(struct device_node *np)
17251725
struct rockchip_clk_provider *ctx;
17261726
unsigned long clk_nr_clks;
17271727
void __iomem *reg_base;
1728-
struct regmap *grf;
1728+
struct rockchip_aux_grf *pmu0_grf_e;
1729+
struct regmap *pmu0_grf;
17291730

17301731
clk_nr_clks = rockchip_clk_find_max_clk_id(rk3576_clk_branches,
17311732
ARRAY_SIZE(rk3576_clk_branches)) + 1;
17321733

1733-
grf = syscon_regmap_lookup_by_compatible("rockchip,rk3576-pmu0-grf");
1734-
if (IS_ERR(grf)) {
1734+
pmu0_grf = syscon_regmap_lookup_by_compatible("rockchip,rk3576-pmu0-grf");
1735+
if (IS_ERR(pmu0_grf)) {
17351736
pr_err("%s: could not get PMU0 GRF syscon\n", __func__);
17361737
return;
17371738
}
@@ -1745,11 +1746,16 @@ static void __init rk3576_clk_init(struct device_node *np)
17451746
ctx = rockchip_clk_init(np, reg_base, clk_nr_clks);
17461747
if (IS_ERR(ctx)) {
17471748
pr_err("%s: rockchip clk init failed\n", __func__);
1748-
iounmap(reg_base);
1749-
return;
1749+
goto err_unmap;
17501750
}
17511751

1752-
ctx->grf = grf;
1752+
pmu0_grf_e = kzalloc(sizeof(*pmu0_grf_e), GFP_KERNEL);
1753+
if (!pmu0_grf_e)
1754+
goto err_unmap;
1755+
1756+
pmu0_grf_e->grf = pmu0_grf;
1757+
pmu0_grf_e->type = grf_type_pmu0;
1758+
hash_add(ctx->aux_grf_table, &pmu0_grf_e->node, grf_type_pmu0);
17531759

17541760
rockchip_clk_register_plls(ctx, rk3576_pll_clks,
17551761
ARRAY_SIZE(rk3576_pll_clks),
@@ -1772,6 +1778,12 @@ static void __init rk3576_clk_init(struct device_node *np)
17721778
rockchip_register_restart_notifier(ctx, RK3576_GLB_SRST_FST, NULL);
17731779

17741780
rockchip_clk_of_add_provider(np, ctx);
1781+
1782+
return;
1783+
1784+
err_unmap:
1785+
iounmap(reg_base);
1786+
return;
17751787
}
17761788

17771789
CLK_OF_DECLARE(rk3576_cru, "rockchip,rk3576-cru", rk3576_clk_init);

drivers/clk/rockchip/clk-rv1126.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static struct rockchip_clk_branch rv1126_clk_branches[] __initdata = {
857857
RV1126_GMAC_CON, 5, 1, MFLAGS),
858858
MUXGRF(CLK_GMAC_SRC, "clk_gmac_src", mux_clk_gmac_src_p, CLK_SET_RATE_PARENT |
859859
CLK_SET_RATE_NO_REPARENT,
860-
RV1126_GRF_IOFUNC_CON1, 12, 1, MFLAGS),
860+
RV1126_GRF_IOFUNC_CON1, 12, 1, MFLAGS, grf_type_sys),
861861

862862
GATE(CLK_GMAC_REF, "clk_gmac_ref", "clk_gmac_src", 0,
863863
RV1126_CLKGATE_CON(20), 7, GFLAGS),

drivers/clk/rockchip/clk.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ static struct rockchip_clk_provider *rockchip_clk_init_base(
382382
ctx->cru_node = np;
383383
spin_lock_init(&ctx->lock);
384384

385+
hash_init(ctx->aux_grf_table);
386+
385387
ctx->grf = syscon_regmap_lookup_by_phandle(ctx->cru_node,
386388
"rockchip,grf");
387389

@@ -496,6 +498,8 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
496498
struct rockchip_clk_branch *list,
497499
unsigned int nr_clk)
498500
{
501+
struct regmap *grf = ctx->grf;
502+
struct rockchip_aux_grf *agrf;
499503
struct clk *clk;
500504
unsigned int idx;
501505
unsigned long flags;
@@ -504,6 +508,17 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
504508
flags = list->flags;
505509
clk = NULL;
506510

511+
/* for GRF-dependent branches, choose the right grf first */
512+
if (list->branch_type == branch_muxgrf &&
513+
list->grf_type != grf_type_sys) {
514+
hash_for_each_possible(ctx->aux_grf_table, agrf, node, list->grf_type) {
515+
if (agrf->type == list->grf_type) {
516+
grf = agrf->grf;
517+
break;
518+
}
519+
}
520+
}
521+
507522
/* catch simple muxes */
508523
switch (list->branch_type) {
509524
case branch_mux:
@@ -526,7 +541,7 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
526541
case branch_muxgrf:
527542
clk = rockchip_clk_register_muxgrf(list->name,
528543
list->parent_names, list->num_parents,
529-
flags, ctx->grf, list->muxdiv_offset,
544+
flags, grf, list->muxdiv_offset,
530545
list->mux_shift, list->mux_width,
531546
list->mux_flags);
532547
break;

drivers/clk/rockchip/clk.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/io.h>
2121
#include <linux/clk-provider.h>
22+
#include <linux/hashtable.h>
2223

2324
struct clk;
2425

@@ -440,19 +441,43 @@ enum rockchip_pll_type {
440441
.k = _k, \
441442
}
442443

444+
enum rockchip_grf_type {
445+
grf_type_sys = 0,
446+
grf_type_pmu0,
447+
grf_type_pmu1,
448+
grf_type_ioc,
449+
};
450+
451+
/* ceil(sqrt(enums in rockchip_grf_type - 1)) */
452+
#define GRF_HASH_ORDER 2
453+
454+
/**
455+
* struct rockchip_aux_grf - entry for the aux_grf_table hashtable
456+
* @grf: pointer to the grf this entry references
457+
* @type: what type of GRF this is
458+
* @node: hlist node
459+
*/
460+
struct rockchip_aux_grf {
461+
struct regmap *grf;
462+
enum rockchip_grf_type type;
463+
struct hlist_node node;
464+
};
465+
443466
/**
444467
* struct rockchip_clk_provider - information about clock provider
445468
* @reg_base: virtual address for the register base.
446469
* @clk_data: holds clock related data like clk* and number of clocks.
447470
* @cru_node: device-node of the clock-provider
448471
* @grf: regmap of the general-register-files syscon
472+
* @aux_grf_table: hashtable of auxiliary GRF regmaps, indexed by grf_type
449473
* @lock: maintains exclusion between callbacks for a given clock-provider.
450474
*/
451475
struct rockchip_clk_provider {
452476
void __iomem *reg_base;
453477
struct clk_onecell_data clk_data;
454478
struct device_node *cru_node;
455479
struct regmap *grf;
480+
DECLARE_HASHTABLE(aux_grf_table, GRF_HASH_ORDER);
456481
spinlock_t lock;
457482
};
458483

@@ -660,6 +685,7 @@ struct rockchip_clk_branch {
660685
u8 gate_shift;
661686
u8 gate_flags;
662687
unsigned int linked_clk_id;
688+
enum rockchip_grf_type grf_type;
663689
struct rockchip_clk_branch *child;
664690
};
665691

@@ -900,7 +926,7 @@ struct rockchip_clk_branch {
900926
.mux_table = mt, \
901927
}
902928

903-
#define MUXGRF(_id, cname, pnames, f, o, s, w, mf) \
929+
#define MUXGRF(_id, cname, pnames, f, o, s, w, mf, gt) \
904930
{ \
905931
.id = _id, \
906932
.branch_type = branch_muxgrf, \
@@ -913,6 +939,7 @@ struct rockchip_clk_branch {
913939
.mux_width = w, \
914940
.mux_flags = mf, \
915941
.gate_offset = -1, \
942+
.grf_type = gt, \
916943
}
917944

918945
#define DIV(_id, cname, pname, f, o, s, w, df) \

0 commit comments

Comments
 (0)