Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-24 Thread Hugues FRUCHET
Many thanks for this work Jacopo and Sakari,

On my side I've made some other improvements/fixes on OV5640 that I will 
push in the coming days.

BR,
Hugues.

On 09/17/2018 01:40 PM, Sakari Ailus wrote:
> On Mon, Sep 17, 2018 at 09:47:19AM +0200, jacopo mondi wrote:
>> Hi Sakari,
>>  thanks for handling this
>>
>> On Sun, Sep 16, 2018 at 02:02:30AM +0300, Sakari Ailus wrote:
>>> Hi Jacopo, Hugues,
>>>
>>> On Fri, Sep 14, 2018 at 06:07:12PM +0200, jacopo mondi wrote:
 Hi Sakari,

 On Tue, Sep 11, 2018 at 03:48:16PM +0200, Hugues Fruchet wrote:
> This patch serie fixes some problems around exposure & gain in OV5640 
> driver.

 As you offered to collect this series and my CSI-2 fixes I have just
 re-sent, you might be interested in this branch:

 git://jmondi.org/linux
 engicam-imx6q/media-master/ov5640/csi2_init_v4_exposure_v3

 I have there re-based this series on top of mine, which is in turn
 based on latest media master, where this series do not apply as-is
 afaict.

 I have added to Hugues' patches my reviewed-by and tested-by tags.
 If you prefer to I can send you a pull request, or if you want to have
 a chance to review the whole patch list please refer to the above
 branch.

 Let me know if I can help speeding up the inclusion of these two
 series as they fix two real issues of MIPI CSI-2 capture operations
 for this sensor.
>>>
>>> I've pushed the patches here:
>>>
>>> https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-5>
>>>
>>> There was a merge commit and a few extra patches in your tree; I threw them
>>> out. :-)
>>
>> Yeah, those are a few patches I need for my testing platform... Forgot to
>> remove them, hope you didn't spend too much time on this.
> 
> No, it was rather easy to remove them. I've sent a pull request on these:
> 
> https://patchwork.linuxtv.org/patch/52091/>
> 

Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-17 Thread Sakari Ailus
On Mon, Sep 17, 2018 at 09:47:19AM +0200, jacopo mondi wrote:
> Hi Sakari,
> thanks for handling this
> 
> On Sun, Sep 16, 2018 at 02:02:30AM +0300, Sakari Ailus wrote:
> > Hi Jacopo, Hugues,
> >
> > On Fri, Sep 14, 2018 at 06:07:12PM +0200, jacopo mondi wrote:
> > > Hi Sakari,
> > >
> > > On Tue, Sep 11, 2018 at 03:48:16PM +0200, Hugues Fruchet wrote:
> > > > This patch serie fixes some problems around exposure & gain in OV5640 
> > > > driver.
> > >
> > > As you offered to collect this series and my CSI-2 fixes I have just
> > > re-sent, you might be interested in this branch:
> > >
> > > git://jmondi.org/linux
> > > engicam-imx6q/media-master/ov5640/csi2_init_v4_exposure_v3
> > >
> > > I have there re-based this series on top of mine, which is in turn
> > > based on latest media master, where this series do not apply as-is
> > > afaict.
> > >
> > > I have added to Hugues' patches my reviewed-by and tested-by tags.
> > > If you prefer to I can send you a pull request, or if you want to have
> > > a chance to review the whole patch list please refer to the above
> > > branch.
> > >
> > > Let me know if I can help speeding up the inclusion of these two
> > > series as they fix two real issues of MIPI CSI-2 capture operations
> > > for this sensor.
> >
> > I've pushed the patches here:
> >
> > https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-5>
> >
> > There was a merge commit and a few extra patches in your tree; I threw them
> > out. :-)
> 
> Yeah, those are a few patches I need for my testing platform... Forgot to
> remove them, hope you didn't spend too much time on this.

No, it was rather easy to remove them. I've sent a pull request on these:

https://patchwork.linuxtv.org/patch/52091/>

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi


Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-17 Thread jacopo mondi
Hi Sakari,
thanks for handling this

