xref: /linux/drivers/media/platform/qcom/venus/pm_helpers.h (revision 69bfec7548f4c1595bac0e3ddfc0458a5af31f4c)
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 struct venus_core;
8 
9 #define POWER_ON	1
10 #define POWER_OFF	0
11 
12 struct venus_pm_ops {
13 	int (*core_get)(struct venus_core *core);
14 	void (*core_put)(struct venus_core *core);
15 	int (*core_power)(struct venus_core *core, int on);
16 
17 	int (*vdec_get)(struct device *dev);
18 	void (*vdec_put)(struct device *dev);
19 	int (*vdec_power)(struct device *dev, int on);
20 
21 	int (*venc_get)(struct device *dev);
22 	void (*venc_put)(struct device *dev);
23 	int (*venc_power)(struct device *dev, int on);
24 
25 	int (*coreid_power)(struct venus_inst *inst, int on);
26 
27 	int (*load_scale)(struct venus_inst *inst);
28 };
29 
30 const struct venus_pm_ops *venus_pm_get(enum hfi_version version);
31 
32 static inline int venus_pm_load_scale(struct venus_inst *inst)
33 {
34 	struct venus_core *core = inst->core;
35 
36 	if (!core->pm_ops || !core->pm_ops->load_scale)
37 		return 0;
38 
39 	return core->pm_ops->load_scale(inst);
40 }
41 
42 static inline int venus_pm_acquire_core(struct venus_inst *inst)
43 {
44 	struct venus_core *core = inst->core;
45 	const struct venus_pm_ops *pm_ops = core->pm_ops;
46 	int ret = 0;
47 
48 	if (pm_ops && pm_ops->coreid_power)
49 		ret = pm_ops->coreid_power(inst, POWER_ON);
50 
51 	return ret;
52 }
53 
54 static inline int venus_pm_release_core(struct venus_inst *inst)
55 {
56 	struct venus_core *core = inst->core;
57 	const struct venus_pm_ops *pm_ops = core->pm_ops;
58 	int ret = 0;
59 
60 	if (pm_ops && pm_ops->coreid_power)
61 		ret = pm_ops->coreid_power(inst, POWER_OFF);
62 
63 	return ret;
64 }
65 
66 #endif
67