Skip to content

Commit 5fd67a1

Browse files
mripard6by9
authored andcommitted
media: gc2145: Fix the RGB MBUS format
Upstream series https://lore.kernel.org/linux-media/[email protected]/ The GalaxyCore GC2145 is an MIPI-CSI2 sensor. Among others, it support the MIPI-CSI2 RGB565 format, listed in the driver as MEDIA_BUS_FMT_RGB565_1X16. Most CSI2 receiver drivers then map MEDIA_BUS_FMT_RGB565_1X16 to V4L2_PIX_FMT_RGB565. However, V4L2_PIX_FMT_RGB565 is defined as having its color components in the R, G and B order, from left to right. MIPI-CSI2 however defines the RGB565 format with blue first. This essentially means that the R and B will be swapped compared to what V4L2_PIX_FMT_RGB565 defines. The proper MBUS format would be BGR565, so let's use that. Fixes: 03cc7fe ("media: i2c: gc2145: Galaxy Core GC2145 sensor support") Signed-off-by: Maxime Ripard <[email protected]>
1 parent 2679781 commit 5fd67a1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

drivers/media/i2c/gc2145.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ static const struct gc2145_format supported_formats[] = {
582582
.output_fmt = 0x03,
583583
},
584584
{
585-
.code = MEDIA_BUS_FMT_RGB565_1X16,
585+
.code = MEDIA_BUS_FMT_BGR565_1X16,
586586
.colorspace = V4L2_COLORSPACE_SRGB,
587587
.datatype = MIPI_CSI2_DT_RGB565,
588588
.output_fmt = 0x06,
@@ -616,6 +616,21 @@ static const struct gc2145_format supported_formats[] = {
616616
.output_fmt = 0x17,
617617
.row_col_switch = GC2145_SYNC_MODE_ROW_SWITCH,
618618
},
619+
{
620+
/*
621+
* The driver was initially introduced with RGB565 support, but
622+
* CSI really means BGR.
623+
*
624+
* Since we might have applications that would have hard-coded
625+
* the RGB565, let's support both, with RGB being last to make
626+
* sure it's only a last resort.
627+
*/
628+
.code = MEDIA_BUS_FMT_RGB565_1X16,
629+
.colorspace = V4L2_COLORSPACE_SRGB,
630+
.datatype = MIPI_CSI2_DT_RGB565,
631+
.output_fmt = 0x06,
632+
.switch_bit = true,
633+
},
619634
};
620635

621636
struct gc2145_ctrls {
@@ -661,8 +676,13 @@ static inline struct v4l2_subdev *gc2145_ctrl_to_sd(struct v4l2_ctrl *ctrl)
661676
static const struct gc2145_format *
662677
gc2145_get_format_code(struct gc2145 *gc2145, u32 code)
663678
{
679+
struct i2c_client *client = v4l2_get_subdevdata(&gc2145->sd);
664680
unsigned int i;
665681

682+
if (code == MEDIA_BUS_FMT_RGB565_1X16)
683+
dev_warn_once(&client->dev,
684+
"RGB format isn't actually supported by the hardware. The application should be fixed to use BGR.");
685+
666686
for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
667687
if (supported_formats[i].code == code)
668688
break;
@@ -699,7 +719,7 @@ static int gc2145_init_state(struct v4l2_subdev *sd,
699719
/* Initialize pad format */
700720
format = v4l2_subdev_state_get_format(state, 0);
701721
gc2145_update_pad_format(gc2145, &supported_modes[0], format,
702-
MEDIA_BUS_FMT_RGB565_1X16,
722+
MEDIA_BUS_FMT_BGR565_1X16,
703723
V4L2_COLORSPACE_SRGB);
704724

705725
/* Initialize crop rectangle. */

0 commit comments

Comments
 (0)