On Sun, Sep 16, 2018 at 02:02:30AM +0300, Sakari Ailus wrote:
> Hi Jacopo, Hugues,
>
> On Fri, Sep 14, 2018 at 06:07:12PM +0200, jacopo mondi wrote:
> > Hi Sakari,
> >
> > On Tue, Sep 11, 2018 at 03:48:16PM +0200, Hugues Fruchet wrote:
> > > This patch serie fixes some problems around exposure & gain in OV5640 
> > > driver.
> >
> > As you offered to collect this series and my CSI-2 fixes I have just
> > re-sent, you might be interested in this branch:
> >
> > git://jmondi.org/linux
> > engicam-imx6q/media-master/ov5640/csi2_init_v4_exposure_v3
> >
> > I have there re-based this series on top of mine, which is in turn
> > based on latest media master, where this series do not apply as-is
> > afaict.
> >
> > I have added to Hugues' patches my reviewed-by and tested-by tags.
> > If you prefer to I can send you a pull request, or if you want to have
> > a chance to review the whole patch list please refer to the above
> > branch.
> >
> > Let me know if I can help speeding up the inclusion of these two
> > series as they fix two real issues of MIPI CSI-2 capture operations
> > for this sensor.
>
> I've pushed the patches here:
>
> https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-5>
>
> There was a merge commit and a few extra patches in your tree; I threw them
> out. :-)

Yeah, those are a few patches I need for my testing platform... Forgot to
remove them, hope you didn't spend too much time on this.
>
> I also edited the commit messages slightly (format; no change in content)
> --- the patches are as-is. I'll still check they look right before sending
> a pull request, likely on Monday.

Thanks, let me now if I can help.
Cheers
   j

>
> --
> Regards,
>
> Sakari Ailus
> sakari.ai...@linux.intel.com


signature.asc
Description: PGP signature


Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-15 Thread Sakari Ailus
Hi Jacopo, Hugues,

On Fri, Sep 14, 2018 at 06:07:12PM +0200, jacopo mondi wrote:
> Hi Sakari,
> 
> On Tue, Sep 11, 2018 at 03:48:16PM +0200, Hugues Fruchet wrote:
> > This patch serie fixes some problems around exposure & gain in OV5640 
> > driver.
> 
> As you offered to collect this series and my CSI-2 fixes I have just
> re-sent, you might be interested in this branch:
> 
> git://jmondi.org/linux
> engicam-imx6q/media-master/ov5640/csi2_init_v4_exposure_v3
> 
> I have there re-based this series on top of mine, which is in turn
> based on latest media master, where this series do not apply as-is
> afaict.
> 
> I have added to Hugues' patches my reviewed-by and tested-by tags.
> If you prefer to I can send you a pull request, or if you want to have
> a chance to review the whole patch list please refer to the above
> branch.
> 
> Let me know if I can help speeding up the inclusion of these two
> series as they fix two real issues of MIPI CSI-2 capture operations
> for this sensor.

I've pushed the patches here:

https://git.linuxtv.org/sailus/media_tree.git/log/?h=for-4.20-5>

There was a merge commit and a few extra patches in your tree; I threw them
out. :-)

I also edited the commit messages slightly (format; no change in content)
--- the patches are as-is. I'll still check they look right before sending
a pull request, likely on Monday.

-- 
Regards,

Sakari Ailus
sakari.ai...@linux.intel.com


Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-14 Thread Nicolas Dufresne
Interesting, I just hit this problem yesterday. Same module as Steve,  
with MIPI CSI-2 OV5640 (on Sabre Lite).

Tested-By: Nicolas Dufresne 

