RE: [PATCH 4/5 v2] [media] ov9740: Remove hardcoded resolution regs
On Tue, 31 May 2011, Andrew Chew wrote: + /* Width must be a multiple of 4 pixels. */ + *width += *width % 4; No, this doesn't make it a multiple of 4, unless it was even;) Just take 5 as an example. What you really want here is Geez, you're right. Not sure what was going on in my head when I did this. Thanks for catching it. + /* + * Try to use as much of the sensor area as possible when supporting + * smaller resolutions. Depending on the aspect ratio of the + * chosen resolution, we can either use the full width of the sensor, + * or the full height of the sensor (or both if the aspect ratio is + * the same as 1280x720. + */ + if ((OV9740_MAX_WIDTH * height) (OV9740_MAX_HEIGHT * width)) { + scale_input_x = (OV9740_MAX_HEIGHT * width) / height; + scale_input_y = OV9740_MAX_HEIGHT; } else { - dev_err(client-dev, Failed to select resolution!\n); - return -EINVAL; + scale_input_x = OV9740_MAX_WIDTH; + scale_input_y = (OV9740_MAX_WIDTH * height) / width; } I don'z know how this sensor works, but the above two divisions round down. And these are input sizes. Cannot it possibly lead to the output window being smaller, than required? Maybe you have to round up (hint: use DIV_ROUND_UP())? The intention is to do some ratio math without floating point instructions, Of course, DIV_ROUND_UP is integer maths only too, as well as (almost) all maths in the kernel. which resulted in some algebraic twiddling (which is why that math looks so weird). No, it doesn't look weird, I just wasn't sure, whether your maths would work in all situations. The only difference between yours and mine, is that yours rounds down, and mine rounds up. So, I'm not sure which one is better in this case. I think what's there is okay. If there's any rounding at all (and there shouldn't be any rounding, if standard image dimensions are called for), then there's going to be some aspect ratio weirdness no matter which way you round that division. No, you should be prepared to handle all possible crazy resolution requests. 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 majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 4/5 v2] [media] ov9740: Remove hardcoded resolution regs
+ /* Width must be a multiple of 4 pixels. */ + *width += *width % 4; No, this doesn't make it a multiple of 4, unless it was even;) Just take 5 as an example. What you really want here is Geez, you're right. Not sure what was going on in my head when I did this. Thanks for catching it. + /* +* Try to use as much of the sensor area as possible when supporting +* smaller resolutions. Depending on the aspect ratio of the +* chosen resolution, we can either use the full width of the sensor, +* or the full height of the sensor (or both if the aspect ratio is +* the same as 1280x720. +*/ + if ((OV9740_MAX_WIDTH * height) (OV9740_MAX_HEIGHT * width)) { + scale_input_x = (OV9740_MAX_HEIGHT * width) / height; + scale_input_y = OV9740_MAX_HEIGHT; } else { - dev_err(client-dev, Failed to select resolution!\n); - return -EINVAL; + scale_input_x = OV9740_MAX_WIDTH; + scale_input_y = (OV9740_MAX_WIDTH * height) / width; } I don'z know how this sensor works, but the above two divisions round down. And these are input sizes. Cannot it possibly lead to the output window being smaller, than required? Maybe you have to round up (hint: use DIV_ROUND_UP())? The intention is to do some ratio math without floating point instructions, which resulted in some algebraic twiddling (which is why that math looks so weird). I think what's there is okay. If there's any rounding at all (and there shouldn't be any rounding, if standard image dimensions are called for), then there's going to be some aspect ratio weirdness no matter which way you round that division.-- To unsubscribe from this list: send the line unsubscribe linux-media in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/5 v2] [media] ov9740: Remove hardcoded resolution regs
Now, this is really the direction I like! Now it's becoming a real driver;) Thanks for doing this! On Wed, 25 May 2011, ac...@nvidia.com wrote: From: Andrew Chew ac...@nvidia.com Derive resolution-dependent register settings programmatically. Signed-off-by: Andrew Chew ac...@nvidia.com --- drivers/media/video/ov9740.c | 210 +++--- 1 files changed, 114 insertions(+), 96 deletions(-) diff --git a/drivers/media/video/ov9740.c b/drivers/media/video/ov9740.c index 9d7c74d..6c28ae8 100644 --- a/drivers/media/video/ov9740.c +++ b/drivers/media/video/ov9740.c @@ -181,27 +181,8 @@ #define OV9740_MIPI_CTRL_30120x3012 #define OV9740_SC_CMMM_MIPI_CTR 0x3014 -/* supported resolutions */ -enum { - OV9740_VGA, - OV9740_720P, -}; - -struct ov9740_resolution { - unsigned int width; - unsigned int height; -}; - -static struct ov9740_resolution ov9740_resolutions[] = { - [OV9740_VGA] = { - .width = 640, - .height = 480, - }, - [OV9740_720P] = { - .width = 1280, - .height = 720, - }, -}; +#define OV9740_MAX_WIDTH 1280 +#define OV9740_MAX_HEIGHT720 /* Misc. structures */ struct ov9740_reg { @@ -403,54 +384,6 @@ static const struct ov9740_reg ov9740_defaults[] = { { OV9740_ISP_CTRL19,0x02 }, }; -static const struct ov9740_reg ov9740_regs_vga[] = { - { OV9740_X_ADDR_START_HI, 0x00 }, - { OV9740_X_ADDR_START_LO, 0xa0 }, - { OV9740_Y_ADDR_START_HI, 0x00 }, - { OV9740_Y_ADDR_START_LO, 0x00 }, - { OV9740_X_ADDR_END_HI, 0x04 }, - { OV9740_X_ADDR_END_LO, 0x63 }, - { OV9740_Y_ADDR_END_HI, 0x02 }, - { OV9740_Y_ADDR_END_LO, 0xd3 }, - { OV9740_X_OUTPUT_SIZE_HI, 0x02 }, - { OV9740_X_OUTPUT_SIZE_LO, 0x80 }, - { OV9740_Y_OUTPUT_SIZE_HI, 0x01 }, - { OV9740_Y_OUTPUT_SIZE_LO, 0xe0 }, - { OV9740_ISP_CTRL1E,0x03 }, - { OV9740_ISP_CTRL1F,0xc0 }, - { OV9740_ISP_CTRL20,0x02 }, - { OV9740_ISP_CTRL21,0xd0 }, - { OV9740_VFIFO_READ_START_HI, 0x01 }, - { OV9740_VFIFO_READ_START_LO, 0x40 }, - { OV9740_ISP_CTRL00,0xff }, - { OV9740_ISP_CTRL01,0xff }, - { OV9740_ISP_CTRL03,0xff }, -}; - -static const struct ov9740_reg ov9740_regs_720p[] = { - { OV9740_X_ADDR_START_HI, 0x00 }, - { OV9740_X_ADDR_START_LO, 0x00 }, - { OV9740_Y_ADDR_START_HI, 0x00 }, - { OV9740_Y_ADDR_START_LO, 0x00 }, - { OV9740_X_ADDR_END_HI, 0x05 }, - { OV9740_X_ADDR_END_LO, 0x03 }, - { OV9740_Y_ADDR_END_HI, 0x02 }, - { OV9740_Y_ADDR_END_LO, 0xd3 }, - { OV9740_X_OUTPUT_SIZE_HI, 0x05 }, - { OV9740_X_OUTPUT_SIZE_LO, 0x00 }, - { OV9740_Y_OUTPUT_SIZE_HI, 0x02 }, - { OV9740_Y_OUTPUT_SIZE_LO, 0xd0 }, - { OV9740_ISP_CTRL1E,0x05 }, - { OV9740_ISP_CTRL1F,0x00 }, - { OV9740_ISP_CTRL20,0x02 }, - { OV9740_ISP_CTRL21,0xd0 }, - { OV9740_VFIFO_READ_START_HI, 0x02 }, - { OV9740_VFIFO_READ_START_LO, 0x30 }, - { OV9740_ISP_CTRL00,0xff }, - { OV9740_ISP_CTRL01,0xef }, - { OV9740_ISP_CTRL03,0xff }, -}; - static enum v4l2_mbus_pixelcode ov9740_codes[] = { V4L2_MBUS_FMT_YUYV8_2X8, }; @@ -727,39 +660,124 @@ static int ov9740_set_register(struct v4l2_subdev *sd, /* select nearest higher resolution for capture */ static void ov9740_res_roundup(u32 *width, u32 *height) { - int i; + /* Width must be a multiple of 4 pixels. */ + *width += *width % 4; No, this doesn't make it a multiple of 4, unless it was even;) Just take 5 as an example. What you really want here is *width = ALIGN(*width, 4); - for (i = 0; i ARRAY_SIZE(ov9740_resolutions); i++) - if ((ov9740_resolutions[i].width = *width) - (ov9740_resolutions[i].height = *height)) { - *width = ov9740_resolutions[i].width; - *height = ov9740_resolutions[i].height; - return; - } + /* Max resolution is 1280x720 (720p). */ + if (*width OV9740_MAX_WIDTH) + *width = OV9740_MAX_WIDTH; - *width = ov9740_resolutions[OV9740_720P].width; - *height = ov9740_resolutions[OV9740_720P].height; + if (*height OV9740_MAX_HEIGHT) + *height = OV9740_MAX_HEIGHT; } /* Setup registers according to resolution and color encoding */ -static int ov9740_set_res(struct i2c_client *client, u32 width) +static int ov9740_set_res(struct i2c_client *client, u32 width, u32 height) { +