clk: mediatek: reset: Support nonsequence base offsets of reset registers
authorRex-BC Chen <rex-bc.chen@mediatek.com>
Mon, 23 May 2022 09:33:34 +0000 (17:33 +0800)
committerStephen Boyd <sboyd@kernel.org>
Thu, 16 Jun 2022 00:24:12 +0000 (17:24 -0700)
The bank offsets are not serial for all reset registers.
For example, there are five infra reset banks for MT8192: 0x120, 0x130,
0x140, 0x150 and 0x730.

To support this,
- Change reg_ofs to rst_bank_ofs which is a pointer to base offsets of
  the reset register.
- Add a new define RST_NR_PER_BANK to define reset number for each
  reset bank.

Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Tested-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
Link: https://lore.kernel.org/r/20220523093346.28493-8-rex-bc.chen@mediatek.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
15 files changed:
drivers/clk/mediatek/clk-mt2701-eth.c
drivers/clk/mediatek/clk-mt2701-g3d.c
drivers/clk/mediatek/clk-mt2701-hif.c
drivers/clk/mediatek/clk-mt2701.c
drivers/clk/mediatek/clk-mt2712.c
drivers/clk/mediatek/clk-mt7622-eth.c
drivers/clk/mediatek/clk-mt7622-hif.c
drivers/clk/mediatek/clk-mt7622.c
drivers/clk/mediatek/clk-mt7629-eth.c
drivers/clk/mediatek/clk-mt7629-hif.c
drivers/clk/mediatek/clk-mt8135.c
drivers/clk/mediatek/clk-mt8173.c
drivers/clk/mediatek/clk-mt8183.c
drivers/clk/mediatek/reset.c
drivers/clk/mediatek/reset.h

index 270d15ce58bfd0fe962bef8f3bae343e8562cd4c..b4e7f38860d0c33b7df52c16442e33551d1cd48b 100644 (file)
@@ -36,10 +36,12 @@ static const struct mtk_gate eth_clks[] = {
        GATE_ETH(CLK_ETHSYS_CRYPTO, "crypto_clk", "ethif_sel", 29),
 };
 
+static u16 rst_ofs[] = { 0x34, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0x34,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static const struct of_device_id of_match_clk_mt2701_eth[] = {
index 9cfd589939e5c93e67358dec38039fb09aa56aef..1431fa76a0f8510f78bb783e19e8def2f4c0d0c0 100644 (file)
@@ -35,10 +35,12 @@ static const struct mtk_gate g3d_clks[] = {
        GATE_G3D(CLK_G3DSYS_CORE, "g3d_core", "mfg_sel", 0),
 };
 
+static u16 rst_ofs[] = { 0xc, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0xc,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static int clk_mt2701_g3dsys_init(struct platform_device *pdev)
index a6b812fcc9222e81a4008377ecc72f158d7ef0cc..60bda56a102cccbb124dad9c4e313d500b47e795 100644 (file)
@@ -33,10 +33,12 @@ static const struct mtk_gate hif_clks[] = {
        GATE_HIF(CLK_HIFSYS_PCIE2, "pcie2_clk", "ethpll_500m_ck", 26),
 };
 
+static u16 rst_ofs[] = { 0x34, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0x34,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static const struct of_device_id of_match_clk_mt2701_hif[] = {
index f165126232d300fd0fcba9884191f250b0fc24ae..6c7a80fb43491946cbb0913d35179dab68a4e9aa 100644 (file)
@@ -735,18 +735,21 @@ static const struct mtk_fixed_factor infra_fixed_divs[] = {
        FACTOR(CLK_INFRA_CLK_13M, "clk13m", "clk26m", 1, 2),
 };
 
+static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
+static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc[] = {
        /* infrasys */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x30,
+               .rst_bank_ofs = infrasys_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
        },
        /* pericfg */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x0,
+               .rst_bank_ofs = pericfg_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
        },
 };
 
index c7a8aafd44cc159c6e724e4eac2218e1257a3793..fd310c375fdf26eae969bb1544ed64dd0227d843 100644 (file)
@@ -1258,18 +1258,21 @@ static const struct mtk_pll_data plls[] = {
                0, 31, 0x0300, 4, 0, 0, 0, 0x0304, 0),
 };
 
+static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
+static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc[] = {
        /* infra */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x30,
+               .rst_bank_ofs = infrasys_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
        },
        /* peri */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x0,
+               .rst_bank_ofs = pericfg_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
        },
 };
 