Le mardi 11 septembre 2018 à 15:48 +0200, Hugues Fruchet a écrit :
> This patch serie fixes some problems around exposure & gain in OV5640
> driver.
> 
> The 4th patch about autocontrols requires also a fix in v4l2-ctrls.c:
> 
https://www.mail-archive.com/linux-media@vger.kernel.org/msg133164.html
> 
> Here is the test procedure used for exposure & gain controls check:
> 1) Preview in background
> $> gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480" !
> queue ! waylandsink -e &
> 2) Check gain & exposure values
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1
> default=0 value=330 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1
> default=0 value=19 flags=inactive, volatile
> 3) Put finger in front of camera and check that gain/exposure values
> are changing:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1
> default=0 value=660 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1
> default=0 value=37 flags=inactive, volatile
> 4) switch to manual mode, image exposition must not change
> $> v4l2-ctl --set-ctrl=gain_automatic=0
> $> v4l2-ctl --set-ctrl=auto_exposure=1
> Note the "1" for manual exposure.
> 
> 5) Check current gain/exposure values:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1
> default=0 value=330
>gain (int): min=0 max=1023 step=1
> default=0 value=20
> 
> 6) Put finger behind camera and check that gain/exposure values are
> NOT changing:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1
> default=0 value=330
>gain (int): min=0 max=1023 step=1
> default=0 value=20
> 7) Update exposure, check that it is well changed on display and that
> same value is returned:
> $> v4l2-ctl --set-ctrl=exposure=100
> $> v4l2-ctl --get-ctrl=exposure
> exposure: 100
> 
> 9) Update gain, check that it is well changed on display and that
> same value is returned:
> $> v4l2-ctl --set-ctrl=gain=10
> $> v4l2-ctl --get-ctrl=gain
> gain: 10
> 
> 10) Switch back to auto gain/exposure, verify that image is correct
> and values returned are correct:
> $> v4l2-ctl --set-ctrl=gain_automatic=1
> $> v4l2-ctl --set-ctrl=auto_exposure=0
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1
> default=0 value=330 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1
> default=0 value=22 flags=inactive, volatile
> Note the "0" for auto exposure.
> 
> ===
> = history =
> ===
> version 3:
>   - Change patch 5/5 by removing set_mode() orig_mode parameter as
> per jacopo' suggestion:
> https://www.spinics.net/lists/linux-media/msg139457.html
> 
> version 2:
>   - Fix patch 3/5 commit comment and rename binning function as per
> jacopo' suggestion:
> 
> https://www.mail-archive.com/linux-media@vger.kernel.org/msg133272.html
> 
> Hugues Fruchet (5):
>   media: ov5640: fix exposure regression
>   media: ov5640: fix auto gain & exposure when changing mode
>   media: ov5640: fix wrong binning value in exposure calculation
>   media: ov5640: fix auto controls values when switching to manual
> mode
>   media: ov5640: fix restore of last mode set
> 
>  drivers/media/i2c/ov5640.c | 128 ++-
> --
>  1 file changed, 73 insertions(+), 55 deletions(-)
> 


signature.asc
Description: This is a digitally signed message part


Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-14 Thread Steve Longerbeam

Hi Hughes,

The whole series,

Acked-by: Steve Longerbeam 

and

Tested-by: Steve Longerbeam 
on i.MX6q SabreSD with MIPI CSI-2 OV5640 module


On 09/11/2018 06:48 AM, Hugues Fruchet wrote:

This patch serie fixes some problems around exposure & gain in OV5640 driver.

The 4th patch about autocontrols requires also a fix in v4l2-ctrls.c:
https://www.mail-archive.com/linux-media@vger.kernel.org/msg133164.html

Here is the test procedure used for exposure & gain controls check:
1) Preview in background
$> gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480" ! queue ! 
waylandsink -e &
2) Check gain & exposure values
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
exposure (int): min=0 max=65535 step=1 default=0 
value=330 flags=inactive, volatile
gain (int): min=0 max=1023 step=1 default=0 
value=19 flags=inactive, volatile
3) Put finger in front of camera and check that gain/exposure values are 
changing:
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
exposure (int): min=0 max=65535 step=1 default=0 
value=660 flags=inactive, volatile
gain (int): min=0 max=1023 step=1 default=0 
value=37 flags=inactive, volatile
4) switch to manual mode, image exposition must not change
$> v4l2-ctl --set-ctrl=gain_automatic=0
$> v4l2-ctl --set-ctrl=auto_exposure=1
Note the "1" for manual exposure.

5) Check current gain/exposure values:
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
exposure (int): min=0 max=65535 step=1 default=0 
value=330
gain (int): min=0 max=1023 step=1 default=0 
value=20

6) Put finger behind camera and check that gain/exposure values are NOT 
changing:
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
exposure (int): min=0 max=65535 step=1 default=0 
value=330
gain (int): min=0 max=1023 step=1 default=0 
value=20
7) Update exposure, check that it is well changed on display and that same 
value is returned:
$> v4l2-ctl --set-ctrl=exposure=100
$> v4l2-ctl --get-ctrl=exposure
exposure: 100

9) Update gain, check that it is well changed on display and that same value is 
returned:
$> v4l2-ctl --set-ctrl=gain=10
$> v4l2-ctl --get-ctrl=gain
gain: 10

