xref: /rk3399_rockchip-uboot/drivers/power/dvfs/dvfs-uclass.c (revision 6aa65bb1ee0951865e27da81dde1de76c6d4687e)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd
4  */
5 
6 #include <common.h>
7 #include <console.h>
8 #include <dvfs.h>
9 
10 int dvfs_apply(struct udevice *dev)
11 {
12 	const struct dm_dvfs_ops *ops = device_get_ops(dev);
13 
14 	if (!ops->apply)
15 		return -ENOSYS;
16 
17 	return ops->apply(dev);
18 }
19 
20 int dvfs_repeat_apply(struct udevice *dev)
21 {
22 	const struct dm_dvfs_ops *ops = device_get_ops(dev);
23 
24 	if (!ops->repeat_apply)
25 		return -ENOSYS;
26 
27 	return ops->repeat_apply(dev);
28 }
29 
30 int dvfs_init(bool apply)
31 {
32 	struct udevice *dev;
33 	int ret;
34 
35 	ret = uclass_get_device(UCLASS_DVFS, 0, &dev);
36 	if (ret) {
37 		printf("DVFS: Get dvfs device failed, ret=%d\n", ret);
38 		return ret;
39 	}
40 
41 	if (apply)
42 		return dvfs_apply(dev);
43 
44 	return 0;
45 }
46 
47 UCLASS_DRIVER(dvfs) = {
48 	.id	= UCLASS_DVFS,
49 	.name	= "dvfs",
50 };
51