aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/mt9m111.c
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>2011-06-07 05:47:30 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-27 16:53:22 -0400
commit2768cbbba3a131e5f483832ff0ff75d97392caa8 (patch)
tree2692a45431b24c0e8d512c8277798b627a220591 /drivers/media/video/mt9m111.c
parentb7ccdba02aaa5100eec85d41c56c37c78d3ab407 (diff)
[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: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Acked-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/mt9m111.c')
-rw-r--r--drivers/media/video/mt9m111.c167
1 files changed, 82 insertions, 85 deletions
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index ebebed929627..0495def412ad 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -251,9 +251,10 @@ static int mt9m111_reg_clear(struct i2c_client *client, const u16 reg,
251 return mt9m111_reg_write(client, reg, ret & ~data); 251 return mt9m111_reg_write(client, reg, ret & ~data);
252} 252}
253 253
254static int mt9m111_set_context(struct i2c_client *client, 254static int mt9m111_set_context(struct mt9m111 *mt9m111,
255 enum mt9m111_context ctxt) 255 enum mt9m111_context ctxt)
256{ 256{
257 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
257 int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B 258 int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B
258 | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B 259 | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B
259 | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B 260 | 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 return reg_write(CONTEXT_CONTROL, valA); 268 return reg_write(CONTEXT_CONTROL, valA);
268} 269}
269 270
270static int mt9m111_setup_rect(struct i2c_client *client, 271static int mt9m111_setup_rect(struct mt9m111 *mt9m111,
271 struct v4l2_rect *rect) 272 struct v4l2_rect *rect)
272{ 273{
273 struct mt9m111 *mt9m111 = to_mt9m111(client); 274 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
274 int ret, is_raw_format; 275 int ret, is_raw_format;
275 int width = rect->width; 276 int width = rect->width;
276 int height = rect->height; 277 int height = rect->height;
@@ -332,48 +333,50 @@ static int mt9m111_setup_pixfmt(struct i2c_client *client, u16 outfmt)
332 return ret; 333 return ret;
333} 334}
334 335
335static int mt9m111_setfmt_bayer8(struct i2c_client *client) 336static int mt9m111_setfmt_bayer8(struct mt9m111 *mt9m111)
336{ 337{
338 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
339
337 return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER | 340 return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_PROCESSED_BAYER |
338 MT9M111_OUTFMT_RGB); 341 MT9M111_OUTFMT_RGB);
339} 342}
340 343
341static int mt9m111_setfmt_bayer10(struct i2c_client *client) 344static int mt9m111_setfmt_bayer10(struct mt9m111 *mt9m111)
342{ 345{
346 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
347
343 return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP); 348 return mt9m111_setup_pixfmt(client, MT9M111_OUTFMT_BYPASS_IFP);
344} 349}
345 350
346static int mt9m111_setfmt_rgb565(struct i2c_client *client) 351static int mt9m111_setfmt_rgb565(struct mt9m111 *mt9m111)
347{ 352{
348 struct mt9m111 *mt9m111 = to_mt9m111(client); 353 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
349 int val = 0; 354 int val = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
350 355
351 if (mt9m111->swap_rgb_red_blue) 356 if (mt9m111->swap_rgb_red_blue)
352 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; 357 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
353 if (mt9m111->swap_rgb_even_odd) 358 if (mt9m111->swap_rgb_even_odd)
354 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; 359 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
355 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
356 360
357 return mt9m111_setup_pixfmt(client, val); 361 return mt9m111_setup_pixfmt(client, val);
358} 362}
359 363
360static int mt9m111_setfmt_rgb555(struct i2c_client *client) 364static int mt9m111_setfmt_rgb555(struct mt9m111 *mt9m111)
361{ 365{
362 struct mt9m111 *mt9m111 = to_mt9m111(client); 366 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
363 int val = 0; 367 int val = MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
364 368
365 if (mt9m111->swap_rgb_red_blue) 369 if (mt9m111->swap_rgb_red_blue)
366 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr; 370 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
367 if (mt9m111->swap_rgb_even_odd) 371 if (mt9m111->swap_rgb_even_odd)
368 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN; 372 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
369 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
370 373
371 return mt9m111_setup_pixfmt(client, val); 374 return mt9m111_setup_pixfmt(client, val);
372} 375}
373 376
374static int mt9m111_setfmt_yuv(struct i2c_client *client) 377static int mt9m111_setfmt_yuv(struct mt9m111 *mt9m111)
375{ 378{
376 struct mt9m111 *mt9m111 = to_mt9m111(client); 379 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
377 int val = 0; 380 int val = 0;
378 381
379 if (mt9m111->swap_yuv_cb_cr) 382 if (mt9m111->swap_yuv_cb_cr)
@@ -384,9 +387,9 @@ static int mt9m111_setfmt_yuv(struct i2c_client *client)
384 return mt9m111_setup_pixfmt(client, val); 387 return mt9m111_setup_pixfmt(client, val);
385} 388}
386 389
387static int mt9m111_enable(struct i2c_client *client) 390static int mt9m111_enable(struct mt9m111 *mt9m111)
388{ 391{
389 struct mt9m111 *mt9m111 = to_mt9m111(client); 392 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
390 int ret; 393 int ret;
391 394
392 ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE); 395 ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE);
@@ -395,8 +398,9 @@ static int mt9m111_enable(struct i2c_client *client)
395 return ret; 398 return ret;
396} 399}
397 400
398static int mt9m111_reset(struct i2c_client *client) 401static int mt9m111_reset(struct mt9m111 *mt9m111)
399{ 402{
403 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
400 int ret; 404 int ret;
401 405
402 ret = reg_set(RESET, MT9M111_RESET_RESET_MODE); 406 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 return 0; 428 return 0;
425} 429}
426 430
427static int mt9m111_make_rect(struct i2c_client *client, 431static int mt9m111_make_rect(struct mt9m111 *mt9m111,
428 struct v4l2_rect *rect) 432 struct v4l2_rect *rect)
429{ 433{
430 struct mt9m111 *mt9m111 = to_mt9m111(client);
431
432 if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 || 434 if (mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR8_1X8 ||
433 mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) { 435 mt9m111->fmt->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE) {
434 /* Bayer format - even size lengths */ 436 /* Bayer format - even size lengths */
@@ -444,14 +446,14 @@ static int mt9m111_make_rect(struct i2c_client *client,
444 soc_camera_limit_side(&rect->top, &rect->height, 446 soc_camera_limit_side(&rect->top, &rect->height,
445 MT9M111_MIN_DARK_ROWS, 2, MT9M111_MAX_HEIGHT); 447 MT9M111_MIN_DARK_ROWS, 2, MT9M111_MAX_HEIGHT);
446 448
447 return mt9m111_setup_rect(client, rect); 449 return mt9m111_setup_rect(mt9m111, rect);
448} 450}
449 451
450static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 452static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
451{ 453{
452 struct v4l2_rect rect = a->c; 454 struct v4l2_rect rect = a->c;
453 struct i2c_client *client = v4l2_get_subdevdata(sd); 455 struct i2c_client *client = v4l2_get_subdevdata(sd);
454 struct mt9m111 *mt9m111 = to_mt9m111(client); 456 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
455 int ret; 457 int ret;
456 458
457 dev_dbg(&client->dev, "%s left=%d, top=%d, width=%d, height=%d\n", 459 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 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 462 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
461 return -EINVAL; 463 return -EINVAL;
462 464
463 ret = mt9m111_make_rect(client, &rect); 465 ret = mt9m111_make_rect(mt9m111, &rect);
464 if (!ret) 466 if (!ret)
465 mt9m111->rect = rect; 467 mt9m111->rect = rect;
466 return ret; 468 return ret;
@@ -468,8 +470,7 @@ static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
468 470
469static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 471static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
470{ 472{
471 struct i2c_client *client = v4l2_get_subdevdata(sd); 473 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
472 struct mt9m111 *mt9m111 = to_mt9m111(client);
473 474
474 a->c = mt9m111->rect; 475 a->c = mt9m111->rect;
475 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 476 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -496,8 +497,7 @@ static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
496static int mt9m111_g_fmt(struct v4l2_subdev *sd, 497static int mt9m111_g_fmt(struct v4l2_subdev *sd,
497 struct v4l2_mbus_framefmt *mf) 498 struct v4l2_mbus_framefmt *mf)
498{ 499{
499 struct i2c_client *client = v4l2_get_subdevdata(sd); 500 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
500 struct mt9m111 *mt9m111 = to_mt9m111(client);
501 501
502 mf->width = mt9m111->rect.width; 502 mf->width = mt9m111->rect.width;
503 mf->height = mt9m111->rect.height; 503 mf->height = mt9m111->rect.height;
@@ -508,46 +508,47 @@ static int mt9m111_g_fmt(struct v4l2_subdev *sd,
508 return 0; 508 return 0;
509} 509}
510 510
511static int mt9m111_set_pixfmt(struct i2c_client *client, 511static int mt9m111_set_pixfmt(struct mt9m111 *mt9m111,
512 enum v4l2_mbus_pixelcode code) 512 enum v4l2_mbus_pixelcode code)
513{ 513{
514 struct mt9m111 *mt9m111 = to_mt9m111(client); 514 struct i2c_client *client;
515 int ret; 515 int ret;
516 516
517 switch (code) { 517 switch (code) {
518 case V4L2_MBUS_FMT_SBGGR8_1X8: 518 case V4L2_MBUS_FMT_SBGGR8_1X8:
519 ret = mt9m111_setfmt_bayer8(client); 519 ret = mt9m111_setfmt_bayer8(mt9m111);
520 break; 520 break;
521 case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE: 521 case V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE:
522 ret = mt9m111_setfmt_bayer10(client); 522 ret = mt9m111_setfmt_bayer10(mt9m111);
523 break; 523 break;
524 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE: 524 case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE:
525 ret = mt9m111_setfmt_rgb555(client); 525 ret = mt9m111_setfmt_rgb555(mt9m111);
526 break; 526 break;
527 case V4L2_MBUS_FMT_RGB565_2X8_LE: 527 case V4L2_MBUS_FMT_RGB565_2X8_LE:
528 ret = mt9m111_setfmt_rgb565(client); 528 ret = mt9m111_setfmt_rgb565(mt9m111);
529 break; 529 break;
530 case V4L2_MBUS_FMT_UYVY8_2X8: 530 case V4L2_MBUS_FMT_UYVY8_2X8:
531 mt9m111->swap_yuv_y_chromas = 0; 531 mt9m111->swap_yuv_y_chromas = 0;
532 mt9m111->swap_yuv_cb_cr = 0; 532 mt9m111->swap_yuv_cb_cr = 0;
533 ret = mt9m111_setfmt_yuv(client); 533 ret = mt9m111_setfmt_yuv(mt9m111);
534 break; 534 break;
535 case V4L2_MBUS_FMT_VYUY8_2X8: 535 case V4L2_MBUS_FMT_VYUY8_2X8:
536 mt9m111->swap_yuv_y_chromas = 0; 536 mt9m111->swap_yuv_y_chromas = 0;
537 mt9m111->swap_yuv_cb_cr = 1; 537 mt9m111->swap_yuv_cb_cr = 1;
538 ret = mt9m111_setfmt_yuv(client); 538 ret = mt9m111_setfmt_yuv(mt9m111);
539 break; 539 break;
540 case V4L2_MBUS_FMT_YUYV8_2X8: 540 case V4L2_MBUS_FMT_YUYV8_2X8:
541 mt9m111->swap_yuv_y_chromas = 1; 541 mt9m111->swap_yuv_y_chromas = 1;
542 mt9m111->swap_yuv_cb_cr = 0; 542 mt9m111->swap_yuv_cb_cr = 0;
543 ret = mt9m111_setfmt_yuv(client); 543 ret = mt9m111_setfmt_yuv(mt9m111);
544 break; 544 break;
545 case V4L2_MBUS_FMT_YVYU8_2X8: 545 case V4L2_MBUS_FMT_YVYU8_2X8:
546 mt9m111->swap_yuv_y_chromas = 1; 546 mt9m111->swap_yuv_y_chromas = 1;
547 mt9m111->swap_yuv_cb_cr = 1; 547 mt9m111->swap_yuv_cb_cr = 1;
548 ret = mt9m111_setfmt_yuv(client); 548 ret = mt9m111_setfmt_yuv(mt9m111);
549 break; 549 break;
550 default: 550 default:
551 client = v4l2_get_subdevdata(&mt9m111->subdev);
551 dev_err(&client->dev, "Pixel format not handled : %x\n", 552 dev_err(&client->dev, "Pixel format not handled : %x\n",
552 code); 553 code);
553 ret = -EINVAL; 554 ret = -EINVAL;
@@ -561,7 +562,7 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
561{ 562{
562 struct i2c_client *client = v4l2_get_subdevdata(sd); 563 struct i2c_client *client = v4l2_get_subdevdata(sd);
563 const struct mt9m111_datafmt *fmt; 564 const struct mt9m111_datafmt *fmt;
564 struct mt9m111 *mt9m111 = to_mt9m111(client); 565 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
565 struct v4l2_rect rect = { 566 struct v4l2_rect rect = {
566 .left = mt9m111->rect.left, 567 .left = mt9m111->rect.left,
567 .top = mt9m111->rect.top, 568 .top = mt9m111->rect.top,
@@ -579,9 +580,9 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
579 "%s code=%x left=%d, top=%d, width=%d, height=%d\n", __func__, 580 "%s code=%x left=%d, top=%d, width=%d, height=%d\n", __func__,
580 mf->code, rect.left, rect.top, rect.width, rect.height); 581 mf->code, rect.left, rect.top, rect.width, rect.height);
581 582
582 ret = mt9m111_make_rect(client, &rect); 583 ret = mt9m111_make_rect(mt9m111, &rect);
583 if (!ret) 584 if (!ret)
584 ret = mt9m111_set_pixfmt(client, mf->code); 585 ret = mt9m111_set_pixfmt(mt9m111, mf->code);
585 if (!ret) { 586 if (!ret) {
586 mt9m111->rect = rect; 587 mt9m111->rect = rect;
587 mt9m111->fmt = fmt; 588 mt9m111->fmt = fmt;
@@ -594,8 +595,7 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
594static int mt9m111_try_fmt(struct v4l2_subdev *sd, 595static int mt9m111_try_fmt(struct v4l2_subdev *sd,
595 struct v4l2_mbus_framefmt *mf) 596 struct v4l2_mbus_framefmt *mf)
596{ 597{
597 struct i2c_client *client = v4l2_get_subdevdata(sd); 598 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
598 struct mt9m111 *mt9m111 = to_mt9m111(client);
599 const struct mt9m111_datafmt *fmt; 599 const struct mt9m111_datafmt *fmt;
600 bool bayer = mf->code == V4L2_MBUS_FMT_SBGGR8_1X8 || 600 bool bayer = mf->code == V4L2_MBUS_FMT_SBGGR8_1X8 ||
601 mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE; 601 mf->code == V4L2_MBUS_FMT_SBGGR10_2X8_PADHI_LE;
@@ -635,7 +635,7 @@ static int mt9m111_g_chip_ident(struct v4l2_subdev *sd,
635 struct v4l2_dbg_chip_ident *id) 635 struct v4l2_dbg_chip_ident *id)
636{ 636{
637 struct i2c_client *client = v4l2_get_subdevdata(sd); 637 struct i2c_client *client = v4l2_get_subdevdata(sd);
638 struct mt9m111 *mt9m111 = to_mt9m111(client); 638 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
639 639
640 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR) 640 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
641 return -EINVAL; 641 return -EINVAL;
@@ -738,9 +738,9 @@ static struct soc_camera_ops mt9m111_ops = {
738 .num_controls = ARRAY_SIZE(mt9m111_controls), 738 .num_controls = ARRAY_SIZE(mt9m111_controls),
739}; 739};
740 740
741static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask) 741static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask)
742{ 742{
743 struct mt9m111 *mt9m111 = to_mt9m111(client); 743 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
744 int ret; 744 int ret;
745 745
746 if (mt9m111->context == HIGHPOWER) { 746 if (mt9m111->context == HIGHPOWER) {
@@ -758,8 +758,9 @@ static int mt9m111_set_flip(struct i2c_client *client, int flip, int mask)
758 return ret; 758 return ret;
759} 759}
760 760
761static int mt9m111_get_global_gain(struct i2c_client *client) 761static int mt9m111_get_global_gain(struct mt9m111 *mt9m111)
762{ 762{
763 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
763 int data; 764 int data;
764 765
765 data = reg_read(GLOBAL_GAIN); 766 data = reg_read(GLOBAL_GAIN);
@@ -769,9 +770,9 @@ static int mt9m111_get_global_gain(struct i2c_client *client)
769 return data; 770 return data;
770} 771}
771 772
772static int mt9m111_set_global_gain(struct i2c_client *client, int gain) 773static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
773{ 774{
774 struct mt9m111 *mt9m111 = to_mt9m111(client); 775 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
775 u16 val; 776 u16 val;
776 777
777 if (gain > 63 * 2 * 2) 778 if (gain > 63 * 2 * 2)
@@ -788,9 +789,9 @@ static int mt9m111_set_global_gain(struct i2c_client *client, int gain)
788 return reg_write(GLOBAL_GAIN, val); 789 return reg_write(GLOBAL_GAIN, val);
789} 790}
790 791
791static int mt9m111_set_autoexposure(struct i2c_client *client, int on) 792static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on)
792{ 793{
793 struct mt9m111 *mt9m111 = to_mt9m111(client); 794 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
794 int ret; 795 int ret;
795 796
796 if (on) 797 if (on)
@@ -804,9 +805,9 @@ static int mt9m111_set_autoexposure(struct i2c_client *client, int on)
804 return ret; 805 return ret;
805} 806}
806 807
807static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on) 808static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on)
808{ 809{
809 struct mt9m111 *mt9m111 = to_mt9m111(client); 810 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
810 int ret; 811 int ret;
811 812
812 if (on) 813 if (on)
@@ -823,7 +824,7 @@ static int mt9m111_set_autowhitebalance(struct i2c_client *client, int on)
823static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 824static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
824{ 825{
825 struct i2c_client *client = v4l2_get_subdevdata(sd); 826 struct i2c_client *client = v4l2_get_subdevdata(sd);
826 struct mt9m111 *mt9m111 = to_mt9m111(client); 827 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
827 int data; 828 int data;
828 829
829 switch (ctrl->id) { 830 switch (ctrl->id) {
@@ -848,7 +849,7 @@ static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
848 ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS); 849 ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
849 break; 850 break;
850 case V4L2_CID_GAIN: 851 case V4L2_CID_GAIN:
851 data = mt9m111_get_global_gain(client); 852 data = mt9m111_get_global_gain(mt9m111);
852 if (data < 0) 853 if (data < 0)
853 return data; 854 return data;
854 ctrl->value = data; 855 ctrl->value = data;
@@ -865,8 +866,7 @@ static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
865 866
866static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 867static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
867{ 868{
868 struct i2c_client *client = v4l2_get_subdevdata(sd); 869 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
869 struct mt9m111 *mt9m111 = to_mt9m111(client);
870 const struct v4l2_queryctrl *qctrl; 870 const struct v4l2_queryctrl *qctrl;
871 int ret; 871 int ret;
872 872
@@ -877,22 +877,22 @@ static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
877 switch (ctrl->id) { 877 switch (ctrl->id) {
878 case V4L2_CID_VFLIP: 878 case V4L2_CID_VFLIP:
879 mt9m111->vflip = ctrl->value; 879 mt9m111->vflip = ctrl->value;
880 ret = mt9m111_set_flip(client, ctrl->value, 880 ret = mt9m111_set_flip(mt9m111, ctrl->value,
881 MT9M111_RMB_MIRROR_ROWS); 881 MT9M111_RMB_MIRROR_ROWS);
882 break; 882 break;
883 case V4L2_CID_HFLIP: 883 case V4L2_CID_HFLIP:
884 mt9m111->hflip = ctrl->value; 884 mt9m111->hflip = ctrl->value;
885 ret = mt9m111_set_flip(client, ctrl->value, 885 ret = mt9m111_set_flip(mt9m111, ctrl->value,
886 MT9M111_RMB_MIRROR_COLS); 886 MT9M111_RMB_MIRROR_COLS);
887 break; 887 break;
888 case V4L2_CID_GAIN: 888 case V4L2_CID_GAIN:
889 ret = mt9m111_set_global_gain(client, ctrl->value); 889 ret = mt9m111_set_global_gain(mt9m111, ctrl->value);
890 break; 890 break;
891 case V4L2_CID_EXPOSURE_AUTO: 891 case V4L2_CID_EXPOSURE_AUTO:
892 ret = mt9m111_set_autoexposure(client, ctrl->value); 892 ret = mt9m111_set_autoexposure(mt9m111, ctrl->value);
893 break; 893 break;
894 case V4L2_CID_AUTO_WHITE_BALANCE: 894 case V4L2_CID_AUTO_WHITE_BALANCE:
895 ret = mt9m111_set_autowhitebalance(client, ctrl->value); 895 ret = mt9m111_set_autowhitebalance(mt9m111, ctrl->value);
896 break; 896 break;
897 default: 897 default:
898 ret = -EINVAL; 898 ret = -EINVAL;
@@ -906,24 +906,21 @@ static int mt9m111_suspend(struct soc_camera_device *icd, pm_message_t state)
906 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 906 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
907 struct mt9m111 *mt9m111 = to_mt9m111(client); 907 struct mt9m111 *mt9m111 = to_mt9m111(client);
908 908
909 mt9m111->gain = mt9m111_get_global_gain(client); 909 mt9m111->gain = mt9m111_get_global_gain(mt9m111);
910 910
911 return 0; 911 return 0;
912} 912}
913 913
914static int mt9m111_restore_state(struct i2c_client *client) 914static void mt9m111_restore_state(struct mt9m111 *mt9m111)
915{ 915{
916 struct mt9m111 *mt9m111 = to_mt9m111(client); 916 mt9m111_set_context(mt9m111, mt9m111->context);
917 917 mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code);
918 mt9m111_set_context(client, mt9m111->context); 918 mt9m111_setup_rect(mt9m111, &mt9m111->rect);
919 mt9m111_set_pixfmt(client, mt9m111->fmt->code); 919 mt9m111_set_flip(mt9m111, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
920 mt9m111_setup_rect(client, &mt9m111->rect); 920 mt9m111_set_flip(mt9m111, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
921 mt9m111_set_flip(client, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); 921 mt9m111_set_global_gain(mt9m111, mt9m111->gain);
922 mt9m111_set_flip(client, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS); 922 mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
923 mt9m111_set_global_gain(client, mt9m111->gain); 923 mt9m111_set_autowhitebalance(mt9m111, mt9m111->autowhitebalance);
924 mt9m111_set_autoexposure(client, mt9m111->autoexposure);
925 mt9m111_set_autowhitebalance(client, mt9m111->autowhitebalance);
926 return 0;
927} 924}
928 925
929static int mt9m111_resume(struct soc_camera_device *icd) 926static int mt9m111_resume(struct soc_camera_device *icd)
@@ -933,28 +930,28 @@ static int mt9m111_resume(struct soc_camera_device *icd)
933 int ret = 0; 930 int ret = 0;
934 931
935 if (mt9m111->powered) { 932 if (mt9m111->powered) {
936 ret = mt9m111_enable(client); 933 ret = mt9m111_enable(mt9m111);
937 if (!ret) 934 if (!ret)
938 ret = mt9m111_reset(client); 935 ret = mt9m111_reset(mt9m111);
939 if (!ret) 936 if (!ret)
940 ret = mt9m111_restore_state(client); 937 mt9m111_restore_state(mt9m111);
941 } 938 }
942 return ret; 939 return ret;
943} 940}
944 941
945static int mt9m111_init(struct i2c_client *client) 942static int mt9m111_init(struct mt9m111 *mt9m111)
946{ 943{
947 struct mt9m111 *mt9m111 = to_mt9m111(client); 944 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
948 int ret; 945 int ret;
949 946
950 mt9m111->context = HIGHPOWER; 947 mt9m111->context = HIGHPOWER;
951 ret = mt9m111_enable(client); 948 ret = mt9m111_enable(mt9m111);
952 if (!ret) 949 if (!ret)
953 ret = mt9m111_reset(client); 950 ret = mt9m111_reset(mt9m111);
954 if (!ret) 951 if (!ret)
955 ret = mt9m111_set_context(client, mt9m111->context); 952 ret = mt9m111_set_context(mt9m111, mt9m111->context);
956 if (!ret) 953 if (!ret)
957 ret = mt9m111_set_autoexposure(client, mt9m111->autoexposure); 954 ret = mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
958 if (ret) 955 if (ret)
959 dev_err(&client->dev, "mt9m111 init failed: %d\n", ret); 956 dev_err(&client->dev, "mt9m111 init failed: %d\n", ret);
960 return ret; 957 return ret;
@@ -1005,7 +1002,7 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
1005 goto ei2c; 1002 goto ei2c;
1006 } 1003 }
1007 1004
1008 ret = mt9m111_init(client); 1005 ret = mt9m111_init(mt9m111);
1009 1006
1010ei2c: 1007ei2c:
1011 return ret; 1008 return ret;