.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Coda multi-standard codec IP |
---|
3 | 4 | * |
---|
.. | .. |
---|
5 | 6 | * Javier Martin, <javier.martin@vista-silicon.com> |
---|
6 | 7 | * Xavier Duret |
---|
7 | 8 | * Copyright (C) 2012-2014 Philipp Zabel, Pengutronix |
---|
8 | | - * |
---|
9 | | - * This program is free software; you can redistribute it and/or modify |
---|
10 | | - * it under the terms of the GNU General Public License as published by |
---|
11 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
12 | | - * (at your option) any later version. |
---|
13 | 9 | */ |
---|
14 | 10 | |
---|
15 | 11 | #ifndef __CODA_H__ |
---|
.. | .. |
---|
73 | 69 | |
---|
74 | 70 | struct coda_dev { |
---|
75 | 71 | struct v4l2_device v4l2_dev; |
---|
76 | | - struct video_device vfd[5]; |
---|
77 | | - struct platform_device *plat_dev; |
---|
| 72 | + struct video_device vfd[6]; |
---|
| 73 | + struct device *dev; |
---|
78 | 74 | const struct coda_devtype *devtype; |
---|
79 | 75 | int firmware; |
---|
80 | 76 | struct vdoa_data *vdoa; |
---|
.. | .. |
---|
90 | 86 | struct gen_pool *iram_pool; |
---|
91 | 87 | struct coda_aux_buf iram; |
---|
92 | 88 | |
---|
93 | | - spinlock_t irqlock; |
---|
94 | 89 | struct mutex dev_mutex; |
---|
95 | 90 | struct mutex coda_mutex; |
---|
96 | 91 | struct workqueue_struct *workqueue; |
---|
97 | 92 | struct v4l2_m2m_dev *m2m_dev; |
---|
98 | | - struct list_head instances; |
---|
99 | 93 | struct ida ida; |
---|
100 | 94 | struct dentry *debugfs_root; |
---|
101 | 95 | }; |
---|
.. | .. |
---|
119 | 113 | u8 h264_disable_deblocking_filter_idc; |
---|
120 | 114 | s8 h264_slice_alpha_c0_offset_div2; |
---|
121 | 115 | s8 h264_slice_beta_offset_div2; |
---|
| 116 | + bool h264_constrained_intra_pred_flag; |
---|
| 117 | + s8 h264_chroma_qp_index_offset; |
---|
122 | 118 | u8 h264_profile_idc; |
---|
123 | 119 | u8 h264_level_idc; |
---|
| 120 | + u8 mpeg2_profile_idc; |
---|
| 121 | + u8 mpeg2_level_idc; |
---|
124 | 122 | u8 mpeg4_intra_qp; |
---|
125 | 123 | u8 mpeg4_inter_qp; |
---|
126 | 124 | u8 gop_size; |
---|
127 | 125 | int intra_refresh; |
---|
| 126 | + enum v4l2_jpeg_chroma_subsampling jpeg_chroma_subsampling; |
---|
128 | 127 | u8 jpeg_quality; |
---|
129 | 128 | u8 jpeg_restart_interval; |
---|
130 | 129 | u8 *jpeg_qmat_tab[3]; |
---|
| 130 | + int jpeg_qmat_index[3]; |
---|
| 131 | + int jpeg_huff_dc_index[3]; |
---|
| 132 | + int jpeg_huff_ac_index[3]; |
---|
| 133 | + u32 *jpeg_huff_data; |
---|
| 134 | + struct coda_huff_tab *jpeg_huff_tab; |
---|
131 | 135 | int codec_mode; |
---|
132 | 136 | int codec_mode_aux; |
---|
133 | 137 | enum v4l2_mpeg_video_multi_slice_mode slice_mode; |
---|
.. | .. |
---|
138 | 142 | u32 slice_max_bits; |
---|
139 | 143 | u32 slice_max_mb; |
---|
140 | 144 | bool force_ipicture; |
---|
| 145 | + bool gop_size_changed; |
---|
| 146 | + bool bitrate_changed; |
---|
| 147 | + bool framerate_changed; |
---|
| 148 | + bool h264_intra_qp_changed; |
---|
| 149 | + bool intra_refresh_changed; |
---|
| 150 | + bool slice_mode_changed; |
---|
| 151 | + bool frame_rc_enable; |
---|
| 152 | + bool mb_rc_enable; |
---|
141 | 153 | }; |
---|
142 | 154 | |
---|
143 | 155 | struct coda_buffer_meta { |
---|
.. | .. |
---|
145 | 157 | u32 sequence; |
---|
146 | 158 | struct v4l2_timecode timecode; |
---|
147 | 159 | u64 timestamp; |
---|
148 | | - u32 start; |
---|
149 | | - u32 end; |
---|
| 160 | + unsigned int start; |
---|
| 161 | + unsigned int end; |
---|
| 162 | + bool last; |
---|
150 | 163 | }; |
---|
151 | 164 | |
---|
152 | 165 | /* Per-queue, driver-specific private data */ |
---|
.. | .. |
---|
186 | 199 | int (*prepare_run)(struct coda_ctx *ctx); |
---|
187 | 200 | void (*finish_run)(struct coda_ctx *ctx); |
---|
188 | 201 | void (*run_timeout)(struct coda_ctx *ctx); |
---|
| 202 | + void (*seq_init_work)(struct work_struct *work); |
---|
189 | 203 | void (*seq_end_work)(struct work_struct *work); |
---|
190 | 204 | void (*release)(struct coda_ctx *ctx); |
---|
| 205 | +}; |
---|
| 206 | + |
---|
| 207 | +struct coda_internal_frame { |
---|
| 208 | + struct coda_aux_buf buf; |
---|
| 209 | + struct coda_buffer_meta meta; |
---|
| 210 | + u32 type; |
---|
| 211 | + u32 error; |
---|
191 | 212 | }; |
---|
192 | 213 | |
---|
193 | 214 | struct coda_ctx { |
---|
194 | 215 | struct coda_dev *dev; |
---|
195 | 216 | struct mutex buffer_mutex; |
---|
196 | | - struct list_head list; |
---|
197 | 217 | struct work_struct pic_run_work; |
---|
| 218 | + struct work_struct seq_init_work; |
---|
198 | 219 | struct work_struct seq_end_work; |
---|
199 | 220 | struct completion completion; |
---|
200 | 221 | const struct coda_video_device *cvd; |
---|
.. | .. |
---|
217 | 238 | struct v4l2_ctrl_handler ctrls; |
---|
218 | 239 | struct v4l2_ctrl *h264_profile_ctrl; |
---|
219 | 240 | struct v4l2_ctrl *h264_level_ctrl; |
---|
| 241 | + struct v4l2_ctrl *mpeg2_profile_ctrl; |
---|
| 242 | + struct v4l2_ctrl *mpeg2_level_ctrl; |
---|
| 243 | + struct v4l2_ctrl *mpeg4_profile_ctrl; |
---|
| 244 | + struct v4l2_ctrl *mpeg4_level_ctrl; |
---|
220 | 245 | struct v4l2_fh fh; |
---|
221 | 246 | int gopcounter; |
---|
222 | 247 | int runcounter; |
---|
| 248 | + int jpeg_ecs_offset; |
---|
223 | 249 | char vpu_header[3][64]; |
---|
224 | 250 | int vpu_header_size[3]; |
---|
225 | 251 | struct kfifo bitstream_fifo; |
---|
.. | .. |
---|
229 | 255 | struct coda_aux_buf parabuf; |
---|
230 | 256 | struct coda_aux_buf psbuf; |
---|
231 | 257 | struct coda_aux_buf slicebuf; |
---|
232 | | - struct coda_aux_buf internal_frames[CODA_MAX_FRAMEBUFFERS]; |
---|
233 | | - u32 frame_types[CODA_MAX_FRAMEBUFFERS]; |
---|
234 | | - struct coda_buffer_meta frame_metas[CODA_MAX_FRAMEBUFFERS]; |
---|
235 | | - u32 frame_errors[CODA_MAX_FRAMEBUFFERS]; |
---|
| 258 | + struct coda_internal_frame internal_frames[CODA_MAX_FRAMEBUFFERS]; |
---|
236 | 259 | struct list_head buffer_meta_list; |
---|
237 | 260 | spinlock_t buffer_meta_lock; |
---|
238 | 261 | int num_metas; |
---|
.. | .. |
---|
245 | 268 | u32 bit_stream_param; |
---|
246 | 269 | u32 frm_dis_flg; |
---|
247 | 270 | u32 frame_mem_ctrl; |
---|
| 271 | + u32 para_change; |
---|
248 | 272 | int display_idx; |
---|
249 | 273 | struct dentry *debugfs_entry; |
---|
250 | 274 | bool use_bit; |
---|
251 | 275 | bool use_vdoa; |
---|
252 | 276 | struct vdoa_ctx *vdoa; |
---|
| 277 | + /* |
---|
| 278 | + * wakeup mutex used to serialize encoder stop command and finish_run, |
---|
| 279 | + * ensures that finish_run always either flags the last returned buffer |
---|
| 280 | + * or wakes up the capture queue to signal EOS afterwards. |
---|
| 281 | + */ |
---|
| 282 | + struct mutex wakeup_mutex; |
---|
253 | 283 | }; |
---|
254 | 284 | |
---|
255 | 285 | extern int coda_debug; |
---|
| 286 | + |
---|
| 287 | +#define coda_dbg(level, ctx, fmt, arg...) \ |
---|
| 288 | + do { \ |
---|
| 289 | + if (coda_debug >= (level)) \ |
---|
| 290 | + v4l2_dbg((level), coda_debug, &(ctx)->dev->v4l2_dev, \ |
---|
| 291 | + "%u: " fmt, (ctx)->idx, ##arg); \ |
---|
| 292 | + } while (0) |
---|
256 | 293 | |
---|
257 | 294 | void coda_write(struct coda_dev *dev, u32 data, u32 reg); |
---|
258 | 295 | unsigned int coda_read(struct coda_dev *dev, u32 reg); |
---|
.. | .. |
---|
296 | 333 | return kfifo_len(&ctx->bitstream_fifo); |
---|
297 | 334 | } |
---|
298 | 335 | |
---|
| 336 | +/* |
---|
| 337 | + * The bitstream prefetcher needs to read at least 2 256 byte periods past |
---|
| 338 | + * the desired bitstream position for all data to reach the decoder. |
---|
| 339 | + */ |
---|
| 340 | +static inline bool coda_bitstream_can_fetch_past(struct coda_ctx *ctx, |
---|
| 341 | + unsigned int pos) |
---|
| 342 | +{ |
---|
| 343 | + return (int)(ctx->bitstream_fifo.kfifo.in - ALIGN(pos, 256)) > 512; |
---|
| 344 | +} |
---|
| 345 | + |
---|
| 346 | +bool coda_bitstream_can_fetch_past(struct coda_ctx *ctx, unsigned int pos); |
---|
| 347 | +int coda_bitstream_flush(struct coda_ctx *ctx); |
---|
| 348 | + |
---|
299 | 349 | void coda_bit_stream_end_flag(struct coda_ctx *ctx); |
---|
300 | 350 | |
---|
301 | 351 | void coda_m2m_buf_done(struct coda_ctx *ctx, struct vb2_v4l2_buffer *buf, |
---|
.. | .. |
---|
309 | 359 | int coda_h264_sps_fixup(struct coda_ctx *ctx, int width, int height, char *buf, |
---|
310 | 360 | int *size, int max_size); |
---|
311 | 361 | |
---|
| 362 | +int coda_mpeg2_profile(int profile_idc); |
---|
| 363 | +int coda_mpeg2_level(int level_idc); |
---|
| 364 | +u32 coda_mpeg2_parse_headers(struct coda_ctx *ctx, u8 *buf, u32 size); |
---|
| 365 | +int coda_mpeg4_profile(int profile_idc); |
---|
| 366 | +int coda_mpeg4_level(int level_idc); |
---|
| 367 | +u32 coda_mpeg4_parse_headers(struct coda_ctx *ctx, u8 *buf, u32 size); |
---|
| 368 | + |
---|
| 369 | +void coda_update_profile_level_ctrls(struct coda_ctx *ctx, u8 profile_idc, |
---|
| 370 | + u8 level_idc); |
---|
| 371 | + |
---|
312 | 372 | bool coda_jpeg_check_buffer(struct coda_ctx *ctx, struct vb2_buffer *vb); |
---|
| 373 | +int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb); |
---|
313 | 374 | int coda_jpeg_write_tables(struct coda_ctx *ctx); |
---|
314 | 375 | void coda_set_jpeg_compression_quality(struct coda_ctx *ctx, int quality); |
---|
315 | 376 | |
---|
316 | 377 | extern const struct coda_context_ops coda_bit_encode_ops; |
---|
317 | 378 | extern const struct coda_context_ops coda_bit_decode_ops; |
---|
| 379 | +extern const struct coda_context_ops coda9_jpeg_encode_ops; |
---|
| 380 | +extern const struct coda_context_ops coda9_jpeg_decode_ops; |
---|
318 | 381 | |
---|
319 | 382 | irqreturn_t coda_irq_handler(int irq, void *data); |
---|
| 383 | +irqreturn_t coda9_jpeg_irq_handler(int irq, void *data); |
---|
320 | 384 | |
---|
321 | 385 | #endif /* __CODA_H__ */ |
---|