Signed-off-by: Robert Tivy <[email protected]>
---
 drivers/remoteproc/Kconfig              |   31 ++++
 drivers/remoteproc/Makefile             |    1 +
 drivers/remoteproc/davinci_remoteproc.c |  282 +++++++++++++++++++++++++++++++
 3 files changed, 314 insertions(+)
 create mode 100644 drivers/remoteproc/davinci_remoteproc.c

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index f8d818a..8bc1622 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -27,4 +27,35 @@ config OMAP_REMOTEPROC
          It's safe to say n here if you're not interested in multimedia
          offloading or just want a bare minimum kernel.
 
+config DAVINCI_REMOTEPROC
+       tristate "DaVinci DA850/OMAPL138 remoteproc support"
+       depends on EXPERIMENTAL
+       depends on ARCH_DAVINCI_DA850
+       select REMOTEPROC
+       select RPMSG
+       select FW_LOADER
+       default y
+       help
+         Say y here to support DaVinci DA850/OMAPL138 remote processors
+         via the remote processor framework.
+
+         Usually you want to say y here, in order to enable AMP
+         use-cases to run on your platform (multimedia codecs are
+         offloaded to remote DSP processors using this framework).
+
+         It's safe to say n here if you're not interested in multimedia
+         offloading or just want a bare minimum kernel.
+
+# Amount of CMA memory to reserve for Davinci's DSP sub-system.
+# We need quite much. Fortunately, CMA makes sure this memory isn't
+# wasted in case we're not loading the remote processors.
+config DAVINCI_DSP_CMA_SIZE
+       hex "DSP physically contiguous memory pool size (in bytes)"
+       depends on DAVINCI_REMOTEPROC
+       default 0x2000000
+       help
+         Allocate a specified size of physically contiguous memory (CMA)
+         for Davinci's DSP sub-system. Vast majority of this memory isn't
+         wasted in case the DSP sub-system isn't loaded.
+
 endmenu
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 5445d9b..10d5a81 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -7,3 +7,4 @@ remoteproc-y                            := remoteproc_core.o
 remoteproc-y                           += remoteproc_debugfs.o
 remoteproc-y                           += remoteproc_virtio.o
 obj-$(CONFIG_OMAP_REMOTEPROC)          += omap_remoteproc.o
