Skip to content

Commit bcb40cc

Browse files
Rahi374pinchartl
authored andcommitted
media: rkisp1: Support setting memory stride for main path
Some versions of the ISP supported by the rkisp1 driver, such as the ISP in the i.MX8MP, implement configurable memory stride for the main path the same way as already implemented by the driver for the self path. Support this feature by adding a main stride feature flag and program the corresponding registers accordingly. Signed-off-by: Laurent Pinchart <[email protected]> Signed-off-by: Paul Elder <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Tested-by: Alexander Stein <[email protected]> Tested-by: Adam Ford <[email protected]> Reviewed-by: Tomi Valkeinen <[email protected]>
1 parent 900f667 commit bcb40cc

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@ static void rkisp1_mp_config(struct rkisp1_capture *cap)
442442
rkisp1_write(rkisp1, cap->config->mi.cr_size_init,
443443
rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_CR));
444444

445+
if (rkisp1_has_feature(rkisp1, MAIN_STRIDE)) {
446+
rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_LLENGTH, cap->stride);
447+
rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_WIDTH, pixm->width);
448+
rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_HEIGHT, pixm->height);
449+
rkisp1_write(rkisp1, RKISP1_CIF_MI_MP_Y_PIC_SIZE,
450+
cap->stride * pixm->height);
451+
}
452+
445453
rkisp1_irq_frame_end_enable(cap);
446454

447455
/* set uv swapping for semiplanar formats */
@@ -479,11 +487,11 @@ static void rkisp1_sp_config(struct rkisp1_capture *cap)
479487
rkisp1_write(rkisp1, cap->config->mi.cr_size_init,
480488
rkisp1_pixfmt_comp_size(pixm, RKISP1_PLANE_CR));
481489

482-
rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_LLENGTH, cap->sp_y_stride);
490+
rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_LLENGTH, cap->stride);
483491
rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_WIDTH, pixm->width);
484492
rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_HEIGHT, pixm->height);
485493
rkisp1_write(rkisp1, RKISP1_CIF_MI_SP_Y_PIC_SIZE,
486-
cap->sp_y_stride * pixm->height);
494+
cap->stride * pixm->height);
487495

488496
rkisp1_irq_frame_end_enable(cap);
489497

