mbox series

[v4,0/5] media: Add MIPI CCI register access helper functions

Message ID 20230627125109.52354-1-hdegoede@redhat.com
Headers show
Series media: Add MIPI CCI register access helper functions | expand

Message

Hans de Goede June 27, 2023, 12:51 p.m. UTC
Hi Laurent, Sakari, et al.,

Here is v4 of my MIPI CCI register access helper patches.

New in the CCI register access helpers in v4:
- Add V4L2_CCI_I2C Kconfig and wrap devm_cci_regmap_init_i2c()
  with if IS_ENABLED(CONFIG_V4L2_CCI_I2C)

New in the CCI register access helpers in v3:
- Use unsigned int instead of int in a couple of places
- Run + fix checkpatch.pl --strict --max-line-length=80
- Rename cci_regmap_init_i2c() to devm_cci_regmap_init_i2c()
- Some small kerneldoc text tweaks

Other changes in v3:
- Some small tweaks to some of the driver conversions,
  see individual patch changelogs

New in the CCI register access helpers in v2:
- Drop cci_reg_type enum
- Make having an encoded reg-width mandatory rather then using 0 to encode
  8 bit width making reg-addresses without an encoded width default to
  a width of 8
- Add support for 64 bit wide registers
- Introduce a new cci_reg_sequence struct with 64 bit reg values for 64 bit
  support and without the delay_us field
- Various kerneldoc updates
- Stop supporting delays in cci_multi_reg_write()
- Some includes cleanups
- Disable regmap locking

Other changes in v2:
- Add a patch to convert the ov5693 driver (tested on Surface Go)
- Add a patch to convert the imx290 driver (untested)

Original (v1) cover-letter:

The CSI2 specification specifies a standard method to access camera sensor
registers called "Camera Control Interface (CCI)".

Currently a lot of Linux camera sensor drivers all have their own custom
helpers for this, often copy and pasted from other drivers.

This adds a set of generic helpers for this so that all sensor drivers can
switch to a single common implementation.

This is based on / the result of our previous discussion on this here:
Link: https://lore.kernel.org/linux-media/59aefa7f-7bf9-6736-6040-39551329cd0a@redhat.com/

Patches 2-4 are examples of how these helpers can be used and patch 5
removes the now no longer necessary ov_16bit_addr_reg_helpers.h which was
the previous attempt to add common CCI access helpers.

Regards,

Hans


Hans de Goede (5):
  media: Add MIPI CCI register access helper functions
  media: ov5693: Convert to new CCI register access helpers
  media: imx290: Convert to new CCI register access helpers
  media: atomisp: ov2680: Convert to new CCI register access helpers
  media: Remove ov_16bit_addr_reg_helpers.h

 Documentation/driver-api/media/v4l2-cci.rst   |   5 +
 Documentation/driver-api/media/v4l2-core.rst  |   1 +
 drivers/media/i2c/Kconfig                     |   2 +
 drivers/media/i2c/imx290.c                    | 360 +++++------
 drivers/media/i2c/ov5693.c                    | 585 +++++++-----------
 drivers/media/v4l2-core/Kconfig               |   9 +
 drivers/media/v4l2-core/Makefile              |   1 +
 drivers/media/v4l2-core/v4l2-cci.c            | 166 +++++
 drivers/staging/media/atomisp/i2c/Kconfig     |   1 +
 .../media/atomisp/i2c/atomisp-ov2680.c        | 251 ++++----
 drivers/staging/media/atomisp/i2c/ov2680.h    |  86 +--
 include/media/ov_16bit_addr_reg_helpers.h     |  92 ---
 include/media/v4l2-cci.h                      | 125 ++++
 13 files changed, 807 insertions(+), 877 deletions(-)
 create mode 100644 Documentation/driver-api/media/v4l2-cci.rst
 create mode 100644 drivers/media/v4l2-core/v4l2-cci.c
 delete mode 100644 include/media/ov_16bit_addr_reg_helpers.h
 create mode 100644 include/media/v4l2-cci.h

Comments

Sakari Ailus July 2, 2023, 10:51 a.m. UTC | #1
Hi Hans, Laurent,

On Tue, Jun 27, 2023 at 02:51:03PM +0200, Hans de Goede wrote:
> Hi Laurent, Sakari, et al.,
> 
> Here is v4 of my MIPI CCI register access helper patches.
> 
> New in the CCI register access helpers in v4:
> - Add V4L2_CCI_I2C Kconfig and wrap devm_cci_regmap_init_i2c()
>   with if IS_ENABLED(CONFIG_V4L2_CCI_I2C)

