linux-stable/drivers/media/i2c
Paul Elder 39111cedd7 media: ov5640: Fix analogue gain control
[ Upstream commit afa4805799 ]

Gain control is badly documented in publicly available (including
leaked) documentation.

There is an AGC pre-gain in register 0x3a13, expressed as a 6-bit value
(plus an enable bit in bit 6). The driver hardcodes it to 0x43, which
one application note states is equal to x1.047. The documentation also
states that 0x40 is equel to x1.000. The pre-gain thus seems to be
expressed as in 1/64 increments, and thus ranges from x1.00 to x1.984.
What the pre-gain does is however unspecified.

There is then an AGC gain limit, in registers 0x3a18 and 0x3a19,
expressed as a 10-bit "real gain format" value. One application note
sets it to 0x00f8 and states it is equal to x15.5, so it appears to be
expressed in 1/16 increments, up to x63.9375.

The manual gain is stored in registers 0x350a and 0x350b, also as a
10-bit "real gain format" value. It is documented in the application
note as a Q6.4 values, up to x63.9375.

One version of the datasheet indicates that the sensor supports a
digital gain:

  The OV5640 supports 1/2/4 digital gain. Normally, the gain is
  controlled automatically by the automatic gain control (AGC) block.

It isn't clear how that would be controlled manually.

There appears to be no indication regarding whether the gain controlled
through registers 0x350a and 0x350b is an analogue gain only or also
includes digital gain. The words "real gain" don't necessarily mean
"combined analogue and digital gains". Some OmniVision sensors (such as
the OV8858) are documented as supoprting different formats for the gain
values, selectable through a register bit, and they are called "real
gain format" and "sensor gain format". For that sensor, we have (one of)
the gain registers documented as

  0x3503[2]=0, gain[7:0] is real gain format, where low 4 bits are
  fraction bits, for example, 0x10 is 1x gain, 0x28 is 2.5x gain

  If 0x3503[2]=1, gain[7:0] is sensor gain format, gain[7:4] is coarse
  gain, 00000: 1x, 00001: 2x, 00011: 4x, 00111: 8x, gain[7] is 1,
  gain[3:0] is fine gain. For example, 0x10 is 1x gain, 0x30 is 2x gain,
  0x70 is 4x gain

(The second part of the text makes little sense)

"Real gain" may thus refer to the combination of the coarse and fine
analogue gains as a single value.

The OV5640 0x350a and 0x350b registers thus appear to control analogue
gain. The driver incorrectly uses V4L2_CID_GAIN as V4L2 has a specific
control for analogue gain, V4L2_CID_ANALOGUE_GAIN. Use it.

