Skip to contentSkip to conversation

media: m2m-deinterlace: add device-tree support

PATCH Superseded Matthew Majewski 3 participants 8 messages Feb 12, 2025 – Feb 18, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover media: m2m-deinterlace: add device-tree support

Hello all, this patch series adds device-tree support for the generic m2m-deinterlace driver.

A specific dma controller channel can now be provided to the driver via the dt, but the driver still supports the original dma query if an of_node is not present. This should preserve backwards compatibility with platform drivers that directly instantiate the device.

Probing the m2m-deinterlace device via device-tree was tested on the BeagleBone Black with an m2m-appropriate edma channel.

Best,

Matthew Majewski

Matthew Majewski (2):
media: dt-bindings: Add dt bindings for m2m-deinterlace device
media: m2m-deinterlace: add device-tree support

 .../bindings/media/m2m-deinterlace.yaml       | 41 +++++++++++++++++++
 drivers/media/platform/m2m-deinterlace.c      | 25 ++++++++---
 2 files changed, 60 insertions(+), 6 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/m2m-deinterlace.yaml
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 media: dt-bindings: Add dt bindings for m2m-deinterlace device

Create a new yaml schema file to describe the device tree bindings for the generic m2m-deinterlace driver.

---
 .../bindings/media/m2m-deinterlace.yaml       | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/m2m-deinterlace.yaml
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +41 -0
new file mode 100644
index 000000000000..3ac9c1e7be88
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/m2m-deinterlace.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: M2M Deinterlacer
+
+maintainers:
+ - Mauro Carvalho Chehab <[email protected]>
+
+description: |
+  A generic memory2memory device for deinterlacing video
+  using dmaengine.
+
+properties:
+  compatible:
+    const: m2m-deinterlace
+
+  dma-names:
+    items:
+      - const: rxtx
+
+  dmas:
+    items:
+      - description: mem-to-mem capable DMA channel
+
+required:
+  - compatible
+  - dma-names
+  - dmas
+
+additionalProperties: false
+
+examples:
+  - |
+    m2m-deinterlace {
+        compatible = "m2m-deinterlace";
+        dma-names = "rxtx";
+        dmas = <&edma 20 0>;
+    };
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] media: dt-bindings: Add dt bindings for m2m-deinterlace device

Quoted 2 lines · Matthew Majewski

Create a new yaml schema file to describe the device tree bindings for the generic m2m-deinterlace driver.

Bindings are for hardware, not drivers, and usually not generic.

Please describe here exemplary devices.

Quoted 17 lines
---
 .../bindings/media/m2m-deinterlace.yaml       | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/m2m-deinterlace.yaml
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +4 -0
new file mode 100644
index 000000000000..3ac9c1e7be88
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/media/m2m-deinterlace.yaml#

Documentation/devicetree/bindings/media/m2m-deinterlace.yaml line 14

Quoted 10 lines
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +10 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: M2M Deinterlacer
+
+maintainers:
+ - Mauro Carvalho Chehab <[email protected]>
+
+description: |
+  A generic memory2memory device for deinterlacing video
+  using dmaengine.

And what is this generic device supposed to do? What fits to generic device?

Quoted 16 lines
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +16 -0
+
+properties:
+  compatible:
+    const: m2m-deinterlace
+
+  dma-names:
+    items:
+      - const: rxtx
+
+  dmas:
+    items:
+      - description: mem-to-mem capable DMA channel
+
+required:
+  - compatible
+  - dma-names

Documentation/devicetree/bindings/media/m2m-deinterlace.yaml line 40

Quoted 10 lines
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +10 -0
+  - dmas
+
+additionalProperties: false
+
+examples:
+  - |
+    m2m-deinterlace {
+        compatible = "m2m-deinterlace";
+        dma-names = "rxtx";
+        dmas = <&edma 20 0>;

This all looks rather like bindings for driver and not even quite generic because looks quite simple. I guess media folks will provide more input, but anyway it looks a bit not-DT-enough.

Documentation/devicetree/bindings/media/m2m-deinterlace.yaml line 41

Quoted 1 line
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +1 -0
+    };

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/2] media: dt-bindings: Add dt bindings for m2m-deinterlace device

Hi Krzysztof, thanks for the quick feedback.

Quoted 8 lines · Krzysztof Kozlowski
Quoted 3 lines · Matthew Majewski

Create a new yaml schema file to describe the device tree bindings for
the generic m2m-deinterlace driver.

Bindings are for hardware, not drivers, and usually not generic.

Ok, I'll change the wording from "driver" to "device" in V2.

Quoted 1 line

Please describe here exemplary devices.

