Lines Matching +full:10918 +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Coda multi-standard codec IP - JPEG support functions
16 #include <media/v4l2-common.h>
17 #include <media/v4l2-fh.h>
18 #include <media/v4l2-jpeg.h>
19 #include <media/v4l2-mem2mem.h>
20 #include <media/videobuf2-core.h>
21 #include <media/videobuf2-dma-contig.h>
58 * Typical Huffman tables for 8-bit precision luminance and
59 * chrominance from JPEG ITU-T.81 (ISO/IEC 10918-1) Annex K.3
105 0xf9, 0xfa, /* padded to 32-bit */
133 0xf9, 0xfa, /* padded to 32-bit */
138 * zig-zag scan order from the Freescale i.MX VPU libraries
192 return -EINVAL; in coda9_jpeg_chroma_format()
204 u32 *dst = parabuf + desc->offset; in coda_memcpy_parabuf()
205 const u32 *src = desc->src; in coda_memcpy_parabuf()
206 int len = desc->len / 4; in coda_memcpy_parabuf()
210 dst[i + 1] = swab32(src[i]); in coda_memcpy_parabuf()
211 dst[i] = swab32(src[i + 1]); in coda_memcpy_parabuf()
225 { 512, ctx->params.jpeg_qmat_tab[0], 64 }, in coda_jpeg_write_tables()
226 { 576, ctx->params.jpeg_qmat_tab[1], 64 }, in coda_jpeg_write_tables()
227 { 640, ctx->params.jpeg_qmat_tab[1], 64 }, in coda_jpeg_write_tables()
232 coda_memcpy_parabuf(ctx->parabuf.vaddr, huff + i); in coda_jpeg_write_tables()
234 /* Write Q-matrix to parameter memory */ in coda_jpeg_write_tables()
236 coda_memcpy_parabuf(ctx->parabuf.vaddr, qmat + i); in coda_jpeg_write_tables()
252 vaddr += len - 2; in coda_jpeg_check_buffer()
254 eoi = be16_to_cpup((__be16 *)(vaddr - i)); in coda_jpeg_check_buffer()
257 vb2_set_plane_payload(vb, 0, len - i); in coda_jpeg_check_buffer()
269 struct coda_dev *dev = ctx->dev; in coda_jpeg_decode_header()
286 v4l2_err(&dev->v4l2_dev, "failed to parse JPEG header: %pe\n", in coda_jpeg_decode_header()
291 ctx->params.jpeg_restart_interval = header.restart_interval; in coda_jpeg_decode_header()
294 if (header.frame.height > ctx->codec->max_h || in coda_jpeg_decode_header()
295 header.frame.width > ctx->codec->max_w) { in coda_jpeg_decode_header()
296 v4l2_err(&dev->v4l2_dev, "invalid dimensions: %dx%d\n", in coda_jpeg_decode_header()
298 return -EINVAL; in coda_jpeg_decode_header()
302 if (header.frame.height != q_data_src->height || in coda_jpeg_decode_header()
303 header.frame.width != q_data_src->width) { in coda_jpeg_decode_header()
304 v4l2_err(&dev->v4l2_dev, in coda_jpeg_decode_header()
307 return -EINVAL; in coda_jpeg_decode_header()
311 v4l2_err(&dev->v4l2_dev, in coda_jpeg_decode_header()
314 return -EINVAL; in coda_jpeg_decode_header()
319 v4l2_err(&dev->v4l2_dev, in coda_jpeg_decode_header()
321 return -EINVAL; in coda_jpeg_decode_header()
327 v4l2_err(&dev->v4l2_dev, in coda_jpeg_decode_header()
328 "only 8-bit quantization tables supported\n"); in coda_jpeg_decode_header()
331 if (!ctx->params.jpeg_qmat_tab[i]) { in coda_jpeg_decode_header()
332 ctx->params.jpeg_qmat_tab[i] = kmalloc(64, GFP_KERNEL); in coda_jpeg_decode_header()
333 if (!ctx->params.jpeg_qmat_tab[i]) in coda_jpeg_decode_header()
334 return -ENOMEM; in coda_jpeg_decode_header()
336 memcpy(ctx->params.jpeg_qmat_tab[i], in coda_jpeg_decode_header()
343 v4l2_err(&dev->v4l2_dev, "missing Huffman table\n"); in coda_jpeg_decode_header()
344 return -EINVAL; in coda_jpeg_decode_header()
346 /* AC tables should be between 17 -> 178, DC between 17 -> 28 */ in coda_jpeg_decode_header()
350 v4l2_err(&dev->v4l2_dev, in coda_jpeg_decode_header()
353 return -EINVAL; in coda_jpeg_decode_header()
356 huff_tab = ctx->params.jpeg_huff_tab; in coda_jpeg_decode_header()
360 return -ENOMEM; in coda_jpeg_decode_header()
361 ctx->params.jpeg_huff_tab = huff_tab; in coda_jpeg_decode_header()
365 memcpy(huff_tab->luma_dc, huffman_tables[0].start, huffman_tables[0].length); in coda_jpeg_decode_header()
366 memcpy(huff_tab->chroma_dc, huffman_tables[1].start, huffman_tables[1].length); in coda_jpeg_decode_header()
367 memcpy(huff_tab->luma_ac, huffman_tables[2].start, huffman_tables[2].length); in coda_jpeg_decode_header()
368 memcpy(huff_tab->chroma_ac, huffman_tables[3].start, huffman_tables[3].length); in coda_jpeg_decode_header()
377 scan_component->component_selector) in coda_jpeg_decode_header()
383 ctx->params.jpeg_huff_dc_index[j] = in coda_jpeg_decode_header()
384 scan_component->dc_entropy_coding_table_selector; in coda_jpeg_decode_header()
385 ctx->params.jpeg_huff_ac_index[j] = in coda_jpeg_decode_header()
386 scan_component->ac_entropy_coding_table_selector; in coda_jpeg_decode_header()
394 ctx->jpeg_ecs_offset = header.ecs_offset; in coda_jpeg_decode_header()
399 ctx->params.jpeg_chroma_subsampling = header.frame.subsampling; in coda_jpeg_decode_header()
402 v4l2_err(&dev->v4l2_dev, "chroma subsampling not supported: %d", in coda_jpeg_decode_header()
404 return -EINVAL; in coda_jpeg_decode_header()
419 values[i] = -1; in coda9_jpeg_write_huff_values()
426 struct coda_huff_tab *huff_tab = ctx->params.jpeg_huff_tab; in coda9_jpeg_dec_huff_setup()
427 struct coda_dev *dev = ctx->dev; in coda9_jpeg_dec_huff_setup()
428 s16 *huff_min = huff_tab->min; in coda9_jpeg_dec_huff_setup()
429 s16 *huff_max = huff_tab->max; in coda9_jpeg_dec_huff_setup()
430 s8 *huff_ptr = huff_tab->ptr; in coda9_jpeg_dec_huff_setup()
453 coda9_jpeg_write_huff_values(dev, huff_tab->luma_dc, 12); in coda9_jpeg_dec_huff_setup()
454 coda9_jpeg_write_huff_values(dev, huff_tab->chroma_dc, 12); in coda9_jpeg_dec_huff_setup()
455 coda9_jpeg_write_huff_values(dev, huff_tab->luma_ac, 162); in coda9_jpeg_dec_huff_setup()
456 coda9_jpeg_write_huff_values(dev, huff_tab->chroma_ac, 162); in coda9_jpeg_dec_huff_setup()
473 struct coda_dev *dev = ctx->dev; in coda9_jpeg_qmat_setup()
474 int *qmat_index = ctx->params.jpeg_qmat_index; in coda9_jpeg_qmat_setup()
475 u8 **qmat_tab = ctx->params.jpeg_qmat_tab; in coda9_jpeg_qmat_setup()
478 coda9_jpeg_write_qmat_tab(dev, qmat_tab[qmat_index[1]], 0x40); in coda9_jpeg_qmat_setup()
485 struct coda_dev *dev = ctx->dev; in coda9_jpeg_dec_bbc_gbu_setup()
496 if (page_ptr & 1) in coda9_jpeg_dec_bbc_gbu_setup()
499 if (word_ptr & 1) in coda9_jpeg_dec_bbc_gbu_setup()
506 /* Leave 3 256-byte page margin to avoid a BBC interrupt */ in coda9_jpeg_dec_bbc_gbu_setup()
515 coda_write(dev, (bbc_cur_pos & 1) << 6, CODA9_REG_JPEG_BBC_INT_ADDR); in coda9_jpeg_dec_bbc_gbu_setup()
520 } while (ret == 1); in coda9_jpeg_dec_bbc_gbu_setup()
526 coda_write(dev, (bbc_cur_pos & 1) << 6, CODA9_REG_JPEG_BBC_INT_ADDR); in coda9_jpeg_dec_bbc_gbu_setup()
531 } while (ret == 1); in coda9_jpeg_dec_bbc_gbu_setup()
535 coda_write(dev, 1, CODA9_REG_JPEG_BBC_CTRL); in coda9_jpeg_dec_bbc_gbu_setup()
541 if (page_ptr & 1) { in coda9_jpeg_dec_bbc_gbu_setup()
573 [CODA9_JPEG_FORMAT_400] = MCU_INFO(1, 1, 5, 0, 0),
578 * For reference, see JPEG ITU-T.81 (ISO/IEC 10918-1) [1]
580 * [1] https://www.w3.org/Graphics/JPEG/itu-t81.pdf
594 int ret = -EINVAL; in coda9_jpeg_gen_enc_huff_tab()
598 return -ENOMEM; in coda9_jpeg_gen_enc_huff_tab()
603 maxsymbol = tab_num & 1 ? 256 : 16; in coda9_jpeg_gen_enc_huff_tab()
605 /* Figure C.1 - Generation of table of Huffman code sizes */ in coda9_jpeg_gen_enc_huff_tab()
607 for (i = 1; i <= 16; i++) { in coda9_jpeg_gen_enc_huff_tab()
608 j = bits[i - 1]; in coda9_jpeg_gen_enc_huff_tab()
611 while (j--) in coda9_jpeg_gen_enc_huff_tab()
612 huff->size[k++] = i; in coda9_jpeg_gen_enc_huff_tab()
616 /* Figure C.2 - Generation of table of Huffman codes */ in coda9_jpeg_gen_enc_huff_tab()
619 si = huff->size[0]; in coda9_jpeg_gen_enc_huff_tab()
621 while (huff->size[k] == si) { in coda9_jpeg_gen_enc_huff_tab()
622 huff->code[k++] = code; in coda9_jpeg_gen_enc_huff_tab()
625 if (code >= (1 << si)) in coda9_jpeg_gen_enc_huff_tab()
627 code <<= 1; in coda9_jpeg_gen_enc_huff_tab()
631 /* Figure C.3 - Ordering procedure for encoding procedure code tables */ in coda9_jpeg_gen_enc_huff_tab()
636 ehufco[i] = huff->code[k]; in coda9_jpeg_gen_enc_huff_tab()
637 ehufsi[i] = huff->size[k]; in coda9_jpeg_gen_enc_huff_tab()
647 #define AC_TABLE_INDEX0 1
653 struct coda_huff_tab *huff_tab = ctx->params.jpeg_huff_tab; in coda9_jpeg_get_huff_bits()
659 case DC_TABLE_INDEX0: return huff_tab->luma_dc; in coda9_jpeg_get_huff_bits()
660 case AC_TABLE_INDEX0: return huff_tab->luma_ac; in coda9_jpeg_get_huff_bits()
661 case DC_TABLE_INDEX1: return huff_tab->chroma_dc; in coda9_jpeg_get_huff_bits()
662 case AC_TABLE_INDEX1: return huff_tab->chroma_ac; in coda9_jpeg_get_huff_bits()
680 return -EINVAL; in coda9_jpeg_gen_dec_huff_tab()
682 /* DC/AC Luma, DC/AC Chroma -> DC Luma/Chroma, AC Luma/Chroma */ in coda9_jpeg_gen_dec_huff_tab()
683 ofs = ((tab_num & 1) << 1) | ((tab_num >> 1) & 1); in coda9_jpeg_gen_dec_huff_tab()
686 huff_ptr = ctx->params.jpeg_huff_tab->ptr + ofs; in coda9_jpeg_gen_dec_huff_tab()
687 huff_max = ctx->params.jpeg_huff_tab->max + ofs; in coda9_jpeg_gen_dec_huff_tab()
688 huff_min = ctx->params.jpeg_huff_tab->min + ofs; in coda9_jpeg_gen_dec_huff_tab()
695 huff_max[i] = huff_code + (huff_bits[i] - 1); in coda9_jpeg_gen_dec_huff_tab()
696 data_flag = 1; in coda9_jpeg_gen_dec_huff_tab()
699 huff_ptr[i] = -1; in coda9_jpeg_gen_dec_huff_tab()
700 huff_min[i] = -1; in coda9_jpeg_gen_dec_huff_tab()
701 huff_max[i] = -1; in coda9_jpeg_gen_dec_huff_tab()
702 zero_flag = 1; in coda9_jpeg_gen_dec_huff_tab()
705 if (data_flag == 1) { in coda9_jpeg_gen_dec_huff_tab()
706 if (zero_flag == 1) in coda9_jpeg_gen_dec_huff_tab()
707 huff_code <<= 1; in coda9_jpeg_gen_dec_huff_tab()
709 huff_code = (huff_max[i] + 1) << 1; in coda9_jpeg_gen_dec_huff_tab()
728 return -ENOMEM; in coda9_jpeg_load_huff_tab()
732 ret = coda9_jpeg_gen_enc_huff_tab(ctx, i, huff->size[i], in coda9_jpeg_load_huff_tab()
733 huff->code[i]); in coda9_jpeg_load_huff_tab()
738 if (!ctx->params.jpeg_huff_data) { in coda9_jpeg_load_huff_tab()
739 ctx->params.jpeg_huff_data = in coda9_jpeg_load_huff_tab()
742 if (!ctx->params.jpeg_huff_data) { in coda9_jpeg_load_huff_tab()
743 ret = -ENOMEM; in coda9_jpeg_load_huff_tab()
747 huff_data = ctx->params.jpeg_huff_data; in coda9_jpeg_load_huff_tab()
752 (j == 1) ? AC_TABLE_INDEX1 : in coda9_jpeg_load_huff_tab()
759 if (huff->size[t][i] == 0 && huff->code[t][i] == 0) in coda9_jpeg_load_huff_tab()
763 ((huff->size[t][i] - 1) << 16) | in coda9_jpeg_load_huff_tab()
764 huff->code[t][i]; in coda9_jpeg_load_huff_tab()
776 struct coda_dev *dev = ctx->dev; in coda9_jpeg_write_huff_tab()
777 u32 *huff_data = ctx->params.jpeg_huff_data; in coda9_jpeg_write_huff_tab()
800 struct coda_dev *dev = ctx->dev; in coda9_jpeg_load_qmat_tab()
804 luma_tab = ctx->params.jpeg_qmat_tab[0]; in coda9_jpeg_load_qmat_tab()
808 chroma_tab = ctx->params.jpeg_qmat_tab[1]; in coda9_jpeg_load_qmat_tab()
824 if (stream->curr >= stream->end) in coda_jpeg_put_byte()
825 return -EINVAL; in coda_jpeg_put_byte()
827 *stream->curr++ = byte; in coda_jpeg_put_byte()
834 if (stream->curr + sizeof(__be16) > stream->end) in coda_jpeg_put_word()
835 return -EINVAL; in coda_jpeg_put_word()
837 put_unaligned_be16(word, stream->curr); in coda_jpeg_put_word()
838 stream->curr += sizeof(__be16); in coda_jpeg_put_word()
865 ctx->params.jpeg_qmat_tab[index], 64, in coda_jpeg_define_quantization_table()
883 chroma_format = coda9_jpeg_chroma_format(q_data_src->fourcc); in coda9_jpeg_encode_header()
893 if (ctx->params.jpeg_restart_interval) { in coda9_jpeg_encode_header()
900 ret = coda_jpeg_put_word(ctx->params.jpeg_restart_interval, in coda9_jpeg_encode_header()
938 comp_num = (chroma_format == CODA9_JPEG_FORMAT_400) ? 1 : 3; in coda9_jpeg_encode_header()
945 ret = coda_jpeg_put_word(q_data_src->height, &stream); in coda9_jpeg_encode_header()
948 ret = coda_jpeg_put_word(q_data_src->width, &stream); in coda9_jpeg_encode_header()
964 ret = coda_jpeg_put_byte(i + 1, &stream); in coda9_jpeg_encode_header()
972 ret = coda_jpeg_put_byte((i == 0) ? 0 : 1, &stream); in coda9_jpeg_encode_header()
978 pad = (stream.curr - buf) % 8; in coda9_jpeg_encode_header()
980 pad = 8 - pad; in coda9_jpeg_encode_header()
981 while (pad--) { in coda9_jpeg_encode_header()
988 return stream.curr - buf; in coda9_jpeg_encode_header()
1003 temp = 1; in coda_scale_quant_table()
1014 ctx->params.jpeg_quality = quality; in coda_set_jpeg_compression_quality()
1023 * Non-linear scaling factor: in coda_set_jpeg_compression_quality()
1024 * [5,50] -> [1000..100], [51,100] -> [98..0] in coda_set_jpeg_compression_quality()
1029 scale = 200 - 2 * quality; in coda_set_jpeg_compression_quality()
1031 if (ctx->params.jpeg_qmat_tab[0]) { in coda_set_jpeg_compression_quality()
1032 memcpy(ctx->params.jpeg_qmat_tab[0], luma_q, 64); in coda_set_jpeg_compression_quality()
1033 coda_scale_quant_table(ctx->params.jpeg_qmat_tab[0], scale); in coda_set_jpeg_compression_quality()
1035 if (ctx->params.jpeg_qmat_tab[1]) { in coda_set_jpeg_compression_quality()
1036 memcpy(ctx->params.jpeg_qmat_tab[1], chroma_q, 64); in coda_set_jpeg_compression_quality()
1037 coda_scale_quant_table(ctx->params.jpeg_qmat_tab[1], scale); in coda_set_jpeg_compression_quality()
1047 struct coda_dev *dev = ctx->dev; in coda9_jpeg_start_encoding()
1052 v4l2_err(&dev->v4l2_dev, "error loading Huffman tables\n"); in coda9_jpeg_start_encoding()
1055 if (!ctx->params.jpeg_qmat_tab[0]) { in coda9_jpeg_start_encoding()
1056 ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL); in coda9_jpeg_start_encoding()
1057 if (!ctx->params.jpeg_qmat_tab[0]) in coda9_jpeg_start_encoding()
1058 return -ENOMEM; in coda9_jpeg_start_encoding()
1060 if (!ctx->params.jpeg_qmat_tab[1]) { in coda9_jpeg_start_encoding()
1061 ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL); in coda9_jpeg_start_encoding()
1062 if (!ctx->params.jpeg_qmat_tab[1]) in coda9_jpeg_start_encoding()
1063 return -ENOMEM; in coda9_jpeg_start_encoding()
1065 coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality); in coda9_jpeg_start_encoding()
1074 struct coda_dev *dev = ctx->dev; in coda9_jpeg_prepare_encode()
1083 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda9_jpeg_prepare_encode()
1084 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda9_jpeg_prepare_encode()
1087 if (vb2_get_plane_payload(&src_buf->vb2_buf, 0) == 0) in coda9_jpeg_prepare_encode()
1088 vb2_set_plane_payload(&src_buf->vb2_buf, 0, in coda9_jpeg_prepare_encode()
1089 vb2_plane_size(&src_buf->vb2_buf, 0)); in coda9_jpeg_prepare_encode()
1091 src_buf->sequence = ctx->osequence; in coda9_jpeg_prepare_encode()
1092 dst_buf->sequence = ctx->osequence; in coda9_jpeg_prepare_encode()
1093 ctx->osequence++; in coda9_jpeg_prepare_encode()
1095 src_buf->flags |= V4L2_BUF_FLAG_KEYFRAME; in coda9_jpeg_prepare_encode()
1096 src_buf->flags &= ~V4L2_BUF_FLAG_PFRAME; in coda9_jpeg_prepare_encode()
1100 start_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); in coda9_jpeg_prepare_encode()
1101 end_addr = start_addr + vb2_plane_size(&dst_buf->vb2_buf, 0); in coda9_jpeg_prepare_encode()
1103 chroma_format = coda9_jpeg_chroma_format(q_data_src->fourcc); in coda9_jpeg_prepare_encode()
1108 aligned_width = round_up(q_data_src->width, width_align[chroma_format]); in coda9_jpeg_prepare_encode()
1109 aligned_height = round_up(q_data_src->height, in coda9_jpeg_prepare_encode()
1111 if (aligned_width != q_data_src->bytesperline) { in coda9_jpeg_prepare_encode()
1112 v4l2_err(&dev->v4l2_dev, "wrong stride: %d instead of %d\n", in coda9_jpeg_prepare_encode()
1113 aligned_width, q_data_src->bytesperline); in coda9_jpeg_prepare_encode()
1118 vb2_plane_size(&dst_buf->vb2_buf, 0), in coda9_jpeg_prepare_encode()
1119 vb2_plane_vaddr(&dst_buf->vb2_buf, 0)); in coda9_jpeg_prepare_encode()
1128 /* 64 words per 256-byte page */ in coda9_jpeg_prepare_encode()
1136 coda_write(dev, BIT(31) | ((end_addr - start_addr - header_len) / 256), in coda9_jpeg_prepare_encode()
1144 chroma_interleave = (q_data_src->fourcc == V4L2_PIX_FMT_NV12); in coda9_jpeg_prepare_encode()
1149 coda_write(dev, ctx->params.jpeg_restart_interval, in coda9_jpeg_prepare_encode()
1151 coda_write(dev, 1, CODA9_REG_JPEG_BBC_CTRL); in coda9_jpeg_prepare_encode()
1158 if (ctx->params.rot_mode & CODA_ROT_90) { in coda9_jpeg_prepare_encode()
1160 aligned_height = q_data_src->bytesperline; in coda9_jpeg_prepare_encode()
1169 coda_write(dev, ctx->params.rot_mode ? in coda9_jpeg_prepare_encode()
1170 (CODA_ROT_MIR_ENABLE | ctx->params.rot_mode) : 0, in coda9_jpeg_prepare_encode()
1175 coda_write(dev, 1, CODA9_GDI_CONTROL); in coda9_jpeg_prepare_encode()
1180 v4l2_err(&dev->v4l2_dev, "timeout waiting for GDI\n"); in coda9_jpeg_prepare_encode()
1181 return -ETIMEDOUT; in coda9_jpeg_prepare_encode()
1186 q_data_src->bytesperline, CODA9_GDI_INFO_CONTROL); in coda9_jpeg_prepare_encode()
1195 coda_write(dev, 1, CODA9_GDI_PIC_INIT_HOST); in coda9_jpeg_prepare_encode()
1197 coda_write(dev, 1, CODA9_GDI_WPROT_ERR_CLR); in coda9_jpeg_prepare_encode()
1202 coda_write(dev, 1, CODA9_REG_JPEG_PIC_START); in coda9_jpeg_prepare_encode()
1210 struct coda_dev *dev = ctx->dev; in coda9_jpeg_finish_encode()
1214 if (ctx->aborting) { in coda9_jpeg_finish_encode()
1215 coda_write(ctx->dev, 0, CODA9_REG_JPEG_BBC_FLUSH_CMD); in coda9_jpeg_finish_encode()
1224 mutex_lock(&ctx->wakeup_mutex); in coda9_jpeg_finish_encode()
1225 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda9_jpeg_finish_encode()
1226 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda9_jpeg_finish_encode()
1234 start_ptr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); in coda9_jpeg_finish_encode()
1236 vb2_set_plane_payload(&dst_buf->vb2_buf, 0, wr_ptr - start_ptr); in coda9_jpeg_finish_encode()
1240 coda_dbg(1, ctx, "ERRMB: 0x%x\n", err_mb); in coda9_jpeg_finish_encode()
1244 dst_buf->flags &= ~(V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_LAST); in coda9_jpeg_finish_encode()
1245 dst_buf->flags |= V4L2_BUF_FLAG_KEYFRAME; in coda9_jpeg_finish_encode()
1246 dst_buf->flags |= src_buf->flags & V4L2_BUF_FLAG_LAST; in coda9_jpeg_finish_encode()
1253 mutex_unlock(&ctx->wakeup_mutex); in coda9_jpeg_finish_encode()
1255 coda_dbg(1, ctx, "job finished: encoded frame (%u)%s\n", in coda9_jpeg_finish_encode()
1256 dst_buf->sequence, in coda9_jpeg_finish_encode()
1257 (dst_buf->flags & V4L2_BUF_FLAG_LAST) ? " (last)" : ""); in coda9_jpeg_finish_encode()
1269 struct coda_dev *dev = ctx->dev; in coda9_jpeg_encode_timeout()
1275 if (wr_ptr >= end_addr - 256) { in coda9_jpeg_encode_timeout()
1276 v4l2_err(&dev->v4l2_dev, "JPEG too large for capture buffer\n"); in coda9_jpeg_encode_timeout()
1288 if (ctx->params.jpeg_qmat_tab[0] == luma_q) in coda9_jpeg_release()
1289 ctx->params.jpeg_qmat_tab[0] = NULL; in coda9_jpeg_release()
1290 if (ctx->params.jpeg_qmat_tab[1] == chroma_q) in coda9_jpeg_release()
1291 ctx->params.jpeg_qmat_tab[1] = NULL; in coda9_jpeg_release()
1293 kfree(ctx->params.jpeg_qmat_tab[i]); in coda9_jpeg_release()
1294 kfree(ctx->params.jpeg_huff_data); in coda9_jpeg_release()
1295 kfree(ctx->params.jpeg_huff_tab); in coda9_jpeg_release()
1313 ctx->params.jpeg_qmat_index[0] = 0; in coda9_jpeg_start_decoding()
1314 ctx->params.jpeg_qmat_index[1] = 1; in coda9_jpeg_start_decoding()
1315 ctx->params.jpeg_qmat_index[2] = 1; in coda9_jpeg_start_decoding()
1316 ctx->params.jpeg_qmat_tab[0] = luma_q; in coda9_jpeg_start_decoding()
1317 ctx->params.jpeg_qmat_tab[1] = chroma_q; in coda9_jpeg_start_decoding()
1329 struct coda_dev *dev = ctx->dev; in coda9_jpeg_prepare_decode()
1339 src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); in coda9_jpeg_prepare_decode()
1340 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); in coda9_jpeg_prepare_decode()
1343 dst_fourcc = q_data_dst->fourcc; in coda9_jpeg_prepare_decode()
1345 scl_hor_mode = coda_jpeg_scale(q_data_src->width, q_data_dst->width); in coda9_jpeg_prepare_decode()
1346 scl_ver_mode = coda_jpeg_scale(q_data_src->height, q_data_dst->height); in coda9_jpeg_prepare_decode()
1348 if (vb2_get_plane_payload(&src_buf->vb2_buf, 0) == 0) in coda9_jpeg_prepare_decode()
1349 vb2_set_plane_payload(&src_buf->vb2_buf, 0, in coda9_jpeg_prepare_decode()
1350 vb2_plane_size(&src_buf->vb2_buf, 0)); in coda9_jpeg_prepare_decode()
1352 chroma_format = coda9_jpeg_chroma_format(q_data_dst->fourcc); in coda9_jpeg_prepare_decode()
1356 ret = coda_jpeg_decode_header(ctx, &src_buf->vb2_buf); in coda9_jpeg_prepare_decode()
1358 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda9_jpeg_prepare_decode()
1359 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda9_jpeg_prepare_decode()
1367 aligned_width = round_up(q_data_src->width, width_align[chroma_format]); in coda9_jpeg_prepare_decode()
1368 aligned_height = round_up(q_data_src->height, height_align[chroma_format]); in coda9_jpeg_prepare_decode()
1369 if (aligned_width != q_data_dst->bytesperline) { in coda9_jpeg_prepare_decode()
1370 v4l2_err(&dev->v4l2_dev, "stride mismatch: %d != %d\n", in coda9_jpeg_prepare_decode()
1371 aligned_width, q_data_dst->bytesperline); in coda9_jpeg_prepare_decode()
1376 val = ctx->params.jpeg_huff_ac_index[0] << 12 | in coda9_jpeg_prepare_decode()
1377 ctx->params.jpeg_huff_ac_index[1] << 11 | in coda9_jpeg_prepare_decode()
1378 ctx->params.jpeg_huff_ac_index[2] << 10 | in coda9_jpeg_prepare_decode()
1379 ctx->params.jpeg_huff_dc_index[0] << 9 | in coda9_jpeg_prepare_decode()
1380 ctx->params.jpeg_huff_dc_index[1] << 8 | in coda9_jpeg_prepare_decode()
1381 ctx->params.jpeg_huff_dc_index[2] << 7; in coda9_jpeg_prepare_decode()
1382 if (ctx->params.jpeg_huff_tab) in coda9_jpeg_prepare_decode()
1399 coda_write(dev, ctx->params.jpeg_restart_interval, in coda9_jpeg_prepare_decode()
1402 if (ctx->params.jpeg_huff_tab) in coda9_jpeg_prepare_decode()
1407 coda9_jpeg_dec_bbc_gbu_setup(ctx, &src_buf->vb2_buf, in coda9_jpeg_prepare_decode()
1408 ctx->jpeg_ecs_offset); in coda9_jpeg_prepare_decode()
1419 coda_write(dev, 1, CODA9_GDI_CONTROL); in coda9_jpeg_prepare_decode()
1425 q_data_dst->bytesperline; in coda9_jpeg_prepare_decode()
1426 if (ctx->tiled_map_type == GDI_TILED_FRAME_MB_RASTER_MAP) in coda9_jpeg_prepare_decode()
1437 coda_write(dev, 1, CODA9_GDI_PIC_INIT_HOST); in coda9_jpeg_prepare_decode()
1441 coda_write(dev, 1, CODA9_REG_JPEG_PIC_START); in coda9_jpeg_prepare_decode()
1448 struct coda_dev *dev = ctx->dev; in coda9_jpeg_finish_decode()
1455 v4l2_err(&dev->v4l2_dev, "ERRMB: 0x%x\n", err_mb); in coda9_jpeg_finish_decode()
1464 mutex_lock(&ctx->wakeup_mutex); in coda9_jpeg_finish_decode()
1465 src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); in coda9_jpeg_finish_decode()
1466 dst_buf = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); in coda9_jpeg_finish_decode()
1467 dst_buf->sequence = ctx->osequence++; in coda9_jpeg_finish_decode()
1471 dst_buf->flags &= ~(V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_LAST); in coda9_jpeg_finish_decode()
1472 dst_buf->flags |= V4L2_BUF_FLAG_KEYFRAME; in coda9_jpeg_finish_decode()
1473 dst_buf->flags |= src_buf->flags & V4L2_BUF_FLAG_LAST; in coda9_jpeg_finish_decode()
1478 vb2_set_plane_payload(&dst_buf->vb2_buf, 0, q_data_dst->sizeimage); in coda9_jpeg_finish_decode()
1484 mutex_unlock(&ctx->wakeup_mutex); in coda9_jpeg_finish_decode()
1486 coda_dbg(1, ctx, "job finished: decoded frame (%u)%s\n", in coda9_jpeg_finish_decode()
1487 dst_buf->sequence, in coda9_jpeg_finish_decode()
1488 (dst_buf->flags & V4L2_BUF_FLAG_LAST) ? " (last)" : ""); in coda9_jpeg_finish_decode()
1499 .queue_init = coda_encoder_queue_init, /* non-bitstream operation */
1519 v4l2_err(&dev->v4l2_dev, "JPEG overflow\n"); in coda9_jpeg_irq_handler()
1522 v4l2_err(&dev->v4l2_dev, "JPEG BBC interrupt\n"); in coda9_jpeg_irq_handler()
1525 v4l2_err(&dev->v4l2_dev, "JPEG error\n"); in coda9_jpeg_irq_handler()
1529 v4l2_err(&dev->v4l2_dev, in coda9_jpeg_irq_handler()
1536 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); in coda9_jpeg_irq_handler()
1538 v4l2_err(&dev->v4l2_dev, in coda9_jpeg_irq_handler()
1540 mutex_unlock(&dev->coda_mutex); in coda9_jpeg_irq_handler()
1544 complete(&ctx->completion); in coda9_jpeg_irq_handler()