Skip to content

Commit b224c42

Browse files
Tommaso Merciaigeertu
authored andcommitted
clk: renesas: rzv2h: Simplify rzv2h_cpg_assert()/rzv2h_cpg_deassert()
rzv2h_cpg_assert() and rzv2h_cpg_deassert() functions are similar. Share this code via __rzv2h_cpg_assert(). This avoid code duplication. Reported-by: Pavel Machek <[email protected]> Closes: https://lore.kernel.org/cip-dev/[email protected]/ Signed-off-by: Tommaso Merciai <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent ce0a97f commit b224c42

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

drivers/clk/renesas/rzv2h-cpg.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -709,44 +709,40 @@ rzv2h_cpg_register_mod_clk(const struct rzv2h_mod_clk *mod,
709709
mod->name, PTR_ERR(clk));
710710
}
711711

712-
static int rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
713-
unsigned long id)
712+
static int __rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
713+
unsigned long id, bool assert)
714714
{
715715
struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
716716
unsigned int reg = GET_RST_OFFSET(priv->resets[id].reset_index);
717717
u32 mask = BIT(priv->resets[id].reset_bit);
718718
u8 monbit = priv->resets[id].mon_bit;
719719
u32 value = mask << 16;
720720

721-
dev_dbg(rcdev->dev, "assert id:%ld offset:0x%x\n", id, reg);
721+
dev_dbg(rcdev->dev, "%s id:%ld offset:0x%x\n",
722+
assert ? "assert" : "deassert", id, reg);
722723

724+
if (!assert)
725+
value |= mask;
723726
writel(value, priv->base + reg);
724727

725728
reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
726729
mask = BIT(monbit);
727730

728731
return readl_poll_timeout_atomic(priv->base + reg, value,
729-
value & mask, 10, 200);
732+
assert ? (value & mask) : !(value & mask),
733+
10, 200);
734+
}
735+
736+
static int rzv2h_cpg_assert(struct reset_controller_dev *rcdev,
737+
unsigned long id)
738+
{
739+
return __rzv2h_cpg_assert(rcdev, id, true);
730740
}
731741

732742
static int rzv2h_cpg_deassert(struct reset_controller_dev *rcdev,
733743
unsigned long id)
734744
{
735-
struct rzv2h_cpg_priv *priv = rcdev_to_priv(rcdev);
736-
unsigned int reg = GET_RST_OFFSET(priv->resets[id].reset_index);
737-
u32 mask = BIT(priv->resets[id].reset_bit);
738-
u8 monbit = priv->resets[id].mon_bit;
739-
u32 value = (mask << 16) | mask;
740-
741-
dev_dbg(rcdev->dev, "deassert id:%ld offset:0x%x\n", id, reg);
742-
743-
writel(value, priv->base + reg);
744-
745-
reg = GET_RST_MON_OFFSET(priv->resets[id].mon_index);
746-
mask = BIT(monbit);
747-
748-
return readl_poll_timeout_atomic(priv->base + reg, value,
749-
!(value & mask), 10, 200);
745+
return __rzv2h_cpg_assert(rcdev, id, false);
750746
}
751747

752748
static int rzv2h_cpg_reset(struct reset_controller_dev *rcdev,

0 commit comments

Comments
 (0)