summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorNishanth Menon <nm@ti.com>2015-09-17 15:42:40 -0500
committerTom Rini <trini@konsulko.com>2015-10-22 14:18:39 -0400
commit3df0b8b4dad19c764c1cc81d283bf903f4ab9e69 (patch)
tree78034d1d88f1b2888b43427bc059f1794dbd9540 /drivers
parentddf56bc7e3ef43920b4a23320e70c1998f1ef843 (diff)
downloadu-boot-imx-3df0b8b4dad19c764c1cc81d283bf903f4ab9e69.zip
u-boot-imx-3df0b8b4dad19c764c1cc81d283bf903f4ab9e69.tar.gz
u-boot-imx-3df0b8b4dad19c764c1cc81d283bf903f4ab9e69.tar.bz2
remoteproc: Introduce a sandbox dummy driver
Introduce a dummy driver for sandbox that allows us to verify basic functionality. This is not meant to do anything functional - but is more or less meant as a framework plumbing debug helper. The sandbox remoteproc driver maintains absolutey no states and is a simple driver which just is filled with empty hooks. Idea being to give an approximate idea to implement own remoteproc driver using this as a template. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Nishanth Menon <nm@ti.com> Acked-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/remoteproc/Kconfig9
-rw-r--r--drivers/remoteproc/Makefile3
-rw-r--r--drivers/remoteproc/sandbox_testproc.c336
3 files changed, 348 insertions, 0 deletions
diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 4446826..437224b 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -12,4 +12,13 @@ config REMOTEPROC
bool
depends on DM
+# Please keep the configuration alphabetically sorted.
+config REMOTEPROC_SANDBOX
+ bool "Support for Test processor for Sandbox"
+ select REMOTEPROC
+ depends on DM
+ depends on SANDBOX
+ help
+ Say 'y' here to add support for test processor which does dummy
+ operations for sandbox platform.
endmenu
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 14c2792..720aa6e 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -5,3 +5,6 @@
#
obj-$(CONFIG_REMOTEPROC) += rproc-uclass.o
+
+# Remote proc drivers - Please keep this list alphabetically sorted.
+obj-$(CONFIG_REMOTEPROC_SANDBOX) += sandbox_testproc.o
diff --git a/drivers/remoteproc/sandbox_testproc.c b/drivers/remoteproc/sandbox_testproc.c
new file mode 100644
index 0000000..004c779
--- /dev/null
+++ b/drivers/remoteproc/sandbox_testproc.c
@@ -0,0 +1,336 @@
+/*
+ * (C) Copyright 2015
+ * Texas Instruments Incorporated - http://www.ti.com/
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#define pr_fmt(fmt) "%s: " fmt, __func__
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <remoteproc.h>
+
+/**
+ * enum sandbox_state - different device states
+ * @sb_booted: Entry condition, just booted
+ * @sb_init: Initialized (basic environment is ready)
+ * @sb_reset: Held in reset (accessible, but not running)
+ * @sb_loaded: Loaded with image (but not running)
+ * @sb_running: Processor is running
+ */
+enum sandbox_state {
+ sb_booted,
+ sb_init,
+ sb_reset,
+ sb_loaded,
+ sb_running
+};
+
+/**
+ * struct sandbox_test_devdata - private data per device
+ * @current_state: device current state
+ */
+struct sandbox_test_devdata {
+ enum sandbox_state current_state;
+};
+
+/**
+ * sandbox_dev_move_to_state() - statemachine for our dummy device
+ * @dev: device to switch state
+ * @next_state: next proposed state
+ *
+ * This tries to follow the following statemachine:
+ * Entry
+ * |
+ * v
+ * +-------+
+ * +---+ init |
+ * | | | <---------------------+
+ * | +-------+ |
+ * | |
+ * | |
+ * | +--------+ |
+ * Load| | reset | |
+ * | | | <----------+ |
+ * | +--------+ | |
+ * | |Load | |
+ * | | | |
+ * | +----v----+ reset | |
+ * +-> | | (opt) | |
+ * | Loaded +-----------+ |
+ * | | |
+ * +----+----+ |
+ * | Start |
+ * +---v-----+ (opt) |
+ * +->| Running | Stop |
+ * Ping +- | +--------------------+
+ * (opt) +---------+
+ *
+ * (is_running does not change state)
+ *
+ * Return: 0 when valid state transition is seen, else returns -EINVAL
+ */
+static int sandbox_dev_move_to_state(struct udevice *dev,
+ enum sandbox_state next_state)
+{
+ struct sandbox_test_devdata *ddata = dev_get_priv(dev);
+
+ /* No state transition is OK */
+ if (ddata->current_state == next_state)
+ return 0;
+
+ debug("current_state=%d, next_state=%d\n", ddata->current_state,
+ next_state);
+ switch (ddata->current_state) {
+ case sb_booted:
+ if (next_state == sb_init)
+ goto ok_state;
+ break;
+
+ case sb_init:
+ if (next_state == sb_reset || next_state == sb_loaded)
+ goto ok_state;
+ break;
+
+ case sb_reset:
+ if (next_state == sb_loaded || next_state == sb_init)
+ goto ok_state;
+ break;
+
+ case sb_loaded:
+ if (next_state == sb_reset || next_state == sb_init ||
+ next_state == sb_running)
+ goto ok_state;
+ break;
+
+ case sb_running:
+ if (next_state == sb_reset || next_state == sb_init)
+ goto ok_state;
+ break;
+ };
+ return -EINVAL;
+
+ok_state:
+ ddata->current_state = next_state;
+ return 0;
+}
+
+/**
+ * sandbox_testproc_probe() - basic probe function
+ * @dev: test proc device that is being probed.
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int sandbox_testproc_probe(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ struct sandbox_test_devdata *ddata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+ ddata = dev_get_priv(dev);
+ if (!ddata) {
+ debug("%s: platform private data missing\n", uc_pdata->name);
+ return -EINVAL;
+ }
+ ret = sandbox_dev_move_to_state(dev, sb_booted);
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+
+ return ret;
+}
+
+/**
+ * sandbox_testproc_init() - Simple initialization function
+ * @dev: device to operate upon
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int sandbox_testproc_init(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+
+ ret = sandbox_dev_move_to_state(dev, sb_init);
+
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+ if (ret)
+ debug("%s init failed\n", uc_pdata->name);
+
+ return ret;
+}
+
+/**
+ * sandbox_testproc_reset() - Reset the remote processor
+ * @dev: device to operate upon
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int sandbox_testproc_reset(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+
+ ret = sandbox_dev_move_to_state(dev, sb_reset);
+
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+
+ if (ret)
+ debug("%s reset failed\n", uc_pdata->name);
+ return ret;
+}
+
+/**
+ * sandbox_testproc_load() - (replace: short desc)
+ * @dev: device to operate upon
+ * @addr: Address of the binary image to load
+ * @size: Size (in bytes) of the binary image to load
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int sandbox_testproc_load(struct udevice *dev, ulong addr, ulong size)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+
+ ret = sandbox_dev_move_to_state(dev, sb_loaded);
+
+ debug("%s: called(%d) Loading to %08lX %lu size\n",
+ uc_pdata->name, ret, addr, size);
+
+ if (ret)
+ debug("%s load failed\n", uc_pdata->name);
+ return ret;
+}
+
+/**
+ * sandbox_testproc_start() - Start the remote processor
+ * @dev: device to operate upon
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int sandbox_testproc_start(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+
+ ret = sandbox_dev_move_to_state(dev, sb_running);
+
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+
+ if (ret)
+ debug("%s start failed\n", uc_pdata->name);
+ return ret;
+}
+
+/**
+ * sandbox_testproc_stop() - Stop the remote processor
+ * @dev: device to operate upon
+ *
+ * Return: 0 if all went ok, else return appropriate error
+ */
+static int sandbox_testproc_stop(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+
+ ret = sandbox_dev_move_to_state(dev, sb_init);
+
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+
+ if (ret)
+ debug("%s stop failed\n", uc_pdata->name);
+ return ret;
+}
+
+/**
+ * sandbox_testproc_is_running() - Check if remote processor is running
+ * @dev: device to operate upon
+ *
+ * Return: 0 if running, 1 if not running
+ */
+static int sandbox_testproc_is_running(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ struct sandbox_test_devdata *ddata;
+ int ret = 1;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+ ddata = dev_get_priv(dev);
+
+ if (ddata->current_state == sb_running)
+ ret = 0;
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+
+ return ret;
+}
+
+/**
+ * sandbox_testproc_ping() - Try pinging remote processor
+ * @dev: device to operate upon
+ *
+ * Return: 0 if running, -EINVAL if not running
+ */
+static int sandbox_testproc_ping(struct udevice *dev)
+{
+ struct dm_rproc_uclass_pdata *uc_pdata;
+ struct sandbox_test_devdata *ddata;
+ int ret;
+
+ uc_pdata = dev_get_uclass_platdata(dev);
+ ddata = dev_get_priv(dev);
+
+ if (ddata->current_state == sb_running)
+ ret = 0;
+ else
+ ret = -EINVAL;
+
+ debug("%s: called(%d)\n", uc_pdata->name, ret);
+ if (ret)
+ debug("%s: No response.(Not started?)\n", uc_pdata->name);
+
+ return ret;
+}
+
+static const struct dm_rproc_ops sandbox_testproc_ops = {
+ .init = sandbox_testproc_init,
+ .reset = sandbox_testproc_reset,
+ .load = sandbox_testproc_load,
+ .start = sandbox_testproc_start,
+ .stop = sandbox_testproc_stop,
+ .is_running = sandbox_testproc_is_running,
+ .ping = sandbox_testproc_ping,
+};
+
+static const struct udevice_id sandbox_ids[] = {
+ {.compatible = "sandbox,test-processor"},
+ {}
+};
+
+U_BOOT_DRIVER(sandbox_testproc) = {
+ .name = "sandbox_test_proc",
+ .of_match = sandbox_ids,
+ .id = UCLASS_REMOTEPROC,
+ .ops = &sandbox_testproc_ops,
+ .probe = sandbox_testproc_probe,
+ .priv_auto_alloc_size = sizeof(struct sandbox_test_devdata),
+};
+
+/* TODO(nm@ti.com): Remove this along with non-DT support */
+static struct dm_rproc_uclass_pdata proc_3_test = {
+ .name = "proc_3_legacy",
+ .mem_type = RPROC_INTERNAL_MEMORY_MAPPED,
+};
+
+U_BOOT_DEVICE(proc_3_demo) = {
+ .name = "sandbox_test_proc",
+ .platdata = &proc_3_test,
+};