xref: /OK3568_Linux_fs/u-boot/drivers/power/dvfs/dvfs-uclass.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
dvfs_apply(struct udevice * dev)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 
dvfs_repeat_apply(struct udevice * dev)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 
dvfs_init(bool apply)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 		if (ret != -ENODEV)
38 			printf("DVFS: Get dvfs device failed, ret=%d\n", ret);
39 		return ret;
40 	}
41 
42 	if (apply)
43 		return dvfs_apply(dev);
44 
45 	return 0;
46 }
47 
48 UCLASS_DRIVER(dvfs) = {
49 	.id	= UCLASS_DVFS,
50 	.name	= "dvfs",
51 };
52