The m2m-deinterlace device can be used on any hardware that provides a MEM_TO_MEM and interleaved capable dma channel. I'll note that in the commit message for V2 as well.

Quoted 8 lines
Quoted 4 lines

+description: |
+  A generic memory2memory device for deinterlacing video +  using dmaengine.

And what is this generic device supposed to do? What fits to generic device?

The term "generic" was taken from the driver description. It's generic insofar as it only relies on the dmaengine API for processing (and hence is relatively platform agnostic).

I will add more information about the device in the description for V2. I'll also mention that it's intended for converting between interlaced and non-interlaced formats by line-doubling.

Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +23 -0
+
+properties:
+  compatible:
+    const: m2m-deinterlace
+
+  dma-names:
+    items:
+      - const: rxtx
+
+  dmas:
+    items:
+      - description: mem-to-mem capable DMA channel
+
+required:
+  - compatible
+  - dma-names
+  - dmas
+
+additionalProperties: false
+
+examples:
+  - |
+    m2m-deinterlace {
Quoted 10 lines
Quoted 3 lines

+        compatible = "m2m-deinterlace";
+        dma-names = "rxtx";
+        dmas = <&edma 20 0>;

This all looks rather like bindings for driver and not even quite generic because looks quite simple. I guess media folks will provide more input, but anyway it looks a bit not-DT-enough.

Quoted 1 line

+    };

Yes, the bindings are much simpler than a typical media device, but that is because the m2m-deinterlace device only needs to be provided a handle to a dma channel to function properly. My reasoning for adding dt-bindings for this device is because it is a consumer of a dma- channel and the dt bindings are a platform-agnostic way to be able to provide a specific dma channel to the device.

As an example, say on an embedded device I have a dma controller which provides multiple interleaved MEM_TO_MEM capable channels. I want the m2m-deinterlace device to consume one particular channel because it is higher-priority than the others. With these dt-bindings I can simply specify the correct dma channel that should be used. Without the device-tree bindings I would have to manually edit the driver to filter for the correct dma channel to be used, but then the device is no longer "generic".

It would be helpful to hear what the media people have to say about it. The m2m-deinterlace device is a bit of an edge-case since it's not quite a "virtual" device since it relies on the presence of specific dma hardware. However, it doesn't follow the typical conventions of any other in-tree media driver that consumes a dma channel, which all seem to have dt-bindings.

Best,
Matthew

#4 lore raw

Re: [PATCH 1/2] media: dt-bindings: Add dt bindings for m2m-deinterlace device

Quoted 12 lines · Matthew Majewski

Hi Krzysztof, thanks for the quick feedback.

Quoted 8 lines · Krzysztof Kozlowski
Quoted 3 lines · Matthew Majewski

Create a new yaml schema file to describe the device tree bindings for
the generic m2m-deinterlace driver.

Bindings are for hardware, not drivers, and usually not generic.

Quoted 7 lines

Ok, I'll change the wording from "driver" to "device" in V2.

Quoted 1 line

Please describe here exemplary devices.

The m2m-deinterlace device can be used on any hardware that provides a MEM_TO_MEM and interleaved capable dma channel. I'll note that in the commit message for V2 as well.

I asked to give names of actual hardware you are writing bindings for.

Quoted 50 lines
Quoted 9 lines
Quoted 5 lines

+description: |
+  A generic memory2memory device for deinterlacing video +  using dmaengine.

And what is this generic device supposed to do? What fits to generic device?

The term "generic" was taken from the driver description. It's generic insofar as it only relies on the dmaengine API for processing (and hence is relatively platform agnostic).

I will add more information about the device in the description for V2. I'll also mention that it's intended for converting between interlaced and non-interlaced formats by line-doubling.

Quoted 32 lines
Quoted 16 lines
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +16 -0
+
+properties:
+  compatible:
+    const: m2m-deinterlace
+
+  dma-names:
+    items:
+      - const: rxtx
+
+  dmas:
+    items:
+      - description: mem-to-mem capable DMA channel
+
+required:
+  - compatible
+  - dma-names

Documentation/devicetree/bindings/media/m2m-deinterlace.yaml line 40

Quoted 10 lines
Documentation/devicetree/bindings/media/m2m-deinterlace.yaml new file +10 -0
+  - dmas
+
+additionalProperties: false
+
+examples:
+  - |
+    m2m-deinterlace {
+        compatible = "m2m-deinterlace";
+        dma-names = "rxtx";
+        dmas = <&edma 20 0>;

This all looks rather like bindings for driver and not even quite generic because looks quite simple. I guess media folks will provide more input, but anyway it looks a bit not-DT-enough.

Quoted 5 lines
Quoted 1 line
Quoted 1 line

+    };

