mbox series

[0/3] media: imx258: Remove rotation=<80 requirement

Message ID 20230117100603.51631-1-jacopo.mondi@ideasonboard.com
Headers show
Series media: imx258: Remove rotation=<80 requirement | expand

Message

Jacopo Mondi Jan. 17, 2023, 10:06 a.m. UTC
Currently the imx258 driver requires to have the 'rotation' device node
property specified in DTS with a fixed value of 180 degrees.

The "rotation" fwnode device property is intended to allow specify the
sensor's physical mounting rotation, so that it can be exposed through
the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
can decide how to compensate for that.

The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
a 180 degrees image rotation being produced by the sensor. But this
doesn't imply that the physical mounting rotation should match the
driver's implementation.

I took into the series Robert's patch that register device node properties and
on top of that register flips controls, in order to remove the hard requirement
of the 180 degrees rotation property presence.

Jacopo Mondi (2):
  media: imx258: Register H/V flip controls
  media: imx258: Remove mandatory 180 degrees rotation

Robert Mader (1):
  media: imx258: Parse and register properties

 drivers/media/i2c/imx258.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

--
2.39.0

Comments

Dave Stevenson Jan. 26, 2023, 3:48 p.m. UTC | #1
Hi Jacopo and Sakari

On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
>
> Hi Jacopo,
>
> On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > Currently the imx258 driver requires to have the 'rotation' device node
> > property specified in DTS with a fixed value of 180 degrees.
> >
> > The "rotation" fwnode device property is intended to allow specify the
> > sensor's physical mounting rotation, so that it can be exposed through
> > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > can decide how to compensate for that.
> >
> > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > a 180 degrees image rotation being produced by the sensor. But this
> > doesn't imply that the physical mounting rotation should match the
> > driver's implementation.
> >
> > I took into the series Robert's patch that register device node properties and
> > on top of that register flips controls, in order to remove the hard requirement
> > of the 180 degrees rotation property presence.
>
> Reconsidering these patches after the flipping vs. rotation discussion,
> they seem fine. The only thing I'd like to see, after removing the rotation
> property check, would be to add support for the actual flipping controls.
> I'm pretty sure they can be found in the same registers as on CCS --- the
> rest of the registers look very much like that. Would you like to send a
> patch? :-)

Yes it is register 0x0101, bits 0 (H) & 1 (V).

Do watch out as there are register errors in the driver. Currently
Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
That means that when you initially implement flips the Bayer order
won't change, but you change the field of view by one line.
The start and end values also break the requirements listed in the
datasheets for STA/END values being multiples of X (table 4-2 of the
datasheet). Correcting that will change the Bayer order when inverted.
Does that count as a regression to userspace? I hope not. Memory says
that if you don't correct Y_ADD_END then some of the binned modes
misbehave.

I have been through this loop before as Soho Enterprise [1] make an
IMX258 board for the Pi. I haven't upstreamed the patches [2] though
(sorry).

  Dave

[1] https://soho-enterprise.com/
[2] https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c

> --
> Regards,
>
> Sakari Ailus
Laurent Pinchart Jan. 26, 2023, 4:01 p.m. UTC | #2
Hi Dave,

On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> On Thu, 26 Jan 2023 at 14:52, Sakari Ailus wrote:
> > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > Currently the imx258 driver requires to have the 'rotation' device node
> > > property specified in DTS with a fixed value of 180 degrees.
> > >
> > > The "rotation" fwnode device property is intended to allow specify the
> > > sensor's physical mounting rotation, so that it can be exposed through
> > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > can decide how to compensate for that.
> > >
> > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > a 180 degrees image rotation being produced by the sensor. But this
> > > doesn't imply that the physical mounting rotation should match the
> > > driver's implementation.
> > >
> > > I took into the series Robert's patch that register device node properties and
> > > on top of that register flips controls, in order to remove the hard requirement
> > > of the 180 degrees rotation property presence.
> >
> > Reconsidering these patches after the flipping vs. rotation discussion,
> > they seem fine. The only thing I'd like to see, after removing the rotation
> > property check, would be to add support for the actual flipping controls.
> > I'm pretty sure they can be found in the same registers as on CCS --- the
> > rest of the registers look very much like that. Would you like to send a
> > patch? :-)
> 
> Yes it is register 0x0101, bits 0 (H) & 1 (V).
> 
> Do watch out as there are register errors in the driver. Currently
> Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
> That means that when you initially implement flips the Bayer order
> won't change, but you change the field of view by one line.
> The start and end values also break the requirements listed in the
> datasheets for STA/END values being multiples of X (table 4-2 of the
> datasheet). Correcting that will change the Bayer order when inverted.
> Does that count as a regression to userspace? I hope not. Memory says
> that if you don't correct Y_ADD_END then some of the binned modes
> misbehave.

