blob: 3c5a83c523c102c54e5331c29500a49aa3cd6ce9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada31adfc22016-01-19 13:55:28 +09002/*
3 * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada31adfc22016-01-19 13:55:28 +09004 */
5
6#include <common.h>
Stephen Warrena9622432016-06-17 09:44:00 -06007#include <clk-uclass.h>
Simon Glass11c89f32017-05-17 17:18:03 -06008#include <dm.h>
Simon Glass95588622020-12-22 19:30:28 -07009#include <dm/device-internal.h>
Peng Fanec424a72019-07-31 07:01:39 +000010#include <linux/clk-provider.h>
Masahiro Yamada31adfc22016-01-19 13:55:28 +090011
Stephen Warrena9622432016-06-17 09:44:00 -060012static ulong clk_fixed_rate_get_rate(struct clk *clk)
Masahiro Yamada31adfc22016-01-19 13:55:28 +090013{
Stephen Warrena9622432016-06-17 09:44:00 -060014 return to_clk_fixed_rate(clk->dev)->fixed_rate;
Masahiro Yamada31adfc22016-01-19 13:55:28 +090015}
16
developercdb0efd2020-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 Yamada31adfc22016-01-19 13:55:28 +090023const struct clk_ops clk_fixed_rate_ops = {
24 .get_rate = clk_fixed_rate_get_rate,
developercdb0efd2020-01-09 11:35:08 +080025 .enable = dummy_enable,
Masahiro Yamada31adfc22016-01-19 13:55:28 +090026};
27
Simon Glassaad29ae2020-12-03 16:55:21 -070028static int clk_fixed_rate_of_to_plat(struct udevice *dev)
Masahiro Yamada31adfc22016-01-19 13:55:28 +090029{
Lukasz Majewski9ded469272019-06-24 15:50:40 +020030 struct clk *clk = &to_clk_fixed_rate(dev)->clk;
Simon Glass589d9152016-07-04 11:58:03 -060031#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Mario Sixa6a04632018-01-15 11:06:52 +010032 to_clk_fixed_rate(dev)->fixed_rate =
33 dev_read_u32_default(dev, "clock-frequency", 0);
Simon Glass589d9152016-07-04 11:58:03 -060034#endif
Lukasz Majewski9ded469272019-06-24 15:50:40 +020035 /* Make fixed rate clock accessible from higher level struct clk */
Simon Glass95588622020-12-22 19:30:28 -070036 /* FIXME: This is not allowed */
37 dev_set_uclass_priv(dev, clk);
Lukasz Majewski9ded469272019-06-24 15:50:40 +020038 clk->dev = dev;
Peng Fan30a6ebc2019-08-21 13:35:03 +000039 clk->enable_count = 0;
Masahiro Yamada31adfc22016-01-19 13:55:28 +090040
41 return 0;
42}
43
44static const struct udevice_id clk_fixed_rate_match[] = {
45 {
46 .compatible = "fixed-clock",
47 },
48 { /* sentinel */ }
49};
50
Simon Glass6b927b12020-10-03 11:31:32 -060051U_BOOT_DRIVER(fixed_clock) = {
52 .name = "fixed_clock",
Masahiro Yamada31adfc22016-01-19 13:55:28 +090053 .id = UCLASS_CLK,
54 .of_match = clk_fixed_rate_match,
Simon Glassaad29ae2020-12-03 16:55:21 -070055 .of_to_plat = clk_fixed_rate_of_to_plat,
Simon Glass71fa5b42020-12-03 16:55:18 -070056 .plat_auto = sizeof(struct clk_fixed_rate),
Masahiro Yamada31adfc22016-01-19 13:55:28 +090057 .ops = &clk_fixed_rate_ops,
Michal Simek34f67812020-09-16 13:20:55 +020058 .flags = DM_FLAG_PRE_RELOC,
Masahiro Yamada31adfc22016-01-19 13:55:28 +090059};