diff options
Diffstat (limited to 'drivers/staging/media/imx/imx-media-utils.c')
-rw-r--r-- | drivers/staging/media/imx/imx-media-utils.c | 118 |
1 files changed, 79 insertions, 39 deletions
diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 13dafa77a2eb..fab98fc0d6a0 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -93,7 +93,7 @@ static const struct imx_media_pixfmt rgb_formats[] = { .bpp = 32, .ipufmt = true, }, - /*** raw bayer formats start here ***/ + /*** raw bayer and grayscale formats start here ***/ { .fourcc = V4L2_PIX_FMT_SBGGR8, .codes = {MEDIA_BUS_FMT_SBGGR8_1X8}, @@ -162,6 +162,12 @@ static const struct imx_media_pixfmt rgb_formats[] = { .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, + }, { + .fourcc = V4L2_PIX_FMT_GREY, + .codes = {MEDIA_BUS_FMT_Y8_1X8}, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 8, + .bayer = true, }, /*** * non-mbus RGB formats start here. NOTE! when adding non-mbus @@ -219,58 +225,63 @@ 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) +{ + const struct imx_media_pixfmt *fmt; + int i, j; + + for (i = 0; i < array_size; i++) { + fmt = &array[i]; + + if ((!allow_non_mbus && !fmt->codes[0]) || + (!allow_bayer && fmt->bayer)) + continue; + + if (fourcc && fmt->fourcc == fourcc) + return fmt; + + if (!code) + continue; + + for (j = 0; 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 *array, *fmt, *ret = NULL; - u32 array_size; - int i, j; + const struct imx_media_pixfmt *ret; switch (cs_sel) { case CS_SEL_YUV: - array_size = NUM_YUV_FORMATS; - array = yuv_formats; - break; + return __find_format(fourcc, code, allow_non_mbus, allow_bayer, + yuv_formats, NUM_YUV_FORMATS); case CS_SEL_RGB: - array_size = NUM_RGB_FORMATS; - array = rgb_formats; - break; + return __find_format(fourcc, code, allow_non_mbus, allow_bayer, + rgb_formats, NUM_RGB_FORMATS); case CS_SEL_ANY: - array_size = NUM_YUV_FORMATS + NUM_RGB_FORMATS; - array = yuv_formats; - break; + 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; } - - for (i = 0; i < array_size; i++) { - if (cs_sel == CS_SEL_ANY && i >= NUM_YUV_FORMATS) - fmt = &rgb_formats[i - NUM_YUV_FORMATS]; - else - fmt = &array[i]; - - if ((!allow_non_mbus && fmt->codes[0] == 0) || - (!allow_bayer && fmt->bayer)) - continue; - - if (fourcc && fmt->fourcc == fourcc) { - ret = fmt; - goto out; - } - - for (j = 0; code && fmt->codes[j]; j++) { - if (code == fmt->codes[j]) { - ret = fmt; - goto out; - } - } - } - -out: - return ret; } static int enum_format(u32 *fourcc, u32 *code, u32 index, @@ -465,6 +476,35 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, EXPORT_SYMBOL_GPL(imx_media_init_mbus_fmt); /* + * Initializes the TRY format to the ACTIVE format on all pads + * of a subdev. Can be used as the .init_cfg pad operation. + */ +int imx_media_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg) +{ + struct v4l2_mbus_framefmt *mf_try; + struct v4l2_subdev_format format; + unsigned int pad; + int ret; + + for (pad = 0; pad < sd->entity.num_pads; pad++) { + memset(&format, 0, sizeof(format)); + + format.pad = pad; + format.which = V4L2_SUBDEV_FORMAT_ACTIVE; + ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); + if (ret) + continue; + + mf_try = v4l2_subdev_get_try_format(sd, cfg, pad); + *mf_try = format.format; + } + + return 0; +} +EXPORT_SYMBOL_GPL(imx_media_init_cfg); + +/* * Check whether the field and colorimetry parameters in tryfmt are * uninitialized, and if so fill them with the values from fmt, * or if tryfmt->colorspace has been initialized, all the default |