As long as the driver reports the correct bayer pattern, it should be
fine.

Interactions between formats and flip controls is something we still
need to clarify. I plan to have a follow-up discussion on this with
Jacopo and Sakari after sending documentation patches for the
interactions between rotation and flips. If you would like to join the
fun, please let me know.

Also, if you have any comment on the rotation & flip discussion notes,
and especially if there's anything that doesn't seem right to you,
feedback would be appreciated. If everything is good, you can just ack
the documentation patches when I'll post them :-)

> I have been through this loop before as Soho Enterprise [1] make an
> IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> (sorry).

Thanks for sharing the branch.

> [1] https://soho-enterprise.com/
> [2] https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c
Sakari Ailus Jan. 26, 2023, 4:02 p.m. UTC | #3
Hi Dave,

On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> Hi Jacopo and Sakari
> 
> On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
> >
> > Hi Jacopo,
> >
> > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > Currently the imx258 driver requires to have the 'rotation' device node
> > > property specified in DTS with a fixed value of 180 degrees.
> > >
> > > The "rotation" fwnode device property is intended to allow specify the
> > > sensor's physical mounting rotation, so that it can be exposed through
> > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > can decide how to compensate for that.
> > >
> > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > a 180 degrees image rotation being produced by the sensor. But this
> > > doesn't imply that the physical mounting rotation should match the
> > > driver's implementation.
> > >
> > > I took into the series Robert's patch that register device node properties and
> > > on top of that register flips controls, in order to remove the hard requirement
> > > of the 180 degrees rotation property presence.
> >
> > Reconsidering these patches after the flipping vs. rotation discussion,
> > they seem fine. The only thing I'd like to see, after removing the rotation
> > property check, would be to add support for the actual flipping controls.
> > I'm pretty sure they can be found in the same registers as on CCS --- the
> > rest of the registers look very much like that. Would you like to send a
> > patch? :-)
> 
> Yes it is register 0x0101, bits 0 (H) & 1 (V).
> 
> Do watch out as there are register errors in the driver. Currently
> Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.

Yes, this is the problem with register list based drivers. Well spotted.

I remember one driver for a Toshiba sensor using value of 5 for a register
the range of which was 2--10, but only even values were allowed. It worked
nonetheless... oh well.

I wonder if this sensor would work better with the CCS driver 

> That means that when you initially implement flips the Bayer order
> won't change, but you change the field of view by one line.
> The start and end values also break the requirements listed in the
> datasheets for STA/END values being multiples of X (table 4-2 of the
> datasheet). Correcting that will change the Bayer order when inverted.
> Does that count as a regression to userspace? I hope not. Memory says
> that if you don't correct Y_ADD_END then some of the binned modes
> misbehave.

Most sensors also require even values for the ?_ADDR_START registers (and
odd for the _ADDR_END registers). Using an invalid value sometimes might
work, too, but only testing will tell.

> 
> I have been through this loop before as Soho Enterprise [1] make an
> IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> (sorry).

It'd be nice if both worked with the same driver.
Dave Stevenson Jan. 26, 2023, 4:13 p.m. UTC | #4
Hi Laurent

On Thu, 26 Jan 2023 at 16:01, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Dave,
>
> On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> > On Thu, 26 Jan 2023 at 14:52, Sakari Ailus wrote:
> > > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > > Currently the imx258 driver requires to have the 'rotation' device node
> > > > property specified in DTS with a fixed value of 180 degrees.
> > > >
> > > > The "rotation" fwnode device property is intended to allow specify the
> > > > sensor's physical mounting rotation, so that it can be exposed through
> > > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > > can decide how to compensate for that.
> > > >
> > > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > > a 180 degrees image rotation being produced by the sensor. But this
> > > > doesn't imply that the physical mounting rotation should match the
> > > > driver's implementation.
> > > >
> > > > I took into the series Robert's patch that register device node properties and
> > > > on top of that register flips controls, in order to remove the hard requirement
> > > > of the 180 degrees rotation property presence.
> > >
> > > Reconsidering these patches after the flipping vs. rotation discussion,
> > > they seem fine. The only thing I'd like to see, after removing the rotation
> > > property check, would be to add support for the actual flipping controls.
> > > I'm pretty sure they can be found in the same registers as on CCS --- the
> > > rest of the registers look very much like that. Would you like to send a
> > > patch? :-)
> >
> > Yes it is register 0x0101, bits 0 (H) & 1 (V).
> >
> > Do watch out as there are register errors in the driver. Currently
> > Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
> > That means that when you initially implement flips the Bayer order
> > won't change, but you change the field of view by one line.
> > The start and end values also break the requirements listed in the
> > datasheets for STA/END values being multiples of X (table 4-2 of the
> > datasheet). Correcting that will change the Bayer order when inverted.
> > Does that count as a regression to userspace? I hope not. Memory says
> > that if you don't correct Y_ADD_END then some of the binned modes
> > misbehave.
>
> As long as the driver reports the correct bayer pattern, it should be
> fine.

