1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
6 #define LOG_CATEGORY UCLASS_CLK
9 #include <clk-uclass.h>
12 #include <dm/device-internal.h>
13 #include <linux/clk-provider.h>
15 #define UBOOT_DM_CLK_FIXED_RATE "fixed_rate_clock"
16 #define UBOOT_DM_CLK_FIXED_RATE_RAW "fixed_rate_raw_clock"
18 static ulong clk_fixed_rate_get_rate(struct clk *clk)
20 return to_clk_fixed_rate(clk->dev)->fixed_rate;
23 /* avoid clk_enable() return -ENOSYS */
24 static int dummy_enable(struct clk *clk)
29 const struct clk_ops clk_fixed_rate_ops = {
30 .get_rate = clk_fixed_rate_get_rate,
31 .enable = dummy_enable,
32 .disable = dummy_enable,
35 void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev,
36 struct clk_fixed_rate *plat)
38 struct clk *clk = &plat->clk;
39 if (CONFIG_IS_ENABLED(OF_REAL))
40 plat->fixed_rate = dev_read_u32_default(dev, "clock-frequency",
43 /* Make fixed rate clock accessible from higher level struct clk */
44 /* FIXME: This is not allowed */
45 dev_set_uclass_priv(dev, clk);
48 clk->enable_count = 0;
51 static ulong clk_fixed_rate_raw_get_rate(struct clk *clk)
53 return container_of(clk, struct clk_fixed_rate, clk)->fixed_rate;
56 const struct clk_ops clk_fixed_rate_raw_ops = {
57 .get_rate = clk_fixed_rate_raw_get_rate,
60 static int clk_fixed_rate_of_to_plat(struct udevice *dev)
62 clk_fixed_rate_ofdata_to_plat_(dev, to_clk_fixed_rate(dev));
67 #if CONFIG_IS_ENABLED(CLK_CCF)
68 struct clk *clk_register_fixed_rate(struct device *dev, const char *name,
72 struct clk_fixed_rate *fixed;
75 fixed = kzalloc(sizeof(*fixed), GFP_KERNEL);
77 return ERR_PTR(-ENOMEM);
79 fixed->fixed_rate = rate;
83 ret = clk_register(clk, UBOOT_DM_CLK_FIXED_RATE_RAW, name, NULL);
93 static const struct udevice_id clk_fixed_rate_match[] = {
95 .compatible = "fixed-clock",
100 U_BOOT_DRIVER(fixed_clock) = {
101 .name = "fixed_clock",
103 .of_match = clk_fixed_rate_match,
104 .of_to_plat = clk_fixed_rate_of_to_plat,
105 .plat_auto = sizeof(struct clk_fixed_rate),
106 .ops = &clk_fixed_rate_ops,
107 .flags = DM_FLAG_PRE_RELOC,
110 U_BOOT_DRIVER(clk_fixed_rate_raw) = {
111 .name = UBOOT_DM_CLK_FIXED_RATE_RAW,
113 .ops = &clk_fixed_rate_raw_ops,
114 .flags = DM_FLAG_PRE_RELOC,