All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <hansg@kernel.org>
To: Kieran Bingham <kieran.bingham@ideasonboard.com>,
	Andy Shevchenko <andy@kernel.org>,
	Hans de Goede <hdegoede@redhat.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev
Subject: Re: [PATCH 05/23] media: atomisp: gc0310: Use V4L2_CID_ANALOGUE_GAIN for gain control
Date: Fri, 4 Jul 2025 22:53:52 +0200	[thread overview]
Message-ID: <2bee7047-ce37-4878-bf19-37c323f256cf@kernel.org> (raw)
In-Reply-To: <174751615300.335894.3402272890581119176@ping.linuxembedded.co.uk>

Hi Kieran,

Thank you for the reviews.

On 17-May-25 23:09, Kieran Bingham wrote:
> Quoting Hans de Goede (2025-05-17 12:40:48)
>> Use V4L2_CID_ANALOGUE_GAIN for gain control, as expected by userspace.
>>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>>  drivers/staging/media/atomisp/i2c/atomisp-gc0310.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c
>> index ee039f3be4da..756e56f639b7 100644
>> --- a/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c
>> +++ b/drivers/staging/media/atomisp/i2c/atomisp-gc0310.c
>> @@ -289,7 +289,7 @@ static int gc0310_s_ctrl(struct v4l2_ctrl *ctrl)
>>                 ret = cci_write(sensor->regmap, GC0310_AEC_PK_EXPO_REG,
>>                                 ctrl->val, NULL);
>>                 break;
>> -       case V4L2_CID_GAIN:
>> +       case V4L2_CID_ANALOGUE_GAIN:
>>                 ret = gc0310_gain_set(sensor, ctrl->val);
>>                 break;
>>         default:
>> @@ -533,7 +533,7 @@ static int gc0310_init_controls(struct gc0310_device *sensor)
>>  
>>         /* 32 steps at base gain 1 + 64 half steps at base gain 2 */
> 
> sounds like a curious gain model...
> 
> Will be interesting when we get the sensor calibration tools up and
> running to plot this. (Or is there already a public datasheet
> documenting this?)

There is a datasheet but it does not document much other then
register names.
 
> Is there a split here between analogue gain and digital gain ? Or is it
> all expected to be 'analogue gain' ?

here is the actual method setting the gain:

        /* Taken from original driver, this never sets dgain lower then 32? */

        /* Change 0 - 95 to 32 - 127 */
        gain += 32;

        if (gain < 64) {
                again = 0x0; /* sqrt(2) */
                dgain = gain;
        } else {
                again = 0x2; /* 2 * sqrt(2) */
                dgain = gain / 2;
        }

        cci_write(sensor->regmap, GC0310_AGC_ADJ_REG, again, &ret);
        cci_write(sensor->regmap, GC0310_DGC_ADJ_REG, dgain, &ret);

The 32 half steps come from the dgain = gain / 2 for steps 32 - 95 .

Note the again / dgain names here are confusing. The data sheet describes
the 2 registers which are being written as follows:

AGC:
P0:0x48 ANALOG_COL_gain-col_code 4 bit wide default 0x00 RO [7:4] ANALOG_COL_gain [2:0] col_code

DGC:
P0:0x71 Auto_pregain 8 bit wide default 0x20 RO Auto_pregain

Note DGC is described as read-only in the datasheet, maybe the datesheet is off by one
and we should actually look at register 0x70 in the datasheet:

P0:0x70 Global_gain 8 bit wide default 0x40 RW Global_gain

Either way based on the function calculations I get the feeling that
the first register is actually setting some fixed analog pre-multiplier
and the second register is the actual analog gain.

Despite the names used in the driver (inherited from Android kernels) it
does not feel to me like one of the 2 registers is a digital gain
register.

So I'm going to keep this as is for now and once we've gain calibration
tooling up and running make a plot with the current gain code and then
modify the driver to make this fit one of the standard gain models.

Regards,