It does report the correct Bayer order so I would hope so too, however
I know the hard coding that can go on in client apps!

> Interactions between formats and flip controls is something we still
> need to clarify. I plan to have a follow-up discussion on this with
> Jacopo and Sakari after sending documentation patches for the
> interactions between rotation and flips. If you would like to join the
> fun, please let me know.

Feel free to send me an invite for future discussions, however I'm
currently assigned to other tasks and have been told to leave image
sensors alone :-(

> Also, if you have any comment on the rotation & flip discussion notes,
> and especially if there's anything that doesn't seem right to you,
> feedback would be appreciated. If everything is good, you can just ack
> the documentation patches when I'll post them :-)

I have the luxury of being able to largely ignore the existing
clients, but the proposals as currently described seem like they
should work for all parties. I'll respond to your docs when they're
posted.

> > I have been through this loop before as Soho Enterprise [1] make an
> > IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> > (sorry).
>
> Thanks for sharing the branch.

No problem. I am trying to persuade management here that it is worth
the effort to upstream patches, but it's tough going sometimes.
I do always try to ensure that our downstream patches follow the rules
and have SoB etc, so others are at liberty to lift them if they wish.

  Dave

> > [1] https://soho-enterprise.com/
> > [2] https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c
>
> --
> Regards,
>
> Laurent Pinchart
Dave Stevenson Jan. 26, 2023, 4:44 p.m. UTC | #5
Hi Sakari

On Thu, 26 Jan 2023 at 16:02, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
>
> Hi Dave,
>
> On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> > Hi Jacopo and Sakari
> >
> > On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
> > >
> > > Hi Jacopo,
> > >
> > > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > > Currently the imx258 driver requires to have the 'rotation' device node
> > > > property specified in DTS with a fixed value of 180 degrees.
> > > >
> > > > The "rotation" fwnode device property is intended to allow specify the
> > > > sensor's physical mounting rotation, so that it can be exposed through
> > > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > > can decide how to compensate for that.
> > > >
> > > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > > a 180 degrees image rotation being produced by the sensor. But this
> > > > doesn't imply that the physical mounting rotation should match the
> > > > driver's implementation.
> > > >
> > > > I took into the series Robert's patch that register device node properties and
> > > > on top of that register flips controls, in order to remove the hard requirement
> > > > of the 180 degrees rotation property presence.
> > >
> > > Reconsidering these patches after the flipping vs. rotation discussion,
> > > they seem fine. The only thing I'd like to see, after removing the rotation
> > > property check, would be to add support for the actual flipping controls.
> > > I'm pretty sure they can be found in the same registers as on CCS --- the
> > > rest of the registers look very much like that. Would you like to send a
> > > patch? :-)
> >
> > Yes it is register 0x0101, bits 0 (H) & 1 (V).
> >
> > Do watch out as there are register errors in the driver. Currently
> > Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
>
> Yes, this is the problem with register list based drivers. Well spotted.

It fell out when I flipped the image and the Bayer order didn't change.

> I remember one driver for a Toshiba sensor using value of 5 for a register
> the range of which was 2--10, but only even values were allowed. It worked
> nonetheless... oh well.
>
> I wonder if this sensor would work better with the CCS driver

That's a question I'll leave to others to investigate :-)

> > That means that when you initially implement flips the Bayer order
> > won't change, but you change the field of view by one line.
> > The start and end values also break the requirements listed in the
> > datasheets for STA/END values being multiples of X (table 4-2 of the
> > datasheet). Correcting that will change the Bayer order when inverted.
> > Does that count as a regression to userspace? I hope not. Memory says
> > that if you don't correct Y_ADD_END then some of the binned modes
> > misbehave.
>
> Most sensors also require even values for the ?_ADDR_START registers (and
> odd for the _ADDR_END registers). Using an invalid value sometimes might
> work, too, but only testing will tell.
>
> >
> > I have been through this loop before as Soho Enterprise [1] make an
> > IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> > (sorry).
>
> It'd be nice if both worked with the same driver.

