mbox series

[v8,00/16] CSI2RX support on J721E and AM62

Message ID 20230731-upstream_csi-v8-0-fb7d3661c2c9@ti.com
Headers show
Series CSI2RX support on J721E and AM62 | expand

Message

Jai Luthra July 31, 2023, 8:29 a.m. UTC
Hi,

This series adds support for CSI2 capture on J721E. It includes some
fixes to the Cadence CSI2RX driver, and adds the TI CSI2RX wrapper driver.

This is a V8 of the below V7 series,
https://lore.kernel.org/all/20230314115516.667-1-vaishnav.a@ti.com/

Since Pratyush moved out of TI, Vaishnav & I have been working on
this driver, and I will be maintaining it upstream.

J721E CSI2RX driver can also be extended to support multi-stream
capture, filtering different CSI Virtual Channels (VC) or Data Types
(DT) to different DMA channels. A WIP series based on v7 is available
for reference at https://github.com/jailuthra/linux/commits/csi_multi_wip

I will rebase the multi-stream patches on the current series (v8) and
post them as RFC in the coming weeks.

Testing logs: https://gist.github.com/jailuthra/eaeb3af3c65b67e1bc0d5db28180131d

Signed-off-by: Jai Luthra <j-luthra@ti.com>
---

Range-diff from v7 -> v8: http://0x0.st/H21u.diff

New Patches:
[01/16]	   Export v4l2_subdev_link_validate_get_format() helper
[03-04/16] Add new compatible for TI-specific SoC intergration of the
           Cadence CSI2RX bridge IP
[14/16]    Add support for RAW8 and RAW10 formats in Cadence CSI2RX

For [07/16] media: cadence: csi2rx: Add get_fmt and set_fmt pad ops:
- Use active subdev state to use v4l2_subdev_get_fmt
- Propagate formats from sink to source pads
- Drop Laurent's R-by because of the above changes

For [08/16] media: cadence: csi2rx: Configure DPHY using link freq:
- Drop original patch in-lieu of already merged
  https://lore.kernel.org/linux-media/20230523085626.3295-5-jack.zhu@starfivetech.com/
- Add a new patch to configure DPHY using link_freq control from the
  source

For [10/16] media: cadence: csi2rx: Set the STOP bit when stopping a stream:
- Fix bug where intention was to wait till stream status is idle, i.e.
  STREAM_STATUS[31] -> 0 - but we were instead checking the opposite

For [15/16] media: dt-bindings: Add DT bindings for TI J721E CSI2RX driver:
- Drop "Device Tree Bindings" from title
- Rename "Wrapper" to "Shim" in title as that is the name referred in
  the TRM and other places
- Update maintainer to myself
- Drop items from compatible as only a single element is present
- Rename compatible to "ti,j721e-csi2rx-shim" to distinguish from the
  SoC-specific CSI2RX bridge compatible

For [16/16] media: ti: Add CSI2RX support for J721E:
- Move after dt-bindings to keep the series bisectable
- Rename compatible to "ti,j721e-csi2rx-shim" to distinguish from the
  SoC-specific CSI2RX bridge compatible
- Make myself the Maintainer
- Support RAW8 and RAW10 formats, and setting the pixel-unwrap size on
  SHIM (RAW10 is stored in 16-bit containers, while RAW8 in 8-bit containers)
- Fix enum_fmt_vid_cap() to respect CAP_IO_MC and only list pixelformats
  matching the mbus formats set on the subdev.
- Fix enum_framesizes() to stop enumerating more than a single framesize
  (reject non-zero fsize->index)
- Simplify notifier bound fucntion to use v4l2_create_fwnode_links_to_pad()
  and inline the video_register() method
- Add support for draining the DMA with an extra buffer, to get rid of
  stale data in the pipeline on stream stop (or when frames start
  getting dropped due to load)
- Queue all available buffers to DMAEngine in the callback, also use a
  separate "submitted" queue to track all buffers submitted to DMA
- Use video_device_pipeline_start() instead of media_pipeline_start()
- Drop support for VB_READ
- Print issues in link validation as DEBUG instead of ERROR
- s/async_subdev/async_connection