+obj-$(CONFIG_DAVINCI_REMOTEPROC)       += davinci_remoteproc.o
diff --git a/drivers/remoteproc/davinci_remoteproc.c 
b/drivers/remoteproc/davinci_remoteproc.c
new file mode 100644
index 0000000..e445698
--- /dev/null
+++ b/drivers/remoteproc/davinci_remoteproc.c
@@ -0,0 +1,282 @@
+/*
+ * Remote processor machine-specific module for Davinci
+ *
+ * Copyright (C) 2011-2012 Texas Instruments, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#define pr_fmt(fmt)    "%s: " fmt, __func__
+
+#include <linux/kernel.h>
+#include <linux/err.h>
+#include <linux/printk.h>
+#include <linux/bitops.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc.h>
+#include <linux/platform_data/da8xx-remoteproc.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/irq.h>
+
+#include <mach/da8xx.h>   /* for DA8XX_SYSCFG0_BASE */
+#include <mach/common.h>  /* for davinci_soc_info */
+#include <mach/psc.h>     /* for some offset #defines */
+
+#include "remoteproc_internal.h"
+
+/*
+ * OMAP-L138 Technical References:
+ * http://www.ti.com/product/omap-l138
+ */
+
+/* next state bits in MDCTL15 register (section 9.6.18) */
+#define NEXT_ENABLED 0x3
+
+#define SYSCFG_CHIPSIG_OFFSET 0x174
+#define SYSCFG_CHIPSIG_CLR_OFFSET 0x178
+#define SYSCFG_CHIPINT0 (1 << 0)
+#define SYSCFG_CHIPINT1 (1 << 1)
+#define SYSCFG_CHIPINT2 (1 << 2)
+#define SYSCFG_CHIPINT3 (1 << 3)
+
+/**
+ * struct davinci_rproc - davinci remote processor state
+ * @rproc: rproc handle
+ */
+struct davinci_rproc {
+       struct rproc *rproc;
+       struct clk *dsp_clk;
+};
+
+static void __iomem *syscfg0_base;
+static struct platform_device *remoteprocdev;
+static struct irq_data *irq_data;
+static void (*ack_fxn)(struct irq_data *data);
+static int irq;
+static int host1cfg_offset;
+
+/**
+ * handle_event() - inbound virtqueue message workqueue function
+ *
+ * This funciton is registered with 'workqueue' and is scheduled by the
+ * ISR handler.
+ */
+static irqreturn_t handle_event(int irq, void *p)
+{
+       struct rproc *rproc = platform_get_drvdata(remoteprocdev);
+
+       /* Process incoming buffers on our vring */
+       while (IRQ_HANDLED == rproc_vq_interrupt(rproc, 0))
+               ;
+
+       /* Must allow wakeup of potenitally blocking senders: */
+       rproc_vq_interrupt(rproc, 1);
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * davinci_rproc_callback() - inbound virtqueue message handler
+ *
+ * This handler is invoked directly by the kernel whenever the remote
+ * core (DSP) has modified the state of a virtqueue.  There is no
+ * "payload" message indicating the virtqueue index as is the case with
+ * mailbox-based implementations on OMAP4.  As such, this handler "polls"
+ * each known virtqueue index for every invocation.
+ */
+static irqreturn_t davinci_rproc_callback(int irq, void *p)
+{
+       if (readl(syscfg0_base + SYSCFG_CHIPSIG_OFFSET) &
+           SYSCFG_CHIPINT0) {
+               /* Clear interrupt level source */
+               writel(SYSCFG_CHIPINT0,
+                       syscfg0_base + SYSCFG_CHIPSIG_CLR_OFFSET);
+
+               /*
+                * ACK intr to AINTC.
+                *
+                * It has already been ack'ed by the kernel before calling
+                * this function, but since the ARM<->DSP interrupts in the
+                * CHIPSIG register are "level" instead of "pulse" variety,
+                * we need to ack it after taking down the level else we'll
+                * be called again immediately after returning.
+                */
+               ack_fxn(irq_data);
+
+               return IRQ_WAKE_THREAD;
+       }
+
+       return IRQ_HANDLED;
+}
+
+static int davinci_rproc_start(struct rproc *rproc)
+{
+       struct platform_device *pdev = to_platform_device(rproc->dev);
+       struct device *dev = rproc->dev;
+       struct davinci_rproc *drproc = rproc->priv;
+       struct clk *dsp_clk;
+       struct resource *r;
+       int ret;
+
+       remoteprocdev = pdev;
+
+       /* hw requires the start (boot) address be on 1KB boundary */
+       if (rproc->bootaddr & 0x3ff) {
+               dev_err(dev, "invalid boot address: must be aligned to 1KB\n");
+
+               return -EINVAL;
+       }
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (IS_ERR_OR_NULL(r)) {
+               dev_err(dev, "platform_get_resource() error: %ld\n",
+                       PTR_ERR(r));
+
+               return PTR_ERR(r);
+       }
+       host1cfg_offset = (int)r->start;
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               dev_err(dev, "platform_get_irq(pdev, 0) error: %d\n", irq);
+
+               return irq;
+       }
+
+       irq_data = irq_get_irq_data(irq);
+       if (IS_ERR_OR_NULL(irq_data)) {
+               dev_err(dev, "irq_get_irq_data(%d) error: %ld\n",
+                       irq, PTR_ERR(irq_data));
+
+               return PTR_ERR(irq_data);
+       }
+       ack_fxn = irq_data->chip->irq_ack;
+
+       dsp_clk = clk_get(dev, NULL);
+       if (IS_ERR_OR_NULL(dsp_clk)) {
+               dev_err(dev, "clk_get error: %ld\n", PTR_ERR(dsp_clk));
+               return PTR_ERR(dsp_clk);
+       }
+
+       ret = request_threaded_irq(irq, davinci_rproc_callback, handle_event,
+               0, "davinci-remoteproc", drproc);
+       if (ret) {
+               dev_err(dev, "request_threaded_irq error: %d\n", ret);
+               goto fail;
+       }
+
+       syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
+       writel(rproc->bootaddr, syscfg0_base + host1cfg_offset);
+
+       clk_enable(dsp_clk);
+       drproc->dsp_clk = dsp_clk;
+
+       return 0;
+fail:
+       clk_put(dsp_clk);
+
+       return ret;
+}
+
+static int davinci_rproc_stop(struct rproc *rproc)
+{
+       struct davinci_rproc *drproc = rproc->priv;
+       struct clk *dsp_clk = drproc->dsp_clk;
+
+       clk_disable(dsp_clk);
+       clk_put(dsp_clk);
+       iounmap(syscfg0_base);
+       free_irq(irq, drproc);
+
+       return 0;
+}
+
+/* kick a virtqueue */
+static void davinci_rproc_kick(struct rproc *rproc, int vqid)
+{
+       int timed_out;
+       unsigned long timeout;
+
+       timed_out = 0;
+       timeout = jiffies + HZ/100;
+
+       /* Poll for ack from other side first */
+       while (readl(syscfg0_base + SYSCFG_CHIPSIG_OFFSET) &
+               SYSCFG_CHIPINT2)
+               if (time_after(jiffies, timeout)) {
+                       dev_err(rproc->dev, "failed to receive ack\n");
+                       timed_out = 1;
+
+                       break;
+               }
+
+       if (!timed_out)
+               /* Interupt remote proc */
+               writel(SYSCFG_CHIPINT2, syscfg0_base + SYSCFG_CHIPSIG_OFFSET);
+}
+
+static struct rproc_ops davinci_rproc_ops = {
+       .start = davinci_rproc_start,
+       .stop = davinci_rproc_stop,
+       .kick = davinci_rproc_kick,
+};
+
+static int davinci_rproc_probe(struct platform_device *pdev)
+{
+       struct davinci_soc_info *soc_info = &davinci_soc_info;
+       struct da8xx_rproc_pdata *pdata = pdev->dev.platform_data;
+       struct davinci_rproc *drproc;
+       struct rproc *rproc;
+       void __iomem *psc_base;
+       int ret;
+
+       rproc = rproc_alloc(&pdev->dev, pdata->name, &davinci_rproc_ops,
+                               pdata->firmware, sizeof(*drproc));
+       if (!rproc)
+               return -ENOMEM;
+
+       drproc = rproc->priv;
+       drproc->rproc = rproc;
+
+       platform_set_drvdata(pdev, rproc);
+
+       ret = rproc_register(rproc);
+       if (ret)
+               goto free_rproc;
+
+       /* insure the dsp is halted by asserting local reset (LRST=0) */
+       psc_base = ioremap(soc_info->psc_bases[0], SZ_4K);
+       writel(NEXT_ENABLED, psc_base + MDCTL + 4 * DA8XX_LPSC0_GEM);
+       iounmap(psc_base);
+
+       return 0;
+
+free_rproc:
+       rproc_free(rproc);
+       return ret;
+}
+
+static int __devexit davinci_rproc_remove(struct platform_device *pdev)
+{
+       struct rproc *rproc = platform_get_drvdata(pdev);
+
+       return rproc_unregister(rproc);
+}
+
+static struct platform_driver davinci_rproc_driver = {
+       .probe = davinci_rproc_probe,
+       .remove = __devexit_p(davinci_rproc_remove),
+       .driver = {
+               .name = "davinci-rproc",
+               .owner = THIS_MODULE,
+       },
+};
+
+module_platform_driver(davinci_rproc_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Davinci DA850 Remote Processor control driver");
-- 
1.7.9.4

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to