All my patches on that branch should work for existing users, other
than potentially the change of Bayer order if they're making
assumptions.

I have been in touch with Sony about IMX258, however they couldn't
release some information as it was confidential to some company called
Intel ;-)
The PDAF or non-PDAF version information is in the OTP, but they can't
release the details with regard to where.

  Dave

> --
> Kind regards,
>
> Sakari Ailus
Jacopo Mondi Jan. 26, 2023, 5:31 p.m. UTC | #6
Hello

On Thu, Jan 26, 2023 at 06:02:07PM +0200, Sakari Ailus wrote:
> Hi Dave,
>
> On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> > Hi Jacopo and Sakari
> >
> > On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
> > >
> > > Hi Jacopo,
> > >
> > > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > > Currently the imx258 driver requires to have the 'rotation' device node
> > > > property specified in DTS with a fixed value of 180 degrees.
> > > >
> > > > The "rotation" fwnode device property is intended to allow specify the
> > > > sensor's physical mounting rotation, so that it can be exposed through
> > > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > > can decide how to compensate for that.
> > > >
> > > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > > a 180 degrees image rotation being produced by the sensor. But this
> > > > doesn't imply that the physical mounting rotation should match the
> > > > driver's implementation.
> > > >
> > > > I took into the series Robert's patch that register device node properties and
> > > > on top of that register flips controls, in order to remove the hard requirement
> > > > of the 180 degrees rotation property presence.
> > >
> > > Reconsidering these patches after the flipping vs. rotation discussion,
> > > they seem fine. The only thing I'd like to see, after removing the rotation
> > > property check, would be to add support for the actual flipping controls.
> > > I'm pretty sure they can be found in the same registers as on CCS --- the
> > > rest of the registers look very much like that. Would you like to send a
> > > patch? :-)
> >
> > Yes it is register 0x0101, bits 0 (H) & 1 (V).
> >
> > Do watch out as there are register errors in the driver. Currently
> > Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
>
> Yes, this is the problem with register list based drivers. Well spotted.
>
> I remember one driver for a Toshiba sensor using value of 5 for a register
> the range of which was 2--10, but only even values were allowed. It worked
> nonetheless... oh well.
>
> I wonder if this sensor would work better with the CCS driver
>
> > That means that when you initially implement flips the Bayer order
> > won't change, but you change the field of view by one line.
> > The start and end values also break the requirements listed in the
> > datasheets for STA/END values being multiples of X (table 4-2 of the
> > datasheet). Correcting that will change the Bayer order when inverted.
> > Does that count as a regression to userspace? I hope not. Memory says
> > that if you don't correct Y_ADD_END then some of the binned modes
> > misbehave.
>
> Most sensors also require even values for the ?_ADDR_START registers (and
> odd for the _ADDR_END registers). Using an invalid value sometimes might
> work, too, but only testing will tell.
>
> >
> > I have been through this loop before as Soho Enterprise [1] make an
> > IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> > (sorry).
>
> It'd be nice if both worked with the same driver.
>

There are a lot of interesting changes in here that would be worth
upstreaming
https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c

I would prefer if we can get these three easy patches of minr in and
then start shoveling the good stuff from the rpi repo ?

Otherwise I can plumb flip support in with the current wrong totals
which, if I understand you right, doesn't require changing the bayer
patter order ?


> --
> Kind regards,
>
> Sakari Ailus
Dave Stevenson Jan. 26, 2023, 5:58 p.m. UTC | #7
Hi Jacopo

