1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2013 Texas Instruments Inc.
5 * David Griego, <dagriego@biglakesoftware.com>
6 * Dale Farnsworth, <dale@farnsworth.org>
7 * Archit Taneja, <archit@ti.com>
13 #define VPDMA_MAX_NUM_LIST 8
15 * A vpdma_buf tracks the size, DMA address and mapping status of each
25 struct vpdma_desc_list
{
34 struct platform_device
*pdev
;
37 bool hwlist_used
[VPDMA_MAX_NUM_LIST
];
38 void *hwlist_priv
[VPDMA_MAX_NUM_LIST
];
39 /* callback to VPE driver when the firmware is loaded */
40 void (*cb
)(struct platform_device
*pdev
);
43 enum vpdma_data_format_type
{
44 VPDMA_DATA_FMT_TYPE_YUV
,
45 VPDMA_DATA_FMT_TYPE_RGB
,
46 VPDMA_DATA_FMT_TYPE_MISC
,
49 struct vpdma_data_format
{
50 enum vpdma_data_format_type type
;
55 #define VPDMA_DESC_ALIGN 16 /* 16-byte descriptor alignment */
56 #define VPDMA_STRIDE_ALIGN 16 /*
57 * line stride of source and dest
58 * buffers should be 16 byte aligned
60 #define VPDMA_MAX_STRIDE 65520 /* Max line stride 16 byte aligned */
61 #define VPDMA_DTD_DESC_SIZE 32 /* 8 words */
62 #define VPDMA_CFD_CTD_DESC_SIZE 16 /* 4 words */
64 #define VPDMA_LIST_TYPE_NORMAL 0
65 #define VPDMA_LIST_TYPE_SELF_MODIFYING 1
66 #define VPDMA_LIST_TYPE_DOORBELL 2
68 enum vpdma_yuv_formats
{
69 VPDMA_DATA_FMT_Y444
= 0,
76 VPDMA_DATA_FMT_YCR422
,
78 VPDMA_DATA_FMT_CRY422
,
79 VPDMA_DATA_FMT_CBY422
,
80 VPDMA_DATA_FMT_YCB422
,
83 enum vpdma_rgb_formats
{
84 VPDMA_DATA_FMT_RGB565
= 0,
85 VPDMA_DATA_FMT_ARGB16_1555
,
86 VPDMA_DATA_FMT_ARGB16
,
87 VPDMA_DATA_FMT_RGBA16_5551
,
88 VPDMA_DATA_FMT_RGBA16
,
89 VPDMA_DATA_FMT_ARGB24
,
91 VPDMA_DATA_FMT_ARGB32
,
92 VPDMA_DATA_FMT_RGBA24
,
93 VPDMA_DATA_FMT_RGBA32
,
94 VPDMA_DATA_FMT_BGR565
,
95 VPDMA_DATA_FMT_ABGR16_1555
,
96 VPDMA_DATA_FMT_ABGR16
,
97 VPDMA_DATA_FMT_BGRA16_5551
,
98 VPDMA_DATA_FMT_BGRA16
,
99 VPDMA_DATA_FMT_ABGR24
,
100 VPDMA_DATA_FMT_BGR24
,
101 VPDMA_DATA_FMT_ABGR32
,
102 VPDMA_DATA_FMT_BGRA24
,
103 VPDMA_DATA_FMT_BGRA32
,
106 enum vpdma_raw_formats
{
107 VPDMA_DATA_FMT_RAW8
= 0,
108 VPDMA_DATA_FMT_RAW16
,
111 enum vpdma_misc_formats
{
112 VPDMA_DATA_FMT_MV
= 0,
115 extern const struct vpdma_data_format vpdma_yuv_fmts
[];
116 extern const struct vpdma_data_format vpdma_rgb_fmts
[];
117 extern const struct vpdma_data_format vpdma_raw_fmts
[];
118 extern const struct vpdma_data_format vpdma_misc_fmts
[];
120 enum vpdma_frame_start_event
{
121 VPDMA_FSEVENT_HDMI_FID
= 0,
122 VPDMA_FSEVENT_DVO2_FID
,
123 VPDMA_FSEVENT_HDCOMP_FID
,
124 VPDMA_FSEVENT_SD_FID
,
125 VPDMA_FSEVENT_LM_FID0
,
126 VPDMA_FSEVENT_LM_FID1
,
127 VPDMA_FSEVENT_LM_FID2
,
128 VPDMA_FSEVENT_CHANNEL_ACTIVE
,
131 /* max width configurations */
132 enum vpdma_max_width
{
133 MAX_OUT_WIDTH_UNLIMITED
= 0,
143 /* max height configurations */
144 enum vpdma_max_height
{
145 MAX_OUT_HEIGHT_UNLIMITED
= 0,
156 * VPDMA channel numbers
172 #define VIP_CHAN_VIP2_OFFSET 70
173 #define VIP_CHAN_MULT_PORTB_OFFSET 16
174 #define VIP_CHAN_YUV_PORTB_OFFSET 2
175 #define VIP_CHAN_RGB_PORTB_OFFSET 1
177 #define VPDMA_MAX_CHANNELS 256
179 /* flags for VPDMA data descriptors */
180 #define VPDMA_DATA_ODD_LINE_SKIP (1 << 0)
181 #define VPDMA_DATA_EVEN_LINE_SKIP (1 << 1)
182 #define VPDMA_DATA_FRAME_1D (1 << 2)
183 #define VPDMA_DATA_MODE_TILED (1 << 3)
186 * client identifiers used for configuration descriptors
188 #define CFD_MMR_CLIENT 0
189 #define CFD_SC_CLIENT 4
191 /* Address data block header format */
192 struct vpdma_adb_hdr
{
199 /* helpers for creating ADB headers for config descriptors MMRs as client */
200 #define ADB_ADDR(dma_buf, str, fld) ((dma_buf)->addr + offsetof(str, fld))
201 #define MMR_ADB_ADDR(buf, str, fld) ADB_ADDR(&(buf), struct str, fld)
203 #define VPDMA_SET_MMR_ADB_HDR(buf, str, hdr, regs, offset_a) \
205 struct vpdma_adb_hdr *h; \
206 struct str *adb = NULL; \
207 h = MMR_ADB_ADDR(buf, str, hdr); \
208 h->offset = (offset_a); \
209 h->nwords = sizeof(adb->regs) >> 2; \
212 /* vpdma descriptor buffer allocation and management */
213 int vpdma_alloc_desc_buf(struct vpdma_buf
*buf
, size_t size
);
214 void vpdma_free_desc_buf(struct vpdma_buf
*buf
);
215 int vpdma_map_desc_buf(struct vpdma_data
*vpdma
, struct vpdma_buf
*buf
);
216 void vpdma_unmap_desc_buf(struct vpdma_data
*vpdma
, struct vpdma_buf
*buf
);
218 /* vpdma descriptor list funcs */
219 int vpdma_create_desc_list(struct vpdma_desc_list
*list
, size_t size
, int type
);
220 void vpdma_reset_desc_list(struct vpdma_desc_list
*list
);
221 void vpdma_free_desc_list(struct vpdma_desc_list
*list
);
222 int vpdma_submit_descs(struct vpdma_data
*vpdma
, struct vpdma_desc_list
*list
,
224 bool vpdma_list_busy(struct vpdma_data
*vpdma
, int list_num
);
225 void vpdma_update_dma_addr(struct vpdma_data
*vpdma
,
226 struct vpdma_desc_list
*list
, dma_addr_t dma_addr
,
227 void *write_dtd
, int drop
, int idx
);
229 /* VPDMA hardware list funcs */
230 int vpdma_hwlist_alloc(struct vpdma_data
*vpdma
, void *priv
);
231 void *vpdma_hwlist_get_priv(struct vpdma_data
*vpdma
, int list_num
);
232 void *vpdma_hwlist_release(struct vpdma_data
*vpdma
, int list_num
);
234 /* helpers for creating vpdma descriptors */
235 void vpdma_add_cfd_block(struct vpdma_desc_list
*list
, int client
,
236 struct vpdma_buf
*blk
, u32 dest_offset
);
237 void vpdma_add_cfd_adb(struct vpdma_desc_list
*list
, int client
,
238 struct vpdma_buf
*adb
);
239 void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list
*list
,
240 enum vpdma_channel chan
);
241 void vpdma_add_abort_channel_ctd(struct vpdma_desc_list
*list
,
243 void vpdma_add_out_dtd(struct vpdma_desc_list
*list
, int width
,
244 int stride
, const struct v4l2_rect
*c_rect
,
245 const struct vpdma_data_format
*fmt
, dma_addr_t dma_addr
,
246 int max_w
, int max_h
, enum vpdma_channel chan
, u32 flags
);
247 void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list
*list
, int width
,
248 int stride
, const struct v4l2_rect
*c_rect
,
249 const struct vpdma_data_format
*fmt
, dma_addr_t dma_addr
,
250 int max_w
, int max_h
, int raw_vpdma_chan
, u32 flags
);
252 void vpdma_add_in_dtd(struct vpdma_desc_list
*list
, int width
,
253 int stride
, const struct v4l2_rect
*c_rect
,
254 const struct vpdma_data_format
*fmt
, dma_addr_t dma_addr
,
255 enum vpdma_channel chan
, int field
, u32 flags
, int frame_width
,
256 int frame_height
, int start_h
, int start_v
);
257 int vpdma_list_cleanup(struct vpdma_data
*vpdma
, int list_num
,
258 int *channels
, int size
);
260 /* vpdma list interrupt management */
261 void vpdma_enable_list_complete_irq(struct vpdma_data
*vpdma
, int irq_num
,
262 int list_num
, bool enable
);
263 void vpdma_clear_list_stat(struct vpdma_data
*vpdma
, int irq_num
,
265 unsigned int vpdma_get_list_stat(struct vpdma_data
*vpdma
, int irq_num
);
266 unsigned int vpdma_get_list_mask(struct vpdma_data
*vpdma
, int irq_num
);
268 /* vpdma client configuration */
269 void vpdma_set_line_mode(struct vpdma_data
*vpdma
, int line_mode
,
270 enum vpdma_channel chan
);
271 void vpdma_set_frame_start_event(struct vpdma_data
*vpdma
,
272 enum vpdma_frame_start_event fs_event
, enum vpdma_channel chan
);
273 void vpdma_set_max_size(struct vpdma_data
*vpdma
, int reg_addr
,
274 u32 width
, u32 height
);
276 void vpdma_set_bg_color(struct vpdma_data
*vpdma
,
277 struct vpdma_data_format
*fmt
, u32 color
);
278 void vpdma_dump_regs(struct vpdma_data
*vpdma
);
280 /* initialize vpdma, passed with VPE's platform device pointer */
281 int vpdma_create(struct platform_device
*pdev
, struct vpdma_data
*vpdma
,
282 void (*cb
)(struct platform_device
*pdev
));