Hi Rob,<br><br><div class="gmail_quote">On 26 August 2011 18:46, Rob Herring <span dir="ltr"><<a href="mailto:robherring2@gmail.com" target="_blank">robherring2@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Thomas,<br>
<div><div></div><div><br>
On 08/26/2011 03:40 AM, Thomas Abraham wrote:<br>
> For PL330 dma controllers instantiated from device tree, the channel<br>
> lookup is based on phandle of the dma controller and dma request id<br>
> specified by the client node. During probe, the private data of each<br>
> channel of the controller is set to point to the device node of the<br>
> dma controller. The 'chan_id' of the each channel is used as the<br>
> dma request id.<br>
><br>
> Client driver requesting dma channels specify the phandle of the<br>
> dma controller and the request id. The pl330 filter function<br>
> converts the phandle to the device node pointer and matches that<br>
> with channel's private data. If a match is found, the request id<br>
> from the client node and the 'chan_id' of the channel is matched.<br>
> A channel is found if both the values match.<br>
><br>
> Signed-off-by: Thomas Abraham <<a href="mailto:thomas.abraham@linaro.org" target="_blank">thomas.abraham@linaro.org</a>><br>
> ---<br>
>  .../devicetree/bindings/dma/arm-pl330.txt          |   42 +++++++++++++<br>
>  drivers/dma/pl330.c                                |   63 +++++++++++++++++++-<br>
>  2 files changed, 103 insertions(+), 2 deletions(-)<br>
>  create mode 100644 Documentation/devicetree/bindings/dma/arm-pl330.txt<br>
><br>
> diff --git a/Documentation/devicetree/bindings/dma/arm-pl330.txt b/Documentation/devicetree/bindings/dma/arm-pl330.txt<br>
> new file mode 100644<br>
> index 0000000..46a8307<br>
> --- /dev/null<br>
> +++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt<br>
> @@ -0,0 +1,42 @@<br>
> +* ARM PrimeCell PL330 DMA Controller<br>
> +<br>
> +The ARM PrimeCell PL330 DMA controller can move blocks of memory contents<br>
> +between memory and peripherals or memory to memory.<br>
> +<br>
> +Required properties:<br>
> +  - compatible: should one or more of the following<br>
> +    - arm,pl330-pdma - For controllers that support mem-to-dev and dev-to-mem<br>
> +      transfers.<br>
> +    - arm,pl330-mdma - For controllers that support mem-to-mem transfers only.<br>
<br>
</div></div>And if they support both? I would think all controllers can support<br>
mem-to-mem. If so, the distinction can be made with the number of requests.<br>
<br></blockquote><div><br>If a controller supports both types of transfer, the device node should not claim compatibility for "arm,pl330-pdma" or "arm,pl330-mdma". Compatible should be "arm,primecell".<br>

 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>
> +    - arm,primecell - should be included for all pl330 dma controller nodes.<br>
> +<br>
> +  - reg: physical base address of the controller and length of memory mapped<br>
> +    region.<br>
> +<br>
> +  - interrupts: interrupt number to the cpu.<br>
> +<br>
> +  - arm,primecell-periphid: should be 0x00041330.<br>
<br>
</div>Should be optional. It's only needed when the h/w value is wrong. This<br>
is already documented in primecell.txt.<br></blockquote><div><br>Ok. This will be made optional.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