On Thu, 26 Jan 2023 at 17:31, Jacopo Mondi
<jacopo.mondi@ideasonboard.com> wrote:
>
> Hello
>
> On Thu, Jan 26, 2023 at 06:02:07PM +0200, Sakari Ailus wrote:
> > Hi Dave,
> >
> > On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> > > Hi Jacopo and Sakari
> > >
> > > On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
> > > >
> > > > Hi Jacopo,
> > > >
> > > > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > > > Currently the imx258 driver requires to have the 'rotation' device node
> > > > > property specified in DTS with a fixed value of 180 degrees.
> > > > >
> > > > > The "rotation" fwnode device property is intended to allow specify the
> > > > > sensor's physical mounting rotation, so that it can be exposed through
> > > > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > > > can decide how to compensate for that.
> > > > >
> > > > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > > > a 180 degrees image rotation being produced by the sensor. But this
> > > > > doesn't imply that the physical mounting rotation should match the
> > > > > driver's implementation.
> > > > >
> > > > > I took into the series Robert's patch that register device node properties and
> > > > > on top of that register flips controls, in order to remove the hard requirement
> > > > > of the 180 degrees rotation property presence.
> > > >
> > > > Reconsidering these patches after the flipping vs. rotation discussion,
> > > > they seem fine. The only thing I'd like to see, after removing the rotation
> > > > property check, would be to add support for the actual flipping controls.
> > > > I'm pretty sure they can be found in the same registers as on CCS --- the
> > > > rest of the registers look very much like that. Would you like to send a
> > > > patch? :-)
> > >
> > > Yes it is register 0x0101, bits 0 (H) & 1 (V).
> > >
> > > Do watch out as there are register errors in the driver. Currently
> > > Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
> >
> > Yes, this is the problem with register list based drivers. Well spotted.
> >
> > I remember one driver for a Toshiba sensor using value of 5 for a register
> > the range of which was 2--10, but only even values were allowed. It worked
> > nonetheless... oh well.
> >
> > I wonder if this sensor would work better with the CCS driver
> >
> > > That means that when you initially implement flips the Bayer order
> > > won't change, but you change the field of view by one line.
> > > The start and end values also break the requirements listed in the
> > > datasheets for STA/END values being multiples of X (table 4-2 of the
> > > datasheet). Correcting that will change the Bayer order when inverted.
> > > Does that count as a regression to userspace? I hope not. Memory says
> > > that if you don't correct Y_ADD_END then some of the binned modes
> > > misbehave.
> >
> > Most sensors also require even values for the ?_ADDR_START registers (and
> > odd for the _ADDR_END registers). Using an invalid value sometimes might
> > work, too, but only testing will tell.
> >
> > >
> > > I have been through this loop before as Soho Enterprise [1] make an
> > > IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> > > (sorry).
> >
> > It'd be nice if both worked with the same driver.
> >
>
> There are a lot of interesting changes in here that would be worth
> upstreaming
> https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c

I do feel a little guilty for not upstreaming these patches myself,
but I'm currently not being given any time to do so. Perhaps I'll take
an afternoon off and blitz a load of patches (imx258, imx290, and
ov7251 for a start).

