mbox series

[v4,00/45] Allwinner A31/A83T MIPI CSI-2 and A31 ISP / CSI Rework

Message ID 20220415152811.636419-1-paul.kocialkowski@bootlin.com
Headers show
Series Allwinner A31/A83T MIPI CSI-2 and A31 ISP / CSI Rework | expand

Message

Paul Kocialkowski April 15, 2022, 3:27 p.m. UTC
This new version is an offspring from the big "Allwinner A31/A83T
MIPI CSI-2 Support and A31 ISP Support" series, which was split into
individual series for better clarity and handling.

This part only concerns the rework of the CSI driver to support the MIPI CSI-2
and ISP workflows.

Changes since v3:
- Updated Kconfig to follow the latest media-wide changes;
- Rebased on latest changes to the driver (JPEG/sRGB colorspaces);
- Added helper to get a single enabled link for an entity's pad, to replace
  source selection at link_validate time and select the remote source at
  stream on time instead;
- Kept clock-managed regmap mmio;
- Added collected review tags;
- Various cosmetic cleanups;

Changes since all-in-one v2:
- Reworked capture video device registration, which stays in the main path.
- Reworked async subdev handling with a dedicated structure holding the
  corresponding source to avoid matching in the driver;
- Added mutex for mbus format serialization;
- Remove useless else in link_validate;
- Reworked commit logs to include missing information;
- Cleaned up Kconfig, added PM dependency;
- Moved platform-specific clock rate to of match data;
- Added collected Reviewed-by tags;
- Updated copyright years;

Paul Kocialkowski (45):
  media: sun6i-csi: Define and use driver name and (reworked)
    description
  media: sun6i-csi: Refactor main driver data structures
  media: sun6i-csi: Tidy up platform code
  media: sun6i-csi: Always set exclusive module clock rate
  media: sun6i-csi: Define and use variant to get module clock rate
  media: sun6i-csi: Use runtime pm for clocks and reset
  media: sun6i-csi: Tidy up Kconfig
  media: sun6i-csi: Tidy up v4l2 code
  media: sun6i-csi: Tidy up video code
  media: sun6i-csi: Pass and store csi device directly in video code
  media: sun6i-csi: Register the media device after creation
  media: sun6i-csi: Add media ops with link notify callback
  media: sun6i-csi: Introduce and use video helper functions
  media: sun6i-csi: Move csi buffer definition to main header file
  media: media-entity: Add helper to get a single enabled link
  media: sun6i-csi: Add bridge v4l2 subdev with port management
  media: sun6i-csi: Rename sun6i_video to sun6i_csi_capture
  media: sun6i-csi: Add capture state using vsync for page flip
  media: sun6i-csi: Rework register definitions, invert misleading
    fields
  media: sun6i-csi: Add dimensions and format helpers to capture
  media: sun6i-csi: Implement address configuration without indirection
  media: sun6i-csi: Split stream sequences and irq code in capture
  media: sun6i-csi: Move power management to runtime pm in capture
  media: sun6i-csi: Move register configuration to capture
  media: sun6i-csi: Rework capture format management with helper
  media: sun6i-csi: Remove custom format helper and rework configure
  media: sun6i-csi: Add bridge dimensions and format helpers
  media: sun6i-csi: Get mbus code from bridge instead of storing it
  media: sun6i-csi: Tidy capture configure code
  media: sun6i-csi: Introduce bridge format structure, list and helper
  media: sun6i-csi: Introduce capture format structure, list and helper
  media: sun6i-csi: Configure registers from format tables
  media: sun6i-csi: Introduce format match structure, list and helper
  media: sun6i-csi: Implement capture link validation with logic
  media: sun6i-csi: Get bridge subdev directly in capture stream ops
  media: sun6i-csi: Move hardware control to the bridge
  media: sun6i-csi: Rename the capture video device to sun6i-csi-capture
  media: sun6i-csi: Cleanup headers and includes, update copyright lines
  media: sun6i-csi: Add support for MIPI CSI-2 to the bridge code
  media: sun6i-csi: Only configure capture when streaming
  media: sun6i-csi: Add extra checks to the interrupt routine
  media: sun6i-csi: Request a shared interrupt
  media: sun6i-csi: Detect the availability of the ISP
  media: sun6i-csi: Add support for hooking to the isp devices
  MAINTAINERS: Add myself as sun6i-csi maintainer and rename/move entry

 MAINTAINERS                                   |   17 +-
 drivers/media/mc/mc-entity.c                  |   26 +
 .../media/platform/sunxi/sun6i-csi/Kconfig    |   12 +-
 .../media/platform/sunxi/sun6i-csi/Makefile   |    2 +-
 .../platform/sunxi/sun6i-csi/sun6i_csi.c      | 1077 +++++-----------
 .../platform/sunxi/sun6i-csi/sun6i_csi.h      |  153 +--
 .../sunxi/sun6i-csi/sun6i_csi_bridge.c        |  869 +++++++++++++
 .../sunxi/sun6i-csi/sun6i_csi_bridge.h        |   69 +
 .../sunxi/sun6i-csi/sun6i_csi_capture.c       | 1109 +++++++++++++++++
 .../sunxi/sun6i-csi/sun6i_csi_capture.h       |   89 ++
 .../platform/sunxi/sun6i-csi/sun6i_csi_reg.h  |  362 +++---
 .../platform/sunxi/sun6i-csi/sun6i_video.c    |  685 ----------
 .../platform/sunxi/sun6i-csi/sun6i_video.h    |   38 -
 include/media/media-entity.h                  |   13 +
 14 files changed, 2707 insertions(+), 1814 deletions(-)
 create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.c
 create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_bridge.h
 create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c
 create mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.h
 delete mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.c
 delete mode 100644 drivers/media/platform/sunxi/sun6i-csi/sun6i_video.h