index 40eefed3d12bbecf8191df7158b6a7df56bfde7b..90d55f88221545ee3aba7c70cca4430dd1ece578 100644 (file)
@@ -65,10 +65,12 @@ static const struct mtk_gate sgmii_clks[] = {
                   "ssusb_cdr_fb", 5),
 };
 
+static u16 rst_ofs[] = { 0x34, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0x34,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static int clk_mt7622_ethsys_init(struct platform_device *pdev)
index ca29d93ce2d080d7f52564539d76346912fdff24..489b64725b22d353514024ac0a7c6fc83832c253 100644 (file)
@@ -76,10 +76,12 @@ static const struct mtk_gate pcie_clks[] = {
        GATE_PCIE(CLK_SATA_PM_EN, "sata_pm_en", "univpll2_d4", 30),
 };
 
+static u16 rst_ofs[] = { 0x34, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0x34,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static int clk_mt7622_ssusbsys_init(struct platform_device *pdev)
index 115db564a6d4f662b66cd1c01abfa218b8de1729..0cba74d384996085f7d05e9553fd1e0b03b65ade 100644 (file)
@@ -610,18 +610,21 @@ static struct mtk_composite peri_muxes[] = {
        MUX(CLK_PERIBUS_SEL, "peribus_ck_sel", peribus_ck_parents, 0x05C, 0, 1),
 };
 
+static u16 infrasys_rst_ofs[] = { 0x30, };
+static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc[] = {
        /* infrasys */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 1,
-               .reg_ofs = 0x30,
+               .rst_bank_ofs = infrasys_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
        },
        /* pericfg */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x0,
+               .rst_bank_ofs = pericfg_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
        },
 };
 
index c20c7853500d2d35abb3132a5954f069af5082bc..11b346c9d916d66aed4fc9d1b1f5ebfe1d440c4f 100644 (file)
@@ -76,10 +76,12 @@ static const struct mtk_gate sgmii_clks[2][4] = {
        }
 };
 
+static u16 rst_ofs[] = { 0x34, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0x34,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static int clk_mt7629_ethsys_init(struct platform_device *pdev)
index 5d7ec861afab7cfeef7a8fd1b75b529ae61b65dc..c0583043710fd9e5c4e07dd94ef5bba31cf23f99 100644 (file)
@@ -71,10 +71,12 @@ static const struct mtk_gate pcie_clks[] = {
        GATE_PCIE(CLK_PCIE_P0_PIPE_EN, "pcie_p0_pipe_en", "pcie0_pipe_en", 23),
 };
 
+static u16 rst_ofs[] = { 0x34, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SIMPLE,
-       .rst_bank_nr = 1,
-       .reg_ofs = 0x34,
+       .rst_bank_ofs = rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(rst_ofs),
 };
 
 static int clk_mt7629_ssusbsys_init(struct platform_device *pdev)
index f554574b25670b719589c64b84ce47d566ff148f..b68888a034c40924e32be9a713dbc7fb7e323fe9 100644 (file)
@@ -514,18 +514,21 @@ static const struct mtk_composite peri_clks[] __initconst = {
        MUX(CLK_PERI_UART3_SEL, "uart3_ck_sel", uart_ck_sel_parents, 0x40c, 3, 1),
 };
 
+static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
+static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc[] = {
        /* infrasys */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x30,
+               .rst_bank_ofs = infrasys_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
        },
        /* pericfg */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x0,
+               .rst_bank_ofs = pericfg_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
        }
 };
 
index 1e86210e9c66f9c4b7e1d99f19d5e91a4c981a92..b8529ee7199dad75afe289b970478ef8ce475f93 100644 (file)
@@ -819,18 +819,21 @@ static const struct mtk_gate venclt_clks[] __initconst = {
        GATE_VENCLT(CLK_VENCLT_CKE1, "venclt_cke1", "venclt_sel", 4),
 };
 
+static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
+static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
+
 static const struct mtk_clk_rst_desc clk_rst_desc[] = {
        /* infrasys */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x30,
+               .rst_bank_ofs = infrasys_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
        },
        /* pericfg */
        {
                .version = MTK_RST_SIMPLE,
-               .rst_bank_nr = 2,
-               .reg_ofs = 0x0,
+               .rst_bank_ofs = pericfg_rst_ofs,
+               .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
        }
 };
 