Obviously that branch is based on 5.15. I was going to say that the
rpi-6.2.y branch may be a better source, however it looks like all the
commits got squashed :-(

> I would prefer if we can get these three easy patches of minr in and
> then start shoveling the good stuff from the rpi repo ?
>
> Otherwise I can plumb flip support in with the current wrong totals
> which, if I understand you right, doesn't require changing the bayer
> patter order ?

Memory says VFLIP won't currently change Bayer order, but I think HFLIP will.
If it is permitted to merge the current read-only FLIP patches, then
I'd suggest doing that initially.

Out of interest, do you have a user of imx258, or is this just as clean ups?
It may be possible to get a sample from Soho Enterprises if you
explain your involvement in libcamera. They're generally very
approachable.

  Dave

>
> > --
> > Kind regards,
> >
> > Sakari Ailus
Jacopo Mondi Jan. 26, 2023, 8:03 p.m. UTC | #8
Hi David

On Thu, Jan 26, 2023 at 05:58:30PM +0000, Dave Stevenson wrote:
> Hi Jacopo
>
> On Thu, 26 Jan 2023 at 17:31, Jacopo Mondi
> <jacopo.mondi@ideasonboard.com> wrote:
> >
> > Hello
> >
> > On Thu, Jan 26, 2023 at 06:02:07PM +0200, Sakari Ailus wrote:
> > > Hi Dave,
> > >
> > > On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> > > > Hi Jacopo and Sakari
> > > >
> > > > On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
> > > > >
> > > > > Hi Jacopo,
> > > > >
> > > > > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > > > > Currently the imx258 driver requires to have the 'rotation' device node
> > > > > > property specified in DTS with a fixed value of 180 degrees.
> > > > > >
> > > > > > The "rotation" fwnode device property is intended to allow specify the
> > > > > > sensor's physical mounting rotation, so that it can be exposed through
> > > > > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > > > > can decide how to compensate for that.
> > > > > >
> > > > > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > > > > a 180 degrees image rotation being produced by the sensor. But this
> > > > > > doesn't imply that the physical mounting rotation should match the
> > > > > > driver's implementation.
> > > > > >
> > > > > > I took into the series Robert's patch that register device node properties and
> > > > > > on top of that register flips controls, in order to remove the hard requirement
> > > > > > of the 180 degrees rotation property presence.
> > > > >
> > > > > Reconsidering these patches after the flipping vs. rotation discussion,
> > > > > they seem fine. The only thing I'd like to see, after removing the rotation
> > > > > property check, would be to add support for the actual flipping controls.
> > > > > I'm pretty sure they can be found in the same registers as on CCS --- the
> > > > > rest of the registers look very much like that. Would you like to send a
> > > > > patch? :-)
> > > >
> > > > Yes it is register 0x0101, bits 0 (H) & 1 (V).
> > > >
> > > > Do watch out as there are register errors in the driver. Currently
> > > > Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
> > >
> > > Yes, this is the problem with register list based drivers. Well spotted.
> > >
> > > I remember one driver for a Toshiba sensor using value of 5 for a register
> > > the range of which was 2--10, but only even values were allowed. It worked
> > > nonetheless... oh well.
> > >
> > > I wonder if this sensor would work better with the CCS driver
> > >
> > > > That means that when you initially implement flips the Bayer order
> > > > won't change, but you change the field of view by one line.
> > > > The start and end values also break the requirements listed in the
> > > > datasheets for STA/END values being multiples of X (table 4-2 of the
> > > > datasheet). Correcting that will change the Bayer order when inverted.
> > > > Does that count as a regression to userspace? I hope not. Memory says
> > > > that if you don't correct Y_ADD_END then some of the binned modes
> > > > misbehave.
> > >
> > > Most sensors also require even values for the ?_ADDR_START registers (and
> > > odd for the _ADDR_END registers). Using an invalid value sometimes might
> > > work, too, but only testing will tell.
> > >
> > > >
> > > > I have been through this loop before as Soho Enterprise [1] make an
> > > > IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> > > > (sorry).
> > >
> > > It'd be nice if both worked with the same driver.
> > >
> >
> > There are a lot of interesting changes in here that would be worth
> > upstreaming
> > https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c
>
> I do feel a little guilty for not upstreaming these patches myself,
> but I'm currently not being given any time to do so. Perhaps I'll take
> an afternoon off and blitz a load of patches (imx258, imx290, and
> ov7251 for a start).
>
> Obviously that branch is based on 5.15. I was going to say that the
> rpi-6.2.y branch may be a better source, however it looks like all the
> commits got squashed :-(
>
> > I would prefer if we can get these three easy patches of minr in and
> > then start shoveling the good stuff from the rpi repo ?
> >
> > Otherwise I can plumb flip support in with the current wrong totals
> > which, if I understand you right, doesn't require changing the bayer
> > patter order ?
>
> Memory says VFLIP won't currently change Bayer order, but I think HFLIP will.
> If it is permitted to merge the current read-only FLIP patches, then
> I'd suggest doing that initially.
>
> Out of interest, do you have a user of imx258, or is this just as clean ups?
> It may be possible to get a sample from Soho Enterprises if you
> explain your involvement in libcamera. They're generally very
> approachable.
>

Thanks for the hint.

I'm using the imx258 on the PinephonePro, so I have a testing device.

I don't see a tuning file for the sensor in libcamera, does Soho
Enterprise ever published one ?

>   Dave
>
> >
> > > --
> > > Kind regards,
> > >
> > > Sakari Ailus
Dave Stevenson Jan. 27, 2023, 11:08 a.m. UTC | #9
Hi Jacopo

On Thu, 26 Jan 2023 at 20:03, Jacopo Mondi
<jacopo.mondi@ideasonboard.com> wrote:
>
> Hi David
>
> On Thu, Jan 26, 2023 at 05:58:30PM +0000, Dave Stevenson wrote:
> > Hi Jacopo
> >
> > On Thu, 26 Jan 2023 at 17:31, Jacopo Mondi
> > <jacopo.mondi@ideasonboard.com> wrote:
> > >
> > > Hello
> > >
> > > On Thu, Jan 26, 2023 at 06:02:07PM +0200, Sakari Ailus wrote:
> > > > Hi Dave,
> > > >
> > > > On Thu, Jan 26, 2023 at 03:48:04PM +0000, Dave Stevenson wrote:
> > > > > Hi Jacopo and Sakari
> > > > >
> > > > > On Thu, 26 Jan 2023 at 14:52, Sakari Ailus <sakari.ailus@linux.intel.com> wrote:
> > > > > >
> > > > > > Hi Jacopo,
> > > > > >
> > > > > > On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> > > > > > > Currently the imx258 driver requires to have the 'rotation' device node
> > > > > > > property specified in DTS with a fixed value of 180 degrees.
> > > > > > >
> > > > > > > The "rotation" fwnode device property is intended to allow specify the
> > > > > > > sensor's physical mounting rotation, so that it can be exposed through
> > > > > > > the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> > > > > > > can decide how to compensate for that.
> > > > > > >
> > > > > > > The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> > > > > > > a 180 degrees image rotation being produced by the sensor. But this
> > > > > > > doesn't imply that the physical mounting rotation should match the
> > > > > > > driver's implementation.
> > > > > > >
> > > > > > > I took into the series Robert's patch that register device node properties and
> > > > > > > on top of that register flips controls, in order to remove the hard requirement
> > > > > > > of the 180 degrees rotation property presence.
> > > > > >
> > > > > > Reconsidering these patches after the flipping vs. rotation discussion,
> > > > > > they seem fine. The only thing I'd like to see, after removing the rotation
> > > > > > property check, would be to add support for the actual flipping controls.
> > > > > > I'm pretty sure they can be found in the same registers as on CCS --- the
> > > > > > rest of the registers look very much like that. Would you like to send a
> > > > > > patch? :-)
> > > > >
> > > > > Yes it is register 0x0101, bits 0 (H) & 1 (V).
> > > > >
> > > > > Do watch out as there are register errors in the driver. Currently
> > > > > Y_ADD_STA is set to 0, and Y_ADD_END to 3118, giving 3119 lines total.
> > > >
> > > > Yes, this is the problem with register list based drivers. Well spotted.
> > > >
> > > > I remember one driver for a Toshiba sensor using value of 5 for a register
> > > > the range of which was 2--10, but only even values were allowed. It worked
> > > > nonetheless... oh well.
> > > >
> > > > I wonder if this sensor would work better with the CCS driver
> > > >
> > > > > That means that when you initially implement flips the Bayer order
> > > > > won't change, but you change the field of view by one line.
> > > > > The start and end values also break the requirements listed in the
> > > > > datasheets for STA/END values being multiples of X (table 4-2 of the
> > > > > datasheet). Correcting that will change the Bayer order when inverted.
> > > > > Does that count as a regression to userspace? I hope not. Memory says
> > > > > that if you don't correct Y_ADD_END then some of the binned modes
> > > > > misbehave.
> > > >
> > > > Most sensors also require even values for the ?_ADDR_START registers (and
> > > > odd for the _ADDR_END registers). Using an invalid value sometimes might
> > > > work, too, but only testing will tell.
> > > >
> > > > >
> > > > > I have been through this loop before as Soho Enterprise [1] make an
> > > > > IMX258 board for the Pi. I haven't upstreamed the patches [2] though
> > > > > (sorry).
> > > >
> > > > It'd be nice if both worked with the same driver.
> > > >
> > >
> > > There are a lot of interesting changes in here that would be worth
> > > upstreaming
> > > https://github.com/raspberrypi/linux/commits/rpi-5.15.y/drivers/media/i2c/imx258.c
> >
> > I do feel a little guilty for not upstreaming these patches myself,
> > but I'm currently not being given any time to do so. Perhaps I'll take
> > an afternoon off and blitz a load of patches (imx258, imx290, and
> > ov7251 for a start).
> >
> > Obviously that branch is based on 5.15. I was going to say that the
> > rpi-6.2.y branch may be a better source, however it looks like all the
> > commits got squashed :-(
> >
> > > I would prefer if we can get these three easy patches of minr in and
> > > then start shoveling the good stuff from the rpi repo ?
> > >
> > > Otherwise I can plumb flip support in with the current wrong totals
> > > which, if I understand you right, doesn't require changing the bayer
> > > patter order ?
> >
> > Memory says VFLIP won't currently change Bayer order, but I think HFLIP will.
> > If it is permitted to merge the current read-only FLIP patches, then
> > I'd suggest doing that initially.
> >
> > Out of interest, do you have a user of imx258, or is this just as clean ups?
> > It may be possible to get a sample from Soho Enterprises if you
> > explain your involvement in libcamera. They're generally very
> > approachable.
> >
>
> Thanks for the hint.
>
> I'm using the imx258 on the PinephonePro, so I have a testing device.
>
> I don't see a tuning file for the sensor in libcamera, does Soho
> Enterprise ever published one ?

I don't recall having seen a final tuning file for imx258, but it
would be for the Pi IPA anyway which would make it less applicable for
the PinephonePro.
They've been making a number of modules, and I need to encourage them
to upstream their drivers and tunings. Their main guy is ex-Sony, so
he's fairly hot on image quality and tuning, but has turned to me for
a moderate amount of the kernel side detail.

It looks like https://forums.raspberrypi.com/viewtopic.php?t=331819
was our forum thread discussing imx258. The incorrect register
settings were giving white lines on the edges of the images,
particularly on the binned modes.
I have no information on HDR or PDAF for imx258, although I do know
both are different from IMX708. Also note that PDAF is optional in the
module, so shielded pixel correction needs to be correctly set for the
module.

Feel free to shout if you need me to test any driver changes, although
I'll keep an eye out for any imx258 patches anyway.

  Dave

> >   Dave
> >
> > >
> > > > --
> > > > Kind regards,
> > > >
> > > > Sakari Ailus
Jacopo Mondi Feb. 27, 2023, 5:11 p.m. UTC | #10
Hi Sakari

   I don't see this patch being collected for 6.3 while I recall that
based on the discussion we concluded we can have these in and the
iterate on top ?

Thanks
  j

On Tue, Jan 17, 2023 at 11:06:00AM +0100, Jacopo Mondi wrote:
> Currently the imx258 driver requires to have the 'rotation' device node
> property specified in DTS with a fixed value of 180 degrees.
>
> The "rotation" fwnode device property is intended to allow specify the
> sensor's physical mounting rotation, so that it can be exposed through
> the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications
> can decide how to compensate for that.
>
> The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in
> a 180 degrees image rotation being produced by the sensor. But this
> doesn't imply that the physical mounting rotation should match the
> driver's implementation.
>
> I took into the series Robert's patch that register device node properties and
> on top of that register flips controls, in order to remove the hard requirement
> of the 180 degrees rotation property presence.
>
> Jacopo Mondi (2):
>   media: imx258: Register H/V flip controls
>   media: imx258: Remove mandatory 180 degrees rotation
>
> Robert Mader (1):
>   media: imx258: Parse and register properties
>
>  drivers/media/i2c/imx258.c | 33 ++++++++++++++++++++++++---------
>  1 file changed, 24 insertions(+), 9 deletions(-)
>
> --
> 2.39.0
>
Sakari Ailus Feb. 27, 2023, 10:09 p.m. UTC | #11
Hi Jacopo,

On Mon, Feb 27, 2023 at 06:11:47PM +0100, Jacopo Mondi wrote:
> Hi Sakari
> 
>    I don't see this patch being collected for 6.3 while I recall that
> based on the discussion we concluded we can have these in and the
> iterate on top ?

I know... I'll take it to my tree early in the next cycle (once we have
rc1).
Jacopo Mondi March 22, 2023, 12:27 p.m. UTC | #12
Hi Sakari,
  as Robert noted, this doesn't seem to be part of the pull request