For [v7 13/13] media: dt-bindings: Convert Cadence CSI2RX binding to YAML:
 - Drop patch in-lieu of
   https://lore.kernel.org/linux-media/20230523085626.3295-2-jack.zhu@starfivetech.com/

---
Jai Luthra (4):
      media: subdev: Export get_format helper for link validation
      media: dt-bindings: cadence-csi2rx: Add TI compatible string
      media: cadence: Add support for TI SoCs
      media: cadence: csi2rx: Support RAW8 and RAW10 formats

Pratyush Yadav (12):
      media: dt-bindings: Make sure items in data-lanes are unique
      media: cadence: csi2rx: Unregister v4l2 async notifier
      media: cadence: csi2rx: Cleanup media entity properly
      media: cadence: csi2rx: Add get_fmt and set_fmt pad ops
      media: cadence: csi2rx: Configure DPHY using link freq
      media: cadence: csi2rx: Soft reset the streams before starting capture
      media: cadence: csi2rx: Set the STOP bit when stopping a stream
      media: cadence: csi2rx: Fix stream data configuration
      media: cadence: csi2rx: Populate subdev devnode
      media: cadence: csi2rx: Add link validation
      media: dt-bindings: Add TI J721E CSI2RX
      media: ti: Add CSI2RX support for J721E

 .../devicetree/bindings/media/cdns,csi2rx.yaml     |    1 +
 .../bindings/media/ti,j721e-csi2rx-shim.yaml       |  100 ++
 .../bindings/media/video-interfaces.yaml           |    1 +
 MAINTAINERS                                        |    7 +
 drivers/media/platform/cadence/cdns-csi2rx.c       |  217 +++-
 drivers/media/platform/ti/Kconfig                  |   12 +
 drivers/media/platform/ti/Makefile                 |    1 +
 drivers/media/platform/ti/j721e-csi2rx/Makefile    |    2 +
 .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  | 1127 ++++++++++++++++++++
 drivers/media/v4l2-core/v4l2-subdev.c              |    8 +-
 include/media/v4l2-subdev.h                        |   12 +
 11 files changed, 1478 insertions(+), 10 deletions(-)
---
base-commit: ec89391563792edd11d138a853901bce76d11f44
change-id: 20230727-upstream_csi-acbeabe038d8

Best regards,

Comments

