Skip to content

Commit 3b37979

Browse files
prabhakarladgeertu
authored andcommitted
clk: renesas: cpg-mssr: Add module reset support for RZ/T2H
Add support for module reset handling on the RZ/T2H SoC. Unlike earlier CPG/MSSR variants, RZ/T2H uses a unified set of Module Reset Control Registers (MRCR) where both reset and deassert actions are done via read-modify-write (RMW) to the same register. Introduce a new MRCR offset table (mrcr_for_rzt2h) for RZ/T2H and assign it to reset_regs. For this SoC, the number of resets is based on the number of MRCR registers rather than the number of module clocks. Also add cpg_mrcr_reset_ops to implement reset, assert, and deassert using RMW while holding the spinlock. This follows the RZ/T2H requirements, where processing after releasing a module reset must be secured by performing seven dummy reads of the same register, and where a module that is reset and released again must ensure the target bit in the Module Reset Control Register is set to 1. Update the reset controller registration to select cpg_mrcr_reset_ops for RZ/T2H, while keeping the existing cpg_mssr_reset_ops for other SoCs. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Link: https://patch.msgid.link/20250929112324.3622148-1-prabhakar.mahadev-lad.rj@bp.renesas.com Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
1 parent 0f537c4 commit 3b37979

1 file changed

Lines changed: 107 additions & 4 deletions

File tree

drivers/clk/renesas/renesas-cpg-mssr.c

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#define WARN_DEBUG(x) do { } while (0)
4141
#endif
4242

43+
#define RZT2H_RESET_REG_READ_COUNT 7
44+
4345
/*
4446
* Module Standby and Software Reset register offets.
4547
*
@@ -137,6 +139,22 @@ static const u16 srcr_for_gen4[] = {
137139
0x2C60, 0x2C64, 0x2C68, 0x2C6C, 0x2C70, 0x2C74,
138140
};
139141

142+
static const u16 mrcr_for_rzt2h[] = {
143+
0x240, /* MRCTLA */
144+
0x244, /* Reserved */
145+
0x248, /* Reserved */
146+
0x24C, /* Reserved */
147+
0x250, /* MRCTLE */
148+
0x254, /* Reserved */
149+
0x258, /* Reserved */
150+
0x25C, /* Reserved */
151+
0x260, /* MRCTLI */
152+
0x264, /* Reserved */
153+
0x268, /* Reserved */
154+
0x26C, /* Reserved */
155+
0x270, /* MRCTLM */
156+
};
157+
140158
/*
141159
* Software Reset Clearing Register offsets
142160
*/
@@ -739,13 +757,86 @@ static int cpg_mssr_status(struct reset_controller_dev *rcdev,
739757
return !!(readl(priv->pub.base0 + priv->reset_regs[reg]) & bitmask);
740758
}
741759

760+
static int cpg_mrcr_set_reset_state(struct reset_controller_dev *rcdev,
761+
unsigned long id, bool set)
762+
{
763+
struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
764+
unsigned int reg = id / 32;
765+
unsigned int bit = id % 32;
766+
u32 bitmask = BIT(bit);
767+
void __iomem *reg_addr;
768+
unsigned long flags;
769+
unsigned int i;
770+
u32 val;
771+
772+
dev_dbg(priv->dev, "%s %u%02u\n", set ? "assert" : "deassert", reg, bit);
773+
774+
spin_lock_irqsave(&priv->pub.rmw_lock, flags);
775+
776+
reg_addr = priv->pub.base0 + priv->reset_regs[reg];
777+
/* Read current value and modify */
778+
val = readl(reg_addr);
779+
if (set)
780+
val |= bitmask;
781+
else
782+
val &= ~bitmask;
783+
writel(val, reg_addr);
784+
785+
/*
786+
* For secure processing after release from a module reset, one must
787+
* perform multiple dummy reads of the same register.
788+
*/
789+
for (i = 0; !set && i < RZT2H_RESET_REG_READ_COUNT; i++)
790+
readl(reg_addr);
791+
792+
/* Verify the operation */
793+
val = readl(reg_addr);
794+
if (set == !(bitmask & val)) {
795+
dev_err(priv->dev, "Reset register %u%02u operation failed\n", reg, bit);
796+
spin_unlock_irqrestore(&priv->pub.rmw_lock, flags);
797+
return -EIO;
798+
}
799+
800+
spin_unlock_irqrestore(&priv->pub.rmw_lock, flags);
801+
802+
return 0;
803+
}
804+
805+
static int cpg_mrcr_reset(struct reset_controller_dev *rcdev, unsigned long id)
806+
{
807+
int ret;
808+
809+
ret = cpg_mrcr_set_reset_state(rcdev, id, true);
810+
if (ret)
811+
return ret;
812+
813+
return cpg_mrcr_set_reset_state(rcdev, id, false);
814+
}
815+
816+
static int cpg_mrcr_assert(struct reset_controller_dev *rcdev, unsigned long id)
817+
{
818+
return cpg_mrcr_set_reset_state(rcdev, id, true);
819+
}
820+
821+
static int cpg_mrcr_deassert(struct reset_controller_dev *rcdev, unsigned long id)
822+
{
823+
return cpg_mrcr_set_reset_state(rcdev, id, false);
824+
}
825+
742826
static const struct reset_control_ops cpg_mssr_reset_ops = {
743827
.reset = cpg_mssr_reset,
744828
.assert = cpg_mssr_assert,
745829
.deassert = cpg_mssr_deassert,
746830
.status = cpg_mssr_status,
747831
};
748832

