linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] media: ov5645: Fix write_reg return code
@ 2018-02-08  9:41 Todor Tomov
  2018-02-08  9:42 ` [PATCH 2/2] media: ov5645: Improve mode finding function Todor Tomov
  2018-03-06 13:40 ` [PATCH 1/2] media: ov5645: Fix write_reg return code Mauro Carvalho Chehab
  0 siblings, 2 replies; 5+ messages in thread
From: Todor Tomov @ 2018-02-08  9:41 UTC (permalink / raw)
  To: mchehab, sakari.ailus, hverkuil; +Cc: linux-media, linux-kernel, Todor Tomov

I2C transfer functions return number of successful operations (on success).

Do not return the received positive return code but instead return 0 on
success. The users of write_reg function already use this logic.

Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
---
 drivers/media/i2c/ov5645.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index d28845f..9755562 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -600,11 +600,13 @@ static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
 	regbuf[2] = val;
 
 	ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
 			__func__, ret, reg, val);
+		return ret;
+	}
 
-	return ret;
+	return 0;
 }
 
 static int ov5645_read_reg(struct ov5645 *ov5645, u16 reg, u8 *val)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] media: ov5645: Improve mode finding function
  2018-02-08  9:41 [PATCH 1/2] media: ov5645: Fix write_reg return code Todor Tomov
@ 2018-02-08  9:42 ` Todor Tomov
  2018-03-06 13:58   ` Sakari Ailus
  2018-03-06 13:40 ` [PATCH 1/2] media: ov5645: Fix write_reg return code Mauro Carvalho Chehab
  1 sibling, 1 reply; 5+ messages in thread
From: Todor Tomov @ 2018-02-08  9:42 UTC (permalink / raw)
  To: mchehab, sakari.ailus, hverkuil; +Cc: linux-media, linux-kernel, Todor Tomov

Find the sensor mode by comparing the size of the requested image size
and the sensor mode's image size. The distance between image sizes is the
size in pixels of the non-overlapping regions between the requested size
and the frame-specified size. This logic is borrowed from et8ek8 sensor
driver.

Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
---
 drivers/media/i2c/ov5645.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
index 9755562..6d06c50 100644
--- a/drivers/media/i2c/ov5645.c
+++ b/drivers/media/i2c/ov5645.c
@@ -964,18 +964,24 @@ __ov5645_get_pad_crop(struct ov5645 *ov5645, struct v4l2_subdev_pad_config *cfg,
 static const struct ov5645_mode_info *
 ov5645_find_nearest_mode(unsigned int width, unsigned int height)
 {
-	int i;
+	unsigned int max_dist_match = (unsigned int) -1;
+	int i, n = 0;
 
-	for (i = ARRAY_SIZE(ov5645_mode_info_data) - 1; i >= 0; i--) {
-		if (ov5645_mode_info_data[i].width <= width &&
-		    ov5645_mode_info_data[i].height <= height)
-			break;
+	for (i = 0; i < ARRAY_SIZE(ov5645_mode_info_data); i++) {
+		unsigned int dist = min(width, ov5645_mode_info_data[i].width)
+				* min(height, ov5645_mode_info_data[i].height);
+
+		dist = ov5645_mode_info_data[i].width *
+				ov5645_mode_info_data[i].height
+		     + width * height - 2 * dist;
+
+		if (dist < max_dist_match) {
+			n = i;
+			max_dist_match = dist;
+		}
 	}
 
-	if (i < 0)
-		i = 0;
-
-	return &ov5645_mode_info_data[i];
+	return &ov5645_mode_info_data[n];
 }
 
 static int ov5645_set_format(struct v4l2_subdev *sd,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] media: ov5645: Fix write_reg return code
  2018-02-08  9:41 [PATCH 1/2] media: ov5645: Fix write_reg return code Todor Tomov
  2018-02-08  9:42 ` [PATCH 2/2] media: ov5645: Improve mode finding function Todor Tomov
@ 2018-03-06 13:40 ` Mauro Carvalho Chehab
  2018-03-06 13:56   ` Sakari Ailus
  1 sibling, 1 reply; 5+ messages in thread
From: Mauro Carvalho Chehab @ 2018-03-06 13:40 UTC (permalink / raw)
  To: Todor Tomov; +Cc: sakari.ailus, hverkuil, linux-media, linux-kernel

Em Thu,  8 Feb 2018 11:41:59 +0200
Todor Tomov <todor.tomov@linaro.org> escreveu:

> I2C transfer functions return number of successful operations (on success).
> 
> Do not return the received positive return code but instead return 0 on
> success. The users of write_reg function already use this logic.
> 
> Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> ---
>  drivers/media/i2c/ov5645.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index d28845f..9755562 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -600,11 +600,13 @@ static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
>  	regbuf[2] = val;
>  
>  	ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
>  			__func__, ret, reg, val);
> +		return ret;
> +	}

