mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-02 09:30:10 +00:00
135aa95002
The following changes are made to the clock API: * The concept of "clocks" and "peripheral clocks" are unified; each clock provider now implements a single set of clocks. This provides a simpler conceptual interface to clients, and better aligns with device tree clock bindings. * Clocks are now identified with a single "struct clk", rather than requiring clients to store the clock provider device and clock identity values separately. For simple clock consumers, this isolates clients from internal details of the clock API. * clk.h is split so it only contains the client/consumer API, whereas clk-uclass.h contains the provider API. This aligns with the recently added reset and mailbox APIs. * clk_ops .of_xlate(), .request(), and .free() are added so providers can customize these operations if needed. This also aligns with the recently added reset and mailbox APIs. * clk_disable() is added. * All users of the current clock APIs are updated. * Sandbox clock tests are updated to exercise clock lookup via DT, and clock enable/disable. * rkclk_get_clk() is removed and replaced with standard APIs. Buildman shows no clock-related errors for any board for which buildman can download a toolchain. test/py passes for sandbox (which invokes the dm clk test amongst others). Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Simon Glass <sjg@chromium.org>
107 lines
2.1 KiB
C
107 lines
2.1 KiB
C
/*
|
|
* (C) Copyright 2015 Google, Inc
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <clk-uclass.h>
|
|
#include <dm.h>
|
|
#include <errno.h>
|
|
#include <asm/clk.h>
|
|
|
|
struct sandbox_clk_priv {
|
|
ulong rate[SANDBOX_CLK_ID_COUNT];
|
|
bool enabled[SANDBOX_CLK_ID_COUNT];
|
|
};
|
|
|
|
static ulong sandbox_clk_get_rate(struct clk *clk)
|
|
{
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
if (clk->id < 0 || clk->id >= SANDBOX_CLK_ID_COUNT)
|
|
return -EINVAL;
|
|
|
|
return priv->rate[clk->id];
|
|
}
|
|
|
|
static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
|
|
{
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
ulong old_rate;
|
|
|
|
if (clk->id < 0 || clk->id >= SANDBOX_CLK_ID_COUNT)
|
|
return -EINVAL;
|
|
|
|
if (!rate)
|
|
return -EINVAL;
|
|
|
|
old_rate = priv->rate[clk->id];
|
|
priv->rate[clk->id] = rate;
|
|
|
|
return old_rate;
|
|
}
|
|
|
|
static int sandbox_clk_enable(struct clk *clk)
|
|
{
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
if (clk->id < 0 || clk->id >= SANDBOX_CLK_ID_COUNT)
|
|
return -EINVAL;
|
|
|
|
priv->enabled[clk->id] = true;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sandbox_clk_disable(struct clk *clk)
|
|
{
|
|
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
|
|
|
|
if (clk->id < 0 || clk->id >= SANDBOX_CLK_ID_COUNT)
|
|
return -EINVAL;
|
|
|
|
priv->enabled[clk->id] = false;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct clk_ops sandbox_clk_ops = {
|
|
.get_rate = sandbox_clk_get_rate,
|
|
.set_rate = sandbox_clk_set_rate,
|
|
.enable = sandbox_clk_enable,
|
|
.disable = sandbox_clk_disable,
|
|
};
|
|
|
|
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,
|
|
.priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
|
|
};
|
|
|
|
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];
|
|
}
|