@@ -215,3 +215,46 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
&dma_spec->args[0]);
}
EXPORT_SYMBOL_GPL(of_dma_simple_xlate);
+
+struct dma_chan *of_dma_slave_xlate(struct of_phandle_args *dma_spec,
+ struct of_dma *ofdma)
+{
+ struct of_dma_slave_xlate_info *info = ofdma->of_dma_data;
+ struct dma_chan *candidate, *chan;
+ int ret;
+
+retry:
+ candidate = NULL;
+
+ /*
+ * walk the list of channels registered with the current instance and
+ * find one that is currently unused
+ */
+ list_for_each_entry(chan, &info->device->channels, device_node)
+ if (chan->client_count == 0) {
+ candidate = chan;
+ break;
+ }
+
+ if (!candidate)
+ return NULL;
+
+ /*
+ * dma_get_slave_channel will return NULL if we lost a race between
+ * the lookup and the reservation
+ */
+ chan = dma_get_slave_channel(candidate);
+ if (!chan)
+ goto retry;
+
+ if (info->post_alloc) {
+ ret = info->post_alloc(chan, dma_spec);
+ if (ret) {
+ dma_release_channel(chan);
+ return NULL;
+ }
+ }
+
+ return chan;
+}
+EXPORT_SYMBOL_GPL(of_dma_slave_xlate);
@@ -31,6 +31,12 @@ struct of_dma_filter_info {
dma_filter_fn filter_fn;
};
+struct of_dma_slave_xlate_info {
+ struct dma_device *device;
+ int (*post_alloc)(struct dma_chan *chan,
+ struct of_phandle_args *dma_spec);
+};
+
#ifdef CONFIG_OF
extern int of_dma_controller_register(struct device_node *np,
struct dma_chan *(*of_dma_xlate)
@@ -41,6 +47,8 @@ extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
const char *name);
extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
struct of_dma *ofdma);
+extern struct dma_chan *of_dma_slave_xlate(struct of_phandle_args *dma_spec,
+ struct of_dma *ofdma);
#else
static inline int of_dma_controller_register(struct device_node *np,
struct dma_chan *(*of_dma_xlate)
@@ -66,6 +74,12 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s
return NULL;
}
+static inline struct dma_chan *of_dma_slave_xlate(struct of_phandle_args *dma_spec,
+ struct of_dma *ofdma)
+{
+ return NULL;
+}
+
#endif
#endif /* __LINUX_OF_DMA_H */