1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 16:52:14 +02:00

clk: convert API to match reset/mailbox style

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>
This commit is contained in:
Stephen Warren
2016-06-17 09:44:00 -06:00
committed by Simon Glass
parent 4581b717b1
commit 135aa95002
37 changed files with 1009 additions and 594 deletions

View File

@@ -5,61 +5,63 @@
*/
#include <common.h>
#include <clk.h>
#include <clk-uclass.h>
#include <dm.h>
#include <errno.h>
#include <asm/test.h>
#include <asm/clk.h>
struct sandbox_clk_priv {
ulong rate;
ulong periph_rate[PERIPH_ID_COUNT];
ulong rate[SANDBOX_CLK_ID_COUNT];
bool enabled[SANDBOX_CLK_ID_COUNT];
};
static ulong sandbox_clk_get_rate(struct udevice *dev)
static ulong sandbox_clk_get_rate(struct clk *clk)
{
struct sandbox_clk_priv *priv = dev_get_priv(dev);
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
return priv->rate;
if (clk->id < 0 || clk->id >= SANDBOX_CLK_ID_COUNT)
return -EINVAL;
return priv->rate[clk->id];
}
static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate)
static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
{
struct sandbox_clk_priv *priv = dev_get_priv(dev);
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;
priv->rate = rate;
return 0;
}
static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
{
struct sandbox_clk_priv *priv = dev_get_priv(dev);
if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT)
return -EINVAL;
return priv->periph_rate[periph];
}
static ulong sandbox_set_periph_rate(struct udevice *dev, int periph,
ulong rate)
{
struct sandbox_clk_priv *priv = dev_get_priv(dev);
ulong old_rate;
if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT)
return -EINVAL;
old_rate = priv->periph_rate[periph];
priv->periph_rate[periph] = rate;
old_rate = priv->rate[clk->id];
priv->rate[clk->id] = rate;
return old_rate;
}
static int sandbox_clk_probe(struct udevice *dev)
static int sandbox_clk_enable(struct clk *clk)
{
struct sandbox_clk_priv *priv = dev_get_priv(dev);
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
priv->rate = SANDBOX_CLK_RATE;
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;
}
@@ -67,8 +69,8 @@ static int sandbox_clk_probe(struct udevice *dev)
static struct clk_ops sandbox_clk_ops = {
.get_rate = sandbox_clk_get_rate,
.set_rate = sandbox_clk_set_rate,
.get_periph_rate = sandbox_get_periph_rate,
.set_periph_rate = sandbox_set_periph_rate,
.enable = sandbox_clk_enable,
.disable = sandbox_clk_disable,
};
static const struct udevice_id sandbox_clk_ids[] = {
@@ -82,5 +84,24 @@ U_BOOT_DRIVER(clk_sandbox) = {
.of_match = sandbox_clk_ids,
.ops = &sandbox_clk_ops,
.priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
.probe = sandbox_clk_probe,
};
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];
}