xref: /openbmc/u-boot/drivers/clk/clk_fixed_rate.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2b21e20b2SMasahiro Yamada /*
3b21e20b2SMasahiro Yamada  * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
4b21e20b2SMasahiro Yamada  */
5b21e20b2SMasahiro Yamada 
6b21e20b2SMasahiro Yamada #include <common.h>
7135aa950SStephen Warren #include <clk-uclass.h>
89d922450SSimon Glass #include <dm.h>
9b21e20b2SMasahiro Yamada 
10b21e20b2SMasahiro Yamada struct clk_fixed_rate {
11b21e20b2SMasahiro Yamada 	unsigned long fixed_rate;
12b21e20b2SMasahiro Yamada };
13b21e20b2SMasahiro Yamada 
14b21e20b2SMasahiro Yamada #define to_clk_fixed_rate(dev)	((struct clk_fixed_rate *)dev_get_platdata(dev))
15b21e20b2SMasahiro Yamada 
clk_fixed_rate_get_rate(struct clk * clk)16135aa950SStephen Warren static ulong clk_fixed_rate_get_rate(struct clk *clk)
17b21e20b2SMasahiro Yamada {
18135aa950SStephen Warren 	if (clk->id != 0)
19135aa950SStephen Warren 		return -EINVAL;
20b21e20b2SMasahiro Yamada 
21135aa950SStephen Warren 	return to_clk_fixed_rate(clk->dev)->fixed_rate;
22b21e20b2SMasahiro Yamada }
23b21e20b2SMasahiro Yamada 
24b21e20b2SMasahiro Yamada const struct clk_ops clk_fixed_rate_ops = {
25b21e20b2SMasahiro Yamada 	.get_rate = clk_fixed_rate_get_rate,
26b21e20b2SMasahiro Yamada };
27b21e20b2SMasahiro Yamada 
clk_fixed_rate_ofdata_to_platdata(struct udevice * dev)28b21e20b2SMasahiro Yamada static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
29b21e20b2SMasahiro Yamada {
307423daa6SSimon Glass #if !CONFIG_IS_ENABLED(OF_PLATDATA)
31e2db9e7aSMario Six 	to_clk_fixed_rate(dev)->fixed_rate =
32e2db9e7aSMario Six 		dev_read_u32_default(dev, "clock-frequency", 0);
337423daa6SSimon Glass #endif
34b21e20b2SMasahiro Yamada 
35b21e20b2SMasahiro Yamada 	return 0;
36b21e20b2SMasahiro Yamada }
37b21e20b2SMasahiro Yamada 
38b21e20b2SMasahiro Yamada static const struct udevice_id clk_fixed_rate_match[] = {
39b21e20b2SMasahiro Yamada 	{
40b21e20b2SMasahiro Yamada 		.compatible = "fixed-clock",
41b21e20b2SMasahiro Yamada 	},
42b21e20b2SMasahiro Yamada 	{ /* sentinel */ }
43b21e20b2SMasahiro Yamada };
44b21e20b2SMasahiro Yamada 
45b21e20b2SMasahiro Yamada U_BOOT_DRIVER(clk_fixed_rate) = {
46b21e20b2SMasahiro Yamada 	.name = "fixed_rate_clock",
47b21e20b2SMasahiro Yamada 	.id = UCLASS_CLK,
48b21e20b2SMasahiro Yamada 	.of_match = clk_fixed_rate_match,
49b21e20b2SMasahiro Yamada 	.ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
50b21e20b2SMasahiro Yamada 	.platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
51b21e20b2SMasahiro Yamada 	.ops = &clk_fixed_rate_ops,
52b21e20b2SMasahiro Yamada };
53