blob: 09f9ef26a4242ae9e44d2aec012f63780f7b0200 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadab21e20b2016-01-19 13:55:28 +09002/*
3 * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadab21e20b2016-01-19 13:55:28 +09004 */
5
6#include <common.h>
Stephen Warren135aa952016-06-17 09:44:00 -06007#include <clk-uclass.h>
Simon Glass9d922452017-05-17 17:18:03 -06008#include <dm.h>
Simon Glass0fd3d912020-12-22 19:30:28 -07009#include <dm/device-internal.h>
Peng Fan4f305bf2019-07-31 07:01:39 +000010#include <linux/clk-provider.h>
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090011
Stephen Warren135aa952016-06-17 09:44:00 -060012static ulong clk_fixed_rate_get_rate(struct clk *clk)
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090013{
Stephen Warren135aa952016-06-17 09:44:00 -060014 return to_clk_fixed_rate(clk->dev)->fixed_rate;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090015}
16
Chunfeng Yun6bf6d812020-01-09 11:35:08 +080017/* avoid clk_enable() return -ENOSYS */
18static int dummy_enable(struct clk *clk)
19{
20 return 0;
21}
22
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090023const struct clk_ops clk_fixed_rate_ops = {
24 .get_rate = clk_fixed_rate_get_rate,
Chunfeng Yun6bf6d812020-01-09 11:35:08 +080025 .enable = dummy_enable,
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090026};
27
Simon Glass4ddc91b2021-03-15 17:25:23 +130028void clk_fixed_rate_ofdata_to_plat_(struct udevice *dev,
29 struct clk_fixed_rate *plat)
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090030{
Simon Glass4ddc91b2021-03-15 17:25:23 +130031 struct clk *clk = &plat->clk;
Simon Glass7423daa2016-07-04 11:58:03 -060032#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass4ddc91b2021-03-15 17:25:23 +130033 plat->fixed_rate = dev_read_u32_default(dev, "clock-frequency", 0);
Simon Glass7423daa2016-07-04 11:58:03 -060034#endif
Lukasz Majewski36bac0a2019-06-24 15:50:40 +020035 /* Make fixed rate clock accessible from higher level struct clk */
Simon Glass0fd3d912020-12-22 19:30:28 -070036 /* FIXME: This is not allowed */
37 dev_set_uclass_priv(dev, clk);
Simon Glass4ddc91b2021-03-15 17:25:23 +130038
Lukasz Majewski36bac0a2019-06-24 15:50:40 +020039 clk->dev = dev;
Peng Fane6849e22019-08-21 13:35:03 +000040 clk->enable_count = 0;
Simon Glass4ddc91b2021-03-15 17:25:23 +130041}
42
43static int clk_fixed_rate_of_to_plat(struct udevice *dev)
44{
45 clk_fixed_rate_ofdata_to_plat_(dev, to_clk_fixed_rate(dev));
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090046
47 return 0;
48}
49
50static const struct udevice_id clk_fixed_rate_match[] = {
51 {
52 .compatible = "fixed-clock",
53 },
54 { /* sentinel */ }
55};
56
Simon Glass88280522020-10-03 11:31:32 -060057U_BOOT_DRIVER(fixed_clock) = {
58 .name = "fixed_clock",
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090059 .id = UCLASS_CLK,
60 .of_match = clk_fixed_rate_match,
Simon Glassd1998a92020-12-03 16:55:21 -070061 .of_to_plat = clk_fixed_rate_of_to_plat,
Simon Glasscaa4daa2020-12-03 16:55:18 -070062 .plat_auto = sizeof(struct clk_fixed_rate),
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090063 .ops = &clk_fixed_rate_ops,
Michal Simek4ab38172020-09-16 13:20:55 +020064 .flags = DM_FLAG_PRE_RELOC,
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090065};