833+
static const struct reset_control_ops cpg_mrcr_reset_ops = {
834+
.reset = cpg_mrcr_reset,
835+
.assert = cpg_mrcr_assert,
836+
.deassert = cpg_mrcr_deassert,
837+
.status = cpg_mssr_status,
838+
};
839+
749840
static int cpg_mssr_reset_xlate(struct reset_controller_dev *rcdev,
750841
const struct of_phandle_args *reset_spec)
751842
{
@@ -763,11 +854,23 @@ static int cpg_mssr_reset_xlate(struct reset_controller_dev *rcdev,
763854

764855
static int cpg_mssr_reset_controller_register(struct cpg_mssr_priv *priv)
765856
{
766-
priv->rcdev.ops = &cpg_mssr_reset_ops;
857+
/*
858+
* RZ/T2H (and family) has the Module Reset Control Registers
859+
* which allows control resets of certain modules.
860+
* The number of resets is not equal to the number of module clocks.
861+
*/
862+
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_T2H) {
863+
priv->rcdev.ops = &cpg_mrcr_reset_ops;
864+
priv->rcdev.nr_resets = ARRAY_SIZE(mrcr_for_rzt2h) * 32;
865+
} else {
866+
priv->rcdev.ops = &cpg_mssr_reset_ops;
867+
priv->rcdev.nr_resets = priv->num_mod_clks;
868+
}
869+
767870
priv->rcdev.of_node = priv->dev->of_node;
768871
priv->rcdev.of_reset_n_cells = 1;
769872
priv->rcdev.of_xlate = cpg_mssr_reset_xlate;
770-
priv->rcdev.nr_resets = priv->num_mod_clks;
873+
771874
return devm_reset_controller_register(priv->dev, &priv->rcdev);
772875
}
773876

@@ -1172,6 +1275,7 @@ static int __init cpg_mssr_common_init(struct device *dev,
11721275
priv->control_regs = stbcr;
11731276
} else if (priv->reg_layout == CLK_REG_LAYOUT_RZ_T2H) {
11741277
priv->control_regs = mstpcr_for_rzt2h;
1278+
priv->reset_regs = mrcr_for_rzt2h;
11751279
} else if (priv->reg_layout == CLK_REG_LAYOUT_RCAR_GEN4) {
11761280
priv->status_regs = mstpsr_for_gen4;
11771281
priv->control_regs = mstpcr_for_gen4;
@@ -1268,8 +1372,7 @@ static int __init cpg_mssr_probe(struct platform_device *pdev)
12681372
goto reserve_exit;
12691373

12701374
/* Reset Controller not supported for Standby Control SoCs */
1271-
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A ||
1272-
priv->reg_layout == CLK_REG_LAYOUT_RZ_T2H)
1375+
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
12731376
goto reserve_exit;
12741377

12751378
error = cpg_mssr_reset_controller_register(priv);

0 commit comments

Comments
 (0)