Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: imx-jpeg: Add encoder ops layer for hardware abstraction

Introduce mxc_jpeg_enc_ops function pointer structure to abstract
encoder configuration differences between hardware versions.

Extract the existing two-phase manual configuration into dedicated
functions (enter_config_mode/exit_config_mode) for v0 hardware.
Add setup_desc callback placeholder for future v1 hardware support
which will use descriptor-based configuration.

Store the extended sequential mode flag in the context to avoid
recalculating it during configuration phases.

No functional change.

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Ming Qian and committed by
Hans Verkuil
03b5048a 80930797

+58 -9
+47 -9
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
··· 64 64 #include "mxc-jpeg-hw.h" 65 65 #include "mxc-jpeg.h" 66 66 67 + #define call_void_jpeg_enc_ops(jpeg, op, args...) \ 68 + do { \ 69 + if ((jpeg)->enc_cfg_ops && (jpeg)->enc_cfg_ops->op) \ 70 + (jpeg)->enc_cfg_ops->op(args); \ 71 + } while (0) 72 + 67 73 static const struct mxc_jpeg_fmt mxc_formats[] = { 68 74 { 69 75 .name = "JPEG", ··· 1036 1030 1037 1031 if (jpeg->mode == MXC_JPEG_ENCODE && 1038 1032 ctx->enc_state == MXC_JPEG_ENC_CONF) { 1039 - q_data = mxc_jpeg_get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); 1040 - ctx->enc_state = MXC_JPEG_ENCODING; 1041 - dev_dbg(dev, "Encoder config finished. Start encoding...\n"); 1042 - mxc_jpeg_enc_set_quality(dev, reg, ctx->jpeg_quality); 1043 - mxc_jpeg_enc_mode_go(dev, reg, mxc_jpeg_is_extended_sequential(q_data->fmt)); 1033 + call_void_jpeg_enc_ops(jpeg, exit_config_mode, ctx); 1044 1034 goto job_unlock; 1045 1035 } 1046 1036 if (jpeg->mode == MXC_JPEG_DECODE && jpeg_src_buf->dht_needed && ··· 1274 1272 1275 1273 jpeg_src_buf = vb2_to_mxc_buf(src_buf); 1276 1274 1275 + ctx->extseq = mxc_jpeg_is_extended_sequential(jpeg_src_buf->fmt); 1277 1276 /* setup the decoding descriptor */ 1278 1277 desc->next_descpt_ptr = 0; /* end of chain */ 1279 1278 q_data_cap = mxc_jpeg_get_q_data(ctx, cap_type); ··· 1338 1335 struct mxc_jpeg_q_data *q_data; 1339 1336 enum mxc_jpeg_image_format img_fmt; 1340 1337 int w, h; 1338 + bool extseq; 1341 1339 1342 1340 q_data = mxc_jpeg_get_q_data(ctx, src_buf->vb2_queue->type); 1341 + extseq = mxc_jpeg_is_extended_sequential(q_data->fmt); 1342 + 1343 + ctx->extseq = extseq; 1343 1344 1344 1345 memset(desc, 0, sizeof(struct mxc_jpeg_desc)); 1345 1346 memset(cfg_desc, 0, sizeof(struct mxc_jpeg_desc)); ··· 1376 1369 desc->stm_ctrl = STM_CTRL_CONFIG_MOD(0) | 1377 1370 STM_CTRL_IMAGE_FORMAT(img_fmt); 1378 1371 desc->stm_ctrl |= STM_CTRL_BITBUF_PTR_CLR(1); 1379 - if (mxc_jpeg_is_extended_sequential(q_data->fmt)) 1372 + if (extseq) 1380 1373 desc->stm_ctrl |= STM_CTRL_PIXEL_PRECISION; 1381 1374 else 1382 1375 desc->stm_ctrl &= ~STM_CTRL_PIXEL_PRECISION; 1383 1376 mxc_jpeg_addrs(desc, src_buf, dst_buf, 0); 1377 + 1378 + call_void_jpeg_enc_ops(jpeg, setup_desc, ctx); 1379 + 1384 1380 dev_dbg(jpeg->dev, "cfg_desc:\n"); 1385 1381 print_descriptor_info(jpeg->dev, cfg_desc); 1386 1382 dev_dbg(jpeg->dev, "enc desc:\n"); ··· 1394 1384 /* validate the configuration descriptor */ 1395 1385 mxc_jpeg_set_desc(cfg_desc_handle, reg, slot); 1396 1386 } 1387 + 1388 + static void mxc_jpeg_enc_start_config_manually(struct mxc_jpeg_ctx *ctx) 1389 + { 1390 + struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; 1391 + void __iomem *reg = jpeg->base_reg; 1392 + struct device *dev = jpeg->dev; 1393 + 1394 + ctx->enc_state = MXC_JPEG_ENC_CONF; 1395 + mxc_jpeg_enc_mode_conf(dev, reg, ctx->extseq); 1396 + } 1397 + 1398 + static void mxc_jpeg_enc_finish_config_manually(struct mxc_jpeg_ctx *ctx) 1399 + { 1400 + struct mxc_jpeg_dev *jpeg = ctx->mxc_jpeg; 1401 + void __iomem *reg = jpeg->base_reg; 1402 + struct device *dev = jpeg->dev; 1403 + 1404 + ctx->enc_state = MXC_JPEG_ENCODING; 1405 + dev_dbg(dev, "Encoder config finished. Start encoding...\n"); 1406 + mxc_jpeg_enc_set_quality(dev, reg, ctx->jpeg_quality); 1407 + mxc_jpeg_enc_mode_go(dev, reg, ctx->extseq); 1408 + } 1409 + 1410 + static const struct mxc_jpeg_enc_ops mxc_jpeg_enc_cfg_ops_v0 = { 1411 + .enter_config_mode = mxc_jpeg_enc_start_config_manually, 1412 + .exit_config_mode = mxc_jpeg_enc_finish_config_manually 1413 + }; 1397 1414 1398 1415 static const struct mxc_jpeg_fmt *mxc_jpeg_get_sibling_format(const struct mxc_jpeg_fmt *fmt) 1399 1416 { ··· 1627 1590 1628 1591 if (jpeg->mode == MXC_JPEG_ENCODE) { 1629 1592 dev_dbg(dev, "Encoding on slot %d\n", ctx->slot); 1630 - ctx->enc_state = MXC_JPEG_ENC_CONF; 1631 1593 mxc_jpeg_config_enc_desc(&dst_buf->vb2_buf, ctx, 1632 1594 &src_buf->vb2_buf, &dst_buf->vb2_buf); 1633 1595 /* start config phase */ 1634 - mxc_jpeg_enc_mode_conf(dev, reg, 1635 - mxc_jpeg_is_extended_sequential(q_data_out->fmt)); 1596 + call_void_jpeg_enc_ops(jpeg, enter_config_mode, ctx); 1636 1597 } else { 1637 1598 dev_dbg(dev, "Decoding on slot %d\n", ctx->slot); 1638 1599 print_mxc_buf(jpeg, &src_buf->vb2_buf, 0); ··· 3011 2976 dev_err(dev, "Failed to enable runtime PM: %d\n", ret); 3012 2977 goto err_pm; 3013 2978 } 2979 + 2980 + if (mode == MXC_JPEG_ENCODE) 2981 + jpeg->enc_cfg_ops = &mxc_jpeg_enc_cfg_ops_v0; 3014 2982 3015 2983 return 0; 3016 2984
+11
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h
··· 105 105 unsigned int source_change; 106 106 bool need_initial_source_change_evt; 107 107 bool header_parsed; 108 + bool extseq; 108 109 struct v4l2_ctrl_handler ctrl_handler; 109 110 u8 jpeg_quality; 110 111 struct delayed_work task_timer; ··· 126 125 dma_addr_t cfg_dec_daddr; 127 126 }; 128 127 128 + struct mxc_jpeg_enc_ops { 129 + /* Manual configuration (v0 hardware) - two-phase process */ 130 + void (*enter_config_mode)(struct mxc_jpeg_ctx *ctx); 131 + void (*exit_config_mode)(struct mxc_jpeg_ctx *ctx); 132 + 133 + /* Descriptor-based configuration (v1 hardware) - single-phase */ 134 + void (*setup_desc)(struct mxc_jpeg_ctx *ctx); 135 + }; 136 + 129 137 struct mxc_jpeg_dev { 130 138 spinlock_t hw_lock; /* hardware access lock */ 131 139 unsigned int mode; ··· 152 142 struct device **pd_dev; 153 143 struct device_link **pd_link; 154 144 struct gen_pool *sram_pool; 145 + const struct mxc_jpeg_enc_ops *enc_cfg_ops; 155 146 }; 156 147 157 148 /**