Skip to content

Commit 621ba4d

Browse files
ziyao233mmind
authored andcommitted
clk: rockchip: Support MMC clocks in GRF region
Registers of MMC drive/sample clocks in Rockchip RV1106 and RK3528 locate in GRF regions. Adjust MMC clock code to support register operations through regmap. Signed-off-by: Yao Zi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Heiko Stuebner <[email protected]>
1 parent 58883d5 commit 621ba4d

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

drivers/clk/rockchip/clk-mmc-phase.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
#include <linux/clk-provider.h>
1010
#include <linux/io.h>
1111
#include <linux/kernel.h>
12+
#include <linux/regmap.h>
1213
#include "clk.h"
1314

1415
struct rockchip_mmc_clock {
1516
struct clk_hw hw;
1617
void __iomem *reg;
18+
struct regmap *grf;
19+
int grf_reg;
1720
int shift;
1821
int cached_phase;
1922
struct notifier_block clk_rate_change_nb;
@@ -54,7 +57,12 @@ static int rockchip_mmc_get_phase(struct clk_hw *hw)
5457
if (!rate)
5558
return 0;
5659

57-
raw_value = readl(mmc_clock->reg) >> (mmc_clock->shift);
60+
if (mmc_clock->grf)
61+
regmap_read(mmc_clock->grf, mmc_clock->grf_reg, &raw_value);
62+
else
63+
raw_value = readl(mmc_clock->reg);
64+
65+
raw_value >>= mmc_clock->shift;
5866

5967
degrees = (raw_value & ROCKCHIP_MMC_DEGREE_MASK) * 90;
6068

@@ -134,8 +142,12 @@ static int rockchip_mmc_set_phase(struct clk_hw *hw, int degrees)
134142
raw_value = delay_num ? ROCKCHIP_MMC_DELAY_SEL : 0;
135143
raw_value |= delay_num << ROCKCHIP_MMC_DELAYNUM_OFFSET;
136144
raw_value |= nineties;
137-
writel(HIWORD_UPDATE(raw_value, 0x07ff, mmc_clock->shift),
138-
mmc_clock->reg);
145+
raw_value = HIWORD_UPDATE(raw_value, 0x07ff, mmc_clock->shift);
146+
147+
if (mmc_clock->grf)
148+
regmap_write(mmc_clock->grf, mmc_clock->grf_reg, raw_value);
149+
else
150+
writel(raw_value, mmc_clock->reg);
139151

140152
pr_debug("%s->set_phase(%d) delay_nums=%u reg[0x%p]=0x%03x actual_degrees=%d\n",
141153
clk_hw_get_name(hw), degrees, delay_num,
@@ -189,7 +201,9 @@ static int rockchip_mmc_clk_rate_notify(struct notifier_block *nb,
189201

190202
struct clk *rockchip_clk_register_mmc(const char *name,
191203
const char *const *parent_names, u8 num_parents,
192-
void __iomem *reg, int shift)
204+
void __iomem *reg,
205+
struct regmap *grf, int grf_reg,
206+
int shift)
193207
{
194208
struct clk_init_data init;
195209
struct rockchip_mmc_clock *mmc_clock;
@@ -208,6 +222,8 @@ struct clk *rockchip_clk_register_mmc(const char *name,
208222

209223
mmc_clock->hw.init = &init;
210224
mmc_clock->reg = reg;
225+
mmc_clock->grf = grf;
226+
mmc_clock->grf_reg = grf_reg;
211227
mmc_clock->shift = shift;
212228

213229
clk = clk_register(NULL, &mmc_clock->hw);

drivers/clk/rockchip/clk.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,10 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
509509
clk = NULL;
510510

511511
/* for GRF-dependent branches, choose the right grf first */
512-
if ((list->branch_type == branch_muxgrf || list->branch_type == branch_grf_gate) &&
513-
list->grf_type != grf_type_sys) {
512+
if ((list->branch_type == branch_muxgrf ||
513+
list->branch_type == branch_grf_gate ||
514+
list->branch_type == branch_grf_mmc) &&
515+
list->grf_type != grf_type_sys) {
514516
hash_for_each_possible(ctx->aux_grf_table, agrf, node, list->grf_type) {
515517
if (agrf->type == list->grf_type) {
516518
grf = agrf->grf;
@@ -612,6 +614,16 @@ void rockchip_clk_register_branches(struct rockchip_clk_provider *ctx,
612614
list->name,
613615
list->parent_names, list->num_parents,
614616
ctx->reg_base + list->muxdiv_offset,
617+
NULL, 0,
618+
list->div_shift
619+
);
620+
break;
621+
case branch_grf_mmc:
622+
clk = rockchip_clk_register_mmc(
623+
list->name,
624+
list->parent_names, list->num_parents,
625+
0,
626+
grf, list->muxdiv_offset,
615627
list->div_shift
616628
);
617629
break;

drivers/clk/rockchip/clk.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ struct clk *rockchip_clk_register_cpuclk(const char *name,
619619

620620
struct clk *rockchip_clk_register_mmc(const char *name,
621621
const char *const *parent_names, u8 num_parents,
622-
void __iomem *reg, int shift);
622+
void __iomem *reg,
623+
struct regmap *grf, int grf_reg,
624+
int shift);
623625

624626
/*
625627
* DDRCLK flags, including method of setting the rate
@@ -664,6 +666,7 @@ enum rockchip_clk_branch_type {
664666
branch_grf_gate,
665667
branch_linked_gate,
666668
branch_mmc,
669+
branch_grf_mmc,
667670
branch_inverter,
668671
branch_factor,
669672
branch_ddrclk,
@@ -1030,6 +1033,18 @@ struct rockchip_clk_branch {
10301033
.div_shift = shift, \
10311034
}
10321035

1036+
#define MMC_GRF(_id, cname, pname, offset, shift, grftype) \
1037+
{ \
1038+
.id = _id, \
1039+
.branch_type = branch_grf_mmc, \
1040+
.name = cname, \
1041+
.parent_names = (const char *[]){ pname }, \
1042+
.num_parents = 1, \
1043+
.muxdiv_offset = offset, \
1044+
.div_shift = shift, \
1045+
.grf_type = grftype, \
1046+
}
1047+
10331048
#define INVERTER(_id, cname, pname, io, is, if) \
10341049
{ \
10351050
.id = _id, \

0 commit comments

Comments
 (0)