|
@@ -1,7 +1,8 @@
|
|
|
|
|
+// SPDX-License-Identifier: GPL-2.0
|
|
|
/*
|
|
/*
|
|
|
* OMAP Remote Processor driver
|
|
* 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.
|
|
* Copyright (C) 2011 Google, Inc.
|
|
|
*
|
|
*
|
|
|
* Ohad Ben-Cohen <ohad@wizery.com>
|
|
* Ohad Ben-Cohen <ohad@wizery.com>
|
|
@@ -10,43 +11,307 @@
|
|
|
* Mark Grosen <mgrosen@ti.com>
|
|
* Mark Grosen <mgrosen@ti.com>
|
|
|
* Suman Anna <s-anna@ti.com>
|
|
* Suman Anna <s-anna@ti.com>
|
|
|
* Hari Kanigeri <h-kanigeri2@ti.com>
|
|
* Hari Kanigeri <h-kanigeri2@ti.com>
|
|
|
- *
|
|
|
|
|
- * 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.
|
|
|
|
|
- *
|
|
|
|
|
- * This program is distributed in the hope that it will be useful,
|
|
|
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
- * GNU General Public License for more details.
|
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/kernel.h>
|
|
|
#include <linux/module.h>
|
|
#include <linux/module.h>
|
|
|
#include <linux/err.h>
|
|
#include <linux/err.h>
|
|
|
|
|
+#include <linux/of_device.h>
|
|
|
|
|
+#include <linux/of_address.h>
|
|
|
|
|
+#include <linux/of_reserved_mem.h>
|
|
|
#include <linux/platform_device.h>
|
|
#include <linux/platform_device.h>
|
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/dma-mapping.h>
|
|
|
#include <linux/remoteproc.h>
|
|
#include <linux/remoteproc.h>
|
|
|
#include <linux/mailbox_client.h>
|
|
#include <linux/mailbox_client.h>
|
|
|
#include <linux/omap-mailbox.h>
|
|
#include <linux/omap-mailbox.h>
|
|
|
|
|
+#include <linux/regmap.h>
|
|
|
|
|
+#include <linux/mfd/syscon.h>
|
|
|
|
|
+#include <clocksource/timer-ti-dm.h>
|
|
|
|
|
|
|
|
#include <linux/platform_data/remoteproc-omap.h>
|
|
#include <linux/platform_data/remoteproc-omap.h>
|
|
|
|
|
+#include <linux/platform_data/dmtimer-omap.h>
|
|
|
|
|
|
|
|
#include "omap_remoteproc.h"
|
|
#include "omap_remoteproc.h"
|
|
|
#include "remoteproc_internal.h"
|
|
#include "remoteproc_internal.h"
|
|
|
|
|
|
|
|
|
|
+#define OMAP_RPROC_DSP_LOCAL_MEM_OFFSET (0x00800000)
|
|
|
|
|
+#define OMAP_RPROC_IPU_L2RAM_DEV_ADDR (0x20000000)
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 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
|
|
|
|
|
+ * @boot_reg_shift: bit-field shift required for the boot address value in
|
|
|
|
|
+ * @boot_reg
|
|
|
|
|
+ */
|
|
|
|
|
+struct omap_rproc_boot_data {
|
|
|
|
|
+ struct regmap *syscon;
|
|
|
|
|
+ unsigned int boot_reg;
|
|
|
|
|
+ unsigned int boot_reg_shift;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * struct omap_rproc_mem - internal memory structure
|
|
|
|
|
+ * @cpu_addr: MPU virtual address of the memory region
|
|
|
|
|
+ * @bus_addr: bus address used to access the memory region
|
|
|
|
|
+ * @dev_addr: device address of the memory region from DSP view
|
|
|
|
|
+ * @size: size of the memory region
|
|
|
|
|
+ */
|
|
|
|
|
+struct omap_rproc_mem {
|
|
|
|
|
+ void __iomem *cpu_addr;
|
|
|
|
|
+ phys_addr_t bus_addr;
|
|
|
|
|
+ u32 dev_addr;
|
|
|
|
|
+ size_t size;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * struct omap_rproc_timer - data structure for a timer used by a omap rproc
|
|
|
|
|
+ * @odt: timer pointer
|
|
|
|
|
+ * @timer_ops: OMAP dmtimer ops for @odt timer
|
|
|
|
|
+ */
|
|
|
|
|
+struct omap_rproc_timer {
|
|
|
|
|
+ struct omap_dm_timer *odt;
|
|
|
|
|
+ const struct omap_dm_timer_ops *timer_ops;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* struct omap_rproc - omap remote processor state
|
|
* struct omap_rproc - omap remote processor state
|
|
|
* @mbox: mailbox channel handle
|
|
* @mbox: mailbox channel handle
|
|
|
* @client: mailbox client to request the mailbox channel
|
|
* @client: mailbox client to request the mailbox channel
|
|
|
|
|
+ * @boot_data: boot data structure for setting processor boot address
|
|
|
|
|
+ * @mem: internal memory regions data
|
|
|
|
|
+ * @num_mems: number of internal memory regions
|
|
|
|
|
+ * @num_timers: number of rproc timer(s)
|
|
|
|
|
+ * @timers: timer(s) info used by rproc
|
|
|
* @rproc: rproc handle
|
|
* @rproc: rproc handle
|
|
|
*/
|
|
*/
|
|
|
struct omap_rproc {
|
|
struct omap_rproc {
|
|
|
struct mbox_chan *mbox;
|
|
struct mbox_chan *mbox;
|
|
|
struct mbox_client client;
|
|
struct mbox_client client;
|
|
|
|
|
+ struct omap_rproc_boot_data *boot_data;
|
|
|
|
|
+ struct omap_rproc_mem *mem;
|
|
|
|
|
+ int num_mems;
|
|
|
|
|
+ int num_timers;
|
|
|
|
|
+ struct omap_rproc_timer *timers;
|
|
|
struct rproc *rproc;
|
|
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_request_timer - request a timer for a remoteproc
|
|
|
|
|
+ * @np: device node pointer to the desired timer
|
|
|
|
|
+ * @timer: handle to a struct omap_rproc_timer to return the timer handle
|
|
|
|
|
+ *
|
|
|
|
|
+ * This helper function is used primarily to request a timer associated with
|
|
|
|
|
+ * a remoteproc. The returned handle is stored in the .odt field of the
|
|
|
|
|
+ * @timer structure passed in, and is used to invoke other timer specific
|
|
|
|
|
+ * ops (like starting a timer either during device initialization or during
|
|
|
|
|
+ * a resume operation, or for stopping/freeing a timer).
|
|
|
|
|
+ *
|
|
|
|
|
+ * Returns 0 on success, otherwise an appropriate failure
|
|
|
|
|
+ */
|
|
|
|
|
+static int omap_rproc_request_timer(struct device_node *np,
|
|
|
|
|
+ struct omap_rproc_timer *timer)
|
|
|
|
|
+{
|
|
|
|
|
+ int ret = 0;
|
|
|
|
|
+
|
|
|
|
|
+ timer->odt = timer->timer_ops->request_by_node(np);
|
|
|
|
|
+ if (!timer->odt) {
|
|
|
|
|
+ pr_err("request for timer node %p failed\n", np);
|
|
|
|
|
+ return -EBUSY;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret = timer->timer_ops->set_source(timer->odt, OMAP_TIMER_SRC_SYS_CLK);
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ pr_err("error setting OMAP_TIMER_SRC_SYS_CLK as source for timer node %p\n",
|
|
|
|
|
+ np);
|
|
|
|
|
+ timer->timer_ops->free(timer->odt);
|
|
|
|
|
+ return ret;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /* clean counter, remoteproc code will set the value */
|
|
|
|
|
+ timer->timer_ops->set_load(timer->odt, 0, 0);
|
|
|
|
|
+
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * omap_rproc_start_timer - start a timer for a remoteproc
|
|
|
|
|
+ * @timer: handle to a OMAP rproc timer
|
|
|
|
|
+ *
|
|
|
|
|
+ * This helper function is used to start a timer associated with a remoteproc,
|
|
|
|
|
+ * obtained using the request_timer ops. The helper function needs to be
|
|
|
|
|
+ * invoked by the driver to start the timer (during device initialization)
|
|
|
|
|
+ * or to just resume the timer.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Returns 0 on success, otherwise a failure as returned by DMTimer ops
|
|
|
|
|
+ */
|
|
|
|
|
+static inline int omap_rproc_start_timer(struct omap_rproc_timer *timer)
|
|
|
|
|
+{
|
|
|
|
|
+ return timer->timer_ops->start(timer->odt);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * omap_rproc_stop_timer - stop a timer for a remoteproc
|
|
|
|
|
+ * @timer: handle to a OMAP rproc timer
|
|
|
|
|
+ *
|
|
|
|
|
+ * This helper function is used to disable a timer associated with a
|
|
|
|
|
+ * remoteproc, and needs to be called either during a device shutdown
|
|
|
|
|
+ * or suspend operation. The separate helper function allows the driver
|
|
|
|
|
+ * to just stop a timer without having to release the timer during a
|
|
|
|
|
+ * suspend operation.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Returns 0 on success, otherwise a failure as returned by DMTimer ops
|
|
|
|
|
+ */
|
|
|
|
|
+static inline int omap_rproc_stop_timer(struct omap_rproc_timer *timer)
|
|
|
|
|
+{
|
|
|
|
|
+ return timer->timer_ops->stop(timer->odt);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * omap_rproc_release_timer - release a timer for a remoteproc
|
|
|
|
|
+ * @timer: handle to a OMAP rproc timer
|
|
|
|
|
+ *
|
|
|
|
|
+ * This helper function is used primarily to release a timer associated
|
|
|
|
|
+ * with a remoteproc. The dmtimer will be available for other clients to
|
|
|
|
|
+ * use once released.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Returns 0 on success, otherwise a failure as returned by DMTimer ops
|
|
|
|
|
+ */
|
|
|
|
|
+static inline int omap_rproc_release_timer(struct omap_rproc_timer *timer)
|
|
|
|
|
+{
|
|
|
|
|
+ return timer->timer_ops->free(timer->odt);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * omap_rproc_enable_timers - enable the timers for a remoteproc
|
|
|
|
|
+ * @rproc: handle of a remote processor
|
|
|
|
|
+ * @configure: boolean flag used to acquire and configure the timer handle
|
|
|
|
|
+ *
|
|
|
|
|
+ * This function is used primarily to enable the timers associated with
|
|
|
|
|
+ * a remoteproc. The configure flag is provided to allow the driver to
|
|
|
|
|
+ * to either acquire and start a timer (during device initialization) or
|
|
|
|
|
+ * to just start a timer (during a resume operation).
|
|
|
|
|
+ */
|
|
|
|
|
+static int omap_rproc_enable_timers(struct rproc *rproc, bool configure)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+ int ret = 0;
|
|
|
|
|
+ struct platform_device *tpdev;
|
|
|
|
|
+ struct dmtimer_platform_data *tpdata;
|
|
|
|
|
+ const struct omap_dm_timer_ops *timer_ops;
|
|
|
|
|
+ struct omap_rproc *oproc = rproc->priv;
|
|
|
|
|
+ struct omap_rproc_timer *timers = oproc->timers;
|
|
|
|
|
+ struct device *dev = rproc->dev.parent;
|
|
|
|
|
+ struct device_node *np = NULL;
|
|
|
|
|
+
|
|
|
|
|
+ if (oproc->num_timers <= 0)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (!configure)
|
|
|
|
|
+ goto start_timers;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < oproc->num_timers; i++) {
|
|
|
|
|
+ np = of_parse_phandle(dev->of_node, "timers", i);
|
|
|
|
|
+ if (!np) {
|
|
|
|
|
+ ret = -ENXIO;
|
|
|
|
|
+ dev_err(dev, "device node lookup for timer at index %d failed: %d\n",
|
|
|
|
|
+ i, ret);
|
|
|
|
|
+ goto free_timers;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ tpdev = of_find_device_by_node(np);
|
|
|
|
|
+ if (!tpdev) {
|
|
|
|
|
+ ret = -ENODEV;
|
|
|
|
|
+ dev_err(dev, "could not get timer platform device\n");
|
|
|
|
|
+ goto put_node;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ tpdata = dev_get_platdata(&tpdev->dev);
|
|
|
|
|
+ put_device(&tpdev->dev);
|
|
|
|
|
+ if (!tpdata) {
|
|
|
|
|
+ ret = -EINVAL;
|
|
|
|
|
+ dev_err(dev, "dmtimer pdata structure NULL\n");
|
|
|
|
|
+ goto put_node;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ timer_ops = tpdata->timer_ops;
|
|
|
|
|
+ if (!timer_ops || !timer_ops->request_by_node ||
|
|
|
|
|
+ !timer_ops->set_source || !timer_ops->set_load ||
|
|
|
|
|
+ !timer_ops->free || !timer_ops->start ||
|
|
|
|
|
+ !timer_ops->stop) {
|
|
|
|
|
+ ret = -EINVAL;
|
|
|
|
|
+ dev_err(dev, "device does not have required timer ops\n");
|
|
|
|
|
+ goto put_node;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ timers[i].timer_ops = timer_ops;
|
|
|
|
|
+ ret = omap_rproc_request_timer(np, &timers[i]);
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ dev_err(dev, "request for timer %p failed: %d\n", np,
|
|
|
|
|
+ ret);
|
|
|
|
|
+ goto put_node;
|
|
|
|
|
+ }
|
|
|
|
|
+ of_node_put(np);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+start_timers:
|
|
|
|
|
+ for (i = 0; i < oproc->num_timers; i++)
|
|
|
|
|
+ omap_rproc_start_timer(&timers[i]);
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+put_node:
|
|
|
|
|
+ of_node_put(np);
|
|
|
|
|
+free_timers:
|
|
|
|
|
+ while (i--) {
|
|
|
|
|
+ omap_rproc_release_timer(&timers[i]);
|
|
|
|
|
+ timers[i].odt = NULL;
|
|
|
|
|
+ timers[i].timer_ops = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ret;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * omap_rproc_disable_timers - disable the timers for a remoteproc
|
|
|
|
|
+ * @rproc: handle of a remote processor
|
|
|
|
|
+ * @configure: boolean flag used to release the timer handle
|
|
|
|
|
+ *
|
|
|
|
|
+ * This function is used primarily to disable the timers associated with
|
|
|
|
|
+ * a remoteproc. The configure flag is provided to allow the driver to
|
|
|
|
|
+ * to either stop and release a timer (during device shutdown) or to just
|
|
|
|
|
+ * stop a timer (during a suspend operation).
|
|
|
|
|
+ */
|
|
|
|
|
+static int omap_rproc_disable_timers(struct rproc *rproc, bool configure)
|
|
|
|
|
+{
|
|
|
|
|
+ int i;
|
|
|
|
|
+ struct omap_rproc *oproc = rproc->priv;
|
|
|
|
|
+ struct omap_rproc_timer *timers = oproc->timers;
|
|
|
|
|
+
|
|
|
|
|
+ if (oproc->num_timers <= 0)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < oproc->num_timers; i++) {
|
|
|
|
|
+ omap_rproc_stop_timer(&timers[i]);
|
|
|
|
|
+ if (configure) {
|
|
|
|
|
+ omap_rproc_release_timer(&timers[i]);
|
|
|
|
|
+ timers[i].odt = NULL;
|
|
|
|
|
+ timers[i].timer_ops = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* omap_rproc_mbox_callback() - inbound mailbox message handler
|
|
* omap_rproc_mbox_callback() - inbound mailbox message handler
|
|
|
* @client: mailbox client pointer used for requesting the mailbox channel
|
|
* @client: mailbox client pointer used for requesting the mailbox channel
|
|
@@ -106,6 +371,35 @@ static void omap_rproc_kick(struct rproc *rproc, int vqid)
|
|
|
ret);
|
|
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 int omap_rproc_write_dsp_boot_addr(struct rproc *rproc)
|
|
|
|
|
+{
|
|
|
|
|
+ struct device *dev = rproc->dev.parent;
|
|
|
|
|
+ struct omap_rproc *oproc = rproc->priv;
|
|
|
|
|
+ struct omap_rproc_boot_data *bdata = oproc->boot_data;
|
|
|
|
|
+ u32 offset = bdata->boot_reg;
|
|
|
|
|
+ unsigned int value = rproc->bootaddr;
|
|
|
|
|
+ unsigned int mask = ~(SZ_1K - 1);
|
|
|
|
|
+
|
|
|
|
|
+ if (value & (SZ_1K - 1)) {
|
|
|
|
|
+ dev_err(dev, "invalid boot address 0x%x, must be aligned on a 1KB boundary\n",
|
|
|
|
|
+ value);
|
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ value >>= bdata->boot_reg_shift;
|
|
|
|
|
+ mask >>= bdata->boot_reg_shift;
|
|
|
|
|
+
|
|
|
|
|
+ regmap_update_bits(bdata->syscon, offset, mask, value);
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* Power up the remote processor.
|
|
* Power up the remote processor.
|
|
|
*
|
|
*
|
|
@@ -122,8 +416,11 @@ static int omap_rproc_start(struct rproc *rproc)
|
|
|
int ret;
|
|
int ret;
|
|
|
struct mbox_client *client = &oproc->client;
|
|
struct mbox_client *client = &oproc->client;
|
|
|
|
|
|
|
|
- if (pdata->set_bootaddr)
|
|
|
|
|
- pdata->set_bootaddr(rproc->bootaddr);
|
|
|
|
|
|
|
+ if (oproc->boot_data) {
|
|
|
|
|
+ ret = omap_rproc_write_dsp_boot_addr(rproc);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ return ret;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
client->dev = dev;
|
|
client->dev = dev;
|
|
|
client->tx_done = NULL;
|
|
client->tx_done = NULL;
|
|
@@ -131,7 +428,7 @@ static int omap_rproc_start(struct rproc *rproc)
|
|
|
client->tx_block = false;
|
|
client->tx_block = false;
|
|
|
client->knows_txdone = 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)) {
|
|
if (IS_ERR(oproc->mbox)) {
|
|
|
ret = -EBUSY;
|
|
ret = -EBUSY;
|
|
|
dev_err(dev, "mbox_request_channel failed: %ld\n",
|
|
dev_err(dev, "mbox_request_channel failed: %ld\n",
|
|
@@ -152,14 +449,22 @@ static int omap_rproc_start(struct rproc *rproc)
|
|
|
goto put_mbox;
|
|
goto put_mbox;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ ret = omap_rproc_enable_timers(rproc, true);
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ dev_err(dev, "omap_rproc_enable_timers failed: %d\n", ret);
|
|
|
|
|
+ goto put_mbox;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ret = pdata->device_enable(pdev);
|
|
ret = pdata->device_enable(pdev);
|
|
|
if (ret) {
|
|
if (ret) {
|
|
|
dev_err(dev, "omap_device_enable failed: %d\n", ret);
|
|
dev_err(dev, "omap_device_enable failed: %d\n", ret);
|
|
|
- goto put_mbox;
|
|
|
|
|
|
|
+ goto reset_timers;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
+reset_timers:
|
|
|
|
|
+ omap_rproc_disable_timers(rproc, true);
|
|
|
put_mbox:
|
|
put_mbox:
|
|
|
mbox_free_channel(oproc->mbox);
|
|
mbox_free_channel(oproc->mbox);
|
|
|
return ret;
|
|
return ret;
|
|
@@ -178,32 +483,301 @@ static int omap_rproc_stop(struct rproc *rproc)
|
|
|
if (ret)
|
|
if (ret)
|
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
+ ret = omap_rproc_disable_timers(rproc, true);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ return ret;
|
|
|
|
|
+
|
|
|
mbox_free_channel(oproc->mbox);
|
|
mbox_free_channel(oproc->mbox);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
|
+ * Internal Memory translation helper
|
|
|
|
|
+ *
|
|
|
|
|
+ * Custom function implementing the rproc .da_to_va ops to provide address
|
|
|
|
|
+ * translation (device address to kernel virtual address) for internal RAMs
|
|
|
|
|
+ * present in a DSP or IPU device). The translated addresses can be used
|
|
|
|
|
+ * either by the remoteproc core for loading, or by any rpmsg bus drivers.
|
|
|
|
|
+ */
|
|
|
|
|
+static void *omap_rproc_da_to_va(struct rproc *rproc, u64 da, int len,
|
|
|
|
|
+ u32 flags)
|
|
|
|
|
+{
|
|
|
|
|
+ struct omap_rproc *oproc = rproc->priv;
|
|
|
|
|
+ void *va = NULL;
|
|
|
|
|
+ int i;
|
|
|
|
|
+ u32 offset;
|
|
|
|
|
+
|
|
|
|
|
+ if (len <= 0)
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+
|
|
|
|
|
+ if (!oproc->num_mems)
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < oproc->num_mems; i++) {
|
|
|
|
|
+ if (da >= oproc->mem[i].dev_addr && da + len <=
|
|
|
|
|
+ oproc->mem[i].dev_addr + oproc->mem[i].size) {
|
|
|
|
|
+ offset = da - oproc->mem[i].dev_addr;
|
|
|
|
|
+ /* __force to make sparse happy with type conversion */
|
|
|
|
|
+ va = (__force void *)(oproc->mem[i].cpu_addr + offset);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return va;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static const struct rproc_ops omap_rproc_ops = {
|
|
static const struct rproc_ops omap_rproc_ops = {
|
|
|
.start = omap_rproc_start,
|
|
.start = omap_rproc_start,
|
|
|
.stop = omap_rproc_stop,
|
|
.stop = omap_rproc_stop,
|
|
|
.kick = omap_rproc_kick,
|
|
.kick = omap_rproc_kick,
|
|
|
|
|
+ .da_to_va = omap_rproc_da_to_va,
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+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 omap_rproc_dev_data dra7_rproc_dev_data[] = {
|
|
|
|
|
+ {
|
|
|
|
|
+ .device_name = "40800000.dsp",
|
|
|
|
|
+ .fw_name = "dra7-dsp1-fw.xe66",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ .device_name = "41000000.dsp",
|
|
|
|
|
+ .fw_name = "dra7-dsp2-fw.xe66",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ .device_name = "55020000.ipu",
|
|
|
|
|
+ .fw_name = "dra7-ipu2-fw.xem4",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ .device_name = "58820000.ipu",
|
|
|
|
|
+ .fw_name = "dra7-ipu1-fw.xem4",
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ /* sentinel */
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+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,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ .compatible = "ti,dra7-dsp",
|
|
|
|
|
+ .data = dra7_rproc_dev_data,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ .compatible = "ti,dra7-ipu",
|
|
|
|
|
+ .data = dra7_rproc_dev_data,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ /* end */
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
+MODULE_DEVICE_TABLE(of, omap_rproc_of_match);
|
|
|
|
|
+
|
|
|
|
|
+static const char *omap_rproc_get_firmware(struct platform_device *pdev)
|
|
|
|
|
+{
|
|
|
|
|
+ struct device_node *np = pdev->dev.of_node;
|
|
|
|
|
+ const struct omap_rproc_dev_data *data;
|
|
|
|
|
+
|
|
|
|
|
+ data = of_device_get_match_data(&pdev->dev);
|
|
|
|
|
+ if (!data)
|
|
|
|
|
+ return ERR_PTR(-ENODEV);
|
|
|
|
|
+
|
|
|
|
|
+ if (!of_device_is_compatible(np, "ti,dra7-dsp") &&
|
|
|
|
|
+ !of_device_is_compatible(np, "ti,dra7-ipu"))
|
|
|
|
|
+ return data->fw_name;
|
|
|
|
|
+
|
|
|
|
|
+ for (; data && data->device_name; data++) {
|
|
|
|
|
+ if (!strcmp(dev_name(&pdev->dev), data->device_name))
|
|
|
|
|
+ return data->fw_name;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ERR_PTR(-ENOENT);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+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") &&
|
|
|
|
|
+ !of_device_is_compatible(np, "ti,dra7-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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (of_device_is_compatible(np, "ti,dra7-dsp"))
|
|
|
|
|
+ oproc->boot_data->boot_reg_shift = 10;
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int omap_rproc_of_get_internal_memories(struct platform_device *pdev,
|
|
|
|
|
+ struct rproc *rproc)
|
|
|
|
|
+{
|
|
|
|
|
+ static const char * const ipu_mem_names[] = {"l2ram"};
|
|
|
|
|
+ static const char * const dra7_dsp_mem_names[] = {"l2ram", "l1pram",
|
|
|
|
|
+ "l1dram"};
|
|
|
|
|
+ struct device_node *np = pdev->dev.of_node;
|
|
|
|
|
+ struct omap_rproc *oproc = rproc->priv;
|
|
|
|
|
+ struct device *dev = &pdev->dev;
|
|
|
|
|
+ const char * const *mem_names;
|
|
|
|
|
+ struct resource *res;
|
|
|
|
|
+ int num_mems;
|
|
|
|
|
+ const __be32 *addrp;
|
|
|
|
|
+ u32 l4_offset = 0;
|
|
|
|
|
+ u64 size;
|
|
|
|
|
+ int i;
|
|
|
|
|
+
|
|
|
|
|
+ /* OMAP4 and OMAP5 DSPs do not have support for flat SRAM */
|
|
|
|
|
+ if (of_device_is_compatible(np, "ti,omap4-dsp") ||
|
|
|
|
|
+ of_device_is_compatible(np, "ti,omap5-dsp"))
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ /* DRA7 DSPs have two additional SRAMs at L1 level */
|
|
|
|
|
+ if (of_device_is_compatible(np, "ti,dra7-dsp")) {
|
|
|
|
|
+ mem_names = dra7_dsp_mem_names;
|
|
|
|
|
+ num_mems = ARRAY_SIZE(dra7_dsp_mem_names);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mem_names = ipu_mem_names;
|
|
|
|
|
+ num_mems = ARRAY_SIZE(ipu_mem_names);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ oproc->mem = devm_kcalloc(dev, num_mems, sizeof(*oproc->mem),
|
|
|
|
|
+ GFP_KERNEL);
|
|
|
|
|
+ if (!oproc->mem)
|
|
|
|
|
+ return -ENOMEM;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < num_mems; i++) {
|
|
|
|
|
+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
|
|
|
|
|
+ mem_names[i]);
|
|
|
|
|
+ oproc->mem[i].cpu_addr = devm_ioremap_resource(dev, res);
|
|
|
|
|
+ if (IS_ERR(oproc->mem[i].cpu_addr)) {
|
|
|
|
|
+ dev_err(dev, "failed to parse and map %s memory\n",
|
|
|
|
|
+ mem_names[i]);
|
|
|
|
|
+ return PTR_ERR(oproc->mem[i].cpu_addr);
|
|
|
|
|
+ }
|
|
|
|
|
+ oproc->mem[i].bus_addr = res->start;
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * The DSPs have the internal memories starting at a fixed
|
|
|
|
|
+ * offset of 0x800000 from address 0, and this corresponds to
|
|
|
|
|
+ * L2RAM. The L3 address view has the L2RAM bus address as the
|
|
|
|
|
+ * starting address for the IP, so the L2RAM memory region needs
|
|
|
|
|
+ * to be processed first, and the device addresses for each
|
|
|
|
|
+ * memory region can be computed using the relative offset
|
|
|
|
|
+ * from this base address.
|
|
|
|
|
+ */
|
|
|
|
|
+ if (of_device_is_compatible(np, "ti,dra7-dsp") &&
|
|
|
|
|
+ !strcmp(mem_names[i], "l2ram")) {
|
|
|
|
|
+ addrp = of_get_address(dev->of_node, i, &size, NULL);
|
|
|
|
|
+ l4_offset = be32_to_cpu(*addrp);
|
|
|
|
|
+ }
|
|
|
|
|
+ oproc->mem[i].dev_addr =
|
|
|
|
|
+ of_device_is_compatible(np, "ti,dra7-dsp") ?
|
|
|
|
|
+ res->start - l4_offset +
|
|
|
|
|
+ OMAP_RPROC_DSP_LOCAL_MEM_OFFSET :
|
|
|
|
|
+ OMAP_RPROC_IPU_L2RAM_DEV_ADDR;
|
|
|
|
|
+ oproc->mem[i].size = resource_size(res);
|
|
|
|
|
+
|
|
|
|
|
+ dev_dbg(dev, "memory %8s: bus addr %pa size 0x%x va %p da 0x%x\n",
|
|
|
|
|
+ mem_names[i], &oproc->mem[i].bus_addr,
|
|
|
|
|
+ oproc->mem[i].size, oproc->mem[i].cpu_addr,
|
|
|
|
|
+ oproc->mem[i].dev_addr);
|
|
|
|
|
+ }
|
|
|
|
|
+ oproc->num_mems = num_mems;
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static int omap_rproc_probe(struct platform_device *pdev)
|
|
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 omap_rproc *oproc;
|
|
|
struct rproc *rproc;
|
|
struct rproc *rproc;
|
|
|
|
|
+ const char *firmware;
|
|
|
int ret;
|
|
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));
|
|
ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
|
|
|
if (ret) {
|
|
if (ret) {
|
|
|
dev_err(&pdev->dev, "dma_set_coherent_mask: %d\n", ret);
|
|
dev_err(&pdev->dev, "dma_set_coherent_mask: %d\n", ret);
|
|
|
return 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)
|
|
if (!rproc)
|
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
|
@@ -212,14 +786,57 @@ static int omap_rproc_probe(struct platform_device *pdev)
|
|
|
/* All existing OMAP IPU and DSP processors have an MMU */
|
|
/* All existing OMAP IPU and DSP processors have an MMU */
|
|
|
rproc->has_iommu = true;
|
|
rproc->has_iommu = true;
|
|
|
|
|
|
|
|
|
|
+ ret = omap_rproc_of_get_internal_memories(pdev, rproc);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ goto free_rproc;
|
|
|
|
|
+
|
|
|
|
|
+ ret = omap_rproc_get_boot_data(pdev, rproc);
|
|
|
|
|
+ if (ret)
|
|
|
|
|
+ goto free_rproc;
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * Timer nodes are directly used in client nodes as phandles, so
|
|
|
|
|
+ * retrieve the count using appropriate size
|
|
|
|
|
+ */
|
|
|
|
|
+ oproc->num_timers = of_property_count_elems_of_size(np, "timers",
|
|
|
|
|
+ sizeof(phandle));
|
|
|
|
|
+ if (oproc->num_timers <= 0) {
|
|
|
|
|
+ dev_dbg(&pdev->dev, "device does not have timers, status = %d\n",
|
|
|
|
|
+ oproc->num_timers);
|
|
|
|
|
+ oproc->num_timers = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (oproc->num_timers) {
|
|
|
|
|
+ oproc->timers = devm_kzalloc(&pdev->dev, sizeof(*oproc->timers)
|
|
|
|
|
+ * oproc->num_timers, GFP_KERNEL);
|
|
|
|
|
+ if (!oproc->timers) {
|
|
|
|
|
+ ret = -ENOMEM;
|
|
|
|
|
+ goto free_rproc;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ dev_dbg(&pdev->dev, "device has %d tick timers\n",
|
|
|
|
|
+ oproc->num_timers);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ret = of_reserved_mem_device_init(&pdev->dev);
|
|
|
|
|
+ if (ret) {
|
|
|
|
|
+ dev_err(&pdev->dev, "device does not have specific CMA pool\n");
|
|
|
|
|
+ goto free_rproc;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
platform_set_drvdata(pdev, rproc);
|
|
platform_set_drvdata(pdev, rproc);
|
|
|
|
|
|
|
|
ret = rproc_add(rproc);
|
|
ret = rproc_add(rproc);
|
|
|
if (ret)
|
|
if (ret)
|
|
|
- goto free_rproc;
|
|
|
|
|
|
|
+ goto release_mem;
|
|
|
|
|
+
|
|
|
|
|
+ if (rproc_get_id(rproc) < 0)
|
|
|
|
|
+ dev_warn(&pdev->dev, "device does not have an alias id\n");
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
+release_mem:
|
|
|
|
|
+ of_reserved_mem_device_release(&pdev->dev);
|
|
|
free_rproc:
|
|
free_rproc:
|
|
|
rproc_free(rproc);
|
|
rproc_free(rproc);
|
|
|
return ret;
|
|
return ret;
|
|
@@ -231,6 +848,7 @@ static int omap_rproc_remove(struct platform_device *pdev)
|
|
|
|
|
|
|
|
rproc_del(rproc);
|
|
rproc_del(rproc);
|
|
|
rproc_free(rproc);
|
|
rproc_free(rproc);
|
|
|
|
|
+ of_reserved_mem_device_release(&pdev->dev);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -240,6 +858,7 @@ static struct platform_driver omap_rproc_driver = {
|
|
|
.remove = omap_rproc_remove,
|
|
.remove = omap_rproc_remove,
|
|
|
.driver = {
|
|
.driver = {
|
|
|
.name = "omap-rproc",
|
|
.name = "omap-rproc",
|
|
|
|
|
+ .of_match_table = omap_rproc_of_match,
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
|
|
|