media: imx: Miscellaneous format-related cleanups
Steve Longerbeam
maintainerv6 cover media: imx: Miscellaneous format-related cleanups
This series picks up Laurent Pinchart's series:
[PATCH 0/8] media: imx: Miscalleanous format-related cleanups
with a merge of two patches from Philipp Zabel's series:
[PATCH 1/3] media: imx: enable V4L2_PIX_FMT_XBGR32, _BGRX32, and _RGBX32
with an additional patch at the end that splits up the find_enum_format() functions into separate functions for in-memory fourcc codes and mbus codes, as requested by Hans Verkuil in the series from Philipp.
History:
v6:
- Moved the last patch, "Split find|enum_format into fourcc and mbus functions", up in the series, which makes the patches cleaner and reduces the patch count by 1.
- "if (sel_ipu && !fmt->ipufmt) ..." should be
"if (sel_ipu != fmt->ipufmt) ...".
v5:
- Added a patch that renames the pixel format selection enums/flags.
- Added a patch that adds another format selection flag, to select the IPU-internal formats. This is an alternative to the previous patch "media: imx: utils: Simplify IPU format lookup and enumeration".
- Add comments for the struct imx_media_pixfmt members, with a warning that the codes pointer is NULL for the in-memory-only formats.
v4:
- Constify mbus arg to imx_media_mbus_fmt_to_ipu_image().
- Constify ipu_image arg to imx_media_ipu_image_to_mbus_fmt().
- Return -EINVAL in imx_media_ipu_image_to_mbus_fmt() if given image pixelformat does not have mbus codes.
v3:
- fixed derefencing a NULL cc->codes on return from imx_media_find_format() in several places.
v2:
- fixed a bug:
"for (j=0; j < fmt->codes[j]; j++)" should be
"for (j=0; fmt->codes[j]; j++)", in the mbus format enum functions. Caught by Laurent.
- move some local vars under the pixel_formats[] loop. Suggested by Laurent.
- decrement the index passed to the enum functions, instead of introducing a match_index local var. Suggested by Laurent.
Laurent Pinchart (5):
media: imx: utils: Inline init_mbus_colorimetry() in its caller
media: imx: utils: Handle Bayer format lookup through a selection flag
media: imx: utils: Make imx_media_pixfmt handle variable number of
codes
media: imx: utils: Rename format lookup and enumeration functions
media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_*
Philipp Zabel (2):
media: imx: utils: fix and simplify pixel format enumeration
media: imx: utils: fix media bus format enumeration
Steve Longerbeam (4):
media: imx: utils: Rename pixel format selection enumeration
media: imx: utils: Introduce PIXFMT_SEL_IPU
media: imx: utils: Split find|enum_format into fourcc and mbus
functions
media: imx: utils: Constify ipu_image argument to
imx_media_ipu_image_to_mbus_fmt()
drivers/staging/media/imx/imx-ic-prp.c | 13 +- drivers/staging/media/imx/imx-ic-prpencvf.c | 13 +- drivers/staging/media/imx/imx-media-capture.c | 42 +- .../staging/media/imx/imx-media-csc-scaler.c | 3 +- drivers/staging/media/imx/imx-media-csi.c | 42 +- drivers/staging/media/imx/imx-media-utils.c | 526 ++++++++---------- drivers/staging/media/imx/imx-media-vdic.c | 12 +- drivers/staging/media/imx/imx-media.h | 45 +- drivers/staging/media/imx/imx7-media-csi.c | 15 +- 9 files changed, 327 insertions(+), 384 deletions(-)
Signature · 1 line
2.17.1
Steve Longerbeam
maintainerPATCH v6 1/11 media: imx: utils: fix and simplify pixel format enumeration
From: Philipp Zabel <[email protected]>
Merge yuv_formats and rgb_formats into a single array. Always loop over all entries, skipping those that do not match the requested search criteria. This simplifies the code, lets us get rid of the manual counting of array entries, and stops accidentally ignoring some non-mbus RGB formats.
Before:
$ v4l2-ctl -d /dev/video14 --list-formats-out ioctl: VIDIOC_ENUM_FMT Type: Video Output
[0]: 'UYVY' (UYVY 4:2:2) [1]: 'YUYV' (YUYV 4:2:2) [2]: 'YU12' (Planar YUV 4:2:0) [3]: 'YV12' (Planar YVU 4:2:0) [4]: '422P' (Planar YUV 4:2:2) [5]: 'NV12' (Y/CbCr 4:2:0) [6]: 'NV16' (Y/CbCr 4:2:2) [7]: 'RGBP' (16-bit RGB 5-6-5) [8]: 'RGB3' (24-bit RGB 8-8-8) [9]: 'BX24' (32-bit XRGB 8-8-8-8)
After:
$ v4l2-ctl -d /dev/video14 --list-formats-out ioctl: VIDIOC_ENUM_FMT Type: Video Output
[0]: 'UYVY' (UYVY 4:2:2) [1]: 'YUYV' (YUYV 4:2:2) [2]: 'YU12' (Planar YUV 4:2:0) [3]: 'YV12' (Planar YVU 4:2:0) [4]: '422P' (Planar YUV 4:2:2) [5]: 'NV12' (Y/CbCr 4:2:0) [6]: 'NV16' (Y/CbCr 4:2:2) [7]: 'RGBP' (16-bit RGB 5-6-5) [8]: 'RGB3' (24-bit RGB 8-8-8) [9]: 'BGR3' (24-bit BGR 8-8-8) [10]: 'BX24' (32-bit XRGB 8-8-8-8) [11]: 'XR24' (32-bit BGRX 8-8-8-8) [12]: 'RX24' (32-bit XBGR 8-8-8-8) [13]: 'XB24' (32-bit RGBX 8-8-8-8)
--- drivers/staging/media/imx/imx-media-utils.c | 193 ++++++-------------- 1 file changed, 59 insertions(+), 134 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +59 -134
@@ -9,12 +9,9 @@/* * List of supported pixel formats for the subdevs. -* -* In all of these tables, the non-mbus formats (with no -* mbus codes) must all fall at the end of the table. */ - -static const struct imx_media_pixfmt yuv_formats[] = { +static const struct imx_media_pixfmt pixel_formats[] = { +/*** YUV formats start here ***/ { .fourcc =V4L2_PIX_FMT_UYVY , .codes = {
@@ -31,12 +28,7 @@ static const struct imx_media_pixfmt yuv_formats[] = { }, .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, - }, -/*** -* non-mbus YUV formats start here. NOTE! when adding non-mbus -* formats, NUM_NON_MBUS_YUV_FORMATS must be updated below. -***/ - { + }, { .fourcc = V4L2_PIX_FMT_YUV420, .cs = IPUV3_COLORSPACE_YUV, .bpp = 12,
@@ -62,13 +54,7 @@ static const struct imx_media_pixfmt yuv_formats[] = { .bpp = 16, .planar = true, }, -}; - -#define NUM_NON_MBUS_YUV_FORMATS 5 -#define NUM_YUV_FORMATS ARRAY_SIZE(yuv_formats) -#define NUM_MBUS_YUV_FORMATS (NUM_YUV_FORMATS - NUM_NON_MBUS_YUV_FORMATS) - -static const struct imx_media_pixfmt rgb_formats[] = { +/*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565, .codes = {MEDIA_BUS_FMT_RGB565_2X8_LE},
@@ -83,12 +69,28 @@ static const struct imx_media_pixfmt rgb_formats[] = { }, .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, + }, { + .fourcc = V4L2_PIX_FMT_BGR24, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 24, }, { .fourcc = V4L2_PIX_FMT_XRGB32, .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true, + }, { + .fourcc = V4L2_PIX_FMT_XBGR32, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, + }, { + .fourcc = V4L2_PIX_FMT_BGRX32, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, + }, { + .fourcc = V4L2_PIX_FMT_RGBX32, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, }, /*** raw bayer and grayscale formats start here ***/ {
@@ -182,33 +184,8 @@ static const struct imx_media_pixfmt rgb_formats[] = { .bpp = 16, .bayer = true, }, -/*** -* non-mbus RGB formats start here. NOTE! when adding non-mbus -* formats, NUM_NON_MBUS_RGB_FORMATS must be updated below. -***/ - { - .fourcc = V4L2_PIX_FMT_BGR24, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 24, - }, { - .fourcc = V4L2_PIX_FMT_XBGR32, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - }, { - .fourcc = V4L2_PIX_FMT_BGRX32, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - }, { - .fourcc = V4L2_PIX_FMT_RGBX32, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - }, }; -#define NUM_NON_MBUS_RGB_FORMATS 2 -#define NUM_RGB_FORMATS ARRAY_SIZE(rgb_formats) -#define NUM_MBUS_RGB_FORMATS (NUM_RGB_FORMATS - NUM_NON_MBUS_RGB_FORMATS) -static const struct imx_media_pixfmt ipu_yuv_formats[] = { { .fourcc =V4L2_PIX_FMT_YUV32 ,
@@ -246,21 +223,24 @@ static void init_mbus_colorimetry(struct v4l2_mbus_framefmt *mbus, mbus->ycbcr_enc); } -static const -struct imx_media_pixfmt *__find_format (u32 fourcc, -u32 code, -bool allow_non_mbus, -bool allow_bayer, -const struct imx_media_pixfmt *array, -u32 array_size) +static const struct imx_media_pixfmt *find_format (u32 fourcc, +u32 code, +enum codespace_sel cs_sel, +bool allow_non_mbus, +bool allow_bayer) { -const struct imx_media_pixfmt *fmt; -int i, j; +unsigned int i; -for (i =0 ; i < array_size; i++) { - fmt = &array[i]; +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) { +const struct imx_media_pixfmt *fmt = &pixel_formats[i]; +enum codespace_sel fmt_cs_sel; +unsigned int j; -if ((!allow_non_mbus && !fmt->codes[0 ]) || + fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ; + +if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]) || (!allow_bayer && fmt->bayer))continue ;
@@ -270,39 +250,13 @@ struct imx_media_pixfmt *__find_format(u32 fourcc,if (!code)continue ; -for (j =0 ; fmt->codes[j]; j++) { +for (j =0 ; j <ARRAY_SIZE (fmt->codes) && fmt->codes[j]; j++) {if (code == fmt->codes[j])return fmt; } } -return NULL ; -} -static const struct imx_media_pixfmt *find_format (u32 fourcc, -u32 code, -enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) -{ -const struct imx_media_pixfmt *ret; - -switch (cs_sel) { -case CS_SEL_YUV : -return __find_format (fourcc, code, allow_non_mbus, allow_bayer, - yuv_formats,NUM_YUV_FORMATS ); -case CS_SEL_RGB : -return __find_format (fourcc, code, allow_non_mbus, allow_bayer, - rgb_formats,NUM_RGB_FORMATS ); -case CS_SEL_ANY : - ret =__find_format (fourcc, code, allow_non_mbus, allow_bayer, - yuv_formats,NUM_YUV_FORMATS ); -if (ret) -return ret; -return __find_format (fourcc, code, allow_non_mbus, allow_bayer, - rgb_formats,NUM_RGB_FORMATS ); -default : -return NULL ; - } +return NULL ; } static int enum_format(u32 *fourcc, u32 *code, u32 index,
@@ -310,61 +264,32 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, bool allow_non_mbus, bool allow_bayer) { -const struct imx_media_pixfmt *fmt; -u32 mbus_yuv_sz =NUM_MBUS_YUV_FORMATS ; -u32 mbus_rgb_sz =NUM_MBUS_RGB_FORMATS ; -u32 yuv_sz =NUM_YUV_FORMATS ; -u32 rgb_sz =NUM_RGB_FORMATS ; +unsigned int i; -switch (cs_sel) { -case CS_SEL_YUV : -if (index >= yuv_sz || - (!allow_non_mbus && index >= mbus_yuv_sz)) -return -EINVAL ; - fmt = &yuv_formats[index]; -break ; -case CS_SEL_RGB : -if (index >= rgb_sz || - (!allow_non_mbus && index >= mbus_rgb_sz)) -return -EINVAL ; - fmt = &rgb_formats[index]; -if (!allow_bayer && fmt->bayer) -return -EINVAL ; -break ; -case CS_SEL_ANY : -if (!allow_non_mbus) { -if (index >= mbus_yuv_sz) { - index -= mbus_yuv_sz; -if (index >= mbus_rgb_sz) -return -EINVAL ; - fmt = &rgb_formats[index]; -if (!allow_bayer && fmt->bayer) -return -EINVAL ; - }else { - fmt = &yuv_formats[index]; - } - }else { -if (index >= yuv_sz + rgb_sz) -return -EINVAL ; -if (index >= yuv_sz) { - fmt = &rgb_formats[index - yuv_sz]; -if (!allow_bayer && fmt->bayer) -return -EINVAL ; - }else { - fmt = &yuv_formats[index]; - } +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) { +const struct imx_media_pixfmt *fmt = &pixel_formats[i]; +enum codespace_sel fmt_cs_sel; + + fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ; + +if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]) || + (!allow_bayer && fmt->bayer)) +continue ; + +if (index ==0 ) { +if (fourcc) + *fourcc = fmt->fourcc; +if (code) + *code = fmt->codes[0 ]; +return 0 ; } -break ; -default : -return -EINVAL ; - } -if (fourcc) - *fourcc = fmt->fourcc; -if (code) - *code = fmt->codes[0 ]; + index--; + } -return 0 ; +return -EINVAL ; } const struct imx_media_pixfmt *
Signature · 1 line
2.17.1
Steve Longerbeam
maintainerPATCH v6 2/11 media: imx: utils: fix media bus format enumeration
In reply to Steve LongerbeamFrom: Philipp Zabel <[email protected]>
Iterate over all media bus formats, not just over the first format in each imx_media_pixfmt entry.
Before:
$ v4l2-ctl -d $(media-ctl -e ipu1_csi0) --list-subdev-mbus-codes 0 ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x100a: MEDIA_BUS_FMT_RGB888_1X24 0x100d: MEDIA_BUS_FMT_ARGB8888_1X32 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x200a: MEDIA_BUS_FMT_Y10_1X10
After:
$ v4l2-ctl -d $(media-ctl -e ipu1_csi0) --list-subdev-mbus-codes 0 ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x200f: MEDIA_BUS_FMT_UYVY8_1X16 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2011: MEDIA_BUS_FMT_YUYV8_1X16 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x100a: MEDIA_BUS_FMT_RGB888_1X24 0x100c: MEDIA_BUS_FMT_RGB888_2X12_LE 0x100d: MEDIA_BUS_FMT_ARGB8888_1X32 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x3008: MEDIA_BUS_FMT_SBGGR12_1X12 0x3019: MEDIA_BUS_FMT_SBGGR14_1X14 0x301d: MEDIA_BUS_FMT_SBGGR16_1X16 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x3010: MEDIA_BUS_FMT_SGBRG12_1X12 0x301a: MEDIA_BUS_FMT_SGBRG14_1X14 0x301e: MEDIA_BUS_FMT_SGBRG16_1X16 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x3011: MEDIA_BUS_FMT_SGRBG12_1X12 0x301b: MEDIA_BUS_FMT_SGRBG14_1X14 0x301f: MEDIA_BUS_FMT_SGRBG16_1X16 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x3012: MEDIA_BUS_FMT_SRGGB12_1X12 0x301c: MEDIA_BUS_FMT_SRGGB14_1X14 0x3020: MEDIA_BUS_FMT_SRGGB16_1X16 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x200a: MEDIA_BUS_FMT_Y10_1X10 0x2013: MEDIA_BUS_FMT_Y12_1X12
--- drivers/staging/media/imx/imx-media-utils.c | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +16 -6
@@ -269,6 +269,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum codespace_sel fmt_cs_sel; +unsigned int j; fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ?CS_SEL_YUV :CS_SEL_RGB ;
@@ -278,15 +279,24 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, (!allow_bayer && fmt->bayer))continue ; -if (index ==0 ) { -if (fourcc) - *fourcc = fmt->fourcc; -if (code) - *code = fmt->codes[0 ]; +if (fourcc && index ==0 ) { + *fourcc = fmt->fourcc;return 0 ; } - index--; +if (!code) { + index--; +continue ; + } + +for (j =0 ; j <ARRAY_SIZE (fmt->codes) && fmt->codes[j]; j++) { +if (index ==0 ) { + *code = fmt->codes[j]; +return 0 ; + } + + index--; + } }return -EINVAL ;
Signature · 1 line
2.17.1
Steve Longerbeam
maintainerPATCH v6 3/11 media: imx: utils: Inline init_mbus_colorimetry() in its caller
In reply to Steve LongerbeamFrom: Laurent Pinchart <[email protected]>
The init_mbus_colorimetry() function is small and used in a single place. The code becomes easier to follow if it gets inline in its caller. Do so.
--- drivers/staging/media/imx/imx-media-utils.c | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +10 -14
@@ -210,19 +210,6 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {#define NUM_IPU_RGB_FORMATS ARRAY_SIZE(ipu_rgb_formats) -static void init_mbus_colorimetry (struct v4l2_mbus_framefmt *mbus, -const struct imx_media_pixfmt *fmt) -{ - mbus->colorspace = (fmt->cs ==IPUV3_COLORSPACE_RGB ) ? -V4L2_COLORSPACE_SRGB :V4L2_COLORSPACE_SMPTE170M ; - mbus->xfer_func =V4L2_MAP_XFER_FUNC_DEFAULT (mbus->colorspace); - mbus->ycbcr_enc =V4L2_MAP_YCBCR_ENC_DEFAULT (mbus->colorspace); - mbus->quantization = -V4L2_MAP_QUANTIZATION_DEFAULT (fmt->cs ==IPUV3_COLORSPACE_RGB , - mbus->colorspace, - mbus->ycbcr_enc); -} - static const struct imx_media_pixfmt *find_format(u32 fourcc, u32 code, enum codespace_sel cs_sel,
@@ -423,7 +410,16 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, } mbus->code = code; -init_mbus_colorimetry (mbus, lcc); + + mbus->colorspace = (lcc->cs ==IPUV3_COLORSPACE_RGB ) ? +V4L2_COLORSPACE_SRGB :V4L2_COLORSPACE_SMPTE170M ; + mbus->xfer_func =V4L2_MAP_XFER_FUNC_DEFAULT (mbus->colorspace); + mbus->ycbcr_enc =V4L2_MAP_YCBCR_ENC_DEFAULT (mbus->colorspace); + mbus->quantization = +V4L2_MAP_QUANTIZATION_DEFAULT (lcc->cs ==IPUV3_COLORSPACE_RGB , + mbus->colorspace, + mbus->ycbcr_enc); +if (cc) *cc = lcc;
Signature · 1 line
2.17.1
Steve Longerbeam
maintainerPATCH v6 4/11 media: imx: utils: Handle Bayer format lookup through a selection flag
In reply to Steve LongerbeamFrom: Laurent Pinchart <[email protected]>
The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as
return enum_format(fourcc, NULL, index, cs_sel, true, false);
where the boolean parameters can easily be mixed. To make the code clearer, add a CS_SEL_BAYER flag that can be passed through the codespace_sel parameter of the lookup functions to replace the bool parameter.
[Instead of declaring CS_SEL_ANY as a bitfield containing only
CS_SEL_YUV | CS_SEL_RGB, declare CS_SEL_ANY as all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection as CS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings. CS_SEL_ANY is now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.]
--- drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +-- drivers/staging/media/imx/imx-media-capture.c | 14 ++-- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++-- drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++---------- drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++-- 8 files changed, 70 insertions(+), 74 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +4 -4
@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :
@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN); cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); sdformat->format.code = cc->codes[0 ]; }
drivers/staging/media/imx/imx-ic-prpencvf.c +5 -4
@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=PRPENCVF_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_ANY ); +return imx_media_enum_ipu_format (&code->code, code->index, +CS_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,
@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_ANY ); + *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB );if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }
drivers/staging/media/imx/imx-media-capture.c +7 -7
@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;
@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;
@@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;
@@ -217,14 +217,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV :CS_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel);if (!cc) {imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;
@@ -790,7 +790,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY , false); +CS_SEL_ANY );v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));
drivers/staging/media/imx/imx-media-csc-scaler.c +1 -1
@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_ANY ); + ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB );if (ret)return ret;
drivers/staging/media/imx/imx-media-csi.c +6 -9
@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :
@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code, -CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;
@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN); *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 , -CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code, -CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
drivers/staging/media/imx/imx-media-utils.c +34 -34
175 lines not on this page · raw message
drivers/staging/media/imx/imx-media.h +8 -8
@@ -150,20 +150,20 @@ struct imx_media_dev { };enum codespace_sel { -CS_SEL_YUV =0 , -CS_SEL_RGB , -CS_SEL_ANY , +CS_SEL_YUV =BIT (0 ), +CS_SEL_RGB =BIT (1 ), +CS_SEL_BAYER =BIT (2 ), +CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , +CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , };/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer); +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer); +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel);
drivers/staging/media/imx/imx7-media-csi.c +5 -7
@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {
@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY , - true); + in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY ); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;
@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY , - false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
Signature · 1 line
2.17.1
Re: [PATCH v6 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag
Hi Steve,
Thank you for the patch.
Quoted 48 lines · Steve Longerbeam
From: Laurent Pinchart <[email protected]>
The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as
return enum_format(fourcc, NULL, index, cs_sel, true, false);where the boolean parameters can easily be mixed. To make the code clearer, add a
CS_SEL_BAYERflag that can be passed through thecodespace_selparameter of the lookup functions to replace the bool parameter.Signed-off-by Laurent Pinchart <[email protected]>[Instead of declaring
CS_SEL_ANYas a bitfield containing only
CS_SEL_YUV|CS_SEL_RGB, declareCS_SEL_ANYas all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection asCS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings.CS_SEL_ANYis now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.]Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +-- drivers/staging/media/imx/imx-media-capture.c | 14 ++-- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++-- drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++---------- drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++-- 8 files changed, 70 insertions(+), 74 deletions(-)drivers/staging/media/imx/imx-ic-prp.c +1
-1@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :
drivers/staging/media/imx/imx-ic-prp.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 186
Quoted 10 lines
drivers/staging/media/imx/imx-ic-prp.c +3
-3@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN); cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_ipu_format (code,CS_SEL_YUV );
Should these two be CS_SEL_YUV_RGB ?
Quoted 20 lines
drivers/staging/media/imx/imx-ic-prp.c +0
-0sdformat->format.code = cc->codes[0 ]; }drivers/staging/media/imx/imx-ic-prpencvf.c +2
-1@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=PRPENCVF_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_ANY ); +return imx_media_enum_ipu_format (&code->code, code->index, +CS_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt;
drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 894
Quoted 10 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +3
-3- *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_ANY ); + *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB );if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,CS_SEL_YUV );
And here too ?
Quoted 53 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-capture.c +6
-6@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;@@ -217,14 +217,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV :CS_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel);if (!cc) {imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;
drivers/staging/media/imx/imx-media-capture.c int imx_media_capture_device_register(struct imx_media_video_dev *vdev) · line 793
Quoted 5 lines
drivers/staging/media/imx/imx-media-capture.c +1
-1@@ -790,7 +790,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY , false); +CS_SEL_ANY );
Should this be CS_SEL_YUV_RGB too ?
Quoted 48 lines
drivers/staging/media/imx/imx-media-capture.c +0
-0v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));drivers/staging/media/imx/imx-media-csc-scaler.c +1
-1@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_ANY ); + ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB );if (ret)return ret;drivers/staging/media/imx/imx-media-csi.c +3
-4@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code, -CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN);
drivers/staging/media/imx/imx-media-csi.c static void csi_try_fmt(struct csi_priv *priv, · line 1475
Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +3
-5*cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 , -CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code, -CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );
Same here.
Quoted 147 lines
drivers/staging/media/imx/imx-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-utils.c +26
-26@@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && fmt->fourcc == fourcc)@@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,static int enum_format (u32 *fourcc,u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && index ==0 ) {@@ -290,30 +288,28 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, }const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer) +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel) { -return find_format (fourcc,0 , cs_sel, true, allow_bayer); +return find_format (fourcc,0 , cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_find_format);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel) { -return enum_format (fourcc,NULL , index, cs_sel, true, false); +return enum_format (fourcc,NULL , index, cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_enum_format);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer) +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel) { -return find_format (0 , code, cs_sel, false, allow_bayer); +return find_format (0 , code, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer) +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel) { -return enum_format (NULL , code, index, cs_sel, false, allow_bayer); +return enum_format (NULL , code, index, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);@@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)u32 array_size;int i, j; + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV : array_size =NUM_IPU_YUV_FORMATS ;@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) array_size =NUM_IPU_RGB_FORMATS ; array = ipu_rgb_formats;break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB : array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; array = ipu_yuv_formats;break ;@@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) }for (i =0 ; i < array_size; i++) { -if (cs_sel ==CS_SEL_ANY && i >=NUM_IPU_YUV_FORMATS ) +if (cs_sel ==CS_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ];else fmt = &array[i];@@ -362,6 +360,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel) { + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV :if (index >=NUM_IPU_YUV_FORMATS )@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)return -EINVAL ; *code = ipu_rgb_formats[index].codes[0 ];break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB :if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS )return -EINVAL ;if (index >=NUM_IPU_YUV_FORMATS ) {
drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 405
Quoted 7 lines
drivers/staging/media/imx/imx-media-utils.c +2
-2@@ -401,8 +401,8 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->height = height; mbus->field = field;if (code ==0 ) -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - lcc =imx_media_find_mbus_format (code,CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + lcc =imx_media_find_mbus_format (code,CS_SEL_ANY );
And here.
Quoted 101 lines
drivers/staging/media/imx/imx-media-utils.c +6
-6if (!lcc) { lcc =imx_media_find_ipu_format (code,CS_SEL_ANY );if (!lcc)@@ -473,7 +473,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,const struct imx_media_pixfmt *cc;bool is_rgb = false; - cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY , true); + cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY );if (!cc) cc =imx_media_find_ipu_format (tryfmt->code,CS_SEL_ANY );if (cc && cc->cs ==IPUV3_COLORSPACE_RGB )@@ -527,8 +527,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (!cc) { cc =imx_media_find_ipu_format (mbus->code,CS_SEL_ANY );if (!cc) - cc =imx_media_find_mbus_format (mbus->code,CS_SEL_ANY , - true); + cc =imx_media_find_mbus_format (mbus->code, +CS_SEL_ANY );if (!cc)return -EINVAL ; }@@ -540,8 +540,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (cc->ipufmt && cc->cs ==IPUV3_COLORSPACE_YUV ) {u32 code; -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - cc =imx_media_find_mbus_format (code,CS_SEL_YUV , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_mbus_format (code,CS_SEL_YUV ); }/* Round up width for minimum burst size */ @@ -592,7 +592,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, {const struct imx_media_pixfmt *fmt; - fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY , true); + fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY );if (!fmt)return -EINVAL ;drivers/staging/media/imx/imx-media.h +8
-8@@ -150,20 +150,20 @@ struct imx_media_dev { };enum codespace_sel { -CS_SEL_YUV =0 , -CS_SEL_RGB , -CS_SEL_ANY , +CS_SEL_YUV =BIT (0 ), +CS_SEL_RGB =BIT (1 ), +CS_SEL_BAYER =BIT (2 ), +CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , +CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , };/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer); +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer); +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel);drivers/staging/media/imx/imx7-media-csi.c +2
-3@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY , - true); + in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY ); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;
drivers/staging/media/imx/imx7-media-csi.c static int imx7_csi_try_fmt(struct imx7_csi *csi, · line 1040
Quoted 10 lines
drivers/staging/media/imx/imx7-media-csi.c +3
-4case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY , - false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );
And finally here.
Quoted 3 lines
drivers/staging/media/imx/imx7-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }
Signature · 3 lines
Regards, Laurent Pinchart
Steve Longerbeam
maintainerRe: [PATCH v6 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag
Hi Laurent,
Quoted 55 lines · Laurent Pinchart
Hi Steve,
Thank you for the patch.
Quoted 50 lines · Steve Longerbeam
From: Laurent Pinchart <[email protected]>
The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as
return enum_format(fourcc, NULL, index, cs_sel, true, false);where the boolean parameters can easily be mixed. To make the code clearer, add a
CS_SEL_BAYERflag that can be passed through thecodespace_selparameter of the lookup functions to replace the bool parameter.Signed-off-by Laurent Pinchart <[email protected]>[Instead of declaring
CS_SEL_ANYas a bitfield containing only
CS_SEL_YUV|CS_SEL_RGB, declareCS_SEL_ANYas all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection asCS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings.CS_SEL_ANYis now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.]Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +-- drivers/staging/media/imx/imx-media-capture.c | 14 ++-- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++-- drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++---------- drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++-- 8 files changed, 70 insertions(+), 74 deletions(-)drivers/staging/media/imx/imx-ic-prp.c +1
-1@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN);
Quoted 9 lines
drivers/staging/media/imx/imx-ic-prp.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 186
Quoted 8 lines
drivers/staging/media/imx/imx-ic-prp.c +3
-3cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_ipu_format (code,CS_SEL_YUV );Should these two be
CS_SEL_YUV_RGB?
It could be, but this is selecting a default format if the requested format isn't supported, so it just asks for the first enumerated IPU-internal format (AYUV32) as a default.
Which brings up an idea I've been considering to clean up these default format selection paths a bit. A
const struct imx_media_pixfmt * imx_media_default_{pixel|mbus|ipu}_format(enum imx_pixfmt_sel fmt_sel)
would return a default YUV/RGB/BAYER format depending on fmt_sel.
Quoted 27 lines
Quoted 27 lines
drivers/staging/media/imx/imx-ic-prp.c +0
-0sdformat->format.code = cc->codes[0 ]; }drivers/staging/media/imx/imx-ic-prpencvf.c +3
-2@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=PRPENCVF_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_ANY ); +return imx_media_enum_ipu_format (&code->code, code->index, +CS_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_ANY ); + *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB );if (!*cc) {u32 code;
Quoted 5 lines
drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 894
Quoted 4 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +2
-2-imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,CS_SEL_YUV );And here too ?
Same as above.
Quoted 53 lines
Quoted 53 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-capture.c +6
-6@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;@@ -217,14 +217,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV :CS_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel);if (!cc) {imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;
Quoted 7 lines
drivers/staging/media/imx/imx-media-capture.c int imx_media_capture_device_register(struct imx_media_video_dev *vdev) · line 793
Quoted 6 lines
drivers/staging/media/imx/imx-media-capture.c +1
-1@@ -790,7 +790,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY , false); +CS_SEL_ANY );Should this be
CS_SEL_YUV_RGBtoo ?
Not in this case. The capture interface could be attached to a CSI, which supports bayer, so the CSI may have selected a bayer format when it registered (see below re: imx_media_enum_mbus_format()), so bayer needs to be included in the search.
Quoted 49 lines
Quoted 49 lines
drivers/staging/media/imx/imx-media-capture.c +0
-0v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));drivers/staging/media/imx/imx-media-csc-scaler.c +1
-1@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_ANY ); + ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB );if (ret)return ret;drivers/staging/media/imx/imx-media-csi.c +3
-4@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code, -CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN);
Quoted 11 lines
drivers/staging/media/imx/imx-media-csi.c static void csi_try_fmt(struct csi_priv *priv, · line 1475
Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +3
-5*cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 , -CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code, -CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );Same here.
Same as above, CSI supports bayer so the default format search should technically include bayer. Although since this is selecting some default, maybe it shouldn't allow bayer as a default.
Quoted 148 lines
Quoted 148 lines
drivers/staging/media/imx/imx-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-utils.c +26
-26@@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && fmt->fourcc == fourcc)@@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,static int enum_format (u32 *fourcc,u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && index ==0 ) {@@ -290,30 +288,28 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, }const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer) +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel) { -return find_format (fourcc,0 , cs_sel, true, allow_bayer); +return find_format (fourcc,0 , cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_find_format);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel) { -return enum_format (fourcc,NULL , index, cs_sel, true, false); +return enum_format (fourcc,NULL , index, cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_enum_format);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer) +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel) { -return find_format (0 , code, cs_sel, false, allow_bayer); +return find_format (0 , code, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer) +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel) { -return enum_format (NULL , code, index, cs_sel, false, allow_bayer); +return enum_format (NULL , code, index, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);@@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)u32 array_size;int i, j; + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV : array_size =NUM_IPU_YUV_FORMATS ;@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) array_size =NUM_IPU_RGB_FORMATS ; array = ipu_rgb_formats;break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB : array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; array = ipu_yuv_formats;break ;@@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) }for (i =0 ; i < array_size; i++) { -if (cs_sel ==CS_SEL_ANY && i >=NUM_IPU_YUV_FORMATS ) +if (cs_sel ==CS_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ];else fmt = &array[i];@@ -362,6 +360,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel) { + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV :if (index >=NUM_IPU_YUV_FORMATS )@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)return -EINVAL ; *code = ipu_rgb_formats[index].codes[0 ];break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB :if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS )return -EINVAL ;if (index >=NUM_IPU_YUV_FORMATS ) {@@ -401,8 +401,8 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
Quoted 8 lines
drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 405
Quoted 7 lines
drivers/staging/media/imx/imx-media-utils.c +2
-2mbus->height = height; mbus->field = field;if (code ==0 ) -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - lcc =imx_media_find_mbus_format (code,CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + lcc =imx_media_find_mbus_format (code,CS_SEL_ANY );And here.
This is imx_media_enum_mbus_format(), which is called by a subdev when it is registered to fill its mbus formats with some sane defaults. It's appropriate to use PIXFMT_SEL_ANY here since it is called by CSI.
Quoted 98 lines
Quoted 98 lines
drivers/staging/media/imx/imx-media-utils.c +6
-6if (!lcc) { lcc =imx_media_find_ipu_format (code,CS_SEL_ANY );if (!lcc)@@ -473,7 +473,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,const struct imx_media_pixfmt *cc;bool is_rgb = false; - cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY , true); + cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY );if (!cc) cc =imx_media_find_ipu_format (tryfmt->code,CS_SEL_ANY );if (cc && cc->cs ==IPUV3_COLORSPACE_RGB )@@ -527,8 +527,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (!cc) { cc =imx_media_find_ipu_format (mbus->code,CS_SEL_ANY );if (!cc) - cc =imx_media_find_mbus_format (mbus->code,CS_SEL_ANY , - true); + cc =imx_media_find_mbus_format (mbus->code, +CS_SEL_ANY );if (!cc)return -EINVAL ; }@@ -540,8 +540,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (cc->ipufmt && cc->cs ==IPUV3_COLORSPACE_YUV ) {u32 code; -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - cc =imx_media_find_mbus_format (code,CS_SEL_YUV , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_mbus_format (code,CS_SEL_YUV ); }/* Round up width for minimum burst size */ @@ -592,7 +592,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, {const struct imx_media_pixfmt *fmt; - fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY , true); + fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY );if (!fmt)return -EINVAL ;drivers/staging/media/imx/imx-media.h +8
-8@@ -150,20 +150,20 @@ struct imx_media_dev { };enum codespace_sel { -CS_SEL_YUV =0 , -CS_SEL_RGB , -CS_SEL_ANY , +CS_SEL_YUV =BIT (0 ), +CS_SEL_RGB =BIT (1 ), +CS_SEL_BAYER =BIT (2 ), +CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , +CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , };/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer); +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer); +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel);drivers/staging/media/imx/imx7-media-csi.c +2
-3@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY , - true); + in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY );
Quoted 15 lines
Quoted 4 lines
drivers/staging/media/imx/imx7-media-csi.c +0
-0sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;drivers/staging/media/imx/imx7-media-csi.c static int imx7_csi_try_fmt(struct imx7_csi *csi, · line 1040
Quoted 10 lines
drivers/staging/media/imx/imx7-media-csi.c +3
-4case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY , - false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );And finally here.
I *think* the i.MX7 CSI supports bayer, so this is allowing a bayer format as a default, but again maybe it should avoid selecting bayer in that case.
Steve
Quoted 4 lines
Quoted 4 lines
drivers/staging/media/imx/imx7-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }
Steve Longerbeam
maintainerRe: [PATCH v6 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag
Quoted 164 lines · Steve Longerbeam
Hi Laurent,
Quoted 57 lines · Laurent Pinchart
Hi Steve,
Thank you for the patch.
Quoted 52 lines · Steve Longerbeam
From: Laurent Pinchart <[email protected]>
The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as
return
enum_format(fourcc, NULL, index, cs_sel, true, false);where the boolean parameters can easily be mixed. To make the code clearer, add a
CS_SEL_BAYERflag that can be passed through thecodespace_selparameter of the lookup functions to replace the bool parameter.Signed-off-by Laurent Pinchart <[email protected]>[Instead of declaring
CS_SEL_ANYas a bitfield containing onlyCS_SEL_YUV|CS_SEL_RGB, declareCS_SEL_ANYas all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection asCS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings.CS_SEL_ANYis now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.]Signed-off-by Steve Longerbeam <[email protected]>---
drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +--drivers/staging/media/imx/imx-media-capture.c| 14 ++-- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++-- drivers/staging/media/imx/imx-media-utils.c | 68
+++++++++----------
drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++--8 files changed, 70 insertions(+), 74 deletions(-)drivers/staging/media/imx/imx-ic-prp.c +0
-0@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) {case
PRP_SINK_PAD:
ret =imx_media_enum_ipu_format(&code->code, code->index, - CS_SEL_ANY);
+CS_SEL_YUV_RGB);
break;
casePRP_SRC_PAD_PRPENC:
casePRP_SRC_PAD_PRPVF:drivers/staging/media/imx/imx-ic-prp.c +0
-0@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN); cc = imx_media_find_ipu_format(sdformat->format.code,Quoted 8 lines
drivers/staging/media/imx/imx-ic-prp.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 186
Quoted 7 lines
drivers/staging/media/imx/imx-ic-prp.c +3
-3- CS_SEL_ANY); + CS_SEL_YUV_RGB); if (!cc) { - imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); - cc = imx_media_find_ipu_format(code, CS_SEL_ANY); + imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + cc = imx_media_find_ipu_format(code, CS_SEL_YUV);Should these two be
CS_SEL_YUV_RGB?It could be, but this is selecting a default format if the requested format isn't supported, so it just asks for the first enumerated IPU-internal format (AYUV32) as a default.
Which brings up an idea I've been considering to clean up these default format selection paths a bit. A
const struct
imx_media_pixfmt* imx_media_default_{pixel|mbus|ipu}_format(enumimx_pixfmt_selfmt_sel)would return a default YUV/RGB/BAYER format depending on
fmt_sel.Quoted 21 lines
Quoted 21 lines
drivers/staging/media/imx/imx-ic-prp.c +0
-0sdformat->format.code = cc->codes[0]; }diff --git
a/drivers/staging/media/imx/imx-ic-prpencvf.cb/drivers/staging/media/imx/imx-ic-prpencvf.cindex09c4e3f33807..5a22cdc7378a100644drivers/staging/media/imx/imx-ic-prpencvf.c +3
-0@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad >= PRPENCVF_NUM_PADS) return -EINVAL; - return imx_media_enum_ipu_format(&code->code, code->index, CS_SEL_ANY); + return imx_media_enum_ipu_format(&code->code, code->index, + CS_SEL_YUV_RGB); } static int prp_get_fmt(struct v4l2_subdev *sd,@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, { struct v4l2_mbus_framefmt *infmt; - *cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_ANY); + *cc = imx_media_find_ipu_format(sdformat->format.code,Quoted 8 lines
drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 894
Quoted 7 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +2
-1CS_SEL_YUV_RGB); if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); - *cc = imx_media_find_ipu_format(code, CS_SEL_ANY); + imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + *cc = imx_media_find_ipu_format(code, CS_SEL_YUV);And here too ?
Same as above.
Quoted 45 lines
Quoted 45 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-0sdformat->format.code = (*cc)->codes[0]; }diff --git
a/drivers/staging/media/imx/imx-media-capture.cb/drivers/staging/media/imx/imx-media-capture.cindexd37b776ff86d..d60b49ec4fa4100644drivers/staging/media/imx/imx-media-capture.c +1
-0@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY, true); + cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL;@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };
int ret;
- cc =imx_media_find_format(fival->pixel_format, CS_SEL_ANY, true);
+ cc =imx_media_find_format(fival->pixel_format, CS_SEL_ANY);
if (!cc)
return-EINVAL;
@@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, return ret;
} else {
cc_src= imx_media_find_mbus_format(fmt_src.format.code,
-CS_SEL_ANY, true);
+CS_SEL_ANY);
if (WARN_ON(!cc_src))
return-EINVAL;
@@ -217,14 +217,14 @@ static int __capture_try_fmt_vid_cap(structcapture_priv*priv,CS_SEL_YUV:CS_SEL_RGB;
fourcc =f->fmt.pix.pixelformat;
- cc =imx_media_find_format(fourcc, cs_sel, false);
+ cc =imx_media_find_format(fourcc, cs_sel);
if (!cc) {
imx_media_enum_format(&fourcc, 0, cs_sel);
- cc =imx_media_find_format(fourcc, cs_sel, false);
+ cc =imx_media_find_format(fourcc, cs_sel);
}
} else {
cc_src= imx_media_find_mbus_format(fmt_src->format.code,
-CS_SEL_ANY, true);
+CS_SEL_ANY);
if (WARN_ON(!cc_src))Quoted 8 lines
Quoted 7 lines
return
-EINVAL;
@@ -790,7 +790,7 @@ intimx_media_capture_device_register(struct imx_media_video_dev *vdev)vdev->compose.width= fmt_src.format.width;
vdev->compose.height= fmt_src.format.height;
vdev->cc= imx_media_find_format(vdev->fmt.fmt.pix.pixelformat,
-CS_SEL_ANY, false);
+CS_SEL_ANY);Should this be
CS_SEL_YUV_RGBtoo ?
Quoted 1 line
Not in this case. The capture interface could be attached to a CSI, which supports bayer, so the CSI may have selected a bayer format when it registered (see below re:
imx_media_enum_mbus_format())
^^ sorry, re: imx_media_init_mbus_fmt().
Quoted 208 lines
, so bayer needs to be included in the search.
Quoted 47 lines
Quoted 47 lines
v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name, video_device_node_name(vfd));drivers/staging/media/imx/imx-media-csc-scaler.c +1
-0@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh, u32 fourcc; int ret; - ret = imx_media_enum_format(&fourcc, f->index, CS_SEL_ANY); + ret = imx_media_enum_format(&fourcc, f->index, CS_SEL_YUV_RGB); if (ret) return ret;diff --git
a/drivers/staging/media/imx/imx-media-csi.cb/drivers/staging/media/imx/imx-media-csi.cindexe76a6a85baa3..298294b95293100644drivers/staging/media/imx/imx-media-csi.c +1
-1@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(structv4l2_subdev *sd, mutex_lock(&priv->lock); infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, code->which); - incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY, true); + incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY); switch (code->pad) {case
CSI_SINK_PAD:
ret =imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY, true);
+CS_SEL_ANY);
break;
caseCSI_SRC_PAD_DIRECT:
caseCSI_SRC_PAD_IDMAC:drivers/staging/media/imx/imx-media-csi.c +0
-0@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv, switch (sdformat->pad) {case
CSI_SRC_PAD_DIRECT:
caseCSI_SRC_PAD_IDMAC:
- incc = imx_media_find_mbus_format(infmt->code,
-CS_SEL_ANY, true);
+ incc =imx_media_find_mbus_format(infmt->code, CS_SEL_ANY);sdformat->format.width=compose->width;sdformat->format.height=compose->height;drivers/staging/media/imx/imx-media-csi.c +1
-1@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN); *cc = imx_media_find_mbus_format(sdformat->format.code, - CS_SEL_ANY, true); + CS_SEL_ANY);Quoted 8 lines
drivers/staging/media/imx/imx-media-csi.c static void csi_try_fmt(struct csi_priv *priv, · line 1475
Quoted 7 lines
drivers/staging/media/imx/imx-media-csi.c +2
-4if (!*cc) { - imx_media_enum_mbus_format(&code, 0, - CS_SEL_ANY, false); - *cc = imx_media_find_mbus_format(code, - CS_SEL_ANY, false); + imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + *cc = imx_media_find_mbus_format(code, CS_SEL_ANY);Same here.
Same as above, CSI supports bayer so the default format search should technically include bayer. Although since this is selecting some default, maybe it shouldn't allow bayer as a default.
Quoted 139 lines
Quoted 139 lines
drivers/staging/media/imx/imx-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0]; }diff --git
a/drivers/staging/media/imx/imx-media-utils.cb/drivers/staging/media/imx/imx-media-utils.cindexcf0aba8d53ba..6a3b0b737e5f100644drivers/staging/media/imx/imx-media-utils.c +1
-2@@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = { static const struct imx_media_pixfmt *find_format(u32 fourcc, u32 code, enum codespace_sel cs_sel, - bool allow_non_mbus, - bool allow_bayer) + bool allow_non_mbus) { unsigned int i;@@ -223,12 +222,12 @@ static const struct
imx_media_pixfmt*find_format(u32 fourcc, enumcodespace_selfmt_cs_sel;
unsigned int j;
-fmt_cs_sel= (fmt->cs==IPUV3_COLORSPACE_YUV) ?
-CS_SEL_YUV:CS_SEL_RGB;
+fmt_cs_sel=fmt->bayer?CS_SEL_BAYER:
+ ((fmt->cs==IPUV3_COLORSPACE_YUV) ?
+CS_SEL_YUV:CS_SEL_RGB);
- if ((cs_sel!=CS_SEL_ANY&&fmt_cs_sel!=cs_sel) ||
- (!allow_non_mbus && !fmt->codes[0]) ||
- (!allow_bayer &&fmt->bayer))
+ if (!(fmt_cs_sel &cs_sel) ||
+ (!allow_non_mbus && !fmt->codes[0]))
continue;
if (fourcc &&fmt->fourcc== fourcc)drivers/staging/media/imx/imx-media-utils.c +1
-2@@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, static int enum_format(u32 *fourcc, u32 *code, u32 index, enum codespace_sel cs_sel, - bool allow_non_mbus, - bool allow_bayer) + bool allow_non_mbus) { unsigned int i; @@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum
codespace_selfmt_cs_sel;
unsigned int j;
-fmt_cs_sel= (fmt->cs==IPUV3_COLORSPACE_YUV) ? -CS_SEL_YUV:CS_SEL_RGB;
+fmt_cs_sel=fmt->bayer?CS_SEL_BAYER:
+ ((fmt->cs==IPUV3_COLORSPACE_YUV) ?
+CS_SEL_YUV:CS_SEL_RGB);
- if ((cs_sel!=CS_SEL_ANY&&fmt_cs_sel!=cs_sel) || - (!allow_non_mbus && !fmt->codes[0]) ||
- (!allow_bayer &&fmt->bayer))
+ if (!(fmt_cs_sel &cs_sel) ||
+ (!allow_non_mbus && !fmt->codes[0])) continue;
if (fourcc && index == 0) {drivers/staging/media/imx/imx-media-utils.c +0
-0@@ -290,30 +288,28 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, }const struct
imx_media_pixfmt*
-imx_media_find_format(u32 fourcc, enumcodespace_selcs_sel, boolallow_bayer)
+imx_media_find_format(u32 fourcc, enumcodespace_selcs_sel)
{
- returnfind_format(fourcc, 0, cs_sel, true, allow_bayer);
+ returnfind_format(fourcc, 0, cs_sel, true);
}
EXPORT_SYMBOL_GPL(imx_media_find_format);
intimx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel){
- returnenum_format(fourcc, NULL, index, cs_sel, true, false); + returnenum_format(fourcc, NULL, index, cs_sel, true);
}
EXPORT_SYMBOL_GPL(imx_media_enum_format);
const structimx_media_pixfmt*drivers/staging/media/imx/imx-media-utils.c +1
-2-imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel, - bool allow_bayer) +imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel){
- returnfind_format(0, code, cs_sel, false, allow_bayer);
+ returnfind_format(0, code, cs_sel, false);
}
EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);
-int imx_media_enum_mbus_format(u32 *code, u32 index, enumcodespace_selcs_sel, - boolallow_bayer)
+intimx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel)
{
- returnenum_format(NULL, code, index, cs_sel, false, allow_bayer); + returnenum_format(NULL, code, index, cs_sel, false);
}
EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);
@@ -324,6 +320,8 @@imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)u32array_size;
int i, j;
+cs_sel&= ~CS_SEL_BAYER;
+
switch (cs_sel) {
caseCS_SEL_YUV:
array_size=NUM_IPU_YUV_FORMATS;drivers/staging/media/imx/imx-media-utils.c +1
-1@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) array_size = NUM_IPU_RGB_FORMATS; array = ipu_rgb_formats; break; - case CS_SEL_ANY: + case CS_SEL_YUV_RGB: array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; array = ipu_yuv_formats;break;
drivers/staging/media/imx/imx-media-utils.c +1
-1@@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) } for (i = 0; i < array_size; i++) { - if (cs_sel == CS_SEL_ANY && i >= NUM_IPU_YUV_FORMATS) + if (cs_sel == CS_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS) fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS];else
fmt = &array[i];drivers/staging/media/imx/imx-media-utils.c +2
-0@@ -362,6 +360,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) { + cs_sel &= ~CS_SEL_BAYER; + switch (cs_sel) {case
CS_SEL_YUV:
if (index >=NUM_IPU_YUV_FORMATS)drivers/staging/media/imx/imx-media-utils.c +1
-1@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) return -EINVAL; *code = ipu_rgb_formats[index].codes[0]; break; - case CS_SEL_ANY: + case CS_SEL_YUV_RGB: if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS) return -EINVAL;if (index >=
NUM_IPU_YUV_FORMATS) {drivers/staging/media/imx/imx-media-utils.c +0
-0@@ -401,8 +401,8 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,Quoted 8 lines
drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 405
Quoted 7 lines
drivers/staging/media/imx/imx-media-utils.c +2
-2mbus->height = height; mbus->field = field; if (code == 0) - imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV, false); - lcc = imx_media_find_mbus_format(code, CS_SEL_ANY, false); + imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + lcc = imx_media_find_mbus_format(code, CS_SEL_ANY);And here.
Quoted 1 line
This is
imx_media_enum_mbus_format()
^^ sorry, I meant imx_media_init_mbus_fmt().
Quoted 124 lines
, which is called by a subdev when it is registered to fill its mbus formats with some sane defaults. It's appropriate to use
PIXFMT_SEL_ANYhere since it is called by CSI.Quoted 105 lines
Quoted 105 lines
drivers/staging/media/imx/imx-media-utils.c +0
-0if (!lcc) { lcc = imx_media_find_ipu_format(code, CS_SEL_ANY);if (!lcc)
drivers/staging/media/imx/imx-media-utils.c +1
-0@@ -473,7 +473,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, const struct imx_media_pixfmt *cc; bool is_rgb = false; - cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY, true); + cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY); if (!cc) cc = imx_media_find_ipu_format(tryfmt->code, CS_SEL_ANY);if (cc &&
cc->cs==IPUV3_COLORSPACE_RGB)drivers/staging/media/imx/imx-media-utils.c +2
-2@@ -527,8 +527,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, if (!cc) { cc = imx_media_find_ipu_format(mbus->code, CS_SEL_ANY); if (!cc) - cc = imx_media_find_mbus_format(mbus->code, CS_SEL_ANY, - true); + cc = imx_media_find_mbus_format(mbus->code, + CS_SEL_ANY); if (!cc) return -EINVAL;}
drivers/staging/media/imx/imx-media-utils.c +3
-1@@ -540,8 +540,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) { u32 code; - imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV, false); - cc = imx_media_find_mbus_format(code, CS_SEL_YUV, false); + imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + cc = imx_media_find_mbus_format(code, CS_SEL_YUV); } /* Round up width for minimum burst size */@@ -592,7 +592,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, { const struct imx_media_pixfmt *fmt; - fmt = imx_media_find_format(image->pix.pixelformat, CS_SEL_ANY, true); + fmt = imx_media_find_format(image->pix.pixelformat, CS_SEL_ANY); if (!fmt) return -EINVAL;diff --git
a/drivers/staging/media/imx/imx-media.hb/drivers/staging/media/imx/imx-media.hindex11861191324a..652673a703cd100644drivers/staging/media/imx/imx-media.h +5
-3@@ -150,20 +150,20 @@ struct imx_media_dev { }; enum codespace_sel { - CS_SEL_YUV = 0, - CS_SEL_RGB, - CS_SEL_ANY, + CS_SEL_YUV = BIT(0), + CS_SEL_RGB = BIT(1), + CS_SEL_BAYER = BIT(2), + CS_SEL_YUV_RGB = CS_SEL_YUV | CS_SEL_RGB, + CS_SEL_ANY = CS_SEL_YUV | CS_SEL_RGB | CS_SEL_BAYER, }; /* imx-media-utils.c */const struct
imx_media_pixfmt*
-imx_media_find_format(u32 fourcc, enumcodespace_selcs_sel, boolallow_bayer);
+imx_media_find_format(u32 fourcc, enumcodespace_selcs_sel);
intimx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel); const structimx_media_pixfmt*drivers/staging/media/imx/imx-media.h +0
-3-imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel, - bool allow_bayer); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum
codespace_selcs_sel,
- boolallow_bayer);drivers/staging/media/imx/imx-media.h +2
-0+imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel); +int imx_media_enum_mbus_format(u32 *code, u32 index, enum
codespace_selcs_sel);
const structimx_media_pixfmt*
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel); intimx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel);drivers/staging/media/imx/imx7-media-csi.c +0
-0@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) {case
IMX7_CSI_PAD_SINK:
ret =imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY, true);
+CS_SEL_ANY);
break;
caseIMX7_CSI_PAD_SRC:
if (code->index!= 0) {drivers/staging/media/imx/imx7-media-csi.c +0
-0@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, switch (sdformat->pad) {case
IMX7_CSI_PAD_SRC:
-in_cc=imx_media_find_mbus_format(in_fmt->code, CS_SEL_ANY, - true);
+in_cc=imx_media_find_mbus_format(in_fmt->code, CS_SEL_ANY);sdformat->format.width=in_fmt->width;sdformat->format.height=in_fmt->height;drivers/staging/media/imx/imx7-media-csi.c +0
-0@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, break;case
IMX7_CSI_PAD_SINK:
*cc =imx_media_find_mbus_format(sdformat->format.code, - CS_SEL_ANY, true);Quoted 8 lines
Quoted 7 lines
+
CS_SEL_ANY);
if (!*cc) {
-imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY, false); - *cc =imx_media_find_mbus_format(code, CS_SEL_ANY, - false);
+imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + *cc =imx_media_find_mbus_format(code, CS_SEL_ANY);And finally here.
I *think* the i.MX7 CSI supports bayer, so this is allowing a bayer format as a default, but again maybe it should avoid selecting bayer in that case.
Steve
Quoted 3 lines
Quoted 3 lines
sdformat->format.code= (*cc)->codes[0]; }
Re: [PATCH v6 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag
In reply to Steve LongerbeamHi Steve,
Quoted 63 lines · Steve Longerbeam
Quoted 51 lines · Laurent Pinchart
Quoted 50 lines · Steve Longerbeam
From: Laurent Pinchart <[email protected]>
The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as
return enum_format(fourcc, NULL, index, cs_sel, true, false);where the boolean parameters can easily be mixed. To make the code clearer, add a
CS_SEL_BAYERflag that can be passed through thecodespace_selparameter of the lookup functions to replace the bool parameter.Signed-off-by Laurent Pinchart <[email protected]>[Instead of declaring
CS_SEL_ANYas a bitfield containing only
CS_SEL_YUV|CS_SEL_RGB, declareCS_SEL_ANYas all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection asCS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings.CS_SEL_ANYis now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.]Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +-- drivers/staging/media/imx/imx-media-capture.c | 14 ++-- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++-- drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++---------- drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++-- 8 files changed, 70 insertions(+), 74 deletions(-)drivers/staging/media/imx/imx-ic-prp.c +1
-1@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN);Quoted 10 lines
drivers/staging/media/imx/imx-ic-prp.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 186
Quoted 8 lines
drivers/staging/media/imx/imx-ic-prp.c +3
-3cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_ipu_format (code,CS_SEL_YUV );Should these two be
CS_SEL_YUV_RGB?
Quoted 3 lines
It could be, but this is selecting a default format if the requested format isn't supported, so it just asks for the first enumerated IPU-internal format (AYUV32) as a default.
I agree it won't change anything in practice, as the YUV format is first in the table, but I think it expresses the intent better (retrieving the first format, whatever it is). If you would like to code to retrieve the first YUV format explicitly, I'm not opposed to that, but I think it should be a separate patch (or at least explained in the commit message).
Quoted 104 lines
Which brings up an idea I've been considering to clean up these default format selection paths a bit. A
const struct
imx_media_pixfmt* imx_media_default_{pixel|mbus|ipu}_format(enumimx_pixfmt_selfmt_sel)would return a default YUV/RGB/BAYER format depending on
fmt_sel.Quoted 26 lines
Quoted 26 lines
drivers/staging/media/imx/imx-ic-prp.c +0
-0sdformat->format.code = cc->codes[0 ]; }drivers/staging/media/imx/imx-ic-prpencvf.c +3
-2@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=PRPENCVF_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_ANY ); +return imx_media_enum_ipu_format (&code->code, code->index, +CS_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_ANY ); + *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB );if (!*cc) {u32 code;Quoted 6 lines
drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 894
Quoted 4 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +2
-2-imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,CS_SEL_YUV );And here too ?
Same as above.
Quoted 52 lines
Quoted 52 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-capture.c +6
-6@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;@@ -217,14 +217,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV :CS_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel);if (!cc) {imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;Quoted 8 lines
drivers/staging/media/imx/imx-media-capture.c int imx_media_capture_device_register(struct imx_media_video_dev *vdev) · line 793
Quoted 6 lines
drivers/staging/media/imx/imx-media-capture.c +1
-1@@ -790,7 +790,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY , false); +CS_SEL_ANY );Should this be
CS_SEL_YUV_RGBtoo ?
Quoted 4 lines
Not in this case. The capture interface could be attached to a CSI, which supports bayer, so the CSI may have selected a bayer format when it registered (see below re:
imx_media_enum_mbus_format()), so bayer needs to be included in the search.
It wasn't before though. I'm fine fixing this, but I think it should then be split to a separate patch, the change is too hidden in the refactoring.
Quoted 222 lines
Quoted 48 lines
Quoted 48 lines
drivers/staging/media/imx/imx-media-capture.c +0
-0v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));drivers/staging/media/imx/imx-media-csc-scaler.c +1
-1@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_ANY ); + ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB );if (ret)return ret;drivers/staging/media/imx/imx-media-csi.c +3
-4@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code, -CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN);Quoted 12 lines
drivers/staging/media/imx/imx-media-csi.c static void csi_try_fmt(struct csi_priv *priv, · line 1475
Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +3
-5*cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 , -CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code, -CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );Same here.
Same as above, CSI supports bayer so the default format search should technically include bayer. Although since this is selecting some default, maybe it shouldn't allow bayer as a default.
Quoted 148 lines
Quoted 148 lines
drivers/staging/media/imx/imx-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-utils.c +26
-26@@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && fmt->fourcc == fourcc)@@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,static int enum_format (u32 *fourcc,u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && index ==0 ) {@@ -290,30 +288,28 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, }const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer) +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel) { -return find_format (fourcc,0 , cs_sel, true, allow_bayer); +return find_format (fourcc,0 , cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_find_format);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel) { -return enum_format (fourcc,NULL , index, cs_sel, true, false); +return enum_format (fourcc,NULL , index, cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_enum_format);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer) +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel) { -return find_format (0 , code, cs_sel, false, allow_bayer); +return find_format (0 , code, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer) +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel) { -return enum_format (NULL , code, index, cs_sel, false, allow_bayer); +return enum_format (NULL , code, index, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);@@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)u32 array_size;int i, j; + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV : array_size =NUM_IPU_YUV_FORMATS ;@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) array_size =NUM_IPU_RGB_FORMATS ; array = ipu_rgb_formats;break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB : array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; array = ipu_yuv_formats;break ;@@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) }for (i =0 ; i < array_size; i++) { -if (cs_sel ==CS_SEL_ANY && i >=NUM_IPU_YUV_FORMATS ) +if (cs_sel ==CS_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ];else fmt = &array[i];@@ -362,6 +360,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel) { + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV :if (index >=NUM_IPU_YUV_FORMATS )@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)return -EINVAL ; *code = ipu_rgb_formats[index].codes[0 ];break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB :if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS )return -EINVAL ;if (index >=NUM_IPU_YUV_FORMATS ) {@@ -401,8 +401,8 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->height = height;Quoted 8 lines
drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 405
Quoted 6 lines
drivers/staging/media/imx/imx-media-utils.c +2
-2mbus->field = field;if (code ==0 ) -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - lcc =imx_media_find_mbus_format (code,CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + lcc =imx_media_find_mbus_format (code,CS_SEL_ANY );And here.
Quoted 3 lines
This is
imx_media_enum_mbus_format(), which is called by a subdev when it is registered to fill its mbus formats with some sane defaults. It's appropriate to usePIXFMT_SEL_ANYhere since it is called by CSI.
Fine with me, but as it changes the behaviour, let's split it to a separate patch.
Quoted 114 lines
Quoted 97 lines
Quoted 97 lines
drivers/staging/media/imx/imx-media-utils.c +6
-6if (!lcc) { lcc =imx_media_find_ipu_format (code,CS_SEL_ANY );if (!lcc)@@ -473,7 +473,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,const struct imx_media_pixfmt *cc;bool is_rgb = false; - cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY , true); + cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY );if (!cc) cc =imx_media_find_ipu_format (tryfmt->code,CS_SEL_ANY );if (cc && cc->cs ==IPUV3_COLORSPACE_RGB )@@ -527,8 +527,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (!cc) { cc =imx_media_find_ipu_format (mbus->code,CS_SEL_ANY );if (!cc) - cc =imx_media_find_mbus_format (mbus->code,CS_SEL_ANY , - true); + cc =imx_media_find_mbus_format (mbus->code, +CS_SEL_ANY );if (!cc)return -EINVAL ; }@@ -540,8 +540,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (cc->ipufmt && cc->cs ==IPUV3_COLORSPACE_YUV ) {u32 code; -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - cc =imx_media_find_mbus_format (code,CS_SEL_YUV , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_mbus_format (code,CS_SEL_YUV ); }/* Round up width for minimum burst size */ @@ -592,7 +592,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, {const struct imx_media_pixfmt *fmt; - fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY , true); + fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY );if (!fmt)return -EINVAL ;drivers/staging/media/imx/imx-media.h +8
-8@@ -150,20 +150,20 @@ struct imx_media_dev { };enum codespace_sel { -CS_SEL_YUV =0 , -CS_SEL_RGB , -CS_SEL_ANY , +CS_SEL_YUV =BIT (0 ), +CS_SEL_RGB =BIT (1 ), +CS_SEL_BAYER =BIT (2 ), +CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , +CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , };/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer); +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer); +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel);drivers/staging/media/imx/imx7-media-csi.c +2
-3@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY , - true); + in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY );Quoted 16 lines
Quoted 4 lines
drivers/staging/media/imx/imx7-media-csi.c +0
-0sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;drivers/staging/media/imx/imx7-media-csi.c static int imx7_csi_try_fmt(struct imx7_csi *csi, · line 1040
Quoted 10 lines
drivers/staging/media/imx/imx7-media-csi.c +3
-4case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY , - false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );And finally here.
Quoted 3 lines
I *think* the i.MX7 CSI supports bayer, so this is allowing a bayer format as a default, but again maybe it should avoid selecting bayer in that case.
The i.MX7 supports Bayer in the sense that it can capture raw data. There's no debayering support at the hardware level unfortunately :-(
I'm also fine with this change, but let's split it too with the others.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/staging/media/imx/imx7-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }
Signature · 3 lines
Regards, Laurent Pinchart
Steve Longerbeam
maintainerRe: [PATCH v6 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag
Quoted 67 lines · Laurent Pinchart
Hi Steve,
Quoted 61 lines · Steve Longerbeam
Quoted 51 lines · Laurent Pinchart
Quoted 50 lines · Steve Longerbeam
From: Laurent Pinchart <[email protected]>
The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as
return enum_format(fourcc, NULL, index, cs_sel, true, false);where the boolean parameters can easily be mixed. To make the code clearer, add a
CS_SEL_BAYERflag that can be passed through thecodespace_selparameter of the lookup functions to replace the bool parameter.Signed-off-by Laurent Pinchart <[email protected]>[Instead of declaring
CS_SEL_ANYas a bitfield containing only
CS_SEL_YUV|CS_SEL_RGB, declareCS_SEL_ANYas all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection asCS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings.CS_SEL_ANYis now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.]Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +-- drivers/staging/media/imx/imx-media-capture.c | 14 ++-- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++-- drivers/staging/media/imx/imx-media-utils.c | 68 +++++++++---------- drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++-- 8 files changed, 70 insertions(+), 74 deletions(-)drivers/staging/media/imx/imx-ic-prp.c +1
-1@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN);Quoted 9 lines
drivers/staging/media/imx/imx-ic-prp.c static int prp_set_fmt(struct v4l2_subdev *sd, · line 186
Quoted 8 lines
drivers/staging/media/imx/imx-ic-prp.c +3
-3cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_ANY ); +CS_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_ipu_format (code,CS_SEL_YUV );Should these two be
CS_SEL_YUV_RGB?Quoted 3 lines
It could be, but this is selecting a default format if the requested format isn't supported, so it just asks for the first enumerated IPU-internal format (AYUV32) as a default.
Quoted 6 lines
I agree it won't change anything in practice, as the YUV format is first in the table, but I think it expresses the intent better (retrieving the first format, whatever it is). If you would like to code to retrieve the first YUV format explicitly, I'm not opposed to that, but I think it should be a separate patch (or at least explained in the commit message).
You're right, it changes the behavior, I'll use SEL_YUV_RGB here so it's equivalent.
Quoted 101 lines
Quoted 101 lines
Which brings up an idea I've been considering to clean up these default format selection paths a bit. A
const struct
imx_media_pixfmt* imx_media_default_{pixel|mbus|ipu}_format(enumimx_pixfmt_selfmt_sel)would return a default YUV/RGB/BAYER format depending on
fmt_sel.Quoted 26 lines
Quoted 26 lines
drivers/staging/media/imx/imx-ic-prp.c +0
-0sdformat->format.code = cc->codes[0 ]; }drivers/staging/media/imx/imx-ic-prpencvf.c +3
-2@@ -850,7 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=PRPENCVF_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_ANY ); +return imx_media_enum_ipu_format (&code->code, code->index, +CS_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,@@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_ANY ); + *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB );if (!*cc) {u32 code;Quoted 5 lines
drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_try_fmt(struct prp_priv *priv, · line 894
Quoted 4 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +2
-2-imx_media_enum_ipu_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_ipu_format (code,CS_SEL_ANY ); +imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,CS_SEL_YUV );And here too ?
Same as above.
Quoted 59 lines
Quoted 53 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-capture.c +6
-6@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY , true); + cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY );if (!cc)return -EINVAL ;@@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;@@ -217,14 +217,14 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV :CS_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel);if (!cc) {imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel, false); + cc =imx_media_find_format (fourcc, cs_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;drivers/staging/media/imx/imx-media-capture.c int imx_media_capture_device_register(struct imx_media_video_dev *vdev) · line 793
Quoted 5 lines
drivers/staging/media/imx/imx-media-capture.c +1
-1@@ -790,7 +790,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY , false); +CS_SEL_ANY );Should this be
CS_SEL_YUV_RGBtoo ?
Quoted 7 lines
Quoted 4 lines
Not in this case. The capture interface could be attached to a CSI, which supports bayer, so the CSI may have selected a bayer format when it registered (see below re:
imx_media_enum_mbus_format()), so bayer needs to be included in the search.It wasn't before though. I'm fine fixing this, but I think it should then be split to a separate patch, the change is too hidden in the refactoring.
You caught me :) Yeah this is fixing a bug, I'll move this to a separate patch.
Quoted 60 lines
Quoted 60 lines
Quoted 60 lines
Quoted 49 lines
drivers/staging/media/imx/imx-media-capture.c +0
-0v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));drivers/staging/media/imx/imx-media-csc-scaler.c +1
-1@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_ANY ); + ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB );if (ret)return ret;drivers/staging/media/imx/imx-media-csi.c +3
-4@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :@@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code, -CS_SEL_ANY , true); + incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;@@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN);drivers/staging/media/imx/imx-media-csi.c static void csi_try_fmt(struct csi_priv *priv, · line 1475
Quoted 10 lines
drivers/staging/media/imx/imx-media-csi.c +3
-5*cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 , -CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code, -CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );Same here.
Quoted 3 lines
Quoted 3 lines
Same as above, CSI supports bayer so the default format search should technically include bayer. Although since this is selecting some default, maybe it shouldn't allow bayer as a default.
I'll change this to SEL_YUV_RGB to make it equivalent.
Quoted 156 lines
Quoted 156 lines
Quoted 156 lines
Quoted 148 lines
drivers/staging/media/imx/imx-media-csi.c +0
-0sdformat->format.code = (*cc)->codes[0 ]; }drivers/staging/media/imx/imx-media-utils.c +26
-26@@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && fmt->fourcc == fourcc)@@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,static int enum_format (u32 *fourcc,u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_non_mbus, -bool allow_bayer) +bool allow_non_mbus) {unsigned int i;@@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum codespace_sel fmt_cs_sel;unsigned int j; - fmt_cs_sel = (fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +CS_SEL_YUV :CS_SEL_RGB ); -if ((cs_sel !=CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0 ]) || - (!allow_bayer && fmt->bayer)) +if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0 ]))continue ;if (fourcc && index ==0 ) {@@ -290,30 +288,28 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, }const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer) +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel) { -return find_format (fourcc,0 , cs_sel, true, allow_bayer); +return find_format (fourcc,0 , cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_find_format);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel) { -return enum_format (fourcc,NULL , index, cs_sel, true, false); +return enum_format (fourcc,NULL , index, cs_sel, true); }EXPORT_SYMBOL_GPL (imx_media_enum_format);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer) +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel) { -return find_format (0 , code, cs_sel, false, allow_bayer); +return find_format (0 , code, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer) +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel) { -return enum_format (NULL , code, index, cs_sel, false, allow_bayer); +return enum_format (NULL , code, index, cs_sel, false); }EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);@@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)u32 array_size;int i, j; + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV : array_size =NUM_IPU_YUV_FORMATS ;@@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) array_size =NUM_IPU_RGB_FORMATS ; array = ipu_rgb_formats;break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB : array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; array = ipu_yuv_formats;break ;@@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) }for (i =0 ; i < array_size; i++) { -if (cs_sel ==CS_SEL_ANY && i >=NUM_IPU_YUV_FORMATS ) +if (cs_sel ==CS_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ];else fmt = &array[i];@@ -362,6 +360,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel) { + cs_sel &= ~CS_SEL_BAYER ; +switch (cs_sel) {case CS_SEL_YUV :if (index >=NUM_IPU_YUV_FORMATS )@@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)return -EINVAL ; *code = ipu_rgb_formats[index].codes[0 ];break ; -case CS_SEL_ANY : +case CS_SEL_YUV_RGB :if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS )return -EINVAL ;if (index >=NUM_IPU_YUV_FORMATS ) {drivers/staging/media/imx/imx-media-utils.c int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, · line 405
Quoted 7 lines
drivers/staging/media/imx/imx-media-utils.c +2
-2@@ -401,8 +401,8 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->height = height; mbus->field = field;if (code ==0 ) -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - lcc =imx_media_find_mbus_format (code,CS_SEL_ANY , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + lcc =imx_media_find_mbus_format (code,CS_SEL_ANY );And here.
Quoted 5 lines
Quoted 3 lines
This is
imx_media_enum_mbus_format(), which is called by a subdev when it is registered to fill its mbus formats with some sane defaults. It's appropriate to usePIXFMT_SEL_ANYhere since it is called by CSI.Fine with me, but as it changes the behaviour, let's split it to a separate patch.
Agreed, moving this to new patch.
Quoted 113 lines
Quoted 113 lines
Quoted 113 lines
Quoted 102 lines
drivers/staging/media/imx/imx-media-utils.c +6
-6if (!lcc) { lcc =imx_media_find_ipu_format (code,CS_SEL_ANY );if (!lcc)@@ -473,7 +473,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,const struct imx_media_pixfmt *cc;bool is_rgb = false; - cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY , true); + cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY );if (!cc) cc =imx_media_find_ipu_format (tryfmt->code,CS_SEL_ANY );if (cc && cc->cs ==IPUV3_COLORSPACE_RGB )@@ -527,8 +527,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (!cc) { cc =imx_media_find_ipu_format (mbus->code,CS_SEL_ANY );if (!cc) - cc =imx_media_find_mbus_format (mbus->code,CS_SEL_ANY , - true); + cc =imx_media_find_mbus_format (mbus->code, +CS_SEL_ANY );if (!cc)return -EINVAL ; }@@ -540,8 +540,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (cc->ipufmt && cc->cs ==IPUV3_COLORSPACE_YUV ) {u32 code; -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV , false); - cc =imx_media_find_mbus_format (code,CS_SEL_YUV , false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); + cc =imx_media_find_mbus_format (code,CS_SEL_YUV ); }/* Round up width for minimum burst size */ @@ -592,7 +592,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, {const struct imx_media_pixfmt *fmt; - fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY , true); + fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY );if (!fmt)return -EINVAL ;drivers/staging/media/imx/imx-media.h +8
-8@@ -150,20 +150,20 @@ struct imx_media_dev { };enum codespace_sel { -CS_SEL_YUV =0 , -CS_SEL_RGB , -CS_SEL_ANY , +CS_SEL_YUV =BIT (0 ), +CS_SEL_RGB =BIT (1 ), +CS_SEL_BAYER =BIT (2 ), +CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , +CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , };/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel,bool allow_bayer); +imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel);int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel, -bool allow_bayer); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel, -bool allow_bayer); +imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel);int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel);drivers/staging/media/imx/imx7-media-csi.c +2
-3@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY , true); +CS_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {@@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY , - true); + in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY ); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;@@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;drivers/staging/media/imx/imx7-media-csi.c static int imx7_csi_try_fmt(struct imx7_csi *csi, · line 1040
Quoted 10 lines
drivers/staging/media/imx/imx7-media-csi.c +3
-4case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY , true); +CS_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY , false); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY , - false); +imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,CS_SEL_ANY );And finally here.
Quoted 7 lines
Quoted 3 lines
I *think* the i.MX7 CSI supports bayer, so this is allowing a bayer format as a default, but again maybe it should avoid selecting bayer in that case.
The i.MX7 supports Bayer in the sense that it can capture raw data. There's no debayering support at the hardware level unfortunately :-(
I'm also fine with this change, but let's split it too with the others.
Agreed.
Steve
Steve Longerbeam
maintainerPATCH v6 5/11 media: imx: utils: Rename pixel format selection enumeration
In reply to Steve LongerbeamAfter the introduction of the CS_SEL_BAYER flag, the "codespace" pixel format selection enumeration wording no longer makes sense (and even before, when selecting between YUV or RGB formats, "codespace" was a misuse of the term).
Rename
- 'enum codespace_sel' to 'enum imx_pixfmt_sel'
- CS_SEL_* to PIXFMT_SEL_*
- local vars named cs_sel to fmt_sel or just sel
No functional changes.
--- drivers/staging/media/imx/imx-ic-prp.c | 10 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 11 +-- drivers/staging/media/imx/imx-media-capture.c | 36 ++++---- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 33 ++++---- drivers/staging/media/imx/imx-media-utils.c | 84 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 12 +-- drivers/staging/media/imx/imx-media.h | 28 +++---- drivers/staging/media/imx/imx7-media-csi.c | 11 +-- 9 files changed, 120 insertions(+), 107 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +5 -5
@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_YUV_RGB ); +PIXFMT_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :
@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN); cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_YUV_RGB ); +PIXFMT_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); - cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); + cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = cc->codes[0 ]; }
@@ -438,7 +438,7 @@ static int prp_registered(struct v4l2_subdev *sd) priv->frame_interval.denominator =30 ;/* set a default mbus format */ -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );return imx_media_init_mbus_fmt (&priv->format_mbus,640 ,480 , code,V4L2_FIELD_NONE ,NULL ); }
drivers/staging/media/imx/imx-ic-prpencvf.c +6 -5
@@ -851,7 +851,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,return -EINVAL ;return imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_YUV_RGB ); +PIXFMT_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,
@@ -886,12 +886,13 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB ); + *cc =imx_media_find_ipu_format (sdformat->format.code, +PIXFMT_SEL_YUV_RGB );if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); - *cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -1249,7 +1250,7 @@ static int prp_registered(struct v4l2_subdev *sd)u32 code;/* set a default mbus format */ -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );for (i =0 ; i <PRPENCVF_NUM_PADS ; i++) { ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], 640, 480, code, V4L2_FIELD_NONE,
drivers/staging/media/imx/imx-media-capture.c +20 -16
@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY ); + cc =imx_media_find_format (fsize->pixel_format,PIXFMT_SEL_ANY );if (!cc)return -EINVAL ;
@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY ); + cc =imx_media_find_format (fival->pixel_format,PIXFMT_SEL_ANY );if (!cc)return -EINVAL ;
@@ -167,17 +167,19 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; } - cc_src =imx_media_find_ipu_format (fmt_src.format.code,CS_SEL_ANY ); + cc_src =imx_media_find_ipu_format (fmt_src.format.code, +PIXFMT_SEL_ANY );if (cc_src) { -u32 cs_sel = (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; +enum imx_pixfmt_sel fmt_sel = + (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; - ret =imx_media_enum_format (&fourcc, f->index, cs_sel); + ret =imx_media_enum_format (&fourcc, f->index, fmt_sel);if (ret)return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;
@@ -209,22 +211,24 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, {const struct imx_media_pixfmt *cc, *cc_src; - cc_src =imx_media_find_ipu_format (fmt_src->format.code,CS_SEL_ANY ); + cc_src =imx_media_find_ipu_format (fmt_src->format.code, +PIXFMT_SEL_ANY );if (cc_src) { -u32 fourcc, cs_sel; +enum imx_pixfmt_sel fmt_sel; +u32 fourcc; - cs_sel = (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_sel = (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel); + cc =imx_media_find_format (fourcc, fmt_sel);if (!cc) { -imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel); +imx_media_enum_format (&fourcc,0 , fmt_sel); + cc =imx_media_find_format (fourcc, fmt_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;
@@ -790,7 +794,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));
drivers/staging/media/imx/imx-media-csc-scaler.c +1 -1
@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB ); + ret =imx_media_enum_format (&fourcc, f->index,PIXFMT_SEL_YUV_RGB );if (ret)return ret;
drivers/staging/media/imx/imx-media-csi.c +18 -15
@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); + incc =imx_media_find_mbus_format (infmt->code,PIXFMT_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :
@@ -1256,11 +1256,13 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, } code->code = infmt->code; }else { -u32 cs_sel = (incc->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; +enum imx_pixfmt_sel fmt_sel = + (incc->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; + ret =imx_media_enum_ipu_format (&code->code, code->index, - cs_sel); + fmt_sel); }break ;default :
@@ -1433,7 +1435,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); + incc =imx_media_find_mbus_format (infmt->code,PIXFMT_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;
@@ -1442,14 +1444,15 @@ static void csi_try_fmt(struct csi_priv *priv, sdformat->format.code = infmt->code; *cc = incc; }else { -u32 cs_sel = (incc->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; +enum imx_pixfmt_sel fmt_sel = + (incc->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; *cc =imx_media_find_ipu_format (sdformat->format.code, - cs_sel); + fmt_sel);if (!*cc) { -imx_media_enum_ipu_format (&code,0 , cs_sel); - *cc =imx_media_find_ipu_format (code, cs_sel); +imx_media_enum_ipu_format (&code,0 , fmt_sel); + *cc =imx_media_find_ipu_format (code, fmt_sel); sdformat->format.code = (*cc)->codes[0 ]; } }
@@ -1469,10 +1472,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN); *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY ); +imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -1758,7 +1761,7 @@ static int csi_registered(struct v4l2_subdev *sd)for (i =0 ; i <CSI_NUM_PADS ; i++) { code =0 ;if (i !=CSI_SINK_PAD ) -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );/* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
drivers/staging/media/imx/imx-media-utils.c +43 -41
208 lines not on this page · raw message
drivers/staging/media/imx/imx-media-vdic.c +7 -5
@@ -548,7 +548,8 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=VDIC_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_YUV ); +return imx_media_enum_ipu_format (&code->code, code->index, +PIXFMT_SEL_YUV ); } static int vdic_get_fmt(struct v4l2_subdev *sd,
@@ -583,12 +584,13 @@ static void vdic_try_fmt(struct vdic_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (sdformat->format.code, +PIXFMT_SEL_YUV );if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); - *cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -850,7 +852,7 @@ static int vdic_registered(struct v4l2_subdev *sd)for (i =0 ; i <VDIC_NUM_PADS ; i++) { code =0 ;if (i !=VDIC_SINK_PAD_IDMAC ) -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );/* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
drivers/staging/media/imx/imx-media.h +14 -14
@@ -79,6 +79,14 @@ struct imx_media_pixfmt {bool ipufmt;/* is one of the IPU internal formats */ }; +enum imx_pixfmt_sel { +PIXFMT_SEL_YUV =BIT (0 ),/* select YUV formats */ +PIXFMT_SEL_RGB =BIT (1 ),/* select RGB formats */ +PIXFMT_SEL_BAYER =BIT (2 ),/* select BAYER formats */ +PIXFMT_SEL_YUV_RGB =PIXFMT_SEL_YUV |PIXFMT_SEL_RGB , +PIXFMT_SEL_ANY =PIXFMT_SEL_YUV |PIXFMT_SEL_RGB |PIXFMT_SEL_BAYER , +}; +struct imx_media_buffer {struct vb2_v4l2_buffer vbuf;/* v4l buffer must be first */ struct list_head list;
@@ -149,24 +157,16 @@ struct imx_media_dev {struct v4l2_subdev *sync_sd[2 ][NUM_IPU_SUBDEVS ]; }; -enum codespace_sel { -CS_SEL_YUV =BIT (0 ), -CS_SEL_RGB =BIT (1 ), -CS_SEL_BAYER =BIT (2 ), -CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , -CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , -}; -/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel); -int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel); +imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel sel); +int imx_media_enum_format (u32 *fourcc,u32 index,enum imx_pixfmt_sel sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel); +imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum imx_pixfmt_sel sel);const struct imx_media_pixfmt * -imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel); -int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel); +imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel sel); +int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel sel);int imx_media_init_mbus_fmt (struct v4l2_mbus_framefmt *mbus,u32 width,u32 height,u32 code,u32 field,const struct imx_media_pixfmt **cc);
drivers/staging/media/imx/imx7-media-csi.c +6 -5
@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {
@@ -1019,7 +1019,8 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY ); + in_cc =imx_media_find_mbus_format (in_fmt->code, +PIXFMT_SEL_ANY ); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;
@@ -1034,10 +1035,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY ); +imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
Signature · 1 line
2.17.1
Re: [PATCH v6 05/11] media: imx: utils: Rename pixel format selection enumeration
Hi Steve,
Thank you for the patch.
Quoted 7 lines · Steve Longerbeam
After the introduction of the
CS_SEL_BAYERflag, the "codespace" pixel format selection enumeration wording no longer makes sense (and even before, when selecting between YUV or RGB formats, "codespace" was a misuse of the term).Rename
Quoted 7 lines
- 'enum
codespace_sel' to 'enumimx_pixfmt_sel'
- CS_SEL_* to PIXFMT_SEL_*
- local vars namedcs_seltofmt_selor just selNo functional changes.
Signed-off-by Steve Longerbeam <[email protected]>
Quoted 627 lines
--- drivers/staging/media/imx/imx-ic-prp.c | 10 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 11 +-- drivers/staging/media/imx/imx-media-capture.c | 36 ++++---- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 33 ++++---- drivers/staging/media/imx/imx-media-utils.c | 84 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 12 +-- drivers/staging/media/imx/imx-media.h | 28 +++---- drivers/staging/media/imx/imx7-media-csi.c | 11 +-- 9 files changed, 120 insertions(+), 107 deletions(-)drivers/staging/media/imx/imx-ic-prp.c +5
-5@@ -107,7 +107,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : ret =imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_YUV_RGB ); +PIXFMT_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :@@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN); cc =imx_media_find_ipu_format (sdformat->format.code, -CS_SEL_YUV_RGB ); +PIXFMT_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); - cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); + cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = cc->codes[0 ]; }@@ -438,7 +438,7 @@ static int prp_registered(struct v4l2_subdev *sd) priv->frame_interval.denominator =30 ;/* set a default mbus format */ -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );return imx_media_init_mbus_fmt (&priv->format_mbus,640 ,480 , code,V4L2_FIELD_NONE ,NULL ); }drivers/staging/media/imx/imx-ic-prpencvf.c +6
-5@@ -851,7 +851,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,return -EINVAL ;return imx_media_enum_ipu_format (&code->code, code->index, -CS_SEL_YUV_RGB ); +PIXFMT_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,@@ -886,12 +886,13 @@ static void prp_try_fmt(struct prp_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV_RGB ); + *cc =imx_media_find_ipu_format (sdformat->format.code, +PIXFMT_SEL_YUV_RGB );if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); - *cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }@@ -1249,7 +1250,7 @@ static int prp_registered(struct v4l2_subdev *sd)u32 code;/* set a default mbus format */ -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );for (i =0 ; i <PRPENCVF_NUM_PADS ; i++) { ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], 640, 480, code, V4L2_FIELD_NONE,drivers/staging/media/imx/imx-media-capture.c +20
-16@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,CS_SEL_ANY ); + cc =imx_media_find_format (fsize->pixel_format,PIXFMT_SEL_ANY );if (!cc)return -EINVAL ;@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,CS_SEL_ANY ); + cc =imx_media_find_format (fival->pixel_format,PIXFMT_SEL_ANY );if (!cc)return -EINVAL ;@@ -167,17 +167,19 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,return ret; } - cc_src =imx_media_find_ipu_format (fmt_src.format.code,CS_SEL_ANY ); + cc_src =imx_media_find_ipu_format (fmt_src.format.code, +PIXFMT_SEL_ANY );if (cc_src) { -u32 cs_sel = (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; +enum imx_pixfmt_sel fmt_sel = + (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; - ret =imx_media_enum_format (&fourcc, f->index, cs_sel); + ret =imx_media_enum_format (&fourcc, f->index, fmt_sel);if (ret)return ret; }else { cc_src =imx_media_find_mbus_format (fmt_src.format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;@@ -209,22 +211,24 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, {const struct imx_media_pixfmt *cc, *cc_src; - cc_src =imx_media_find_ipu_format (fmt_src->format.code,CS_SEL_ANY ); + cc_src =imx_media_find_ipu_format (fmt_src->format.code, +PIXFMT_SEL_ANY );if (cc_src) { -u32 fourcc, cs_sel; +enum imx_pixfmt_sel fmt_sel; +u32 fourcc; - cs_sel = (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; + fmt_sel = (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, cs_sel); + cc =imx_media_find_format (fourcc, fmt_sel);if (!cc) { -imx_media_enum_format (&fourcc,0 , cs_sel); - cc =imx_media_find_format (fourcc, cs_sel); +imx_media_enum_format (&fourcc,0 , fmt_sel); + cc =imx_media_find_format (fourcc, fmt_sel); } }else { cc_src =imx_media_find_mbus_format (fmt_src->format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (WARN_ON (!cc_src))return -EINVAL ;@@ -790,7 +794,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));drivers/staging/media/imx/imx-media-csc-scaler.c +1
-1@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,CS_SEL_YUV_RGB ); + ret =imx_media_enum_format (&fourcc, f->index,PIXFMT_SEL_YUV_RGB );if (ret)return ret;drivers/staging/media/imx/imx-media-csi.c +18
-15@@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,mutex_lock (&priv->lock); infmt =__csi_get_fmt (priv, cfg,CSI_SINK_PAD , code->which); - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); + incc =imx_media_find_mbus_format (infmt->code,PIXFMT_SEL_ANY );switch (code->pad) {case CSI_SINK_PAD : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :@@ -1256,11 +1256,13 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, } code->code = infmt->code; }else { -u32 cs_sel = (incc->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; +enum imx_pixfmt_sel fmt_sel = + (incc->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; + ret =imx_media_enum_ipu_format (&code->code, code->index, - cs_sel); + fmt_sel); }break ;default :@@ -1433,7 +1435,7 @@ static void csi_try_fmt(struct csi_priv *priv,switch (sdformat->pad) {case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC : - incc =imx_media_find_mbus_format (infmt->code,CS_SEL_ANY ); + incc =imx_media_find_mbus_format (infmt->code,PIXFMT_SEL_ANY ); sdformat->format.width = compose->width; sdformat->format.height = compose->height;@@ -1442,14 +1444,15 @@ static void csi_try_fmt(struct csi_priv *priv, sdformat->format.code = infmt->code; *cc = incc; }else { -u32 cs_sel = (incc->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ; +enum imx_pixfmt_sel fmt_sel = + (incc->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; *cc =imx_media_find_ipu_format (sdformat->format.code, - cs_sel); + fmt_sel);if (!*cc) { -imx_media_enum_ipu_format (&code,0 , cs_sel); - *cc =imx_media_find_ipu_format (code, cs_sel); +imx_media_enum_ipu_format (&code,0 , fmt_sel); + *cc =imx_media_find_ipu_format (code, fmt_sel); sdformat->format.code = (*cc)->codes[0 ]; } }@@ -1469,10 +1472,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN); *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY ); +imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }@@ -1758,7 +1761,7 @@ static int csi_registered(struct v4l2_subdev *sd)for (i =0 ; i <CSI_NUM_PADS ; i++) { code =0 ;if (i !=CSI_SINK_PAD ) -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );/* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],drivers/staging/media/imx/imx-media-utils.c +43
-41@@ -212,21 +212,21 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = {static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code, -enum codespace_sel cs_sel, +enum imx_pixfmt_sel fmt_sel,bool allow_non_mbus) {unsigned int i;for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i]; -enum codespace_sel fmt_cs_sel; +enum imx_pixfmt_sel sel;unsigned int j; - fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + sel = fmt->bayer ?PIXFMT_SEL_BAYER : ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ); +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!(fmt_cs_sel & cs_sel) || +if (!(fmt_sel & sel) || (!allow_non_mbus && !fmt->codes[0 ]))continue ;@@ -246,21 +246,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, }static int enum_format (u32 *fourcc,u32 *code,u32 index, -enum codespace_sel cs_sel, +enum imx_pixfmt_sel fmt_sel,bool allow_non_mbus) {unsigned int i;for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i]; -enum codespace_sel fmt_cs_sel; +enum imx_pixfmt_sel sel;unsigned int j; - fmt_cs_sel = fmt->bayer ?CS_SEL_BAYER : + sel = fmt->bayer ?PIXFMT_SEL_BAYER : ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? -CS_SEL_YUV :CS_SEL_RGB ); +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!(fmt_cs_sel & cs_sel) || +if (!(fmt_sel & sel) || (!allow_non_mbus && !fmt->codes[0 ]))continue ;@@ -288,50 +288,51 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, }const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel) +imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) { -return find_format (fourcc,0 , cs_sel, true); +return find_format (fourcc,0 , fmt_sel, true); }EXPORT_SYMBOL_GPL (imx_media_find_format); -int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel) +int imx_media_enum_format (u32 *fourcc,u32 index,enum imx_pixfmt_sel fmt_sel) { -return enum_format (fourcc,NULL , index, cs_sel, true); +return enum_format (fourcc,NULL , index, fmt_sel, true); }EXPORT_SYMBOL_GPL (imx_media_enum_format);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel) +imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel fmt_sel) { -return find_format (0 , code, cs_sel, false); +return find_format (0 , code, fmt_sel, false); }EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel) +int imx_media_enum_mbus_format (u32 *code,u32 index, +enum imx_pixfmt_sel fmt_sel) { -return enum_format (NULL , code, index, cs_sel, false); +return enum_format (NULL , code, index, fmt_sel, false); }EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);const struct imx_media_pixfmt * -imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel) +imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel fmt_sel) {const struct imx_media_pixfmt *array, *fmt, *ret =NULL ;u32 array_size;int i, j; - cs_sel &= ~CS_SEL_BAYER ; + fmt_sel &= ~PIXFMT_SEL_BAYER ; -switch (cs_sel) { -case CS_SEL_YUV : +switch (fmt_sel) { +case PIXFMT_SEL_YUV : array_size =NUM_IPU_YUV_FORMATS ; array = ipu_yuv_formats;break ; -case CS_SEL_RGB : +case PIXFMT_SEL_RGB : array_size =NUM_IPU_RGB_FORMATS ; array = ipu_rgb_formats;break ; -case CS_SEL_YUV_RGB : +case PIXFMT_SEL_YUV_RGB : array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; array = ipu_yuv_formats;break ;@@ -340,7 +341,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) }for (i =0 ; i < array_size; i++) { -if (cs_sel ==CS_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) +if (fmt_sel ==PIXFMT_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ];else fmt = &array[i];@@ -358,22 +359,23 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) }EXPORT_SYMBOL_GPL (imx_media_find_ipu_format); -int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel) +int imx_media_enum_ipu_format (u32 *code,u32 index, +enum imx_pixfmt_sel fmt_sel) { - cs_sel &= ~CS_SEL_BAYER ; + fmt_sel &= ~PIXFMT_SEL_BAYER ; -switch (cs_sel) { -case CS_SEL_YUV : +switch (fmt_sel) { +case PIXFMT_SEL_YUV :if (index >=NUM_IPU_YUV_FORMATS )return -EINVAL ; *code = ipu_yuv_formats[index].codes[0 ];break ; -case CS_SEL_RGB : +case PIXFMT_SEL_RGB :if (index >=NUM_IPU_RGB_FORMATS )return -EINVAL ; *code = ipu_rgb_formats[index].codes[0 ];break ; -case CS_SEL_YUV_RGB : +case PIXFMT_SEL_YUV_RGB :if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS )return -EINVAL ;if (index >=NUM_IPU_YUV_FORMATS ) {@@ -401,10 +403,10 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->height = height; mbus->field = field;if (code ==0 ) -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); - lcc =imx_media_find_mbus_format (code,CS_SEL_ANY ); +imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_YUV ); + lcc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY );if (!lcc) { - lcc =imx_media_find_ipu_format (code,CS_SEL_ANY ); + lcc =imx_media_find_ipu_format (code,PIXFMT_SEL_ANY );if (!lcc)return -EINVAL ; }@@ -473,9 +475,9 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,const struct imx_media_pixfmt *cc;bool is_rgb = false; - cc =imx_media_find_mbus_format (tryfmt->code,CS_SEL_ANY ); + cc =imx_media_find_mbus_format (tryfmt->code,PIXFMT_SEL_ANY );if (!cc) - cc =imx_media_find_ipu_format (tryfmt->code,CS_SEL_ANY ); + cc =imx_media_find_ipu_format (tryfmt->code,PIXFMT_SEL_ANY );if (cc && cc->cs ==IPUV3_COLORSPACE_RGB ) is_rgb = true;@@ -525,10 +527,10 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,u32 stride;if (!cc) { - cc =imx_media_find_ipu_format (mbus->code,CS_SEL_ANY ); + cc =imx_media_find_ipu_format (mbus->code,PIXFMT_SEL_ANY );if (!cc) cc =imx_media_find_mbus_format (mbus->code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (!cc)return -EINVAL ; }@@ -540,8 +542,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (cc->ipufmt && cc->cs ==IPUV3_COLORSPACE_YUV ) {u32 code; -imx_media_enum_mbus_format (&code,0 ,CS_SEL_YUV ); - cc =imx_media_find_mbus_format (code,CS_SEL_YUV ); +imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_YUV ); + cc =imx_media_find_mbus_format (code,PIXFMT_SEL_YUV ); }/* Round up width for minimum burst size */ @@ -592,7 +594,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, {const struct imx_media_pixfmt *fmt; - fmt =imx_media_find_format (image->pix.pixelformat,CS_SEL_ANY ); + fmt =imx_media_find_format (image->pix.pixelformat,PIXFMT_SEL_ANY );if (!fmt)return -EINVAL ;drivers/staging/media/imx/imx-media-vdic.c +7
-5@@ -548,7 +548,8 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=VDIC_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index,CS_SEL_YUV ); +return imx_media_enum_ipu_format (&code->code, code->index, +PIXFMT_SEL_YUV ); } static int vdic_get_fmt(struct v4l2_subdev *sd,@@ -583,12 +584,13 @@ static void vdic_try_fmt(struct vdic_priv *priv, {struct v4l2_mbus_framefmt *infmt; - *cc =imx_media_find_ipu_format (sdformat->format.code,CS_SEL_YUV ); + *cc =imx_media_find_ipu_format (sdformat->format.code, +PIXFMT_SEL_YUV );if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); - *cc =imx_media_find_ipu_format (code,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); + *cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }@@ -850,7 +852,7 @@ static int vdic_registered(struct v4l2_subdev *sd)for (i =0 ; i <VDIC_NUM_PADS ; i++) { code =0 ;if (i !=VDIC_SINK_PAD_IDMAC ) -imx_media_enum_ipu_format (&code,0 ,CS_SEL_YUV ); +imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV );/* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],drivers/staging/media/imx/imx-media.h +14
-14@@ -79,6 +79,14 @@ struct imx_media_pixfmt {bool ipufmt;/* is one of the IPU internal formats */ }; +enum imx_pixfmt_sel { +PIXFMT_SEL_YUV =BIT (0 ),/* select YUV formats */ +PIXFMT_SEL_RGB =BIT (1 ),/* select RGB formats */ +PIXFMT_SEL_BAYER =BIT (2 ),/* select BAYER formats */ +PIXFMT_SEL_YUV_RGB =PIXFMT_SEL_YUV |PIXFMT_SEL_RGB , +PIXFMT_SEL_ANY =PIXFMT_SEL_YUV |PIXFMT_SEL_RGB |PIXFMT_SEL_BAYER , +}; +struct imx_media_buffer {struct vb2_v4l2_buffer vbuf;/* v4l buffer must be first */ struct list_head list;@@ -149,24 +157,16 @@ struct imx_media_dev {struct v4l2_subdev *sync_sd[2 ][NUM_IPU_SUBDEVS ]; }; -enum codespace_sel { -CS_SEL_YUV =BIT (0 ), -CS_SEL_RGB =BIT (1 ), -CS_SEL_BAYER =BIT (2 ), -CS_SEL_YUV_RGB =CS_SEL_YUV |CS_SEL_RGB , -CS_SEL_ANY =CS_SEL_YUV |CS_SEL_RGB |CS_SEL_BAYER , -}; -/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum codespace_sel cs_sel); -int imx_media_enum_format (u32 *fourcc,u32 index,enum codespace_sel cs_sel); +imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel sel); +int imx_media_enum_format (u32 *fourcc,u32 index,enum imx_pixfmt_sel sel);const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum codespace_sel cs_sel); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum codespace_sel cs_sel); +imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel sel); +int imx_media_enum_mbus_format (u32 *code,u32 index,enum imx_pixfmt_sel sel);const struct imx_media_pixfmt * -imx_media_find_ipu_format (u32 code,enum codespace_sel cs_sel); -int imx_media_enum_ipu_format (u32 *code,u32 index,enum codespace_sel cs_sel); +imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel sel); +int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel sel);int imx_media_init_mbus_fmt (struct v4l2_mbus_framefmt *mbus,u32 width,u32 height,u32 code,u32 field,const struct imx_media_pixfmt **cc);drivers/staging/media/imx/imx7-media-csi.c +6
-5@@ -959,7 +959,7 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : ret =imx_media_enum_mbus_format (&code->code, code->index, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {@@ -1019,7 +1019,8 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,switch (sdformat->pad) {case IMX7_CSI_PAD_SRC : - in_cc =imx_media_find_mbus_format (in_fmt->code,CS_SEL_ANY ); + in_cc =imx_media_find_mbus_format (in_fmt->code, +PIXFMT_SEL_ANY ); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height;@@ -1034,10 +1035,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi,break ;case IMX7_CSI_PAD_SINK : *cc =imx_media_find_mbus_format (sdformat->format.code, -CS_SEL_ANY ); +PIXFMT_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,CS_SEL_ANY ); - *cc =imx_media_find_mbus_format (code,CS_SEL_ANY ); +imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_ANY ); + *cc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
Signature · 3 lines
Regards, Laurent Pinchart
Steve Longerbeam
maintainerPATCH v6 6/11 media: imx: utils: Introduce PIXFMT_SEL_IPU
In reply to Steve LongerbeamAdd a PIXFMT_SEL_IPU selection flag, to select only the IPU-internal pixel formats, and move the single-entry IPU-internal pixel format arrays into pixel_formats[]. imx_media_find_ipu_format() and imx_media_enum_ipu_format() can now simply call find_format() and enum_format().
The RGB32 format is both an IPU-internal format, and an in-memory format via idmac channels that is supported by the IPUv3 driver, so it appears twice in pixel_formats[], one with ipufmt=false for the in-memory format, and again with ipufmt=true for the IPU-internal format.
--- drivers/staging/media/imx/imx-media-utils.c | 118 +++++--------------- drivers/staging/media/imx/imx-media.h | 1 + 2 files changed, 27 insertions(+), 92 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +26 -92
@@ -53,7 +53,13 @@ static const struct imx_media_pixfmt pixel_formats[] = { .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, .planar = true, - }, + }, { + .fourcc = V4L2_PIX_FMT_YUV32, + .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .cs = IPUV3_COLORSPACE_YUV, + .bpp = 32, + .ipufmt = true, + }, /*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565,
@@ -73,6 +79,11 @@ static const struct imx_media_pixfmt pixel_formats[] = { .fourcc = V4L2_PIX_FMT_BGR24, .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, + }, { + .fourcc = V4L2_PIX_FMT_XRGB32, + .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, }, { .fourcc = V4L2_PIX_FMT_XRGB32, .codes = {MEDIA_BUS_FMT_ARGB8888_1X32},
@@ -186,42 +197,24 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt ipu_yuv_formats[] = { - { - .fourcc =V4L2_PIX_FMT_YUV32 , - .codes = {MEDIA_BUS_FMT_AYUV8_1X32 }, - .cs =IPUV3_COLORSPACE_YUV , - .bpp =32 , - .ipufmt = true, - }, -}; - -#define NUM_IPU_YUV_FORMATS ARRAY_SIZE(ipu_yuv_formats) - -static const struct imx_media_pixfmt ipu_rgb_formats[] = { - { - .fourcc =V4L2_PIX_FMT_XRGB32 , - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32 }, - .cs =IPUV3_COLORSPACE_RGB , - .bpp =32 , - .ipufmt = true, - }, -}; - -#define NUM_IPU_RGB_FORMATS ARRAY_SIZE(ipu_rgb_formats) -static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code,enum imx_pixfmt_sel fmt_sel,bool allow_non_mbus) { +bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i; + fmt_sel &= ~PIXFMT_SEL_IPU ; +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel;unsigned int j; +if (sel_ipu != fmt->ipufmt) +continue ; + sel = fmt->bayer ?PIXFMT_SEL_BAYER : ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB );
@@ -249,13 +242,19 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum imx_pixfmt_sel fmt_sel, bool allow_non_mbus) { + bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU;unsigned int i; + fmt_sel &= ~PIXFMT_SEL_IPU ; +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel;unsigned int j; +if (sel_ipu != fmt->ipufmt) +continue ; + sel = fmt->bayer ?PIXFMT_SEL_BAYER : ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB );
@@ -317,79 +316,14 @@ EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel fmt_sel) { -const struct imx_media_pixfmt *array, *fmt, *ret =NULL ; -u32 array_size; -int i, j; - - fmt_sel &= ~PIXFMT_SEL_BAYER ; - -switch (fmt_sel) { -case PIXFMT_SEL_YUV : - array_size =NUM_IPU_YUV_FORMATS ; - array = ipu_yuv_formats; -break ; -case PIXFMT_SEL_RGB : - array_size =NUM_IPU_RGB_FORMATS ; - array = ipu_rgb_formats; -break ; -case PIXFMT_SEL_YUV_RGB : - array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; - array = ipu_yuv_formats; -break ; -default : -return NULL ; - } - -for (i =0 ; i < array_size; i++) { -if (fmt_sel ==PIXFMT_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) - fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ]; -else - fmt = &array[i]; - -for (j =0 ; code && fmt->codes[j]; j++) { -if (code == fmt->codes[j]) { - ret = fmt; - goto out; - } - } - } - -out: -return ret; +return find_format (0 , code, fmt_sel |PIXFMT_SEL_IPU , false); }EXPORT_SYMBOL_GPL (imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel fmt_sel) { - fmt_sel &= ~PIXFMT_SEL_BAYER ; - -switch (fmt_sel) { -case PIXFMT_SEL_YUV : -if (index >=NUM_IPU_YUV_FORMATS ) -return -EINVAL ; - *code = ipu_yuv_formats[index].codes[0 ]; -break ; -case PIXFMT_SEL_RGB : -if (index >=NUM_IPU_RGB_FORMATS ) -return -EINVAL ; - *code = ipu_rgb_formats[index].codes[0 ]; -break ; -case PIXFMT_SEL_YUV_RGB : -if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ) -return -EINVAL ; -if (index >=NUM_IPU_YUV_FORMATS ) { - index -=NUM_IPU_YUV_FORMATS ; - *code = ipu_rgb_formats[index].codes[0 ]; - }else { - *code = ipu_yuv_formats[index].codes[0 ]; - } -break ; -default : -return -EINVAL ; - } - -return 0 ; +return enum_format (NULL , code, index, fmt_sel |PIXFMT_SEL_IPU , false); }EXPORT_SYMBOL_GPL (imx_media_enum_ipu_format);
drivers/staging/media/imx/imx-media.h +1 -0
@@ -83,6 +83,7 @@ enum imx_pixfmt_sel {PIXFMT_SEL_YUV =BIT (0 ),/* select YUV formats */ PIXFMT_SEL_RGB =BIT (1 ),/* select RGB formats */ PIXFMT_SEL_BAYER =BIT (2 ),/* select BAYER formats */ +PIXFMT_SEL_IPU =BIT (3 ),/* select IPU-internal formats */ PIXFMT_SEL_YUV_RGB =PIXFMT_SEL_YUV |PIXFMT_SEL_RGB , PIXFMT_SEL_ANY = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB | PIXFMT_SEL_BAYER, };
Signature · 1 line
2.17.1
Re: [PATCH v6 06/11] media: imx: utils: Introduce PIXFMT_SEL_IPU
Hi Steve,
Thank you for the patch.
Quoted 10 lines · Steve Longerbeam
Add a
PIXFMT_SEL_IPUselection flag, to select only the IPU-internal pixel formats, and move the single-entry IPU-internal pixel format arrays into pixel_formats[].imx_media_find_ipu_format()andimx_media_enum_ipu_format()can now simply callfind_format()andenum_format().The RGB32 format is both an IPU-internal format, and an in-memory format via idmac channels that is supported by the IPUv3 driver, so it appears twice in pixel_formats[], one with ipufmt=false for the in-memory format, and again with ipufmt=true for the IPU-internal format.
I like code sharing, but I think the big pixel_formats array is starting to mix unrelated information together. The fact that the V4L2_PIX_FMT_YUV32 entry only exists as a .ipufmt == true variant bothers me. Down the line I'll propose splitting the i.MX7 code out to a separate driver, without using imx-media-utils.c. We'll then have an opportunity to refactor this for IPU-based systems only. Until then,
Quoted 200 lines
Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-media-utils.c | 118 +++++--------------- drivers/staging/media/imx/imx-media.h | 1 + 2 files changed, 27 insertions(+), 92 deletions(-)drivers/staging/media/imx/imx-media-utils.c +26
-92@@ -53,7 +53,13 @@ static const struct imx_media_pixfmt pixel_formats[] = { .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, .planar = true, - }, + }, { + .fourcc = V4L2_PIX_FMT_YUV32, + .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .cs = IPUV3_COLORSPACE_YUV, + .bpp = 32, + .ipufmt = true, + }, /*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565,@@ -73,6 +79,11 @@ static const struct imx_media_pixfmt pixel_formats[] = { .fourcc = V4L2_PIX_FMT_BGR24, .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, + }, { + .fourcc = V4L2_PIX_FMT_XRGB32, + .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, }, { .fourcc = V4L2_PIX_FMT_XRGB32, .codes = {MEDIA_BUS_FMT_ARGB8888_1X32},@@ -186,42 +197,24 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt ipu_yuv_formats[] = { - { - .fourcc =V4L2_PIX_FMT_YUV32 , - .codes = {MEDIA_BUS_FMT_AYUV8_1X32 }, - .cs =IPUV3_COLORSPACE_YUV , - .bpp =32 , - .ipufmt = true, - }, -}; - -#define NUM_IPU_YUV_FORMATS ARRAY_SIZE(ipu_yuv_formats) - -static const struct imx_media_pixfmt ipu_rgb_formats[] = { - { - .fourcc =V4L2_PIX_FMT_XRGB32 , - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32 }, - .cs =IPUV3_COLORSPACE_RGB , - .bpp =32 , - .ipufmt = true, - }, -}; - -#define NUM_IPU_RGB_FORMATS ARRAY_SIZE(ipu_rgb_formats) -static const struct imx_media_pixfmt *find_format (u32 fourcc,u32 code,enum imx_pixfmt_sel fmt_sel,bool allow_non_mbus) { +bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i; + fmt_sel &= ~PIXFMT_SEL_IPU ; +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel;unsigned int j; +if (sel_ipu != fmt->ipufmt) +continue ; + sel = fmt->bayer ?PIXFMT_SEL_BAYER : ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB );@@ -249,13 +242,19 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,enum imx_pixfmt_sel fmt_sel, bool allow_non_mbus) { + bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU;unsigned int i; + fmt_sel &= ~PIXFMT_SEL_IPU ; +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel;unsigned int j; +if (sel_ipu != fmt->ipufmt) +continue ; + sel = fmt->bayer ?PIXFMT_SEL_BAYER : ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB );@@ -317,79 +316,14 @@ EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel fmt_sel) { -const struct imx_media_pixfmt *array, *fmt, *ret =NULL ; -u32 array_size; -int i, j; - - fmt_sel &= ~PIXFMT_SEL_BAYER ; - -switch (fmt_sel) { -case PIXFMT_SEL_YUV : - array_size =NUM_IPU_YUV_FORMATS ; - array = ipu_yuv_formats; -break ; -case PIXFMT_SEL_RGB : - array_size =NUM_IPU_RGB_FORMATS ; - array = ipu_rgb_formats; -break ; -case PIXFMT_SEL_YUV_RGB : - array_size =NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ; - array = ipu_yuv_formats; -break ; -default : -return NULL ; - } - -for (i =0 ; i < array_size; i++) { -if (fmt_sel ==PIXFMT_SEL_YUV_RGB && i >=NUM_IPU_YUV_FORMATS ) - fmt = &ipu_rgb_formats[i -NUM_IPU_YUV_FORMATS ]; -else - fmt = &array[i]; - -for (j =0 ; code && fmt->codes[j]; j++) { -if (code == fmt->codes[j]) { - ret = fmt; - goto out; - } - } - } - -out: -return ret; +return find_format (0 , code, fmt_sel |PIXFMT_SEL_IPU , false); }EXPORT_SYMBOL_GPL (imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel fmt_sel) { - fmt_sel &= ~PIXFMT_SEL_BAYER ; - -switch (fmt_sel) { -case PIXFMT_SEL_YUV : -if (index >=NUM_IPU_YUV_FORMATS ) -return -EINVAL ; - *code = ipu_yuv_formats[index].codes[0 ]; -break ; -case PIXFMT_SEL_RGB : -if (index >=NUM_IPU_RGB_FORMATS ) -return -EINVAL ; - *code = ipu_rgb_formats[index].codes[0 ]; -break ; -case PIXFMT_SEL_YUV_RGB : -if (index >=NUM_IPU_YUV_FORMATS +NUM_IPU_RGB_FORMATS ) -return -EINVAL ; -if (index >=NUM_IPU_YUV_FORMATS ) { - index -=NUM_IPU_YUV_FORMATS ; - *code = ipu_rgb_formats[index].codes[0 ]; - }else { - *code = ipu_yuv_formats[index].codes[0 ]; - } -break ; -default : -return -EINVAL ; - } - -return 0 ; +return enum_format (NULL , code, index, fmt_sel |PIXFMT_SEL_IPU , false); }EXPORT_SYMBOL_GPL (imx_media_enum_ipu_format);drivers/staging/media/imx/imx-media.h +1
-0@@ -83,6 +83,7 @@ enum imx_pixfmt_sel {PIXFMT_SEL_YUV =BIT (0 ),/* select YUV formats */ PIXFMT_SEL_RGB =BIT (1 ),/* select RGB formats */ PIXFMT_SEL_BAYER =BIT (2 ),/* select BAYER formats */ +PIXFMT_SEL_IPU =BIT (3 ),/* select IPU-internal formats */ PIXFMT_SEL_YUV_RGB =PIXFMT_SEL_YUV |PIXFMT_SEL_RGB , PIXFMT_SEL_ANY = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB | PIXFMT_SEL_BAYER, };
Signature · 3 lines
Regards, Laurent Pinchart
Steve Longerbeam
maintainerPATCH v6 7/11 media: imx: utils: Make imx_media_pixfmt handle variable number of codes
In reply to Steve LongerbeamFrom: Laurent Pinchart <[email protected]>
The imx_media_pixfmt structures include a codes member that stores media bus codes as a fixed array of 4 integers. The functions dealing with the imx_media_pixfmt structures assume that the array of codes is terminated by a 0 element. This mechanism is fragile, as demonstrated by several instances of the structure containing 4 non-zero codes.
Fix this by turning the array into a pointer, and providing an IMX_BUS_FMTS macro to initialize the codes member with a guaranteed 0 element at the end.
[Fixed a NULL deref of the codes pointer in a couple places] [Added more comments for the struct imx_media_pixfmt members,
includung a bold NOTE! for future developers that codes pointer is NULL for the in-memory-only formats]
--- drivers/staging/media/imx/imx-media-capture.c | 4 +- drivers/staging/media/imx/imx-media-utils.c | 74 ++++++++++--------- drivers/staging/media/imx/imx-media.h | 7 +- 3 files changed, 46 insertions(+), 39 deletions(-)
drivers/staging/media/imx/imx-media-capture.c +2 -2
@@ -95,7 +95,7 @@ static int capture_enum_framesizes(struct file *file, void *fh,if (!cc)return -EINVAL ; - fse.code = cc->codes[0 ]; + fse.code = cc->codes ? cc->codes[0 ] :0 ; ret =v4l2_subdev_call (priv->src_sd, pad, enum_frame_size,NULL , &fse);if (ret)
@@ -137,7 +137,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh,if (!cc)return -EINVAL ; - fie.code = cc->codes[0 ]; + fie.code = cc->codes ? cc->codes[0 ] :0 ; ret =v4l2_subdev_call (priv->src_sd, pad, enum_frame_interval,NULL , &fie);
drivers/staging/media/imx/imx-media-utils.c +38 -36
225 lines not on this page · raw message
drivers/staging/media/imx/imx-media.h +6 -1
@@ -68,8 +68,13 @@ enum {#define IMX_MEDIA_EOF_TIMEOUT 1000struct imx_media_pixfmt { +/* the in-memory FourCC pixel format */ u32 fourcc; -u32 codes[4 ]; +/* +* the set of equivalent media bus codes for the fourcc. +* NOTE! codes pointer is NULL for in-memory-only formats. +*/ +const u32 *codes;int bpp;/* total bpp */ /* cycles per pixel for generic (bayer) formats for the parallel bus */ int cycles;
Signature · 1 line
2.17.1
Re: [PATCH v6 07/11] media: imx: utils: Make imx_media_pixfmt handle variable number of codes
Hi Steve,
Thank you for the patch.
Quoted 12 lines · Steve Longerbeam
From: Laurent Pinchart <[email protected]>
The
imx_media_pixfmtstructures include a codes member that stores media bus codes as a fixed array of 4 integers. The functions dealing with theimx_media_pixfmtstructures assume that the array of codes is terminated by a 0 element. This mechanism is fragile, as demonstrated by several instances of the structure containing 4 non-zero codes.Fix this by turning the array into a pointer, and providing an
IMX_BUS_FMTSmacro to initialize the codes member with a guaranteed 0 element at the end.
Quoted 5 lines
Signed-off-by Laurent Pinchart <[email protected]>[Fixed a NULL deref of the codes pointer in a couple places] [Added more comments for the struct
imx_media_pixfmtmembers,
includung a bold NOTE! for future developers that codes pointer
s/includung/including/
Quoted 3 lines
is NULL for the in-memory-only formats]
Signed-off-by Steve Longerbeam <[email protected]>
Quoted 286 lines
--- drivers/staging/media/imx/imx-media-capture.c | 4 +- drivers/staging/media/imx/imx-media-utils.c | 74 ++++++++++--------- drivers/staging/media/imx/imx-media.h | 7 +- 3 files changed, 46 insertions(+), 39 deletions(-)drivers/staging/media/imx/imx-media-capture.c +2
-2@@ -95,7 +95,7 @@ static int capture_enum_framesizes(struct file *file, void *fh,if (!cc)return -EINVAL ; - fse.code = cc->codes[0 ]; + fse.code = cc->codes ? cc->codes[0 ] :0 ; ret =v4l2_subdev_call (priv->src_sd, pad, enum_frame_size,NULL , &fse);if (ret)@@ -137,7 +137,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh,if (!cc)return -EINVAL ; - fie.code = cc->codes[0 ]; + fie.code = cc->codes ? cc->codes[0 ] :0 ; ret =v4l2_subdev_call (priv->src_sd, pad, enum_frame_interval,NULL , &fie);drivers/staging/media/imx/imx-media-utils.c +38
-36@@ -7,6 +7,8 @@#include <linux/module.h> #include "imx-media.h" +#define IMX_BUS_FMTS(fmt...) (const u32[]) {fmt, 0} +/* * List of supported pixel formats for the subdevs. */ @@ -14,18 +16,18 @@ static const struct imx_media_pixfmt pixel_formats[] = {/*** YUV formats start here ***/ { .fourcc = V4L2_PIX_FMT_UYVY, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_UYVY8_1X16 - }, + ), .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, }, { .fourcc = V4L2_PIX_FMT_YUYV, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_YUYV8_1X16 - }, + ), .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, }, {@@ -55,7 +57,7 @@ static const struct imx_media_pixfmt pixel_formats[] = { .planar = true, }, { .fourcc = V4L2_PIX_FMT_YUV32, - .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32), .cs = IPUV3_COLORSPACE_YUV, .bpp = 32, .ipufmt = true,@@ -63,16 +65,16 @@ static const struct imx_media_pixfmt pixel_formats[] = {/*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565, - .codes = {MEDIA_BUS_FMT_RGB565_2X8_LE}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .cycles = 2, }, { .fourcc = V4L2_PIX_FMT_RGB24, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_RGB888_1X24, MEDIA_BUS_FMT_RGB888_2X12_LE - }, + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, }, {@@ -81,12 +83,12 @@ static const struct imx_media_pixfmt pixel_formats[] = { .bpp = 24, }, { .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32), .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, }, { .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32), .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true,@@ -106,91 +108,91 @@ static const struct imx_media_pixfmt pixel_formats[] = {/*** raw bayer and grayscale formats start here ***/ { .fourcc = V4L2_PIX_FMT_SBGGR8, - .codes = {MEDIA_BUS_FMT_SBGGR8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, - .codes = {MEDIA_BUS_FMT_SGBRG8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, - .codes = {MEDIA_BUS_FMT_SGRBG8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, - .codes = {MEDIA_BUS_FMT_SRGGB8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR14_1X14, MEDIA_BUS_FMT_SBGGR16_1X16 - }, + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG14_1X14, - MEDIA_BUS_FMT_SGBRG16_1X16, - }, + MEDIA_BUS_FMT_SGBRG16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG14_1X14, - MEDIA_BUS_FMT_SGRBG16_1X16, - }, + MEDIA_BUS_FMT_SGRBG16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB14_1X14, - MEDIA_BUS_FMT_SRGGB16_1X16, - }, + MEDIA_BUS_FMT_SRGGB16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_GREY, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y10_1X10, - MEDIA_BUS_FMT_Y12_1X12, - }, + MEDIA_BUS_FMT_Y12_1X12 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_Y10, - .codes = {MEDIA_BUS_FMT_Y10_1X10}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_Y12, - .codes = {MEDIA_BUS_FMT_Y12_1X12}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true,@@ -220,16 +222,16 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes[0 ])) + (!allow_non_mbus && !fmt->codes))continue ;if (fourcc && fmt->fourcc == fourcc)return fmt; -if (!code) +if (!code || !fmt->codes)continue ; -for (j =0 ; j <ARRAY_SIZE (fmt->codes) && fmt->codes[j]; j++) { +for (j =0 ; fmt->codes[j]; j++) {if (code == fmt->codes[j])return fmt; }@@ -260,7 +262,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes[0 ])) + (!allow_non_mbus && !fmt->codes))continue ;if (fourcc && index ==0 ) {@@ -273,7 +275,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,continue ; } -for (j =0 ; j <ARRAY_SIZE (fmt->codes) && fmt->codes[j]; j++) { +for (j =0 ; fmt->codes[j]; j++) {if (index ==0 ) { *code = fmt->codes[j];return 0 ;@@ -529,7 +531,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus,const struct imx_media_pixfmt *fmt; fmt =imx_media_find_format (image->pix.pixelformat,PIXFMT_SEL_ANY ); -if (!fmt) +if (!fmt || !fmt->codes || !fmt->codes[0 ])return -EINVAL ;memset (mbus,0 ,sizeof (*mbus));drivers/staging/media/imx/imx-media.h +6
-1@@ -68,8 +68,13 @@ enum {#define IMX_MEDIA_EOF_TIMEOUT 1000struct imx_media_pixfmt { +/* the in-memory FourCC pixel format */ u32 fourcc; -u32 codes[4 ]; +/* +* the set of equivalent media bus codes for the fourcc. +* NOTE! codes pointer is NULL for in-memory-only formats. +*/ +const u32 *codes;int bpp;/* total bpp */ /* cycles per pixel for generic (bayer) formats for the parallel bus */ int cycles;
Signature · 3 lines
Regards, Laurent Pinchart
Steve Longerbeam
maintainerPATCH v6 8/11 media: imx: utils: Split find|enum_format into fourcc and mbus functions
In reply to Steve LongerbeamTo make the code easier to follow, split up find_format() into separate search functions for pixel formats and media-bus codes, and inline find_format() into the exported functions imx_media_find_format() and imx_media_find_mbus_format().
Do the equivalent for enum_format().
Also add comment blocks for the exported find|enum functions.
--- drivers/staging/media/imx/imx-media-utils.c | 148 +++++++++++++------- 1 file changed, 100 insertions(+), 48 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +100 -48
@@ -199,10 +199,15 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt *find_format (u32 fourcc, -u32 code, -enum imx_pixfmt_sel fmt_sel, -bool allow_non_mbus) +/* +* Search for and return an entry in the pixel_formats[] array that matches +* the requested selection criteria. +* +* @fourcc: Search for an entry with the given fourcc pixel format. +* @fmt_sel: Allow entries only with the given selection criteria. +*/ +const struct imx_media_pixfmt * +imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;
@@ -212,7 +217,6 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel; -unsigned int j;if (sel_ipu != fmt->ipufmt)continue ;
@@ -221,14 +225,42 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes)) +if ((fmt_sel & sel) && fmt->fourcc == fourcc) +return fmt; + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (imx_media_find_format); + +/* +* Search for and return an entry in the pixel_formats[] array that matches +* the requested selection criteria. +* +* @code: Search for an entry with the given media-bus code. +* @fmt_sel: Allow entries only with the given selection criteria. +*/ +const struct imx_media_pixfmt * +imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel fmt_sel) +{ +bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ; +unsigned int i; + + fmt_sel &= ~PIXFMT_SEL_IPU ; + +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) { +const struct imx_media_pixfmt *fmt = &pixel_formats[i]; +enum imx_pixfmt_sel sel; +unsigned int j; + +if (sel_ipu != fmt->ipufmt)continue ; -if (fourcc && fmt->fourcc == fourcc) -return fmt; + sel = fmt->bayer ?PIXFMT_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!code || !fmt->codes) +if (!(fmt_sel & sel) || !fmt->codes)continue ;for (j =0 ; fmt->codes[j]; j++) {
@@ -239,10 +271,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,return NULL ; } +EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -static int enum_format (u32 *fourcc,u32 *code,u32 index, -enum imx_pixfmt_sel fmt_sel, -bool allow_non_mbus) +/* +* Enumerate entries in the pixel_formats[] array that match the +* requested selection criteria. Returns the fourcc that matches the +* selection criteria at the requested match index. +* +* @fourcc: The returned fourcc that matches the search criteria at +* the requested match index. +* @index: The requested match index. +* @fmt_sel: Include in the enumeration entries with the given selection +* criteria. +*/ +int imx_media_enum_format (u32 *fourcc,u32 index, +enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;
@@ -252,7 +295,6 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel; -unsigned int j;if (sel_ipu != fmt->ipufmt)continue ;
@@ -261,19 +303,54 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes)) +if (!(fmt_sel & sel))continue ; -if (fourcc && index ==0 ) { +if (index ==0 ) { *fourcc = fmt->fourcc;return 0 ; } -if (!code) { - index--; + index--; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (imx_media_enum_format); + +/* +* Enumerate entries in the pixel_formats[] array that match the +* requested search criteria. Returns the media-bus code that matches +* the search criteria at the requested match index. +* +* @code: The returned media-bus code that matches the search criteria at +* the requested match index. +* @index: The requested match index. +* @fmt_sel: Include in the enumeration entries with the given selection +* criteria. +*/ +int imx_media_enum_mbus_format (u32 *code,u32 index, +enum imx_pixfmt_sel fmt_sel) +{ +bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ; +unsigned int i; + + fmt_sel &= ~PIXFMT_SEL_IPU ; + +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) { +const struct imx_media_pixfmt *fmt = &pixel_formats[i]; +enum imx_pixfmt_sel sel; +unsigned int j; + +if (sel_ipu != fmt->ipufmt) +continue ; + + sel = fmt->bayer ?PIXFMT_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); + +if (!(fmt_sel & sel) || !fmt->codes)continue ; - }for (j =0 ; fmt->codes[j]; j++) {if (index ==0 ) {
@@ -287,45 +364,20 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,return -EINVAL ; } - -const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) -{ -return find_format (fourcc,0 , fmt_sel, true); -} -EXPORT_SYMBOL_GPL (imx_media_find_format); - -int imx_media_enum_format (u32 *fourcc,u32 index,enum imx_pixfmt_sel fmt_sel) -{ -return enum_format (fourcc,NULL , index, fmt_sel, true); -} -EXPORT_SYMBOL_GPL (imx_media_enum_format); - -const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel fmt_sel) -{ -return find_format (0 , code, fmt_sel, false); -} -EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); - -int imx_media_enum_mbus_format (u32 *code,u32 index, -enum imx_pixfmt_sel fmt_sel) -{ -return enum_format (NULL , code, index, fmt_sel, false); -}EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel fmt_sel) { -return find_format (0 , code, fmt_sel |PIXFMT_SEL_IPU , false); +return imx_media_find_mbus_format (code, fmt_sel |PIXFMT_SEL_IPU ); }EXPORT_SYMBOL_GPL (imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel fmt_sel) { -return enum_format (NULL , code, index, fmt_sel |PIXFMT_SEL_IPU , false); +return imx_media_enum_mbus_format (code, index, + fmt_sel |PIXFMT_SEL_IPU ); }EXPORT_SYMBOL_GPL (imx_media_enum_ipu_format);
Signature · 1 line
2.17.1
Re: [PATCH v6 08/11] media: imx: utils: Split find|enum_format into fourcc and mbus functions
Hi Steve,
Thank you for the patch.
Quoted 19 lines · Steve Longerbeam
To make the code easier to follow, split up
find_format()into separate search functions for pixel formats and media-bus codes, and inlinefind_format()into the exported functionsimx_media_find_format()andimx_media_find_mbus_format().Do the equivalent for
enum_format().Also add comment blocks for the exported find|enum functions.
Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-media-utils.c | 148 +++++++++++++------- 1 file changed, 100 insertions(+), 48 deletions(-)drivers/staging/media/imx/imx-media-utils.c +0
-0
drivers/staging/media/imx/imx-media-utils.c static const struct imx_media_pixfmt pixel_formats[] = { · line 204
Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +3
-4@@ -199,10 +199,15 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt *find_format (u32 fourcc, -u32 code, -enum imx_pixfmt_sel fmt_sel, -bool allow_non_mbus) +/* +* Search for and return an entry in the pixel_formats[] array that matches +* the requested selection criteria.
To differentiate this from the next function, I would write
* Search in the pixel_formats[] array for an entry with the given fourcc that
* matches the requested selection criteria and return it.
Quoted 24 lines
drivers/staging/media/imx/imx-media-utils.c +7
-3+* +* @fourcc: Search for an entry with the given fourcc pixel format. +* @fmt_sel: Allow entries only with the given selection criteria. +*/ +const struct imx_media_pixfmt * +imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;@@ -212,7 +217,6 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel; -unsigned int j;if (sel_ipu != fmt->ipufmt)continue ;@@ -221,14 +225,42 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes)) +if ((fmt_sel & sel) && fmt->fourcc == fourcc)
drivers/staging/media/imx/imx-media-utils.c static const struct imx_media_pixfmt *find_format(u32 fourcc, · line 238
Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +10
-0+return fmt; + } + +return NULL ; +} +EXPORT_SYMBOL_GPL (imx_media_find_format); + +/* +* Search for and return an entry in the pixel_formats[] array that matches +* the requested selection criteria.
And here
* Search in the pixel_formats[] array for an entry with the given media bus
* code that matches the requested selection criteria and return it.
Quoted 33 lines
drivers/staging/media/imx/imx-media-utils.c +22
-3+* +* @code: Search for an entry with the given media-bus code. +* @fmt_sel: Allow entries only with the given selection criteria. +*/ +const struct imx_media_pixfmt * +imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel fmt_sel) +{ +bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ; +unsigned int i; + + fmt_sel &= ~PIXFMT_SEL_IPU ; + +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) { +const struct imx_media_pixfmt *fmt = &pixel_formats[i]; +enum imx_pixfmt_sel sel; +unsigned int j; + +if (sel_ipu != fmt->ipufmt)continue ; -if (fourcc && fmt->fourcc == fourcc) -return fmt; + sel = fmt->bayer ?PIXFMT_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!code || !fmt->codes) +if (!(fmt_sel & sel) || !fmt->codes)continue ;for (j =0 ; fmt->codes[j]; j++) {@@ -239,10 +271,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
drivers/staging/media/imx/imx-media-utils.c static const struct imx_media_pixfmt *find_format(u32 fourcc, · line 278
Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +4
-3return NULL ; } +EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); -static int enum_format (u32 *fourcc,u32 *code,u32 index, -enum imx_pixfmt_sel fmt_sel, -bool allow_non_mbus) +/* +* Enumerate entries in the pixel_formats[] array that match the +* requested selection criteria. Returns the fourcc that matches the
s/Returns/Return/
Quoted 38 lines
drivers/staging/media/imx/imx-media-utils.c +12
-6+* selection criteria at the requested match index. +* +* @fourcc: The returned fourcc that matches the search criteria at +* the requested match index. +* @index: The requested match index. +* @fmt_sel: Include in the enumeration entries with the given selection +* criteria. +*/ +int imx_media_enum_format (u32 *fourcc,u32 index, +enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;@@ -252,7 +295,6 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) {const struct imx_media_pixfmt *fmt = &pixel_formats[i];enum imx_pixfmt_sel sel; -unsigned int j;if (sel_ipu != fmt->ipufmt)continue ;@@ -261,19 +303,54 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); -if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes)) +if (!(fmt_sel & sel))continue ; -if (fourcc && index ==0 ) { +if (index ==0 ) { *fourcc = fmt->fourcc;return 0 ; } -if (!code) { - index--;
drivers/staging/media/imx/imx-media-utils.c static int enum_format(u32 *fourcc, u32 *code, u32 index, · line 323
Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +10
-0+ index--; + } + +return -EINVAL ; +} +EXPORT_SYMBOL_GPL (imx_media_enum_format); + +/* +* Enumerate entries in the pixel_formats[] array that match the +* requested search criteria. Returns the media-bus code that matches
s/Returns/Return/
Quoted 72 lines
drivers/staging/media/imx/imx-media-utils.c +30
-28+* the search criteria at the requested match index. +* +* @code: The returned media-bus code that matches the search criteria at +* the requested match index. +* @index: The requested match index. +* @fmt_sel: Include in the enumeration entries with the given selection +* criteria. +*/ +int imx_media_enum_mbus_format (u32 *code,u32 index, +enum imx_pixfmt_sel fmt_sel) +{ +bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ; +unsigned int i; + + fmt_sel &= ~PIXFMT_SEL_IPU ; + +for (i =0 ; i <ARRAY_SIZE (pixel_formats); i++) { +const struct imx_media_pixfmt *fmt = &pixel_formats[i]; +enum imx_pixfmt_sel sel; +unsigned int j; + +if (sel_ipu != fmt->ipufmt) +continue ; + + sel = fmt->bayer ?PIXFMT_SEL_BAYER : + ((fmt->cs ==IPUV3_COLORSPACE_YUV ) ? +PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ); + +if (!(fmt_sel & sel) || !fmt->codes)continue ; - }for (j =0 ; fmt->codes[j]; j++) {if (index ==0 ) {@@ -287,45 +364,20 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,return -EINVAL ; } - -const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) -{ -return find_format (fourcc,0 , fmt_sel, true); -} -EXPORT_SYMBOL_GPL (imx_media_find_format); - -int imx_media_enum_format (u32 *fourcc,u32 index,enum imx_pixfmt_sel fmt_sel) -{ -return enum_format (fourcc,NULL , index, fmt_sel, true); -} -EXPORT_SYMBOL_GPL (imx_media_enum_format); - -const struct imx_media_pixfmt * -imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel fmt_sel) -{ -return find_format (0 , code, fmt_sel, false); -} -EXPORT_SYMBOL_GPL (imx_media_find_mbus_format); - -int imx_media_enum_mbus_format (u32 *code,u32 index, -enum imx_pixfmt_sel fmt_sel) -{ -return enum_format (NULL , code, index, fmt_sel, false); -}EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel fmt_sel) { -return find_format (0 , code, fmt_sel |PIXFMT_SEL_IPU , false); +return imx_media_find_mbus_format (code, fmt_sel |PIXFMT_SEL_IPU ); }
drivers/staging/media/imx/imx-media-utils.c static int enum_format(u32 *fourcc, u32 *code, u32 index, · line 382
Quoted 10 lines
drivers/staging/media/imx/imx-media-utils.c +2
-1EXPORT_SYMBOL_GPL (imx_media_find_ipu_format);int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel fmt_sel) { -return enum_format (NULL , code, index, fmt_sel |PIXFMT_SEL_IPU , false); +return imx_media_enum_mbus_format (code, index, + fmt_sel |PIXFMT_SEL_IPU ); }EXPORT_SYMBOL_GPL (imx_media_enum_ipu_format);
You could turn those two functions into static inlines in imx-media.h. Apart from that,
Signature · 3 lines
Regards, Laurent Pinchart
Steve Longerbeam
maintainerPATCH v6 9/11 media: imx: utils: Rename format lookup and enumeration functions
In reply to Steve LongerbeamFrom: Laurent Pinchart <[email protected]>
Rename the format lookup and enumeration functions according to their usage:
- Rename imx_media_(find|enum)_format() to *_pixel_format() to explicitly state on what formats the functions operate. This aligns the naming scheme with the media bus and IPU format functions that already end with *_mbus_format() and *_ipu_formats().
- Rename all enumeration functions to pluralize 'formats' at the end, as they enumerate multiple formats.
--- drivers/staging/media/imx/imx-ic-prp.c | 9 ++--- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 ++--- drivers/staging/media/imx/imx-media-capture.c | 16 ++++----- .../staging/media/imx/imx-media-csc-scaler.c | 3 +- drivers/staging/media/imx/imx-media-csi.c | 16 ++++----- drivers/staging/media/imx/imx-media-utils.c | 35 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 8 ++--- drivers/staging/media/imx/imx-media.h | 11 +++--- drivers/staging/media/imx/imx7-media-csi.c | 6 ++-- 9 files changed, 61 insertions(+), 52 deletions(-)
drivers/staging/media/imx/imx-ic-prp.c +5 -4
@@ -106,8 +106,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case PRP_SINK_PAD : - ret =imx_media_enum_ipu_format (&code->code, code->index, -PIXFMT_SEL_YUV_RGB ); + ret =imx_media_enum_ipu_formats (&code->code, code->index, +PIXFMT_SEL_YUV_RGB );break ;case PRP_SRC_PAD_PRPENC :case PRP_SRC_PAD_PRPVF :
@@ -182,7 +182,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd, cc =imx_media_find_ipu_format (sdformat->format.code,PIXFMT_SEL_YUV_RGB );if (!cc) { -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV ); cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = cc->codes[0 ]; }
@@ -438,7 +438,8 @@ static int prp_registered(struct v4l2_subdev *sd) priv->frame_interval.denominator =30 ;/* set a default mbus format */ -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV ); +return imx_media_init_mbus_fmt (&priv->format_mbus,640 ,480 , code,V4L2_FIELD_NONE ,NULL ); }
drivers/staging/media/imx/imx-ic-prpencvf.c +5 -4
@@ -850,8 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=PRPENCVF_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index, -PIXFMT_SEL_YUV_RGB ); +return imx_media_enum_ipu_formats (&code->code, code->index, +PIXFMT_SEL_YUV_RGB ); } static int prp_get_fmt(struct v4l2_subdev *sd,
@@ -891,7 +891,7 @@ static void prp_try_fmt(struct prp_priv *priv,if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV ); *cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -1250,7 +1250,8 @@ static int prp_registered(struct v4l2_subdev *sd)u32 code;/* set a default mbus format */ -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV ); +for (i =0 ; i <PRPENCVF_NUM_PADS ; i++) { ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], 640, 480, code, V4L2_FIELD_NONE,
drivers/staging/media/imx/imx-media-capture.c +8 -8
@@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fsize->pixel_format,PIXFMT_SEL_ANY ); + cc =imx_media_find_pixel_format (fsize->pixel_format,PIXFMT_SEL_ANY );if (!cc)return -EINVAL ;
@@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, };int ret; - cc =imx_media_find_format (fival->pixel_format,PIXFMT_SEL_ANY ); + cc =imx_media_find_pixel_format (fival->pixel_format,PIXFMT_SEL_ANY );if (!cc)return -EINVAL ;
@@ -174,7 +174,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, (cc_src->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; - ret =imx_media_enum_format (&fourcc, f->index, fmt_sel); + ret =imx_media_enum_pixel_formats (&fourcc, f->index, fmt_sel);if (ret)return ret; }else {
@@ -221,10 +221,10 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; fourcc = f->fmt.pix.pixelformat; - cc =imx_media_find_format (fourcc, fmt_sel); + cc =imx_media_find_pixel_format (fourcc, fmt_sel);if (!cc) { -imx_media_enum_format (&fourcc,0 , fmt_sel); - cc =imx_media_find_format (fourcc, fmt_sel); +imx_media_enum_pixel_formats (&fourcc,0 , fmt_sel); + cc =imx_media_find_pixel_format (fourcc, fmt_sel); } }else { cc_src = imx_media_find_mbus_format(fmt_src->format.code,
@@ -793,8 +793,8 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) &fmt_src.format, NULL); vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; - vdev->cc =imx_media_find_format (vdev->fmt.fmt.pix.pixelformat, -PIXFMT_SEL_ANY ); + vdev->cc =imx_media_find_pixel_format (vdev->fmt.fmt.pix.pixelformat, +PIXFMT_SEL_ANY );v4l2_info (sd,"Registered %s as /dev/%s\n" , vfd->name,video_device_node_name (vfd));
drivers/staging/media/imx/imx-media-csc-scaler.c +2 -1
@@ -164,7 +164,8 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,u32 fourcc;int ret; - ret =imx_media_enum_format (&fourcc, f->index,PIXFMT_SEL_YUV_RGB ); + ret =imx_media_enum_pixel_formats (&fourcc, f->index, +PIXFMT_SEL_YUV_RGB );if (ret)return ret;
drivers/staging/media/imx/imx-media-csi.c +8 -8
@@ -1238,8 +1238,8 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case CSI_SINK_PAD : - ret =imx_media_enum_mbus_format (&code->code, code->index, -PIXFMT_SEL_ANY ); + ret =imx_media_enum_mbus_formats (&code->code, code->index, +PIXFMT_SEL_ANY );break ;case CSI_SRC_PAD_DIRECT :case CSI_SRC_PAD_IDMAC :
@@ -1260,9 +1260,9 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, (incc->cs ==IPUV3_COLORSPACE_YUV ) ?PIXFMT_SEL_YUV :PIXFMT_SEL_RGB ; - ret =imx_media_enum_ipu_format (&code->code, - code->index, - fmt_sel); + ret =imx_media_enum_ipu_formats (&code->code, + code->index, + fmt_sel); }break ;default :
@@ -1451,7 +1451,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc =imx_media_find_ipu_format (sdformat->format.code, fmt_sel);if (!*cc) { -imx_media_enum_ipu_format (&code,0 , fmt_sel); +imx_media_enum_ipu_formats (&code,0 , fmt_sel); *cc =imx_media_find_ipu_format (code, fmt_sel); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -1474,7 +1474,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc =imx_media_find_mbus_format (sdformat->format.code,PIXFMT_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_ANY ); +imx_media_enum_mbus_formats (&code,0 ,PIXFMT_SEL_ANY ); *cc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -1761,7 +1761,7 @@ static int csi_registered(struct v4l2_subdev *sd)for (i =0 ; i <CSI_NUM_PADS ; i++) { code =0 ;if (i !=CSI_SINK_PAD ) -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV );/* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
drivers/staging/media/imx/imx-media-utils.c +19 -16
@@ -207,7 +207,7 @@ static const struct imx_media_pixfmt pixel_formats[] = {* @fmt_sel: Allow entries only with the given selection criteria. */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) +imx_media_find_pixel_format (u32 fourcc,enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;
@@ -231,7 +231,7 @@ imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel)return NULL ; } -EXPORT_SYMBOL_GPL (imx_media_find_format); +EXPORT_SYMBOL_GPL (imx_media_find_pixel_format);/* * Search for and return an entry in the pixel_formats[] array that matches
@@ -284,8 +284,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);* @fmt_sel: Include in the enumeration entries with the given selection * criteria. */ -int imx_media_enum_format (u32 *fourcc,u32 index, -enum imx_pixfmt_sel fmt_sel) +int imx_media_enum_pixel_formats (u32 *fourcc,u32 index, +enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;
@@ -316,7 +316,7 @@ int imx_media_enum_format(u32 *fourcc, u32 index,return -EINVAL ; } -EXPORT_SYMBOL_GPL (imx_media_enum_format); +EXPORT_SYMBOL_GPL (imx_media_enum_pixel_formats);/* * Enumerate entries in the pixel_formats[] array that match the
@@ -329,8 +329,8 @@ EXPORT_SYMBOL_GPL(imx_media_enum_format);* @fmt_sel: Include in the enumeration entries with the given selection * criteria. */ -int imx_media_enum_mbus_format (u32 *code,u32 index, -enum imx_pixfmt_sel fmt_sel) +int imx_media_enum_mbus_formats (u32 *code,u32 index, +enum imx_pixfmt_sel fmt_sel) {bool sel_ipu = fmt_sel &PIXFMT_SEL_IPU ;unsigned int i;
@@ -364,7 +364,7 @@ int imx_media_enum_mbus_format(u32 *code, u32 index,return -EINVAL ; } -EXPORT_SYMBOL_GPL (imx_media_enum_mbus_format); +EXPORT_SYMBOL_GPL (imx_media_enum_mbus_formats);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel fmt_sel)
@@ -373,13 +373,13 @@ imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel) }EXPORT_SYMBOL_GPL (imx_media_find_ipu_format); -int imx_media_enum_ipu_format (u32 *code,u32 index, -enum imx_pixfmt_sel fmt_sel) +int imx_media_enum_ipu_formats (u32 *code,u32 index, +enum imx_pixfmt_sel fmt_sel) { -return imx_media_enum_mbus_format (code, index, - fmt_sel |PIXFMT_SEL_IPU ); +return imx_media_enum_mbus_formats (code, index, + fmt_sel |PIXFMT_SEL_IPU ); } -EXPORT_SYMBOL_GPL (imx_media_enum_ipu_format); +EXPORT_SYMBOL_GPL (imx_media_enum_ipu_formats); int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, u32 width, u32 height, u32 code, u32 field,
@@ -390,8 +390,10 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->width = width; mbus->height = height; mbus->field = field; +if (code ==0 ) -imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_mbus_formats (&code,0 ,PIXFMT_SEL_YUV ); + lcc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY );if (!lcc) { lcc =imx_media_find_ipu_format (code,PIXFMT_SEL_ANY );
@@ -530,7 +532,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,if (cc->ipufmt && cc->cs ==IPUV3_COLORSPACE_YUV ) {u32 code; -imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_mbus_formats (&code,0 ,PIXFMT_SEL_YUV ); cc =imx_media_find_mbus_format (code,PIXFMT_SEL_YUV ); }
@@ -582,7 +584,8 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, {const struct imx_media_pixfmt *fmt; - fmt =imx_media_find_format (image->pix.pixelformat,PIXFMT_SEL_ANY ); + fmt =imx_media_find_pixel_format (image->pix.pixelformat, +PIXFMT_SEL_ANY );if (!fmt || !fmt->codes || !fmt->codes[0 ])return -EINVAL ;
drivers/staging/media/imx/imx-media-vdic.c +4 -4
@@ -548,8 +548,8 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd,if (code->pad >=VDIC_NUM_PADS )return -EINVAL ; -return imx_media_enum_ipu_format (&code->code, code->index, -PIXFMT_SEL_YUV ); +return imx_media_enum_ipu_formats (&code->code, code->index, +PIXFMT_SEL_YUV ); } static int vdic_get_fmt(struct v4l2_subdev *sd,
@@ -589,7 +589,7 @@ static void vdic_try_fmt(struct vdic_priv *priv,if (!*cc) {u32 code; -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV ); *cc =imx_media_find_ipu_format (code,PIXFMT_SEL_YUV ); sdformat->format.code = (*cc)->codes[0 ]; }
@@ -852,7 +852,7 @@ static int vdic_registered(struct v4l2_subdev *sd)for (i =0 ; i <VDIC_NUM_PADS ; i++) { code =0 ;if (i !=VDIC_SINK_PAD_IDMAC ) -imx_media_enum_ipu_format (&code,0 ,PIXFMT_SEL_YUV ); +imx_media_enum_ipu_formats (&code,0 ,PIXFMT_SEL_YUV );/* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i],
drivers/staging/media/imx/imx-media.h +7 -4
@@ -165,14 +165,17 @@ struct imx_media_dev {/* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format (u32 fourcc,enum imx_pixfmt_sel sel); -int imx_media_enum_format (u32 *fourcc,u32 index,enum imx_pixfmt_sel sel); +imx_media_find_pixel_format (u32 fourcc,enum imx_pixfmt_sel sel); +int imx_media_enum_pixel_formats (u32 *fourcc,u32 index, +enum imx_pixfmt_sel sel);const struct imx_media_pixfmt *imx_media_find_mbus_format (u32 code,enum imx_pixfmt_sel sel); -int imx_media_enum_mbus_format (u32 *code,u32 index,enum imx_pixfmt_sel sel); +int imx_media_enum_mbus_formats (u32 *code,u32 index, +enum imx_pixfmt_sel sel);const struct imx_media_pixfmt *imx_media_find_ipu_format (u32 code,enum imx_pixfmt_sel sel); -int imx_media_enum_ipu_format (u32 *code,u32 index,enum imx_pixfmt_sel sel); +int imx_media_enum_ipu_formats (u32 *code,u32 index, +enum imx_pixfmt_sel sel);int imx_media_init_mbus_fmt (struct v4l2_mbus_framefmt *mbus,u32 width,u32 height,u32 code,u32 field,const struct imx_media_pixfmt **cc);
drivers/staging/media/imx/imx7-media-csi.c +3 -3
@@ -958,8 +958,8 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd,switch (code->pad) {case IMX7_CSI_PAD_SINK : - ret =imx_media_enum_mbus_format (&code->code, code->index, -PIXFMT_SEL_ANY ); + ret =imx_media_enum_mbus_formats (&code->code, code->index, +PIXFMT_SEL_ANY );break ;case IMX7_CSI_PAD_SRC :if (code->index !=0 ) {
@@ -1037,7 +1037,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, *cc =imx_media_find_mbus_format (sdformat->format.code,PIXFMT_SEL_ANY );if (!*cc) { -imx_media_enum_mbus_format (&code,0 ,PIXFMT_SEL_ANY ); +imx_media_enum_mbus_formats (&code,0 ,PIXFMT_SEL_ANY ); *cc =imx_media_find_mbus_format (code,PIXFMT_SEL_ANY ); sdformat->format.code = (*cc)->codes[0 ]; }
Signature · 1 line
2.17.1
Steve Longerbeam
maintainerPATCH v6 10/11 media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_*
In reply to Steve LongerbeamFrom: Laurent Pinchart <[email protected]>
The imx_media_mbus_fmt_to_pix_fmt() and imx_media_mbus_fmt_to_ipu_image() functions do not need to modify their mbus argument. Make them const.
--- drivers/staging/media/imx/imx-media-utils.c | 4 ++-- drivers/staging/media/imx/imx-media.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +2 -2
@@ -510,7 +510,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt,EXPORT_SYMBOL_GPL (imx_media_try_colorimetry);int imx_media_mbus_fmt_to_pix_fmt (struct v4l2_pix_format *pix, -struct v4l2_mbus_framefmt *mbus, +const struct v4l2_mbus_framefmt *mbus,const struct imx_media_pixfmt *cc) {u32 width;
@@ -562,7 +562,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,EXPORT_SYMBOL_GPL (imx_media_mbus_fmt_to_pix_fmt);int imx_media_mbus_fmt_to_ipu_image (struct ipu_image *image, -struct v4l2_mbus_framefmt *mbus) +const struct v4l2_mbus_framefmt *mbus) {int ret;
drivers/staging/media/imx/imx-media.h +2 -2
@@ -184,10 +184,10 @@ int imx_media_init_cfg(struct v4l2_subdev *sd,void imx_media_try_colorimetry (struct v4l2_mbus_framefmt *tryfmt,bool ic_route);int imx_media_mbus_fmt_to_pix_fmt (struct v4l2_pix_format *pix, -struct v4l2_mbus_framefmt *mbus, +const struct v4l2_mbus_framefmt *mbus,const struct imx_media_pixfmt *cc);int imx_media_mbus_fmt_to_ipu_image (struct ipu_image *image, -struct v4l2_mbus_framefmt *mbus); +const struct v4l2_mbus_framefmt *mbus);int imx_media_ipu_image_to_mbus_fmt (struct v4l2_mbus_framefmt *mbus,struct ipu_image *image); void imx_media_grp_id_to_sd_name(char *sd_name, int sz,
Signature · 1 line
2.17.1
Steve Longerbeam
maintainerPATCH v6 11/11 media: imx: utils: Constify ipu_image argument to imx_media_ipu_image_to_mbus_fmt()
In reply to Steve LongerbeamThe imx_media_ipu_image_to_mbus_fmt() function doesn't need to modify its ipu_image argument. Make it const.
--- drivers/staging/media/imx/imx-media-utils.c | 2 +- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/imx/imx-media-utils.c +1 -1
@@ -580,7 +580,7 @@ int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image,EXPORT_SYMBOL_GPL (imx_media_mbus_fmt_to_ipu_image);int imx_media_ipu_image_to_mbus_fmt (struct v4l2_mbus_framefmt *mbus, -struct ipu_image *image) +const struct ipu_image *image) {const struct imx_media_pixfmt *fmt;
drivers/staging/media/imx/imx-media.h +1 -1
@@ -189,7 +189,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,int imx_media_mbus_fmt_to_ipu_image (struct ipu_image *image,const struct v4l2_mbus_framefmt *mbus);int imx_media_ipu_image_to_mbus_fmt (struct v4l2_mbus_framefmt *mbus, -struct ipu_image *image); +const struct ipu_image *image);void imx_media_grp_id_to_sd_name (char *sd_name,int sz,u32 grp_id,int ipu_id); struct v4l2_subdev *
Signature · 1 line
2.17.1
Re: [PATCH v6 11/11] media: imx: utils: Constify ipu_image argument to imx_media_ipu_image_to_mbus_fmt()
Hi Steve,
Thank you for the patch.
Quoted 2 lines · Steve Longerbeam
The
imx_media_ipu_image_to_mbus_fmt()function doesn't need to modify itsipu_imageargument. Make it const.
You could squash this with patch 10/11. In any case,
Quoted 32 lines
Signed-off-by Steve Longerbeam <[email protected]>--- drivers/staging/media/imx/imx-media-utils.c | 2 +- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/staging/media/imx/imx-media-utils.c +1
-1@@ -580,7 +580,7 @@ int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image,EXPORT_SYMBOL_GPL (imx_media_mbus_fmt_to_ipu_image);int imx_media_ipu_image_to_mbus_fmt (struct v4l2_mbus_framefmt *mbus, -struct ipu_image *image) +const struct ipu_image *image) {const struct imx_media_pixfmt *fmt;drivers/staging/media/imx/imx-media.h +1
-1@@ -189,7 +189,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix,int imx_media_mbus_fmt_to_ipu_image (struct ipu_image *image,const struct v4l2_mbus_framefmt *mbus);int imx_media_ipu_image_to_mbus_fmt (struct v4l2_mbus_framefmt *mbus, -struct ipu_image *image); +const struct ipu_image *image);void imx_media_grp_id_to_sd_name (char *sd_name,int sz,u32 grp_id,int ipu_id); struct v4l2_subdev *
Signature · 3 lines
Regards, Laurent Pinchart
Hi Steve,
Quoted 11 lines · Steve Longerbeam
This series picks up Laurent Pinchart's series:
[PATCH 0/8] media: imx: Miscalleanous format-related cleanups
with a merge of two patches from Philipp Zabel's series:
[PATCH 1/3] media: imx: enable
V4L2_PIX_FMT_XBGR32,_BGRX32, and_RGBX32with an additional patch at the end that splits up the
find_enum_format()functions into separate functions for in-memory fourcc codes and mbus codes, as requested by Hans Verkuil in the series from Philipp.
Thank you. I've reviewed everything, there are only minor comments. Hans, do you want to go through the series before Steve posts the final v7 ?
Quoted 68 lines
History:
v6:
- Moved the last patch, "Split find|enum_format into fourcc and mbus functions", up in the series, which makes the patches cleaner and reduces the patch count by 1.
- "if (sel_ipu&& !fmt->ipufmt) ..." should be
"if (sel_ipu!=fmt->ipufmt) ...".v5:
- Added a patch that renames the pixel format selection enums/flags.
- Added a patch that adds another format selection flag, to select the IPU-internal formats. This is an alternative to the previous patch "media: imx: utils: Simplify IPU format lookup and enumeration".
- Add comments for the structimx_media_pixfmtmembers, with a warning that the codes pointer is NULL for the in-memory-only formats.v4:
- Constify mbus arg toimx_media_mbus_fmt_to_ipu_image().
- Constifyipu_imagearg toimx_media_ipu_image_to_mbus_fmt().
- Return-EINVALinimx_media_ipu_image_to_mbus_fmt()if given image pixelformat does not have mbus codes.v3:
- fixed derefencing a NULLcc->codeson return fromimx_media_find_format()in several places.v2:
- fixed a bug:
"for (j=0; j < fmt->codes[j]; j++)" should be
"for (j=0; fmt->codes[j]; j++)", in the mbus format enum functions. Caught by Laurent.
- move some local vars under the pixel_formats[] loop. Suggested by Laurent.
- decrement the index passed to the enum functions, instead of introducing amatch_indexlocal var. Suggested by Laurent.Laurent Pinchart (5):
media: imx: utils: Inlineinit_mbus_colorimetry()in its caller
media: imx: utils: Handle Bayer format lookup through a selection flag
media: imx: utils: Makeimx_media_pixfmthandle variable number of
codes
media: imx: utils: Rename format lookup and enumeration functions
media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_*Philipp Zabel (2):
media: imx: utils: fix and simplify pixel format enumeration
media: imx: utils: fix media bus format enumerationSteve Longerbeam (4):
media: imx: utils: Rename pixel format selection enumeration
media: imx: utils: IntroducePIXFMT_SEL_IPU
media: imx: utils: Split find|enum_format into fourcc and mbus
functions
media: imx: utils: Constifyipu_imageargument to
imx_media_ipu_image_to_mbus_fmt()drivers/staging/media/imx/imx-ic-prp.c | 13 +- drivers/staging/media/imx/imx-ic-prpencvf.c | 13 +- drivers/staging/media/imx/imx-media-capture.c | 42 +- .../staging/media/imx/imx-media-csc-scaler.c | 3 +- drivers/staging/media/imx/imx-media-csi.c | 42 +- drivers/staging/media/imx/imx-media-utils.c | 526 ++++++++---------- drivers/staging/media/imx/imx-media-vdic.c | 12 +- drivers/staging/media/imx/imx-media.h | 45 +- drivers/staging/media/imx/imx7-media-csi.c | 15 +- 9 files changed, 327 insertions(+), 384 deletions(-)
Signature · 3 lines
Regards, Laurent Pinchart