1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Amarula Solutions.
4 * Author: Jagan Teki <jagan@amarulasolutions.com>
8 #include <clk-uclass.h>
13 #include <asm/arch/ccu.h>
14 #include <linux/log2.h>
16 static const struct ccu_clk_gate *priv_to_gate(struct ccu_priv *priv,
19 return &priv->desc->gates[id];
22 static int sunxi_set_gate(struct clk *clk, bool on)
24 struct ccu_priv *priv = dev_get_priv(clk->dev);
25 const struct ccu_clk_gate *gate = priv_to_gate(priv, clk->id);
28 if (!(gate->flags & CCU_CLK_F_IS_VALID)) {
29 printf("%s: (CLK#%ld) unhandled\n", __func__, clk->id);
33 debug("%s: (CLK#%ld) off#0x%x, BIT(%d)\n", __func__,
34 clk->id, gate->off, ilog2(gate->bit));
36 reg = readl(priv->base + gate->off);
42 writel(reg, priv->base + gate->off);
47 static int sunxi_clk_enable(struct clk *clk)
49 return sunxi_set_gate(clk, true);
52 static int sunxi_clk_disable(struct clk *clk)
54 return sunxi_set_gate(clk, false);
57 struct clk_ops sunxi_clk_ops = {
58 .enable = sunxi_clk_enable,
59 .disable = sunxi_clk_disable,
62 int sunxi_clk_probe(struct udevice *dev)
64 struct ccu_priv *priv = dev_get_priv(dev);
65 struct clk_bulk clk_bulk;
66 struct reset_ctl_bulk rst_bulk;
69 priv->base = dev_read_addr_ptr(dev);
73 priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev);
77 ret = clk_get_bulk(dev, &clk_bulk);
79 clk_enable_bulk(&clk_bulk);
81 ret = reset_get_bulk(dev, &rst_bulk);
83 reset_deassert_bulk(&rst_bulk);