10) Switch back to auto gain/exposure, verify that image is correct and values 
returned are correct:
$> v4l2-ctl --set-ctrl=gain_automatic=1
$> v4l2-ctl --set-ctrl=auto_exposure=0
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
exposure (int): min=0 max=65535 step=1 default=0 
value=330 flags=inactive, volatile
gain (int): min=0 max=1023 step=1 default=0 
value=22 flags=inactive, volatile
Note the "0" for auto exposure.

===
= history =
===
version 3:
   - Change patch 5/5 by removing set_mode() orig_mode parameter as per jacopo' 
suggestion:
 https://www.spinics.net/lists/linux-media/msg139457.html

version 2:
   - Fix patch 3/5 commit comment and rename binning function as per jacopo' 
suggestion:
 https://www.mail-archive.com/linux-media@vger.kernel.org/msg133272.html

Hugues Fruchet (5):
   media: ov5640: fix exposure regression
   media: ov5640: fix auto gain & exposure when changing mode
   media: ov5640: fix wrong binning value in exposure calculation
   media: ov5640: fix auto controls values when switching to manual mode
   media: ov5640: fix restore of last mode set

  drivers/media/i2c/ov5640.c | 128 ++---
  1 file changed, 73 insertions(+), 55 deletions(-)





Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-14 Thread jacopo mondi
Hi Sakari,

On Tue, Sep 11, 2018 at 03:48:16PM +0200, Hugues Fruchet wrote:
> This patch serie fixes some problems around exposure & gain in OV5640 driver.

As you offered to collect this series and my CSI-2 fixes I have just
re-sent, you might be interested in this branch:

git://jmondi.org/linux
engicam-imx6q/media-master/ov5640/csi2_init_v4_exposure_v3

I have there re-based this series on top of mine, which is in turn
based on latest media master, where this series do not apply as-is
afaict.

I have added to Hugues' patches my reviewed-by and tested-by tags.
If you prefer to I can send you a pull request, or if you want to have
a chance to review the whole patch list please refer to the above
branch.

Let me know if I can help speeding up the inclusion of these two
series as they fix two real issues of MIPI CSI-2 capture operations
for this sensor.

Thanks
  j

>
> The 4th patch about autocontrols requires also a fix in v4l2-ctrls.c:
> https://www.mail-archive.com/linux-media@vger.kernel.org/msg133164.html
>
> Here is the test procedure used for exposure & gain controls check:
> 1) Preview in background
> $> gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480" ! queue ! 
> waylandsink -e &
> 2) Check gain & exposure values
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1 default=0 
> value=19 flags=inactive, volatile
> 3) Put finger in front of camera and check that gain/exposure values are 
> changing:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=660 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1 default=0 
> value=37 flags=inactive, volatile
> 4) switch to manual mode, image exposition must not change
> $> v4l2-ctl --set-ctrl=gain_automatic=0
> $> v4l2-ctl --set-ctrl=auto_exposure=1
> Note the "1" for manual exposure.
>
> 5) Check current gain/exposure values:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330
>gain (int): min=0 max=1023 step=1 default=0 
> value=20
>
> 6) Put finger behind camera and check that gain/exposure values are NOT 
> changing:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330
>gain (int): min=0 max=1023 step=1 default=0 
> value=20
> 7) Update exposure, check that it is well changed on display and that same 
> value is returned:
> $> v4l2-ctl --set-ctrl=exposure=100
> $> v4l2-ctl --get-ctrl=exposure
> exposure: 100
>
> 9) Update gain, check that it is well changed on display and that same value 
> is returned:
> $> v4l2-ctl --set-ctrl=gain=10
> $> v4l2-ctl --get-ctrl=gain
> gain: 10
>
> 10) Switch back to auto gain/exposure, verify that image is correct and 
> values returned are correct:
> $> v4l2-ctl --set-ctrl=gain_automatic=1
> $> v4l2-ctl --set-ctrl=auto_exposure=0
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1 default=0 
> value=22 flags=inactive, volatile
> Note the "0" for auto exposure.
>
> ===
> = history =
> ===
> version 3:
>   - Change patch 5/5 by removing set_mode() orig_mode parameter as per 
> jacopo' suggestion:
> https://www.spinics.net/lists/linux-media/msg139457.html
>
> version 2:
>   - Fix patch 3/5 commit comment and rename binning function as per jacopo' 
> suggestion:
> https://www.mail-archive.com/linux-media@vger.kernel.org/msg133272.html
>
> Hugues Fruchet (5):
>   media: ov5640: fix exposure regression
>   media: ov5640: fix auto gain & exposure when changing mode
>   media: ov5640: fix wrong binning value in exposure calculation
>   media: ov5640: fix auto controls values when switching to manual mode
>   media: ov5640: fix restore of last mode set
>
>  drivers/media/i2c/ov5640.c | 128 
> ++---
>  1 file changed, 73 insertions(+), 55 deletions(-)
>
> --
> 2.7.4
>


