blob: 1fdf8c4e540a7962297c53038a01916d33a3f11f [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>
Masahiro Yamada31adfc22016-01-19 13:55:28 +09009
Masahiro Yamada31adfc22016-01-19 13:55:28 +090010struct clk_fixed_rate {
Lukasz Majewski9ded469272019-06-24 15:50:40 +020011 struct clk clk;
Masahiro Yamada31adfc22016-01-19 13:55:28 +090012 unsigned long fixed_rate;
13};
14
15#define to_clk_fixed_rate(dev) ((struct clk_fixed_rate *)dev_get_platdata(dev))
16
Stephen Warrena9622432016-06-17 09:44:00 -060017static ulong clk_fixed_rate_get_rate(struct clk *clk)
Masahiro Yamada31adfc22016-01-19 13:55:28 +090018{
Stephen Warrena9622432016-06-17 09:44:00 -060019 return to_clk_fixed_rate(clk->dev)->fixed_rate;
Masahiro Yamada31adfc22016-01-19 13:55:28 +090020}
21
22const struct clk_ops clk_fixed_rate_ops = {
23 .get_rate = clk_fixed_rate_get_rate,
Masahiro Yamada31adfc22016-01-19 13:55:28 +090024};
25
26static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
27{
Lukasz Majewski9ded469272019-06-24 15:50:40 +020028 struct clk *clk = &to_clk_fixed_rate(dev)->clk;
Simon Glass589d9152016-07-04 11:58:03 -060029#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Mario Sixa6a04632018-01-15 11:06:52 +010030 to_clk_fixed_rate(dev)->fixed_rate =
31 dev_read_u32_default(dev, "clock-frequency", 0);
Simon Glass589d9152016-07-04 11:58:03 -060032#endif
Lukasz Majewski9ded469272019-06-24 15:50:40 +020033 /* Make fixed rate clock accessible from higher level struct clk */
34 dev->uclass_priv = clk;
35 clk->dev = dev;
Masahiro Yamada31adfc22016-01-19 13:55:28 +090036
37 return 0;
38}
39
40static const struct udevice_id clk_fixed_rate_match[] = {
41 {
42 .compatible = "fixed-clock",
43 },
44 { /* sentinel */ }
45};
46
47U_BOOT_DRIVER(clk_fixed_rate) = {
48 .name = "fixed_rate_clock",
49 .id = UCLASS_CLK,
50 .of_match = clk_fixed_rate_match,
51 .ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
52 .platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
53 .ops = &clk_fixed_rate_ops,
54};