From: rizhao@nvidia.com (Richard Zhao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] DMA: add help function to check whether dma controller registered
Date: Fri, 2 Aug 2013 14:04:18 +0800 [thread overview]
Message-ID: <1375423458-6868-1-git-send-email-rizhao@nvidia.com> (raw)
DMA client device driver usually needs to know at probe time whether
dma controller has been registered to deffer probe. So add a help
function of_dma_check_controller.
DMA request channel functions can also used to check it, but they
are usually called at open() time.
Signed-off-by: Richard Zhao <rizhao@nvidia.com>
---
drivers/dma/of-dma.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/of_dma.h | 6 ++++++
2 files changed, 44 insertions(+)
diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index e1c4d3b..b6828c1 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -188,6 +188,44 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
}
/**
+ * of_dma_check_controller - Check whether dma controller registered
+ * @dev: pointer to client device structure
+ * @name: slave channel name
+ */
+int of_dma_check_controller(struct device *dev, const char *name)
+{
+ struct device_node *np = dev->of_node;
+ struct of_phandle_args dma_spec;
+ struct of_dma *ofdma = NULL;
+ int count, i;
+
+ if (!np || !name)
+ return -EINVAL;
+
+ count = of_property_count_strings(np, "dma-names");
+ if (count < 0) {
+ dev_err(dev, "dma-names property missing or empty\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < count; i++) {
+ if (of_dma_match_channel(np, name, i, &dma_spec))
+ continue;
+
+ mutex_lock(&of_dma_lock);
+ ofdma = of_dma_find_controller(&dma_spec);
+ mutex_unlock(&of_dma_lock);
+ of_node_put(dma_spec.np);
+ }
+
+ if (ofdma)
+ return 0;
+ else
+ return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_dma_check_controller);
+
+/**
* of_dma_simple_xlate - Simple DMA engine translation function
* @dma_spec: pointer to DMA specifier as found in the device tree
* @of_dma: pointer to DMA controller data
diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index ae36298..bc7195f 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -39,6 +39,7 @@ extern int of_dma_controller_register(struct device_node *np,
extern void of_dma_controller_free(struct device_node *np);
extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
const char *name);
+extern int of_dma_check_controller(struct device *dev, const char *name);
extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
struct of_dma *ofdma);
#else
@@ -60,6 +61,11 @@ static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *
return NULL;
}
+static inline int of_dma_check_controller(struct device *dev, const char *name)
+{
+ return 0;
+}
+
static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
struct of_dma *ofdma)
{
--
1.8.1.5
WARNING: multiple messages have this Message-ID (diff)
From: Richard Zhao <rizhao@nvidia.com>
To: <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>
Cc: <vinod.koul@intel.com>, <djbw@fb.com>, <grant.likely@linaro.org>,
<rob.herring@calxeda.com>, <swarren@wwwdotorg.org>,
Richard Zhao <rizhao@nvidia.com>
Subject: [PATCH] DMA: add help function to check whether dma controller registered
Date: Fri, 2 Aug 2013 14:04:18 +0800 [thread overview]
Message-ID: <1375423458-6868-1-git-send-email-rizhao@nvidia.com> (raw)
DMA client device driver usually needs to know at probe time whether
dma controller has been registered to deffer probe. So add a help
function of_dma_check_controller.
DMA request channel functions can also used to check it, but they
are usually called at open() time.
Signed-off-by: Richard Zhao <rizhao@nvidia.com>
---
drivers/dma/of-dma.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/of_dma.h | 6 ++++++
2 files changed, 44 insertions(+)
diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index e1c4d3b..b6828c1 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -188,6 +188,44 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
}
/**
+ * of_dma_check_controller - Check whether dma controller registered
+ * @dev: pointer to client device structure
+ * @name: slave channel name
+ */
+int of_dma_check_controller(struct device *dev, const char *name)
+{
+ struct device_node *np = dev->of_node;
+ struct of_phandle_args dma_spec;
+ struct of_dma *ofdma = NULL;
+ int count, i;
+
+ if (!np || !name)
+ return -EINVAL;
+
+ count = of_property_count_strings(np, "dma-names");
+ if (count < 0) {
+ dev_err(dev, "dma-names property missing or empty\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < count; i++) {
+ if (of_dma_match_channel(np, name, i, &dma_spec))
+ continue;
+
+ mutex_lock(&of_dma_lock);
+ ofdma = of_dma_find_controller(&dma_spec);
+ mutex_unlock(&of_dma_lock);
+ of_node_put(dma_spec.np);
+ }
+
+ if (ofdma)
+ return 0;
+ else
+ return -ENODEV;
+}
+EXPORT_SYMBOL_GPL(of_dma_check_controller);
+
+/**
* of_dma_simple_xlate - Simple DMA engine translation function
* @dma_spec: pointer to DMA specifier as found in the device tree
* @of_dma: pointer to DMA controller data
diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index ae36298..bc7195f 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -39,6 +39,7 @@ extern int of_dma_controller_register(struct device_node *np,
extern void of_dma_controller_free(struct device_node *np);
extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
const char *name);
+extern int of_dma_check_controller(struct device *dev, const char *name);
extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
struct of_dma *ofdma);
#else
@@ -60,6 +61,11 @@ static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *
return NULL;
}
+static inline int of_dma_check_controller(struct device *dev, const char *name)
+{
+ return 0;
+}
+
static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
struct of_dma *ofdma)
{
--
1.8.1.5
next reply other threads:[~2013-08-02 6:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-02 6:04 Richard Zhao [this message]
2013-08-02 6:04 ` [PATCH] DMA: add help function to check whether dma controller registered Richard Zhao
2013-08-02 19:59 ` Stephen Warren
2013-08-02 19:59 ` Stephen Warren
2013-08-05 5:56 ` Richard Zhao
2013-08-05 5:56 ` Richard Zhao
2013-08-22 6:43 ` [PATCH v2] " Richard Zhao
2013-08-22 6:43 ` Richard Zhao
2013-08-22 6:43 ` Richard Zhao
2013-08-22 20:36 ` Stephen Warren
2013-08-22 20:36 ` Stephen Warren
2013-08-23 1:17 ` Richard Zhao
2013-08-23 1:17 ` Richard Zhao
2013-08-23 15:56 ` Stephen Warren
2013-08-23 15:56 ` Stephen Warren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1375423458-6868-1-git-send-email-rizhao@nvidia.com \
--to=rizhao@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.