1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2020, The Linux Foundation. All rights reserved.
4  */
5 #include <linux/of_device.h>
6 #include "hfi_platform.h"
7 #include "core.h"
8 
9 const struct hfi_platform *hfi_platform_get(enum hfi_version version)
10 {
11 	switch (version) {
12 	case HFI_VERSION_4XX:
13 		return &hfi_plat_v4;
14 	case HFI_VERSION_6XX:
15 		return &hfi_plat_v6;
16 	default:
17 		break;
18 	}
19 
20 	return NULL;
21 }
22 
23 unsigned long
24 hfi_platform_get_codec_vpp_freq(enum hfi_version version, u32 codec, u32 session_type)
25 {
26 	const struct hfi_platform *plat;
27 	unsigned long freq = 0;
28 
29 	plat = hfi_platform_get(version);
30 	if (!plat)
31 		return 0;
32 
33 	if (plat->codec_vpp_freq)
34 		freq = plat->codec_vpp_freq(session_type, codec);
35 
36 	return freq;
37 }
38 
39 unsigned long
40 hfi_platform_get_codec_vsp_freq(enum hfi_version version, u32 codec, u32 session_type)
41 {
42 	const struct hfi_platform *plat;
43 	unsigned long freq = 0;
44 
45 	plat = hfi_platform_get(version);
46 	if (!plat)
47 		return 0;
48 
49 	if (plat->codec_vpp_freq)
50 		freq = plat->codec_vsp_freq(session_type, codec);
51 
52 	return freq;
53 }
54 
55 unsigned long
56 hfi_platform_get_codec_lp_freq(enum hfi_version version, u32 codec, u32 session_type)
57 {
58 	const struct hfi_platform *plat;
59 	unsigned long freq = 0;
60 
61 	plat = hfi_platform_get(version);
62 	if (!plat)
63 		return 0;
64 
65 	if (plat->codec_lp_freq)
66 		freq = plat->codec_lp_freq(session_type, codec);
67 
68 	return freq;
69 }
70 
71 int
72 hfi_platform_get_codecs(struct venus_core *core, u32 *enc_codecs, u32 *dec_codecs, u32 *count)
73 {
74 	const struct hfi_platform *plat;
75 
76 	plat = hfi_platform_get(core->res->hfi_version);
77 	if (!plat)
78 		return -EINVAL;
79 
80 	if (plat->codecs)
81 		plat->codecs(enc_codecs, dec_codecs, count);
82 
83 	if (of_device_is_compatible(core->dev->of_node, "qcom,sc7280-venus")) {
84 		*enc_codecs &= ~HFI_VIDEO_CODEC_VP8;
85 		*dec_codecs &= ~HFI_VIDEO_CODEC_VP8;
86 	}
87 
88 	return 0;
89 }
90 
91