Skip to content

Commit 67d1b0a

Browse files
Tero Kristonmenon
authored andcommitted
soc: ti: pruss: Add pruss_get()/put() API
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(). Co-developed-by: Suman Anna <s-anna@ti.com> Signed-off-by: Suman Anna <s-anna@ti.com> Signed-off-by: Tero Kristo <t-kristo@ti.com> Co-developed-by: Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org> Signed-off-by: Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org> Signed-off-by: Puranjay Mohan <p-mohan@ti.com> Reviewed-by: Roger Quadros <rogerq@kernel.org> Reviewed-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Acked-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: MD Danish Anwar <danishanwar@ti.com> Link: https://lore.kernel.org/r/20230414045542.3249939-2-danishanwar@ti.com Signed-off-by: Nishanth Menon <nm@ti.com>
1 parent e752f9b commit 67d1b0a

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

drivers/soc/ti/pruss.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Author(s):
77
* Suman Anna <s-anna@ti.com>
88
* Andrew F. Davis <afd@ti.com>
9+
* Tero Kristo <t-kristo@ti.com>
910
*/
1011

1112
#include <linux/clk-provider.h>
@@ -18,6 +19,7 @@
1819
#include <linux/pm_runtime.h>
1920
#include <linux/pruss_driver.h>
2021
#include <linux/regmap.h>
22+
#include <linux/remoteproc.h>
2123
#include <linux/slab.h>
2224

2325
/**
@@ -30,6 +32,66 @@ struct pruss_private_data {
3032
bool has_core_mux_clock;
3133
};
3234

35+
/**
36+
* pruss_get() - get the pruss for a given PRU remoteproc
37+
* @rproc: remoteproc handle of a PRU instance
38+
*
39+
* Finds the parent pruss device for a PRU given the @rproc handle of the
40+
* PRU remote processor. This function increments the pruss device's refcount,
41+
* so always use pruss_put() to decrement it back once pruss isn't needed
42+
* anymore.
43+
*
44+
* This API doesn't check if @rproc is valid or not. It is expected the caller
45+
* will have done a pru_rproc_get() on @rproc, before calling this API to make
46+
* sure that @rproc is valid.
47+
*
48+
* Return: pruss handle on success, and an ERR_PTR on failure using one
49+
* of the following error values
50+
* -EINVAL if invalid parameter
51+
* -ENODEV if PRU device or PRUSS device is not found
52+
*/
53+
struct pruss *pruss_get(struct rproc *rproc)
54+
{
55+
struct pruss *pruss;
56+
struct device *dev;
57+
struct platform_device *ppdev;
58+
59+
if (IS_ERR_OR_NULL(rproc))
60+
return ERR_PTR(-EINVAL);
61+
62+
dev = &rproc->dev;
63+
64+
/* make sure it is PRU rproc */
65+
if (!dev->parent || !is_pru_rproc(dev->parent))
66+
return ERR_PTR(-ENODEV);
67+
68+
ppdev = to_platform_device(dev->parent->parent);
69+
pruss = platform_get_drvdata(ppdev);
70+
if (!pruss)
71+
return ERR_PTR(-ENODEV);
72+
73+
get_device(pruss->dev);
74+
75+
return pruss;
76+
}
77+
EXPORT_SYMBOL_GPL(pruss_get);
78+
79+
/**
80+
* pruss_put() - decrement pruss device's usecount
81+
* @pruss: pruss handle
82+
*
83+
* Complimentary function for pruss_get(). Needs to be called
84+
* after the PRUSS is used, and only if the pruss_get() succeeds.
85+
*/
86+
void pruss_put(struct pruss *pruss)
87+
{
88+
if (IS_ERR_OR_NULL(pruss))
89+
return;
90+
91+
put_device(pruss->dev);
92+
}
93+
EXPORT_SYMBOL_GPL(pruss_put);
94+
3395
static void pruss_of_free_clk_provider(void *data)
3496
{
3597
struct device_node *clk_mux_np = data;

include/linux/pruss_driver.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifndef _PRUSS_DRIVER_H_
1010
#define _PRUSS_DRIVER_H_
1111

12+
#include <linux/remoteproc/pruss.h>
1213
#include <linux/types.h>
14+
#include <linux/err.h>
1315

1416
/*
1517
* enum pruss_mem - PRUSS memory range identifiers
@@ -51,4 +53,20 @@ struct pruss {
5153
struct clk *iep_clk_mux;
5254
};
5355

56+
#if IS_ENABLED(CONFIG_TI_PRUSS)
57+
58+
struct pruss *pruss_get(struct rproc *rproc);
59+
void pruss_put(struct pruss *pruss);
60+
61+
#else
62+
63+
static inline struct pruss *pruss_get(struct rproc *rproc)
64+
{
65+
return ERR_PTR(-EOPNOTSUPP);
66+
}
67+
68+
static inline void pruss_put(struct pruss *pruss) { }
69+
70+
#endif /* CONFIG_TI_PRUSS */
71+
5472
#endif /* _PRUSS_DRIVER_H_ */

0 commit comments

Comments
 (0)