[v2,10/11] mt9m111: rewrite set_pixfmt
Commit Message
added more supported BE colour formats
and also support BGR565 swapped pixel formats
removed pixfmt helper functions and option flags
setting the configuration register directly in set_pixfmt
Signed-off-by: Philipp Wiesner <p.wiesner@phytec.de>
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
Changes v1 -> v2
* removed unrelated OPMODE handling in this function
drivers/media/video/mt9m111.c | 143 ++++++++++++++++-------------------------
1 files changed, 56 insertions(+), 87 deletions(-)
Comments
Robert, I'll need your ack / tested by on this one too. It actually
changes behaviour, for example, it sets MT9M111_OUTFMT_FLIP_BAYER_ROW in
the OUTPUT_FORMAT_CTRL register for the V4L2_MBUS_FMT_SBGGR8_1X8 8 bit
Bayer format. Maybe other things too - please have a look.
Thanks
Guennadi
On Tue, 3 Aug 2010, Michael Grzeschik wrote:
> added more supported BE colour formats
> and also support BGR565 swapped pixel formats
>
> removed pixfmt helper functions and option flags
> setting the configuration register directly in set_pixfmt
>
> Signed-off-by: Philipp Wiesner <p.wiesner@phytec.de>
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> ---
> Changes v1 -> v2
> * removed unrelated OPMODE handling in this function
>
> drivers/media/video/mt9m111.c | 143 ++++++++++++++++-------------------------
> 1 files changed, 56 insertions(+), 87 deletions(-)
>
> diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
> index e865938..25b2317 100644
> --- a/drivers/media/video/mt9m111.c
> +++ b/drivers/media/video/mt9m111.c
> @@ -101,7 +101,8 @@
>
> #define MT9M111_OPMODE_AUTOEXPO_EN (1 << 14)
> #define MT9M111_OPMODE_AUTOWHITEBAL_EN (1 << 1)
> -
> +#define MT9M111_OUTFMT_FLIP_BAYER_COL (1 << 9)
> +#define MT9M111_OUTFMT_FLIP_BAYER_ROW (1 << 8)
> #define MT9M111_OUTFMT_PROCESSED_BAYER (1 << 14)
> #define MT9M111_OUTFMT_BYPASS_IFP (1 << 10)
> #define MT9M111_OUTFMT_INV_PIX_CLOCK (1 << 9)
> @@ -119,6 +120,7 @@
> #define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1 << 1)
> #define MT9M111_OUTFMT_SWAP_RGB_EVEN (1 << 1)
> #define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1 << 0)
> +#define MT9M111_OUTFMT_SWAP_RGB_R_B (1 << 0)
>
> /*
> * Camera control register addresses (0x200..0x2ff not implemented)
> @@ -161,7 +163,11 @@ static const struct mt9m111_datafmt mt9m111_colour_fmts[] = {
> {V4L2_MBUS_FMT_YUYV8_2X8_BE, V4L2_COLORSPACE_JPEG},
> {V4L2_MBUS_FMT_YVYU8_2X8_BE, V4L2_COLORSPACE_JPEG},
> {V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
> + {V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, V4L2_COLORSPACE_SRGB},
> {V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB},
> + {V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB},
> + {V4L2_MBUS_FMT_BGR565_2X8_LE, V4L2_COLORSPACE_SRGB},
> + {V4L2_MBUS_FMT_BGR565_2X8_BE, V4L2_COLORSPACE_SRGB},
> {V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB},
> {V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
> };
> @@ -184,10 +190,6 @@ struct mt9m111 {
> unsigned int powered:1;
> unsigned int hflip:1;
> unsigned int vflip:1;
> - unsigned int swap_rgb_even_odd:1;
> - unsigned int swap_rgb_red_blue:1;
> - unsigned int swap_yuv_y_chromas:1;
> - unsigned int swap_yuv_cb_cr:1;
> unsigned int autowhitebalance:1;
> };
>
> @@ -329,68 +331,6 @@ static int mt9m111_setup_rect(struct i2c_client *client,
> return ret;
> }
>
> -static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt)
> -{
> - int ret;
> -
> - ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt);
> - if (!ret)
> - ret = reg_write(OUTPUT_FORMAT_CTRL2_B, outfmt);
> - return ret;
> -}
> -
> -static int mt9m111_setfmt_bayer8(struct i2c_client *client)
> -{
> - return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER |
> - MT9M111_OUTFMT_RGB);
> -}
> -
> -static int mt9m111_setfmt_bayer10(struct i2c_client *client)
> -{
> - return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP);
> -}
> -
> -static int mt9m111_setfmt_rgb565(struct i2c_client *client)
> -{
> - struct mt9m111 *mt9m111 = to_mt9m111(client);
> - int val = 0;
> -
> - if (mt9m111->swap_rgb_red_blue)
> - val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
> - if (mt9m111->swap_rgb_even_odd)
> - val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
> - val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
> -
> - return mt9m111_setup_pixfmt(client, val);
> -}
> -
> -static int mt9m111_setfmt_rgb555(struct i2c_client *client)
> -{
> - struct mt9m111 *mt9m111 = to_mt9m111(client);
> - int val = 0;
> -
> - if (mt9m111->swap_rgb_red_blue)
> - val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
> - if (mt9m111->swap_rgb_even_odd)
> - val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
> - val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
> -
> - return mt9m111_setup_pixfmt(client, val);
> -}
> -
> -static int mt9m111_setfmt_yuv(struct i2c_client *client)
> -{
> - struct mt9m111 *mt9m111 = to_mt9m111(client);
> - int val = 0;
> -
> - if (mt9m111->swap_yuv_cb_cr)
> - val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
> - if (mt9m111->swap_yuv_y_chromas)
> - val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
> -
> - return mt9m111_setup_pixfmt(client, val);
> -}
> -
> static int mt9m111_enable(struct i2c_client *client)
> {
> struct mt9m111 *mt9m111 = to_mt9m111(client);
> @@ -518,41 +458,54 @@ static int mt9m111_g_fmt(struct v4l2_subdev *sd,
> static int mt9m111_set_pixfmt(struct i2c_client *client,
> enum v4l2_mbus_pixelcode code)
> {
> - struct mt9m111 *mt9m111 = to_mt9m111(client);
> + u16 data_outfmt1 = 0, data_outfmt2 = 0, mask_outfmt1, mask_outfmt2;
> int ret;
>
> switch (code) {
> case V4L2_MBUS_FMT_SBGGR8_1X8:
> - ret = mt9m111_setfmt_bayer8(client);
> + data_outfmt1 = MT9M111_OUTFMT_FLIP_BAYER_ROW;
> + data_outfmt2 = MT9M111_OUTFMT_PROCESSED_BAYER |
> + MT9M111_OUTFMT_RGB;
> break;
> case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE:
> - ret = mt9m111_setfmt_bayer10(client);
> + data_outfmt2 = MT9M111_OUTFMT_BYPASS_IFP | MT9M111_OUTFMT_RGB;
> break;
> case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE:
> - ret = mt9m111_setfmt_rgb555(client);
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_RGB_EVEN |
> + MT9M111_OUTFMT_RGB |
> + MT9M111_OUTFMT_RGB555;
> + break;
> + case V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE:
> + data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
> break;
> case V4L2_MBUS_FMT_RGB565_2X8_LE:
> - ret = mt9m111_setfmt_rgb565(client);
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_RGB_EVEN |
> + MT9M111_OUTFMT_RGB |
> + MT9M111_OUTFMT_RGB565;
> + break;
> + case V4L2_MBUS_FMT_RGB565_2X8_BE:
> + data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
> + break;
> + case V4L2_MBUS_FMT_BGR565_2X8_LE:
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr |
> + MT9M111_OUTFMT_SWAP_RGB_EVEN |
> + MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
> + break;
> + case V4L2_MBUS_FMT_BGR565_2X8_BE:
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr |
> + MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
> break;
> case V4L2_MBUS_FMT_YUYV8_2X8_BE:
> - mt9m111->swap_yuv_y_chromas = 0;
> - mt9m111->swap_yuv_cb_cr = 0;
> - ret = mt9m111_setfmt_yuv(client);
> break;
> case V4L2_MBUS_FMT_YVYU8_2X8_BE:
> - mt9m111->swap_yuv_y_chromas = 0;
> - mt9m111->swap_yuv_cb_cr = 1;
> - ret = mt9m111_setfmt_yuv(client);
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
> break;
> case V4L2_MBUS_FMT_YUYV8_2X8_LE:
> - mt9m111->swap_yuv_y_chromas = 1;
> - mt9m111->swap_yuv_cb_cr = 0;
> - ret = mt9m111_setfmt_yuv(client);
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
> break;
> case V4L2_MBUS_FMT_YVYU8_2X8_LE:
> - mt9m111->swap_yuv_y_chromas = 1;
> - mt9m111->swap_yuv_cb_cr = 1;
> - ret = mt9m111_setfmt_yuv(client);
> + data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_C_Y |
> + MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
> break;
> default:
> dev_err(&client->dev, "Pixel format not handled : %x\n",
> @@ -560,6 +513,25 @@ static int mt9m111_set_pixfmt(struct i2c_client *client,
> ret = -EINVAL;
> }
>
> + mask_outfmt1 = MT9M111_OUTFMT_FLIP_BAYER_COL |
> + MT9M111_OUTFMT_FLIP_BAYER_ROW;
> +
> + mask_outfmt2 = MT9M111_OUTFMT_PROCESSED_BAYER |
> + MT9M111_OUTFMT_BYPASS_IFP | MT9M111_OUTFMT_RGB |
> + MT9M111_OUTFMT_RGB565 | MT9M111_OUTFMT_RGB555 |
> + MT9M111_OUTFMT_RGB444x | MT9M111_OUTFMT_RGBx444 |
> + MT9M111_OUTFMT_SWAP_YCbCr_C_Y | MT9M111_OUTFMT_SWAP_RGB_EVEN |
> + MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr | MT9M111_OUTFMT_SWAP_RGB_R_B;
> +
> + ret = reg_mask(OUTPUT_FORMAT_CTRL, data_outfmt1, mask_outfmt1);
> +
> + if (!ret)
> + ret = reg_mask(OUTPUT_FORMAT_CTRL2_A, data_outfmt2,
> + mask_outfmt2);
> + if (!ret)
> + ret = reg_mask(OUTPUT_FORMAT_CTRL2_B, data_outfmt2,
> + mask_outfmt2);
> +
> return ret;
> }
>
> @@ -989,9 +961,6 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
> mt9m111->autoexposure = 1;
> mt9m111->autowhitebalance = 1;
>
> - mt9m111->swap_rgb_even_odd = 1;
> - mt9m111->swap_rgb_red_blue = 1;
> -
> data = reg_read(CHIP_VERSION);
>
> switch (data) {
> --
> 1.7.1
>
>
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Guennadi Liakhovetski <g.liakhovetski@gmx.de> writes:
> Robert, I'll need your ack / tested by on this one too. It actually
> changes behaviour, for example, it sets MT9M111_OUTFMT_FLIP_BAYER_ROW in
> the OUTPUT_FORMAT_CTRL register for the V4L2_MBUS_FMT_SBGGR8_1X8 8 bit
> Bayer format. Maybe other things too - please have a look.
For the YUV and RGB formats, tested and acked.
For the bayer, I don't use it. With row switch, that gives back:
byte offset: 0 1 2 3
B G B G
G R G R
Without the switch:
byte offset: 0 1 2 3
G R G R
B G B G
I would have expected the second version (ie. without the switch, ie. the
original version of mt9m111 driver) to be correct, but I might be wrong. Maybe
Michael can enlighten me here.
Hi Robert and Guennadi
On Sun, Aug 29, 2010 at 09:17:00PM +0200, Robert Jarzmik wrote:
> Guennadi Liakhovetski <g.liakhovetski@gmx.de> writes:
>
> > Robert, I'll need your ack / tested by on this one too. It actually
> > changes behaviour, for example, it sets MT9M111_OUTFMT_FLIP_BAYER_ROW in
> > the OUTPUT_FORMAT_CTRL register for the V4L2_MBUS_FMT_SBGGR8_1X8 8 bit
> > Bayer format. Maybe other things too - please have a look.
>
> For the YUV and RGB formats, tested and acked.
> For the bayer, I don't use it. With row switch, that gives back:
> byte offset: 0 1 2 3
> B G B G
> G R G R
>
> Without the switch:
> byte offset: 0 1 2 3
> G R G R
> B G B G
>
> I would have expected the second version (ie. without the switch, ie. the
> original version of mt9m111 driver) to be correct, but I might be wrong. Maybe
> Michael can enlighten me here.
Yes this seems odd, i normaly expect the first line to be BGBG.
I will search for the cause and reply a little later, perhaps end of
the week, since i am also short on time at this moment.
Michael
On Tue, 31 Aug 2010, Michael Grzeschik wrote:
> Hi Robert and Guennadi
>
> On Sun, Aug 29, 2010 at 09:17:00PM +0200, Robert Jarzmik wrote:
> > Guennadi Liakhovetski <g.liakhovetski@gmx.de> writes:
> >
> > > Robert, I'll need your ack / tested by on this one too. It actually
> > > changes behaviour, for example, it sets MT9M111_OUTFMT_FLIP_BAYER_ROW in
> > > the OUTPUT_FORMAT_CTRL register for the V4L2_MBUS_FMT_SBGGR8_1X8 8 bit
> > > Bayer format. Maybe other things too - please have a look.
> >
> > For the YUV and RGB formats, tested and acked.
> > For the bayer, I don't use it. With row switch, that gives back:
> > byte offset: 0 1 2 3
> > B G B G
> > G R G R
> >
> > Without the switch:
> > byte offset: 0 1 2 3
> > G R G R
> > B G B G
> >
> > I would have expected the second version (ie. without the switch, ie. the
> > original version of mt9m111 driver) to be correct, but I might be wrong. Maybe
> > Michael can enlighten me here.
> Yes this seems odd, i normaly expect the first line to be BGBG.
> I will search for the cause and reply a little later, perhaps end of
> the week, since i am also short on time at this moment.
Ok, _if_ you have to redo this patch, maybe you could also merge
[PATCH 04/11] mt9m111: added new bit offset defines
[PATCH 08/11] mt9m111: added reg_mask function
into it, otherwise their purpose is unclear.
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Michael, any insight?
Thanks
Guennadi
On Sat, 4 Sep 2010, Guennadi Liakhovetski wrote:
> On Tue, 31 Aug 2010, Michael Grzeschik wrote:
>
> > Hi Robert and Guennadi
> >
> > On Sun, Aug 29, 2010 at 09:17:00PM +0200, Robert Jarzmik wrote:
> > > Guennadi Liakhovetski <g.liakhovetski@gmx.de> writes:
> > >
> > > > Robert, I'll need your ack / tested by on this one too. It actually
> > > > changes behaviour, for example, it sets MT9M111_OUTFMT_FLIP_BAYER_ROW in
> > > > the OUTPUT_FORMAT_CTRL register for the V4L2_MBUS_FMT_SBGGR8_1X8 8 bit
> > > > Bayer format. Maybe other things too - please have a look.
> > >
> > > For the YUV and RGB formats, tested and acked.
> > > For the bayer, I don't use it. With row switch, that gives back:
> > > byte offset: 0 1 2 3
> > > B G B G
> > > G R G R
> > >
> > > Without the switch:
> > > byte offset: 0 1 2 3
> > > G R G R
> > > B G B G
> > >
> > > I would have expected the second version (ie. without the switch, ie. the
> > > original version of mt9m111 driver) to be correct, but I might be wrong. Maybe
> > > Michael can enlighten me here.
> > Yes this seems odd, i normaly expect the first line to be BGBG.
> > I will search for the cause and reply a little later, perhaps end of
> > the week, since i am also short on time at this moment.
>
> Ok, _if_ you have to redo this patch, maybe you could also merge
>
> [PATCH 04/11] mt9m111: added new bit offset defines
> [PATCH 08/11] mt9m111: added reg_mask function
>
> into it, otherwise their purpose is unclear.
>
> Thanks
> Guennadi
> ---
> Guennadi Liakhovetski, Ph.D.
> Freelance Open-Source Software Developer
> http://www.open-technology.de/
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sat, Oct 02, 2010 at 10:03:55AM +0200, Guennadi Liakhovetski wrote:
> Michael, any insight?
long time ago...
> > > > For the YUV and RGB formats, tested and acked.
> > > > For the bayer, I don't use it. With row switch, that gives back:
> > > > byte offset: 0 1 2 3
> > > > B G B G
> > > > G R G R
> > > >
> > > > Without the switch:
> > > > byte offset: 0 1 2 3
> > > > G R G R
> > > > B G B G
> > > >
> > > > I would have expected the second version (ie. without the switch, ie. the
> > > > original version of mt9m111 driver) to be correct, but I might be wrong. Maybe
> > > > Michael can enlighten me here.
> > > Yes this seems odd, i normaly expect the first line to be BGBG.
> > > I will search for the cause and reply a little later, perhaps end of
> > > the week, since i am also short on time at this moment.
I have reviewed the Datasheet of the Camera and found Roberts previously
described behaviour as correct. So the Bayercode seems functional in
that patch.
> > Ok, _if_ you have to redo this patch, maybe you could also merge
> >
> > [PATCH 04/11] mt9m111: added new bit offset defines
> > [PATCH 08/11] mt9m111: added reg_mask function
> >
> > into it, otherwise their purpose is unclear.
I will send a squashed Version of the three patches in some minutes.
Cheers,
Michael
@@ -101,7 +101,8 @@
#define MT9M111_OPMODE_AUTOEXPO_EN (1 << 14)
#define MT9M111_OPMODE_AUTOWHITEBAL_EN (1 << 1)
-
+#define MT9M111_OUTFMT_FLIP_BAYER_COL (1 << 9)
+#define MT9M111_OUTFMT_FLIP_BAYER_ROW (1 << 8)
#define MT9M111_OUTFMT_PROCESSED_BAYER (1 << 14)
#define MT9M111_OUTFMT_BYPASS_IFP (1 << 10)
#define MT9M111_OUTFMT_INV_PIX_CLOCK (1 << 9)
@@ -119,6 +120,7 @@
#define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1 << 1)
#define MT9M111_OUTFMT_SWAP_RGB_EVEN (1 << 1)
#define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1 << 0)
+#define MT9M111_OUTFMT_SWAP_RGB_R_B (1 << 0)
/*
* Camera control register addresses (0x200..0x2ff not implemented)
@@ -161,7 +163,11 @@ static const struct mt9m111_datafmt mt9m111_colour_fmts[] = {
{V4L2_MBUS_FMT_YUYV8_2X8_BE, V4L2_COLORSPACE_JPEG},
{V4L2_MBUS_FMT_YVYU8_2X8_BE, V4L2_COLORSPACE_JPEG},
{V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
+ {V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, V4L2_COLORSPACE_SRGB},
{V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB},
+ {V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB},
+ {V4L2_MBUS_FMT_BGR565_2X8_LE, V4L2_COLORSPACE_SRGB},
+ {V4L2_MBUS_FMT_BGR565_2X8_BE, V4L2_COLORSPACE_SRGB},
{V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB},
{V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE, V4L2_COLORSPACE_SRGB},
};
@@ -184,10 +190,6 @@ struct mt9m111 {
unsigned int powered:1;
unsigned int hflip:1;
unsigned int vflip:1;
- unsigned int swap_rgb_even_odd:1;
- unsigned int swap_rgb_red_blue:1;
- unsigned int swap_yuv_y_chromas:1;
- unsigned int swap_yuv_cb_cr:1;
unsigned int autowhitebalance:1;
};
@@ -329,68 +331,6 @@ static int mt9m111_setup_rect(struct i2c_client *client,
return ret;
}
-static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt)
-{
- int ret;
-
- ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt);
- if (!ret)
- ret = reg_write(OUTPUT_FORMAT_CTRL2_B, outfmt);
- return ret;
-}
-
-static int mt9m111_setfmt_bayer8(struct i2c_client *client)
-{
- return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER |
- MT9M111_OUTFMT_RGB);
-}
-
-static int mt9m111_setfmt_bayer10(struct i2c_client *client)
-{
- return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP);
-}
-
-static int mt9m111_setfmt_rgb565(struct i2c_client *client)
-{
- struct mt9m111 *mt9m111 = to_mt9m111(client);
- int val = 0;
-
- if (mt9m111->swap_rgb_red_blue)
- val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
- if (mt9m111->swap_rgb_even_odd)
- val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
- val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
-
- return mt9m111_setup_pixfmt(client, val);
-}
-
-static int mt9m111_setfmt_rgb555(struct i2c_client *client)
-{
- struct mt9m111 *mt9m111 = to_mt9m111(client);
- int val = 0;
-
- if (mt9m111->swap_rgb_red_blue)
- val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
- if (mt9m111->swap_rgb_even_odd)
- val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
- val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
-
- return mt9m111_setup_pixfmt(client, val);
-}
-
-static int mt9m111_setfmt_yuv(struct i2c_client *client)
-{
- struct mt9m111 *mt9m111 = to_mt9m111(client);
- int val = 0;
-
- if (mt9m111->swap_yuv_cb_cr)
- val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
- if (mt9m111->swap_yuv_y_chromas)
- val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
-
- return mt9m111_setup_pixfmt(client, val);
-}
-
static int mt9m111_enable(struct i2c_client *client)
{
struct mt9m111 *mt9m111 = to_mt9m111(client);
@@ -518,41 +458,54 @@ static int mt9m111_g_fmt(struct v4l2_subdev *sd,
static int mt9m111_set_pixfmt(struct i2c_client *client,
enum v4l2_mbus_pixelcode code)
{
- struct mt9m111 *mt9m111 = to_mt9m111(client);
+ u16 data_outfmt1 = 0, data_outfmt2 = 0, mask_outfmt1, mask_outfmt2;
int ret;
switch (code) {
case V4L2_MBUS_FMT_SBGGR8_1X8:
- ret = mt9m111_setfmt_bayer8(client);
+ data_outfmt1 = MT9M111_OUTFMT_FLIP_BAYER_ROW;
+ data_outfmt2 = MT9M111_OUTFMT_PROCESSED_BAYER |
+ MT9M111_OUTFMT_RGB;
break;
case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE:
- ret = mt9m111_setfmt_bayer10(client);
+ data_outfmt2 = MT9M111_OUTFMT_BYPASS_IFP | MT9M111_OUTFMT_RGB;
break;
case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE:
- ret = mt9m111_setfmt_rgb555(client);
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_RGB_EVEN |
+ MT9M111_OUTFMT_RGB |
+ MT9M111_OUTFMT_RGB555;
+ break;
+ case V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE:
+ data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
break;
case V4L2_MBUS_FMT_RGB565_2X8_LE:
- ret = mt9m111_setfmt_rgb565(client);
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_RGB_EVEN |
+ MT9M111_OUTFMT_RGB |
+ MT9M111_OUTFMT_RGB565;
+ break;
+ case V4L2_MBUS_FMT_RGB565_2X8_BE:
+ data_outfmt2 = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
+ break;
+ case V4L2_MBUS_FMT_BGR565_2X8_LE:
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr |
+ MT9M111_OUTFMT_SWAP_RGB_EVEN |
+ MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
+ break;
+ case V4L2_MBUS_FMT_BGR565_2X8_BE:
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr |
+ MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
break;
case V4L2_MBUS_FMT_YUYV8_2X8_BE:
- mt9m111->swap_yuv_y_chromas = 0;
- mt9m111->swap_yuv_cb_cr = 0;
- ret = mt9m111_setfmt_yuv(client);
break;
case V4L2_MBUS_FMT_YVYU8_2X8_BE:
- mt9m111->swap_yuv_y_chromas = 0;
- mt9m111->swap_yuv_cb_cr = 1;
- ret = mt9m111_setfmt_yuv(client);
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
break;
case V4L2_MBUS_FMT_YUYV8_2X8_LE:
- mt9m111->swap_yuv_y_chromas = 1;
- mt9m111->swap_yuv_cb_cr = 0;
- ret = mt9m111_setfmt_yuv(client);
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
break;
case V4L2_MBUS_FMT_YVYU8_2X8_LE:
- mt9m111->swap_yuv_y_chromas = 1;
- mt9m111->swap_yuv_cb_cr = 1;
- ret = mt9m111_setfmt_yuv(client);
+ data_outfmt2 = MT9M111_OUTFMT_SWAP_YCbCr_C_Y |
+ MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
break;
default:
dev_err(&client->dev, "Pixel format not handled : %x\n",
@@ -560,6 +513,25 @@ static int mt9m111_set_pixfmt(struct i2c_client *client,
ret = -EINVAL;
}
+ mask_outfmt1 = MT9M111_OUTFMT_FLIP_BAYER_COL |
+ MT9M111_OUTFMT_FLIP_BAYER_ROW;
+
+ mask_outfmt2 = MT9M111_OUTFMT_PROCESSED_BAYER |
+ MT9M111_OUTFMT_BYPASS_IFP | MT9M111_OUTFMT_RGB |
+ MT9M111_OUTFMT_RGB565 | MT9M111_OUTFMT_RGB555 |
+ MT9M111_OUTFMT_RGB444x | MT9M111_OUTFMT_RGBx444 |
+ MT9M111_OUTFMT_SWAP_YCbCr_C_Y | MT9M111_OUTFMT_SWAP_RGB_EVEN |
+ MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr | MT9M111_OUTFMT_SWAP_RGB_R_B;
+
+ ret = reg_mask(OUTPUT_FORMAT_CTRL, data_outfmt1, mask_outfmt1);
+
+ if (!ret)
+ ret = reg_mask(OUTPUT_FORMAT_CTRL2_A, data_outfmt2,
+ mask_outfmt2);
+ if (!ret)
+ ret = reg_mask(OUTPUT_FORMAT_CTRL2_B, data_outfmt2,
+ mask_outfmt2);
+
return ret;
}
@@ -989,9 +961,6 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
mt9m111->autoexposure = 1;
mt9m111->autowhitebalance = 1;
- mt9m111->swap_rgb_even_odd = 1;
- mt9m111->swap_rgb_red_blue = 1;
-
data = reg_read(CHIP_VERSION);
switch (data) {