Actually, if ret < 3, it should return an error too (like -EREMOTEIO 
or -EIO).

>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int ov5645_read_reg(struct ov5645 *ov5645, u16 reg, u8 *val)



Thanks,
Mauro

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] media: ov5645: Fix write_reg return code
  2018-03-06 13:40 ` [PATCH 1/2] media: ov5645: Fix write_reg return code Mauro Carvalho Chehab
@ 2018-03-06 13:56   ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2018-03-06 13:56 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Todor Tomov, hverkuil, linux-media, linux-kernel

HI Mauro,

On Tue, Mar 06, 2018 at 10:40:10AM -0300, Mauro Carvalho Chehab wrote:
> Em Thu,  8 Feb 2018 11:41:59 +0200
> Todor Tomov <todor.tomov@linaro.org> escreveu:
> 
> > I2C transfer functions return number of successful operations (on success).
> > 
> > Do not return the received positive return code but instead return 0 on
> > success. The users of write_reg function already use this logic.
> > 
> > Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> > ---
> >  drivers/media/i2c/ov5645.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> > index d28845f..9755562 100644
> > --- a/drivers/media/i2c/ov5645.c
> > +++ b/drivers/media/i2c/ov5645.c
> > @@ -600,11 +600,13 @@ static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val)
> >  	regbuf[2] = val;
> >  
> >  	ret = i2c_master_send(ov5645->i2c_client, regbuf, 3);
> > -	if (ret < 0)
> > +	if (ret < 0) {
> >  		dev_err(ov5645->dev, "%s: write reg error %d: reg=%x, val=%x\n",
> >  			__func__, ret, reg, val);
> > +		return ret;
> > +	}
> 
> Actually, if ret < 3, it should return an error too (like -EREMOTEIO 
> or -EIO).

i2c_master_send() always returns a negative error code or the number of
octets written.

But thank you for reminding me about the patch. :-)

-- 
Regards,

Sakari Ailus
sakari.ailus@linux.intel.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] media: ov5645: Improve mode finding function
  2018-02-08  9:42 ` [PATCH 2/2] media: ov5645: Improve mode finding function Todor Tomov
@ 2018-03-06 13:58   ` Sakari Ailus
  0 siblings, 0 replies; 5+ messages in thread
From: Sakari Ailus @ 2018-03-06 13:58 UTC (permalink / raw)
  To: Todor Tomov; +Cc: mchehab, hverkuil, linux-media, linux-kernel

Hi Todor,

On Thu, Feb 08, 2018 at 11:42:00AM +0200, Todor Tomov wrote:
> Find the sensor mode by comparing the size of the requested image size
> and the sensor mode's image size. The distance between image sizes is the
> size in pixels of the non-overlapping regions between the requested size
> and the frame-specified size. This logic is borrowed from et8ek8 sensor
> driver.
> 
> Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> ---
>  drivers/media/i2c/ov5645.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c
> index 9755562..6d06c50 100644
> --- a/drivers/media/i2c/ov5645.c
> +++ b/drivers/media/i2c/ov5645.c
> @@ -964,18 +964,24 @@ __ov5645_get_pad_crop(struct ov5645 *ov5645, struct v4l2_subdev_pad_config *cfg,
>  static const struct ov5645_mode_info *
>  ov5645_find_nearest_mode(unsigned int width, unsigned int height)
>  {
> -	int i;
> +	unsigned int max_dist_match = (unsigned int) -1;
> +	int i, n = 0;
>  
> -	for (i = ARRAY_SIZE(ov5645_mode_info_data) - 1; i >= 0; i--) {
> -		if (ov5645_mode_info_data[i].width <= width &&
> -		    ov5645_mode_info_data[i].height <= height)
> -			break;
> +	for (i = 0; i < ARRAY_SIZE(ov5645_mode_info_data); i++) {
> +		unsigned int dist = min(width, ov5645_mode_info_data[i].width)
> +				* min(height, ov5645_mode_info_data[i].height);
> +
> +		dist = ov5645_mode_info_data[i].width *
> +				ov5645_mode_info_data[i].height
> +		     + width * height - 2 * dist;

Could you use v4l2_find_nearest_size()?

The patch is here:

<URL:https://git.linuxtv.org/sailus/media_tree.git/commit/?h=v4l2-common-size&id=83fdb8a0ab43fc86c329f63f1052e6113871a965>

The pull request has been sent on it.

-- 
Sakari Ailus
sakari.ailus@linux.intel.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-06 13:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-08  9:41 [PATCH 1/2] media: ov5645: Fix write_reg return code Todor Tomov
2018-02-08  9:42 ` [PATCH 2/2] media: ov5645: Improve mode finding function Todor Tomov
2018-03-06 13:58   ` Sakari Ailus
2018-03-06 13:40 ` [PATCH 1/2] media: ov5645: Fix write_reg return code Mauro Carvalho Chehab
2018-03-06 13:56   ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).