blob: c9a9f0a20b6f1628a0792fe40d8e36119e916d3f [file] [log] [blame]
Masahiro Yamadab21e20b2016-01-19 13:55:28 +09001/*
2 * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Stephen Warren135aa952016-06-17 09:44:00 -06008#include <clk-uclass.h>
Simon Glass9d922452017-05-17 17:18:03 -06009#include <dm.h>
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090010
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090011struct clk_fixed_rate {
12 unsigned long fixed_rate;
13};
14
15#define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev))
16
Stephen Warren135aa952016-06-17 09:44:00 -060017static ulong clk_fixed_rate_get_rate(struct clk *clk)
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090018{
Stephen Warren135aa952016-06-17 09:44:00 -060019 if (clk->id != 0)
20 return -EINVAL;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090021
Stephen Warren135aa952016-06-17 09:44:00 -060022 return to_clk_fixed_rate(clk->dev)->fixed_rate;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090023}
24
25const struct clk_ops clk_fixed_rate_ops = {
26 .get_rate = clk_fixed_rate_get_rate,
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090027};
28
29static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
30{
Simon Glass7423daa2016-07-04 11:58:03 -060031#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Mario Sixe2db9e72018-01-15 11:06:52 +010032 to_clk_fixed_rate(dev)->fixed_rate =
33 dev_read_u32_default(dev, "clock-frequency", 0);
Simon Glass7423daa2016-07-04 11:58:03 -060034#endif
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090035
36 return 0;
37}
38
39static const struct udevice_id clk_fixed_rate_match[] = {
40 {
41 .compatible = "fixed-clock",
42 },
43 { /* sentinel */ }
44};
45
46U_BOOT_DRIVER(clk_fixed_rate) = {
47 .name = "fixed_rate_clock",
48 .id = UCLASS_CLK,
49 .of_match = clk_fixed_rate_match,
50 .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
51 .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
52 .ops = &clk_fixed_rate_ops,
53};