| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 MediaTek Inc. |
|---|
| 3 | 4 | * Author: Ming Hsiu Tsai <minghsiu.tsai@mediatek.com> |
|---|
| 4 | 5 | * Rick Chang <rick.chang@mediatek.com> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 8 | | - * published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | | - * GNU General Public License for more details. |
|---|
| 6 | + * Xia Jiang <xia.jiang@mediatek.com> |
|---|
| 14 | 7 | */ |
|---|
| 15 | 8 | |
|---|
| 16 | 9 | #ifndef _MTK_JPEG_CORE_H |
|---|
| .. | .. |
|---|
| 23 | 16 | |
|---|
| 24 | 17 | #define MTK_JPEG_NAME "mtk-jpeg" |
|---|
| 25 | 18 | |
|---|
| 26 | | -#define MTK_JPEG_FMT_FLAG_DEC_OUTPUT BIT(0) |
|---|
| 27 | | -#define MTK_JPEG_FMT_FLAG_DEC_CAPTURE BIT(1) |
|---|
| 19 | +#define MTK_JPEG_COMP_MAX 3 |
|---|
| 28 | 20 | |
|---|
| 29 | | -#define MTK_JPEG_FMT_TYPE_OUTPUT 1 |
|---|
| 30 | | -#define MTK_JPEG_FMT_TYPE_CAPTURE 2 |
|---|
| 21 | +#define MTK_JPEG_FMT_FLAG_OUTPUT BIT(0) |
|---|
| 22 | +#define MTK_JPEG_FMT_FLAG_CAPTURE BIT(1) |
|---|
| 31 | 23 | |
|---|
| 32 | | -#define MTK_JPEG_MIN_WIDTH 32 |
|---|
| 33 | | -#define MTK_JPEG_MIN_HEIGHT 32 |
|---|
| 34 | | -#define MTK_JPEG_MAX_WIDTH 8192 |
|---|
| 35 | | -#define MTK_JPEG_MAX_HEIGHT 8192 |
|---|
| 24 | +#define MTK_JPEG_MIN_WIDTH 32U |
|---|
| 25 | +#define MTK_JPEG_MIN_HEIGHT 32U |
|---|
| 26 | +#define MTK_JPEG_MAX_WIDTH 65535U |
|---|
| 27 | +#define MTK_JPEG_MAX_HEIGHT 65535U |
|---|
| 36 | 28 | |
|---|
| 37 | 29 | #define MTK_JPEG_DEFAULT_SIZEIMAGE (1 * 1024 * 1024) |
|---|
| 38 | 30 | |
|---|
| 31 | +#define MTK_JPEG_HW_TIMEOUT_MSEC 1000 |
|---|
| 32 | + |
|---|
| 33 | +#define MTK_JPEG_MAX_EXIF_SIZE (64 * 1024) |
|---|
| 34 | + |
|---|
| 35 | +/** |
|---|
| 36 | + * enum mtk_jpeg_ctx_state - states of the context state machine |
|---|
| 37 | + * @MTK_JPEG_INIT: current state is initialized |
|---|
| 38 | + * @MTK_JPEG_RUNNING: current state is running |
|---|
| 39 | + * @MTK_JPEG_SOURCE_CHANGE: current state is source resolution change |
|---|
| 40 | + */ |
|---|
| 39 | 41 | enum mtk_jpeg_ctx_state { |
|---|
| 40 | 42 | MTK_JPEG_INIT = 0, |
|---|
| 41 | 43 | MTK_JPEG_RUNNING, |
|---|
| 42 | 44 | MTK_JPEG_SOURCE_CHANGE, |
|---|
| 45 | +}; |
|---|
| 46 | + |
|---|
| 47 | +/** |
|---|
| 48 | + * mtk_jpeg_variant - mtk jpeg driver variant |
|---|
| 49 | + * @clks: clock names |
|---|
| 50 | + * @num_clks: numbers of clock |
|---|
| 51 | + * @format: jpeg driver's internal color format |
|---|
| 52 | + * @num_format: number of format |
|---|
| 53 | + * @qops: the callback of jpeg vb2_ops |
|---|
| 54 | + * @irq_handler: jpeg irq handler callback |
|---|
| 55 | + * @hw_reset: jpeg hardware reset callback |
|---|
| 56 | + * @m2m_ops: the callback of jpeg v4l2_m2m_ops |
|---|
| 57 | + * @dev_name: jpeg device name |
|---|
| 58 | + * @ioctl_ops: the callback of jpeg v4l2_ioctl_ops |
|---|
| 59 | + * @out_q_default_fourcc: output queue default fourcc |
|---|
| 60 | + * @cap_q_default_fourcc: capture queue default fourcc |
|---|
| 61 | + */ |
|---|
| 62 | +struct mtk_jpeg_variant { |
|---|
| 63 | + struct clk_bulk_data *clks; |
|---|
| 64 | + int num_clks; |
|---|
| 65 | + struct mtk_jpeg_fmt *formats; |
|---|
| 66 | + int num_formats; |
|---|
| 67 | + const struct vb2_ops *qops; |
|---|
| 68 | + irqreturn_t (*irq_handler)(int irq, void *priv); |
|---|
| 69 | + void (*hw_reset)(void __iomem *base); |
|---|
| 70 | + const struct v4l2_m2m_ops *m2m_ops; |
|---|
| 71 | + const char *dev_name; |
|---|
| 72 | + const struct v4l2_ioctl_ops *ioctl_ops; |
|---|
| 73 | + u32 out_q_default_fourcc; |
|---|
| 74 | + u32 cap_q_default_fourcc; |
|---|
| 43 | 75 | }; |
|---|
| 44 | 76 | |
|---|
| 45 | 77 | /** |
|---|
| .. | .. |
|---|
| 51 | 83 | * @v4l2_dev: v4l2 device for mem2mem mode |
|---|
| 52 | 84 | * @m2m_dev: v4l2 mem2mem device data |
|---|
| 53 | 85 | * @alloc_ctx: videobuf2 memory allocator's context |
|---|
| 54 | | - * @dec_vdev: video device node for decoder mem2mem mode |
|---|
| 55 | | - * @dec_reg_base: JPEG registers mapping |
|---|
| 56 | | - * @clk_jdec: JPEG hw working clock |
|---|
| 57 | | - * @clk_jdec_smi: JPEG SMI bus clock |
|---|
| 86 | + * @vdev: video device node for jpeg mem2mem mode |
|---|
| 87 | + * @reg_base: JPEG registers mapping |
|---|
| 58 | 88 | * @larb: SMI device |
|---|
| 89 | + * @job_timeout_work: IRQ timeout structure |
|---|
| 90 | + * @variant: driver variant to be used |
|---|
| 59 | 91 | */ |
|---|
| 60 | 92 | struct mtk_jpeg_dev { |
|---|
| 61 | 93 | struct mutex lock; |
|---|
| .. | .. |
|---|
| 65 | 97 | struct v4l2_device v4l2_dev; |
|---|
| 66 | 98 | struct v4l2_m2m_dev *m2m_dev; |
|---|
| 67 | 99 | void *alloc_ctx; |
|---|
| 68 | | - struct video_device *dec_vdev; |
|---|
| 69 | | - void __iomem *dec_reg_base; |
|---|
| 70 | | - struct clk *clk_jdec; |
|---|
| 71 | | - struct clk *clk_jdec_smi; |
|---|
| 100 | + struct video_device *vdev; |
|---|
| 101 | + void __iomem *reg_base; |
|---|
| 72 | 102 | struct device *larb; |
|---|
| 103 | + struct delayed_work job_timeout_work; |
|---|
| 104 | + const struct mtk_jpeg_variant *variant; |
|---|
| 73 | 105 | }; |
|---|
| 74 | 106 | |
|---|
| 75 | 107 | /** |
|---|
| 76 | 108 | * struct jpeg_fmt - driver's internal color format data |
|---|
| 77 | 109 | * @fourcc: the fourcc code, 0 if not applicable |
|---|
| 110 | + * @hw_format: hardware format value |
|---|
| 78 | 111 | * @h_sample: horizontal sample count of plane in 4 * 4 pixel image |
|---|
| 79 | 112 | * @v_sample: vertical sample count of plane in 4 * 4 pixel image |
|---|
| 80 | 113 | * @colplanes: number of color planes (1 for packed formats) |
|---|
| .. | .. |
|---|
| 84 | 117 | */ |
|---|
| 85 | 118 | struct mtk_jpeg_fmt { |
|---|
| 86 | 119 | u32 fourcc; |
|---|
| 120 | + u32 hw_format; |
|---|
| 87 | 121 | int h_sample[VIDEO_MAX_PLANES]; |
|---|
| 88 | 122 | int v_sample[VIDEO_MAX_PLANES]; |
|---|
| 89 | 123 | int colplanes; |
|---|
| .. | .. |
|---|
| 95 | 129 | /** |
|---|
| 96 | 130 | * mtk_jpeg_q_data - parameters of one queue |
|---|
| 97 | 131 | * @fmt: driver-specific format of this queue |
|---|
| 98 | | - * @w: image width |
|---|
| 99 | | - * @h: image height |
|---|
| 100 | | - * @bytesperline: distance in bytes between the leftmost pixels in two adjacent |
|---|
| 101 | | - * lines |
|---|
| 102 | | - * @sizeimage: image buffer size in bytes |
|---|
| 132 | + * @pix_mp: multiplanar format |
|---|
| 133 | + * @enc_crop_rect: jpeg encoder crop information |
|---|
| 103 | 134 | */ |
|---|
| 104 | 135 | struct mtk_jpeg_q_data { |
|---|
| 105 | 136 | struct mtk_jpeg_fmt *fmt; |
|---|
| 106 | | - u32 w; |
|---|
| 107 | | - u32 h; |
|---|
| 108 | | - u32 bytesperline[VIDEO_MAX_PLANES]; |
|---|
| 109 | | - u32 sizeimage[VIDEO_MAX_PLANES]; |
|---|
| 137 | + struct v4l2_pix_format_mplane pix_mp; |
|---|
| 138 | + struct v4l2_rect enc_crop_rect; |
|---|
| 110 | 139 | }; |
|---|
| 111 | 140 | |
|---|
| 112 | 141 | /** |
|---|
| .. | .. |
|---|
| 115 | 144 | * @out_q: source (output) queue information |
|---|
| 116 | 145 | * @cap_q: destination (capture) queue queue information |
|---|
| 117 | 146 | * @fh: V4L2 file handle |
|---|
| 118 | | - * @dec_param parameters for HW decoding |
|---|
| 119 | 147 | * @state: state of the context |
|---|
| 120 | | - * @header_valid: set if header has been parsed and valid |
|---|
| 121 | | - * @colorspace: enum v4l2_colorspace; supplemental to pixelformat |
|---|
| 122 | | - * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding |
|---|
| 123 | | - * @quantization: enum v4l2_quantization, colorspace quantization |
|---|
| 124 | | - * @xfer_func: enum v4l2_xfer_func, colorspace transfer function |
|---|
| 148 | + * @enable_exif: enable exif mode of jpeg encoder |
|---|
| 149 | + * @enc_quality: jpeg encoder quality |
|---|
| 150 | + * @restart_interval: jpeg encoder restart interval |
|---|
| 151 | + * @ctrl_hdl: controls handler |
|---|
| 125 | 152 | */ |
|---|
| 126 | 153 | struct mtk_jpeg_ctx { |
|---|
| 127 | 154 | struct mtk_jpeg_dev *jpeg; |
|---|
| .. | .. |
|---|
| 129 | 156 | struct mtk_jpeg_q_data cap_q; |
|---|
| 130 | 157 | struct v4l2_fh fh; |
|---|
| 131 | 158 | enum mtk_jpeg_ctx_state state; |
|---|
| 132 | | - |
|---|
| 133 | | - enum v4l2_colorspace colorspace; |
|---|
| 134 | | - enum v4l2_ycbcr_encoding ycbcr_enc; |
|---|
| 135 | | - enum v4l2_quantization quantization; |
|---|
| 136 | | - enum v4l2_xfer_func xfer_func; |
|---|
| 159 | + bool enable_exif; |
|---|
| 160 | + u8 enc_quality; |
|---|
| 161 | + u8 restart_interval; |
|---|
| 162 | + struct v4l2_ctrl_handler ctrl_hdl; |
|---|
| 137 | 163 | }; |
|---|
| 138 | 164 | |
|---|
| 139 | 165 | #endif /* _MTK_JPEG_CORE_H */ |
|---|