blob: d8d9f86c8642c927bce696ab97d111090895d8d0 [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>
Masahiro Yamadab21e20b2016-01-19 13:55:28 +09009
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090010struct clk_fixed_rate {
11 unsigned long fixed_rate;
12};
13
14#define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev))
15
Stephen Warren135aa952016-06-17 09:44:00 -060016static ulong clk_fixed_rate_get_rate(struct clk *clk)
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090017{
Stephen Warren135aa952016-06-17 09:44:00 -060018 if (clk->id != 0)
19 return -EINVAL;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090020
Stephen Warren135aa952016-06-17 09:44:00 -060021 return to_clk_fixed_rate(clk->dev)->fixed_rate;
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090022}
23
24const struct clk_ops clk_fixed_rate_ops = {
25 .get_rate = clk_fixed_rate_get_rate,
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090026};
27
28static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
29{
Simon Glass7423daa2016-07-04 11:58:03 -060030#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Mario Sixe2db9e72018-01-15 11:06:52 +010031 to_clk_fixed_rate(dev)->fixed_rate =
32 dev_read_u32_default(dev, "clock-frequency", 0);
Simon Glass7423daa2016-07-04 11:58:03 -060033#endif
Masahiro Yamadab21e20b2016-01-19 13:55:28 +090034
35 return 0;
36}
37
38static const struct udevice_id clk_fixed_rate_match[] = {
39 {
40 .compatible = "fixed-clock",
41 },
42 { /* sentinel */ }
43};
44
45U_BOOT_DRIVER(clk_fixed_rate) = {
46 .name = "fixed_rate_clock",
47 .id = UCLASS_CLK,
48 .of_match = clk_fixed_rate_match,
49 .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
50 .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
51 .ops = &clk_fixed_rate_ops,
52};