From: Marek Vasut Date: Thu, 26 Jan 2023 20:02:03 +0000 (+0100) Subject: clk: renesas: Add and enable CPG reset driver X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=326e05c5e21752f23f1f6090d4c546867211b823;p=u-boot.git clk: renesas: Add and enable CPG reset driver Add trivial reset driver extension to the CPG clock driver. The change turns current CPG UCLASS_CLK driver instance into an UCLASS_NOP proxy driver, which in turn binds both generic rcar3_clk UCLASS_CLK clock driver as well as generic rcar_rst UCLASS_RESET reset driver to the CPG DT node. This way, any other drivers which use the 'reset' DT property can now obtain valid reset handle backed by a reset driver. The clock tables have been updated to represent the CPG driver and only implement the generic CPG proxy driver bind call, which binds the clock and reset drivers. The DM_RESET is now enabled for all R-Car Gen3 platforms. Signed-off-by: Marek Vasut --- diff --git a/arch/arm/mach-rmobile/Kconfig.64 b/arch/arm/mach-rmobile/Kconfig.64 index bf12b21ecf..8e617e5824 100644 --- a/arch/arm/mach-rmobile/Kconfig.64 +++ b/arch/arm/mach-rmobile/Kconfig.64 @@ -201,4 +201,7 @@ config MULTI_DTB_FIT_USER_DEF_ADDR config SYS_MALLOC_F_LEN default 0x8000 if RCAR_GEN3 +config DM_RESET + default y if RCAR_GEN3 + endif diff --git a/drivers/clk/renesas/clk-rcar-gen3.c b/drivers/clk/renesas/clk-rcar-gen3.c index 94715bb00c..3611bdb06f 100644 --- a/drivers/clk/renesas/clk-rcar-gen3.c +++ b/drivers/clk/renesas/clk-rcar-gen3.c @@ -13,12 +13,15 @@ #include #include #include +#include +#include #include #include #include #include #include #include +#include #include @@ -389,7 +392,7 @@ const struct clk_ops gen3_clk_ops = { .of_xlate = gen3_clk_of_xlate, }; -int gen3_clk_probe(struct udevice *dev) +static int gen3_clk_probe(struct udevice *dev) { struct gen3_clk_priv *priv = dev_get_priv(dev); struct cpg_mssr_info *info = @@ -447,9 +450,84 @@ int gen3_clk_probe(struct udevice *dev) return 0; } -int gen3_clk_remove(struct udevice *dev) +static int gen3_clk_remove(struct udevice *dev) { struct gen3_clk_priv *priv = dev_get_priv(dev); return renesas_clk_remove(priv->base, priv->info); } + +U_BOOT_DRIVER(clk_gen3) = { + .name = "clk_gen3", + .id = UCLASS_CLK, + .priv_auto = sizeof(struct gen3_clk_priv), + .ops = &gen3_clk_ops, + .probe = gen3_clk_probe, + .remove = gen3_clk_remove, +}; + +static int gen3_reset_assert(struct reset_ctl *reset_ctl) +{ + struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev); + struct gen3_clk_priv *priv = dev_get_priv(cdev); + unsigned int reg = reset_ctl->id / 32; + unsigned int bit = reset_ctl->id % 32; + u32 bitmask = BIT(bit); + + writel(bitmask, priv->base + priv->info->reset_regs[reg]); + + return 0; +} + +static int gen3_reset_deassert(struct reset_ctl *reset_ctl) +{ + struct udevice *cdev = (struct udevice *)dev_get_driver_data(reset_ctl->dev); + struct gen3_clk_priv *priv = dev_get_priv(cdev); + unsigned int reg = reset_ctl->id / 32; + unsigned int bit = reset_ctl->id % 32; + u32 bitmask = BIT(bit); + + writel(bitmask, priv->base + priv->info->reset_clear_regs[reg]); + + return 0; +} + +static const struct reset_ops rst_gen3_ops = { + .rst_assert = gen3_reset_assert, + .rst_deassert = gen3_reset_deassert, +}; + +U_BOOT_DRIVER(rst_gen3) = { + .name = "rst_gen3", + .id = UCLASS_RESET, + .ops = &rst_gen3_ops, +}; + +int gen3_cpg_bind(struct udevice *parent) +{ + struct cpg_mssr_info *info = + (struct cpg_mssr_info *)dev_get_driver_data(parent); + struct udevice *cdev, *rdev; + struct driver *drv; + int ret; + + drv = lists_driver_lookup_name("clk_gen3"); + if (!drv) + return -ENOENT; + + ret = device_bind_with_driver_data(parent, drv, "clk_gen3", (ulong)info, + dev_ofnode(parent), &cdev); + if (ret) + return ret; + + drv = lists_driver_lookup_name("rst_gen3"); + if (!drv) + return -ENOENT; + + ret = device_bind_with_driver_data(parent, drv, "rst_gen3", (ulong)cdev, + dev_ofnode(parent), &rdev); + if (ret) + device_unbind(cdev); + + return ret; +} diff --git a/drivers/clk/renesas/r8a774a1-cpg-mssr.c b/drivers/clk/renesas/r8a774a1-cpg-mssr.c index 445c58b88a..1f76d6b2c2 100644 --- a/drivers/clk/renesas/r8a774a1-cpg-mssr.c +++ b/drivers/clk/renesas/r8a774a1-cpg-mssr.c @@ -331,7 +331,7 @@ static const struct cpg_mssr_info r8a774a1_cpg_mssr_info = { .get_pll_config = r8a774a1_get_pll_config, }; -static const struct udevice_id r8a774a1_clk_ids[] = { +static const struct udevice_id r8a774a1_cpg_ids[] = { { .compatible = "renesas,r8a774a1-cpg-mssr", .data = (ulong)&r8a774a1_cpg_mssr_info, @@ -339,12 +339,9 @@ static const struct udevice_id r8a774a1_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a774a1) = { - .name = "clk_r8a774a1", - .id = UCLASS_CLK, - .of_match = r8a774a1_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a774a1) = { + .name = "cpg_r8a774a1", + .id = UCLASS_NOP, + .of_match = r8a774a1_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a774b1-cpg-mssr.c b/drivers/clk/renesas/r8a774b1-cpg-mssr.c index a09f11d433..b5927c7892 100644 --- a/drivers/clk/renesas/r8a774b1-cpg-mssr.c +++ b/drivers/clk/renesas/r8a774b1-cpg-mssr.c @@ -329,7 +329,7 @@ static const struct cpg_mssr_info r8a774b1_cpg_mssr_info = { .get_pll_config = r8a774b1_get_pll_config, }; -static const struct udevice_id r8a774b1_clk_ids[] = { +static const struct udevice_id r8a774b1_cpg_ids[] = { { .compatible = "renesas,r8a774b1-cpg-mssr", .data = (ulong)&r8a774b1_cpg_mssr_info, @@ -337,12 +337,9 @@ static const struct udevice_id r8a774b1_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a774b1) = { - .name = "clk_r8a774b1", - .id = UCLASS_CLK, - .of_match = r8a774b1_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a774b1) = { + .name = "cpg_r8a774b1", + .id = UCLASS_NOP, + .of_match = r8a774b1_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a774c0-cpg-mssr.c b/drivers/clk/renesas/r8a774c0-cpg-mssr.c index f2dce5d885..802a9c0b11 100644 --- a/drivers/clk/renesas/r8a774c0-cpg-mssr.c +++ b/drivers/clk/renesas/r8a774c0-cpg-mssr.c @@ -300,7 +300,7 @@ const struct cpg_mssr_info r8a774c0_cpg_mssr_info = { .get_pll_config = r8a774c0_get_pll_config, }; -static const struct udevice_id r8a774c0_clk_ids[] = { +static const struct udevice_id r8a774c0_cpg_ids[] = { { .compatible = "renesas,r8a774c0-cpg-mssr", .data = (ulong)&r8a774c0_cpg_mssr_info @@ -308,12 +308,9 @@ static const struct udevice_id r8a774c0_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a774c0) = { - .name = "clk_r8a774c0", - .id = UCLASS_CLK, - .of_match = r8a774c0_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a774c0) = { + .name = "cpg_r8a774c0", + .id = UCLASS_NOP, + .of_match = r8a774c0_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a774e1-cpg-mssr.c b/drivers/clk/renesas/r8a774e1-cpg-mssr.c index ab44dbdeeb..617fa769dc 100644 --- a/drivers/clk/renesas/r8a774e1-cpg-mssr.c +++ b/drivers/clk/renesas/r8a774e1-cpg-mssr.c @@ -343,7 +343,7 @@ static const struct cpg_mssr_info r8a774e1_cpg_mssr_info = { .get_pll_config = r8a774e1_get_pll_config, }; -static const struct udevice_id r8a774e1_clk_ids[] = { +static const struct udevice_id r8a774e1_cpg_ids[] = { { .compatible = "renesas,r8a774e1-cpg-mssr", .data = (ulong)&r8a774e1_cpg_mssr_info @@ -351,12 +351,9 @@ static const struct udevice_id r8a774e1_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a774e1) = { - .name = "clk_r8a774e1", - .id = UCLASS_CLK, - .of_match = r8a774e1_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a774e1) = { + .name = "cpg_r8a774e1", + .id = UCLASS_NOP, + .of_match = r8a774e1_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a7795-cpg-mssr.c b/drivers/clk/renesas/r8a7795-cpg-mssr.c index 31cd24ec12..005f6a9ecd 100644 --- a/drivers/clk/renesas/r8a7795-cpg-mssr.c +++ b/drivers/clk/renesas/r8a7795-cpg-mssr.c @@ -380,7 +380,7 @@ static const struct cpg_mssr_info r8a7795_cpg_mssr_info = { .get_pll_config = r8a7795_get_pll_config, }; -static const struct udevice_id r8a7795_clk_ids[] = { +static const struct udevice_id r8a7795_cpg_ids[] = { { .compatible = "renesas,r8a7795-cpg-mssr", .data = (ulong)&r8a7795_cpg_mssr_info @@ -388,12 +388,9 @@ static const struct udevice_id r8a7795_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a7795) = { - .name = "clk_r8a7795", - .id = UCLASS_CLK, - .of_match = r8a7795_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a7795) = { + .name = "cpg_r8a7795", + .id = UCLASS_NOP, + .of_match = r8a7795_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a7796-cpg-mssr.c b/drivers/clk/renesas/r8a7796-cpg-mssr.c index a3fee15851..27cf62e021 100644 --- a/drivers/clk/renesas/r8a7796-cpg-mssr.c +++ b/drivers/clk/renesas/r8a7796-cpg-mssr.c @@ -370,7 +370,7 @@ static const struct cpg_mssr_info r8a77961_cpg_mssr_info = { .get_pll_config = r8a7796_get_pll_config, }; -static const struct udevice_id r8a7796_clk_ids[] = { +static const struct udevice_id r8a7796_cpg_ids[] = { { .compatible = "renesas,r8a7796-cpg-mssr", .data = (ulong)&r8a7796_cpg_mssr_info, @@ -382,12 +382,9 @@ static const struct udevice_id r8a7796_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a7796) = { - .name = "clk_r8a7796", - .id = UCLASS_CLK, - .of_match = r8a7796_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a7796) = { + .name = "cpg_r8a7796", + .id = UCLASS_NOP, + .of_match = r8a7796_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a77965-cpg-mssr.c b/drivers/clk/renesas/r8a77965-cpg-mssr.c index cd3bda9a39..58e557a95f 100644 --- a/drivers/clk/renesas/r8a77965-cpg-mssr.c +++ b/drivers/clk/renesas/r8a77965-cpg-mssr.c @@ -358,7 +358,7 @@ static const struct cpg_mssr_info r8a77965_cpg_mssr_info = { .get_pll_config = r8a77965_get_pll_config, }; -static const struct udevice_id r8a77965_clk_ids[] = { +static const struct udevice_id r8a77965_cpg_ids[] = { { .compatible = "renesas,r8a77965-cpg-mssr", .data = (ulong)&r8a77965_cpg_mssr_info, @@ -366,12 +366,9 @@ static const struct udevice_id r8a77965_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a77965) = { - .name = "clk_r8a77965", - .id = UCLASS_CLK, - .of_match = r8a77965_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a77965) = { + .name = "cpg_r8a77965", + .id = UCLASS_NOP, + .of_match = r8a77965_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a77970-cpg-mssr.c b/drivers/clk/renesas/r8a77970-cpg-mssr.c index a85bed6192..4d72ec1fae 100644 --- a/drivers/clk/renesas/r8a77970-cpg-mssr.c +++ b/drivers/clk/renesas/r8a77970-cpg-mssr.c @@ -219,7 +219,7 @@ static const struct cpg_mssr_info r8a77970_cpg_mssr_info = { .get_pll_config = r8a77970_get_pll_config, }; -static const struct udevice_id r8a77970_clk_ids[] = { +static const struct udevice_id r8a77970_cpg_ids[] = { { .compatible = "renesas,r8a77970-cpg-mssr", .data = (ulong)&r8a77970_cpg_mssr_info @@ -227,12 +227,9 @@ static const struct udevice_id r8a77970_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a77970) = { - .name = "clk_r8a77970", - .id = UCLASS_CLK, - .of_match = r8a77970_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a77970) = { + .name = "cpg_r8a77970", + .id = UCLASS_NOP, + .of_match = r8a77970_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a77980-cpg-mssr.c b/drivers/clk/renesas/r8a77980-cpg-mssr.c index 1f29e77da9..f29727ddb9 100644 --- a/drivers/clk/renesas/r8a77980-cpg-mssr.c +++ b/drivers/clk/renesas/r8a77980-cpg-mssr.c @@ -239,7 +239,7 @@ static const struct cpg_mssr_info r8a77980_cpg_mssr_info = { .get_pll_config = r8a77980_get_pll_config, }; -static const struct udevice_id r8a77980_clk_ids[] = { +static const struct udevice_id r8a77980_cpg_ids[] = { { .compatible = "renesas,r8a77980-cpg-mssr", .data = (ulong)&r8a77980_cpg_mssr_info @@ -247,12 +247,9 @@ static const struct udevice_id r8a77980_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a77980) = { - .name = "clk_r8a77980", - .id = UCLASS_CLK, - .of_match = r8a77980_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a77980) = { + .name = "cpg_r8a77980", + .id = UCLASS_NOP, + .of_match = r8a77980_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a77990-cpg-mssr.c b/drivers/clk/renesas/r8a77990-cpg-mssr.c index 4d9b78ebab..1864af30c8 100644 --- a/drivers/clk/renesas/r8a77990-cpg-mssr.c +++ b/drivers/clk/renesas/r8a77990-cpg-mssr.c @@ -314,7 +314,7 @@ static const struct cpg_mssr_info r8a77990_cpg_mssr_info = { .get_pll_config = r8a77990_get_pll_config, }; -static const struct udevice_id r8a77990_clk_ids[] = { +static const struct udevice_id r8a77990_cpg_ids[] = { { .compatible = "renesas,r8a77990-cpg-mssr", .data = (ulong)&r8a77990_cpg_mssr_info @@ -322,12 +322,9 @@ static const struct udevice_id r8a77990_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a77990) = { - .name = "clk_r8a77990", - .id = UCLASS_CLK, - .of_match = r8a77990_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a77990) = { + .name = "cpg_r8a77990", + .id = UCLASS_NOP, + .of_match = r8a77990_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a77995-cpg-mssr.c b/drivers/clk/renesas/r8a77995-cpg-mssr.c index ee4061f9d8..03ae863c8b 100644 --- a/drivers/clk/renesas/r8a77995-cpg-mssr.c +++ b/drivers/clk/renesas/r8a77995-cpg-mssr.c @@ -250,7 +250,7 @@ static const struct cpg_mssr_info r8a77995_cpg_mssr_info = { .get_pll_config = r8a77995_get_pll_config, }; -static const struct udevice_id r8a77995_clk_ids[] = { +static const struct udevice_id r8a77995_cpg_ids[] = { { .compatible = "renesas,r8a77995-cpg-mssr", .data = (ulong)&r8a77995_cpg_mssr_info @@ -258,12 +258,9 @@ static const struct udevice_id r8a77995_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a77995) = { - .name = "clk_r8a77995", - .id = UCLASS_CLK, - .of_match = r8a77995_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a77995) = { + .name = "cpg_r8a77995", + .id = UCLASS_NOP, + .of_match = r8a77995_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/r8a779a0-cpg-mssr.c b/drivers/clk/renesas/r8a779a0-cpg-mssr.c index 0c28477377..a9c941b6db 100644 --- a/drivers/clk/renesas/r8a779a0-cpg-mssr.c +++ b/drivers/clk/renesas/r8a779a0-cpg-mssr.c @@ -301,7 +301,7 @@ static const struct cpg_mssr_info r8a779a0_cpg_mssr_info = { .reg_layout = CLK_REG_LAYOUT_RCAR_V3U, }; -static const struct udevice_id r8a779a0_clk_ids[] = { +static const struct udevice_id r8a779a0_cpg_ids[] = { { .compatible = "renesas,r8a779a0-cpg-mssr", .data = (ulong)&r8a779a0_cpg_mssr_info @@ -309,12 +309,9 @@ static const struct udevice_id r8a779a0_clk_ids[] = { { } }; -U_BOOT_DRIVER(clk_r8a779a0) = { - .name = "clk_r8a779a0", - .id = UCLASS_CLK, - .of_match = r8a779a0_clk_ids, - .priv_auto = sizeof(struct gen3_clk_priv), - .ops = &gen3_clk_ops, - .probe = gen3_clk_probe, - .remove = gen3_clk_remove, +U_BOOT_DRIVER(cpg_r8a779a0) = { + .name = "cpg_r8a779a0", + .id = UCLASS_NOP, + .of_match = r8a779a0_cpg_ids, + .bind = gen3_cpg_bind, }; diff --git a/drivers/clk/renesas/rcar-gen3-cpg.h b/drivers/clk/renesas/rcar-gen3-cpg.h index 85bfc7233b..a7074e2bcd 100644 --- a/drivers/clk/renesas/rcar-gen3-cpg.h +++ b/drivers/clk/renesas/rcar-gen3-cpg.h @@ -126,8 +126,7 @@ struct gen3_clk_priv { const struct rcar_gen3_cpg_pll_config *cpg_pll_config; }; -int gen3_clk_probe(struct udevice *dev); -int gen3_clk_remove(struct udevice *dev); +int gen3_cpg_bind(struct udevice *parent); extern const struct clk_ops gen3_clk_ops;