@@ -1092,8 +1100,8 @@ static const struct vb2_ops rkisp1_vb2_ops = {
10921100
*/
10931101

10941102
static const struct v4l2_format_info *
1095-
rkisp1_fill_pixfmt(struct v4l2_pix_format_mplane *pixm,
1096-
enum rkisp1_stream_id id)
1103+
rkisp1_fill_pixfmt(const struct rkisp1_capture *cap,
1104+
struct v4l2_pix_format_mplane *pixm)
10971105
{
10981106
struct v4l2_plane_pix_format *plane_y = &pixm->plane_fmt[0];
10991107
const struct v4l2_format_info *info;
@@ -1106,10 +1114,13 @@ rkisp1_fill_pixfmt(struct v4l2_pix_format_mplane *pixm,
11061114

11071115
/*
11081116
* The SP supports custom strides, expressed as a number of pixels for
1109-
* the Y plane. Clamp the stride to a reasonable value to avoid integer
1110-
* overflows when calculating the bytesperline and sizeimage values.
1117+
* the Y plane, and so does the MP in ISP versions that have the
1118+
* MAIN_STRIDE feature. Clamp the stride to a reasonable value to avoid
1119+
* integer overflows when calculating the bytesperline and sizeimage
1120+
* values.
11111121
*/
1112-
if (id == RKISP1_SELFPATH)
1122+
if (cap->id == RKISP1_SELFPATH ||
1123+
rkisp1_has_feature(cap->rkisp1, MAIN_STRIDE))
11131124
stride = clamp(DIV_ROUND_UP(plane_y->bytesperline, info->bpp[0]),
11141125
pixm->width, 65536U);
11151126
else
@@ -1184,7 +1195,7 @@ static void rkisp1_try_fmt(const struct rkisp1_capture *cap,
11841195
pixm->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
11851196
pixm->quantization = V4L2_QUANTIZATION_DEFAULT;
11861197

1187-
info = rkisp1_fill_pixfmt(pixm, cap->id);
1198+
info = rkisp1_fill_pixfmt(cap, pixm);
11881199

11891200
if (fmt_cfg)
11901201
*fmt_cfg = fmt;
@@ -1196,12 +1207,9 @@ static void rkisp1_set_fmt(struct rkisp1_capture *cap,
11961207
struct v4l2_pix_format_mplane *pixm)
11971208
{
11981209
rkisp1_try_fmt(cap, pixm, &cap->pix.cfg, &cap->pix.info);
1199-
cap->pix.fmt = *pixm;
12001210

1201-
/* SP supports custom stride in number of pixels of the Y plane */
1202-
if (cap->id == RKISP1_SELFPATH)
1203-
cap->sp_y_stride = pixm->plane_fmt[0].bytesperline /
1204-
cap->pix.info->bpp[0];
1211+
cap->pix.fmt = *pixm;
1212+
cap->stride = pixm->plane_fmt[0].bytesperline / cap->pix.info->bpp[0];
12051213
}
12061214

12071215
static int rkisp1_try_fmt_vid_cap_mplane(struct file *file, void *fh,

drivers/media/platform/rockchip/rkisp1/rkisp1-common.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ enum rkisp1_isp_pad {
110110
* enum rkisp1_feature - ISP features
111111
*
112112
* @RKISP1_FEATURE_MIPI_CSI2: The ISP has an internal MIPI CSI-2 receiver
113+
* @RKISP1_FEATURE_MAIN_STRIDE: The ISP supports configurable stride on the main path
113114
*
114115
* The ISP features are stored in a bitmask in &rkisp1_info.features and allow
115116
* the driver to implement support for features present in some ISP versions
116117
* only.
117118
*/
118119
enum rkisp1_feature {
119120
RKISP1_FEATURE_MIPI_CSI2 = BIT(0),
121+
RKISP1_FEATURE_MAIN_STRIDE = BIT(1),
120122
};
121123

122124
#define rkisp1_has_feature(rkisp1, feature) \
@@ -266,7 +268,7 @@ struct rkisp1_device;
266268
* handler to stop the streaming by waiting on the 'done' wait queue.
267269
* If the irq handler is not called, the stream is stopped by the callback
268270
* after timeout.
269-
* @sp_y_stride: the selfpath allows to configure a y stride that is longer than the image width.
271+
* @stride: the line stride for the first plane, in pixel units
270272
* @buf.lock: lock to protect buf.queue
271273
* @buf.queue: queued buffer list
272274
* @buf.dummy: dummy space to store dropped data
@@ -287,7 +289,7 @@ struct rkisp1_capture {
287289
bool is_streaming;
288290
bool is_stopping;
289291
wait_queue_head_t done;
290-
unsigned int sp_y_stride;
292+
unsigned int stride;
291293
struct {
292294
/* protects queue, curr and next */
293295
spinlock_t lock;

drivers/media/platform/rockchip/rkisp1/rkisp1-regs.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,24 @@
207207
#define RKISP1_CIF_MI_XTD_FMT_CTRL_SP_CB_CR_SWAP BIT(1)
208208
#define RKISP1_CIF_MI_XTD_FMT_CTRL_DMA_CB_CR_SWAP BIT(2)
209209

210+
/* MI_OUTPUT_ALIGN_FORMAT */
211+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_LSB_ALIGNMENT BIT(0)
212+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_BYTES BIT(1)
213+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_WORDS BIT(2)
214+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_MP_BYTE_SWAP_DWORDS BIT(3)
215+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_BYTES BIT(4)
216+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_WORDS BIT(5)
217+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_SP_BYTE_SWAP_DWORDS BIT(6)
218+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_DMA_BYTE_SWAP_BYTES BIT(7)
219+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_DMA_BYTE_SWAP_WORDS BIT(8)
220+
#define RKISP1_CIF_OUTPUT_ALIGN_FORMAT_DMA_BYTE_SWAP_DWORDS BIT(9)
221+
222+
/* MI_MP_OUTPUT_FIFO_SIZE */
223+
#define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_FULL (0 << 0)
224+
#define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_HALF (1 << 0)
225+
#define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_QUARTER (2 << 0)
226+
#define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE_OUTPUT_FIFO_DEPTH_EIGHT (3 << 0)
227+
210228
/* VI_CCL */
211229
#define RKISP1_CIF_CCL_CIF_CLK_DIS BIT(2)
212230
/* VI_ISP_CLK_CTRL */
@@ -1000,6 +1018,15 @@
10001018
#define RKISP1_CIF_MI_SP_CB_BASE_AD_INIT2 (RKISP1_CIF_MI_BASE + 0x00000140)
10011019
#define RKISP1_CIF_MI_SP_CR_BASE_AD_INIT2 (RKISP1_CIF_MI_BASE + 0x00000144)
10021020
#define RKISP1_CIF_MI_XTD_FORMAT_CTRL (RKISP1_CIF_MI_BASE + 0x00000148)
1021+
#define RKISP1_CIF_MI_MP_HANDSHAKE_0 (RKISP1_CIF_MI_BASE + 0x0000014C)
1022+
#define RKISP1_CIF_MI_MP_Y_LLENGTH (RKISP1_CIF_MI_BASE + 0x00000150)
1023+
#define RKISP1_CIF_MI_MP_Y_SLICE_OFFSET (RKISP1_CIF_MI_BASE + 0x00000154)
1024+
#define RKISP1_CIF_MI_MP_C_SLICE_OFFSET (RKISP1_CIF_MI_BASE + 0x00000158)
1025+
#define RKISP1_CIF_MI_OUTPUT_ALIGN_FORMAT (RKISP1_CIF_MI_BASE + 0x0000015C)
1026+
#define RKISP1_CIF_MI_MP_OUTPUT_FIFO_SIZE (RKISP1_CIF_MI_BASE + 0x00000160)
1027+
#define RKISP1_CIF_MI_MP_Y_PIC_WIDTH (RKISP1_CIF_MI_BASE + 0x00000164)
1028+
#define RKISP1_CIF_MI_MP_Y_PIC_HEIGHT (RKISP1_CIF_MI_BASE + 0x00000168)
1029+
#define RKISP1_CIF_MI_MP_Y_PIC_SIZE (RKISP1_CIF_MI_BASE + 0x0000016C)
10031030

10041031
#define RKISP1_CIF_SMIA_BASE 0x00001a00
10051032
#define RKISP1_CIF_SMIA_CTRL (RKISP1_CIF_SMIA_BASE + 0x00000000)

0 commit comments

Comments
 (0)