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>
diff --git a/drivers/clk/uniphier/clk-uniphier-core.c b/drivers/clk/uniphier/clk-uniphier-core.c
index 25c163b..2f5d4d8 100644
--- a/drivers/clk/uniphier/clk-uniphier-core.c
+++ b/drivers/clk/uniphier/clk-uniphier-core.c
@@ -9,14 +9,14 @@
#include <linux/bitops.h>
#include <linux/io.h>
#include <linux/sizes.h>
-#include <clk.h>
+#include <clk-uclass.h>
#include <dm/device.h>
#include "clk-uniphier.h"
-static int uniphier_clk_enable(struct udevice *dev, int index)
+static int uniphier_clk_enable(struct clk *clk)
{
- struct uniphier_clk_priv *priv = dev_get_priv(dev);
+ struct uniphier_clk_priv *priv = dev_get_priv(clk->dev);
struct uniphier_clk_gate_data *gate = priv->socdata->gate;
unsigned int nr_gate = priv->socdata->nr_gate;
void __iomem *reg;
@@ -24,7 +24,7 @@
int i;
for (i = 0; i < nr_gate; i++) {
- if (gate[i].index != index)
+ if (gate[i].index != clk->id)
continue;
reg = priv->base + gate[i].reg;
@@ -41,9 +41,9 @@
return 0;
}
-static ulong uniphier_clk_get_rate(struct udevice *dev, int index)
+static ulong uniphier_clk_get_rate(struct clk *clk)
{
- struct uniphier_clk_priv *priv = dev_get_priv(dev);
+ struct uniphier_clk_priv *priv = dev_get_priv(clk->dev);
struct uniphier_clk_rate_data *rdata = priv->socdata->rate;
unsigned int nr_rdata = priv->socdata->nr_rate;
void __iomem *reg;
@@ -52,7 +52,7 @@
int i;
for (i = 0; i < nr_rdata; i++) {
- if (rdata[i].index != index)
+ if (rdata[i].index != clk->id)
continue;
if (rdata[i].reg == UNIPHIER_CLK_RATE_IS_FIXED)
@@ -75,9 +75,9 @@
return matched_rate;
}
-static ulong uniphier_clk_set_rate(struct udevice *dev, int index, ulong rate)
+static ulong uniphier_clk_set_rate(struct clk *clk, ulong rate)
{
- struct uniphier_clk_priv *priv = dev_get_priv(dev);
+ struct uniphier_clk_priv *priv = dev_get_priv(clk->dev);
struct uniphier_clk_rate_data *rdata = priv->socdata->rate;
unsigned int nr_rdata = priv->socdata->nr_rate;
void __iomem *reg;
@@ -87,7 +87,7 @@
/* first, decide the best match rate */
for (i = 0; i < nr_rdata; i++) {
- if (rdata[i].index != index)
+ if (rdata[i].index != clk->id)
continue;
if (rdata[i].reg == UNIPHIER_CLK_RATE_IS_FIXED)
@@ -105,7 +105,7 @@
/* second, really set registers */
for (i = 0; i < nr_rdata; i++) {
- if (rdata[i].index != index || rdata[i].rate != best_rate)
+ if (rdata[i].index != clk->id || rdata[i].rate != best_rate)
continue;
reg = priv->base + rdata[i].reg;
@@ -124,8 +124,8 @@
const struct clk_ops uniphier_clk_ops = {
.enable = uniphier_clk_enable,
- .get_periph_rate = uniphier_clk_get_rate,
- .set_periph_rate = uniphier_clk_set_rate,
+ .get_rate = uniphier_clk_get_rate,
+ .set_rate = uniphier_clk_set_rate,
};
int uniphier_clk_probe(struct udevice *dev)