1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright (C) 2019 Linaro Ltd. */
3 #ifndef __VENUS_PM_HELPERS_H__
4 #define __VENUS_PM_HELPERS_H__
5 
6 struct device;
7 
8 #define POWER_ON	1
9 #define POWER_OFF	0
10 
11 struct venus_pm_ops {
12 	int (*core_get)(struct device *dev);
13 	void (*core_put)(struct device *dev);
14 	int (*core_power)(struct device *dev, int on);
15 
16 	int (*vdec_get)(struct device *dev);
17 	void (*vdec_put)(struct device *dev);
18 	int (*vdec_power)(struct device *dev, int on);
19 
20 	int (*venc_get)(struct device *dev);
21 	void (*venc_put)(struct device *dev);
22 	int (*venc_power)(struct device *dev, int on);
23 
24 	int (*coreid_power)(struct venus_inst *inst, int on);
25 
26 	int (*load_scale)(struct venus_inst *inst);
27 };
28 
29 const struct venus_pm_ops *venus_pm_get(enum hfi_version version);
30 
31 static inline int venus_pm_load_scale(struct venus_inst *inst)
32 {
33 	struct venus_core *core = inst->core;
34 
35 	if (!core->pm_ops || !core->pm_ops->load_scale)
36 		return 0;
37 
38 	return core->pm_ops->load_scale(inst);
39 }
40 
41 static inline int venus_pm_acquire_core(struct venus_inst *inst)
42 {
43 	struct venus_core *core = inst->core;
44 	const struct venus_pm_ops *pm_ops = core->pm_ops;
45 	int ret = 0;
46 
47 	if (pm_ops && pm_ops->coreid_power)
48 		ret = pm_ops->coreid_power(inst, POWER_ON);
49 
50 	return ret;
51 }
52 
53 static inline int venus_pm_release_core(struct venus_inst *inst)
54 {
55 	struct venus_core *core = inst->core;
56 	const struct venus_pm_ops *pm_ops = core->pm_ops;
57 	int ret = 0;
58 
59 	if (pm_ops && pm_ops->coreid_power)
60 		ret = pm_ops->coreid_power(inst, POWER_OFF);
61 
62 	return ret;
63 }
64 
65 #endif
66