[PATCH v1 07/19] staging: media: tegra-video: csi: parametrize MIPI calibration device presence

Svyatoslav Ryhel posted 19 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v1 07/19] staging: media: tegra-video: csi: parametrize MIPI calibration device presence
Posted by Svyatoslav Ryhel 1 month, 2 weeks ago
Dedicated MIPI calibration block appears only in Tegra114, before Tegra114
all MIPI calibration pads were part of VI block.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 drivers/staging/media/tegra-video/csi.c      | 12 +++++++-----
 drivers/staging/media/tegra-video/csi.h      |  1 +
 drivers/staging/media/tegra-video/tegra210.c |  1 +
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/tegra-video/csi.c b/drivers/staging/media/tegra-video/csi.c
index 74c92db1032f..2f9907a20db1 100644
--- a/drivers/staging/media/tegra-video/csi.c
+++ b/drivers/staging/media/tegra-video/csi.c
@@ -485,11 +485,13 @@ static int tegra_csi_channel_alloc(struct tegra_csi *csi,
 	if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
 		return 0;
 
-	chan->mipi = tegra_mipi_request(csi->dev, node);
-	if (IS_ERR(chan->mipi)) {
-		ret = PTR_ERR(chan->mipi);
-		chan->mipi = NULL;
-		dev_err(csi->dev, "failed to get mipi device: %d\n", ret);
+	if (csi->soc->has_mipi_calibration) {
+		chan->mipi = tegra_mipi_request(csi->dev, node);
+		if (IS_ERR(chan->mipi)) {
+			ret = PTR_ERR(chan->mipi);
+			chan->mipi = NULL;
+			dev_err(csi->dev, "failed to get mipi device: %d\n", ret);
+		}
 	}
 
 	return ret;
diff --git a/drivers/staging/media/tegra-video/csi.h b/drivers/staging/media/tegra-video/csi.h
index 3ed2dbc73ce9..400b913bb1cb 100644
--- a/drivers/staging/media/tegra-video/csi.h
+++ b/drivers/staging/media/tegra-video/csi.h
@@ -128,6 +128,7 @@ struct tegra_csi_soc {
 	unsigned int num_clks;
 	const struct tpg_framerate *tpg_frmrate_table;
 	unsigned int tpg_frmrate_table_size;
+	bool has_mipi_calibration;
 };
 
 /**
diff --git a/drivers/staging/media/tegra-video/tegra210.c b/drivers/staging/media/tegra-video/tegra210.c
index da99f19a39e7..305472e94af4 100644
--- a/drivers/staging/media/tegra-video/tegra210.c
+++ b/drivers/staging/media/tegra-video/tegra210.c
@@ -1218,4 +1218,5 @@ const struct tegra_csi_soc tegra210_csi_soc = {
 	.num_clks = ARRAY_SIZE(tegra210_csi_cil_clks),
 	.tpg_frmrate_table = tegra210_tpg_frmrate_table,
 	.tpg_frmrate_table_size = ARRAY_SIZE(tegra210_tpg_frmrate_table),
+	.has_mipi_calibration = true,
 };
-- 
2.48.1
Re: [PATCH v1 07/19] staging: media: tegra-video: csi: parametrize MIPI calibration device presence
Posted by Mikko Perttunen 1 month ago
On Tuesday, August 19, 2025 9:16 PM Svyatoslav Ryhel wrote:
> Dedicated MIPI calibration block appears only in Tegra114, before Tegra114
> all MIPI calibration pads were part of VI block.
> 
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
>  drivers/staging/media/tegra-video/csi.c      | 12 +++++++-----
>  drivers/staging/media/tegra-video/csi.h      |  1 +
>  drivers/staging/media/tegra-video/tegra210.c |  1 +
>  3 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/staging/media/tegra-video/csi.c
> b/drivers/staging/media/tegra-video/csi.c index 74c92db1032f..2f9907a20db1
> 100644
> --- a/drivers/staging/media/tegra-video/csi.c
> +++ b/drivers/staging/media/tegra-video/csi.c
> @@ -485,11 +485,13 @@ static int tegra_csi_channel_alloc(struct tegra_csi
> *csi, if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
>  		return 0;
> 
> -	chan->mipi = tegra_mipi_request(csi->dev, node);
> -	if (IS_ERR(chan->mipi)) {
> -		ret = PTR_ERR(chan->mipi);
> -		chan->mipi = NULL;
> -		dev_err(csi->dev, "failed to get mipi device: %d\n", ret);
> +	if (csi->soc->has_mipi_calibration) {
> +		chan->mipi = tegra_mipi_request(csi->dev, node);

The way I would read 'soc->has_mipi_calibration' is that this device (CSI) 
contains the MIPI calibration hardware. I.e. the opposite of here. I would 
invert the logic and optionally call it e.g. 'internal_mipi_calib'.

A cleaner way to do this might be to always call tegra_mipi_request et al. -- 
on pre-Tegra114 SoCs this would just call back to the VI/CSI driver using the 
callbacks registered in the MIPI driver as we discussed before. That way the 
CSI driver won't need separate code paths for SoCs with internal MIPI 
calibration and SoCs with the external MIPI calibration device.

Cheers,
Mikko

> +		if (IS_ERR(chan->mipi)) {
> +			ret = PTR_ERR(chan->mipi);
> +			chan->mipi = NULL;
> +			dev_err(csi->dev, "failed to get mipi device: 
%d\n", ret);
> +		}
>  	}
> 
>  	return ret;
> diff --git a/drivers/staging/media/tegra-video/csi.h
> b/drivers/staging/media/tegra-video/csi.h index 3ed2dbc73ce9..400b913bb1cb
> 100644
> --- a/drivers/staging/media/tegra-video/csi.h
> +++ b/drivers/staging/media/tegra-video/csi.h
> @@ -128,6 +128,7 @@ struct tegra_csi_soc {
>  	unsigned int num_clks;
>  	const struct tpg_framerate *tpg_frmrate_table;
>  	unsigned int tpg_frmrate_table_size;
> +	bool has_mipi_calibration;
>  };
> 
>  /**
> diff --git a/drivers/staging/media/tegra-video/tegra210.c
> b/drivers/staging/media/tegra-video/tegra210.c index
> da99f19a39e7..305472e94af4 100644
> --- a/drivers/staging/media/tegra-video/tegra210.c
> +++ b/drivers/staging/media/tegra-video/tegra210.c
> @@ -1218,4 +1218,5 @@ const struct tegra_csi_soc tegra210_csi_soc = {
>  	.num_clks = ARRAY_SIZE(tegra210_csi_cil_clks),
>  	.tpg_frmrate_table = tegra210_tpg_frmrate_table,
>  	.tpg_frmrate_table_size = ARRAY_SIZE(tegra210_tpg_frmrate_table),
> +	.has_mipi_calibration = true,
>  };
Re: [PATCH v1 07/19] staging: media: tegra-video: csi: parametrize MIPI calibration device presence
Posted by Svyatoslav Ryhel 1 month ago
вт, 2 вер. 2025 р. о 03:47 Mikko Perttunen <mperttunen@nvidia.com> пише:
>
> On Tuesday, August 19, 2025 9:16 PM Svyatoslav Ryhel wrote:
> > Dedicated MIPI calibration block appears only in Tegra114, before Tegra114
> > all MIPI calibration pads were part of VI block.
> >
> > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > ---
> >  drivers/staging/media/tegra-video/csi.c      | 12 +++++++-----
> >  drivers/staging/media/tegra-video/csi.h      |  1 +
> >  drivers/staging/media/tegra-video/tegra210.c |  1 +
> >  3 files changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/staging/media/tegra-video/csi.c
> > b/drivers/staging/media/tegra-video/csi.c index 74c92db1032f..2f9907a20db1
> > 100644
> > --- a/drivers/staging/media/tegra-video/csi.c
> > +++ b/drivers/staging/media/tegra-video/csi.c
> > @@ -485,11 +485,13 @@ static int tegra_csi_channel_alloc(struct tegra_csi
> > *csi, if (IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
> >               return 0;
> >
> > -     chan->mipi = tegra_mipi_request(csi->dev, node);
> > -     if (IS_ERR(chan->mipi)) {
> > -             ret = PTR_ERR(chan->mipi);
> > -             chan->mipi = NULL;
> > -             dev_err(csi->dev, "failed to get mipi device: %d\n", ret);
> > +     if (csi->soc->has_mipi_calibration) {
> > +             chan->mipi = tegra_mipi_request(csi->dev, node);
>
> The way I would read 'soc->has_mipi_calibration' is that this device (CSI)
> contains the MIPI calibration hardware. I.e. the opposite of here. I would
> invert the logic and optionally call it e.g. 'internal_mipi_calib'.
>
> A cleaner way to do this might be to always call tegra_mipi_request et al. --
> on pre-Tegra114 SoCs this would just call back to the VI/CSI driver using the
> callbacks registered in the MIPI driver as we discussed before. That way the
> CSI driver won't need separate code paths for SoCs with internal MIPI
> calibration and SoCs with the external MIPI calibration device.
>

So basically MIPI calibration device for Tegra20/Tegra30 has to be
created within CSI and when MIPI calibration is requested, CSI phandle
is used. Question: may I use a dedicated node for MIPI calibration
within CSI or it has to use CSI node itself? With dedicated node
configuration should be much simpler and can help avoiding probe of
entire.

> Cheers,
> Mikko
>
> > +             if (IS_ERR(chan->mipi)) {
> > +                     ret = PTR_ERR(chan->mipi);
> > +                     chan->mipi = NULL;
> > +                     dev_err(csi->dev, "failed to get mipi device:
> %d\n", ret);
> > +             }
> >       }
> >
> >       return ret;
> > diff --git a/drivers/staging/media/tegra-video/csi.h
> > b/drivers/staging/media/tegra-video/csi.h index 3ed2dbc73ce9..400b913bb1cb
> > 100644
> > --- a/drivers/staging/media/tegra-video/csi.h
> > +++ b/drivers/staging/media/tegra-video/csi.h
> > @@ -128,6 +128,7 @@ struct tegra_csi_soc {
> >       unsigned int num_clks;
> >       const struct tpg_framerate *tpg_frmrate_table;
> >       unsigned int tpg_frmrate_table_size;
> > +     bool has_mipi_calibration;
> >  };
> >
> >  /**
> > diff --git a/drivers/staging/media/tegra-video/tegra210.c
> > b/drivers/staging/media/tegra-video/tegra210.c index
> > da99f19a39e7..305472e94af4 100644
> > --- a/drivers/staging/media/tegra-video/tegra210.c
> > +++ b/drivers/staging/media/tegra-video/tegra210.c
> > @@ -1218,4 +1218,5 @@ const struct tegra_csi_soc tegra210_csi_soc = {
> >       .num_clks = ARRAY_SIZE(tegra210_csi_cil_clks),
> >       .tpg_frmrate_table = tegra210_tpg_frmrate_table,
> >       .tpg_frmrate_table_size = ARRAY_SIZE(tegra210_tpg_frmrate_table),
> > +     .has_mipi_calibration = true,
> >  };
>
>
>
>