1 // SPDX-License-Identifier: GPL-2.0
3 * (C) Copyright 2015 Google, Inc
6 #include <clk-uclass.h>
11 #include <linux/clk-provider.h>
13 static ulong sandbox_clk_get_rate(struct clk *clk)
15 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
20 if (clk->id >= SANDBOX_CLK_ID_COUNT)
23 return priv->rate[clk->id];
26 static ulong sandbox_clk_round_rate(struct clk *clk, ulong rate)
28 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
33 if (clk->id >= SANDBOX_CLK_ID_COUNT)
42 static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
44 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
50 if (clk->id >= SANDBOX_CLK_ID_COUNT)
56 old_rate = priv->rate[clk->id];
57 priv->rate[clk->id] = rate;
62 static int sandbox_clk_enable(struct clk *clk)
64 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
69 if (clk->id >= SANDBOX_CLK_ID_COUNT)
72 priv->enabled[clk->id] = true;
77 static int sandbox_clk_disable(struct clk *clk)
79 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
84 if (clk->id >= SANDBOX_CLK_ID_COUNT)
87 priv->enabled[clk->id] = false;
92 static int sandbox_clk_request(struct clk *clk)
94 struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
96 if (clk->id >= SANDBOX_CLK_ID_COUNT)
99 priv->requested[clk->id] = true;
103 static struct clk_ops sandbox_clk_ops = {
104 .round_rate = sandbox_clk_round_rate,
105 .get_rate = sandbox_clk_get_rate,
106 .set_rate = sandbox_clk_set_rate,
107 .enable = sandbox_clk_enable,
108 .disable = sandbox_clk_disable,
109 .request = sandbox_clk_request,
112 static int sandbox_clk_probe(struct udevice *dev)
114 struct sandbox_clk_priv *priv = dev_get_priv(dev);
120 static const struct udevice_id sandbox_clk_ids[] = {
121 { .compatible = "sandbox,clk" },
125 U_BOOT_DRIVER(sandbox_clk) = {
126 .name = "sandbox_clk",
128 .of_match = sandbox_clk_ids,
129 .ops = &sandbox_clk_ops,
130 .probe = sandbox_clk_probe,
131 .priv_auto = sizeof(struct sandbox_clk_priv),
134 ulong sandbox_clk_query_rate(struct udevice *dev, int id)
136 struct sandbox_clk_priv *priv = dev_get_priv(dev);
138 if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
141 return priv->rate[id];
144 int sandbox_clk_query_enable(struct udevice *dev, int id)
146 struct sandbox_clk_priv *priv = dev_get_priv(dev);
148 if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
151 return priv->enabled[id];
154 int sandbox_clk_query_requested(struct udevice *dev, int id)
156 struct sandbox_clk_priv *priv = dev_get_priv(dev);
158 if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
160 return priv->requested[id];
163 int clk_fixed_rate_of_to_plat(struct udevice *dev)
165 struct clk_fixed_rate *cplat;
167 #if CONFIG_IS_ENABLED(OF_PLATDATA)
168 struct sandbox_clk_fixed_rate_plat *plat = dev_get_plat(dev);
170 cplat = &plat->fixed;
171 cplat->fixed_rate = plat->dtplat.clock_frequency;
173 cplat = to_clk_fixed_rate(dev);
175 clk_fixed_rate_ofdata_to_plat_(dev, cplat);
180 static const struct udevice_id sandbox_clk_fixed_rate_match[] = {
181 { .compatible = "sandbox,fixed-clock" },
185 U_BOOT_DRIVER(sandbox_fixed_clock) = {
186 .name = "sandbox_fixed_clock",
188 .of_match = sandbox_clk_fixed_rate_match,
189 .of_to_plat = clk_fixed_rate_of_to_plat,
190 .plat_auto = sizeof(struct sandbox_clk_fixed_rate_plat),
191 .ops = &clk_fixed_rate_ops,
192 .flags = DM_FLAG_PRE_RELOC,