summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a2636d3)
raw | patch | inline | side by side (parent: a2636d3)
author | Tero Kristo <t-kristo@ti.com> | |
Tue, 19 Feb 2019 17:35:06 +0000 (11:35 -0600) | ||
committer | Suman Anna <s-anna@ti.com> | |
Sun, 24 Feb 2019 01:20:52 +0000 (19:20 -0600) |
Add two new get and put API, pruss_get() and pruss_put(), to the
PRUSS platform driver to allow client drivers to request a handle
to a PRUSS device. This handle will be used by client drivers to
request various operations of the PRUSS platform driver through
additional API that will be added in the following patches.
The pruss_get() function returns the pruss handle corresponding
to a PRUSS device referenced by a PRU remoteproc instance. The
pruss_put() is the complimentary function to pruss_get().
Signed-off-by: Tero Kristo <t-kristo@ti.com>
[s-anna@ti.com: various fixups and cleanups]
Signed-off-by: Suman Anna <s-anna@ti.com>
PRUSS platform driver to allow client drivers to request a handle
to a PRUSS device. This handle will be used by client drivers to
request various operations of the PRUSS platform driver through
additional API that will be added in the following patches.
The pruss_get() function returns the pruss handle corresponding
to a PRUSS device referenced by a PRU remoteproc instance. The
pruss_put() is the complimentary function to pruss_get().
Signed-off-by: Tero Kristo <t-kristo@ti.com>
[s-anna@ti.com: various fixups and cleanups]
Signed-off-by: Suman Anna <s-anna@ti.com>
drivers/soc/ti/pruss.c | patch | blob | history | |
include/linux/pruss.h | patch | blob | history |
diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c
index 656739b4a2042fb0e159d5b030dcaf7558104971..b0ab89af64261dfb762f9ae5e7092994255c91f2 100644 (file)
--- a/drivers/soc/ti/pruss.c
+++ b/drivers/soc/ti/pruss.c
* Copyright (C) 2014-2019 Texas Instruments Incorporated - http://www.ti.com/
* Suman Anna <s-anna@ti.com>
* Andrew F. Davis <afd@ti.com>
+ * Tero Kristo <t-kristo@ti.com>
*/
#include <linux/dma-mapping.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/pruss_driver.h>
+#include <linux/remoteproc.h>
/**
* struct pruss_private_data - PRUSS driver private data
const struct pruss_private_data *priv_data;
};
+/**
+ * pruss_get() - get the pruss for a given PRU remoteproc
+ * @rproc: remoteproc handle of a PRU instance
+ *
+ * Finds the parent pruss device for a PRU given the @rproc handle of the
+ * PRU remote processor. This function increments the pruss device's refcount,
+ * so always use pruss_put() to decrement it back once pruss isn't needed
+ * anymore.
+ *
+ * Returns the pruss handle on success, and an ERR_PTR on failure using one
+ * of the following error values
+ * -EINVAL if invalid parameter
+ * -ENODEV if PRU device or PRUSS device is not found
+ */
+struct pruss *pruss_get(struct rproc *rproc)
+{
+ struct pruss *pruss;
+ struct device *dev;
+ struct platform_device *ppdev;
+
+ if (IS_ERR_OR_NULL(rproc))
+ return ERR_PTR(-EINVAL);
+
+ dev = &rproc->dev;
+ if (!dev->parent)
+ return ERR_PTR(-ENODEV);
+
+ /* rudimentary check to make sure rproc handle is for a PRU */
+ if (!strstr(dev_name(dev->parent), "pru"))
+ return ERR_PTR(-ENODEV);
+
+ ppdev = to_platform_device(dev->parent->parent);
+ pruss = platform_get_drvdata(ppdev);
+ if (!pruss)
+ return ERR_PTR(-ENODEV);
+
+ get_device(pruss->dev);
+
+ return pruss;
+}
+EXPORT_SYMBOL_GPL(pruss_get);
+
+/**
+ * pruss_put() - decrement pruss device's usecount
+ * @pruss: pruss handle
+ *
+ * Complimentary function for pruss_get(). Needs to be called
+ * after the PRUSS is used, and only if the pruss_get() succeeds.
+ */
+void pruss_put(struct pruss *pruss)
+{
+ if (IS_ERR_OR_NULL(pruss))
+ return;
+
+ put_device(pruss->dev);
+}
+EXPORT_SYMBOL_GPL(pruss_put);
+
static const
struct pruss_private_data *pruss_get_private_data(struct platform_device *pdev)
{
diff --git a/include/linux/pruss.h b/include/linux/pruss.h
index 2346e31f70e6e3b7d80a3400b6d86e517ea9b2aa..8bf0a4b751ceeb3b99744e59eef8f8f4fd39d5d2 100644 (file)
--- a/include/linux/pruss.h
+++ b/include/linux/pruss.h
*
* Copyright (C) 2015-2019 Texas Instruments Incorporated - http://www.ti.com
* Suman Anna <s-anna@ti.com>
+ * Tero Kristo <t-kristo@ti.com>
*/
#ifndef __LINUX_PRUSS_H
};
struct rproc;
+struct pruss;
#if IS_ENABLED(CONFIG_TI_PRUSS)
+struct pruss *pruss_get(struct rproc *rproc);
+void pruss_put(struct pruss *pruss);
int pruss_intc_trigger(unsigned int irq);
#else
+static inline struct pruss *pruss_get(struct rproc *rproc)
+{
+ return ERR_PTR(-ENOTSUPP);
+}
+
+static inline void pruss_put(struct pruss *pruss) { }
+
static inline int pruss_intc_trigger(unsigned int irq)
{
return -ENOTSUPP;