If registers 0x350a and 0x350b are later found to control digital gain
as well, the driver could then restrict the range of the analogue gain
control value to lower than x64 and add a separate digital gain control.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Jai Luthra <j-luthra@ti.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-17 08:50:32 +01:00
..
adv748x media: adv748x: afe: Select input port when initializing AFE 2022-12-31 13:32:03 +01:00
ccs i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
cx25840 media updates for v6.1-rc1 2022-10-07 11:04:35 -07:00
et8ek8 i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
m5mols i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
s5c73m3 i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ad5820.c media: i2c: ad5820: Fix error path 2022-12-31 13:32:04 +01:00
ad9389b.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adp1653.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7170.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7175.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7180.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7183.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7183_regs.h
adv7343.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7343_regs.h treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 2) 2022-06-10 14:51:35 +02:00
adv7393.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
adv7393_regs.h treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_30.RULE (part 2) 2022-06-10 14:51:35 +02:00
adv7511-v4l2.c media updates for v6.1-rc1 2022-10-07 11:04:35 -07:00
adv7604.c media updates for v6.1-rc1 2022-10-07 11:04:35 -07:00
adv7842.c media updates for v6.1-rc1 2022-10-07 11:04:35 -07:00
ak881x.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ak7375.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
aptina-pll.c
aptina-pll.h
ar0521.c media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
bt819.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
bt856.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
bt866.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ccs-pll.c Linux 5.11-rc6 2021-02-01 10:03:45 +01:00
ccs-pll.h media: ccs-pll: Switch from standard integer types to kernel ones 2021-01-12 17:55:28 +01:00
cs53l32a.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
cs3308.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
cs5345.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
dw9714.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
dw9768.c dw9768: Enable low-power probe on ACPI 2022-12-31 13:32:05 +01:00
dw9807-vcm.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
hi556.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
hi846.c media: i2c: hi846: Fix memory leak in hi846_parse_dt() 2022-12-31 13:32:04 +01:00
hi847.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx208.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx214.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx219.c media: i2c: imx219: Fix binning for RAW8 capture 2023-03-10 09:33:42 +01:00
imx258.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx274.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx290.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx319.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx334.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx335.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx355.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
imx412.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ir-kbd-i2c.c media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
isl7998x.c media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
Kconfig media: ar0521: fix Kconfig: VIDEO_V4L2 -> VIDEO_DEV 2022-07-15 15:20:16 +01:00
ks0127.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ks0127.h
lm3560.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
lm3646.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
m52790.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
Makefile media: On Semi AR0521 sensor driver 2022-07-08 16:03:20 +01:00
max2175.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
max2175.h
max9271.c media: i2c: max9271: Introduce wake_up() function 2021-06-17 11:30:21 +02:00
max9271.h media: i2c: max9271: Introduce wake_up() function 2021-06-17 11:30:21 +02:00
max9286.c media: max9286: Fix memleak in max9286_v4l2_register() 2023-03-10 09:33:41 +01:00
ml86v7667.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
msp3400-driver.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
msp3400-driver.h
msp3400-kthreads.c
mt9m001.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9m032.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9m111.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9p031.c media: mt9p031: Drop bogus v4l2_subdev_get_try_crop() call from mt9p031_init_cfg() 2022-12-31 13:32:16 +01:00
mt9t001.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9t112.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9v011.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9v032.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
mt9v111.c media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
noon010pc30.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
og01a1b.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov02a10.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov08d10.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov13b10.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov772x.c media: i2c: ov772x: Fix memleak in ov772x_probe() 2023-03-10 09:33:42 +01:00
ov2640.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov2659.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov2680.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov2685.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov2740.c media: ov2740: Fix memleak in ov2740_init_controls() 2023-03-10 09:33:41 +01:00
ov5640.c media: ov5640: Fix analogue gain control 2023-03-17 08:50:32 +01:00
ov5645.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov5647.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov5648.c media: i2c: ov5648: Free V4L2 fwnode data on unbind 2022-12-31 13:32:04 +01:00
ov5670.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov5675.c media: ov5675: Fix memleak in ov5675_init_controls() 2023-03-10 09:33:42 +01:00
ov5693.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov5695.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov6650.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov7251.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov7640.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov7670.c media: i2c: ov7670: 0 instead of -EINVAL was returned 2023-03-10 09:33:44 +01:00
ov7740.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov8856.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov8865.c media fixes for v6.1-rc2 2022-10-22 15:30:15 -07:00
ov9282.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov9640.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov9640.h media: ov9640: Use the generic clock framework 2021-02-06 09:38:05 +01:00
ov9650.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov9734.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ov13858.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
rdacm20.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
rdacm21.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
rj54n1cb0c.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
s5k4ecgx.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
s5k5baf.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
s5k6a3.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
s5k6aa.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa711x_regs.h
saa717x.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa6588.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa6752hs.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa7110.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa7115.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa7127.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
saa7185.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
sony-btf-mpx.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
sr030pc30.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
st-mipid02.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tc358743.c media updates for v6.1-rc1 2022-10-07 11:04:35 -07:00
tc358743_regs.h
tda1997x.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tda1997x_regs.h media: TDA1997x: replace video detection routine 2021-10-19 08:08:38 +01:00
tda7432.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tda9840.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tea6415c.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tea6415c.h
tea6420.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tea6420.h
ths7303.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ths8200.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ths8200_regs.h
tlv320aic23b.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tvaudio.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tvp514x.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tvp514x_regs.h media: media/i2c: fix kerneldoc issues for media i2c headers 2021-03-22 10:23:43 +01:00
tvp5150.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tvp5150_reg.h
tvp7002.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tvp7002_reg.h
tw2804.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tw9903.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tw9906.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
tw9910.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
uda1342.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
upd64031a.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
upd64083.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
video-i2c.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
vp27smpx.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
vpx3220.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
vs6624.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
vs6624_regs.h
wm8739.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
wm8775.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00