1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2022 MediaTek Inc.
4  * Author: Ping-Hsun Wu <ping-hsun.wu@mediatek.com>
5  */
6 
7 #ifndef __MTK_MDP3_CORE_H__
8 #define __MTK_MDP3_CORE_H__
9 
10 #include <media/v4l2-device.h>
11 #include <media/v4l2-mem2mem.h>
12 #include <linux/soc/mediatek/mtk-mmsys.h>
13 #include <linux/soc/mediatek/mtk-mutex.h>
14 #include "mtk-mdp3-comp.h"
15 #include "mtk-mdp3-vpu.h"
16 
17 #define MDP_MODULE_NAME		"mtk-mdp3"
18 #define MDP_DEVICE_NAME		"MediaTek MDP3"
19 #define MDP_PHANDLE_NAME	"mediatek,mdp3"
20 
21 enum mdp_infra_id {
22 	MDP_INFRA_MMSYS,
23 	MDP_INFRA_MUTEX,
24 	MDP_INFRA_SCP,
25 	MDP_INFRA_MAX
26 };
27 
28 enum mdp_buffer_usage {
29 	MDP_BUFFER_USAGE_HW_READ,
30 	MDP_BUFFER_USAGE_MDP,
31 	MDP_BUFFER_USAGE_MDP2,
32 	MDP_BUFFER_USAGE_ISP,
33 	MDP_BUFFER_USAGE_WPE,
34 };
35 
36 struct mdp_platform_config {
37 	bool	rdma_support_10bit;
38 	bool	rdma_rsz1_sram_sharing;
39 	bool	rdma_upsample_repeat_only;
40 	bool	rsz_disable_dcm_small_sample;
41 	bool	wrot_filter_constraint;
42 };
43 
44 /* indicate which mutex is used by each pipepline */
45 enum mdp_pipe_id {
46 	MDP_PIPE_WPEI,
47 	MDP_PIPE_WPEI2,
48 	MDP_PIPE_IMGI,
49 	MDP_PIPE_RDMA0,
50 	MDP_PIPE_MAX
51 };
52 
53 struct mtk_mdp_driver_data {
54 	const int mdp_plat_id;
55 	const struct of_device_id *mdp_probe_infra;
56 	const struct mdp_platform_config *mdp_cfg;
57 	const u32 *mdp_mutex_table_idx;
58 	const struct mdp_comp_data *comp_data;
59 	unsigned int comp_data_len;
60 	const struct of_device_id *mdp_sub_comp_dt_ids;
61 	const struct mdp_format *format;
62 	unsigned int format_len;
63 	const struct mdp_limit *def_limit;
64 	const struct mdp_pipe_info *pipe_info;
65 	unsigned int pipe_info_len;
66 };
67 
68 struct mdp_dev {
69 	struct platform_device			*pdev;
70 	struct device				*mdp_mmsys;
71 	struct mtk_mutex			*mdp_mutex[MDP_PIPE_MAX];
72 	struct mdp_comp				*comp[MDP_MAX_COMP_COUNT];
73 	const struct mtk_mdp_driver_data	*mdp_data;
74 
75 	struct workqueue_struct			*job_wq;
76 	struct workqueue_struct			*clock_wq;
77 	struct mdp_vpu_dev			vpu;
78 	struct mtk_scp				*scp;
79 	struct rproc				*rproc_handle;
80 	/* synchronization protect for accessing vpu working buffer info */
81 	struct mutex				vpu_lock;
82 	s32					vpu_count;
83 	u32					id_count;
84 	struct ida				mdp_ida;
85 	struct cmdq_client			*cmdq_clt;
86 	wait_queue_head_t			callback_wq;
87 
88 	struct v4l2_device			v4l2_dev;
89 	struct video_device			*m2m_vdev;
90 	struct v4l2_m2m_dev			*m2m_dev;
91 	/* synchronization protect for m2m device operation */
92 	struct mutex				m2m_lock;
93 	atomic_t				suspended;
94 	atomic_t				job_count;
95 };
96 
97 struct mdp_pipe_info {
98 	enum mdp_pipe_id pipe_id;
99 	u32 mutex_id;
100 };
101 
102 int mdp_vpu_get_locked(struct mdp_dev *mdp);
103 void mdp_vpu_put_locked(struct mdp_dev *mdp);
104 int mdp_vpu_register(struct mdp_dev *mdp);
105 void mdp_vpu_unregister(struct mdp_dev *mdp);
106 void mdp_video_device_release(struct video_device *vdev);
107 
108 #endif  /* __MTK_MDP3_CORE_H__ */
109