2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-07-06 18:54:24 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2015 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-06-17 15:44:00 +00:00
|
|
|
#include <clk-uclass.h>
|
2015-07-06 18:54:24 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2016-06-17 15:44:00 +00:00
|
|
|
#include <asm/clk.h>
|
2015-07-06 18:54:24 +00:00
|
|
|
|
|
|
|
struct sandbox_clk_priv {
|
2019-10-22 12:00:07 +00:00
|
|
|
bool probed;
|
2016-06-17 15:44:00 +00:00
|
|
|
ulong rate[SANDBOX_CLK_ID_COUNT];
|
|
|
|
bool enabled[SANDBOX_CLK_ID_COUNT];
|
2019-10-22 12:00:05 +00:00
|
|
|
bool requested[SANDBOX_CLK_ID_COUNT];
|
2015-07-06 18:54:24 +00:00
|
|
|
};
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
static ulong sandbox_clk_get_rate(struct clk *clk)
|
2015-07-06 18:54:24 +00:00
|
|
|
{
|
2016-06-17 15:44:00 +00:00
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
|
2019-10-22 12:00:07 +00:00
|
|
|
if (!priv->probed)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2016-06-21 19:32:07 +00:00
|
|
|
if (clk->id >= SANDBOX_CLK_ID_COUNT)
|
2016-06-17 15:44:00 +00:00
|
|
|
return -EINVAL;
|
2015-07-06 18:54:24 +00:00
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
return priv->rate[clk->id];
|
2015-07-06 18:54:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
|
2015-07-06 18:54:24 +00:00
|
|
|
{
|
2016-06-17 15:44:00 +00:00
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
ulong old_rate;
|
|
|
|
|
2019-10-22 12:00:07 +00:00
|
|
|
if (!priv->probed)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2016-06-21 19:32:07 +00:00
|
|
|
if (clk->id >= SANDBOX_CLK_ID_COUNT)
|
2016-06-17 15:44:00 +00:00
|
|
|
return -EINVAL;
|
2015-07-06 18:54:24 +00:00
|
|
|
|
|
|
|
if (!rate)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
old_rate = priv->rate[clk->id];
|
|
|
|
priv->rate[clk->id] = rate;
|
2015-07-06 18:54:24 +00:00
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
return old_rate;
|
2015-07-06 18:54:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
static int sandbox_clk_enable(struct clk *clk)
|
2015-07-06 18:54:24 +00:00
|
|
|
{
|
2016-06-17 15:44:00 +00:00
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
2015-07-06 18:54:24 +00:00
|
|
|
|
2019-10-22 12:00:07 +00:00
|
|
|
if (!priv->probed)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2016-06-21 19:32:07 +00:00
|
|
|
if (clk->id >= SANDBOX_CLK_ID_COUNT)
|
2015-07-06 18:54:24 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
priv->enabled[clk->id] = true;
|
|
|
|
|
|
|
|
return 0;
|
2015-07-06 18:54:24 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
static int sandbox_clk_disable(struct clk *clk)
|
2015-07-06 18:54:24 +00:00
|
|
|
{
|
2016-06-17 15:44:00 +00:00
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
|
2019-10-22 12:00:07 +00:00
|
|
|
if (!priv->probed)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2016-06-21 19:32:07 +00:00
|
|
|
if (clk->id >= SANDBOX_CLK_ID_COUNT)
|
2016-06-17 15:44:00 +00:00
|
|
|
return -EINVAL;
|
2015-07-06 18:54:24 +00:00
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
priv->enabled[clk->id] = false;
|
2015-07-06 18:54:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-22 12:00:05 +00:00
|
|
|
static int sandbox_clk_request(struct clk *clk)
|
|
|
|
{
|
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
|
|
|
|
if (clk->id >= SANDBOX_CLK_ID_COUNT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
priv->requested[clk->id] = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sandbox_clk_free(struct clk *clk)
|
|
|
|
{
|
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
|
|
|
|
if (clk->id >= SANDBOX_CLK_ID_COUNT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
priv->requested[clk->id] = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 18:54:24 +00:00
|
|
|
static struct clk_ops sandbox_clk_ops = {
|
|
|
|
.get_rate = sandbox_clk_get_rate,
|
|
|
|
.set_rate = sandbox_clk_set_rate,
|
2016-06-17 15:44:00 +00:00
|
|
|
.enable = sandbox_clk_enable,
|
|
|
|
.disable = sandbox_clk_disable,
|
2019-10-22 12:00:05 +00:00
|
|
|
.request = sandbox_clk_request,
|
|
|
|
.free = sandbox_clk_free,
|
2015-07-06 18:54:24 +00:00
|
|
|
};
|
|
|
|
|
2019-10-22 12:00:07 +00:00
|
|
|
static int sandbox_clk_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->probed = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 18:54:24 +00:00
|
|
|
static const struct udevice_id sandbox_clk_ids[] = {
|
|
|
|
{ .compatible = "sandbox,clk" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(clk_sandbox) = {
|
|
|
|
.name = "clk_sandbox",
|
|
|
|
.id = UCLASS_CLK,
|
|
|
|
.of_match = sandbox_clk_ids,
|
|
|
|
.ops = &sandbox_clk_ops,
|
2019-10-22 12:00:07 +00:00
|
|
|
.probe = sandbox_clk_probe,
|
2015-07-06 18:54:24 +00:00
|
|
|
.priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
|
|
|
|
};
|
2016-06-17 15:44:00 +00:00
|
|
|
|
|
|
|
ulong sandbox_clk_query_rate(struct udevice *dev, int id)
|
|
|
|
{
|
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return priv->rate[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
int sandbox_clk_query_enable(struct udevice *dev, int id)
|
|
|
|
{
|
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return priv->enabled[id];
|
|
|
|
}
|
2019-10-22 12:00:05 +00:00
|
|
|
|
|
|
|
int sandbox_clk_query_requested(struct udevice *dev, int id)
|
|
|
|
{
|
|
|
|
struct sandbox_clk_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (id < 0 || id >= SANDBOX_CLK_ID_COUNT)
|
|
|
|
return -EINVAL;
|
|
|
|
return priv->requested[id];
|
|
|
|
}
|