blob: 08cce0d79b71033a7d387d4e6ffe045c04958b8a [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>
Peng Fan4f305bf2019-07-31 07:01:39 +00009#include <linux/clk-provider.h>
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090010
Stephen Warren135aa952016-06-17 09:44:00 -060011static ulong clk_fixed_rate_get_rate(struct clk *clk)
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090012{
Stephen Warren135aa952016-06-17 09:44:00 -060013 return to_clk_fixed_rate(clk->dev)->fixed_rate;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090014}
15
16const struct clk_ops clk_fixed_rate_ops = {
17 .get_rate = clk_fixed_rate_get_rate,
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090018};
19
20static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
21{
Lukasz Majewski36bac0a2019-06-24 15:50:40 +020022 struct clk *clk = &to_clk_fixed_rate(dev)->clk;
Simon Glass7423daa2016-07-04 11:58:03 -060023#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Mario Sixe2db9e72018-01-15 11:06:52 +010024 to_clk_fixed_rate(dev)->fixed_rate =
25 dev_read_u32_default(dev, "clock-frequency", 0);
Simon Glass7423daa2016-07-04 11:58:03 -060026#endif
Lukasz Majewski36bac0a2019-06-24 15:50:40 +020027 /* Make fixed rate clock accessible from higher level struct clk */
28 dev->uclass_priv = clk;
29 clk->dev = dev;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090030
31 return 0;
32}
33
34static const struct udevice_id clk_fixed_rate_match[] = {
35 {
36 .compatible = "fixed-clock",
37 },
38 { /* sentinel */ }
39};
40
41U_BOOT_DRIVER(clk_fixed_rate) = {
42 .name = "fixed_rate_clock",
43 .id = UCLASS_CLK,
44 .of_match = clk_fixed_rate_match,
45 .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
46 .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
47 .ops = &clk_fixed_rate_ops,
48};