Message ID | 20221027055515.321791-5-nicholas@rothemail.net |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Nicholas, please pardon me for being pedantic, but I would: libcamera: Add support for ov8858 sensor instead of: ipa: libcamera: add metadata for the ov8858 sensor "metadata" is an overloaded already term and usually refers to the properties associated to a captured frame (the term comes from the Android lingo, but we use it too). On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via libcamera-devel wrote: > From: Nicholas Roth <nicholas@rothemail.net> > > Currently, libcamera does not have information for the ov8858 sensor > used in the PinePhone Pro, a phone designed to run Linux. > > This commit adds metadata, especially that sensor gain is reported and > set in 1/16 discrete increments. > > For more information, see "5.8 manual exposure compensation/ manual > gain compensation" in [0]. > > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf The sensor doesn't seem to be supported mainline :( libcamera has a policy that requires supported components to be upstream or at least on their way to upstream (ie posted to the linux-media mailing list). The policy is there because different downstream driver implementations might behave differently one from the other, making it impossible for libcamera to support the part fully. The policy is a strict requirement for ISPs, I guess we're a bit more elastic when it comes to sensor. Howver knowing what driver you are using, where it lives, and if there's any plan to upstream it would be great. Let's start from the first point: where does this driver lives ? What kernel are you using ? Knowing what driver you're using is relevant, in example, as the OV5688 sensor computes exposure in 1/16 of line length. This is not what libcamera expects, and sensor drivers are expected to express the V4L2_CID_EXPOSURE control in line units. From Documentation/sensor_driver_requirements.rst While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera requires it to be expressed as a number of image lines. Camera sensor drivers that do not comply with this requirement will need to be adapted or will produce incorrect results. > > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > --- > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > 2 files changed, 25 insertions(+) > > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp > index 35056bec..f2040cbd 100644 > --- a/src/ipa/libipa/camera_sensor_helper.cpp > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > @@ -476,6 +476,17 @@ public: > }; > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > > +class CameraSensorHelperOv8858 : public CameraSensorHelper > +{ > +public: > + CameraSensorHelperOv8858() > + { > + gainType_ = AnalogueGainLinear; > + gainConstants_.linear = { 1, 0, 0, 16 }; > + } > +}; Nice this matches the CCS defined linear gain model. However the sensor allows to select two formats for the analogue gain the "real gain" format and "sensor gain" format. The selection is made by register 0x3503[2] and it would be nice to validate that the driver uses the format that you expect. > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) Ah! that's a weird name for the sensor entity :) > + > class CameraSensorHelperOv8865 : public CameraSensorHelper > { > public: > diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp > index e5f27f06..d0757c15 100644 > --- a/src/libcamera/camera_sensor_properties.cpp > +++ b/src/libcamera/camera_sensor_properties.cpp > @@ -146,6 +146,20 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen > */ > }, > } }, > + { "m00_f_ov8858", { > + .unitCellSize = { 1200, 1200 }, I read 1.12 um x 1.12 um > + .testPatternModes = { > + { controls::draft::TestPatternModeOff, 0 }, > + { controls::draft::TestPatternModeColorBars, 1 }, > + /* > + * No best corresponding test pattern for: > + * 1: "Vertical Color Bar Type 1", > + * 2: "Vertical Color Bar Type 2", > + * 3: "Vertical Color Bar Type 3", > + * 4: "Vertical Color Bar Type 4" > + */ > + }, > + } }, > { "ov8865", { > .unitCellSize = { 1400, 1400 }, > .testPatternModes = { > -- > 2.34.1 >
> please pardon me for being pedantic, but I would: > libcamera: Add support for ov8858 sensor > > instead of: > ipa: libcamera: add metadata for the ov8858 sensor Happy to make the change. > The sensor doesn't seem to be supported mainline :(... > Let's start from the first point: where does this driver lives ? What > kernel are you using ? I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). It looks like my package manager is picking up the Manjaro kernel from https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no 8858-related changes. This ultimately pulls the driver from https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c . Looks like this has been in and out of Torvalds' peripheral view, e.g.: https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html If you think that it would be valuable to try and mainline this, I'd be interested to do so once I can get libcamera working on my hardware, though I'll likely need some guidance in the process, since I'll be learning a lot. > Nice this matches the CCS defined linear gain model. > However the sensor allows to select two formats for the analogue gain > the "real gain" format and "sensor gain" format. The selection is made by > register 0x3503[2] and it would be nice to validate that the driver > uses the format that you expect. Frankly, I'm not sure what you mean by this, but I'll try to find out from the driver above and verify. > Knowing what driver you're using is relevant, in example, as the > OV5688 sensor computes exposure in 1/16 of line length. This is not > what libcamera expects, and sensor drivers are expected to express the > V4L2_CID_EXPOSURE control in line units. > From Documentation/sensor_driver_requirements.rst > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > requires it to be expressed as a number of image lines. Camera sensor drivers > that do not comply with this requirement will need to be adapted or will produce > incorrect results. Let me read the driver and get back to you. On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > Hi Nicholas, > > please pardon me for being pedantic, but I would: > libcamera: Add support for ov8858 sensor > > instead of: > ipa: libcamera: add metadata for the ov8858 sensor > > "metadata" is an overloaded already term and usually refers to the > properties associated to a captured frame (the term comes from the > Android lingo, but we use it too). > > On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > libcamera-devel wrote: > > From: Nicholas Roth <nicholas@rothemail.net> > > > > Currently, libcamera does not have information for the ov8858 sensor > > used in the PinePhone Pro, a phone designed to run Linux. > > > > This commit adds metadata, especially that sensor gain is reported and > > set in 1/16 discrete increments. > > > > For more information, see "5.8 manual exposure compensation/ manual > > gain compensation" in [0]. > > > > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > The sensor doesn't seem to be supported mainline :( > libcamera has a policy that requires supported components to be > upstream or at least on their way to upstream (ie posted to the > linux-media mailing list). The policy is there because different > downstream driver implementations might behave differently one from > the other, making it impossible for libcamera to support the part > fully. The policy is a strict requirement for ISPs, I guess we're a > bit more elastic when it comes to sensor. Howver knowing what driver > you are using, where it lives, and if there's any plan to upstream it > would be great. > > Let's start from the first point: where does this driver lives ? What > kernel are you using ? > > Knowing what driver you're using is relevant, in example, as the > OV5688 sensor computes exposure in 1/16 of line length. This is not > what libcamera expects, and sensor drivers are expected to express the > V4L2_CID_EXPOSURE control in line units. > > From Documentation/sensor_driver_requirements.rst > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > requires it to be expressed as a number of image lines. Camera sensor > drivers > that do not comply with this requirement will need to be adapted or will > produce > incorrect results. > > > > > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > --- > > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > 2 files changed, 25 insertions(+) > > > > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > b/src/ipa/libipa/camera_sensor_helper.cpp > > index 35056bec..f2040cbd 100644 > > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > @@ -476,6 +476,17 @@ public: > > }; > > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > > > > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > +{ > > +public: > > + CameraSensorHelperOv8858() > > + { > > + gainType_ = AnalogueGainLinear; > > + gainConstants_.linear = { 1, 0, 0, 16 }; > > + } > > +}; > > Nice this matches the CCS defined linear gain model. > However the sensor allows to select two formats for the analogue gain > the "real gain" format and "sensor gain" format. The selection is made by > register 0x3503[2] and it would be nice to validate that the driver > uses the format that you expect. > > > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) > > Ah! that's a weird name for the sensor entity :) > > > + > > class CameraSensorHelperOv8865 : public CameraSensorHelper > > { > > public: > > diff --git a/src/libcamera/camera_sensor_properties.cpp > b/src/libcamera/camera_sensor_properties.cpp > > index e5f27f06..d0757c15 100644 > > --- a/src/libcamera/camera_sensor_properties.cpp > > +++ b/src/libcamera/camera_sensor_properties.cpp > > @@ -146,6 +146,20 @@ const CameraSensorProperties > *CameraSensorProperties::get(const std::string &sen > > */ > > }, > > } }, > > + { "m00_f_ov8858", { > > + .unitCellSize = { 1200, 1200 }, > > I read 1.12 um x 1.12 um > > > + .testPatternModes = { > > + { controls::draft::TestPatternModeOff, 0 }, > > + { > controls::draft::TestPatternModeColorBars, 1 }, > > + /* > > + * No best corresponding test pattern for: > > + * 1: "Vertical Color Bar Type 1", > > + * 2: "Vertical Color Bar Type 2", > > + * 3: "Vertical Color Bar Type 3", > > + * 4: "Vertical Color Bar Type 4" > > + */ > > + }, > > + } }, > > { "ov8865", { > > .unitCellSize = { 1400, 1400 }, > > .testPatternModes = { > > -- > > 2.34.1 > > >
> Nice this matches the CCS defined linear gain model. > However the sensor allows to select two formats for the analogue gain > the "real gain" format and "sensor gain" format. The selection is made by > register 0x3503[2] and it would be nice to validate that the driver > uses the format that you expect. I think I understand this better after reading the driver. In the register value settings, I see: {0x3502, 0x40}, // exposure L {0x3503, 0x80}, // gain delay ?, exposure delay 1 frame, real gain {0x3505, 0x80}, // gain option The 0 low-nibbl indicates we're using "real gain." According to the datasheet: 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 This tells me that we need to divide reported gain from the driver by 16 to get a properly-scaled double-value gain, which these gain constants do. > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > requires it to be expressed as a number of image lines. Camera sensor drivers > that do not comply with this requirement will need to be adapted or will produce > incorrect results. Looks like the driver multiples inputs x16 to convert to 1/16 line length before writing to the register... case V4L2_CID_EXPOSURE: /* 4 least significant bits of expsoure are fractional part */ ret = ov8858_write_reg(ov8858->client, OV8858_REG_EXPOSURE, OV8858_REG_VALUE_24BIT, ctrl->val << 4); Let me know if this looks good, and what needs to happen to merge this! Thanks, -Nicholas On Thu, Oct 27, 2022 at 12:25 PM Nicholas Roth <nicholas@rothemail.net> wrote: > > please pardon me for being pedantic, but I would: > > libcamera: Add support for ov8858 sensor > > > > instead of: > > ipa: libcamera: add metadata for the ov8858 sensor > > Happy to make the change. > > > The sensor doesn't seem to be supported mainline :(... > > Let's start from the first point: where does this driver lives ? What > > kernel are you using ? > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > It looks like my package manager is picking up the Manjaro kernel from > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no > 8858-related changes. This ultimately pulls the driver from > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > . > > Looks like this has been in and out of Torvalds' peripheral view, e.g.: > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html > > If you think that it would be valuable to try and mainline this, I'd be > interested to do so once I can get libcamera working on my hardware, though > I'll likely need some guidance in the process, since I'll be learning a lot. > > > Nice this matches the CCS defined linear gain model. > > However the sensor allows to select two formats for the analogue gain > > the "real gain" format and "sensor gain" format. The selection is made by > > register 0x3503[2] and it would be nice to validate that the driver > > uses the format that you expect. > Frankly, I'm not sure what you mean by this, but I'll try to find out from > the driver above and verify. > > > Knowing what driver you're using is relevant, in example, as the > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > what libcamera expects, and sensor drivers are expected to express the > > V4L2_CID_EXPOSURE control in line units. > > > From Documentation/sensor_driver_requirements.rst > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > requires it to be expressed as a number of image lines. Camera sensor > drivers > > that do not comply with this requirement will need to be adapted or will > produce > > incorrect results. > > Let me read the driver and get back to you. > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > >> Hi Nicholas, >> >> please pardon me for being pedantic, but I would: >> libcamera: Add support for ov8858 sensor >> >> instead of: >> ipa: libcamera: add metadata for the ov8858 sensor >> >> "metadata" is an overloaded already term and usually refers to the >> properties associated to a captured frame (the term comes from the >> Android lingo, but we use it too). >> >> On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via >> libcamera-devel wrote: >> > From: Nicholas Roth <nicholas@rothemail.net> >> > >> > Currently, libcamera does not have information for the ov8858 sensor >> > used in the PinePhone Pro, a phone designed to run Linux. >> > >> > This commit adds metadata, especially that sensor gain is reported and >> > set in 1/16 discrete increments. >> > >> > For more information, see "5.8 manual exposure compensation/ manual >> > gain compensation" in [0]. >> > >> > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf >> >> The sensor doesn't seem to be supported mainline :( >> libcamera has a policy that requires supported components to be >> upstream or at least on their way to upstream (ie posted to the >> linux-media mailing list). The policy is there because different >> downstream driver implementations might behave differently one from >> the other, making it impossible for libcamera to support the part >> fully. The policy is a strict requirement for ISPs, I guess we're a >> bit more elastic when it comes to sensor. Howver knowing what driver >> you are using, where it lives, and if there's any plan to upstream it >> would be great. >> >> Let's start from the first point: where does this driver lives ? What >> kernel are you using ? >> >> Knowing what driver you're using is relevant, in example, as the >> OV5688 sensor computes exposure in 1/16 of line length. This is not >> what libcamera expects, and sensor drivers are expected to express the >> V4L2_CID_EXPOSURE control in line units. >> >> From Documentation/sensor_driver_requirements.rst >> >> While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera >> requires it to be expressed as a number of image lines. Camera sensor >> drivers >> that do not comply with this requirement will need to be adapted or will >> produce >> incorrect results. >> >> > >> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> >> > --- >> > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ >> > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ >> > 2 files changed, 25 insertions(+) >> > >> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp >> b/src/ipa/libipa/camera_sensor_helper.cpp >> > index 35056bec..f2040cbd 100644 >> > --- a/src/ipa/libipa/camera_sensor_helper.cpp >> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp >> > @@ -476,6 +476,17 @@ public: >> > }; >> > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) >> > >> > +class CameraSensorHelperOv8858 : public CameraSensorHelper >> > +{ >> > +public: >> > + CameraSensorHelperOv8858() >> > + { >> > + gainType_ = AnalogueGainLinear; >> > + gainConstants_.linear = { 1, 0, 0, 16 }; >> > + } >> > +}; >> >> Nice this matches the CCS defined linear gain model. >> However the sensor allows to select two formats for the analogue gain >> the "real gain" format and "sensor gain" format. The selection is made by >> register 0x3503[2] and it would be nice to validate that the driver >> uses the format that you expect. >> >> > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) >> >> Ah! that's a weird name for the sensor entity :) >> >> > + >> > class CameraSensorHelperOv8865 : public CameraSensorHelper >> > { >> > public: >> > diff --git a/src/libcamera/camera_sensor_properties.cpp >> b/src/libcamera/camera_sensor_properties.cpp >> > index e5f27f06..d0757c15 100644 >> > --- a/src/libcamera/camera_sensor_properties.cpp >> > +++ b/src/libcamera/camera_sensor_properties.cpp >> > @@ -146,6 +146,20 @@ const CameraSensorProperties >> *CameraSensorProperties::get(const std::string &sen >> > */ >> > }, >> > } }, >> > + { "m00_f_ov8858", { >> > + .unitCellSize = { 1200, 1200 }, >> >> I read 1.12 um x 1.12 um >> >> > + .testPatternModes = { >> > + { controls::draft::TestPatternModeOff, 0 >> }, >> > + { >> controls::draft::TestPatternModeColorBars, 1 }, >> > + /* >> > + * No best corresponding test pattern for: >> > + * 1: "Vertical Color Bar Type 1", >> > + * 2: "Vertical Color Bar Type 2", >> > + * 3: "Vertical Color Bar Type 3", >> > + * 4: "Vertical Color Bar Type 4" >> > + */ >> > + }, >> > + } }, >> > { "ov8865", { >> > .unitCellSize = { 1400, 1400 }, >> > .testPatternModes = { >> > -- >> > 2.34.1 >> > >> >
Hi Nicholas On Thu, Oct 27, 2022 at 12:25:20PM -0500, Nicholas Roth wrote: > > please pardon me for being pedantic, but I would: > > libcamera: Add support for ov8858 sensor > > > > instead of: > > ipa: libcamera: add metadata for the ov8858 sensor > > Happy to make the change. > > > The sensor doesn't seem to be supported mainline :(... > > Let's start from the first point: where does this driver lives ? What > > kernel are you using ? > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > It looks like my package manager is picking up the Manjaro kernel from > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no 8858-related > changes. This ultimately pulls the driver from > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > . Right! So indeed that's downstream stuff, probably from Rockchip's BSP. The driver is not -that- bad, there's a little vendor's code crud here and there but it looks like a decent candidate for upstreaming. I would be happy to help if you're willing to try. I also own a pinephone pro, which so far I haven't had enough time to play with > > Looks like this has been in and out of Torvalds' peripheral view, e.g.: > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html The driver mentioned lives in: drivers/staging/media/atomisp/i2c/ The AtomISP support was upstreamed with its own set of sensor drivers, which were probably not compliant with the mainline V4L2 kAPI and used some vendor defined abstractions. That's why they used to live in staging. However they might serve as reference is something goes wrong, and sometimes they're even copies of regular drivers/media/i2c/ drivers adapted to work with the custom abstractions. AtomISP has also been removed from upstream a few years ago. It's being re-upstreamed in these days by Hans de Goede, hopefully without custom sensor drivers. TL;DR do not consider drivers/staging/media/atomisp/i2c drivers as candidates for upstreaming, even if they might sometime provide references to hw quirks and configurations. > > If you think that it would be valuable to try and mainline this, I'd be > interested to do so once I can get libcamera working on my hardware, though > I'll likely need some guidance in the process, since I'll be learning a lot. Happy to help if you want to give it a go! > > > Nice this matches the CCS defined linear gain model. > > However the sensor allows to select two formats for the analogue gain > > the "real gain" format and "sensor gain" format. The selection is made by > > register 0x3503[2] and it would be nice to validate that the driver > > uses the format that you expect. > Frankly, I'm not sure what you mean by this, but I'll try to find out from > the driver above and verify. > Sorry for having given a few things for granted. CCS is the MIPI Alliance specification for a "Camera Command Set", an attempt to define a standard for image sensors register interfaces. As part of the register interface definition, CCS specifies how sensor drivers expose their configuration parameters including the analogue gain model. The specs are publicly available https://www.mipi.org/specifications/camera-command-set and you'll find in section 9.3 how the Analogue Global Gain control is implemented. When it comes to this specific sensor, the datasheet documents register 0x3503[2] as 0: Input gain as real gain format 1: Input gain as sensor gain format The "real gain" vs "sensor gain" modes are described in the documentation of register 0x3509 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 So what you want here is to have the sensor operate in "real gain" mode, where 0x01 == 1/16 increment in gain > > Knowing what driver you're using is relevant, in example, as the > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > what libcamera expects, and sensor drivers are expected to express the > > V4L2_CID_EXPOSURE control in line units. > > > From Documentation/sensor_driver_requirements.rst > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > requires it to be expressed as a number of image lines. Camera sensor > drivers > > that do not comply with this requirement will need to be adapted or will > produce > > incorrect results. > > Let me read the driver and get back to you. > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > > > Hi Nicholas, > > > > please pardon me for being pedantic, but I would: > > libcamera: Add support for ov8858 sensor > > > > instead of: > > ipa: libcamera: add metadata for the ov8858 sensor > > > > "metadata" is an overloaded already term and usually refers to the > > properties associated to a captured frame (the term comes from the > > Android lingo, but we use it too). > > > > On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > > libcamera-devel wrote: > > > From: Nicholas Roth <nicholas@rothemail.net> > > > > > > Currently, libcamera does not have information for the ov8858 sensor > > > used in the PinePhone Pro, a phone designed to run Linux. > > > > > > This commit adds metadata, especially that sensor gain is reported and > > > set in 1/16 discrete increments. > > > > > > For more information, see "5.8 manual exposure compensation/ manual > > > gain compensation" in [0]. > > > > > > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > > > The sensor doesn't seem to be supported mainline :( > > libcamera has a policy that requires supported components to be > > upstream or at least on their way to upstream (ie posted to the > > linux-media mailing list). The policy is there because different > > downstream driver implementations might behave differently one from > > the other, making it impossible for libcamera to support the part > > fully. The policy is a strict requirement for ISPs, I guess we're a > > bit more elastic when it comes to sensor. Howver knowing what driver > > you are using, where it lives, and if there's any plan to upstream it > > would be great. > > > > Let's start from the first point: where does this driver lives ? What > > kernel are you using ? > > > > Knowing what driver you're using is relevant, in example, as the > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > what libcamera expects, and sensor drivers are expected to express the > > V4L2_CID_EXPOSURE control in line units. > > > > From Documentation/sensor_driver_requirements.rst > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > requires it to be expressed as a number of image lines. Camera sensor > > drivers > > that do not comply with this requirement will need to be adapted or will > > produce > > incorrect results. > > > > > > > > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > > --- > > > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > > 2 files changed, 25 insertions(+) > > > > > > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > > b/src/ipa/libipa/camera_sensor_helper.cpp > > > index 35056bec..f2040cbd 100644 > > > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > > @@ -476,6 +476,17 @@ public: > > > }; > > > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > > > > > > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > > +{ > > > +public: > > > + CameraSensorHelperOv8858() > > > + { > > > + gainType_ = AnalogueGainLinear; > > > + gainConstants_.linear = { 1, 0, 0, 16 }; > > > + } > > > +}; > > > > Nice this matches the CCS defined linear gain model. > > However the sensor allows to select two formats for the analogue gain > > the "real gain" format and "sensor gain" format. The selection is made by > > register 0x3503[2] and it would be nice to validate that the driver > > uses the format that you expect. > > > > > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) > > > > Ah! that's a weird name for the sensor entity :) > > > > > + > > > class CameraSensorHelperOv8865 : public CameraSensorHelper > > > { > > > public: > > > diff --git a/src/libcamera/camera_sensor_properties.cpp > > b/src/libcamera/camera_sensor_properties.cpp > > > index e5f27f06..d0757c15 100644 > > > --- a/src/libcamera/camera_sensor_properties.cpp > > > +++ b/src/libcamera/camera_sensor_properties.cpp > > > @@ -146,6 +146,20 @@ const CameraSensorProperties > > *CameraSensorProperties::get(const std::string &sen > > > */ > > > }, > > > } }, > > > + { "m00_f_ov8858", { > > > + .unitCellSize = { 1200, 1200 }, > > > > I read 1.12 um x 1.12 um > > > > > + .testPatternModes = { > > > + { controls::draft::TestPatternModeOff, 0 }, > > > + { > > controls::draft::TestPatternModeColorBars, 1 }, > > > + /* > > > + * No best corresponding test pattern for: > > > + * 1: "Vertical Color Bar Type 1", > > > + * 2: "Vertical Color Bar Type 2", > > > + * 3: "Vertical Color Bar Type 3", > > > + * 4: "Vertical Color Bar Type 4" > > > + */ > > > + }, > > > + } }, > > > { "ov8865", { > > > .unitCellSize = { 1400, 1400 }, > > > .testPatternModes = { > > > -- > > > 2.34.1 > > > > >
Hi Nicholas, + Laurent question below On Thu, Oct 27, 2022 at 05:21:37PM -0500, Nicholas Roth wrote: > > Nice this matches the CCS defined linear gain model. > > However the sensor allows to select two formats for the analogue gain > > the "real gain" format and "sensor gain" format. The selection is made by > > register 0x3503[2] and it would be nice to validate that the driver > > uses the format that you expect. > > I think I understand this better after reading the driver. In the register > value settings, I see: > {0x3502, 0x40}, // exposure L > {0x3503, 0x80}, // gain delay ?, exposure delay 1 frame, real gain > {0x3505, 0x80}, // gain option > > The 0 low-nibbl indicates we're using "real gain." > > According to the datasheet: > 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 > > This tells me that we need to divide reported gain from the driver by 16 to > get a properly-scaled double-value gain, which these gain constants do. > Here you go! Looking at the driver you're using I indeed see 3503[2]=0 in all modes > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > requires it to be expressed as a number of image lines. Camera sensor > drivers > > that do not comply with this requirement will need to be adapted or will > produce > > incorrect results. > > Looks like the driver multiples inputs x16 to convert to 1/16 line length > before writing to the register... > > case V4L2_CID_EXPOSURE: > /* 4 least significant bits of expsoure are fractional part */ > ret = ov8858_write_reg(ov8858->client, > OV8858_REG_EXPOSURE, > OV8858_REG_VALUE_24BIT, > ctrl->val << 4); > Great, it means that towards userspace the exposure is indeed in units of 1 line. > > Let me know if this looks good, and what needs to happen to merge this! I think I had a comment on the pixel cell size. Apart from that, let me check with Laurent about the policy when it comes to supporting sensor without an upstream driver. I would not be super happy of adding support to "m00_f_ov8858" as if the driver will be upstreamed the entity name should at least change. As a middle term solution we can add support for "m00_f_ov8858" with a todo note to move to a more canonical "ov8858" name once the driver is upstreamed, or at least submitted upstream. Thanks j > > Thanks, > -Nicholas > > On Thu, Oct 27, 2022 at 12:25 PM Nicholas Roth <nicholas@rothemail.net> > wrote: > > > > please pardon me for being pedantic, but I would: > > > libcamera: Add support for ov8858 sensor > > > > > > instead of: > > > ipa: libcamera: add metadata for the ov8858 sensor > > > > Happy to make the change. > > > > > The sensor doesn't seem to be supported mainline :(... > > > Let's start from the first point: where does this driver lives ? What > > > kernel are you using ? > > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > > > It looks like my package manager is picking up the Manjaro kernel from > > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, > > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no > > 8858-related changes. This ultimately pulls the driver from > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > > . > > > > Looks like this has been in and out of Torvalds' peripheral view, e.g.: > > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html > > > > If you think that it would be valuable to try and mainline this, I'd be > > interested to do so once I can get libcamera working on my hardware, though > > I'll likely need some guidance in the process, since I'll be learning a lot. > > > > > Nice this matches the CCS defined linear gain model. > > > However the sensor allows to select two formats for the analogue gain > > > the "real gain" format and "sensor gain" format. The selection is made by > > > register 0x3503[2] and it would be nice to validate that the driver > > > uses the format that you expect. > > Frankly, I'm not sure what you mean by this, but I'll try to find out from > > the driver above and verify. > > > > > Knowing what driver you're using is relevant, in example, as the > > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > > what libcamera expects, and sensor drivers are expected to express the > > > V4L2_CID_EXPOSURE control in line units. > > > > > From Documentation/sensor_driver_requirements.rst > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > > requires it to be expressed as a number of image lines. Camera sensor > > drivers > > > that do not comply with this requirement will need to be adapted or will > > produce > > > incorrect results. > > > > Let me read the driver and get back to you. > > > > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > > > >> Hi Nicholas, > >> > >> please pardon me for being pedantic, but I would: > >> libcamera: Add support for ov8858 sensor > >> > >> instead of: > >> ipa: libcamera: add metadata for the ov8858 sensor > >> > >> "metadata" is an overloaded already term and usually refers to the > >> properties associated to a captured frame (the term comes from the > >> Android lingo, but we use it too). > >> > >> On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > >> libcamera-devel wrote: > >> > From: Nicholas Roth <nicholas@rothemail.net> > >> > > >> > Currently, libcamera does not have information for the ov8858 sensor > >> > used in the PinePhone Pro, a phone designed to run Linux. > >> > > >> > This commit adds metadata, especially that sensor gain is reported and > >> > set in 1/16 discrete increments. > >> > > >> > For more information, see "5.8 manual exposure compensation/ manual > >> > gain compensation" in [0]. > >> > > >> > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > >> > >> The sensor doesn't seem to be supported mainline :( > >> libcamera has a policy that requires supported components to be > >> upstream or at least on their way to upstream (ie posted to the > >> linux-media mailing list). The policy is there because different > >> downstream driver implementations might behave differently one from > >> the other, making it impossible for libcamera to support the part > >> fully. The policy is a strict requirement for ISPs, I guess we're a > >> bit more elastic when it comes to sensor. Howver knowing what driver > >> you are using, where it lives, and if there's any plan to upstream it > >> would be great. > >> > >> Let's start from the first point: where does this driver lives ? What > >> kernel are you using ? > >> > >> Knowing what driver you're using is relevant, in example, as the > >> OV5688 sensor computes exposure in 1/16 of line length. This is not > >> what libcamera expects, and sensor drivers are expected to express the > >> V4L2_CID_EXPOSURE control in line units. > >> > >> From Documentation/sensor_driver_requirements.rst > >> > >> While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > >> requires it to be expressed as a number of image lines. Camera sensor > >> drivers > >> that do not comply with this requirement will need to be adapted or will > >> produce > >> incorrect results. > >> > >> > > >> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > >> > --- > >> > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > >> > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > >> > 2 files changed, 25 insertions(+) > >> > > >> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > >> b/src/ipa/libipa/camera_sensor_helper.cpp > >> > index 35056bec..f2040cbd 100644 > >> > --- a/src/ipa/libipa/camera_sensor_helper.cpp > >> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > >> > @@ -476,6 +476,17 @@ public: > >> > }; > >> > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > >> > > >> > +class CameraSensorHelperOv8858 : public CameraSensorHelper > >> > +{ > >> > +public: > >> > + CameraSensorHelperOv8858() > >> > + { > >> > + gainType_ = AnalogueGainLinear; > >> > + gainConstants_.linear = { 1, 0, 0, 16 }; > >> > + } > >> > +}; > >> > >> Nice this matches the CCS defined linear gain model. > >> However the sensor allows to select two formats for the analogue gain > >> the "real gain" format and "sensor gain" format. The selection is made by > >> register 0x3503[2] and it would be nice to validate that the driver > >> uses the format that you expect. > >> > >> > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) > >> > >> Ah! that's a weird name for the sensor entity :) > >> > >> > + > >> > class CameraSensorHelperOv8865 : public CameraSensorHelper > >> > { > >> > public: > >> > diff --git a/src/libcamera/camera_sensor_properties.cpp > >> b/src/libcamera/camera_sensor_properties.cpp > >> > index e5f27f06..d0757c15 100644 > >> > --- a/src/libcamera/camera_sensor_properties.cpp > >> > +++ b/src/libcamera/camera_sensor_properties.cpp > >> > @@ -146,6 +146,20 @@ const CameraSensorProperties > >> *CameraSensorProperties::get(const std::string &sen > >> > */ > >> > }, > >> > } }, > >> > + { "m00_f_ov8858", { > >> > + .unitCellSize = { 1200, 1200 }, > >> > >> I read 1.12 um x 1.12 um > >> > >> > + .testPatternModes = { > >> > + { controls::draft::TestPatternModeOff, 0 > >> }, > >> > + { > >> controls::draft::TestPatternModeColorBars, 1 }, > >> > + /* > >> > + * No best corresponding test pattern for: > >> > + * 1: "Vertical Color Bar Type 1", > >> > + * 2: "Vertical Color Bar Type 2", > >> > + * 3: "Vertical Color Bar Type 3", > >> > + * 4: "Vertical Color Bar Type 4" > >> > + */ > >> > + }, > >> > + } }, > >> > { "ov8865", { > >> > .unitCellSize = { 1400, 1400 }, > >> > .testPatternModes = { > >> > -- > >> > 2.34.1 > >> > > >> > >
Quoting Nicholas Roth via libcamera-devel (2022-10-27 18:25:20) > > please pardon me for being pedantic, but I would: > > libcamera: Add support for ov8858 sensor > > > > instead of: > > ipa: libcamera: add metadata for the ov8858 sensor > > Happy to make the change. > > > The sensor doesn't seem to be supported mainline :(... > > Let's start from the first point: where does this driver lives ? What > > kernel are you using ? > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > It looks like my package manager is picking up the Manjaro kernel from > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no 8858-related > changes. This ultimately pulls the driver from > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > . > > Looks like this has been in and out of Torvalds' peripheral view, e.g.: > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html That driver is in fact separate and not what you are using. The AtomISP has a separate architecture, and doesn't use the v4l2-subdevice API. > If you think that it would be valuable to try and mainline this, I'd be Absolutely valuable. (In fact, 'almost' a requirement, to have a camera supported in libcamera). > interested to do so once I can get libcamera working on my hardware, though > I'll likely need some guidance in the process, since I'll be learning a lot. Yes, please do - I keep asking for the kernel patches to be posted, but no one has done so. As I understand it, megi isn't interested in getting the the patches upstream. So someone needs to take ownership of them (ideally with the hardware, so you're an excellent candidate). Happy to help with the process anywhere along the way. The kernel development model is much like libcamera (or rather, libcamera development model is based on the kernel) - so you're already through training. Patches need to be based on an upstream kernel, and posted as a series to the linux-media mailing list. There are some nuances which are a pain, but it's best to work through those as they arrise. (like adding different lists for different patches for instance covering the device tree bindings). > > Nice this matches the CCS defined linear gain model. > > However the sensor allows to select two formats for the analogue gain > > the "real gain" format and "sensor gain" format. The selection is made by > > register 0x3503[2] and it would be nice to validate that the driver > > uses the format that you expect. > Frankly, I'm not sure what you mean by this, but I'll try to find out from > the driver above and verify. > > > Knowing what driver you're using is relevant, in example, as the > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > what libcamera expects, and sensor drivers are expected to express the > > V4L2_CID_EXPOSURE control in line units. > > > From Documentation/sensor_driver_requirements.rst > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > requires it to be expressed as a number of image lines. Camera sensor > drivers > > that do not comply with this requirement will need to be adapted or will > produce > > incorrect results. > > Let me read the driver and get back to you. > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > > > Hi Nicholas, > > > > please pardon me for being pedantic, but I would: > > libcamera: Add support for ov8858 sensor > > > > instead of: > > ipa: libcamera: add metadata for the ov8858 sensor > > > > "metadata" is an overloaded already term and usually refers to the > > properties associated to a captured frame (the term comes from the > > Android lingo, but we use it too). > > > > On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > > libcamera-devel wrote: > > > From: Nicholas Roth <nicholas@rothemail.net> > > > > > > Currently, libcamera does not have information for the ov8858 sensor > > > used in the PinePhone Pro, a phone designed to run Linux. > > > > > > This commit adds metadata, especially that sensor gain is reported and > > > set in 1/16 discrete increments. > > > > > > For more information, see "5.8 manual exposure compensation/ manual > > > gain compensation" in [0]. > > > > > > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > > > The sensor doesn't seem to be supported mainline :( > > libcamera has a policy that requires supported components to be > > upstream or at least on their way to upstream (ie posted to the > > linux-media mailing list). The policy is there because different > > downstream driver implementations might behave differently one from > > the other, making it impossible for libcamera to support the part > > fully. The policy is a strict requirement for ISPs, I guess we're a > > bit more elastic when it comes to sensor. Howver knowing what driver > > you are using, where it lives, and if there's any plan to upstream it > > would be great. > > > > Let's start from the first point: where does this driver lives ? What > > kernel are you using ? > > > > Knowing what driver you're using is relevant, in example, as the > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > what libcamera expects, and sensor drivers are expected to express the > > V4L2_CID_EXPOSURE control in line units. > > > > From Documentation/sensor_driver_requirements.rst > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > requires it to be expressed as a number of image lines. Camera sensor > > drivers > > that do not comply with this requirement will need to be adapted or will > > produce > > incorrect results. > > > > > > > > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > > --- > > > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > > 2 files changed, 25 insertions(+) > > > > > > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > > b/src/ipa/libipa/camera_sensor_helper.cpp > > > index 35056bec..f2040cbd 100644 > > > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > > @@ -476,6 +476,17 @@ public: > > > }; > > > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > > > > > > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > > +{ > > > +public: > > > + CameraSensorHelperOv8858() > > > + { > > > + gainType_ = AnalogueGainLinear; > > > + gainConstants_.linear = { 1, 0, 0, 16 }; > > > + } > > > +}; > > > > Nice this matches the CCS defined linear gain model. > > However the sensor allows to select two formats for the analogue gain > > the "real gain" format and "sensor gain" format. The selection is made by > > register 0x3503[2] and it would be nice to validate that the driver > > uses the format that you expect. > > > > > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) > > > > Ah! that's a weird name for the sensor entity :) > > > > > + > > > class CameraSensorHelperOv8865 : public CameraSensorHelper > > > { > > > public: > > > diff --git a/src/libcamera/camera_sensor_properties.cpp > > b/src/libcamera/camera_sensor_properties.cpp > > > index e5f27f06..d0757c15 100644 > > > --- a/src/libcamera/camera_sensor_properties.cpp > > > +++ b/src/libcamera/camera_sensor_properties.cpp > > > @@ -146,6 +146,20 @@ const CameraSensorProperties > > *CameraSensorProperties::get(const std::string &sen > > > */ > > > }, > > > } }, > > > + { "m00_f_ov8858", { > > > + .unitCellSize = { 1200, 1200 }, > > > > I read 1.12 um x 1.12 um > > > > > + .testPatternModes = { > > > + { controls::draft::TestPatternModeOff, 0 }, > > > + { > > controls::draft::TestPatternModeColorBars, 1 }, > > > + /* > > > + * No best corresponding test pattern for: > > > + * 1: "Vertical Color Bar Type 1", > > > + * 2: "Vertical Color Bar Type 2", > > > + * 3: "Vertical Color Bar Type 3", > > > + * 4: "Vertical Color Bar Type 4" > > > + */ > > > + }, > > > + } }, > > > { "ov8865", { > > > .unitCellSize = { 1400, 1400 }, > > > .testPatternModes = { > > > -- > > > 2.34.1 > > > > >
Quoting Jacopo Mondi via libcamera-devel (2022-10-28 09:14:27) > Hi Nicholas, > + Laurent question below > > On Thu, Oct 27, 2022 at 05:21:37PM -0500, Nicholas Roth wrote: > > > Nice this matches the CCS defined linear gain model. > > > However the sensor allows to select two formats for the analogue gain > > > the "real gain" format and "sensor gain" format. The selection is made by > > > register 0x3503[2] and it would be nice to validate that the driver > > > uses the format that you expect. > > > > I think I understand this better after reading the driver. In the register > > value settings, I see: > > {0x3502, 0x40}, // exposure L > > {0x3503, 0x80}, // gain delay ?, exposure delay 1 frame, real gain > > {0x3505, 0x80}, // gain option > > > > The 0 low-nibbl indicates we're using "real gain." > > > > According to the datasheet: > > 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 > > > > This tells me that we need to divide reported gain from the driver by 16 to > > get a properly-scaled double-value gain, which these gain constants do. > > > > Here you go! > > Looking at the driver you're using I indeed see 3503[2]=0 in all modes > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > > requires it to be expressed as a number of image lines. Camera sensor > > drivers > > > that do not comply with this requirement will need to be adapted or will > > produce > > > incorrect results. > > > > Looks like the driver multiples inputs x16 to convert to 1/16 line length > > before writing to the register... > > > > case V4L2_CID_EXPOSURE: > > /* 4 least significant bits of expsoure are fractional part */ > > ret = ov8858_write_reg(ov8858->client, > > OV8858_REG_EXPOSURE, > > OV8858_REG_VALUE_24BIT, > > ctrl->val << 4); > > > > Great, it means that towards userspace the exposure is indeed in units > of 1 line. > > > > > Let me know if this looks good, and what needs to happen to merge this! > > I think I had a comment on the pixel cell size. > > Apart from that, let me check with Laurent about the policy when it > comes to supporting sensor without an upstream driver. > > I would not be super happy of adding support to "m00_f_ov8858" as if the > driver will be upstreamed the entity name should at least change. Yes, this is problematic. Looking at the driver, it comes from: https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c#L2936 This will likely have to be changed to get this merged upstream in the kernel. > As a middle term solution we can add support for "m00_f_ov8858" with a > todo note to move to a more canonical "ov8858" name once the driver is > upstreamed, or at least submitted upstream. This is problematic too - there would be overlap - would we have to duplicate the camera sensor properties? Or perhaps support registering a camera sensor helper as mutliple names? This is the 'why' upstreaming the driver is 'almost' a requirement. Parts like that should be solved before integrating in libcamera ideally. Perhaps we can workaround it this time as it's hopefully manageable - but it means that we would then have libcamera 'supporting' the pinephone in one version, but then losing it's support when we suddenly change the names to match the upstream kernel until the pinephone developers update their kernel. All a bit messy ... :S > > Thanks > j > > > > > Thanks, > > -Nicholas > > > > On Thu, Oct 27, 2022 at 12:25 PM Nicholas Roth <nicholas@rothemail.net> > > wrote: > > > > > > please pardon me for being pedantic, but I would: > > > > libcamera: Add support for ov8858 sensor > > > > > > > > instead of: > > > > ipa: libcamera: add metadata for the ov8858 sensor > > > > > > Happy to make the change. > > > > > > > The sensor doesn't seem to be supported mainline :(... > > > > Let's start from the first point: where does this driver lives ? What > > > > kernel are you using ? > > > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > > > > > It looks like my package manager is picking up the Manjaro kernel from > > > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, > > > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no > > > 8858-related changes. This ultimately pulls the driver from > > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > > > . > > > > > > Looks like this has been in and out of Torvalds' peripheral view, e.g.: > > > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html > > > > > > If you think that it would be valuable to try and mainline this, I'd be > > > interested to do so once I can get libcamera working on my hardware, though > > > I'll likely need some guidance in the process, since I'll be learning a lot. > > > > > > > Nice this matches the CCS defined linear gain model. > > > > However the sensor allows to select two formats for the analogue gain > > > > the "real gain" format and "sensor gain" format. The selection is made by > > > > register 0x3503[2] and it would be nice to validate that the driver > > > > uses the format that you expect. > > > Frankly, I'm not sure what you mean by this, but I'll try to find out from > > > the driver above and verify. > > > > > > > Knowing what driver you're using is relevant, in example, as the > > > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > > > what libcamera expects, and sensor drivers are expected to express the > > > > V4L2_CID_EXPOSURE control in line units. > > > > > > > From Documentation/sensor_driver_requirements.rst > > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > > > requires it to be expressed as a number of image lines. Camera sensor > > > drivers > > > > that do not comply with this requirement will need to be adapted or will > > > produce > > > > incorrect results. > > > > > > Let me read the driver and get back to you. > > > > > > > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > > > > > >> Hi Nicholas, > > >> > > >> please pardon me for being pedantic, but I would: > > >> libcamera: Add support for ov8858 sensor > > >> > > >> instead of: > > >> ipa: libcamera: add metadata for the ov8858 sensor > > >> > > >> "metadata" is an overloaded already term and usually refers to the > > >> properties associated to a captured frame (the term comes from the > > >> Android lingo, but we use it too). > > >> > > >> On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > > >> libcamera-devel wrote: > > >> > From: Nicholas Roth <nicholas@rothemail.net> > > >> > > > >> > Currently, libcamera does not have information for the ov8858 sensor > > >> > used in the PinePhone Pro, a phone designed to run Linux. > > >> > > > >> > This commit adds metadata, especially that sensor gain is reported and > > >> > set in 1/16 discrete increments. > > >> > > > >> > For more information, see "5.8 manual exposure compensation/ manual > > >> > gain compensation" in [0]. > > >> > > > >> > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > >> > > >> The sensor doesn't seem to be supported mainline :( > > >> libcamera has a policy that requires supported components to be > > >> upstream or at least on their way to upstream (ie posted to the > > >> linux-media mailing list). The policy is there because different > > >> downstream driver implementations might behave differently one from > > >> the other, making it impossible for libcamera to support the part > > >> fully. The policy is a strict requirement for ISPs, I guess we're a > > >> bit more elastic when it comes to sensor. Howver knowing what driver > > >> you are using, where it lives, and if there's any plan to upstream it > > >> would be great. > > >> > > >> Let's start from the first point: where does this driver lives ? What > > >> kernel are you using ? > > >> > > >> Knowing what driver you're using is relevant, in example, as the > > >> OV5688 sensor computes exposure in 1/16 of line length. This is not > > >> what libcamera expects, and sensor drivers are expected to express the > > >> V4L2_CID_EXPOSURE control in line units. > > >> > > >> From Documentation/sensor_driver_requirements.rst > > >> > > >> While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > >> requires it to be expressed as a number of image lines. Camera sensor > > >> drivers > > >> that do not comply with this requirement will need to be adapted or will > > >> produce > > >> incorrect results. > > >> > > >> > > > >> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > >> > --- > > >> > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > >> > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > >> > 2 files changed, 25 insertions(+) > > >> > > > >> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > > >> b/src/ipa/libipa/camera_sensor_helper.cpp > > >> > index 35056bec..f2040cbd 100644 > > >> > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > >> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > >> > @@ -476,6 +476,17 @@ public: > > >> > }; > > >> > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > > >> > > > >> > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > >> > +{ > > >> > +public: > > >> > + CameraSensorHelperOv8858() > > >> > + { > > >> > + gainType_ = AnalogueGainLinear; > > >> > + gainConstants_.linear = { 1, 0, 0, 16 }; > > >> > + } > > >> > +}; > > >> > > >> Nice this matches the CCS defined linear gain model. > > >> However the sensor allows to select two formats for the analogue gain > > >> the "real gain" format and "sensor gain" format. The selection is made by > > >> register 0x3503[2] and it would be nice to validate that the driver > > >> uses the format that you expect. > > >> > > >> > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) > > >> > > >> Ah! that's a weird name for the sensor entity :) > > >> > > >> > + > > >> > class CameraSensorHelperOv8865 : public CameraSensorHelper > > >> > { > > >> > public: > > >> > diff --git a/src/libcamera/camera_sensor_properties.cpp > > >> b/src/libcamera/camera_sensor_properties.cpp > > >> > index e5f27f06..d0757c15 100644 > > >> > --- a/src/libcamera/camera_sensor_properties.cpp > > >> > +++ b/src/libcamera/camera_sensor_properties.cpp > > >> > @@ -146,6 +146,20 @@ const CameraSensorProperties > > >> *CameraSensorProperties::get(const std::string &sen > > >> > */ > > >> > }, > > >> > } }, > > >> > + { "m00_f_ov8858", { > > >> > + .unitCellSize = { 1200, 1200 }, > > >> > > >> I read 1.12 um x 1.12 um > > >> > > >> > + .testPatternModes = { > > >> > + { controls::draft::TestPatternModeOff, 0 > > >> }, > > >> > + { > > >> controls::draft::TestPatternModeColorBars, 1 }, > > >> > + /* > > >> > + * No best corresponding test pattern for: > > >> > + * 1: "Vertical Color Bar Type 1", > > >> > + * 2: "Vertical Color Bar Type 2", > > >> > + * 3: "Vertical Color Bar Type 3", > > >> > + * 4: "Vertical Color Bar Type 4" > > >> > + */ > > >> > + }, > > >> > + } }, > > >> > { "ov8865", { > > >> > .unitCellSize = { 1400, 1400 }, > > >> > .testPatternModes = { > > >> > -- > > >> > 2.34.1 > > >> > > > >> > > >
Hello, On Fri, Oct 28, 2022 at 11:25:38AM +0100, Kieran Bingham wrote: > Quoting Jacopo Mondi via libcamera-devel (2022-10-28 09:14:27) > > Hi Nicholas, > > + Laurent question below > > > > On Thu, Oct 27, 2022 at 05:21:37PM -0500, Nicholas Roth wrote: > > > > Nice this matches the CCS defined linear gain model. > > > > However the sensor allows to select two formats for the analogue gain > > > > the "real gain" format and "sensor gain" format. The selection is made by > > > > register 0x3503[2] and it would be nice to validate that the driver > > > > uses the format that you expect. > > > > > > I think I understand this better after reading the driver. In the register > > > value settings, I see: > > > {0x3502, 0x40}, // exposure L > > > {0x3503, 0x80}, // gain delay ?, exposure delay 1 frame, real gain > > > {0x3505, 0x80}, // gain option > > > > > > The 0 low-nibbl indicates we're using "real gain." > > > > > > According to the datasheet: > > > 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 > > > > > > This tells me that we need to divide reported gain from the driver by 16 to > > > get a properly-scaled double-value gain, which these gain constants do. > > > > Here you go! > > > > Looking at the driver you're using I indeed see 3503[2]=0 in all modes > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > > > requires it to be expressed as a number of image lines. Camera sensor drivers > > > > that do not comply with this requirement will need to be adapted or will produce > > > > incorrect results. > > > > > > Looks like the driver multiples inputs x16 to convert to 1/16 line length > > > before writing to the register... > > > > > > case V4L2_CID_EXPOSURE: > > > /* 4 least significant bits of expsoure are fractional part */ > > > ret = ov8858_write_reg(ov8858->client, > > > OV8858_REG_EXPOSURE, > > > OV8858_REG_VALUE_24BIT, > > > ctrl->val << 4); > > > > Great, it means that towards userspace the exposure is indeed in units > > of 1 line. > > > > > Let me know if this looks good, and what needs to happen to merge this! > > > > I think I had a comment on the pixel cell size. > > > > Apart from that, let me check with Laurent about the policy when it > > comes to supporting sensor without an upstream driver. > > > > I would not be super happy of adding support to "m00_f_ov8858" as if the > > driver will be upstreamed the entity name should at least change. > > Yes, this is problematic. > > Looking at the driver, it comes from: > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c#L2936 > > This will likely have to be changed to get this merged upstream in the > kernel. > > > As a middle term solution we can add support for "m00_f_ov8858" with a > > todo note to move to a more canonical "ov8858" name once the driver is > > upstreamed, or at least submitted upstream. > > This is problematic too - there would be overlap - would we have to > duplicate the camera sensor properties? Or perhaps support registering a > camera sensor helper as mutliple names? > > > This is the 'why' upstreaming the driver is 'almost' a requirement. > Parts like that should be solved before integrating in libcamera > ideally. Perhaps we can workaround it this time as it's hopefully > manageable - but it means that we would then have libcamera 'supporting' > the pinephone in one version, but then losing it's support when we > suddenly change the names to match the upstream kernel until the > pinephone developers update their kernel. Agreed. The driver should be upstreamed, and while we don't require drivers to be merged upstream before support for them can be added to libcamera, we do require the drivers to be on their way to upstream. This means showing a reasonable effort to get it there, most likely with a patch posted to the linux-media mailing list. Give that the entity name will need to change when upstreaming, one way forward would be to patch the pinephone kernel driver with the correct entity name already, and use it in libcamera right away. > All a bit messy ... :S > > > > On Thu, Oct 27, 2022 at 12:25 PM Nicholas Roth wrote: > > > > > > > > please pardon me for being pedantic, but I would: > > > > > libcamera: Add support for ov8858 sensor > > > > > > > > > > instead of: > > > > > ipa: libcamera: add metadata for the ov8858 sensor > > > > > > > > Happy to make the change. > > > > > > > > > The sensor doesn't seem to be supported mainline :(... > > > > > Let's start from the first point: where does this driver lives ? What > > > > > kernel are you using ? > > > > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > > > > > > > It looks like my package manager is picking up the Manjaro kernel from > > > > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config, > > > > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no > > > > 8858-related changes. This ultimately pulls the driver from > > > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > > > > . > > > > > > > > Looks like this has been in and out of Torvalds' peripheral view, e.g.: > > > > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html > > > > > > > > If you think that it would be valuable to try and mainline this, I'd be > > > > interested to do so once I can get libcamera working on my hardware, though > > > > I'll likely need some guidance in the process, since I'll be learning a lot. > > > > > > > > > Nice this matches the CCS defined linear gain model. > > > > > However the sensor allows to select two formats for the analogue gain > > > > > the "real gain" format and "sensor gain" format. The selection is made by > > > > > register 0x3503[2] and it would be nice to validate that the driver > > > > > uses the format that you expect. > > > > > > > > Frankly, I'm not sure what you mean by this, but I'll try to find out from > > > > the driver above and verify. > > > > > > > > > Knowing what driver you're using is relevant, in example, as the > > > > > OV5688 sensor computes exposure in 1/16 of line length. This is not > > > > > what libcamera expects, and sensor drivers are expected to express the > > > > > V4L2_CID_EXPOSURE control in line units. > > > > > > > > > From Documentation/sensor_driver_requirements.rst > > > > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > > > > requires it to be expressed as a number of image lines. Camera sensor drivers > > > > > that do not comply with this requirement will need to be adapted or will produce > > > > > incorrect results. > > > > > > > > Let me read the driver and get back to you. > > > > > > > > > > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> wrote: > > > > > > > >> Hi Nicholas, > > > >> > > > >> please pardon me for being pedantic, but I would: > > > >> libcamera: Add support for ov8858 sensor > > > >> > > > >> instead of: > > > >> ipa: libcamera: add metadata for the ov8858 sensor > > > >> > > > >> "metadata" is an overloaded already term and usually refers to the > > > >> properties associated to a captured frame (the term comes from the > > > >> Android lingo, but we use it too). > > > >> > > > >> On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > > > >> libcamera-devel wrote: > > > >> > From: Nicholas Roth <nicholas@rothemail.net> > > > >> > > > > >> > Currently, libcamera does not have information for the ov8858 sensor > > > >> > used in the PinePhone Pro, a phone designed to run Linux. > > > >> > > > > >> > This commit adds metadata, especially that sensor gain is reported and > > > >> > set in 1/16 discrete increments. > > > >> > > > > >> > For more information, see "5.8 manual exposure compensation/ manual > > > >> > gain compensation" in [0]. > > > >> > > > > >> > [0] http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > > >> > > > >> The sensor doesn't seem to be supported mainline :( > > > >> libcamera has a policy that requires supported components to be > > > >> upstream or at least on their way to upstream (ie posted to the > > > >> linux-media mailing list). The policy is there because different > > > >> downstream driver implementations might behave differently one from > > > >> the other, making it impossible for libcamera to support the part > > > >> fully. The policy is a strict requirement for ISPs, I guess we're a > > > >> bit more elastic when it comes to sensor. Howver knowing what driver > > > >> you are using, where it lives, and if there's any plan to upstream it > > > >> would be great. > > > >> > > > >> Let's start from the first point: where does this driver lives ? What > > > >> kernel are you using ? > > > >> > > > >> Knowing what driver you're using is relevant, in example, as the > > > >> OV5688 sensor computes exposure in 1/16 of line length. This is not > > > >> what libcamera expects, and sensor drivers are expected to express the > > > >> V4L2_CID_EXPOSURE control in line units. > > > >> > > > >> From Documentation/sensor_driver_requirements.rst > > > >> > > > >> While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, libcamera > > > >> requires it to be expressed as a number of image lines. Camera sensor drivers > > > >> that do not comply with this requirement will need to be adapted or will produce > > > >> incorrect results. > > > >> > > > >> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > > >> > --- > > > >> > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > > >> > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > > >> > 2 files changed, 25 insertions(+) > > > >> > > > > >> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp > > > >> > index 35056bec..f2040cbd 100644 > > > >> > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > > >> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > > >> > @@ -476,6 +476,17 @@ public: > > > >> > }; > > > >> > REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) > > > >> > > > > >> > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > > >> > +{ > > > >> > +public: > > > >> > + CameraSensorHelperOv8858() > > > >> > + { > > > >> > + gainType_ = AnalogueGainLinear; > > > >> > + gainConstants_.linear = { 1, 0, 0, 16 }; > > > >> > + } > > > >> > +}; > > > >> > > > >> Nice this matches the CCS defined linear gain model. > > > >> However the sensor allows to select two formats for the analogue gain > > > >> the "real gain" format and "sensor gain" format. The selection is made by > > > >> register 0x3503[2] and it would be nice to validate that the driver > > > >> uses the format that you expect. > > > >> > > > >> > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) > > > >> > > > >> Ah! that's a weird name for the sensor entity :) > > > >> > > > >> > + > > > >> > class CameraSensorHelperOv8865 : public CameraSensorHelper > > > >> > { > > > >> > public: > > > >> > diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp > > > >> > index e5f27f06..d0757c15 100644 > > > >> > --- a/src/libcamera/camera_sensor_properties.cpp > > > >> > +++ b/src/libcamera/camera_sensor_properties.cpp > > > >> > @@ -146,6 +146,20 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen > > > >> > */ > > > >> > }, > > > >> > } }, > > > >> > + { "m00_f_ov8858", { > > > >> > + .unitCellSize = { 1200, 1200 }, > > > >> > > > >> I read 1.12 um x 1.12 um > > > >> > > > >> > + .testPatternModes = { > > > >> > + { controls::draft::TestPatternModeOff, 0 }, > > > >> > + { controls::draft::TestPatternModeColorBars, 1 }, > > > >> > + /* > > > >> > + * No best corresponding test pattern for: > > > >> > + * 1: "Vertical Color Bar Type 1", > > > >> > + * 2: "Vertical Color Bar Type 2", > > > >> > + * 3: "Vertical Color Bar Type 3", > > > >> > + * 4: "Vertical Color Bar Type 4" > > > >> > + */ > > > >> > + }, > > > >> > + } }, > > > >> > { "ov8865", { > > > >> > .unitCellSize = { 1400, 1400 }, > > > >> > .testPatternModes = {
> Agreed. The driver should be upstreamed I'm going to send an initial version to linux-media today for comment. I'll include a link to their mailing list with the next set of changes. > Give that the entity name will need to change when upstreaming, one way > forward would be to patch the pinephone kernel driver with the correct > entity name already, and use it in libcamera right away. TL;DR: Media node names do not seem to be standardized and various formats exist. I suggest adding an `else` case to [6] with an additional regex for the ov8858 driver for maximum compatibility with non-mainline ov8858 implementations while we sort out getting this upstreamed. -- Upon reading the driver [0] more closely, it looks like "m00_f_ov8858" is just the *subdevice name *(set to "m{module_index:02d}_{facing}_{OV8858_NAME}" on :2936), not the driver name (set to OV8858_NAME == "ov8858" on :3004) or sensor name (set to OV8858_NAME == "ov8858" on :1778). Reading the kernel docs [3], it looks like this is required to be unique: "Afterwards you need to initialize sd->name with a unique name and set the module owner. This is done for you if you use the i2c helper functions." The subdevice name *defaults* to the driver name in [4] when v4l2_i2c_subdev_init() invokes v4l2_i2c_subdev_set_name(sd, client, NULL, NULL), but this is not guaranteed to be the driver name if I understand correctly. In fact, this appears to solve for the case where there may be multiple ov8858s installed, which the default implementation would not. Though there is some ambiguity in the phrase "unique name," v4l2-subdev.h [5] seems to suggest that these must be unique among device instances, not drivers, since `struct v4l2_subdev` corresponds to a devnode and also specifies "@name: Name of the sub-device. Please notice that the name must be unique." Meanwhile, both Megi's imx258 fork [1] and the mainline imx258 driver [2] use the default implementation, so we do not have this issue using libcamera with an imx258. ***libcamera subdevice name handling (regex guess)*** Currently, libcamera uses a regex to guess the model name from the subdevice name in v4l2_subdevice.cpp V4L2Subdevice::model() [6]. Instead, ***Proposed Solution***: I suggest adding an `else` case to [6] with an additional regex for the ov8858 driver for maximum compatibility with non-mainline ov8858 implementations while we sort out getting this upstreamed. 0: https://github.com/megous/linux/blob/orange-pi-6.0/drivers/media/i2c/ov8858.c 1: https://github.com/megous/linux/blob/orange-pi-6.0/drivers/media/i2c/imx258.c 2: https://github.com/torvalds/linux/blob/master/drivers/media/i2c/imx258.c 3: https://www.kernel.org/doc/html/latest/driver-api/media/v4l2-subdev.html 4: https://github.com/torvalds/linux/blob/master/drivers/media/v4l2-core/v4l2-i2c.c 5: https://github.com/torvalds/linux/blob/master/include/media/v4l2-subdev.h 6: https://github.com/kbingham/libcamera/blob/master/src/libcamera/v4l2_subdevice.cpp On Sun, Oct 30, 2022 at 11:21 AM Laurent Pinchart < laurent.pinchart@ideasonboard.com> wrote: > Hello, > > On Fri, Oct 28, 2022 at 11:25:38AM +0100, Kieran Bingham wrote: > > Quoting Jacopo Mondi via libcamera-devel (2022-10-28 09:14:27) > > > Hi Nicholas, > > > + Laurent question below > > > > > > On Thu, Oct 27, 2022 at 05:21:37PM -0500, Nicholas Roth wrote: > > > > > Nice this matches the CCS defined linear gain model. > > > > > However the sensor allows to select two formats for the analogue > gain > > > > > the "real gain" format and "sensor gain" format. The selection is > made by > > > > > register 0x3503[2] and it would be nice to validate that the driver > > > > > uses the format that you expect. > > > > > > > > I think I understand this better after reading the driver. In the > register > > > > value settings, I see: > > > > {0x3502, 0x40}, // exposure L > > > > {0x3503, 0x80}, // gain delay ?, exposure delay 1 frame, real gain > > > > {0x3505, 0x80}, // gain option > > > > > > > > The 0 low-nibbl indicates we're using "real gain." > > > > > > > > According to the datasheet: > > > > 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 > > > > > > > > This tells me that we need to divide reported gain from the driver > by 16 to > > > > get a properly-scaled double-value gain, which these gain constants > do. > > > > > > Here you go! > > > > > > Looking at the driver you're using I indeed see 3503[2]=0 in all modes > > > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, > libcamera > > > > > requires it to be expressed as a number of image lines. Camera > sensor drivers > > > > > that do not comply with this requirement will need to be adapted > or will produce > > > > > incorrect results. > > > > > > > > Looks like the driver multiples inputs x16 to convert to 1/16 line > length > > > > before writing to the register... > > > > > > > > case V4L2_CID_EXPOSURE: > > > > /* 4 least significant bits of expsoure are fractional part */ > > > > ret = ov8858_write_reg(ov8858->client, > > > > OV8858_REG_EXPOSURE, > > > > OV8858_REG_VALUE_24BIT, > > > > ctrl->val << 4); > > > > > > Great, it means that towards userspace the exposure is indeed in units > > > of 1 line. > > > > > > > Let me know if this looks good, and what needs to happen to merge > this! > > > > > > I think I had a comment on the pixel cell size. > > > > > > Apart from that, let me check with Laurent about the policy when it > > > comes to supporting sensor without an upstream driver. > > > > > > I would not be super happy of adding support to "m00_f_ov8858" as if > the > > > driver will be upstreamed the entity name should at least change. > > > > Yes, this is problematic. > > > > Looking at the driver, it comes from: > > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c#L2936 > > > > This will likely have to be changed to get this merged upstream in the > > kernel. > > > > > As a middle term solution we can add support for "m00_f_ov8858" with a > > > todo note to move to a more canonical "ov8858" name once the driver is > > > upstreamed, or at least submitted upstream. > > > > This is problematic too - there would be overlap - would we have to > > duplicate the camera sensor properties? Or perhaps support registering a > > camera sensor helper as mutliple names? > > > > > > This is the 'why' upstreaming the driver is 'almost' a requirement. > > Parts like that should be solved before integrating in libcamera > > ideally. Perhaps we can workaround it this time as it's hopefully > > manageable - but it means that we would then have libcamera 'supporting' > > the pinephone in one version, but then losing it's support when we > > suddenly change the names to match the upstream kernel until the > > pinephone developers update their kernel. > > Agreed. The driver should be upstreamed, and while we don't require > drivers to be merged upstream before support for them can be added to > libcamera, we do require the drivers to be on their way to upstream. > This means showing a reasonable effort to get it there, most likely with > a patch posted to the linux-media mailing list. > > Give that the entity name will need to change when upstreaming, one way > forward would be to patch the pinephone kernel driver with the correct > entity name already, and use it in libcamera right away. > > > All a bit messy ... :S > > > > > > On Thu, Oct 27, 2022 at 12:25 PM Nicholas Roth wrote: > > > > > > > > > > please pardon me for being pedantic, but I would: > > > > > > libcamera: Add support for ov8858 sensor > > > > > > > > > > > > instead of: > > > > > > ipa: libcamera: add metadata for the ov8858 sensor > > > > > > > > > > Happy to make the change. > > > > > > > > > > > The sensor doesn't seem to be supported mainline :(... > > > > > > Let's start from the first point: where does this driver lives ? > What > > > > > > kernel are you using ? > > > > > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > > > > > > > > > It looks like my package manager is picking up the Manjaro kernel > from > > > > > > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config > , > > > > > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no > > > > > 8858-related changes. This ultimately pulls the driver from > > > > > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > > > > > . > > > > > > > > > > Looks like this has been in and out of Torvalds' peripheral view, > e.g.: > > > > > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html > > > > > > > > > > If you think that it would be valuable to try and mainline this, > I'd be > > > > > interested to do so once I can get libcamera working on my > hardware, though > > > > > I'll likely need some guidance in the process, since I'll be > learning a lot. > > > > > > > > > > > Nice this matches the CCS defined linear gain model. > > > > > > However the sensor allows to select two formats for the analogue > gain > > > > > > the "real gain" format and "sensor gain" format. The selection > is made by > > > > > > register 0x3503[2] and it would be nice to validate that the > driver > > > > > > uses the format that you expect. > > > > > > > > > > Frankly, I'm not sure what you mean by this, but I'll try to find > out from > > > > > the driver above and verify. > > > > > > > > > > > Knowing what driver you're using is relevant, in example, as the > > > > > > OV5688 sensor computes exposure in 1/16 of line length. This is > not > > > > > > what libcamera expects, and sensor drivers are expected to > express the > > > > > > V4L2_CID_EXPOSURE control in line units. > > > > > > > > > > > From Documentation/sensor_driver_requirements.rst > > > > > > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, > libcamera > > > > > > requires it to be expressed as a number of image lines. Camera > sensor drivers > > > > > > that do not comply with this requirement will need to be adapted > or will produce > > > > > > incorrect results. > > > > > > > > > > Let me read the driver and get back to you. > > > > > > > > > > > > > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> > wrote: > > > > > > > > > >> Hi Nicholas, > > > > >> > > > > >> please pardon me for being pedantic, but I would: > > > > >> libcamera: Add support for ov8858 sensor > > > > >> > > > > >> instead of: > > > > >> ipa: libcamera: add metadata for the ov8858 sensor > > > > >> > > > > >> "metadata" is an overloaded already term and usually refers to the > > > > >> properties associated to a captured frame (the term comes from the > > > > >> Android lingo, but we use it too). > > > > >> > > > > >> On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > > > > >> libcamera-devel wrote: > > > > >> > From: Nicholas Roth <nicholas@rothemail.net> > > > > >> > > > > > >> > Currently, libcamera does not have information for the ov8858 > sensor > > > > >> > used in the PinePhone Pro, a phone designed to run Linux. > > > > >> > > > > > >> > This commit adds metadata, especially that sensor gain is > reported and > > > > >> > set in 1/16 discrete increments. > > > > >> > > > > > >> > For more information, see "5.8 manual exposure compensation/ > manual > > > > >> > gain compensation" in [0]. > > > > >> > > > > > >> > [0] > http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > > > >> > > > > >> The sensor doesn't seem to be supported mainline :( > > > > >> libcamera has a policy that requires supported components to be > > > > >> upstream or at least on their way to upstream (ie posted to the > > > > >> linux-media mailing list). The policy is there because different > > > > >> downstream driver implementations might behave differently one > from > > > > >> the other, making it impossible for libcamera to support the part > > > > >> fully. The policy is a strict requirement for ISPs, I guess we're > a > > > > >> bit more elastic when it comes to sensor. Howver knowing what > driver > > > > >> you are using, where it lives, and if there's any plan to > upstream it > > > > >> would be great. > > > > >> > > > > >> Let's start from the first point: where does this driver lives ? > What > > > > >> kernel are you using ? > > > > >> > > > > >> Knowing what driver you're using is relevant, in example, as the > > > > >> OV5688 sensor computes exposure in 1/16 of line length. This is > not > > > > >> what libcamera expects, and sensor drivers are expected to > express the > > > > >> V4L2_CID_EXPOSURE control in line units. > > > > >> > > > > >> From Documentation/sensor_driver_requirements.rst > > > > >> > > > > >> While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, > libcamera > > > > >> requires it to be expressed as a number of image lines. Camera > sensor drivers > > > > >> that do not comply with this requirement will need to be adapted > or will produce > > > > >> incorrect results. > > > > >> > > > > >> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > > > >> > --- > > > > >> > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > > > >> > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > > > >> > 2 files changed, 25 insertions(+) > > > > >> > > > > > >> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > b/src/ipa/libipa/camera_sensor_helper.cpp > > > > >> > index 35056bec..f2040cbd 100644 > > > > >> > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > > > >> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > > > >> > @@ -476,6 +476,17 @@ public: > > > > >> > }; > > > > >> > REGISTER_CAMERA_SENSOR_HELPER("ov5693", > CameraSensorHelperOv5693) > > > > >> > > > > > >> > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > > > >> > +{ > > > > >> > +public: > > > > >> > + CameraSensorHelperOv8858() > > > > >> > + { > > > > >> > + gainType_ = AnalogueGainLinear; > > > > >> > + gainConstants_.linear = { 1, 0, 0, 16 }; > > > > >> > + } > > > > >> > +}; > > > > >> > > > > >> Nice this matches the CCS defined linear gain model. > > > > >> However the sensor allows to select two formats for the analogue > gain > > > > >> the "real gain" format and "sensor gain" format. The selection is > made by > > > > >> register 0x3503[2] and it would be nice to validate that the > driver > > > > >> uses the format that you expect. > > > > >> > > > > >> > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", > CameraSensorHelperOv8858) > > > > >> > > > > >> Ah! that's a weird name for the sensor entity :) > > > > >> > > > > >> > + > > > > >> > class CameraSensorHelperOv8865 : public CameraSensorHelper > > > > >> > { > > > > >> > public: > > > > >> > diff --git a/src/libcamera/camera_sensor_properties.cpp > b/src/libcamera/camera_sensor_properties.cpp > > > > >> > index e5f27f06..d0757c15 100644 > > > > >> > --- a/src/libcamera/camera_sensor_properties.cpp > > > > >> > +++ b/src/libcamera/camera_sensor_properties.cpp > > > > >> > @@ -146,6 +146,20 @@ const CameraSensorProperties > *CameraSensorProperties::get(const std::string &sen > > > > >> > */ > > > > >> > }, > > > > >> > } }, > > > > >> > + { "m00_f_ov8858", { > > > > >> > + .unitCellSize = { 1200, 1200 }, > > > > >> > > > > >> I read 1.12 um x 1.12 um > > > > >> > > > > >> > + .testPatternModes = { > > > > >> > + { > controls::draft::TestPatternModeOff, 0 }, > > > > >> > + { > controls::draft::TestPatternModeColorBars, 1 }, > > > > >> > + /* > > > > >> > + * No best corresponding test > pattern for: > > > > >> > + * 1: "Vertical Color Bar Type 1", > > > > >> > + * 2: "Vertical Color Bar Type 2", > > > > >> > + * 3: "Vertical Color Bar Type 3", > > > > >> > + * 4: "Vertical Color Bar Type 4" > > > > >> > + */ > > > > >> > + }, > > > > >> > + } }, > > > > >> > { "ov8865", { > > > > >> > .unitCellSize = { 1400, 1400 }, > > > > >> > .testPatternModes = { > > -- > Regards, > > Laurent Pinchart >
Hi Nicholas On Sun, Oct 30, 2022 at 05:15:42PM -0500, Nicholas Roth wrote: > > Agreed. The driver should be upstreamed > > I'm going to send an initial version to linux-media today for comment. I'll > include a link to their mailing list with the next set of changes. > > > Give that the entity name will need to change when upstreaming, one way > > forward would be to patch the pinephone kernel driver with the correct > > entity name already, and use it in libcamera right away. > > TL;DR: Media node names do not seem to be standardized and various formats > exist. I suggest adding an `else` case to [6] with an additional regex for > the ov8858 driver for maximum compatibility with non-mainline ov8858 > implementations while we sort out getting this upstreamed. > -- > > Upon reading the driver [0] more closely, it looks like "m00_f_ov8858" is > just the *subdevice name *(set to > "m{module_index:02d}_{facing}_{OV8858_NAME}" on :2936), not the driver module_index is obtained parsing a vendor property that doesn't exist in mainline and should not be reported in the subdevice name. When you will upstream the driver you'll be asked to remove it. > name (set to OV8858_NAME == "ov8858" on :3004) or sensor name (set to > OV8858_NAME == "ov8858" on :1778). 1778 is the callback for a custom ioctl that does not exist upstream. You will have to remove that part when upstreaming. The driver name is set through [1] and used to identify the driver by the kernel's core. It's not something exposed by the media controller api, ie not something we care about when matching on the subdevice entity name [1] https://github.com/megous/linux/blob/orange-pi-6.0/drivers/media/i2c/ov8858.c#L3003 > > Reading the kernel docs [3], it looks like this is required to be unique: > "Afterwards you need to initialize sd->name with a unique name and set the > module owner. This is done for you if you use the i2c helper functions." > > The subdevice name *defaults* to the driver name in [4] when > v4l2_i2c_subdev_init() invokes v4l2_i2c_subdev_set_name(sd, client, NULL, > NULL), but this is not guaranteed to be the driver name if I understand > correctly. In fact, this appears to solve for the case where there may be driver name != subdevice name The subdevice name (or rather, the media entity name) is exposed by the media controller API (iow it's the one that you see using media-ctl -p, and it's the one libcamera matches on). The driver name is a kernel-wide concept. It is used to construct the subdevice name, but as you have noticed it alone is not sufficient to guarantee it is unique in a system, hence... > multiple ov8858s installed, which the default implementation would not. ... read https://github.com/torvalds/linux/blob/master/drivers/media/v4l2-core/v4l2-i2c.c#L31 snprintf(sd->name, sizeof(sd->name), "%s%s %d-%04x", devname, postfix, i2c_adapter_id(client->adapter), client->addr); The subdevice name is constructed by adding to the driver name the device's i2c bus addresses, which guarantees the resulting subdevice name is unique. > Though there is some ambiguity in the phrase "unique name," v4l2-subdev.h > [5] seems to suggest that these must be unique among device instances, not > drivers, since `struct v4l2_subdev` corresponds to a devnode and also > specifies "@name: Name of the sub-device. Please notice that the name must > be unique." > > Meanwhile, both Megi's imx258 fork [1] and the mainline imx258 driver [2] > use the default implementation, so we do not have this issue using > libcamera with an imx258. > > ***libcamera subdevice name handling (regex guess)*** > Currently, libcamera uses a regex to guess the model name from the > subdevice name in v4l2_subdevice.cpp V4L2Subdevice::model() [6]. Instead, > > ***Proposed Solution***: > I suggest adding an `else` case to [6] with an additional regex for the > ov8858 driver for maximum compatibility with non-mainline ov8858 > implementations while we sort out getting this upstreamed. > When you will upstream the driver all the vendor stupidities (the module_index and the device facing information in the name, the custom ioctls etc) will have to be removed. Same for the the subdevice name: you'll be asked to simply use v4l2_i2c_subdev_init() and let it deal with names for you. You will need -strong- arguments to convince upstream you have to use a custom name there. Now, I don't want to put you in a bad position. Your downstream uses a driver which needs to be changed, and at the same time you're trying to upstream one version of the same driver, and libcamera should work ideally with both until things do not settle. Ofc if you can patch your BSP earlier than anything else, and have your system use the same name as the one we expect to be upstream, the problem is solved and we can use "ov8858" directly here. The ideal path for this would then be for you to succesfully upstream the driver and have your BSP replace the vendor's version with your upstream one, provided it is functionally equal. Mainline kernel code + mainline libcamera code == fully upstream support == victory. Now, if you get any resistence on changing your BSP (something tells me you will, I hope to be wrong), considering your CameraSensorHelper is fairly small, I would accept to have one version that matches on "ov8858" and one that matches on "m00_f_ov8858" for an interim period, with a big todo note that it should be remove and with the idea to converge on the upstream name. I don't like this but I hope it might make things easier for you, if plan A of patching the BSP immediately fails. > 0: > https://github.com/megous/linux/blob/orange-pi-6.0/drivers/media/i2c/ov8858.c > 1: > https://github.com/megous/linux/blob/orange-pi-6.0/drivers/media/i2c/imx258.c > 2: https://github.com/torvalds/linux/blob/master/drivers/media/i2c/imx258.c > 3: https://www.kernel.org/doc/html/latest/driver-api/media/v4l2-subdev.html > 4: > https://github.com/torvalds/linux/blob/master/drivers/media/v4l2-core/v4l2-i2c.c > 5: https://github.com/torvalds/linux/blob/master/include/media/v4l2-subdev.h > 6: > https://github.com/kbingham/libcamera/blob/master/src/libcamera/v4l2_subdevice.cpp > > On Sun, Oct 30, 2022 at 11:21 AM Laurent Pinchart < > laurent.pinchart@ideasonboard.com> wrote: > > > Hello, > > > > On Fri, Oct 28, 2022 at 11:25:38AM +0100, Kieran Bingham wrote: > > > Quoting Jacopo Mondi via libcamera-devel (2022-10-28 09:14:27) > > > > Hi Nicholas, > > > > + Laurent question below > > > > > > > > On Thu, Oct 27, 2022 at 05:21:37PM -0500, Nicholas Roth wrote: > > > > > > Nice this matches the CCS defined linear gain model. > > > > > > However the sensor allows to select two formats for the analogue > > gain > > > > > > the "real gain" format and "sensor gain" format. The selection is > > made by > > > > > > register 0x3503[2] and it would be nice to validate that the driver > > > > > > uses the format that you expect. > > > > > > > > > > I think I understand this better after reading the driver. In the > > register > > > > > value settings, I see: > > > > > {0x3502, 0x40}, // exposure L > > > > > {0x3503, 0x80}, // gain delay ?, exposure delay 1 frame, real gain > > > > > {0x3505, 0x80}, // gain option > > > > > > > > > > The 0 low-nibbl indicates we're using "real gain." > > > > > > > > > > According to the datasheet: > > > > > 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 > > > > > > > > > > This tells me that we need to divide reported gain from the driver > > by 16 to > > > > > get a properly-scaled double-value gain, which these gain constants > > do. > > > > > > > > Here you go! > > > > > > > > Looking at the driver you're using I indeed see 3503[2]=0 in all modes > > > > > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, > > libcamera > > > > > > requires it to be expressed as a number of image lines. Camera > > sensor drivers > > > > > > that do not comply with this requirement will need to be adapted > > or will produce > > > > > > incorrect results. > > > > > > > > > > Looks like the driver multiples inputs x16 to convert to 1/16 line > > length > > > > > before writing to the register... > > > > > > > > > > case V4L2_CID_EXPOSURE: > > > > > /* 4 least significant bits of expsoure are fractional part */ > > > > > ret = ov8858_write_reg(ov8858->client, > > > > > OV8858_REG_EXPOSURE, > > > > > OV8858_REG_VALUE_24BIT, > > > > > ctrl->val << 4); > > > > > > > > Great, it means that towards userspace the exposure is indeed in units > > > > of 1 line. > > > > > > > > > Let me know if this looks good, and what needs to happen to merge > > this! > > > > > > > > I think I had a comment on the pixel cell size. > > > > > > > > Apart from that, let me check with Laurent about the policy when it > > > > comes to supporting sensor without an upstream driver. > > > > > > > > I would not be super happy of adding support to "m00_f_ov8858" as if > > the > > > > driver will be upstreamed the entity name should at least change. > > > > > > Yes, this is problematic. > > > > > > Looking at the driver, it comes from: > > > > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c#L2936 > > > > > > This will likely have to be changed to get this merged upstream in the > > > kernel. > > > > > > > As a middle term solution we can add support for "m00_f_ov8858" with a > > > > todo note to move to a more canonical "ov8858" name once the driver is > > > > upstreamed, or at least submitted upstream. > > > > > > This is problematic too - there would be overlap - would we have to > > > duplicate the camera sensor properties? Or perhaps support registering a > > > camera sensor helper as mutliple names? > > > > > > > > > This is the 'why' upstreaming the driver is 'almost' a requirement. > > > Parts like that should be solved before integrating in libcamera > > > ideally. Perhaps we can workaround it this time as it's hopefully > > > manageable - but it means that we would then have libcamera 'supporting' > > > the pinephone in one version, but then losing it's support when we > > > suddenly change the names to match the upstream kernel until the > > > pinephone developers update their kernel. > > > > Agreed. The driver should be upstreamed, and while we don't require > > drivers to be merged upstream before support for them can be added to > > libcamera, we do require the drivers to be on their way to upstream. > > This means showing a reasonable effort to get it there, most likely with > > a patch posted to the linux-media mailing list. > > > > Give that the entity name will need to change when upstreaming, one way > > forward would be to patch the pinephone kernel driver with the correct > > entity name already, and use it in libcamera right away. > > > > > All a bit messy ... :S > > > > > > > > On Thu, Oct 27, 2022 at 12:25 PM Nicholas Roth wrote: > > > > > > > > > > > > please pardon me for being pedantic, but I would: > > > > > > > libcamera: Add support for ov8858 sensor > > > > > > > > > > > > > > instead of: > > > > > > > ipa: libcamera: add metadata for the ov8858 sensor > > > > > > > > > > > > Happy to make the change. > > > > > > > > > > > > > The sensor doesn't seem to be supported mainline :(... > > > > > > > Let's start from the first point: where does this driver lives ? > > What > > > > > > > kernel are you using ? > > > > > > I'm using Manjaro's kernel 5.19.8-1-MANJARO-ARM (from uname -r). > > > > > > > > > > > > It looks like my package manager is picking up the Manjaro kernel > > from > > > > > > > > https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro/-/blob/5.19-megi/config > > , > > > > > > which sets "CONFIG_VIDEO_OV8858=m" in /config otherwise has no > > > > > > 8858-related changes. This ultimately pulls the driver from > > > > > > > > https://github.com/megous/linux/blob/orange-pi-5.19/drivers/media/i2c/ov8858.c > > > > > > . > > > > > > > > > > > > Looks like this has been in and out of Torvalds' peripheral view, > > e.g.: > > > > > > https://lkml.iu.edu/hypermail/linux/kernel/1711.1/06245.html > > > > > > > > > > > > If you think that it would be valuable to try and mainline this, > > I'd be > > > > > > interested to do so once I can get libcamera working on my > > hardware, though > > > > > > I'll likely need some guidance in the process, since I'll be > > learning a lot. > > > > > > > > > > > > > Nice this matches the CCS defined linear gain model. > > > > > > > However the sensor allows to select two formats for the analogue > > gain > > > > > > > the "real gain" format and "sensor gain" format. The selection > > is made by > > > > > > > register 0x3503[2] and it would be nice to validate that the > > driver > > > > > > > uses the format that you expect. > > > > > > > > > > > > Frankly, I'm not sure what you mean by this, but I'll try to find > > out from > > > > > > the driver above and verify. > > > > > > > > > > > > > Knowing what driver you're using is relevant, in example, as the > > > > > > > OV5688 sensor computes exposure in 1/16 of line length. This is > > not > > > > > > > what libcamera expects, and sensor drivers are expected to > > express the > > > > > > > V4L2_CID_EXPOSURE control in line units. > > > > > > > > > > > > > From Documentation/sensor_driver_requirements.rst > > > > > > > > > > > > > While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, > > libcamera > > > > > > > requires it to be expressed as a number of image lines. Camera > > sensor drivers > > > > > > > that do not comply with this requirement will need to be adapted > > or will produce > > > > > > > incorrect results. > > > > > > > > > > > > Let me read the driver and get back to you. > > > > > > > > > > > > > > > > > > On Thu, Oct 27, 2022 at 11:41 AM Jacopo Mondi <jacopo@jmondi.org> > > wrote: > > > > > > > > > > > >> Hi Nicholas, > > > > > >> > > > > > >> please pardon me for being pedantic, but I would: > > > > > >> libcamera: Add support for ov8858 sensor > > > > > >> > > > > > >> instead of: > > > > > >> ipa: libcamera: add metadata for the ov8858 sensor > > > > > >> > > > > > >> "metadata" is an overloaded already term and usually refers to the > > > > > >> properties associated to a captured frame (the term comes from the > > > > > >> Android lingo, but we use it too). > > > > > >> > > > > > >> On Thu, Oct 27, 2022 at 12:55:09AM -0500, Nicholas Roth via > > > > > >> libcamera-devel wrote: > > > > > >> > From: Nicholas Roth <nicholas@rothemail.net> > > > > > >> > > > > > > >> > Currently, libcamera does not have information for the ov8858 > > sensor > > > > > >> > used in the PinePhone Pro, a phone designed to run Linux. > > > > > >> > > > > > > >> > This commit adds metadata, especially that sensor gain is > > reported and > > > > > >> > set in 1/16 discrete increments. > > > > > >> > > > > > > >> > For more information, see "5.8 manual exposure compensation/ > > manual > > > > > >> > gain compensation" in [0]. > > > > > >> > > > > > > >> > [0] > > http://www.ahdsensor.com/uploadfile/202008/55322e75316871.pdf > > > > > >> > > > > > >> The sensor doesn't seem to be supported mainline :( > > > > > >> libcamera has a policy that requires supported components to be > > > > > >> upstream or at least on their way to upstream (ie posted to the > > > > > >> linux-media mailing list). The policy is there because different > > > > > >> downstream driver implementations might behave differently one > > from > > > > > >> the other, making it impossible for libcamera to support the part > > > > > >> fully. The policy is a strict requirement for ISPs, I guess we're > > a > > > > > >> bit more elastic when it comes to sensor. Howver knowing what > > driver > > > > > >> you are using, where it lives, and if there's any plan to > > upstream it > > > > > >> would be great. > > > > > >> > > > > > >> Let's start from the first point: where does this driver lives ? > > What > > > > > >> kernel are you using ? > > > > > >> > > > > > >> Knowing what driver you're using is relevant, in example, as the > > > > > >> OV5688 sensor computes exposure in 1/16 of line length. This is > > not > > > > > >> what libcamera expects, and sensor drivers are expected to > > express the > > > > > >> V4L2_CID_EXPOSURE control in line units. > > > > > >> > > > > > >> From Documentation/sensor_driver_requirements.rst > > > > > >> > > > > > >> While V4L2 doesn't specify a unit for the ``EXPOSURE`` control, > > libcamera > > > > > >> requires it to be expressed as a number of image lines. Camera > > sensor drivers > > > > > >> that do not comply with this requirement will need to be adapted > > or will produce > > > > > >> incorrect results. > > > > > >> > > > > > >> > Signed-off-by: Nicholas Roth <nicholas@rothemail.net> > > > > > >> > --- > > > > > >> > src/ipa/libipa/camera_sensor_helper.cpp | 11 +++++++++++ > > > > > >> > src/libcamera/camera_sensor_properties.cpp | 14 ++++++++++++++ > > > > > >> > 2 files changed, 25 insertions(+) > > > > > >> > > > > > > >> > diff --git a/src/ipa/libipa/camera_sensor_helper.cpp > > b/src/ipa/libipa/camera_sensor_helper.cpp > > > > > >> > index 35056bec..f2040cbd 100644 > > > > > >> > --- a/src/ipa/libipa/camera_sensor_helper.cpp > > > > > >> > +++ b/src/ipa/libipa/camera_sensor_helper.cpp > > > > > >> > @@ -476,6 +476,17 @@ public: > > > > > >> > }; > > > > > >> > REGISTER_CAMERA_SENSOR_HELPER("ov5693", > > CameraSensorHelperOv5693) > > > > > >> > > > > > > >> > +class CameraSensorHelperOv8858 : public CameraSensorHelper > > > > > >> > +{ > > > > > >> > +public: > > > > > >> > + CameraSensorHelperOv8858() > > > > > >> > + { > > > > > >> > + gainType_ = AnalogueGainLinear; > > > > > >> > + gainConstants_.linear = { 1, 0, 0, 16 }; > > > > > >> > + } > > > > > >> > +}; > > > > > >> > > > > > >> Nice this matches the CCS defined linear gain model. > > > > > >> However the sensor allows to select two formats for the analogue > > gain > > > > > >> the "real gain" format and "sensor gain" format. The selection is > > made by > > > > > >> register 0x3503[2] and it would be nice to validate that the > > driver > > > > > >> uses the format that you expect. > > > > > >> > > > > > >> > +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", > > CameraSensorHelperOv8858) > > > > > >> > > > > > >> Ah! that's a weird name for the sensor entity :) > > > > > >> > > > > > >> > + > > > > > >> > class CameraSensorHelperOv8865 : public CameraSensorHelper > > > > > >> > { > > > > > >> > public: > > > > > >> > diff --git a/src/libcamera/camera_sensor_properties.cpp > > b/src/libcamera/camera_sensor_properties.cpp > > > > > >> > index e5f27f06..d0757c15 100644 > > > > > >> > --- a/src/libcamera/camera_sensor_properties.cpp > > > > > >> > +++ b/src/libcamera/camera_sensor_properties.cpp > > > > > >> > @@ -146,6 +146,20 @@ const CameraSensorProperties > > *CameraSensorProperties::get(const std::string &sen > > > > > >> > */ > > > > > >> > }, > > > > > >> > } }, > > > > > >> > + { "m00_f_ov8858", { > > > > > >> > + .unitCellSize = { 1200, 1200 }, > > > > > >> > > > > > >> I read 1.12 um x 1.12 um > > > > > >> > > > > > >> > + .testPatternModes = { > > > > > >> > + { > > controls::draft::TestPatternModeOff, 0 }, > > > > > >> > + { > > controls::draft::TestPatternModeColorBars, 1 }, > > > > > >> > + /* > > > > > >> > + * No best corresponding test > > pattern for: > > > > > >> > + * 1: "Vertical Color Bar Type 1", > > > > > >> > + * 2: "Vertical Color Bar Type 2", > > > > > >> > + * 3: "Vertical Color Bar Type 3", > > > > > >> > + * 4: "Vertical Color Bar Type 4" > > > > > >> > + */ > > > > > >> > + }, > > > > > >> > + } }, > > > > > >> > { "ov8865", { > > > > > >> > .unitCellSize = { 1400, 1400 }, > > > > > >> > .testPatternModes = { > > > > -- > > Regards, > > > > Laurent Pinchart > >
diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp index 35056bec..f2040cbd 100644 --- a/src/ipa/libipa/camera_sensor_helper.cpp +++ b/src/ipa/libipa/camera_sensor_helper.cpp @@ -476,6 +476,17 @@ public: }; REGISTER_CAMERA_SENSOR_HELPER("ov5693", CameraSensorHelperOv5693) +class CameraSensorHelperOv8858 : public CameraSensorHelper +{ +public: + CameraSensorHelperOv8858() + { + gainType_ = AnalogueGainLinear; + gainConstants_.linear = { 1, 0, 0, 16 }; + } +}; +REGISTER_CAMERA_SENSOR_HELPER("m00_f_ov8858", CameraSensorHelperOv8858) + class CameraSensorHelperOv8865 : public CameraSensorHelper { public: diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp index e5f27f06..d0757c15 100644 --- a/src/libcamera/camera_sensor_properties.cpp +++ b/src/libcamera/camera_sensor_properties.cpp @@ -146,6 +146,20 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen */ }, } }, + { "m00_f_ov8858", { + .unitCellSize = { 1200, 1200 }, + .testPatternModes = { + { controls::draft::TestPatternModeOff, 0 }, + { controls::draft::TestPatternModeColorBars, 1 }, + /* + * No best corresponding test pattern for: + * 1: "Vertical Color Bar Type 1", + * 2: "Vertical Color Bar Type 2", + * 3: "Vertical Color Bar Type 3", + * 4: "Vertical Color Bar Type 4" + */ + }, + } }, { "ov8865", { .unitCellSize = { 1400, 1400 }, .testPatternModes = {