linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id
@ 2013-03-25 13:16 Lars-Peter Clausen
  2013-03-25 13:16 ` [PATCH 2/2] dma: pl330: Use the generic of_dma_xlate_by_chan_id Lars-Peter Clausen
  2013-03-29 21:49 ` [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Vinod Koul
  0 siblings, 2 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2013-03-25 13:16 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams
  Cc: Jon Hunter, Padmavathi Venna, linux-kernel, Lars-Peter Clausen

This patch adds a new generic of dma xlate callback function which will match a
channel by its id.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/dma/of-dma.c   | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_dma.h |  4 ++++
 2 files changed, 51 insertions(+)

diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
index 00db454..7cad4d7 100644
--- a/drivers/dma/of-dma.c
+++ b/drivers/dma/of-dma.c
@@ -269,3 +269,50 @@ 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 of_dma_filter_by_chan_id_args {
+	struct dma_device *dev;
+	unsigned int chan_id;
+};
+
+static bool of_dma_filter_by_chan_id(struct dma_chan *chan, void *params)
+{
+	struct of_dma_filter_by_chan_id_args *args = params;
+
+	return chan->device == args->dev && chan->chan_id == args->chan_id;
+}
+
+/**
+ * of_dma_xlate_by_chan_id - Translate dt property to DMA channel by channel id
+ * @dma_spec:	pointer to DMA specifier as found in the device tree
+ * @of_dma:	pointer to DMA controller data
+ *
+ * This function can be used as the of xlate callback for DMA driver which want
+ * to match the channel based on the channel id. When using this xlate function
+ * the #dma-cells propety of the DMA controller dt node needs to be set to 1.
+ * The data parameter of of_dma_controller_register must be a pointer to the
+ * dma_device struct the function should match uppon.
+ *
+ * Returns pointer to appropriate dma channel on success or NULL on error.
+ */
+struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec,
+					 struct of_dma *ofdma)
+{
+	struct of_dma_filter_by_chan_id_args args;
+	dma_cap_mask_t cap;
+
+	args.dev = ofdma->of_dma_data;
+	if (!args.dev)
+		return NULL;
+
+	if (dma_spec->args_count != 1)
+		return NULL;
+
+	dma_cap_zero(cap);
+	dma_cap_set(DMA_SLAVE, cap);
+
+	args.chan_id = dma_spec->args[0];
+
+	return dma_request_channel(cap, of_dma_filter_by_chan_id, &args);
+}
+EXPORT_SYMBOL_GPL(of_dma_xlate_by_chan_id);
diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index ce6a8ab..46732d3 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -43,6 +43,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_xlate_by_chan_id(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)
@@ -69,6 +71,8 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s
 	return NULL;
 }
 