Laurent: are you fine with this version? I see you've acked all but the
first patch.

I'll pick this to my tree then.
Laurent Pinchart Aug. 15, 2023, 1:54 p.m. UTC | #2
On Tue, Aug 15, 2023 at 03:48:53PM +0200, Alexander Stein wrote:
> Am Dienstag, 15. August 2023, 15:31:55 CEST schrieb Sakari Ailus:
> > On Tue, Aug 15, 2023 at 04:15:39PM +0300, Laurent Pinchart wrote:
> > > On Tue, Jun 27, 2023 at 02:51:06PM +0200, Hans de Goede wrote:
> > > > Use the new comon CCI register access helpers to replace the private
> > > > register access helpers in the imx290 driver.
> > > > 
> > > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > > > ---
> > > > Note:
> > > > 1. This is untested
> > > > 2. For reviewers: all the IMX290_REG_?BIT defines in both the register
> > > > address defines as well as in various reg-sequences were automatically
> > > > changed using search replace.
> > > > ---
> > > > Changes in v3:
> > > > - Fixed a couple of lines > 80 chars
> > > > 
> > > > Changes in v2:
> > > > - New patch in v2 of this series
> > > > ---
> > > > 
> > > >  drivers/media/i2c/Kconfig  |   1 +
> > > >  drivers/media/i2c/imx290.c | 360 +++++++++++++++----------------------
> > > >  2 files changed, 150 insertions(+), 211 deletions(-)
> > > 
> > > [snip]
> > > 
> > > > diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c
> > > > index b3f832e9d7e1..e78c7b91ae72 100644
> > > > --- a/drivers/media/i2c/imx290.c
> > > > +++ b/drivers/media/i2c/imx290.c
> > > > @@ -21,91 +21,86 @@
> > > 
> > > [snip]
> > > 
> > > > @@ -615,63 +605,15 @@ imx290_format_info(const struct imx290 *imx290, u32 code)
> > > > 
> > > >  	return NULL;
> > > >  
> > > >  }
> > > > 
> > > > -/* -----------------------------------------------------------------------------
> > > > - * Register access
> > > > - */
> > > > -
> > > > -static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *value)
> > > > -{
> > > > -	u8 data[3] = { 0, 0, 0 };
> > > > -	int ret;
> > > > -
> > > > -	ret = regmap_raw_read(imx290->regmap, addr & IMX290_REG_ADDR_MASK,
> > > > -			      data, (addr >> IMX290_REG_SIZE_SHIFT) & 3);
> > > > -	if (ret < 0) {
> > > > -		dev_err(imx290->dev, "%u-bit read from 0x%04x failed: %d\n",
> > > > -			((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8,
> > > > -			 addr & IMX290_REG_ADDR_MASK, ret);
> > > > -		return ret;
> > > > -	}
> > > > -
> > > > -	*value = get_unaligned_le24(data);
> > > > -	return 0;
> > > > -}
> > > > -
> > > > -static int imx290_write(struct imx290 *imx290, u32 addr, u32 value, int *err)
> > > > -{
> > > > -	u8 data[3];
> > > > -	int ret;
> > > > -
> > > > -	if (err && *err)
> > > > -		return *err;
> > > > -
> > > > -	put_unaligned_le24(value, data);
> > > 
> > > We seem to be having a problem here, as the CCI helpers unconditionally
> > > use big endian for the data :-(
> > 
> > Well spotted. This driver needs to address this.
> > 
> > It's a hardware issue though. It's the only sensor ever I've seen to have
> > little endian registers.

The IMX296 and IMX297 seem to also have little-endian register values.

> It's getting even worse: There are cameras using this sensor when bulk read is 
> broken (VC MIPI IMX327 C, Laurent knows about this peculiar hardware), so 
> regmap_config.use_single_read has to be set to true. This is currently not 
> possible anymore insode this driver.

I think this could be fixed by passing a flag to the init function. Or,
possibly better, the init function could read a DT property and set the
flag automatically.

> > > > -
> > > > -	ret = regmap_raw_write(imx290->regmap, addr & IMX290_REG_ADDR_MASK,
> > > > -			       data, (addr >> IMX290_REG_SIZE_SHIFT) & 3);
> > > > -	if (ret < 0) {
> > > > -		dev_err(imx290->dev, "%u-bit write to 0x%04x failed: %d\n",
> > > > -			((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8,
> > > > -			 addr & IMX290_REG_ADDR_MASK, ret);
> > > > -		if (err)
> > > > -			*err = ret;
> > > > -	}
> > > > -
> > > > -	return ret;
> > > > -}
> > > > -
> > > 
> > > [snip]