Yes, the bindings are much simpler than a typical media device, but that is because the m2m-deinterlace device only needs to be provided a handle to a dma channel to function properly. My reasoning for adding

Really only this? How do you reset the device? How do you clock it (or does it come with internal oscillator?) How do you program anything there if there are no resources?

Quoted 6 lines

dt-bindings for this device is because it is a consumer of a dma- channel and the dt bindings are a platform-agnostic way to be able to provide a specific dma channel to the device.

As an example, say on an embedded device I have a dma controller which provides multiple interleaved MEM_TO_MEM capable channels. I want the

I asked about the names already, still nothing.

Quoted 8 lines

m2m-deinterlace device to consume one particular channel because it is higher-priority than the others. With these dt-bindings I can simply specify the correct dma channel that should be used. Without the device-tree bindings I would have to manually edit the driver to filter for the correct dma channel to be used, but then the device is no longer "generic".

It would be helpful to hear what the media people have to say about it.

Then wait before sending new version.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH 1/2] media: dt-bindings: Add dt bindings for m2m-deinterlace device

In reply to Matthew Majewski
Quoted 9 lines · Matthew Majewski

Create a new yaml schema file to describe the device tree bindings for the generic m2m-deinterlace driver.

---
 .../bindings/media/m2m-deinterlace.yaml       | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/m2m-deinterlace.yaml

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:
./Documentation/devicetree/bindings/media/m2m-deinterlace.yaml:10:2: [warning] wrong indentation: expected 2 but found 1 (indentation)

dtschema/dtc warnings/errors:

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]

The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.

#6 lore raw

Re: [PATCH 1/2] media: dt-bindings: Add dt bindings for m2m-deinterlace device

Hi Rob, thanks for the feedback.

Quoted 6 lines · Rob Herring (Arm)

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

Yup, I missed a yaml syntax error and didn't notice because I was missing yamllint and dt_binding_check came back ok. Will fix for V2... thanks again.

Best,
Matthew

#7 lore raw

PATCH 2/2 media: m2m-deinterlace: add device-tree support

In reply to Matthew Majewski

Add support for loading the m2m-deinterlace driver through the device-tree.

Prefer to query the dma device through dma_request_chan(), which will get the dma device information from the device-tree node if present. Otherwise, fall back to the original dma_request_channel() to preserve backwards compatibility.

---
 drivers/media/platform/m2m-deinterlace.c | 25 ++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/media/platform/m2m-deinterlace.c +19 -6
index 5188f3189096..ba4e4ee6ad34 100644
@@ -11,6 +11,7 @@
 #include <linux/interrupt.h>
 #include <linux/dmaengine.h>
 #include <linux/platform_device.h>
+#include <linux/module.h>
 
 #include <media/v4l2-mem2mem.h>
 #include <media/v4l2-device.h>
@@ -914,7 +915,6 @@ static int deinterlace_probe(struct platform_device *pdev)
 {
 	struct deinterlace_dev *pcdev;
 	struct video_device *vfd;
-	dma_cap_mask_t mask;
 	int ret = 0;
 
 	pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
@@ -923,9 +923,16 @@ static int deinterlace_probe(struct platform_device *pdev)
 
 	spin_lock_init(&pcdev->irqlock);
 
-	dma_cap_zero(mask);
-	dma_cap_set(DMA_INTERLEAVE, mask);
-	pcdev->dma_chan = dma_request_channel(mask, NULL, pcdev);
+	if (pdev->dev.of_node) {
+		pcdev->dma_chan = dma_request_chan(&pdev->dev, "rxtx");
+	} else {
+		dma_cap_mask_t mask;
+
+		dma_cap_zero(mask);
+		dma_cap_set(DMA_INTERLEAVE, mask);
+		pcdev->dma_chan = dma_request_channel(mask, NULL, pcdev);
+	}
+
 	if (!pcdev->dma_chan)
 		return -ENODEV;
 
@@ -989,12 +996,18 @@ static void deinterlace_remove(struct platform_device *pdev)
 	dma_release_channel(pcdev->dma_chan);
 }
 
+static const struct of_device_id deinterlace_dt_match[] = {
+	{ .compatible = "m2m-deinterlace" },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, deinterlace_dt_match);
+
 static struct platform_driver deinterlace_pdrv = {
 	.probe		= deinterlace_probe,
 	.remove		= deinterlace_remove,
 	.driver		= {
-		.name	= MEM2MEM_NAME,
+		.name		= MEM2MEM_NAME,
+		.of_match_table = deinterlace_dt_match,
 	},
 };
 module_platform_driver(deinterlace_pdrv);
-
Signature · 1 line
2.25.1