aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/i2c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-07-18 09:58:19 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-08-15 16:08:36 -0400
commitca9ef7fa21d6cf26e22c9ff1e00a5abeb2106555 (patch)
treefb38fc309452a0a83b2d1b1ab13df36b9139e82c /drivers/media/i2c
parentedff996eb942ce5595e9b60a0e06586dcc41b19b (diff)
[media] ov772x: Select the default format at probe time
The format and window size are only initialized during the first g_fmt call. This leaves the device in an inconsistent state after initialization, which will cause problems when implementing pad operations. Move the format and window size initialization to probe time. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/i2c')
-rw-r--r--drivers/media/i2c/soc_camera/ov772x.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/drivers/media/i2c/soc_camera/ov772x.c b/drivers/media/i2c/soc_camera/ov772x.c
index 0fede50dde4b..3f6e4bf209de 100644
--- a/drivers/media/i2c/soc_camera/ov772x.c
+++ b/drivers/media/i2c/soc_camera/ov772x.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/kernel.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/i2c.h> 21#include <linux/i2c.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
@@ -504,20 +505,20 @@ static const struct ov772x_color_format ov772x_cfmts[] = {
504#define MAX_WIDTH VGA_WIDTH 505#define MAX_WIDTH VGA_WIDTH
505#define MAX_HEIGHT VGA_HEIGHT 506#define MAX_HEIGHT VGA_HEIGHT
506 507
507static const struct ov772x_win_size ov772x_win_vga = { 508static const struct ov772x_win_size ov772x_win_sizes[] = {
508 .name = "VGA", 509 {
509 .width = VGA_WIDTH, 510 .name = "VGA",
510 .height = VGA_HEIGHT, 511 .width = VGA_WIDTH,
511 .com7_bit = SLCT_VGA, 512 .height = VGA_HEIGHT,
512 .regs = ov772x_vga_regs, 513 .com7_bit = SLCT_VGA,
513}; 514 .regs = ov772x_vga_regs,
514 515 }, {
515static const struct ov772x_win_size ov772x_win_qvga = { 516 .name = "QVGA",
516 .name = "QVGA", 517 .width = QVGA_WIDTH,
517 .width = QVGA_WIDTH, 518 .height = QVGA_HEIGHT,
518 .height = QVGA_HEIGHT, 519 .com7_bit = SLCT_QVGA,
519 .com7_bit = SLCT_QVGA, 520 .regs = ov772x_qvga_regs,
520 .regs = ov772x_qvga_regs, 521 },
521}; 522};
522 523
523/* 524/*
@@ -693,19 +694,18 @@ static int ov772x_s_power(struct v4l2_subdev *sd, int on)
693 694
694static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height) 695static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
695{ 696{
696 __u32 diff; 697 const struct ov772x_win_size *win = &ov772x_win_sizes[0];
697 const struct ov772x_win_size *win; 698 u32 best_diff = UINT_MAX;
698 699 unsigned int i;
699 /* default is QVGA */ 700
700 diff = abs(width - ov772x_win_qvga.width) + 701 for (i = 0; i < ARRAY_SIZE(ov772x_win_sizes); ++i) {
701 abs(height - ov772x_win_qvga.height); 702 u32 diff = abs(width - ov772x_win_sizes[i].width)
702 win = &ov772x_win_qvga; 703 + abs(height - ov772x_win_sizes[i].height);
703 704 if (diff < best_diff) {
704 /* VGA */ 705 best_diff = diff;
705 if (diff > 706 win = &ov772x_win_sizes[i];
706 abs(width - ov772x_win_vga.width) + 707 }
707 abs(height - ov772x_win_vga.height)) 708 }
708 win = &ov772x_win_vga;
709 709
710 return win; 710 return win;
711} 711}
@@ -890,11 +890,6 @@ static int ov772x_g_fmt(struct v4l2_subdev *sd,
890{ 890{
891 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev); 891 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
892 892
893 if (!priv->win || !priv->cfmt) {
894 priv->cfmt = &ov772x_cfmts[0];
895 priv->win = ov772x_select_win(VGA_WIDTH, VGA_HEIGHT);
896 }
897
898 mf->width = priv->win->width; 893 mf->width = priv->win->width;
899 mf->height = priv->win->height; 894 mf->height = priv->win->height;
900 mf->code = priv->cfmt->code; 895 mf->code = priv->cfmt->code;
@@ -1103,6 +1098,11 @@ static int ov772x_probe(struct i2c_client *client,
1103 } 1098 }
1104 1099
1105 ret = ov772x_video_probe(client); 1100 ret = ov772x_video_probe(client);
1101 if (ret < 0)
1102 goto done;
1103
1104 priv->cfmt = &ov772x_cfmts[0];
1105 priv->win = &ov772x_win_sizes[0];
1106 1106
1107done: 1107done:
1108 if (ret) { 1108 if (ret) {