<div><br>
> +<br>
> +  - arm,pl330-peri-reqs: number of actual peripheral requests connected to the<br>
> +    dma controller. Maximum value is 32.<br>
<br>
</div>Perhaps could be a bitmask for sparsely populated requests. May not<br>
matter since phandles will define the connections.<br>
<br>
Can be optional and not present means 00 requests (mem-to-mem only).<br>
<div><br></div></blockquote><div><br>As suggested by Russell, this property will be removed and its value will be read from the configuration register.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div>
> +<br>
> +Example: (from Samsung's Exynos4 processor dtsi file)<br>
> +<br>
> +     pdma0: pdma@12680000 {<br>
> +             compatible = "arm,pl330-pdma", "arm,primecell";<br>
> +             reg = <0x12680000 0x1000>;<br>
> +             interrupts = <99>;<br>
> +             arm,primecell-periphid = <0x00041330>;<br>
> +             arm,pl330-peri-reqs = <30>;<br>
> +     };<br>
> +<br>
> +Client drivers (device nodes requiring dma transfers from dev-to-mem or<br>
> +mem-to-dev) should specify the DMA channel numbers using a two-value pair<br>
> +as shown below.<br>
> +<br>
> +  [property name]  = <[phandle of the dma controller] [dma request id]>;<br>
> +<br>
> +      where 'dma request id' is the dma request number which is connected<br>
> +      to the client controller.<br>
> +<br>
> +  Example:  tx-dma-channel = <&pdma0 12>;<br>
<br>
</div>I like this approach. I looked at this some and some PPC platforms do a<br>
node for each channel/request, but this is much more simple and similar<br>
to clock binding approach.<br>
<br>
You need to define the property name. Probably just "dma-channel" is<br>
enough. For peripherals with more than 1, just list them out like when<br>
you have more than 1 interrupt. The order should be defined as part of<br>
that device's binding (i.e. 1st channel is tx and 2nd channel is rx).<br>
<div><div><br></div></div></blockquote><div><br>I am little hesitant to do this the way you suggested. A controller could have dma request lines connected to multiple dma controllers. So the phandle could be different for each dma channel. Also, the client drivers specify the property value for each dma channel requested (the property value gets assigned to chan->private and then used by the filter function to lookup the dma channel). So changing it the way you have suggested would make things complex.<br>

 </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div>
> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c<br>
> index 9732995..984dc18 100644<br>
> --- a/drivers/dma/pl330.c<br>
> +++ b/drivers/dma/pl330.c<br>
> @@ -19,6 +19,7 @@<br>
>  #include <linux/amba/pl330.h><br>
>  #include <linux/pm_runtime.h><br>
>  #include <linux/scatterlist.h><br>
> +#include <linux/of.h><br>
><br>
>  #define NR_DEFAULT_DESC      16<br>
><br>
> @@ -277,6 +278,20 @@ bool pl330_filter(struct dma_chan *chan, void *param)<br>
>       if (chan->device->dev->driver != &pl330_driver.drv)<br>
>               return false;<br>
><br>
> +#ifdef CONFIG_OF<br>
> +     if (chan->device->dev->of_node) {<br>
> +             const __be32 *prop_value;<br>
> +             phandle phandle;<br>
> +             struct device_node *node;<br>
> +<br>
> +             prop_value = ((struct property *)param)->value;<br>
> +             phandle = be32_to_cpup(prop_value++);<br>
> +             node = of_find_node_by_phandle(phandle);<br>
> +             return ((chan->private == node) &&<br>
> +                             (chan->chan_id == be32_to_cpup(prop_value)));<br>
> +     }<br>
> +#endif<br>
> +<br>
>       peri_id = chan->private;<br>
>       return *peri_id == (unsigned)param;<br>
>  }<br>
> @@ -777,6 +792,40 @@ static irqreturn_t pl330_irq_handler(int irq, void *data)<br>
>               return IRQ_NONE;<br>
>  }<br>
><br>
> +#ifdef CONFIG_OF<br>
> +static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev)<br>
> +{<br>
> +     struct dma_pl330_platdata *pdat;<br>
> +     const void *value;<br>
> +<br>
> +     pdat = devm_kzalloc(dev, sizeof(*pdat), GFP_KERNEL);<br>
> +     if (!pdat)<br>
> +             return NULL;<br>
<br>
</div></div>Ideally, we will get rid of platform_data completely in the future, so I<br>
don't think filling it in from DT is the right approach.<br>
<div><br></div></blockquote><div><br>Ok. I will drop the usage of platform data.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div>
> +<br>
> +     value = of_get_property(dev->of_node, "arm,pl330-peri-reqs", NULL);<br>
> +     if (value)<br>
> +             pdat->nr_valid_peri = be32_to_cpup(value);<br>
<br>
</div>Can't you use the u32 helper function here?<br>
<div><br></div></blockquote><div><br>This will go away now since the number of peripherals connected will be read from the configuration register.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div>
> +<br>
> +     if (of_device_is_compatible(dev->of_node, "arm,pl330-pdma")) {<br>
> +             dma_cap_set(DMA_SLAVE, pdat->cap_mask);<br>
> +             dma_cap_set(DMA_CYCLIC, pdat->cap_mask);<br>
> +     } else if (of_device_is_compatible(dev->of_node, "arm,pl330-mdma")) {<br>
> +             dma_cap_set(DMA_MEMCPY, pdat->cap_mask);<br>
> +     } else if (of_device_is_compatible(dev->of_node, "arm,primecell")) {<br>
<br>
</div>I don't think the driver should look at this property. This is really<br>
just for the bus code.<br></blockquote><div><br>The dma capabilities are derived from the compatible value by the driver. Sorry, I do not understand your suggestion for this.<br> <br>Thanks for your help.<br><br>Regards,<br>
Thomas.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<font color="#888888"><br>
Rob<br>
</font><div><div></div><div><br>
</div></div></blockquote></div><br>