1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
3 * Copyright (C) 2018 Amarula Solutions.
4 * Author: Jagan Teki <jagan@amarulasolutions.com>
12 #include <reset-uclass.h>
14 #include <clk/sunxi.h>
15 #include <linux/bitops.h>
16 #include <linux/log2.h>
18 static const struct ccu_reset *plat_to_reset(struct ccu_plat *plat,
21 return &plat->desc->resets[id];
24 static int sunxi_reset_request(struct reset_ctl *reset_ctl)
26 struct ccu_plat *plat = dev_get_plat(reset_ctl->dev);
28 debug("%s: (RST#%ld)\n", __func__, reset_ctl->id);
30 if (reset_ctl->id >= plat->desc->num_resets)
36 static int sunxi_set_reset(struct reset_ctl *reset_ctl, bool on)
38 struct ccu_plat *plat = dev_get_plat(reset_ctl->dev);
39 const struct ccu_reset *reset = plat_to_reset(plat, reset_ctl->id);
42 if (!(reset->flags & CCU_RST_F_IS_VALID)) {
43 printf("%s: (RST#%ld) unhandled\n", __func__, reset_ctl->id);
47 debug("%s: (RST#%ld) off#0x%x, BIT(%d)\n", __func__,
48 reset_ctl->id, reset->off, ilog2(reset->bit));
50 reg = readl(plat->base + reset->off);
56 writel(reg, plat->base + reset->off);
61 static int sunxi_reset_assert(struct reset_ctl *reset_ctl)
63 return sunxi_set_reset(reset_ctl, false);
66 static int sunxi_reset_deassert(struct reset_ctl *reset_ctl)
68 return sunxi_set_reset(reset_ctl, true);
71 struct reset_ops sunxi_reset_ops = {
72 .request = sunxi_reset_request,
73 .rst_assert = sunxi_reset_assert,
74 .rst_deassert = sunxi_reset_deassert,
77 U_BOOT_DRIVER(sunxi_reset) = {
78 .name = "sunxi_reset",
80 .ops = &sunxi_reset_ops,