Skip to contentSkip to conversation

drivers: dma: altera-msgdma: add OF support

PATCH Superseded Olivier Dautricourt 2 participants 2 messages Apr 28, 2021 – Apr 29, 2021

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 drivers: dma: altera-msgdma: add OF support

This driver had no device tree support.

- add compatible field "altr,msgdma"
- define msgdma_of_xlate, with no argument
- register dma controller with of_dma_controller_register

---
 drivers/dma/altera-msgdma.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/dma/altera-msgdma.c +29 -0
index 9a841ce5f0c5..2b062d5aa636 100644
@@ -19,6 +19,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
+#include <linux/of_dma.h>
 
 #include "dmaengine.h"
 
@@ -784,6 +785,16 @@ static int request_and_map(struct platform_device *pdev, const char *name,
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static struct dma_chan *msgdma_of_xlate(struct of_phandle_args *dma_spec,
+					struct of_dma *ofdma)
+{
+	struct msgdma_device *d = ofdma->of_dma_data;
+
+	return dma_get_any_slave_channel(&d->dmadev);
+}
+#endif
+
 /**
  * msgdma_probe - Driver probe function
  * @pdev: Pointer to the platform_device structure
@@ -888,6 +899,14 @@ static int msgdma_probe(struct platform_device *pdev)
 	if (ret)
 		goto fail;
 
+#ifdef CONFIG_OF
+	ret = of_dma_controller_register(pdev->dev.of_node, msgdma_of_xlate,
+					 mdev);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register dma controller");
+		goto fail;
+	}
+#endif
 	dev_notice(&pdev->dev, "Altera mSGDMA driver probe success\n");
 
 	return 0;
@@ -916,9 +935,19 @@ static int msgdma_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id msgdma_match[] = {
+	{ .compatible = "altr,msgdma",},
+	{ }
+};
+
+MODULE_DEVICE_TABLE(of, msgdma_match);
+#endif
+
 static struct platform_driver msgdma_driver = {
 	.driver = {
 		.name = "altera-msgdma",
+		.of_match_table = of_match_ptr(msgdma_match),
 	},
 	.probe = msgdma_probe,
 	.remove = msgdma_remove,

--
2.31.0.rc2

reviewer
#1 lore raw
Quoted 26 lines · Olivier Dautricourt

This driver had no device tree support.

- add compatible field "altr,msgdma"
- define msgdma_of_xlate, with no argument
- register dma controller with of_dma_controller_register

---
  drivers/dma/altera-msgdma.c | 29 +++++++++++++++++++++++++++++
  1 file changed, 29 insertions(+)
drivers/dma/altera-msgdma.c +1 -0
index 9a841ce5f0c5..2b062d5aa636 100644
@@ -19,6 +19,7 @@
  #include <linux/module.h>
  #include <linux/platform_device.h>
  #include <linux/slab.h>
+#include <linux/of_dma.h>
 
  #include "dmaengine.h"
 
@@ -784,6 +785,16 @@ static int request_and_map(struct platform_device *pdev, const char *name,
  	return 0;
  }

drivers/dma/altera-msgdma.c static int request_and_map(struct platform_device *pdev, const char *name, · line 796

Quoted 10 lines
drivers/dma/altera-msgdma.c +9 -0
 
+#ifdef CONFIG_OF
+static struct dma_chan *msgdma_of_xlate(struct of_phandle_args *dma_spec,
+					struct of_dma *ofdma)
+{
+	struct msgdma_device *d = ofdma->of_dma_data;
+
+	return dma_get_any_slave_channel(&d->dmadev);
+}
+#endif

To avoid the ugly #ifdef's, could you add this function unconditionally and ...

Quoted 6 lines
drivers/dma/altera-msgdma.c +1 -0
+
  /**
   * msgdma_probe - Driver probe function
   * @pdev: Pointer to the platform_device structure
@@ -888,6 +899,14 @@ static int msgdma_probe(struct platform_device *pdev)
  	if (ret)

drivers/dma/altera-msgdma.c static int msgdma_probe(struct platform_device *pdev) · line 909

Quoted 10 lines
drivers/dma/altera-msgdma.c +8 -0
  		goto fail;
 
+#ifdef CONFIG_OF
+	ret = of_dma_controller_register(pdev->dev.of_node, msgdma_of_xlate,
+					 mdev);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to register dma controller");
+		goto fail;
+	}
+#endif

... use:

	if (IS_ENABLED(CONFIG_OF)) {
		ret = of_dma_controller_register(pdev->dev.of_node,
		...

here?

Quoted 6 lines
drivers/dma/altera-msgdma.c +0 -0
  	dev_notice(&pdev->dev, "Altera mSGDMA driver probe success\n");
 
  	return 0;
@@ -916,9 +935,19 @@ static int msgdma_remove(struct platform_device *pdev)
  	return 0;
  }

drivers/dma/altera-msgdma.c static int msgdma_remove(struct platform_device *pdev) · line 946

Quoted 10 lines
drivers/dma/altera-msgdma.c +9 -0
 
+#ifdef CONFIG_OF
+static const struct of_device_id msgdma_match[] = {
+	{ .compatible = "altr,msgdma",},
+	{ }
+};
+
+MODULE_DEVICE_TABLE(of, msgdma_match);
+#endif
+

I think this also can be included unconditionally.

Thanks,
Stefan

Quoted 10 lines
drivers/dma/altera-msgdma.c +1 -1
  static struct platform_driver msgdma_driver = {
  	.driver = {
  		.name = "altera-msgdma",
+		.of_match_table = of_match_ptr(msgdma_match),
  	},
  	.probe = msgdma_probe,
  	.remove = msgdma_remove,
--

2.31.0.rc2