1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2015 Google, Inc
7 #include <clk-uclass.h>
12 struct sandbox_clk_priv {
13 ulong rate[SANDBOX_CLK_ID_COUNT];
14 bool enabled[SANDBOX_CLK_ID_COUNT];
17 static ulong sandbox_clk_get_rate(struct clk *clk)
19 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
21 if (clk->id >= SANDBOX_CLK_ID_COUNT)
24 return priv->rate[clk->id];
27 static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
29 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
32 if (clk->id >= SANDBOX_CLK_ID_COUNT)
38 old_rate = priv->rate[clk->id];
39 priv->rate[clk->id] = rate;
44 static int sandbox_clk_enable(struct clk *clk)
46 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
48 if (clk->id >= SANDBOX_CLK_ID_COUNT)
51 priv->enabled[clk->id] = true;
56 static int sandbox_clk_disable(struct clk *clk)
58 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
60 if (clk->id >= SANDBOX_CLK_ID_COUNT)
63 priv->enabled[clk->id] = false;
68 static struct clk_ops sandbox_clk_ops = {
69 .get_rate = sandbox_clk_get_rate,
70 .set_rate = sandbox_clk_set_rate,
71 .enable = sandbox_clk_enable,
72 .disable = sandbox_clk_disable,
75 static const struct udevice_id sandbox_clk_ids[] = {
76 { .compatible = "sandbox,clk" },
80 U_BOOT_DRIVER(clk_sandbox) = {
81 .name = "clk_sandbox",
83 .of_match = sandbox_clk_ids,
84 .ops = &sandbox_clk_ops,
85 .priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
88 ulong sandbox_clk_query_rate(struct udevice *dev, int id)
90 struct sandbox_clk_priv *priv = dev_get_priv(dev);
92 if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
95 return priv->rate[id];
98 int sandbox_clk_query_enable(struct udevice *dev, int id)
100 struct sandbox_clk_priv *priv = dev_get_priv(dev);
102 if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
105 return priv->enabled[id];