[PATCH] clk: sophgo: Use clock ID translation for cv1800b
Alexey Karyakin
a2karyak at uwaterloo.ca
Tue Jan 7 05:38:48 CET 2025
The internal clock IDs are shifted by 3 accommodate the "osc" and
"bypass" clocks, which IDs are not included in the Linux device tree.
Currently, the `.of_xlate` function is not implemented as the conversion
is handled by custom versions of the clk_ops functions. Unfortunately,
this does work when clocks are looked by using the device tree API
such as `clk_get_by_index`. As a result, devices pick up wrong clocks.
The problem manifests itself when intializing the ethernet controller:
Net: Enable clock-controller at 3002000 failed
failed to enable clock 0
No ethernet found.
This patch adds the `.of_xlate` function and replaces all the custom
functions with the standard ones.
Tested on milk-v duo board.
Signed-off-by: Alexey Karyakin <a2karyak at uwaterloo.ca>
---
drivers/clk/sophgo/clk-cv1800b.c | 70 ++++++++------------------------
1 file changed, 17 insertions(+), 53 deletions(-)
diff --git a/drivers/clk/sophgo/clk-cv1800b.c
b/drivers/clk/sophgo/clk-cv1800b.c
index d946ea57a46..eab57b18b13 100644
--- a/drivers/clk/sophgo/clk-cv1800b.c
+++ b/drivers/clk/sophgo/clk-cv1800b.c
@@ -678,65 +678,29 @@ static int cv1800b_clk_probe(struct udevice *dev)
return cv1800b_register_clk(dev);
}
-static int cv1800b_clk_enable(struct clk *clk)
+static int cv1800b_clk_of_xlate(struct clk *clk,
+ struct ofnode_phandle_args *args)
{
- struct clk *c;
- int err = clk_get_by_id(CV1800B_CLK_ID_TRANSFORM(clk->id), &c);
-
- if (err)
- return err;
- return clk_enable(c);
-}
-
-static int cv1800b_clk_disable(struct clk *clk)
-{
- struct clk *c;
- int err = clk_get_by_id(CV1800B_CLK_ID_TRANSFORM(clk->id), &c);
-
- if (err)
- return err;
- return clk_disable(c);
-}
-
-static ulong cv1800b_clk_get_rate(struct clk *clk)
-{
- struct clk *c;
- int err = clk_get_by_id(CV1800B_CLK_ID_TRANSFORM(clk->id), &c);
-
- if (err)
- return err;
- return clk_get_rate(c);
-}
-
-static ulong cv1800b_clk_set_rate(struct clk *clk, ulong rate)
-{
- struct clk *c;
- int err = clk_get_by_id(CV1800B_CLK_ID_TRANSFORM(clk->id), &c);
+ if (args->args_count > 1) {
+ debug("Invalid args_count: %d\n", args->args_count);
+ return -EINVAL;
+ }
- if (err)
- return err;
- return clk_set_rate(c, rate);
-}
+ if (args->args_count)
+ clk->id = CV1800B_CLK_ID_TRANSFORM(args->args[0]);
+ else
+ clk->id = 0;
-static int cv1800b_clk_set_parent(struct clk *clk, struct clk *parent)
-{
- struct clk *c, *p;
- int err = clk_get_by_id(CV1800B_CLK_ID_TRANSFORM(clk->id), &c);
-
- if (err)
- return err;
- err = clk_get_by_id(CV1800B_CLK_ID_TRANSFORM(parent->id), &p);
- if (err)
- return err;
- return clk_set_parent(c, p);
+ return 0;
}
const struct clk_ops cv1800b_clk_ops = {
- .enable = cv1800b_clk_enable,
- .disable = cv1800b_clk_disable,
- .get_rate = cv1800b_clk_get_rate,
- .set_rate = cv1800b_clk_set_rate,
- .set_parent = cv1800b_clk_set_parent,
+ .enable = ccf_clk_enable,
+ .disable = ccf_clk_disable,
+ .get_rate = ccf_clk_get_rate,
+ .set_rate = ccf_clk_set_rate,
+ .set_parent = ccf_clk_set_parent,
+ .of_xlate = cv1800b_clk_of_xlate,
};
static const struct udevice_id cv1800b_clk_of_match[] = {
--
2.30.2
More information about the U-Boot
mailing list