1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015-2016 MediaTek Inc.
4 * Author: Houlong Wei <houlong.wei@mediatek.com>
5 * Ming Hsiu Tsai <minghsiu.tsai@mediatek.com>
8 #include <linux/platform_device.h>
10 #include "mtk_mdp_core.h"
11 #include "mtk_mdp_regs.h"
14 #define MDP_COLORFMT_PACK(VIDEO, PLANE, COPLANE, HF, VF, BITS, GROUP, SWAP, ID)\
15 (((VIDEO) << 27) | ((PLANE) << 24) | ((COPLANE) << 22) |\
16 ((HF) << 20) | ((VF) << 18) | ((BITS) << 8) | ((GROUP) << 6) |\
17 ((SWAP) << 5) | ((ID) << 0))
20 MDP_COLOR_UNKNOWN
= 0,
21 MDP_COLOR_NV12
= MDP_COLORFMT_PACK(0, 2, 1, 1, 1, 8, 1, 0, 12),
22 MDP_COLOR_I420
= MDP_COLORFMT_PACK(0, 3, 0, 1, 1, 8, 1, 0, 8),
23 MDP_COLOR_YV12
= MDP_COLORFMT_PACK(0, 3, 0, 1, 1, 8, 1, 1, 8),
24 /* Mediatek proprietary format */
25 MDP_COLOR_420_MT21
= MDP_COLORFMT_PACK(5, 2, 1, 1, 1, 256, 1, 0, 12),
28 static int32_t mtk_mdp_map_color_format(int v4l2_format
)
30 switch (v4l2_format
) {
31 case V4L2_PIX_FMT_NV12M
:
32 case V4L2_PIX_FMT_NV12
:
33 return MDP_COLOR_NV12
;
34 case V4L2_PIX_FMT_MT21C
:
35 return MDP_COLOR_420_MT21
;
36 case V4L2_PIX_FMT_YUV420M
:
37 case V4L2_PIX_FMT_YUV420
:
38 return MDP_COLOR_I420
;
39 case V4L2_PIX_FMT_YVU420
:
40 return MDP_COLOR_YV12
;
43 mtk_mdp_err("Unknown format 0x%x", v4l2_format
);
45 return MDP_COLOR_UNKNOWN
;
48 void mtk_mdp_hw_set_input_addr(struct mtk_mdp_ctx
*ctx
,
49 struct mtk_mdp_addr
*addr
)
51 struct mdp_buffer
*src_buf
= &ctx
->vpu
.vsi
->src_buffer
;
54 for (i
= 0; i
< ARRAY_SIZE(addr
->addr
); i
++)
55 src_buf
->addr_mva
[i
] = (uint64_t)addr
->addr
[i
];
58 void mtk_mdp_hw_set_output_addr(struct mtk_mdp_ctx
*ctx
,
59 struct mtk_mdp_addr
*addr
)
61 struct mdp_buffer
*dst_buf
= &ctx
->vpu
.vsi
->dst_buffer
;
64 for (i
= 0; i
< ARRAY_SIZE(addr
->addr
); i
++)
65 dst_buf
->addr_mva
[i
] = (uint64_t)addr
->addr
[i
];
68 void mtk_mdp_hw_set_in_size(struct mtk_mdp_ctx
*ctx
)
70 struct mtk_mdp_frame
*frame
= &ctx
->s_frame
;
71 struct mdp_config
*config
= &ctx
->vpu
.vsi
->src_config
;
73 /* Set input pixel offset */
74 config
->crop_x
= frame
->crop
.left
;
75 config
->crop_y
= frame
->crop
.top
;
77 /* Set input cropped size */
78 config
->crop_w
= frame
->crop
.width
;
79 config
->crop_h
= frame
->crop
.height
;
81 /* Set input original size */
84 config
->w
= frame
->width
;
85 config
->h
= frame
->height
;
88 void mtk_mdp_hw_set_in_image_format(struct mtk_mdp_ctx
*ctx
)
91 struct mtk_mdp_frame
*frame
= &ctx
->s_frame
;
92 struct mdp_config
*config
= &ctx
->vpu
.vsi
->src_config
;
93 struct mdp_buffer
*src_buf
= &ctx
->vpu
.vsi
->src_buffer
;
95 src_buf
->plane_num
= frame
->fmt
->num_comp
;
96 config
->format
= mtk_mdp_map_color_format(frame
->fmt
->pixelformat
);
97 config
->w_stride
= 0; /* MDP will calculate it by color format. */
98 config
->h_stride
= 0; /* MDP will calculate it by color format. */
100 for (i
= 0; i
< src_buf
->plane_num
; i
++)
101 src_buf
->plane_size
[i
] = frame
->payload
[i
];
104 void mtk_mdp_hw_set_out_size(struct mtk_mdp_ctx
*ctx
)
106 struct mtk_mdp_frame
*frame
= &ctx
->d_frame
;
107 struct mdp_config
*config
= &ctx
->vpu
.vsi
->dst_config
;
109 config
->crop_x
= frame
->crop
.left
;
110 config
->crop_y
= frame
->crop
.top
;
111 config
->crop_w
= frame
->crop
.width
;
112 config
->crop_h
= frame
->crop
.height
;
115 config
->w
= frame
->width
;
116 config
->h
= frame
->height
;
119 void mtk_mdp_hw_set_out_image_format(struct mtk_mdp_ctx
*ctx
)
122 struct mtk_mdp_frame
*frame
= &ctx
->d_frame
;
123 struct mdp_config
*config
= &ctx
->vpu
.vsi
->dst_config
;
124 struct mdp_buffer
*dst_buf
= &ctx
->vpu
.vsi
->dst_buffer
;
126 dst_buf
->plane_num
= frame
->fmt
->num_comp
;
127 config
->format
= mtk_mdp_map_color_format(frame
->fmt
->pixelformat
);
128 config
->w_stride
= 0; /* MDP will calculate it by color format. */
129 config
->h_stride
= 0; /* MDP will calculate it by color format. */
130 for (i
= 0; i
< dst_buf
->plane_num
; i
++)
131 dst_buf
->plane_size
[i
] = frame
->payload
[i
];
134 void mtk_mdp_hw_set_rotation(struct mtk_mdp_ctx
*ctx
)
136 struct mdp_config_misc
*misc
= &ctx
->vpu
.vsi
->misc
;
138 misc
->orientation
= ctx
->ctrls
.rotate
->val
;
139 misc
->hflip
= ctx
->ctrls
.hflip
->val
;
140 misc
->vflip
= ctx
->ctrls
.vflip
->val
;
143 void mtk_mdp_hw_set_global_alpha(struct mtk_mdp_ctx
*ctx
)
145 struct mdp_config_misc
*misc
= &ctx
->vpu
.vsi
->misc
;
147 misc
->alpha
= ctx
->ctrls
.global_alpha
->val
;