Comments

Jernej Škrabec April 28, 2022, 8:09 a.m. UTC | #1
Dne četrtek, 28. april 2022 ob 09:55:56 CEST je Paul Kocialkowski napisal(a):
> Hi Jernej,
> 
> Thanks a lot for all your reviews!
> 
> On Wed 27 Apr 22, 22:07, Jernej Škrabec wrote:
> > Dne petek, 15. april 2022 ob 17:28:09 CEST je Paul Kocialkowski 
napisal(a):
> > > Add a helper to detect whether the ISP is available and connected
> > > and store the indication in a driver-wide variable.
> > > 
> > > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > > ---
> > > 
> > >  .../platform/sunxi/sun6i-csi/sun6i_csi.c      | 33 +++++++++++++++++++
> > >  .../platform/sunxi/sun6i-csi/sun6i_csi.h      |  3 ++
> > >  2 files changed, 36 insertions(+)
> > > 
> > > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > > b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index
> > > a88deb8ba1e7..f185cbd113c7 100644
> > > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > > @@ -25,6 +25,35 @@
> > > 
> > >  #include "sun6i_csi_capture.h"
> > >  #include "sun6i_csi_reg.h"
> > > 
> > > +/* ISP */
> > > +
> > > +static bool sun6i_csi_isp_detect(struct sun6i_csi_device *csi_dev)
> > > +{
> > > +	struct device *dev = csi_dev->dev;
> > > +	struct fwnode_handle *handle = NULL;
> > > +
> > > +	/* ISP is not available if disabled in kernel config. */
> > > +	if (!IS_ENABLED(CONFIG_VIDEO_SUN6I_ISP))
> > 
> > Where is this symbol defined?
> 
> That is defined through Kconfig's auto-generated header, from the associated
> option for the ISP driver. It is defined in the ISP support series so this
> will effectively always be false for now.

Well, then, that driver should be merged before this patch. While I understand 
that it's likely that ISP driver with such name will eventually materialize in 
kernel, I don't want to rely on things that are not set in stone, e.g. already 
merged.

Best regards,
Jernej

> 
> > Best regards,
> > Jernej
> > 
> > > +		return 0;
> > > +
> > > +	/*
> > > +	 * ISP is not available if not connected via fwnode graph.
> > > +	 * This weill also check that the remote parent node is available.
> > > +	 */
> > > +	handle = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
> > > +
> > 
> > SUN6I_CSI_PORT_ISP, 0,
> > 
> > > +
> > 
> > FWNODE_GRAPH_ENDPOINT_NEXT);
> > 
> > > +	if (!handle)
> > > +		return 0;
> > > +
> > > +	fwnode_handle_put(handle);
> > > +
> > > +	dev_info(dev, "ISP link is available\n");
> > > +	csi_dev->isp_available = true;
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > 
> > >  /* Media */
> > >  
> > >  static const struct media_device_ops sun6i_csi_media_ops = {
> > > 
> > > @@ -306,6 +335,10 @@ static int sun6i_csi_probe(struct platform_device
> > > *platform_dev) if (ret)
> > > 
> > >  		return ret;
> > > 
> > > +	ret = sun6i_csi_isp_detect(csi_dev);
> > > +	if (ret)
> > > +		goto error_resources;
> > > +
> > > 
> > >  	ret = sun6i_csi_v4l2_setup(csi_dev);
> > >  	if (ret)
> > >  	
> > >  		goto error_resources;
> > > 
> > > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h
> > > b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h index
> > > 6aa83dd11684..9b105c341047 100644
> > > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h
> > > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h
> > > @@ -22,6 +22,7 @@
> > > 
> > >  enum sun6i_csi_port {
> > >  
> > >  	SUN6I_CSI_PORT_PARALLEL		= 0,
> > >  	SUN6I_CSI_PORT_MIPI_CSI2	= 1,
> > > 
> > > +	SUN6I_CSI_PORT_ISP		= 2,
> > > 
> > >  };
> > >  
> > >  struct sun6i_csi_buffer {
> > > 
> > > @@ -46,6 +47,8 @@ struct sun6i_csi_device {
> > > 
> > >  	struct clk			*clock_mod;
> > >  	struct clk			*clock_ram;
> > >  	struct reset_control		*reset;
> > > 
> > > +
> > > +	bool				isp_available;
> > > 
> > >  };
> > >  
> > >  struct sun6i_csi_variant {
Paul Kocialkowski April 28, 2022, 11:39 a.m. UTC | #2
Hi Jernej,

On Thu 28 Apr 22, 10:09, Jernej Škrabec wrote:
> Dne četrtek, 28. april 2022 ob 09:55:56 CEST je Paul Kocialkowski napisal(a):
> > Hi Jernej,
> > 
> > Thanks a lot for all your reviews!
> > 
> > On Wed 27 Apr 22, 22:07, Jernej Škrabec wrote:
> > > Dne petek, 15. april 2022 ob 17:28:09 CEST je Paul Kocialkowski 
> napisal(a):
> > > > Add a helper to detect whether the ISP is available and connected
> > > > and store the indication in a driver-wide variable.
> > > > 
> > > > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > > > ---
> > > > 
> > > >  .../platform/sunxi/sun6i-csi/sun6i_csi.c      | 33 +++++++++++++++++++
> > > >  .../platform/sunxi/sun6i-csi/sun6i_csi.h      |  3 ++
> > > >  2 files changed, 36 insertions(+)
> > > > 
> > > > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > > > b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index
> > > > a88deb8ba1e7..f185cbd113c7 100644
> > > > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > > > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > > > @@ -25,6 +25,35 @@
> > > > 
> > > >  #include "sun6i_csi_capture.h"
> > > >  #include "sun6i_csi_reg.h"
> > > > 
> > > > +/* ISP */
> > > > +
> > > > +static bool sun6i_csi_isp_detect(struct sun6i_csi_device *csi_dev)
> > > > +{
> > > > +	struct device *dev = csi_dev->dev;
> > > > +	struct fwnode_handle *handle = NULL;
> > > > +
> > > > +	/* ISP is not available if disabled in kernel config. */
> > > > +	if (!IS_ENABLED(CONFIG_VIDEO_SUN6I_ISP))
> > > 
> > > Where is this symbol defined?
> > 
> > That is defined through Kconfig's auto-generated header, from the associated
> > option for the ISP driver. It is defined in the ISP support series so this
> > will effectively always be false for now.
> 
> Well, then, that driver should be merged before this patch. While I understand 
> that it's likely that ISP driver with such name will eventually materialize in 
> kernel, I don't want to rely on things that are not set in stone, e.g. already 
> merged.

Okay that would make sense, the patches adding ISP support in sun6i-csi could
be moved to the series adding support for the ISP.

Cheers,

Paul

> Best regards,
> Jernej
> 
> > 
> > > Best regards,
> > > Jernej
> > > 
> > > > +		return 0;
> > > > +
> > > > +	/*
> > > > +	 * ISP is not available if not connected via fwnode graph.
> > > > +	 * This weill also check that the remote parent node is available.
> > > > +	 */
> > > > +	handle = fwnode_graph_get_endpoint_by_id(dev_fwnode(dev),
> > > > +
> > > 
> > > SUN6I_CSI_PORT_ISP, 0,
> > > 
> > > > +
> > > 
> > > FWNODE_GRAPH_ENDPOINT_NEXT);
> > > 
> > > > +	if (!handle)
> > > > +		return 0;
> > > > +
> > > > +	fwnode_handle_put(handle);
> > > > +
> > > > +	dev_info(dev, "ISP link is available\n");
> > > > +	csi_dev->isp_available = true;
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > > 
> > > >  /* Media */
> > > >  
> > > >  static const struct media_device_ops sun6i_csi_media_ops = {
> > > > 
> > > > @@ -306,6 +335,10 @@ static int sun6i_csi_probe(struct platform_device
> > > > *platform_dev) if (ret)
> > > > 
> > > >  		return ret;
> > > > 
> > > > +	ret = sun6i_csi_isp_detect(csi_dev);
> > > > +	if (ret)
> > > > +		goto error_resources;
> > > > +
> > > > 
> > > >  	ret = sun6i_csi_v4l2_setup(csi_dev);
> > > >  	if (ret)
> > > >  	
> > > >  		goto error_resources;
> > > > 
> > > > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h
> > > > b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h index
> > > > 6aa83dd11684..9b105c341047 100644
> > > > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h
> > > > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h
> > > > @@ -22,6 +22,7 @@
> > > > 
> > > >  enum sun6i_csi_port {
> > > >  
> > > >  	SUN6I_CSI_PORT_PARALLEL		= 0,
> > > >  	SUN6I_CSI_PORT_MIPI_CSI2	= 1,
> > > > 
> > > > +	SUN6I_CSI_PORT_ISP		= 2,
> > > > 
> > > >  };
> > > >  
> > > >  struct sun6i_csi_buffer {
> > > > 
> > > > @@ -46,6 +47,8 @@ struct sun6i_csi_device {
> > > > 
> > > >  	struct clk			*clock_mod;
> > > >  	struct clk			*clock_ram;
> > > >  	struct reset_control		*reset;
> > > > 
> > > > +
> > > > +	bool				isp_available;
> > > > 
> > > >  };
> > > >  
> > > >  struct sun6i_csi_variant {
> 
> 
> 
>