xref: /rk3399_rockchip-uboot/drivers/clk/clk-uclass.c (revision 3ade5bc4dc24edf5e1f13f3c43a9e8b7f8c2d853)
1 /*
2  * Copyright (C) 2015 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <clk.h>
10 #include <dm.h>
11 #include <errno.h>
12 #include <dm/lists.h>
13 #include <dm/root.h>
14 
15 ulong clk_get_rate(struct udevice *dev)
16 {
17 	struct clk_ops *ops = clk_get_ops(dev);
18 
19 	if (!ops->get_rate)
20 		return -ENOSYS;
21 
22 	return ops->get_rate(dev);
23 }
24 
25 ulong clk_set_rate(struct udevice *dev, ulong rate)
26 {
27 	struct clk_ops *ops = clk_get_ops(dev);
28 
29 	if (!ops->set_rate)
30 		return -ENOSYS;
31 
32 	return ops->set_rate(dev, rate);
33 }
34 
35 int clk_enable(struct udevice *dev, int periph)
36 {
37 	struct clk_ops *ops = clk_get_ops(dev);
38 
39 	if (!ops->enable)
40 		return -ENOSYS;
41 
42 	return ops->enable(dev, periph);
43 }
44 
45 ulong clk_get_periph_rate(struct udevice *dev, int periph)
46 {
47 	struct clk_ops *ops = clk_get_ops(dev);
48 
49 	if (!ops->get_periph_rate)
50 		return -ENOSYS;
51 
52 	return ops->get_periph_rate(dev, periph);
53 }
54 
55 ulong clk_set_periph_rate(struct udevice *dev, int periph, ulong rate)
56 {
57 	struct clk_ops *ops = clk_get_ops(dev);
58 
59 	if (!ops->set_periph_rate)
60 		return -ENOSYS;
61 
62 	return ops->set_periph_rate(dev, periph, rate);
63 }
64 
65 UCLASS_DRIVER(clk) = {
66 	.id		= UCLASS_CLK,
67 	.name		= "clk",
68 };
69