xref: /rk3399_rockchip-uboot/drivers/clk/clk_fixed_rate.c (revision eda90cbc2ada28031a80c791de51535a9175aad2)
1b21e20b2SMasahiro Yamada /*
2b21e20b2SMasahiro Yamada  * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com>
3b21e20b2SMasahiro Yamada  *
4b21e20b2SMasahiro Yamada  * SPDX-License-Identifier:	GPL-2.0+
5b21e20b2SMasahiro Yamada  */
6b21e20b2SMasahiro Yamada 
7b21e20b2SMasahiro Yamada #include <common.h>
8135aa950SStephen Warren #include <clk-uclass.h>
99d922450SSimon Glass #include <dm.h>
10b21e20b2SMasahiro Yamada 
11b21e20b2SMasahiro Yamada struct clk_fixed_rate {
12b21e20b2SMasahiro Yamada 	unsigned long fixed_rate;
13b21e20b2SMasahiro Yamada };
14b21e20b2SMasahiro Yamada 
15b21e20b2SMasahiro Yamada #define to_clk_fixed_rate(dev)	((struct clk_fixed_rate *)dev_get_platdata(dev))
16b21e20b2SMasahiro Yamada 
clk_fixed_rate_get_rate(struct clk * clk)17135aa950SStephen Warren static ulong clk_fixed_rate_get_rate(struct clk *clk)
18b21e20b2SMasahiro Yamada {
19135aa950SStephen Warren 	if (clk->id != 0)
20135aa950SStephen Warren 		return -EINVAL;
21b21e20b2SMasahiro Yamada 
22135aa950SStephen Warren 	return to_clk_fixed_rate(clk->dev)->fixed_rate;
23b21e20b2SMasahiro Yamada }
24b21e20b2SMasahiro Yamada 
25b21e20b2SMasahiro Yamada const struct clk_ops clk_fixed_rate_ops = {
26b21e20b2SMasahiro Yamada 	.get_rate = clk_fixed_rate_get_rate,
27b21e20b2SMasahiro Yamada };
28b21e20b2SMasahiro Yamada 
clk_fixed_rate_ofdata_to_platdata(struct udevice * dev)29b21e20b2SMasahiro Yamada static int clk_fixed_rate_ofdata_to_platdata(struct udevice *dev)
30b21e20b2SMasahiro Yamada {
317423daa6SSimon Glass #if !CONFIG_IS_ENABLED(OF_PLATDATA)
32*8b92e1cdSSimon Glass 	to_clk_fixed_rate(dev)->fixed_rate = dev_read_u32_default(dev,
33b21e20b2SMasahiro Yamada 							"clock-frequency", 0);
347423daa6SSimon Glass #endif
35b21e20b2SMasahiro Yamada 
36b21e20b2SMasahiro Yamada 	return 0;
37b21e20b2SMasahiro Yamada }
38b21e20b2SMasahiro Yamada 
39b21e20b2SMasahiro Yamada static const struct udevice_id clk_fixed_rate_match[] = {
40b21e20b2SMasahiro Yamada 	{
41b21e20b2SMasahiro Yamada 		.compatible = "fixed-clock",
42b21e20b2SMasahiro Yamada 	},
43b21e20b2SMasahiro Yamada 	{ /* sentinel */ }
44b21e20b2SMasahiro Yamada };
45b21e20b2SMasahiro Yamada 
46b21e20b2SMasahiro Yamada U_BOOT_DRIVER(clk_fixed_rate) = {
47b21e20b2SMasahiro Yamada 	.name = "fixed_rate_clock",
48b21e20b2SMasahiro Yamada 	.id = UCLASS_CLK,
49b21e20b2SMasahiro Yamada 	.of_match = clk_fixed_rate_match,
50b21e20b2SMasahiro Yamada 	.ofdata_to_platdata = clk_fixed_rate_ofdata_to_platdata,
51b21e20b2SMasahiro Yamada 	.platdata_auto_alloc_size = sizeof(struct clk_fixed_rate),
52b21e20b2SMasahiro Yamada 	.ops = &clk_fixed_rate_ops,
53b21e20b2SMasahiro Yamada };
54