+#define of_dma_xlate_by_chan_id NULL
+
 #endif
 
 #endif /* __LINUX_OF_DMA_H */
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] dma: pl330: Use the generic of_dma_xlate_by_chan_id
  2013-03-25 13:16 [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Lars-Peter Clausen
@ 2013-03-25 13:16 ` Lars-Peter Clausen
  2013-03-29 21:49 ` [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Vinod Koul
  1 sibling, 0 replies; 7+ messages in thread
From: Lars-Peter Clausen @ 2013-03-25 13:16 UTC (permalink / raw)
  To: Vinod Koul, Dan Williams
  Cc: Jon Hunter, Padmavathi Venna, linux-kernel, Lars-Peter Clausen

Use the generic of_dma_xlate_by_chan_id xlate callback instead of a custom
implementation.

There is one minor difference between the generic of_dma_xlate_by_chan_id
function and the pl330 specific one. of_dma_xlate_by_chan_id only sets the
DMA_SLAVE capability for the channel capability mask, while the pl330 driver
additionally sets the DMA_CYCLIC capability. But since all pl330 channels which
have the DMA_SLAVE capability set also have DMA_CYCLIC capability set both
functions will have the same result.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/dma/pl330.c | 41 +----------------------------------------
 1 file changed, 1 insertion(+), 40 deletions(-)

diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 345e2a1..ea48de7 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -608,11 +608,6 @@ struct dma_pl330_desc {
 	struct dma_pl330_chan *pchan;
 };
 
-struct dma_pl330_filter_args {
-	struct dma_pl330_dmac *pdmac;
-	unsigned int chan_id;
-};
-
 static inline void _callback(struct pl330_req *r, enum pl330_op_err err)
 {
 	if (r && r->xfer_cb)
@@ -2358,16 +2353,6 @@ static void dma_pl330_rqcb(void *token, enum pl330_op_err err)
 	tasklet_schedule(&pch->task);
 }
 
-static bool pl330_dt_filter(struct dma_chan *chan, void *param)
-{
-	struct dma_pl330_filter_args *fargs = param;
-
-	if (chan->device != &fargs->pdmac->ddma)
-		return false;
-
-	return (chan->chan_id == fargs->chan_id);
-}
-
 bool pl330_filter(struct dma_chan *chan, void *param)
 {
 	u8 *peri_id;
@@ -2380,30 +2365,6 @@ bool pl330_filter(struct dma_chan *chan, void *param)
 }
 EXPORT_SYMBOL(pl330_filter);
 
-static struct dma_chan *of_dma_pl330_xlate(struct of_phandle_args *dma_spec,
-						struct of_dma *ofdma)
-{
-	int count = dma_spec->args_count;
-	struct dma_pl330_dmac *pdmac = ofdma->of_dma_data;
-	struct dma_pl330_filter_args fargs;
-	dma_cap_mask_t cap;
-
-	if (!pdmac)
-		return NULL;
-
-	if (count != 1)
-		return NULL;
-
-	fargs.pdmac = pdmac;
-	fargs.chan_id = dma_spec->args[0];
-
-	dma_cap_zero(cap);
-	dma_cap_set(DMA_SLAVE, cap);
-	dma_cap_set(DMA_CYCLIC, cap);
-
-	return dma_request_channel(cap, pl330_dt_filter, &fargs);
-}
-
 static int pl330_alloc_chan_resources(struct dma_chan *chan)
 {
 	struct dma_pl330_chan *pch = to_pchan(chan);
@@ -2996,7 +2957,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
 		pi->pcfg.num_peri, pi->pcfg.num_events);
 
 	ret = of_dma_controller_register(adev->dev.of_node,
-					 of_dma_pl330_xlate, pdmac);
+					 of_dma_xlate_by_chan_id, pd);
 	if (ret) {
 		dev_err(&adev->dev,
 		"unable to register DMA to the generic DT DMA helpers\n");
-- 
1.8.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id
  2013-03-25 13:16 [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Lars-Peter Clausen
  2013-03-25 13:16 ` [PATCH 2/2] dma: pl330: Use the generic of_dma_xlate_by_chan_id Lars-Peter Clausen
@ 2013-03-29 21:49 ` Vinod Koul
  2013-03-30  8:38   ` Lars-Peter Clausen
  1 sibling, 1 reply; 7+ messages in thread
From: Vinod Koul @ 2013-03-29 21:49 UTC (permalink / raw)
  To: Lars-Peter Clausen, Arnd Bergmann
  Cc: Dan Williams, Jon Hunter, Padmavathi Venna, linux-kernel

On Mon, Mar 25, 2013 at 02:16:51PM +0100, Lars-Peter Clausen wrote:
> This patch adds a new generic of dma xlate callback function which will match a
> channel by its id.
how will the client know which "id" to request? 

> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  drivers/dma/of-dma.c   | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/of_dma.h |  4 ++++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> index 00db454..7cad4d7 100644
> --- a/drivers/dma/of-dma.c
> +++ b/drivers/dma/of-dma.c
> @@ -269,3 +269,50 @@ 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 of_dma_filter_by_chan_id_args {
> +	struct dma_device *dev;
> +	unsigned int chan_id;
> +};
> +
> +static bool of_dma_filter_by_chan_id(struct dma_chan *chan, void *params)
> +{
> +	struct of_dma_filter_by_chan_id_args *args = params;
> +
> +	return chan->device == args->dev && chan->chan_id == args->chan_id;
> +}
> +
> +/**
> + * of_dma_xlate_by_chan_id - Translate dt property to DMA channel by channel id
> + * @dma_spec:	pointer to DMA specifier as found in the device tree
> + * @of_dma:	pointer to DMA controller data
> + *
> + * This function can be used as the of xlate callback for DMA driver which want
> + * to match the channel based on the channel id. When using this xlate function
> + * the #dma-cells propety of the DMA controller dt node needs to be set to 1.
> + * The data parameter of of_dma_controller_register must be a pointer to the
> + * dma_device struct the function should match uppon.
> + *
> + * Returns pointer to appropriate dma channel on success or NULL on error.
> + */
> +struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec,
> +					 struct of_dma *ofdma)
> +{
> +	struct of_dma_filter_by_chan_id_args args;
> +	dma_cap_mask_t cap;
> +
> +	args.dev = ofdma->of_dma_data;
> +	if (!args.dev)
> +		return NULL;
> +
> +	if (dma_spec->args_count != 1)
> +		return NULL;
> +
> +	dma_cap_zero(cap);
> +	dma_cap_set(DMA_SLAVE, cap);
> +
> +	args.chan_id = dma_spec->args[0];
> +
> +	return dma_request_channel(cap, of_dma_filter_by_chan_id, &args);
> +}
> +EXPORT_SYMBOL_GPL(of_dma_xlate_by_chan_id);
> diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
> index ce6a8ab..46732d3 100644
> --- a/include/linux/of_dma.h
> +++ b/include/linux/of_dma.h
> @@ -43,6 +43,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_xlate_by_chan_id(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)
> @@ -69,6 +71,8 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s
>  	return NULL;
>  }
>  
> +#define of_dma_xlate_by_chan_id NULL
> +
>  #endif
>  
>  #endif /* __LINUX_OF_DMA_H */
> -- 
> 1.8.0
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id
  2013-03-29 21:49 ` [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Vinod Koul
@ 2013-03-30  8:38   ` Lars-Peter Clausen
  2013-04-09 11:28     ` Vinod Koul
  0 siblings, 1 reply; 7+ messages in thread
From: Lars-Peter Clausen @ 2013-03-30  8:38 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Arnd Bergmann, Dan Williams, Jon Hunter, Padmavathi Venna, linux-kernel

On 03/29/2013 10:49 PM, Vinod Koul wrote:
> On Mon, Mar 25, 2013 at 02:16:51PM +0100, Lars-Peter Clausen wrote:
>> This patch adds a new generic of dma xlate callback function which will match a
>> channel by its id.
> how will the client know which "id" to request? 

The devicetree tells it, or what exactly do you mean?

- Lars

> 
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> ---
>>  drivers/dma/of-dma.c   | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>>  include/linux/of_dma.h |  4 ++++
>>  2 files changed, 51 insertions(+)
>>
>> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
>> index 00db454..7cad4d7 100644
>> --- a/drivers/dma/of-dma.c
>> +++ b/drivers/dma/of-dma.c
>> @@ -269,3 +269,50 @@ 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 of_dma_filter_by_chan_id_args {
>> +	struct dma_device *dev;
>> +	unsigned int chan_id;
>> +};
>> +
>> +static bool of_dma_filter_by_chan_id(struct dma_chan *chan, void *params)
>> +{
>> +	struct of_dma_filter_by_chan_id_args *args = params;
>> +
>> +	return chan->device == args->dev && chan->chan_id == args->chan_id;
>> +}
>> +
>> +/**
>> + * of_dma_xlate_by_chan_id - Translate dt property to DMA channel by channel id
>> + * @dma_spec:	pointer to DMA specifier as found in the device tree
>> + * @of_dma:	pointer to DMA controller data
>> + *
>> + * This function can be used as the of xlate callback for DMA driver which want
>> + * to match the channel based on the channel id. When using this xlate function
>> + * the #dma-cells propety of the DMA controller dt node needs to be set to 1.
>> + * The data parameter of of_dma_controller_register must be a pointer to the
>> + * dma_device struct the function should match uppon.
>> + *
>> + * Returns pointer to appropriate dma channel on success or NULL on error.
>> + */
>> +struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec,
>> +					 struct of_dma *ofdma)
>> +{
>> +	struct of_dma_filter_by_chan_id_args args;
>> +	dma_cap_mask_t cap;
>> +
>> +	args.dev = ofdma->of_dma_data;
>> +	if (!args.dev)
>> +		return NULL;
>> +
>> +	if (dma_spec->args_count != 1)
>> +		return NULL;
>> +
>> +	dma_cap_zero(cap);
>> +	dma_cap_set(DMA_SLAVE, cap);
>> +
>> +	args.chan_id = dma_spec->args[0];
>> +
>> +	return dma_request_channel(cap, of_dma_filter_by_chan_id, &args);
>> +}
>> +EXPORT_SYMBOL_GPL(of_dma_xlate_by_chan_id);
>> diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
>> index ce6a8ab..46732d3 100644
>> --- a/include/linux/of_dma.h
>> +++ b/include/linux/of_dma.h
>> @@ -43,6 +43,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_xlate_by_chan_id(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)
>> @@ -69,6 +71,8 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s
>>  	return NULL;
>>  }
>>  
>> +#define of_dma_xlate_by_chan_id NULL
>> +
>>  #endif
>>  
>>  #endif /* __LINUX_OF_DMA_H */
>> -- 
>> 1.8.0
>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id
  2013-03-30  8:38   ` Lars-Peter Clausen
@ 2013-04-09 11:28     ` Vinod Koul
  2013-04-09 12:36       ` Lars-Peter Clausen
  0 siblings, 1 reply; 7+ messages in thread
From: Vinod Koul @ 2013-04-09 11:28 UTC (permalink / raw)
  To: Lars-Peter Clausen, Arnd Bergmann
  Cc: Arnd Bergmann, Dan Williams, Jon Hunter, Padmavathi Venna, linux-kernel

On Sat, Mar 30, 2013 at 09:38:54AM +0100, Lars-Peter Clausen wrote:
> On 03/29/2013 10:49 PM, Vinod Koul wrote:
> > On Mon, Mar 25, 2013 at 02:16:51PM +0100, Lars-Peter Clausen wrote:
> >> This patch adds a new generic of dma xlate callback function which will match a
> >> channel by its id.
> > how will the client know which "id" to request? 
> 
> The devicetree tells it, or what exactly do you mean?
Is this global id? Anrd, what does the id mean in DT?
> 
> - Lars
> 
> > 
> >>
> >> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> >> ---
> >>  drivers/dma/of-dma.c   | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> >>  include/linux/of_dma.h |  4 ++++
> >>  2 files changed, 51 insertions(+)
> >>
> >> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
> >> index 00db454..7cad4d7 100644
> >> --- a/drivers/dma/of-dma.c
> >> +++ b/drivers/dma/of-dma.c
> >> @@ -269,3 +269,50 @@ 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 of_dma_filter_by_chan_id_args {
> >> +	struct dma_device *dev;
> >> +	unsigned int chan_id;
> >> +};
> >> +
> >> +static bool of_dma_filter_by_chan_id(struct dma_chan *chan, void *params)
> >> +{
> >> +	struct of_dma_filter_by_chan_id_args *args = params;
> >> +
> >> +	return chan->device == args->dev && chan->chan_id == args->chan_id;
> >> +}
> >> +
> >> +/**
> >> + * of_dma_xlate_by_chan_id - Translate dt property to DMA channel by channel id
> >> + * @dma_spec:	pointer to DMA specifier as found in the device tree
> >> + * @of_dma:	pointer to DMA controller data
> >> + *
> >> + * This function can be used as the of xlate callback for DMA driver which want
> >> + * to match the channel based on the channel id. When using this xlate function
> >> + * the #dma-cells propety of the DMA controller dt node needs to be set to 1.
> >> + * The data parameter of of_dma_controller_register must be a pointer to the
> >> + * dma_device struct the function should match uppon.
> >> + *
> >> + * Returns pointer to appropriate dma channel on success or NULL on error.
> >> + */
> >> +struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec,
> >> +					 struct of_dma *ofdma)
> >> +{
> >> +	struct of_dma_filter_by_chan_id_args args;
> >> +	dma_cap_mask_t cap;
> >> +
> >> +	args.dev = ofdma->of_dma_data;
> >> +	if (!args.dev)
> >> +		return NULL;
> >> +
> >> +	if (dma_spec->args_count != 1)
> >> +		return NULL;
> >> +
> >> +	dma_cap_zero(cap);
> >> +	dma_cap_set(DMA_SLAVE, cap);
> >> +
> >> +	args.chan_id = dma_spec->args[0];
> >> +
> >> +	return dma_request_channel(cap, of_dma_filter_by_chan_id, &args);
> >> +}
> >> +EXPORT_SYMBOL_GPL(of_dma_xlate_by_chan_id);
> >> diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
> >> index ce6a8ab..46732d3 100644
> >> --- a/include/linux/of_dma.h
> >> +++ b/include/linux/of_dma.h
> >> @@ -43,6 +43,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_xlate_by_chan_id(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)
> >> @@ -69,6 +71,8 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s
> >>  	return NULL;
> >>  }
> >>  
> >> +#define of_dma_xlate_by_chan_id NULL
> >> +
> >>  #endif
> >>  
> >>  #endif /* __LINUX_OF_DMA_H */
> >> -- 
> >> 1.8.0
> >>
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id
  2013-04-09 11:28     ` Vinod Koul
@ 2013-04-09 12:36       ` Lars-Peter Clausen
  2013-04-09 13:06         ` Arnd Bergmann
  0 siblings, 1 reply; 7+ messages in thread
From: Lars-Peter Clausen @ 2013-04-09 12:36 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Arnd Bergmann, Dan Williams, Jon Hunter, Padmavathi Venna, linux-kernel

On 04/09/2013 01:28 PM, Vinod Koul wrote:
> On Sat, Mar 30, 2013 at 09:38:54AM +0100, Lars-Peter Clausen wrote:
>> On 03/29/2013 10:49 PM, Vinod Koul wrote:
>>> On Mon, Mar 25, 2013 at 02:16:51PM +0100, Lars-Peter Clausen wrote:
>>>> This patch adds a new generic of dma xlate callback function which will match a
>>>> channel by its id.
>>> how will the client know which "id" to request? 
>>
>> The devicetree tells it, or what exactly do you mean?
> Is this global id? Anrd, what does the id mean in DT?

It's more or less a device specific cookie. And in this case we are using a
1 to 1 mapping to the channel number.

- Lars

>>
>> - Lars
>>
>>>
>>>>
>>>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>>>> ---
>>>>  drivers/dma/of-dma.c   | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>>>>  include/linux/of_dma.h |  4 ++++
>>>>  2 files changed, 51 insertions(+)
>>>>
>>>> diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
>>>> index 00db454..7cad4d7 100644
>>>> --- a/drivers/dma/of-dma.c
>>>> +++ b/drivers/dma/of-dma.c
>>>> @@ -269,3 +269,50 @@ 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 of_dma_filter_by_chan_id_args {
>>>> +	struct dma_device *dev;
>>>> +	unsigned int chan_id;
>>>> +};
>>>> +
>>>> +static bool of_dma_filter_by_chan_id(struct dma_chan *chan, void *params)
>>>> +{
>>>> +	struct of_dma_filter_by_chan_id_args *args = params;
>>>> +
>>>> +	return chan->device == args->dev && chan->chan_id == args->chan_id;
>>>> +}
>>>> +
>>>> +/**
>>>> + * of_dma_xlate_by_chan_id - Translate dt property to DMA channel by channel id
>>>> + * @dma_spec:	pointer to DMA specifier as found in the device tree
>>>> + * @of_dma:	pointer to DMA controller data
>>>> + *
>>>> + * This function can be used as the of xlate callback for DMA driver which want
>>>> + * to match the channel based on the channel id. When using this xlate function
>>>> + * the #dma-cells propety of the DMA controller dt node needs to be set to 1.
>>>> + * The data parameter of of_dma_controller_register must be a pointer to the
>>>> + * dma_device struct the function should match uppon.
>>>> + *
>>>> + * Returns pointer to appropriate dma channel on success or NULL on error.
>>>> + */
>>>> +struct dma_chan *of_dma_xlate_by_chan_id(struct of_phandle_args *dma_spec,
>>>> +					 struct of_dma *ofdma)
>>>> +{
>>>> +	struct of_dma_filter_by_chan_id_args args;
>>>> +	dma_cap_mask_t cap;
>>>> +
>>>> +	args.dev = ofdma->of_dma_data;
>>>> +	if (!args.dev)
>>>> +		return NULL;
>>>> +
>>>> +	if (dma_spec->args_count != 1)
>>>> +		return NULL;
>>>> +
>>>> +	dma_cap_zero(cap);
>>>> +	dma_cap_set(DMA_SLAVE, cap);
>>>> +
>>>> +	args.chan_id = dma_spec->args[0];
>>>> +
>>>> +	return dma_request_channel(cap, of_dma_filter_by_chan_id, &args);
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(of_dma_xlate_by_chan_id);
>>>> diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
>>>> index ce6a8ab..46732d3 100644
>>>> --- a/include/linux/of_dma.h
>>>> +++ b/include/linux/of_dma.h
>>>> @@ -43,6 +43,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_xlate_by_chan_id(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)
>>>> @@ -69,6 +71,8 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s
>>>>  	return NULL;
>>>>  }
>>>>  
>>>> +#define of_dma_xlate_by_chan_id NULL
>>>> +
>>>>  #endif
>>>>  
>>>>  #endif /* __LINUX_OF_DMA_H */
>>>> -- 
>>>> 1.8.0
>>>>
>>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id
  2013-04-09 12:36       ` Lars-Peter Clausen
@ 2013-04-09 13:06         ` Arnd Bergmann
  0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2013-04-09 13:06 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Vinod Koul, Dan Williams, Jon Hunter, Padmavathi Venna, linux-kernel

On Tuesday 09 April 2013, Lars-Peter Clausen wrote:
> On 04/09/2013 01:28 PM, Vinod Koul wrote:
> > On Sat, Mar 30, 2013 at 09:38:54AM +0100, Lars-Peter Clausen wrote:
> >> On 03/29/2013 10:49 PM, Vinod Koul wrote:
> >>> On Mon, Mar 25, 2013 at 02:16:51PM +0100, Lars-Peter Clausen wrote:
> >>>> This patch adds a new generic of dma xlate callback function which will match a
> >>>> channel by its id.
> >>> how will the client know which "id" to request? 
> >>
> >> The devicetree tells it, or what exactly do you mean?
> > Is this global id? Anrd, what does the id mean in DT?
> 
> It's more or less a device specific cookie. And in this case we are using a
> 1 to 1 mapping to the channel number.

To clarify this some more: The slave driver uses a name that is defined in the
binding of for the slave device to request a specific channel. This is typically
something trivial like "rx" or "data" that defines how the slave driver knows
its channel.

This gets passed to the dmaengine core, which looks up a dmaengine driver specific
description of a channel, using the name and the slave device pointer as keys.
Normally this is just a request number, sometimes it can be a combinattion
of request number with some other data like a master number or the DMA direction,
if the dmaengine driver requires that information in order to allocate the channel.

In this specific case, it is the chan_id number, which is correct for any driver
that uses the same number for slave_id and chan_id. It may be an exaggeration 
to call it "generic", since this only works for a few dmaengine drivers, but
it's reasonable to have this kind of helper in common code since there are
multiple drivers with the same characteristic.

	Arnd

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-04-09 13:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-25 13:16 [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Lars-Peter Clausen
2013-03-25 13:16 ` [PATCH 2/2] dma: pl330: Use the generic of_dma_xlate_by_chan_id Lars-Peter Clausen
2013-03-29 21:49 ` [PATCH 1/2] dma: of: Add generic xlate function for matching by channel id Vinod Koul
2013-03-30  8:38   ` Lars-Peter Clausen
2013-04-09 11:28     ` Vinod Koul
2013-04-09 12:36       ` Lars-Peter Clausen
2013-04-09 13:06         ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).