for 6.4 ? Is it intentional ?

Thanks
  j

On Tue, Feb 28, 2023 at 12:09:24AM +0200, Sakari Ailus wrote:
> Hi Jacopo,
>
> On Mon, Feb 27, 2023 at 06:11:47PM +0100, Jacopo Mondi wrote:
> > Hi Sakari
> >
> >    I don't see this patch being collected for 6.3 while I recall that
> > based on the discussion we concluded we can have these in and the
> > iterate on top ?
>
> I know... I'll take it to my tree early in the next cycle (once we have
> rc1).
>
> --
> Kind regards,
>
> Sakari Ailus
Jacopo Mondi March 22, 2023, 12:32 p.m. UTC | #13
Thank you ;)

If you post CCS patches I'll try to have a look if it speeds things up

On Wed, Mar 22, 2023 at 02:30:39PM +0200, Sakari Ailus wrote:
> Hi Jacopo,
>
> On Wed, Mar 22, 2023 at 01:27:30PM +0100, Jacopo Mondi wrote:
> > Hi Sakari,
> >   as Robert noted, this doesn't seem to be part of the pull request
> > for 6.4 ? Is it intentional ?
>
> Uh, yes and no. These definitely should go to 6.4 but I wanted to address
> the CCS driver at the same time. I'll try to post CCS patches next week but
> if these don't make it, I'll just merge these nonetheless.
>
> --
> Kind regards,
>
> Sakari Ailus