diff mbox series

[v4,43/45] media: sun6i-csi: Detect the availability of the ISP

Message ID 20220415152811.636419-44-paul.kocialkowski@bootlin.com (mailing list archive)
State New, archived
Headers show
Series Allwinner A31/A83T MIPI CSI-2 and A31 ISP / CSI Rework | expand

Commit Message

Paul Kocialkowski April 15, 2022, 3:28 p.m. UTC
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(+)

Comments

Jernej Škrabec April 27, 2022, 8:07 p.m. UTC | #1
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?

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, 7:55 a.m. UTC | #2
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.

> 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 {
> 
> 
> 
>
Jernej Škrabec April 28, 2022, 8:09 a.m. UTC | #3
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 {
Maxime Ripard April 28, 2022, 8:11 a.m. UTC | #4
On Thu, Apr 28, 2022 at 09:55:56AM +0200, Paul Kocialkowski wrote:
> 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.

Can the ISP be compiled as a module, but the CSI driver built-in? If so,
that would create a dependency from the kernel image to a module, which
won't compile.

Maxime
Paul Kocialkowski April 28, 2022, 11:39 a.m. UTC | #5
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 {
> 
> 
> 
>
Paul Kocialkowski April 28, 2022, 11:43 a.m. UTC | #6
Hi Maxime,

On Thu 28 Apr 22, 10:11, Maxime Ripard wrote:
> On Thu, Apr 28, 2022 at 09:55:56AM +0200, Paul Kocialkowski wrote:
> > 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.
> 
> Can the ISP be compiled as a module, but the CSI driver built-in?

I think so yes, I don't see any reason why not.

> If so,
> that would create a dependency from the kernel image to a module, which
> won't compile.

I think this would introduce a run-time dependency (sun6i-csi needing sun6i-isp
in order to register) but I don't understand why it wouldn't compile though.
Could you ellaborate a bit?

Thanks!

Paul
Maxime Ripard April 29, 2022, 2:24 p.m. UTC | #7
On Thu, Apr 28, 2022 at 01:43:44PM +0200, Paul Kocialkowski wrote:
> Hi Maxime,
> 
> On Thu 28 Apr 22, 10:11, Maxime Ripard wrote:
> > On Thu, Apr 28, 2022 at 09:55:56AM +0200, Paul Kocialkowski wrote:
> > > 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.
> > 
> > Can the ISP be compiled as a module, but the CSI driver built-in?
> 
> I think so yes, I don't see any reason why not.
> 
> > If so,
> > that would create a dependency from the kernel image to a module, which
> > won't compile.
> 
> I think this would introduce a run-time dependency (sun6i-csi needing sun6i-isp
> in order to register) but I don't understand why it wouldn't compile though.
> Could you ellaborate a bit?

Never mind, that was a brainfart, I was somehow thinking you wer calling
a function there.

Maxime
diff mbox series

Patch

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))
+		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 {