[PATCH 09/13] uio: uio_pruss: add devicetree support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Add support to probe via devicetree.

Signed-off-by: Andre Heider <a.heider@xxxxxxxxx>
---
 drivers/uio/uio_pruss.c | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
index afaf726..2df54ab 100644
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
@@ -26,6 +26,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/genalloc.h>
+#include <linux/of_device.h>
 
 #define DRV_NAME "pruss_uio"
 #define DRV_VERSION "1.0"
@@ -70,6 +71,27 @@ struct uio_pruss_dev {
 	struct gen_pool *sram_pool;
 };
 
+#ifdef CONFIG_OF
+struct uio_pruss_params {
+	u32 pintc_offset;
+};
+
+static const struct uio_pruss_params uio_pruss_v1_params = {
+	.pintc_offset = 0x4000,
+};
+
+static const struct uio_pruss_params uio_pruss_v2_params = {
+	.pintc_offset = 0x20000,
+};
+
+static const struct of_device_id pruss_of_match_table[] = {
+	{ .compatible = "ti,pruss-v1", .data = &uio_pruss_v1_params, },
+	{ .compatible = "ti,pruss-v2", .data = &uio_pruss_v2_params, },
+	{},
+};
+MODULE_DEVICE_TABLE(of, pruss_of_match_table);
+#endif
+
 static irqreturn_t pruss_handler(int irq, struct uio_info *info)
 {
 	struct uio_pruss_dev *gdev = info->priv;
@@ -111,6 +133,8 @@ static int pruss_probe(struct platform_device *pdev)
 	struct uio_pruss_dev *gdev;
 	struct resource *regs_prussio;
 	struct device *dev = &pdev->dev;
+	const struct of_device_id *match;
+	const struct uio_pruss_params *params;
 	int ret = -ENODEV, cnt = 0, i;
 	struct uio_pruss_pdata *pdata = dev_get_platdata(dev);
 	dma_addr_t ddr_paddr;
@@ -123,13 +147,21 @@ static int pruss_probe(struct platform_device *pdev)
 	if (!gdev->info)
 		return -ENOMEM;
 
-	/* Power on PRU in case its not done as part of boot-loader */
-	gdev->pruss_clk = clk_get(dev, "pruss");
-	if (IS_ERR(gdev->pruss_clk)) {
-		dev_err(dev, "Failed to get clock\n");
-		return PTR_ERR(gdev->pruss_clk);
+	if (dev->of_node) {
+		match = of_match_device(pruss_of_match_table, dev);
+		params = match->data;
+		gdev->pintc_base = params->pintc_offset;
 	} else {
+		/* Power on PRU in case its not done as part of boot-loader */
+		gdev->pruss_clk = clk_get(dev, "pruss");
+		if (IS_ERR(gdev->pruss_clk)) {
+			dev_err(dev, "Failed to get clock\n");
+			return PTR_ERR(gdev->pruss_clk);
+		}
+
 		clk_enable(gdev->pruss_clk);
+
+		gdev->pintc_base = pdata->pintc_base;
 	}
 
 	regs_prussio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -139,7 +171,7 @@ static int pruss_probe(struct platform_device *pdev)
 		goto out_free;
 	}
 
-	if (pdata->sram_pool) {
+	if (pdata && pdata->sram_pool) {
 		gdev->sram_pool = pdata->sram_pool;
 		gdev->sram_vaddr =
 			(unsigned long)gen_pool_dma_alloc(gdev->sram_pool,
@@ -156,7 +188,6 @@ static int pruss_probe(struct platform_device *pdev)
 		goto out_free;
 	}
 
-	gdev->pintc_base = pdata->pintc_base;
 	gdev->hostirq_start = platform_get_irq(pdev, 0);
 
 	for (cnt = 0, p = gdev->info; cnt < MAX_PRUSS_EVT; cnt++, p++) {
@@ -214,6 +245,7 @@ static struct platform_driver pruss_driver = {
 	.driver = {
 		   .name = DRV_NAME,
 		   .owner = THIS_MODULE,
+		   .of_match_table = of_match_ptr(pruss_of_match_table),
 		   },
 };
 
-- 
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]
  Powered by Linux