index 5708c5d8b3003a73b6b953ae43d6fa139279e31c..5bc738f4d0e76d50221b0fe23178b676befe6310 100644 (file)
@@ -20,6 +20,9 @@
 
 /* Infra global controller reset set register */
 #define INFRA_RST0_SET_OFFSET          0x120
+#define INFRA_RST1_SET_OFFSET          0x130
+#define INFRA_RST2_SET_OFFSET          0x140
+#define INFRA_RST3_SET_OFFSET          0x150
 
 static DEFINE_SPINLOCK(mt8183_clk_lock);
 
@@ -1153,10 +1156,17 @@ static const struct mtk_pll_data plls[] = {
                0, 0, 32, 8, 0x02B4, 1, 0x02BC, 0x0014, 1, 0x02B8, 0, 0x02B4),
 };
 
+static u16 infra_rst_ofs[] = {
+       INFRA_RST0_SET_OFFSET,
+       INFRA_RST1_SET_OFFSET,
+       INFRA_RST2_SET_OFFSET,
+       INFRA_RST3_SET_OFFSET,
+};
+
 static const struct mtk_clk_rst_desc clk_rst_desc = {
        .version = MTK_RST_SET_CLR,
-       .rst_bank_nr = 4,
-       .reg_ofs = INFRA_RST0_SET_OFFSET,
+       .rst_bank_ofs = infra_rst_ofs,
+       .rst_bank_nr = ARRAY_SIZE(infra_rst_ofs),
 };
 
 static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
index 47bc6b1842fd5c97d0515302b67b6e9e6ccc2847..11b2f74f121d90c4610b5b6a69234d8e5264767e 100644 (file)
@@ -24,8 +24,8 @@ static int mtk_reset_update(struct reset_controller_dev *rcdev,
        unsigned int val = deassert ? 0 : ~0;
 
        return regmap_update_bits(data->regmap,
-                                 data->desc->reg_ofs + ((id / 32) << 2),
-                                 BIT(id % 32), val);
+                                 data->desc->rst_bank_ofs[id / RST_NR_PER_BANK],
+                                 BIT(id % RST_NR_PER_BANK), val);
 }
 
 static int mtk_reset_assert(struct reset_controller_dev *rcdev,
@@ -58,8 +58,9 @@ static int mtk_reset_update_set_clr(struct reset_controller_dev *rcdev,
        unsigned int deassert_ofs = deassert ? 0x4 : 0;
 
        return regmap_write(data->regmap,
-                           data->desc->reg_ofs + ((id / 32) << 4) + deassert_ofs,
-                           BIT(id % 32));
+                           data->desc->rst_bank_ofs[id / RST_NR_PER_BANK] +
+                           deassert_ofs,
+                           BIT(id % RST_NR_PER_BANK));
 }
 
 static int mtk_reset_assert_set_clr(struct reset_controller_dev *rcdev,
@@ -135,7 +136,7 @@ void mtk_register_reset_controller(struct device_node *np,
        data->desc = desc;
        data->regmap = regmap;
        data->rcdev.owner = THIS_MODULE;
-       data->rcdev.nr_resets = desc->rst_bank_nr * 32;
+       data->rcdev.nr_resets = desc->rst_bank_nr * RST_NR_PER_BANK;
        data->rcdev.ops = rcops;
        data->rcdev.of_node = np;
 
index b4c2b468da4ae569fe5a6cc5cf43861f18258e52..d991510ae2d86f4cc256db1f2b812bdb58698e84 100644 (file)
@@ -9,6 +9,8 @@
 #include <linux/reset-controller.h>
 #include <linux/types.h>
 
+#define RST_NR_PER_BANK 32
+
 /**
  * enum mtk_reset_version - Version of MediaTek clock reset controller.
  * @MTK_RST_SIMPLE: Use the same registers for bit set and clear.
@@ -24,12 +26,12 @@ enum mtk_reset_version {
 /**
  * struct mtk_clk_rst_desc - Description of MediaTek clock reset.
  * @version: Reset version which is defined in enum mtk_reset_version.
- * @reg_ofs: Base offset of the reset register.
+ * @rst_bank_ofs: Pointer to an array containing base offsets of the reset register.
  * @rst_bank_nr: Quantity of reset bank.
  */
 struct mtk_clk_rst_desc {
        enum mtk_reset_version version;
-       u16 reg_ofs;
+       u16 *rst_bank_ofs;
        u32 rst_bank_nr;
 };