Tomi Valkeinen Aug. 1, 2023, 2:09 p.m. UTC | #1
On 31/07/2023 11:29, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
> 
> The data-lanes property maps the logical lane numbers to the physical
> lane numbers. The position of an entry is the logical lane number and
> its value is the physical lane number. Since one physical lane can only
> map to one logical lane, no number in the list should repeat. Add the
> uniqueItems constraint on the property to enforce this.
> 
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Acked-by: Rob Herring <robh@kernel.org>
> ---
> v7->v8: No change
> 
>   Documentation/devicetree/bindings/media/video-interfaces.yaml | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/media/video-interfaces.yaml b/Documentation/devicetree/bindings/media/video-interfaces.yaml
> index a211d49dc2ac..26e3e7d7c67b 100644
> --- a/Documentation/devicetree/bindings/media/video-interfaces.yaml
> +++ b/Documentation/devicetree/bindings/media/video-interfaces.yaml
> @@ -160,6 +160,7 @@ properties:
>       $ref: /schemas/types.yaml#/definitions/uint32-array
>       minItems: 1
>       maxItems: 8
> +    uniqueItems: true
>       items:
>         # Assume up to 9 physical lane indices
>         maximum: 8
> 

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi
Tomi Valkeinen Aug. 1, 2023, 2:11 p.m. UTC | #2
On 31/07/2023 11:29, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
> 
> Call media_entity_cleanup() in probe error path and remove to make sure
> the media entity is cleaned up properly.
> 
> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> v7->v8: No change
> 
>   drivers/media/platform/cadence/cdns-csi2rx.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index fd6f2e04e77f..83d1fadd592b 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -547,6 +547,7 @@ static int csi2rx_probe(struct platform_device *pdev)
>   err_cleanup:
>   	v4l2_async_nf_unregister(&csi2rx->notifier);
>   	v4l2_async_nf_cleanup(&csi2rx->notifier);
> +	media_entity_cleanup(&csi2rx->subdev.entity);
>   err_free_priv:
>   	kfree(csi2rx);
>   	return ret;
> @@ -559,6 +560,7 @@ static void csi2rx_remove(struct platform_device *pdev)
>   	v4l2_async_nf_unregister(&csi2rx->notifier);
>   	v4l2_async_nf_cleanup(&csi2rx->notifier);
>   	v4l2_async_unregister_subdev(&csi2rx->subdev);
> +	media_entity_cleanup(&csi2rx->subdev.entity);
>   	kfree(csi2rx);
>   }
>   
> 

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi
Tomi Valkeinen Aug. 1, 2023, 2:16 p.m. UTC | #3
On 31/07/2023 11:29, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
> 
> This resets the stream state machines and FIFOs, giving them a clean
> slate. On J721E if the streams are not reset before starting the
> capture, the captured frame gets wrapped around vertically on every run
> after the first.
> 
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> v7->v8: No change
> 
>   drivers/media/platform/cadence/cdns-csi2rx.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index 2a80c66fb547..30cdc260b46a 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -40,6 +40,7 @@
>   #define CSI2RX_STREAM_BASE(n)		(((n) + 1) * 0x100)
>   
>   #define CSI2RX_STREAM_CTRL_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x000)
> +#define CSI2RX_STREAM_CTRL_SOFT_RST			BIT(4)
>   #define CSI2RX_STREAM_CTRL_START			BIT(0)
>   
>   #define CSI2RX_STREAM_DATA_CFG_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x008)
> @@ -138,12 +139,22 @@ struct csi2rx_priv *v4l2_subdev_to_csi2rx(struct v4l2_subdev *subdev)
>   
>   static void csi2rx_reset(struct csi2rx_priv *csi2rx)
>   {
> +	unsigned int i;
> +
>   	writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,
>   	       csi2rx->base + CSI2RX_SOFT_RESET_REG);
>   
>   	udelay(10);
>   
>   	writel(0, csi2rx->base + CSI2RX_SOFT_RESET_REG);
> +
> +	/* Reset individual streams. */
> +	for (i = 0; i < csi2rx->max_streams; i++) {
> +		writel(CSI2RX_STREAM_CTRL_SOFT_RST,
> +		       csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> +		usleep_range(10, 20);
> +		writel(0, csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> +	}

Do you have to do it like this? Or would it be fine to set the reset bit 
for all stream regs, then sleep, then clear the reset bit from all 
stream regs? Or going even further, can you set the 
CSI2RX_SOFT_RESET_REG and all CSI2RX_STREAM_CTRL_REG regs, then sleep, 
and then clear them all?

  Tomi
Tomi Valkeinen Aug. 1, 2023, 2:18 p.m. UTC | #4
On 31/07/2023 11:29, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
> 
> The devnode can be used by media-ctl and other userspace tools to
> perform configurations on the subdev. Without it, media-ctl returns
> ENOENT when setting format on the sensor subdev.
> 
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> v7->v8: No change
> 
>   drivers/media/platform/cadence/cdns-csi2rx.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index cde7fd6463e1..d82a8938932f 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -678,6 +678,7 @@ static int csi2rx_probe(struct platform_device *pdev)
>   	csi2rx->pads[CSI2RX_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
>   	for (i = CSI2RX_PAD_SOURCE_STREAM0; i < CSI2RX_PAD_MAX; i++)
>   		csi2rx->pads[i].flags = MEDIA_PAD_FL_SOURCE;
> +	csi2rx->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
>   
>   	ret = media_entity_pads_init(&csi2rx->subdev.entity, CSI2RX_PAD_MAX,
>   				     csi2rx->pads);
> 

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi
Tomi Valkeinen Aug. 2, 2023, 9:41 a.m. UTC | #5
On 31/07/2023 11:29, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
> 
> Some platforms like TI's J721E can have the CSI2RX paired with an
> external DPHY. Use the generic PHY framework to configure the DPHY with
> the correct link frequency.
> 
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Co-authored-by: Jai Luthra <j-luthra@ti.com>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> v7->v8
> - Drop original patch in-lieu of already merged
>    https://lore.kernel.org/linux-media/20230523085626.3295-5-jack.zhu@starfivetech.com/
> - Add a new patch to configure DPHY using link_freq control from the
>    source
> 
>   drivers/media/platform/cadence/cdns-csi2rx.c | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index 4f9654366485..2a80c66fb547 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -149,8 +149,33 @@ static void csi2rx_reset(struct csi2rx_priv *csi2rx)
>   static int csi2rx_configure_ext_dphy(struct csi2rx_priv *csi2rx)
>   {
>   	union phy_configure_opts opts = { };
> +	struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy;
> +	struct v4l2_subdev_format sd_fmt = {
> +		.which	= V4L2_SUBDEV_FORMAT_ACTIVE,
> +		.pad	= CSI2RX_PAD_SINK,
> +		.stream	= 0,

I would drop the above line, as this doesn't support streams yet.

> +	};
> +	const struct csi2rx_fmt *fmt;
> +	s64 link_freq;
>   	int ret;
>   
> +	ret = v4l2_subdev_call_state_active(&csi2rx->subdev, pad, get_fmt,
> +					    &sd_fmt);
> +	if (ret < 0)
> +		return ret;
> +
> +	fmt = csi2rx_get_fmt_by_code(sd_fmt.format.code);
> +
> +	link_freq = v4l2_get_link_freq(csi2rx->source_subdev->ctrl_handler,
> +				       fmt->bpp, 2 * csi2rx->num_lanes);
> +	if (link_freq < 0)
> +		return link_freq;
> +
> +	ret = phy_mipi_dphy_get_default_config_for_hsclk(link_freq,
> +							 csi2rx->num_lanes, cfg);
> +	if (ret)
> +		return ret;
> +
>   	ret = phy_power_on(csi2rx->dphy);
>   	if (ret)
>   		return ret;
> 

I think this is fine, but a few things to think about:

Here you lock and unlock the active state for the duration of the 
get_fmt call (and you call it for this same subdev). If the driver 
supports active state, and you need to get the fmt of the driver's 
subdev, I think it usually makes more sense to just use the state and 
get the format from there.

And you might want to keep the active state locked for the duration of 
the s_stream operation, in which case the state would already be locked 
when csi2rx_configure_ext_dphy() gets called.

And if you implement enable_streams/disable_streams, then the state has 
already been locked by the framework. However, I think 
enable_streams/disable_streams only works if the driver actually 
supports streams.

But maybe you have already done all these with the out-of-tree streams 
support?

Anyway, I think this is fine for now:

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi
Tomi Valkeinen Aug. 2, 2023, 9:45 a.m. UTC | #6
On 31/07/2023 11:29, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
> 
> The stream stop procedure says that the STOP bit should be set when the
> stream is to be stopped, and then the ready bit in stream status
> register polled to make sure the STOP operation is finished.
> 
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> v7->v8:
> - Fix bug where intention was to wait till stream status is idle, i.e.
>    STREAM_STATUS[31] -> 0 - but we were instead checking the opposite
> 
>   drivers/media/platform/cadence/cdns-csi2rx.c | 18 +++++++++++++++++-
>   1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index 30cdc260b46a..a17ef88dff82 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -8,6 +8,7 @@
>   #include <linux/clk.h>
>   #include <linux/delay.h>
>   #include <linux/io.h>
> +#include <linux/iopoll.h>
>   #include <linux/module.h>
>   #include <linux/of.h>
>   #include <linux/of_graph.h>
> @@ -41,8 +42,12 @@
>   
>   #define CSI2RX_STREAM_CTRL_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x000)
>   #define CSI2RX_STREAM_CTRL_SOFT_RST			BIT(4)
> +#define CSI2RX_STREAM_CTRL_STOP				BIT(1)
>   #define CSI2RX_STREAM_CTRL_START			BIT(0)
>   
> +#define CSI2RX_STREAM_STATUS_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x004)
> +#define CSI2RX_STREAM_STATUS_RDY			BIT(31)
> +
>   #define CSI2RX_STREAM_DATA_CFG_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x008)
>   #define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT		BIT(31)
>   #define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n)		BIT((n) + 16)
> @@ -314,13 +319,24 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
>   static void csi2rx_stop(struct csi2rx_priv *csi2rx)
>   {
>   	unsigned int i;
> +	u32 val;
> +	int ret;
>   
>   	clk_prepare_enable(csi2rx->p_clk);
>   	reset_control_assert(csi2rx->sys_rst);
>   	clk_disable_unprepare(csi2rx->sys_clk);
>   
>   	for (i = 0; i < csi2rx->max_streams; i++) {
> -		writel(0, csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> +		writel(CSI2RX_STREAM_CTRL_STOP,
> +		       csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> +
> +		ret = readl_relaxed_poll_timeout(csi2rx->base +
> +						 CSI2RX_STREAM_STATUS_REG(i),
> +						 val,
> +						 !(val & CSI2RX_STREAM_STATUS_RDY),
> +						 10, 10000);
> +		if (ret)
> +			dev_warn(csi2rx->dev, "Failed to stop stream%u\n", i);

When adding streams support, I think the driver might need some 
adjustments. E.g. above says that e.g. stopping stream2 failed, which 
will be quite confusing as the reader probably thinks it refers to the 
"logical" streams. It would be helpful if it was always clear which of 
the streams the driver refers to (in prints, but also in code).

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi
Tomi Valkeinen Aug. 2, 2023, 9:46 a.m. UTC | #7
On 31/07/2023 11:29, Jai Luthra wrote:
> Many CSI-2 sensors (specifically IMX219) send RAW bayer data instead of
> processed YUV or RGB, so add support for 8-bit and 10-bit bayer formats.
> 
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> ---
> New in v8
> 
>   drivers/media/platform/cadence/cdns-csi2rx.c | 32 ++++++++++++++++++++++++++++
>   1 file changed, 32 insertions(+)
> 
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index aec33d28a66f..bac74474841a 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -122,6 +122,38 @@ static const struct csi2rx_fmt formats[] = {
>   		.code	= MEDIA_BUS_FMT_VYUY8_1X16,
>   		.bpp	= 16,
>   	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SBGGR8_1X8,
> +		.bpp	= 8,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SGBRG8_1X8,
> +		.bpp	= 8,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SGRBG8_1X8,
> +		.bpp	= 8,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SRGGB8_1X8,
> +		.bpp	= 8,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SBGGR10_1X10,
> +		.bpp	= 10,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SGBRG10_1X10,
> +		.bpp	= 10,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SGRBG10_1X10,
> +		.bpp	= 10,
> +	},
> +	{
> +		.code	= MEDIA_BUS_FMT_SRGGB10_1X10,
> +		.bpp	= 10,
> +	},
>   };
>   
>   static const struct csi2rx_fmt *csi2rx_get_fmt_by_code(u32 code)
> 

Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>

  Tomi
Jai Luthra Aug. 3, 2023, 11:19 a.m. UTC | #8
On Aug 01, 2023 at 17:16:41 +0300, Tomi Valkeinen wrote:
> On 31/07/2023 11:29, Jai Luthra wrote:
> > From: Pratyush Yadav <p.yadav@ti.com>
> > 
> > This resets the stream state machines and FIFOs, giving them a clean
> > slate. On J721E if the streams are not reset before starting the
> > capture, the captured frame gets wrapped around vertically on every run
> > after the first.
> > 
> > Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> > Signed-off-by: Jai Luthra <j-luthra@ti.com>
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> > v7->v8: No change
> > 
> >   drivers/media/platform/cadence/cdns-csi2rx.c | 11 +++++++++++
> >   1 file changed, 11 insertions(+)
> > 
> > diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> > index 2a80c66fb547..30cdc260b46a 100644
> > --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> > +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> > @@ -40,6 +40,7 @@
> >   #define CSI2RX_STREAM_BASE(n)		(((n) + 1) * 0x100)
> >   #define CSI2RX_STREAM_CTRL_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x000)
> > +#define CSI2RX_STREAM_CTRL_SOFT_RST			BIT(4)
> >   #define CSI2RX_STREAM_CTRL_START			BIT(0)
> >   #define CSI2RX_STREAM_DATA_CFG_REG(n)		(CSI2RX_STREAM_BASE(n) + 0x008)
> > @@ -138,12 +139,22 @@ struct csi2rx_priv *v4l2_subdev_to_csi2rx(struct v4l2_subdev *subdev)
> >   static void csi2rx_reset(struct csi2rx_priv *csi2rx)
> >   {
> > +	unsigned int i;
> > +
> >   	writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT,
> >   	       csi2rx->base + CSI2RX_SOFT_RESET_REG);
> >   	udelay(10);
> >   	writel(0, csi2rx->base + CSI2RX_SOFT_RESET_REG);
> > +
> > +	/* Reset individual streams. */
> > +	for (i = 0; i < csi2rx->max_streams; i++) {
> > +		writel(CSI2RX_STREAM_CTRL_SOFT_RST,
> > +		       csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> > +		usleep_range(10, 20);
> > +		writel(0, csi2rx->base + CSI2RX_STREAM_CTRL_REG(i));
> > +	}
> 
> Do you have to do it like this? Or would it be fine to set the reset bit for
> all stream regs, then sleep, then clear the reset bit from all stream regs?
> Or going even further, can you set the CSI2RX_SOFT_RESET_REG and all
> CSI2RX_STREAM_CTRL_REG regs, then sleep, and then clear them all?

You're right I think that should work, and would be much cleaner. Will 
fix.

> 
>  Tomi
>
Vaishnav Achath Aug. 8, 2023, 10:55 p.m. UTC | #9
On 31/07/23 13:59, Jai Luthra wrote:
> Hi,
> 
> This series adds support for CSI2 capture on J721E. It includes some
> fixes to the Cadence CSI2RX driver, and adds the TI CSI2RX wrapper driver.
> 
> This is a V8 of the below V7 series,
> https://lore.kernel.org/all/20230314115516.667-1-vaishnav.a@ti.com/
> 
> Since Pratyush moved out of TI, Vaishnav & I have been working on
> this driver, and I will be maintaining it upstream.
> 
> J721E CSI2RX driver can also be extended to support multi-stream
> capture, filtering different CSI Virtual Channels (VC) or Data Types
> (DT) to different DMA channels. A WIP series based on v7 is available
> for reference at https://github.com/jailuthra/linux/commits/csi_multi_wip
> 
> I will rebase the multi-stream patches on the current series (v8) and
> post them as RFC in the coming weeks.
> 
> Testing logs: https://gist.github.com/jailuthra/eaeb3af3c65b67e1bc0d5db28180131d
> 

Hi Jai,

Thank you for the series,

Tested the series for capture with OV5640 (LI-OV5640 module) on J721E EVM,
Logs and captured images available here:
https://gist.github.com/vaishnavachath/0b70bc5aaef6a3a88be4900979c788d6

Tested-by: Vaishnav Achath <vaishnav.a@ti.com>

Thanks and Regards,
Vaishnav

> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> ---
> 
> Range-diff from v7 -> v8: http://0x0.st/H21u.diff
> 
> New Patches:
> [01/16]	   Export v4l2_subdev_link_validate_get_format() helper
> [03-04/16] Add new compatible for TI-specific SoC intergration of the
>            Cadence CSI2RX bridge IP
> [14/16]    Add support for RAW8 and RAW10 formats in Cadence CSI2RX
> 
> For [07/16] media: cadence: csi2rx: Add get_fmt and set_fmt pad ops:
> - Use active subdev state to use v4l2_subdev_get_fmt
> - Propagate formats from sink to source pads
> - Drop Laurent's R-by because of the above changes
> 
> For [08/16] media: cadence: csi2rx: Configure DPHY using link freq:
> - Drop original patch in-lieu of already merged
>   https://lore.kernel.org/linux-media/20230523085626.3295-5-jack.zhu@starfivetech.com/
> - Add a new patch to configure DPHY using link_freq control from the
>   source
> 
> For [10/16] media: cadence: csi2rx: Set the STOP bit when stopping a stream:
> - Fix bug where intention was to wait till stream status is idle, i.e.
>   STREAM_STATUS[31] -> 0 - but we were instead checking the opposite
> 
> For [15/16] media: dt-bindings: Add DT bindings for TI J721E CSI2RX driver:
> - Drop "Device Tree Bindings" from title
> - Rename "Wrapper" to "Shim" in title as that is the name referred in
>   the TRM and other places
> - Update maintainer to myself
> - Drop items from compatible as only a single element is present
> - Rename compatible to "ti,j721e-csi2rx-shim" to distinguish from the
>   SoC-specific CSI2RX bridge compatible
> 
> For [16/16] media: ti: Add CSI2RX support for J721E:
> - Move after dt-bindings to keep the series bisectable
> - Rename compatible to "ti,j721e-csi2rx-shim" to distinguish from the
>   SoC-specific CSI2RX bridge compatible
> - Make myself the Maintainer
> - Support RAW8 and RAW10 formats, and setting the pixel-unwrap size on
>   SHIM (RAW10 is stored in 16-bit containers, while RAW8 in 8-bit containers)
> - Fix enum_fmt_vid_cap() to respect CAP_IO_MC and only list pixelformats
>   matching the mbus formats set on the subdev.
> - Fix enum_framesizes() to stop enumerating more than a single framesize
>   (reject non-zero fsize->index)
> - Simplify notifier bound fucntion to use v4l2_create_fwnode_links_to_pad()
>   and inline the video_register() method
> - Add support for draining the DMA with an extra buffer, to get rid of
>   stale data in the pipeline on stream stop (or when frames start
>   getting dropped due to load)
> - Queue all available buffers to DMAEngine in the callback, also use a
>   separate "submitted" queue to track all buffers submitted to DMA
> - Use video_device_pipeline_start() instead of media_pipeline_start()
> - Drop support for VB_READ
> - Print issues in link validation as DEBUG instead of ERROR
> - s/async_subdev/async_connection
> 
> For [v7 13/13] media: dt-bindings: Convert Cadence CSI2RX binding to YAML:
>  - Drop patch in-lieu of
>    https://lore.kernel.org/linux-media/20230523085626.3295-2-jack.zhu@starfivetech.com/
> 
> ---
> Jai Luthra (4):
>       media: subdev: Export get_format helper for link validation
>       media: dt-bindings: cadence-csi2rx: Add TI compatible string
>       media: cadence: Add support for TI SoCs
>       media: cadence: csi2rx: Support RAW8 and RAW10 formats
> 
> Pratyush Yadav (12):
>       media: dt-bindings: Make sure items in data-lanes are unique
>       media: cadence: csi2rx: Unregister v4l2 async notifier
>       media: cadence: csi2rx: Cleanup media entity properly
>       media: cadence: csi2rx: Add get_fmt and set_fmt pad ops
>       media: cadence: csi2rx: Configure DPHY using link freq
>       media: cadence: csi2rx: Soft reset the streams before starting capture
>       media: cadence: csi2rx: Set the STOP bit when stopping a stream
>       media: cadence: csi2rx: Fix stream data configuration
>       media: cadence: csi2rx: Populate subdev devnode
>       media: cadence: csi2rx: Add link validation
>       media: dt-bindings: Add TI J721E CSI2RX
>       media: ti: Add CSI2RX support for J721E
> 
>  .../devicetree/bindings/media/cdns,csi2rx.yaml     |    1 +
>  .../bindings/media/ti,j721e-csi2rx-shim.yaml       |  100 ++
>  .../bindings/media/video-interfaces.yaml           |    1 +
>  MAINTAINERS                                        |    7 +
>  drivers/media/platform/cadence/cdns-csi2rx.c       |  217 +++-
>  drivers/media/platform/ti/Kconfig                  |   12 +
>  drivers/media/platform/ti/Makefile                 |    1 +
>  drivers/media/platform/ti/j721e-csi2rx/Makefile    |    2 +
>  .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  | 1127 ++++++++++++++++++++
>  drivers/media/v4l2-core/v4l2-subdev.c              |    8 +-
>  include/media/v4l2-subdev.h                        |   12 +
>  11 files changed, 1478 insertions(+), 10 deletions(-)
> ---
> base-commit: ec89391563792edd11d138a853901bce76d11f44
> change-id: 20230727-upstream_csi-acbeabe038d8
> 
> Best regards,