Commit 74cd3984 authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: imx: utils: Split find|enum_format into fourcc and mbus functions

To 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.

The convenience functions imx_media_find_ipu_format() and
imx_media_enum_ipu_format() can now be made inline and moved to
imx-media.h.
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent c943b694
...@@ -199,10 +199,15 @@ static const struct imx_media_pixfmt pixel_formats[] = { ...@@ -199,10 +199,15 @@ static const struct imx_media_pixfmt pixel_formats[] = {
}, },
}; };
static const struct imx_media_pixfmt *find_format(u32 fourcc, /*
u32 code, * Search in the pixel_formats[] array for an entry with the given fourcc
enum imx_pixfmt_sel fmt_sel, * that matches the requested selection criteria and return it.
bool allow_non_mbus) *
* @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; bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU;
unsigned int i; unsigned int i;
...@@ -212,7 +217,6 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ...@@ -212,7 +217,6 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
const struct imx_media_pixfmt *fmt = &pixel_formats[i]; const struct imx_media_pixfmt *fmt = &pixel_formats[i];
enum imx_pixfmt_sel sel; enum imx_pixfmt_sel sel;
unsigned int j;
if (sel_ipu != fmt->ipufmt) if (sel_ipu != fmt->ipufmt)
continue; continue;
...@@ -221,14 +225,42 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ...@@ -221,14 +225,42 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
((fmt->cs == IPUV3_COLORSPACE_YUV) ? ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);
if (!(fmt_sel & sel) || if ((fmt_sel & sel) && fmt->fourcc == fourcc)
(!allow_non_mbus && !fmt->codes)) return fmt;
}
return NULL;
}
EXPORT_SYMBOL_GPL(imx_media_find_format);
/*
* Search in the pixel_formats[] array for an entry with the given media
* bus code that matches the requested selection criteria and return it.
*
* @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; continue;
if (fourcc && fmt->fourcc == fourcc) sel = fmt->bayer ? PIXFMT_SEL_BAYER :
return fmt; ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);
if (!code || !fmt->codes) if (!(fmt_sel & sel) || !fmt->codes)
continue; continue;
for (j = 0; fmt->codes[j]; j++) { for (j = 0; fmt->codes[j]; j++) {
...@@ -239,10 +271,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ...@@ -239,10 +271,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
return NULL; 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, * Enumerate entries in the pixel_formats[] array that match the
bool allow_non_mbus) * requested selection criteria. Return 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; bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU;
unsigned int i; unsigned int i;
...@@ -252,7 +295,6 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ...@@ -252,7 +295,6 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
const struct imx_media_pixfmt *fmt = &pixel_formats[i]; const struct imx_media_pixfmt *fmt = &pixel_formats[i];
enum imx_pixfmt_sel sel; enum imx_pixfmt_sel sel;
unsigned int j;
if (sel_ipu != fmt->ipufmt) if (sel_ipu != fmt->ipufmt)
continue; continue;
...@@ -261,19 +303,54 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ...@@ -261,19 +303,54 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
((fmt->cs == IPUV3_COLORSPACE_YUV) ? ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); PIXFMT_SEL_YUV : PIXFMT_SEL_RGB);
if (!(fmt_sel & sel) || if (!(fmt_sel & sel))
(!allow_non_mbus && !fmt->codes))
continue; continue;
if (fourcc && index == 0) { if (index == 0) {
*fourcc = fmt->fourcc; *fourcc = fmt->fourcc;
return 0; 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. Return 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; continue;
}
for (j = 0; fmt->codes[j]; j++) { for (j = 0; fmt->codes[j]; j++) {
if (index == 0) { if (index == 0) {
...@@ -287,48 +364,8 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ...@@ -287,48 +364,8 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
return -EINVAL; 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); 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);
}
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);
}
EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format);
int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
u32 width, u32 height, u32 code, u32 field, u32 width, u32 height, u32 code, u32 field,
const struct imx_media_pixfmt **cc) const struct imx_media_pixfmt **cc)
......
...@@ -170,9 +170,20 @@ int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel sel); ...@@ -170,9 +170,20 @@ int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel sel);
const struct imx_media_pixfmt * const struct imx_media_pixfmt *
imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel 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); 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 imx_pixfmt_sel sel); static inline const struct imx_media_pixfmt *
int imx_media_enum_ipu_format(u32 *code, u32 index, enum imx_pixfmt_sel sel); imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel)
{
return imx_media_find_mbus_format(code, fmt_sel | PIXFMT_SEL_IPU);
}
static inline int imx_media_enum_ipu_format(u32 *code, u32 index,
enum imx_pixfmt_sel fmt_sel)
{
return imx_media_enum_mbus_format(code, index,
fmt_sel | PIXFMT_SEL_IPU);
}
int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
u32 width, u32 height, u32 code, u32 field, u32 width, u32 height, u32 code, u32 field,
const struct imx_media_pixfmt **cc); const struct imx_media_pixfmt **cc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment