]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - rpmsg/rpmsg.git/commitdiff
remoteproc/omap: Add device tree support
authorSuman Anna <s-anna@ti.com>
Tue, 20 Feb 2018 18:22:12 +0000 (12:22 -0600)
committerSuman Anna <s-anna@ti.com>
Mon, 4 Mar 2019 16:02:35 +0000 (10:02 -0600)
OMAP4+ SoCs support device tree boot only. The OMAP remoteproc
driver is enhanced to support remoteproc devices created through
Device Tree, support for legacy platform devices has been
deprecated. The current DT support handles the IPU and DSP
processor subsystems on OMAP4 and OMAP5 SoCs.

The OMAP remoteproc driver relies on the omap_device, omap_hwmod
and control module layers for performing clock, reset and boot
vector management (DSP remoteprocs only) of the devices, but
some of these are limited only to the machine-specific layers
in arch/arm. The dependency against control module API for boot
vector management of the DSP remoteprocs has now been removed
with added logic to parse the boot register from the DT node
and program it appropriately directly within the driver.

The dependency on omap_device API for clock and reset control
remains though and is to be achieved through OMAP rproc specific
platform data ops, and the required implementations to boot and
shutdown have been added in the machine layer. These need to be
plugged in to the remoteproc devices through pdata quirks, for
properly booting the remote processors.

The OMAP remoteproc driver expects the firmware images to have
fixed names. This used to be defined through platform data
previously, and are now coded into the driver. The following
names are to be expected of the firmwares,
OMAP4 - IPU: omap4-ipu-fw.xem3
        DSP: omap4-dsp-fw.xe64T
OMAP5 - IPU: omap5-ipu-fw.xem4
        DSP: omap5-dsp-fw.xe64T

Cc: Tony Lindgren <tony@atomide.com>
Signed-off-by: Suman Anna <s-anna@ti.com>
arch/arm/mach-omap2/Makefile
arch/arm/mach-omap2/remoteproc.c [new file with mode: 0644]
arch/arm/mach-omap2/remoteproc.h [new file with mode: 0644]
drivers/remoteproc/omap_remoteproc.c

index 01377c292db43f6e48e7d3f4098140c7bf5cea7f..eeb1e8377d824c4c4c0a0ab5456023454354c037 100644 (file)
@@ -243,3 +243,7 @@ include/generated/ti-pm-asm-offsets.h: arch/arm/mach-omap2/pm-asm-offsets.s FORC
        $(call filechk,offsets,__TI_PM_ASM_OFFSETS_H__)
 
 $(obj)/sleep33xx.o $(obj)/sleep43xx.o: include/generated/ti-pm-asm-offsets.h
+
+ifneq ($(CONFIG_OMAP_REMOTEPROC),)
+obj-y                                  += remoteproc.o
+endif
diff --git a/arch/arm/mach-omap2/remoteproc.c b/arch/arm/mach-omap2/remoteproc.c
new file mode 100644 (file)
index 0000000..093ebcf
--- /dev/null
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Remote processor machine-specific module for OMAP4+ SoCs
+ *
+ * Copyright (C) 2011-2019 Texas Instruments Incorporated - http://www.ti.com/
+ *      Suman Anna <s-anna@ti.com>
+ */
+
+#include <linux/kernel.h>
+
+#include "omap_device.h"
+#include "remoteproc.h"
+
+/**
+ * omap_rproc_device_enable - enable the remoteproc device
+ * @pdev: the rproc platform device
+ *
+ * This function performs the necessary low-level functions to enable
+ * a remoteproc device to start executing. This typically includes
+ * releasing the reset lines, and enabling the clocks for the device.
+ * We do not usually expect this function to fail.
+ *
+ * Return: 0 on success, or the return code from the failed function
+ */
+int omap_rproc_device_enable(struct platform_device *pdev)
+{
+       int ret = -EINVAL;
+       struct omap_device *od = to_omap_device(pdev);
+
+       if (!od) {
+               dev_err(&pdev->dev, "device does not have a backing omap_device\n");
+               goto out;
+       }
+
+       /*
+        * This reset management follows a device name check to differentiate
+        * DSP and IPU processor subsystems. This check is weak and is ok for
+        * now because of the dependencies against the pdata-quirks, where
+        * the devices are given specific device names that satisfy the
+        * criteria for the check. It can easily be replaced with a stronger
+        * check like device node compatibility check, if needed.
+        */
+       if (strstr(dev_name(&pdev->dev), "dsp")) {
+               ret = omap_device_deassert_hardreset(pdev, "dsp");
+               if (ret)
+                       goto out;
+       } else if (strstr(dev_name(&pdev->dev), "ipu")) {
+               ret = omap_device_deassert_hardreset(pdev, "cpu0");
+               if (ret)
+                       goto out;
+
+               ret = omap_device_deassert_hardreset(pdev, "cpu1");
+               if (ret)
+                       goto out;
+       } else {
+               dev_err(&pdev->dev, "unsupported remoteproc\n");
+               goto out;
+       }
+
+       ret = omap_device_enable(pdev);
+
+out:
+       if (ret)
+               dev_err(&pdev->dev, "%s failed, ret = %d\n", __func__, ret);
+       return ret;
+}
+
+/**
+ * omap_rproc_device_shutdown - shutdown the remoteproc device
+ * @pdev: the rproc platform device
+ *
+ * This function performs the necessary low-level functions to shutdown
+ * a remoteproc device. This typically includes disabling the clocks
+ * for the device and asserting the associated reset lines. We do not
+ * usually expect this function to fail.
+ *
+ * Return: 0 on success, or the return code from the failed function
+ */
+int omap_rproc_device_shutdown(struct platform_device *pdev)
+{
+       int ret = -EINVAL;
+       struct omap_device *od = to_omap_device(pdev);
+
+       if (!od) {
+               dev_err(&pdev->dev, "device does not have a backing omap_device\n");
+               goto out;
+       }
+
+       ret = omap_device_idle(pdev);
+       if (ret)
+               goto out;
+
+       /*
+        * This reset management follows a device name check to differentiate
+        * DSP and IPU processor subsystems. This check is weak and is ok for
+        * now because of the dependencies against the pdata-quirks, where
+        * the devices are given specific device names that satisfy the
+        * criteria for the check. It can easily be replaced with a stronger
+        * check like device node compatibility check, if needed.
+        */
+       if (strstr(dev_name(&pdev->dev), "dsp")) {
+               ret = omap_device_assert_hardreset(pdev, "dsp");
+       } else if (strstr(dev_name(&pdev->dev), "ipu")) {
+               ret = omap_device_assert_hardreset(pdev, "cpu1");
+               if (ret)
+                       goto out;
+
+               ret = omap_device_assert_hardreset(pdev, "cpu0");
+               if (ret)
+                       goto out;
+       } else {
+               dev_err(&pdev->dev, "unsupported remoteproc\n");
+       }
+
+out:
+       if (ret)
+               dev_err(&pdev->dev, "%s failed, ret = %d\n", __func__, ret);
+       return ret;
+}
diff --git a/arch/arm/mach-omap2/remoteproc.h b/arch/arm/mach-omap2/remoteproc.h
new file mode 100644 (file)
index 0000000..80244a6
--- /dev/null
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Remote processor machine-specific quirks for OMAP4+ SoCs
+ *
+ * Copyright (C) 2014-2019 Texas Instruments Incorporated - http://www.ti.com/
+ *      Suman Anna <s-anna@ti.com>
+ */
+
+#ifndef __ARCH_ARM_MACH_OMAP2_REMOTEPROC_H
+#define __ARCH_ARM_MACH_OMAP2_REMOTEPROC_H
+
+#include "linux/platform_device.h"
+
+#if IS_ENABLED(CONFIG_OMAP_REMOTEPROC)
+int omap_rproc_device_enable(struct platform_device *pdev);
+int omap_rproc_device_shutdown(struct platform_device *pdev);
+#else
+static inline int omap_rproc_device_enable(struct platform_device *pdev)
+{
+       return 0;
+}
+
+static inline int omap_rproc_device_shutdown(struct platform_device *pdev)
+{
+       return 0;
+}
+#endif
+
+#endif
index 434ca6717c5693e103c2593cfb04af89639ea045..c40d701e33d9b299cd901faf090d08f3f82e767c 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * OMAP Remote Processor driver
  *
- * Copyright (C) 2011 Texas Instruments, Inc.
+ * Copyright (C) 2011-2019 Texas Instruments Incorporated - http://www.ti.com/
  * Copyright (C) 2011 Google, Inc.
  *
  * Ohad Ben-Cohen <ohad@wizery.com>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/err.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 #include <linux/remoteproc.h>
 #include <linux/mailbox_client.h>
 #include <linux/omap-mailbox.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
 #include <linux/platform_data/remoteproc-omap.h>
 
 #include "omap_remoteproc.h"
 #include "remoteproc_internal.h"
 
+/**
+ * struct omap_rproc_boot_data - boot data structure for the DSP omap rprocs
+ * @syscon: regmap handle for the system control configuration module
+ * @boot_reg: boot register offset within the @syscon regmap
+ */
+struct omap_rproc_boot_data {
+       struct regmap *syscon;
+       unsigned int boot_reg;
+};
+
 /**
  * struct omap_rproc - omap remote processor state
  * @mbox: mailbox channel handle
  * @client: mailbox client to request the mailbox channel
+ * @boot_data: boot data structure for setting processor boot address
  * @rproc: rproc handle
  */
 struct omap_rproc {
        struct mbox_chan *mbox;
        struct mbox_client client;
+       struct omap_rproc_boot_data *boot_data;
        struct rproc *rproc;
 };
 