signature.asc
Description: PGP signature


Re: [PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-14 Thread jacopo mondi
Hi  Hugues,
   thanks for the patches

On Tue, Sep 11, 2018 at 03:48:16PM +0200, Hugues Fruchet wrote:
> This patch serie fixes some problems around exposure & gain in OV5640 driver.
>
> The 4th patch about autocontrols requires also a fix in v4l2-ctrls.c:
> https://www.mail-archive.com/linux-media@vger.kernel.org/msg133164.html
>
> Here is the test procedure used for exposure & gain controls check:
> 1) Preview in background
> $> gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480" ! queue ! 
> waylandsink -e &
> 2) Check gain & exposure values
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1 default=0 
> value=19 flags=inactive, volatile
> 3) Put finger in front of camera and check that gain/exposure values are 
> changing:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=660 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1 default=0 
> value=37 flags=inactive, volatile
> 4) switch to manual mode, image exposition must not change
> $> v4l2-ctl --set-ctrl=gain_automatic=0
> $> v4l2-ctl --set-ctrl=auto_exposure=1
> Note the "1" for manual exposure.
>
> 5) Check current gain/exposure values:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330
>gain (int): min=0 max=1023 step=1 default=0 
> value=20
>
> 6) Put finger behind camera and check that gain/exposure values are NOT 
> changing:
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330
>gain (int): min=0 max=1023 step=1 default=0 
> value=20
> 7) Update exposure, check that it is well changed on display and that same 
> value is returned:
> $> v4l2-ctl --set-ctrl=exposure=100
> $> v4l2-ctl --get-ctrl=exposure
> exposure: 100
>
> 9) Update gain, check that it is well changed on display and that same value 
> is returned:
> $> v4l2-ctl --set-ctrl=gain=10
> $> v4l2-ctl --get-ctrl=gain
> gain: 10
>
> 10) Switch back to auto gain/exposure, verify that image is correct and 
> values returned are correct:
> $> v4l2-ctl --set-ctrl=gain_automatic=1
> $> v4l2-ctl --set-ctrl=auto_exposure=0
> $> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
>exposure (int): min=0 max=65535 step=1 default=0 
> value=330 flags=inactive, volatile
>gain (int): min=0 max=1023 step=1 default=0 
> value=22 flags=inactive, volatile
> Note the "0" for auto exposure.
>

I've tested on my side and I can confirm the exposure and gain when in
auto-mode changes as expected, and it is possible to switch back and
forth between auto and manual modes.

The patches also fixes an issue when capturing frames, as the first
two/three frames where always black in my setup before this series.

