Re: [PATCH 03/10] ov772x: Select the default format at probe time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 6 Jul 2012, Laurent Pinchart wrote:

> 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@xxxxxxxxxxxxxxxx>
> ---
>  drivers/media/video/ov772x.c |   63 ++++++++++++++++++++---------------------
>  1 files changed, 31 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
> index 066bac6..576780a 100644
> --- a/drivers/media/video/ov772x.c
> +++ b/drivers/media/video/ov772x.c
> @@ -547,37 +547,36 @@ static const struct ov772x_color_format ov772x_cfmts[] = {
>  #define MAX_WIDTH   VGA_WIDTH
>  #define MAX_HEIGHT  VGA_HEIGHT
>  
> -static const struct ov772x_win_size ov772x_win_vga = {
> -	.name     = "VGA",
> -	.width    = VGA_WIDTH,
> -	.height   = VGA_HEIGHT,
> -	.com7_bit = SLCT_VGA,
> -	.regs     = ov772x_vga_regs,
> -};
> -
> -static const struct ov772x_win_size ov772x_win_qvga = {
> -	.name     = "QVGA",
> -	.width    = QVGA_WIDTH,
> -	.height   = QVGA_HEIGHT,
> -	.com7_bit = SLCT_QVGA,
> -	.regs     = ov772x_qvga_regs,
> +static const struct ov772x_win_size ov772x_win_sizes[] = {
> +	{
> +		.name     = "VGA",
> +		.width    = VGA_WIDTH,
> +		.height   = VGA_HEIGHT,
> +		.com7_bit = SLCT_VGA,
> +		.regs     = ov772x_vga_regs,
> +	}, {
> +		.name     = "QVGA",
> +		.width    = QVGA_WIDTH,
> +		.height   = QVGA_HEIGHT,
> +		.com7_bit = SLCT_QVGA,
> +		.regs     = ov772x_qvga_regs,
> +	},
>  };
>  
>  static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
>  {
> -	__u32 diff;
> -	const struct ov772x_win_size *win;
> -
> -	/* default is QVGA */
> -	diff = abs(width - ov772x_win_qvga.width) +
> -		abs(height - ov772x_win_qvga.height);
> -	win = &ov772x_win_qvga;
> -
> -	/* VGA */
> -	if (diff >
> -	    abs(width  - ov772x_win_vga.width) +
> -	    abs(height - ov772x_win_vga.height))
> -		win = &ov772x_win_vga;
> +	const struct ov772x_win_size *win = &ov772x_win_sizes[0];
> +	unsigned int i;
> +	u32 best_diff = (u32)-1;

Not a reason enough for a new version, if you don't mind and ig I don't 
forget, I might

#include <linux/kernel.h>
+	u32 best_diff = UINT_MAX;

> +
> +	for (i = 0; i < ARRAY_SIZE(ov772x_win_sizes); ++i) {
> +		u32 diff = abs(width - ov772x_win_sizes[i].width)
> +			 + abs(height - ov772x_win_sizes[i].height);
> +		if (diff < best_diff) {
> +			best_diff = diff;
> +			win = &ov772x_win_sizes[i];
> +		}
> +	}
>  
>  	return win;
>  }

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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux