Commit a89f14bb authored by Jacopo Mondi's avatar Jacopo Mondi Committed by Mauro Carvalho Chehab

media: ov5640: Split DVP and CSI-2 formats

The format enumeration list is shared between CSI-2 and DVP modes.
This lead to the enumeration of unsupported format variants in both
modes.

Separate the list of DVP and CSI-2 formats and create helpers to access
the correct one.
Signed-off-by: default avatarJacopo Mondi <jacopo@jmondi.org>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent dd81b8ff
...@@ -188,11 +188,13 @@ enum ov5640_format_mux { ...@@ -188,11 +188,13 @@ enum ov5640_format_mux {
OV5640_FMT_MUX_RAW_CIP, OV5640_FMT_MUX_RAW_CIP,
}; };
static const struct ov5640_pixfmt { struct ov5640_pixfmt {
u32 code; u32 code;
u32 colorspace; u32 colorspace;
u8 bpp; u8 bpp;
} ov5640_formats[] = { };
static const struct ov5640_pixfmt ov5640_dvp_formats[] = {
{ {
.code = MEDIA_BUS_FMT_JPEG_1X8, .code = MEDIA_BUS_FMT_JPEG_1X8,
.colorspace = V4L2_COLORSPACE_JPEG, .colorspace = V4L2_COLORSPACE_JPEG,
...@@ -202,23 +204,48 @@ static const struct ov5640_pixfmt { ...@@ -202,23 +204,48 @@ static const struct ov5640_pixfmt {
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 16, .bpp = 16,
}, { }, {
.code = MEDIA_BUS_FMT_UYVY8_1X16, .code = MEDIA_BUS_FMT_YUYV8_2X8,
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 16, .bpp = 16,
}, { }, {
.code = MEDIA_BUS_FMT_YUYV8_2X8, .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 16, .bpp = 16,
}, { }, {
.code = MEDIA_BUS_FMT_YUYV8_1X16, .code = MEDIA_BUS_FMT_RGB565_2X8_BE,
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 16, .bpp = 16,
}, { }, {
.code = MEDIA_BUS_FMT_RGB565_2X8_LE, .code = MEDIA_BUS_FMT_SBGGR8_1X8,
.colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 8,
}, {
.code = MEDIA_BUS_FMT_SGBRG8_1X8,
.colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 8
}, {
.code = MEDIA_BUS_FMT_SGRBG8_1X8,
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 8,
}, {
.code = MEDIA_BUS_FMT_SRGGB8_1X8,
.colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 8,
},
{ /* sentinel */ }
};
static const struct ov5640_pixfmt ov5640_csi2_formats[] = {
{
.code = MEDIA_BUS_FMT_JPEG_1X8,
.colorspace = V4L2_COLORSPACE_JPEG,
.bpp = 16, .bpp = 16,
}, { }, {
.code = MEDIA_BUS_FMT_RGB565_2X8_BE, .code = MEDIA_BUS_FMT_UYVY8_1X16,
.colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 16,
}, {
.code = MEDIA_BUS_FMT_YUYV8_1X16,
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 16, .bpp = 16,
}, { }, {
...@@ -246,20 +273,9 @@ static const struct ov5640_pixfmt { ...@@ -246,20 +273,9 @@ static const struct ov5640_pixfmt {
.colorspace = V4L2_COLORSPACE_SRGB, .colorspace = V4L2_COLORSPACE_SRGB,
.bpp = 8, .bpp = 8,
}, },
{ /* sentinel */ }
}; };
static u32 ov5640_code_to_bpp(u32 code)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(ov5640_formats); ++i) {
if (ov5640_formats[i].code == code)
return ov5640_formats[i].bpp;
}
return 0;
}
/* /*
* FIXME: remove this when a subdev API becomes available * FIXME: remove this when a subdev API becomes available
* to set the MIPI CSI-2 virtual channel. * to set the MIPI CSI-2 virtual channel.
...@@ -411,6 +427,35 @@ static inline bool ov5640_is_csi2(const struct ov5640_dev *sensor) ...@@ -411,6 +427,35 @@ static inline bool ov5640_is_csi2(const struct ov5640_dev *sensor)
return sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY; return sensor->ep.bus_type == V4L2_MBUS_CSI2_DPHY;
} }
static inline const struct ov5640_pixfmt *
ov5640_formats(struct ov5640_dev *sensor)
{
return ov5640_is_csi2(sensor) ? ov5640_csi2_formats
: ov5640_dvp_formats;
}
static const struct ov5640_pixfmt *
ov5640_code_to_pixfmt(struct ov5640_dev *sensor, u32 code)
{
const struct ov5640_pixfmt *formats = ov5640_formats(sensor);
unsigned int i;
for (i = 0; formats[i].code; ++i) {
if (formats[i].code == code)
return &formats[i];
}
return &formats[0];
}
static u32 ov5640_code_to_bpp(struct ov5640_dev *sensor, u32 code)
{
const struct ov5640_pixfmt *format = ov5640_code_to_pixfmt(sensor,
code);
return format->bpp;
}
/* /*
* FIXME: all of these register tables are likely filled with * FIXME: all of these register tables are likely filled with
* entries that set the register to their power-on default values, * entries that set the register to their power-on default values,
...@@ -1472,7 +1517,7 @@ static int ov5640_set_dvp_pclk(struct ov5640_dev *sensor) ...@@ -1472,7 +1517,7 @@ static int ov5640_set_dvp_pclk(struct ov5640_dev *sensor)
int ret; int ret;
rate = ov5640_calc_pixel_rate(sensor); rate = ov5640_calc_pixel_rate(sensor);
rate *= ov5640_code_to_bpp(sensor->fmt.code); rate *= ov5640_code_to_bpp(sensor, sensor->fmt.code);
rate /= sensor->ep.bus.parallel.bus_width; rate /= sensor->ep.bus.parallel.bus_width;
ov5640_calc_pclk(sensor, rate, &prediv, &mult, &sysdiv, &pll_rdiv, ov5640_calc_pclk(sensor, rate, &prediv, &mult, &sysdiv, &pll_rdiv,
...@@ -2698,15 +2743,18 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, ...@@ -2698,15 +2743,18 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
enum ov5640_frame_rate fr, enum ov5640_frame_rate fr,
const struct ov5640_mode_info **new_mode) const struct ov5640_mode_info **new_mode)
{ {
unsigned int bpp = ov5640_code_to_bpp(fmt->code);
struct ov5640_dev *sensor = to_ov5640_dev(sd); struct ov5640_dev *sensor = to_ov5640_dev(sd);
const struct ov5640_mode_info *mode; const struct ov5640_mode_info *mode;
int i; const struct ov5640_pixfmt *pixfmt;
unsigned int bpp;
mode = ov5640_find_mode(sensor, fmt->width, fmt->height, true); mode = ov5640_find_mode(sensor, fmt->width, fmt->height, true);
if (!mode) if (!mode)
return -EINVAL; return -EINVAL;
pixfmt = ov5640_code_to_pixfmt(sensor, fmt->code);
bpp = pixfmt->bpp;
/* /*
* Adjust mode according to bpp: * Adjust mode according to bpp:
* - 8bpp modes work for resolution >= 1280x720 * - 8bpp modes work for resolution >= 1280x720
...@@ -2723,14 +2771,8 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd, ...@@ -2723,14 +2771,8 @@ static int ov5640_try_fmt_internal(struct v4l2_subdev *sd,
if (new_mode) if (new_mode)
*new_mode = mode; *new_mode = mode;
for (i = 0; i < ARRAY_SIZE(ov5640_formats); i++) fmt->code = pixfmt->code;
if (ov5640_formats[i].code == fmt->code) fmt->colorspace = pixfmt->colorspace;
break;
if (i >= ARRAY_SIZE(ov5640_formats))
i = 0;
fmt->code = ov5640_formats[i].code;
fmt->colorspace = ov5640_formats[i].colorspace;
fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace); fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->colorspace);
fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE; fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace); fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(fmt->colorspace);
...@@ -2773,7 +2815,7 @@ static int ov5640_update_pixel_rate(struct ov5640_dev *sensor) ...@@ -2773,7 +2815,7 @@ static int ov5640_update_pixel_rate(struct ov5640_dev *sensor)
* progressively slow it down if it exceeds 1GHz. * progressively slow it down if it exceeds 1GHz.
*/ */
num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes; num_lanes = sensor->ep.bus.mipi_csi2.num_data_lanes;
bpp = ov5640_code_to_bpp(fmt->code); bpp = ov5640_code_to_bpp(sensor, fmt->code);
do { do {
pixel_rate = ov5640_pixel_rates[pixel_rate_id]; pixel_rate = ov5640_pixel_rates[pixel_rate_id];
link_freq = pixel_rate * bpp / (2 * num_lanes); link_freq = pixel_rate * bpp / (2 * num_lanes);
...@@ -3486,7 +3528,8 @@ static int ov5640_enum_frame_size(struct v4l2_subdev *sd, ...@@ -3486,7 +3528,8 @@ static int ov5640_enum_frame_size(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state, struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_size_enum *fse) struct v4l2_subdev_frame_size_enum *fse)
{ {
u32 bpp = ov5640_code_to_bpp(fse->code); struct ov5640_dev *sensor = to_ov5640_dev(sd);
u32 bpp = ov5640_code_to_bpp(sensor, fse->code);
unsigned int index = fse->index; unsigned int index = fse->index;
if (fse->pad != 0) if (fse->pad != 0)
...@@ -3608,12 +3651,23 @@ static int ov5640_enum_mbus_code(struct v4l2_subdev *sd, ...@@ -3608,12 +3651,23 @@ static int ov5640_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state, struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code) struct v4l2_subdev_mbus_code_enum *code)
{ {
if (code->pad != 0) struct ov5640_dev *sensor = to_ov5640_dev(sd);
return -EINVAL; const struct ov5640_pixfmt *formats;
if (code->index >= ARRAY_SIZE(ov5640_formats)) unsigned int num_formats;
if (ov5640_is_csi2(sensor)) {
formats = ov5640_csi2_formats;
num_formats = ARRAY_SIZE(ov5640_csi2_formats) - 1;
} else {
formats = ov5640_dvp_formats;
num_formats = ARRAY_SIZE(ov5640_dvp_formats) - 1;
}
if (code->index >= num_formats)
return -EINVAL; return -EINVAL;
code->code = ov5640_formats[code->index].code; code->code = formats[code->index].code;
return 0; return 0;
} }
......
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