+/**
+ * struct omap_rproc_dev_data - device data for the omap remote processor
+ * @device_name: device name of the remote processor
+ * @fw_name: firmware name to use
+ */
+struct omap_rproc_dev_data {
+       const char *device_name;
+       const char *fw_name;
+};
+
 /**
  * omap_rproc_mbox_callback() - inbound mailbox message handler
  * @client: mailbox client pointer used for requesting the mailbox channel
@@ -92,6 +117,21 @@ static void omap_rproc_kick(struct rproc *rproc, int vqid)
                        ret);
 }
 
+/**
+ * omap_rproc_write_dsp_boot_addr - set boot address for a DSP remote processor
+ * @rproc: handle of a remote processor
+ *
+ * Set boot address for a supported DSP remote processor.
+ */
+static void omap_rproc_write_dsp_boot_addr(struct rproc *rproc)
+{
+       struct omap_rproc *oproc = rproc->priv;
+       struct omap_rproc_boot_data *bdata = oproc->boot_data;
+       u32 offset = bdata->boot_reg;
+
+       regmap_write(bdata->syscon, offset, rproc->bootaddr);
+}
+
 /*
  * Power up the remote processor.
  *
@@ -108,8 +148,8 @@ static int omap_rproc_start(struct rproc *rproc)
        int ret;
        struct mbox_client *client = &oproc->client;
 
-       if (pdata->set_bootaddr)
-               pdata->set_bootaddr(rproc->bootaddr);
+       if (oproc->boot_data)
+               omap_rproc_write_dsp_boot_addr(rproc);
 
        client->dev = dev;
        client->tx_done = NULL;
@@ -117,7 +157,7 @@ static int omap_rproc_start(struct rproc *rproc)
        client->tx_block = false;
        client->knows_txdone = false;
 
-       oproc->mbox = omap_mbox_request_channel(client, pdata->mbox_name);
+       oproc->mbox = mbox_request_channel(client, 0);
        if (IS_ERR(oproc->mbox)) {
                ret = -EBUSY;
                dev_err(dev, "mbox_request_channel failed: %ld\n",
@@ -175,21 +215,128 @@ static const struct rproc_ops omap_rproc_ops = {
        .kick           = omap_rproc_kick,
 };
 
+static const struct omap_rproc_dev_data omap4_dsp_dev_data = {
+       .device_name    = "dsp",
+       .fw_name        = "omap4-dsp-fw.xe64T",
+};
+
+static const struct omap_rproc_dev_data omap4_ipu_dev_data = {
+       .device_name    = "ipu",
+       .fw_name        = "omap4-ipu-fw.xem3",
+};
+
+static const struct omap_rproc_dev_data omap5_dsp_dev_data = {
+       .device_name    = "dsp",
+       .fw_name        = "omap5-dsp-fw.xe64T",
+};
+
+static const struct omap_rproc_dev_data omap5_ipu_dev_data = {
+       .device_name    = "ipu",
+       .fw_name        = "omap5-ipu-fw.xem4",
+};
+
+static const struct of_device_id omap_rproc_of_match[] = {
+       {
+               .compatible     = "ti,omap4-dsp",
+               .data           = &omap4_dsp_dev_data,
+       },
+       {
+               .compatible     = "ti,omap4-ipu",
+               .data           = &omap4_ipu_dev_data,
+       },
+       {
+               .compatible     = "ti,omap5-dsp",
+               .data           = &omap5_dsp_dev_data,
+       },
+       {
+               .compatible     = "ti,omap5-ipu",
+               .data           = &omap5_ipu_dev_data,
+       },
+       {
+               /* end */
+       },
+};
+MODULE_DEVICE_TABLE(of, omap_rproc_of_match);
+
+static const char *omap_rproc_get_firmware(struct platform_device *pdev)
+{
+       const struct omap_rproc_dev_data *data;
+
+       data = of_device_get_match_data(&pdev->dev);
+       if (!data)
+               return ERR_PTR(-ENODEV);
+
+       return data->fw_name;
+}
+
+static int omap_rproc_get_boot_data(struct platform_device *pdev,
+                                   struct rproc *rproc)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct omap_rproc *oproc = rproc->priv;
+       int ret;
+
+       if (!of_device_is_compatible(np, "ti,omap4-dsp") &&
+           !of_device_is_compatible(np, "ti,omap5-dsp"))
+               return 0;
+
+       oproc->boot_data = devm_kzalloc(&pdev->dev, sizeof(*oproc->boot_data),
+                                       GFP_KERNEL);
+       if (!oproc->boot_data)
+               return -ENOMEM;
+
+       if (!of_property_read_bool(np, "syscon-bootreg")) {
+               dev_err(&pdev->dev, "syscon-bootreg property is missing\n");
+               return -EINVAL;
+       }
+
+       oproc->boot_data->syscon =
+                       syscon_regmap_lookup_by_phandle(np, "syscon-bootreg");
+       if (IS_ERR(oproc->boot_data->syscon)) {
+               ret = PTR_ERR(oproc->boot_data->syscon);
+               return ret;
+       }
+
+       if (of_property_read_u32_index(np, "syscon-bootreg", 1,
+                                      &oproc->boot_data->boot_reg)) {
+               dev_err(&pdev->dev, "couldn't get the boot register\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static int omap_rproc_probe(struct platform_device *pdev)
 {
-       struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
+       struct omap_rproc_pdata *pdata = dev_get_platdata(&pdev->dev);
+       struct device_node *np = pdev->dev.of_node;
        struct omap_rproc *oproc;
        struct rproc *rproc;
+       const char *firmware;
        int ret;
 
+       if (!np) {
+               dev_err(&pdev->dev, "only DT-based devices are supported\n");
+               return -ENODEV;
+       }
+
+       if (!pdata || !pdata->device_enable || !pdata->device_shutdown) {
+               dev_err(&pdev->dev, "platform data is either missing or incomplete\n");
+               return -ENODEV;
+       }
+
+       firmware = omap_rproc_get_firmware(pdev);
+       if (IS_ERR(firmware))
+               return PTR_ERR(firmware);
+
        ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
        if (ret) {
                dev_err(&pdev->dev, "dma_set_coherent_mask: %d\n", ret);
                return ret;
        }
 
-       rproc = rproc_alloc(&pdev->dev, pdata->name, &omap_rproc_ops,
-                           pdata->firmware, sizeof(*oproc));
+       rproc = rproc_alloc(&pdev->dev, dev_name(&pdev->dev), &omap_rproc_ops,
+                           firmware, sizeof(*oproc));
        if (!rproc)
                return -ENOMEM;
 
@@ -198,6 +345,10 @@ static int omap_rproc_probe(struct platform_device *pdev)
        /* All existing OMAP IPU and DSP processors have an MMU */
        rproc->has_iommu = true;
 
+       ret = omap_rproc_get_boot_data(pdev, rproc);
+       if (ret)
+               goto free_rproc;
+
        platform_set_drvdata(pdev, rproc);
 
        ret = rproc_add(rproc);
@@ -226,6 +377,7 @@ static struct platform_driver omap_rproc_driver = {
        .remove = omap_rproc_remove,
        .driver = {
                .name = "omap-rproc",
+               .of_match_table = omap_rproc_of_match,
        },
 };