(While streaming to gstreamers' fakesink)
# v4l2-ctl --get-ctrl "exposure" --get-ctrl "gain" -d /dev/video4
exposure: 885
gain: 50

(Point a light in front of the sensor)
# v4l2-ctl --get-ctrl "exposure" --get-ctrl "gain" -d /dev/video4
exposure: 17
gain: 19

(Disable auto-gain and auto-exposure)
# v4l2-ctl  -d /dev/video4 --set-ctrl=auto_exposure=1
# v4l2-ctl  -d /dev/video4 --set-ctrl=gain_automatic=0
# v4l2-ctl  -d /dev/video4 --set-ctrl=exposure=100
# v4l2-ctl --get-ctrl "exposure" --get-ctrl "gain" -d /dev/video4
exposure: 100
gain: 46

(Re-enable auto-exp and auto-gain)
# v4l2-ctl  -d /dev/video4 --set-ctrl=auto_exposure=0
# v4l2-ctl  -d /dev/video4 --set-ctrl=gain_automatic=1
# v4l2-ctl --get-ctrl "exposure" --get-ctrl "gain" -d /dev/video4
exposure: 885
gain: 46

(Finger on the sensor)
# v4l2-ctl --get-ctrl "exposure" --get-ctrl "gain" -d /dev/video4
exposure: 885
gain: 248

(Point a light on the sensor)
exposure: 16
gain: 19

So please add my
Tested-by: Jacopo Mondi 
to this series.

Thanks
   j

> ===
> = history =
> ===
> version 3:
>   - Change patch 5/5 by removing set_mode() orig_mode parameter as per 
> jacopo' suggestion:
> https://www.spinics.net/lists/linux-media/msg139457.html
>
> version 2:
>   - Fix patch 3/5 commit comment and rename binning function as per jacopo' 
> suggestion:
> https://www.mail-archive.com/linux-media@vger.kernel.org/msg133272.html
>
> Hugues Fruchet (5):
>   media: ov5640: fix exposure regression
>   media: ov5640: fix auto gain & exposure when changing mode
>   media: ov5640: fix wrong binning value in exposure calculation
>   media: ov5640: fix auto controls values when switching to manual mode
>   media: ov5640: fix restore of last mode set
>
>  drivers/media/i2c/ov5640.c | 

[PATCH v3 0/5] Fix OV5640 exposure & gain

2018-09-11 Thread Hugues Fruchet
This patch serie fixes some problems around exposure & gain in OV5640 driver.

The 4th patch about autocontrols requires also a fix in v4l2-ctrls.c:
https://www.mail-archive.com/linux-media@vger.kernel.org/msg133164.html

Here is the test procedure used for exposure & gain controls check:
1) Preview in background
$> gst-launch-1.0 v4l2src ! "video/x-raw, width=640, Height=480" ! queue ! 
waylandsink -e &
2) Check gain & exposure values
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
   exposure (int): min=0 max=65535 step=1 default=0 
value=330 flags=inactive, volatile
   gain (int): min=0 max=1023 step=1 default=0 
value=19 flags=inactive, volatile
3) Put finger in front of camera and check that gain/exposure values are 
changing:
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
   exposure (int): min=0 max=65535 step=1 default=0 
value=660 flags=inactive, volatile
   gain (int): min=0 max=1023 step=1 default=0 
value=37 flags=inactive, volatile
4) switch to manual mode, image exposition must not change
$> v4l2-ctl --set-ctrl=gain_automatic=0
$> v4l2-ctl --set-ctrl=auto_exposure=1
Note the "1" for manual exposure.

5) Check current gain/exposure values:
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
   exposure (int): min=0 max=65535 step=1 default=0 
value=330
   gain (int): min=0 max=1023 step=1 default=0 
value=20

6) Put finger behind camera and check that gain/exposure values are NOT 
changing:
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
   exposure (int): min=0 max=65535 step=1 default=0 
value=330
   gain (int): min=0 max=1023 step=1 default=0 
value=20
7) Update exposure, check that it is well changed on display and that same 
value is returned:
$> v4l2-ctl --set-ctrl=exposure=100
$> v4l2-ctl --get-ctrl=exposure
exposure: 100

9) Update gain, check that it is well changed on display and that same value is 
returned:
$> v4l2-ctl --set-ctrl=gain=10
$> v4l2-ctl --get-ctrl=gain
gain: 10

10) Switch back to auto gain/exposure, verify that image is correct and values 
returned are correct:
$> v4l2-ctl --set-ctrl=gain_automatic=1
$> v4l2-ctl --set-ctrl=auto_exposure=0
$> v4l2-ctl --all | grep -e exposure -e gain | grep "(int)"
   exposure (int): min=0 max=65535 step=1 default=0 
value=330 flags=inactive, volatile
   gain (int): min=0 max=1023 step=1 default=0 
value=22 flags=inactive, volatile
Note the "0" for auto exposure.

===
= history =
===
version 3:
  - Change patch 5/5 by removing set_mode() orig_mode parameter as per jacopo' 
suggestion:
https://www.spinics.net/lists/linux-media/msg139457.html

version 2:
  - Fix patch 3/5 commit comment and rename binning function as per jacopo' 
suggestion:
https://www.mail-archive.com/linux-media@vger.kernel.org/msg133272.html

Hugues Fruchet (5):
  media: ov5640: fix exposure regression
  media: ov5640: fix auto gain & exposure when changing mode
  media: ov5640: fix wrong binning value in exposure calculation
  media: ov5640: fix auto controls values when switching to manual mode
  media: ov5640: fix restore of last mode set

 drivers/media/i2c/ov5640.c | 128 ++---
 1 file changed, 73 insertions(+), 55 deletions(-)

-- 
2.7.4