Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Lad Prabhakar and committed by
Geert Uytterhoeven
3b37979d 0f537c41

+107 -4
+107 -4
drivers/clk/renesas/renesas-cpg-mssr.c
··· 40 40 #define WARN_DEBUG(x) do { } while (0) 41 41 #endif 42 42 43 + #define RZT2H_RESET_REG_READ_COUNT 7 44 + 43 45 /* 44 46 * Module Standby and Software Reset register offets. 45 47 * ··· 137 135 0x2C20, 0x2C24, 0x2C28, 0x2C2C, 0x2C30, 0x2C34, 0x2C38, 0x2C3C, 138 136 0x2C40, 0x2C44, 0x2C48, 0x2C4C, 0x2C50, 0x2C54, 0x2C58, 0x2C5C, 139 137 0x2C60, 0x2C64, 0x2C68, 0x2C6C, 0x2C70, 0x2C74, 138 + }; 139 + 140 + static const u16 mrcr_for_rzt2h[] = { 141 + 0x240, /* MRCTLA */ 142 + 0x244, /* Reserved */ 143 + 0x248, /* Reserved */ 144 + 0x24C, /* Reserved */ 145 + 0x250, /* MRCTLE */ 146 + 0x254, /* Reserved */ 147 + 0x258, /* Reserved */ 148 + 0x25C, /* Reserved */ 149 + 0x260, /* MRCTLI */ 150 + 0x264, /* Reserved */ 151 + 0x268, /* Reserved */ 152 + 0x26C, /* Reserved */ 153 + 0x270, /* MRCTLM */ 140 154 }; 141 155 142 156 /* ··· 757 739 return !!(readl(priv->pub.base0 + priv->reset_regs[reg]) & bitmask); 758 740 } 759 741 742 + static int cpg_mrcr_set_reset_state(struct reset_controller_dev *rcdev, 743 + unsigned long id, bool set) 744 + { 745 + struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev); 746 + unsigned int reg = id / 32; 747 + unsigned int bit = id % 32; 748 + u32 bitmask = BIT(bit); 749 + void __iomem *reg_addr; 750 + unsigned long flags; 751 + unsigned int i; 752 + u32 val; 753 + 754 + dev_dbg(priv->dev, "%s %u%02u\n", set ? "assert" : "deassert", reg, bit); 755 + 756 + spin_lock_irqsave(&priv->pub.rmw_lock, flags); 757 + 758 + reg_addr = priv->pub.base0 + priv->reset_regs[reg]; 759 + /* Read current value and modify */ 760 + val = readl(reg_addr); 761 + if (set) 762 + val |= bitmask; 763 + else 764 + val &= ~bitmask; 765 + writel(val, reg_addr); 766 + 767 + /* 768 + * For secure processing after release from a module reset, one must 769 + * perform multiple dummy reads of the same register. 770 + */ 771 + for (i = 0; !set && i < RZT2H_RESET_REG_READ_COUNT; i++) 772 + readl(reg_addr); 773 + 774 + /* Verify the operation */ 775 + val = readl(reg_addr); 776 + if (set == !(bitmask & val)) { 777 + dev_err(priv->dev, "Reset register %u%02u operation failed\n", reg, bit); 778 + spin_unlock_irqrestore(&priv->pub.rmw_lock, flags); 779 + return -EIO; 780 + } 781 + 782 + spin_unlock_irqrestore(&priv->pub.rmw_lock, flags); 783 + 784 + return 0; 785 + } 786 + 787 + static int cpg_mrcr_reset(struct reset_controller_dev *rcdev, unsigned long id) 788 + { 789 + int ret; 790 + 791 + ret = cpg_mrcr_set_reset_state(rcdev, id, true); 792 + if (ret) 793 + return ret; 794 + 795 + return cpg_mrcr_set_reset_state(rcdev, id, false); 796 + } 797 + 798 + static int cpg_mrcr_assert(struct reset_controller_dev *rcdev, unsigned long id) 799 + { 800 + return cpg_mrcr_set_reset_state(rcdev, id, true); 801 + } 802 + 803 + static int cpg_mrcr_deassert(struct reset_controller_dev *rcdev, unsigned long id) 804 + { 805 + return cpg_mrcr_set_reset_state(rcdev, id, false); 806 + } 807 + 760 808 static const struct reset_control_ops cpg_mssr_reset_ops = { 761 809 .reset = cpg_mssr_reset, 762 810 .assert = cpg_mssr_assert, 763 811 .deassert = cpg_mssr_deassert, 812 + .status = cpg_mssr_status, 813 + }; 814 + 815 + static const struct reset_control_ops cpg_mrcr_reset_ops = { 816 + .reset = cpg_mrcr_reset, 817 + .assert = cpg_mrcr_assert, 818 + .deassert = cpg_mrcr_deassert, 764 819 .status = cpg_mssr_status, 765 820 }; 766 821 ··· 854 763 855 764 static int cpg_mssr_reset_controller_register(struct cpg_mssr_priv *priv) 856 765 { 857 - priv->rcdev.ops = &cpg_mssr_reset_ops; 766 + /* 767 + * RZ/T2H (and family) has the Module Reset Control Registers 768 + * which allows control resets of certain modules. 769 + * The number of resets is not equal to the number of module clocks. 770 + */ 771 + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_T2H) { 772 + priv->rcdev.ops = &cpg_mrcr_reset_ops; 773 + priv->rcdev.nr_resets = ARRAY_SIZE(mrcr_for_rzt2h) * 32; 774 + } else { 775 + priv->rcdev.ops = &cpg_mssr_reset_ops; 776 + priv->rcdev.nr_resets = priv->num_mod_clks; 777 + } 778 + 858 779 priv->rcdev.of_node = priv->dev->of_node; 859 780 priv->rcdev.of_reset_n_cells = 1; 860 781 priv->rcdev.of_xlate = cpg_mssr_reset_xlate; 861 - priv->rcdev.nr_resets = priv->num_mod_clks; 782 + 862 783 return devm_reset_controller_register(priv->dev, &priv->rcdev); 863 784 } 864 785 ··· 1275 1172 priv->control_regs = stbcr; 1276 1173 } else if (priv->reg_layout == CLK_REG_LAYOUT_RZ_T2H) { 1277 1174 priv->control_regs = mstpcr_for_rzt2h; 1175 + priv->reset_regs = mrcr_for_rzt2h; 1278 1176 } else if (priv->reg_layout == CLK_REG_LAYOUT_RCAR_GEN4) { 1279 1177 priv->status_regs = mstpsr_for_gen4; 1280 1178 priv->control_regs = mstpcr_for_gen4; ··· 1372 1268 goto reserve_exit; 1373 1269 1374 1270 /* Reset Controller not supported for Standby Control SoCs */ 1375 - if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A || 1376 - priv->reg_layout == CLK_REG_LAYOUT_RZ_T2H) 1271 + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) 1377 1272 goto reserve_exit; 1378 1273 1379 1274 error = cpg_mssr_reset_controller_register(priv);