Commit 2768cbbb authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mauro Carvalho Chehab

[media] V4L: mt9m111: propagate higher level abstraction down in functions

It is more convenient to propagate the higher level abstraction - the
struct mt9m111 object into functions and then retrieve a pointer to
the i2c client, if needed, than to do the reverse.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent b7ccdba0
...@@ -251,9 +251,10 @@ static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg, ...@@ -251,9 +251,10 @@ static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg,
return mt9m111_reg_write(client, reg, ret & ~data); return mt9m111_reg_write(client, reg, ret & ~data);
} }
static int mt9m111_set_context(struct i2c_client *client, static int mt9m111_set_context(struct mt9m111 *mt9m111,
enum mt9m111_context ctxt) enum mt9m111_context ctxt)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B
| MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B
| MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B
...@@ -267,10 +268,10 @@ static int mt9m111_set_context(struct i2c_client *client, ...@@ -267,10 +268,10 @@ static int mt9m111_set_context(struct i2c_client *client,
return reg_write(CONTEXT_CONTROL, valA); return reg_write(CONTEXT_CONTROL, valA);
} }
static int mt9m111_setup_rect(struct i2c_client *client, static int mt9m111_setup_rect(struct mt9m111 *mt9m111,
struct v4l2_rect *rect) struct v4l2_rect *rect)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret, is_raw_format; int ret, is_raw_format;
int width = rect->width; int width = rect->width;
int height = rect->height; int height = rect->height;
...@@ -332,48 +333,50 @@ static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt) ...@@ -332,48 +333,50 @@ static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt)
return ret; return ret;
} }
static int mt9m111_setfmt_bayer8(struct i2c_client *client) static int mt9m111_setfmt_bayer8(struct mt9m111 *mt9m111)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER | return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER |
MT9M111_OUTFMT_RGB); MT9M111_OUTFMT_RGB);
} }
static int mt9m111_setfmt_bayer10(struct i2c_client *client) static int mt9m111_setfmt_bayer10(struct mt9m111 *mt9m111)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP); return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP);
} }
static int mt9m111_setfmt_rgb565(struct i2c_client *client) static int mt9m111_setfmt_rgb565(struct mt9m111 *mt9m111)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int val = 0; int val = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
if (mt9m111->swap_rgb_red_blue) if (mt9m111->swap_rgb_red_blue)
val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
if (mt9m111->swap_rgb_even_odd) if (mt9m111->swap_rgb_even_odd)
val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
return mt9m111_setup_pixfmt(client, val); return mt9m111_setup_pixfmt(client, val);
} }
static int mt9m111_setfmt_rgb555(struct i2c_client *client) static int mt9m111_setfmt_rgb555(struct mt9m111 *mt9m111)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int val = 0; int val = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
if (mt9m111->swap_rgb_red_blue) if (mt9m111->swap_rgb_red_blue)
val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
if (mt9m111->swap_rgb_even_odd) if (mt9m111->swap_rgb_even_odd)
val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
return mt9m111_setup_pixfmt(client, val); return mt9m111_setup_pixfmt(client, val);
} }
static int mt9m111_setfmt_yuv(struct i2c_client *client) static int mt9m111_setfmt_yuv(struct mt9m111 *mt9m111)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int val = 0; int val = 0;
if (mt9m111->swap_yuv_cb_cr) if (mt9m111->swap_yuv_cb_cr)
...@@ -384,9 +387,9 @@ static int mt9m111_setfmt_yuv(struct i2c_client *client) ...@@ -384,9 +387,9 @@ static int mt9m111_setfmt_yuv(struct i2c_client *client)
return mt9m111_setup_pixfmt(client, val); return mt9m111_setup_pixfmt(client, val);
} }
static int mt9m111_enable(struct i2c_client *client) static int mt9m111_enable(struct mt9m111 *mt9m111)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret; int ret;
ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE); ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE);
...@@ -395,8 +398,9 @@ static int mt9m111_enable(struct i2c_client *client) ...@@ -395,8 +398,9 @@ static int mt9m111_enable(struct i2c_client *client)
return ret; return ret;
} }
static int mt9m111_reset(struct i2c_client *client) static int mt9m111_reset(struct mt9m111 *mt9m111)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret; int ret;
ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
...@@ -424,11 +428,9 @@ static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f) ...@@ -424,11 +428,9 @@ static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
return 0; return 0;
} }
static int mt9m111_make_rect(struct i2c_client *client, static int mt9m111_make_rect(struct mt9m111 *mt9m111,
struct v4l2_rect *rect) struct v4l2_rect *rect)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client);
if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 || if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 ||
mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) { mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) {
/* Bayer format - even size lengths */ /* Bayer format - even size lengths */
...@@ -444,14 +446,14 @@ static int mt9m111_make_rect(struct i2c_client *client, ...@@ -444,14 +446,14 @@ static int mt9m111_make_rect(struct i2c_client *client,
soc_camera_limit_side(&rect->top, &rect->height, soc_camera_limit_side(&rect->top, &rect->height,
MT9M111_MIN_DARK_ROWS, 2, MT9M111_MAX_HEIGHT); MT9M111_MIN_DARK_ROWS, 2, MT9M111_MAX_HEIGHT);
return mt9m111_setup_rect(client, rect); return mt9m111_setup_rect(mt9m111, rect);
} }
static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
{ {
struct v4l2_rect rect = a->c; struct v4l2_rect rect = a->c;
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct mt9m111 *mt9m111 = to_mt9m111(client); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
int ret; int ret;
dev_dbg(&client->dev, "%s left=%d, top=%d, width=%d, height=%d\n", dev_dbg(&client->dev, "%s left=%d, top=%d, width=%d, height=%d\n",
...@@ -460,7 +462,7 @@ static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) ...@@ -460,7 +462,7 @@ static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
ret = mt9m111_make_rect(client, &rect); ret = mt9m111_make_rect(mt9m111, &rect);
if (!ret) if (!ret)
mt9m111->rect = rect; mt9m111->rect = rect;
return ret; return ret;
...@@ -468,8 +470,7 @@ static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) ...@@ -468,8 +470,7 @@ static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
struct mt9m111 *mt9m111 = to_mt9m111(client);
a->c = mt9m111->rect; a->c = mt9m111->rect;
a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
...@@ -496,8 +497,7 @@ static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) ...@@ -496,8 +497,7 @@ static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
static int mt9m111_g_fmt(struct v4l2_subdev *sd, static int mt9m111_g_fmt(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *mf) struct v4l2_mbus_framefmt *mf)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
struct mt9m111 *mt9m111 = to_mt9m111(client);
mf->width = mt9m111->rect.width; mf->width = mt9m111->rect.width;
mf->height = mt9m111->rect.height; mf->height = mt9m111->rect.height;
...@@ -508,46 +508,47 @@ static int mt9m111_g_fmt(struct v4l2_subdev *sd, ...@@ -508,46 +508,47 @@ static int mt9m111_g_fmt(struct v4l2_subdev *sd,
return 0; return 0;
} }
static int mt9m111_set_pixfmt(struct i2c_client *client, static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111,
enum v4l2_mbus_pixelcode code) enum v4l2_mbus_pixelcode code)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client;
int ret; int ret;
switch (code) { switch (code) {
case V4L2_MBUS_FMT_SBGGR8_1X8: case V4L2_MBUS_FMT_SBGGR8_1X8:
ret = mt9m111_setfmt_bayer8(client); ret = mt9m111_setfmt_bayer8(mt9m111);
break; break;
case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE: case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE:
ret = mt9m111_setfmt_bayer10(client); ret = mt9m111_setfmt_bayer10(mt9m111);
break; break;
case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE: case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE:
ret = mt9m111_setfmt_rgb555(client); ret = mt9m111_setfmt_rgb555(mt9m111);
break; break;
case V4L2_MBUS_FMT_RGB565_2X8_LE: case V4L2_MBUS_FMT_RGB565_2X8_LE:
ret = mt9m111_setfmt_rgb565(client); ret = mt9m111_setfmt_rgb565(mt9m111);
break; break;
case V4L2_MBUS_FMT_UYVY8_2X8: case V4L2_MBUS_FMT_UYVY8_2X8:
mt9m111->swap_yuv_y_chromas = 0; mt9m111->swap_yuv_y_chromas = 0;
mt9m111->swap_yuv_cb_cr = 0; mt9m111->swap_yuv_cb_cr = 0;
ret = mt9m111_setfmt_yuv(client); ret = mt9m111_setfmt_yuv(mt9m111);
break; break;
case V4L2_MBUS_FMT_VYUY8_2X8: case V4L2_MBUS_FMT_VYUY8_2X8:
mt9m111->swap_yuv_y_chromas = 0; mt9m111->swap_yuv_y_chromas = 0;
mt9m111->swap_yuv_cb_cr = 1; mt9m111->swap_yuv_cb_cr = 1;
ret = mt9m111_setfmt_yuv(client); ret = mt9m111_setfmt_yuv(mt9m111);
break; break;
case V4L2_MBUS_FMT_YUYV8_2X8: case V4L2_MBUS_FMT_YUYV8_2X8:
mt9m111->swap_yuv_y_chromas = 1; mt9m111->swap_yuv_y_chromas = 1;
mt9m111->swap_yuv_cb_cr = 0; mt9m111->swap_yuv_cb_cr = 0;
ret = mt9m111_setfmt_yuv(client); ret = mt9m111_setfmt_yuv(mt9m111);
break; break;
case V4L2_MBUS_FMT_YVYU8_2X8: case V4L2_MBUS_FMT_YVYU8_2X8:
mt9m111->swap_yuv_y_chromas = 1; mt9m111->swap_yuv_y_chromas = 1;
mt9m111->swap_yuv_cb_cr = 1; mt9m111->swap_yuv_cb_cr = 1;
ret = mt9m111_setfmt_yuv(client); ret = mt9m111_setfmt_yuv(mt9m111);
break; break;
default: default:
client = v4l2_get_subdevdata(&mt9m111->subdev);
dev_err(&client->dev, "Pixel format not handled : %x\n", dev_err(&client->dev, "Pixel format not handled : %x\n",
code); code);
ret = -EINVAL; ret = -EINVAL;
...@@ -561,7 +562,7 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd, ...@@ -561,7 +562,7 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
const struct mt9m111_datafmt *fmt; const struct mt9m111_datafmt *fmt;
struct mt9m111 *mt9m111 = to_mt9m111(client); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
struct v4l2_rect rect = { struct v4l2_rect rect = {
.left = mt9m111->rect.left, .left = mt9m111->rect.left,
.top = mt9m111->rect.top, .top = mt9m111->rect.top,
...@@ -579,9 +580,9 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd, ...@@ -579,9 +580,9 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
"%s code=%x left=%d, top=%d, width=%d, height=%d\n", __func__, "%s code=%x left=%d, top=%d, width=%d, height=%d\n", __func__,
mf->code, rect.left, rect.top, rect.width, rect.height); mf->code, rect.left, rect.top, rect.width, rect.height);
ret = mt9m111_make_rect(client, &rect); ret = mt9m111_make_rect(mt9m111, &rect);
if (!ret) if (!ret)
ret = mt9m111_set_pixfmt(client, mf->code); ret = mt9m111_set_pixfmt(mt9m111, mf->code);
if (!ret) { if (!ret) {
mt9m111->rect = rect; mt9m111->rect = rect;
mt9m111->fmt = fmt; mt9m111->fmt = fmt;
...@@ -594,8 +595,7 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd, ...@@ -594,8 +595,7 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
static int mt9m111_try_fmt(struct v4l2_subdev *sd, static int mt9m111_try_fmt(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *mf) struct v4l2_mbus_framefmt *mf)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
struct mt9m111 *mt9m111 = to_mt9m111(client);
const struct mt9m111_datafmt *fmt; const struct mt9m111_datafmt *fmt;
bool bayer = mf->code == V4L2_MBUS_FMT_SBGGR8_1X8 || bool bayer = mf->code == V4L2_MBUS_FMT_SBGGR8_1X8 ||
mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE; mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE;
...@@ -635,7 +635,7 @@ static int mt9m111_g_chip_ident(struct v4l2_subdev *sd, ...@@ -635,7 +635,7 @@ static int mt9m111_g_chip_ident(struct v4l2_subdev *sd,
struct v4l2_dbg_chip_ident *id) struct v4l2_dbg_chip_ident *id)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct mt9m111 *mt9m111 = to_mt9m111(client); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
return -EINVAL; return -EINVAL;
...@@ -738,9 +738,9 @@ static struct soc_camera_ops mt9m111_ops = { ...@@ -738,9 +738,9 @@ static struct soc_camera_ops mt9m111_ops = {
.num_controls = ARRAY_SIZE(mt9m111_controls), .num_controls = ARRAY_SIZE(mt9m111_controls),
}; };
static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask) static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret; int ret;
if (mt9m111->context == HIGHPOWER) { if (mt9m111->context == HIGHPOWER) {
...@@ -758,8 +758,9 @@ static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask) ...@@ -758,8 +758,9 @@ static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask)
return ret; return ret;
} }
static int mt9m111_get_global_gain(struct i2c_client *client) static int mt9m111_get_global_gain(struct mt9m111 *mt9m111)
{ {
struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int data; int data;
data = reg_read(GLOBAL_GAIN); data = reg_read(GLOBAL_GAIN);
...@@ -769,9 +770,9 @@ static int mt9m111_get_global_gain(struct i2c_client *client) ...@@ -769,9 +770,9 @@ static int mt9m111_get_global_gain(struct i2c_client *client)
return data; return data;
} }
static int mt9m111_set_global_gain(struct i2c_client *client, int gain) static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
u16 val; u16 val;
if (gain > 63 * 2 * 2) if (gain > 63 * 2 * 2)
...@@ -788,9 +789,9 @@ static int mt9m111_set_global_gain(struct i2c_client *client, int gain) ...@@ -788,9 +789,9 @@ static int mt9m111_set_global_gain(struct i2c_client *client, int gain)
return reg_write(GLOBAL_GAIN, val); return reg_write(GLOBAL_GAIN, val);
} }
static int mt9m111_set_autoexposure(struct i2c_client *client, int on) static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret; int ret;
if (on) if (on)
...@@ -804,9 +805,9 @@ static int mt9m111_set_autoexposure(struct i2c_client *client, int on) ...@@ -804,9 +805,9 @@ static int mt9m111_set_autoexposure(struct i2c_client *client, int on)
return ret; return ret;
} }
static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on) static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret; int ret;
if (on) if (on)
...@@ -823,7 +824,7 @@ static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on) ...@@ -823,7 +824,7 @@ static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on)
static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct i2c_client *client = v4l2_get_subdevdata(sd);
struct mt9m111 *mt9m111 = to_mt9m111(client); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
int data; int data;
switch (ctrl->id) { switch (ctrl->id) {
...@@ -848,7 +849,7 @@ static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) ...@@ -848,7 +849,7 @@ static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS); ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
break; break;
case V4L2_CID_GAIN: case V4L2_CID_GAIN:
data = mt9m111_get_global_gain(client); data = mt9m111_get_global_gain(mt9m111);
if (data < 0) if (data < 0)
return data; return data;
ctrl->value = data; ctrl->value = data;
...@@ -865,8 +866,7 @@ static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) ...@@ -865,8 +866,7 @@ static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{ {
struct i2c_client *client = v4l2_get_subdevdata(sd); struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
struct mt9m111 *mt9m111 = to_mt9m111(client);
const struct v4l2_queryctrl *qctrl; const struct v4l2_queryctrl *qctrl;
int ret; int ret;
...@@ -877,22 +877,22 @@ static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) ...@@ -877,22 +877,22 @@ static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_VFLIP: case V4L2_CID_VFLIP:
mt9m111->vflip = ctrl->value; mt9m111->vflip = ctrl->value;
ret = mt9m111_set_flip(client, ctrl->value, ret = mt9m111_set_flip(mt9m111, ctrl->value,
MT9M111_RMB_MIRROR_ROWS); MT9M111_RMB_MIRROR_ROWS);
break; break;
case V4L2_CID_HFLIP: case V4L2_CID_HFLIP:
mt9m111->hflip = ctrl->value; mt9m111->hflip = ctrl->value;
ret = mt9m111_set_flip(client, ctrl->value, ret = mt9m111_set_flip(mt9m111, ctrl->value,
MT9M111_RMB_MIRROR_COLS); MT9M111_RMB_MIRROR_COLS);
break; break;
case V4L2_CID_GAIN: case V4L2_CID_GAIN:
ret = mt9m111_set_global_gain(client, ctrl->value); ret = mt9m111_set_global_gain(mt9m111, ctrl->value);
break; break;
case V4L2_CID_EXPOSURE_AUTO: case V4L2_CID_EXPOSURE_AUTO:
ret = mt9m111_set_autoexposure(client, ctrl->value); ret = mt9m111_set_autoexposure(mt9m111, ctrl->value);
break; break;
case V4L2_CID_AUTO_WHITE_BALANCE: case V4L2_CID_AUTO_WHITE_BALANCE:
ret = mt9m111_set_autowhitebalance(client, ctrl->value); ret = mt9m111_set_autowhitebalance(mt9m111, ctrl->value);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -906,24 +906,21 @@ static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state) ...@@ -906,24 +906,21 @@ static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state)
struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
struct mt9m111 *mt9m111 = to_mt9m111(client); struct mt9m111 *mt9m111 = to_mt9m111(client);
mt9m111->gain = mt9m111_get_global_gain(client); mt9m111->gain = mt9m111_get_global_gain(mt9m111);
return 0; return 0;
} }
static int mt9m111_restore_state(struct i2c_client *client) static void mt9m111_restore_state(struct mt9m111 *mt9m111)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); mt9m111_set_context(mt9m111, mt9m111->context);
mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code);
mt9m111_set_context(client, mt9m111->context); mt9m111_setup_rect(mt9m111, &mt9m111->rect);
mt9m111_set_pixfmt(client, mt9m111->fmt->code); mt9m111_set_flip(mt9m111, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
mt9m111_setup_rect(client, &mt9m111->rect); mt9m111_set_flip(mt9m111, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
mt9m111_set_flip(client, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); mt9m111_set_global_gain(mt9m111, mt9m111->gain);
mt9m111_set_flip(client, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS); mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
mt9m111_set_global_gain(client, mt9m111->gain); mt9m111_set_autowhitebalance(mt9m111, mt9m111->autowhitebalance);
mt9m111_set_autoexposure(client, mt9m111->autoexposure);
mt9m111_set_autowhitebalance(client, mt9m111->autowhitebalance);
return 0;
} }
static int mt9m111_resume(struct soc_camera_device *icd) static int mt9m111_resume(struct soc_camera_device *icd)
...@@ -933,28 +930,28 @@ static int mt9m111_resume(struct soc_camera_device *icd) ...@@ -933,28 +930,28 @@ static int mt9m111_resume(struct soc_camera_device *icd)
int ret = 0; int ret = 0;
if (mt9m111->powered) { if (mt9m111->powered) {
ret = mt9m111_enable(client); ret = mt9m111_enable(mt9m111);
if (!ret) if (!ret)
ret = mt9m111_reset(client); ret = mt9m111_reset(mt9m111);
if (!ret) if (!ret)
ret = mt9m111_restore_state(client); mt9m111_restore_state(mt9m111);
} }
return ret; return ret;
} }
static int mt9m111_init(struct i2c_client *client) static int mt9m111_init(struct mt9m111 *mt9m111)
{ {
struct mt9m111 *mt9m111 = to_mt9m111(client); struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
int ret; int ret;
mt9m111->context = HIGHPOWER; mt9m111->context = HIGHPOWER;
ret = mt9m111_enable(client); ret = mt9m111_enable(mt9m111);
if (!ret) if (!ret)
ret = mt9m111_reset(client); ret = mt9m111_reset(mt9m111);
if (!ret) if (!ret)
ret = mt9m111_set_context(client, mt9m111->context); ret = mt9m111_set_context(mt9m111, mt9m111->context);
if (!ret) if (!ret)
ret = mt9m111_set_autoexposure(client, mt9m111->autoexposure); ret = mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
if (ret) if (ret)
dev_err(&client->dev, "mt9m111 init failed: %d\n", ret); dev_err(&client->dev, "mt9m111 init failed: %d\n", ret);
return ret; return ret;
...@@ -1005,7 +1002,7 @@ static int mt9m111_video_probe(struct soc_camera_device *icd, ...@@ -1005,7 +1002,7 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
goto ei2c; goto ei2c;
} }
ret = mt9m111_init(client); ret = mt9m111_init(mt9m111);
ei2c: ei2c:
return ret; return ret;
......
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