Hans



  parent reply	other threads:[~2025-07-04 20:53 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-17 11:40 [PATCH 00/23] media: atomisp: gc0310: Modernize and move to drivers/media Hans de Goede
2025-05-17 11:40 ` [PATCH 01/23] media: atomisp: gc0310: Rename "dev" function variable to "sensor" Hans de Goede
2025-05-17 20:42   ` Kieran Bingham
2025-05-17 11:40 ` [PATCH 02/23] media: atomisp: gc0310: Drop unused GC0310_FOCAL_LENGTH_NUM define Hans de Goede
2025-05-17 20:43   ` Kieran Bingham
2025-05-17 11:40 ` [PATCH 03/23] media: atomisp: gc0310: Modify vblank value to run at 30 fps Hans de Goede
2025-05-17 20:45   ` Kieran Bingham
2025-05-17 11:40 ` [PATCH 04/23] media: atomisp: gc0310: Switch to CCI register access helpers Hans de Goede
2025-05-19 11:09   ` Andy Shevchenko
2025-05-17 11:40 ` [PATCH 05/23] media: atomisp: gc0310: Use V4L2_CID_ANALOGUE_GAIN for gain control Hans de Goede
2025-05-17 21:09   ` Kieran Bingham
2025-05-18  9:42     ` Kieran Bingham
2025-05-21 14:04       ` Laurent Pinchart
2025-07-04 20:53     ` Hans de Goede [this message]
2025-05-17 11:40 ` [PATCH 06/23] media: atomisp: gc0310: Add selection API support Hans de Goede
2025-05-17 20:41   ` Kieran Bingham
2025-07-06  9:52     ` Hans de Goede
2025-05-17 11:40 ` [PATCH 07/23] media: atomisp: gc0310: Add link-frequency and pixelrate controls Hans de Goede
2025-05-19 11:30   ` Andy Shevchenko
2025-07-06  9:57     ` Hans de Goede
2025-07-08  8:04       ` Sakari Ailus
2025-07-08  9:47         ` Hans de Goede
2025-05-17 11:40 ` [PATCH 08/23] media: atomisp: gc0310: Add vblank and hblank controls Hans de Goede
2025-05-19 11:32   ` Andy Shevchenko
2025-05-17 11:40 ` [PATCH 09/23] media: atomisp: gc0310: Add camera orientation and sensor rotation controls Hans de Goede
2025-05-17 11:40 ` [PATCH 10/23] media: atomisp: gc0310: Limit max exposure value to mode-height + vblank Hans de Goede
2025-05-17 11:40 ` [PATCH 11/23] media: atomisp: gc0310: Add check_hwcfg() function Hans de Goede
2025-05-19 11:35   ` Andy Shevchenko
2025-07-06  9:58     ` Hans de Goede
2025-05-17 11:40 ` [PATCH 12/23] media: atomisp: gc0310: Fix power on/off sleep times Hans de Goede
2025-05-19 11:40   ` Andy Shevchenko
2025-05-17 11:40 ` [PATCH 13/23] media: atomisp: gc0310: Remove unused is_streaming variable Hans de Goede
2025-05-17 11:40 ` [PATCH 14/23] media: atomisp: gc0310: Switch to {enable,disable}_streams Hans de Goede
2025-05-19 11:43   ` Andy Shevchenko
2025-07-06 13:45     ` Hans de Goede
2025-05-17 11:40 ` [PATCH 15/23] media: atomisp: gc0310: Switch to using the sub-device state lock Hans de Goede
2025-05-19 11:44   ` Andy Shevchenko
2025-07-06 13:51     ` Hans de Goede
2025-05-17 11:40 ` [PATCH 16/23] media: atomisp: gc0310: Implement internal_ops.init_state Hans de Goede
2025-05-17 11:41 ` [PATCH 17/23] media: atomisp: gc0310: Use v4l2_subdev_get_fmt() as v4l2_subdev_pad_ops.get_fmt() Hans de Goede
2025-05-17 11:41 ` [PATCH 18/23] media: atomisp: gc0310: Switch to using sd.active_state fmt Hans de Goede
2025-05-17 11:41 ` [PATCH 19/23] media: atomisp: gc0310: Move and rename suspend/resume functions Hans de Goede
2025-05-19 11:50   ` Andy Shevchenko
2025-07-06 14:01     ` Hans de Goede
2025-05-17 11:41 ` [PATCH 20/23] media: atomisp: gc0310: runtime-PM fixes Hans de Goede
2025-05-17 11:41 ` [PATCH 21/23] media: atomisp: gc0310: Drop gc0310_get_frame_interval() Hans de Goede
2025-05-18  9:44   ` Kieran Bingham
2025-05-17 11:41 ` [PATCH 22/23] media: atomisp: gc0310: Drop gc0310_g_skip_frames() Hans de Goede
2025-05-17 14:12   ` Kieran Bingham
2025-05-17 11:41 ` [PATCH 23/23] media: Move gc0310 sensor drivers to drivers/media/i2c/ Hans de Goede
2025-05-19 12:19   ` Sakari Ailus
2025-05-19 11:54 ` [PATCH 00/23] media: atomisp: gc0310: Modernize and move to drivers/media Andy Shevchenko
  -- strict thread matches above, loose matches on Subject: below --
2025-05-21 23:09 [PATCH 23/23] media: Move gc0310 sensor drivers to drivers/media/i2c/ kernel test robot
2025-05-23 10:17 ` Dan Carpenter
2025-05-23  7:59 ` Andy Shevchenko
2025-07-06 13:55 ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2bee7047-ce37-4878-bf19-37c323f256cf@kernel.org \
    --to=hansg@kernel.org \
    --cc=andy@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.