From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Abraham Subject: Re: [PATCH 4/6] DMA: PL330: Add device tree support Date: Tue, 30 Aug 2011 17:48:46 +0530 Message-ID: References: <1314348014-2481-1-git-send-email-thomas.abraham@linaro.org> <1314348014-2481-2-git-send-email-thomas.abraham@linaro.org> <1314348014-2481-3-git-send-email-thomas.abraham@linaro.org> <1314348014-2481-4-git-send-email-thomas.abraham@linaro.org> <1314348014-2481-5-git-send-email-thomas.abraham@linaro.org> <4E579C9B.7030807@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7393440117496744424==" Return-path: In-Reply-To: <4E579C9B.7030807-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org To: Rob Herring Cc: boojin.kim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, kgene.kim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org, devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org, jassisinghbrar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org List-Id: devicetree@vger.kernel.org --===============7393440117496744424== Content-Type: multipart/alternative; boundary=000e0cd215e46e1fd904abb8034f --000e0cd215e46e1fd904abb8034f Content-Type: text/plain; charset=ISO-8859-1 Hi Rob, On 26 August 2011 18:46, Rob Herring wrote: > Thomas, > > On 08/26/2011 03:40 AM, Thomas Abraham wrote: > > For PL330 dma controllers instantiated from device tree, the channel > > lookup is based on phandle of the dma controller and dma request id > > specified by the client node. During probe, the private data of each > > channel of the controller is set to point to the device node of the > > dma controller. The 'chan_id' of the each channel is used as the > > dma request id. > > > > Client driver requesting dma channels specify the phandle of the > > dma controller and the request id. The pl330 filter function > > converts the phandle to the device node pointer and matches that > > with channel's private data. If a match is found, the request id > > from the client node and the 'chan_id' of the channel is matched. > > A channel is found if both the values match. > > > > Signed-off-by: Thomas Abraham > > --- > > .../devicetree/bindings/dma/arm-pl330.txt | 42 +++++++++++++ > > drivers/dma/pl330.c | 63 > +++++++++++++++++++- > > 2 files changed, 103 insertions(+), 2 deletions(-) > > create mode 100644 Documentation/devicetree/bindings/dma/arm-pl330.txt > > > > diff --git a/Documentation/devicetree/bindings/dma/arm-pl330.txt > b/Documentation/devicetree/bindings/dma/arm-pl330.txt > > new file mode 100644 > > index 0000000..46a8307 > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt > > @@ -0,0 +1,42 @@ > > +* ARM PrimeCell PL330 DMA Controller > > + > > +The ARM PrimeCell PL330 DMA controller can move blocks of memory > contents > > +between memory and peripherals or memory to memory. > > + > > +Required properties: > > + - compatible: should one or more of the following > > + - arm,pl330-pdma - For controllers that support mem-to-dev and > dev-to-mem > > + transfers. > > + - arm,pl330-mdma - For controllers that support mem-to-mem transfers > only. > > And if they support both? I would think all controllers can support > mem-to-mem. If so, the distinction can be made with the number of requests. > > 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". > > + - arm,primecell - should be included for all pl330 dma controller > nodes. > > + > > + - reg: physical base address of the controller and length of memory > mapped > > + region. > > + > > + - interrupts: interrupt number to the cpu. > > + > > + - arm,primecell-periphid: should be 0x00041330. > > Should be optional. It's only needed when the h/w value is wrong. This > is already documented in primecell.txt. > Ok. This will be made optional. > > > + > > + - arm,pl330-peri-reqs: number of actual peripheral requests connected > to the > > + dma controller. Maximum value is 32. > > Perhaps could be a bitmask for sparsely populated requests. May not > matter since phandles will define the connections. > > Can be optional and not present means 00 requests (mem-to-mem only). > > As suggested by Russell, this property will be removed and its value will be read from the configuration register. > > + > > +Example: (from Samsung's Exynos4 processor dtsi file) > > + > > + pdma0: pdma@12680000 { > > + compatible = "arm,pl330-pdma", "arm,primecell"; > > + reg = <0x12680000 0x1000>; > > + interrupts = <99>; > > + arm,primecell-periphid = <0x00041330>; > > + arm,pl330-peri-reqs = <30>; > > + }; > > + > > +Client drivers (device nodes requiring dma transfers from dev-to-mem or > > +mem-to-dev) should specify the DMA channel numbers using a two-value > pair > > +as shown below. > > + > > + [property name] = <[phandle of the dma controller] [dma request id]>; > > + > > + where 'dma request id' is the dma request number which is > connected > > + to the client controller. > > + > > + Example: tx-dma-channel = <&pdma0 12>; > > I like this approach. I looked at this some and some PPC platforms do a > node for each channel/request, but this is much more simple and similar > to clock binding approach. > > You need to define the property name. Probably just "dma-channel" is > enough. For peripherals with more than 1, just list them out like when > you have more than 1 interrupt. The order should be defined as part of > that device's binding (i.e. 1st channel is tx and 2nd channel is rx). > > 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. > > diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c > > index 9732995..984dc18 100644 > > --- a/drivers/dma/pl330.c > > +++ b/drivers/dma/pl330.c > > @@ -19,6 +19,7 @@ > > #include > > #include > > #include > > +#include > > > > #define NR_DEFAULT_DESC 16 > > > > @@ -277,6 +278,20 @@ bool pl330_filter(struct dma_chan *chan, void > *param) > > if (chan->device->dev->driver != &pl330_driver.drv) > > return false; > > > > +#ifdef CONFIG_OF > > + if (chan->device->dev->of_node) { > > + const __be32 *prop_value; > > + phandle phandle; > > + struct device_node *node; > > + > > + prop_value = ((struct property *)param)->value; > > + phandle = be32_to_cpup(prop_value++); > > + node = of_find_node_by_phandle(phandle); > > + return ((chan->private == node) && > > + (chan->chan_id == > be32_to_cpup(prop_value))); > > + } > > +#endif > > + > > peri_id = chan->private; > > return *peri_id == (unsigned)param; > > } > > @@ -777,6 +792,40 @@ static irqreturn_t pl330_irq_handler(int irq, void > *data) > > return IRQ_NONE; > > } > > > > +#ifdef CONFIG_OF > > +static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev) > > +{ > > + struct dma_pl330_platdata *pdat; > > + const void *value; > > + > > + pdat = devm_kzalloc(dev, sizeof(*pdat), GFP_KERNEL); > > + if (!pdat) > > + return NULL; > > Ideally, we will get rid of platform_data completely in the future, so I > don't think filling it in from DT is the right approach. > > Ok. I will drop the usage of platform data. > > + > > + value = of_get_property(dev->of_node, "arm,pl330-peri-reqs", NULL); > > + if (value) > > + pdat->nr_valid_peri = be32_to_cpup(value); > > Can't you use the u32 helper function here? > > This will go away now since the number of peripherals connected will be read from the configuration register. > > + > > + if (of_device_is_compatible(dev->of_node, "arm,pl330-pdma")) { > > + dma_cap_set(DMA_SLAVE, pdat->cap_mask); > > + dma_cap_set(DMA_CYCLIC, pdat->cap_mask); > > + } else if (of_device_is_compatible(dev->of_node, "arm,pl330-mdma")) > { > > + dma_cap_set(DMA_MEMCPY, pdat->cap_mask); > > + } else if (of_device_is_compatible(dev->of_node, "arm,primecell")) > { > > I don't think the driver should look at this property. This is really > just for the bus code. > The dma capabilities are derived from the compatible value by the driver. Sorry, I do not understand your suggestion for this. Thanks for your help. Regards, Thomas. > Rob > > --000e0cd215e46e1fd904abb8034f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Rob,

On 26 August 2011 18:46, Rob Herr= ing <robherring2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Thomas,

On 08/26/2011 03:40 AM, Thomas Abraham wrote:
> For PL330 dma controllers instantiated from device tree, the channel > lookup is based on phandle of the dma controller and dma request id > specified by the client node. During probe, the private data of each > channel of the controller is set to point to the device node of the > dma controller. The 'chan_id' of the each channel is used as t= he
> dma request id.
>
> Client driver requesting dma channels specify the phandle of the
> dma controller and the request id. The pl330 filter function
> converts the phandle to the device node pointer and matches that
> with channel's private data. If a match is found, the request id > from the client node and the 'chan_id' of the channel is match= ed.
> A channel is found if both the values match.
>
> Signed-off-by: Thomas Abraham <thomas.abraham-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> =A0.../devicetree/bindings/dma/arm-pl330.txt =A0 =A0 =A0 =A0 =A0| =A0 = 42 +++++++++++++
> =A0drivers/dma/pl330.c =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0| =A0 63 +++++++++++++++++++-
> =A02 files changed, 103 insertions(+), 2 deletions(-)
> =A0create mode 100644 Documentation/devicetree/bindings/dma/arm-pl330.= txt
>
> diff --git a/Documentation/devicetree/bindings/dma/arm-pl330.txt b/Doc= umentation/devicetree/bindings/dma/arm-pl330.txt
> new file mode 100644
> index 0000000..46a8307
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/dma/arm-pl330.txt
> @@ -0,0 +1,42 @@
> +* ARM PrimeCell PL330 DMA Controller
> +
> +The ARM PrimeCell PL330 DMA controller can move blocks of memory cont= ents
> +between memory and peripherals or memory to memory.
> +
> +Required properties:
> + =A0- compatible: should one or more of the following
> + =A0 =A0- arm,pl330-pdma - For controllers that support mem-to-dev an= d dev-to-mem
> + =A0 =A0 =A0transfers.
> + =A0 =A0- arm,pl330-mdma - For controllers that support mem-to-mem tr= ansfers only.

And if they support both? I would think all controllers can sup= port
mem-to-mem. If so, the distinction can be made with the number of requests.=


If a controller supports both types of transfer, = the device node should not claim compatibility for "arm,pl330-pdma&quo= t; or "arm,pl330-mdma". Compatible should be "arm,primecell&= quot;.
=A0
> + =A0 =A0- arm,primecell - should be included for all pl330 dma contro= ller nodes.
> +
> + =A0- reg: physical base address of the controller and length of memo= ry mapped
> + =A0 =A0region.
> +
> + =A0- interrupts: interrupt number to the cpu.
> +
> + =A0- arm,primecell-periphid: should be 0x00041330.

Should be optional. It's only needed when the h/w value is wrong.= This
is already documented in primecell.txt.

Ok. This w= ill be made optional.
=A0

> +
> + =A0- arm,pl330-peri-reqs: number of actual peripheral requests conne= cted to the
> + =A0 =A0dma controller. Maximum value is 32.

Perhaps could be a bitmask for sparsely populated requests. May not matter since phandles will define the connections.

Can be optional and not present means 00 requests (mem-to-mem only).


As suggested by Russell, this property= will be removed and its value will be read from the configuration register= .
=A0
> +
> +Example: (from Samsung's Exynos4 processor dtsi file)
> +
> + =A0 =A0 pdma0: pdma@12680000 {
> + =A0 =A0 =A0 =A0 =A0 =A0 compatible =3D "arm,pl330-pdma", &= quot;arm,primecell";
> + =A0 =A0 =A0 =A0 =A0 =A0 reg =3D <0x12680000 0x1000>;
> + =A0 =A0 =A0 =A0 =A0 =A0 interrupts =3D <99>;
> + =A0 =A0 =A0 =A0 =A0 =A0 arm,primecell-periphid =3D <0x00041330>= ;;
> + =A0 =A0 =A0 =A0 =A0 =A0 arm,pl330-peri-reqs =3D <30>;
> + =A0 =A0 };
> +
> +Client drivers (device nodes requiring dma transfers from dev-to-mem = or
> +mem-to-dev) should specify the DMA channel numbers using a two-value = pair
> +as shown below.
> +
> + =A0[property name] =A0=3D <[phandle of the dma controller] [dma r= equest id]>;
> +
> + =A0 =A0 =A0where 'dma request id' is the dma request number = which is connected
> + =A0 =A0 =A0to the client controller.
> +
> + =A0Example: =A0tx-dma-channel =3D <&pdma0 12>;

I like this approach. I looked at this some and some PPC platforms do= a
node for each channel/request, but this is much more simple and similar
to clock binding approach.

You need to define the property name. Probably just "dma-channel"= is
enough. For peripherals with more than 1, just list them out like when
you have more than 1 interrupt. The order should be defined as part of
that device's binding (i.e. 1st channel is tx and 2nd channel is rx).


I am little hesitant to do = this the way you suggested. A controller could have dma request lines conne= cted to multiple dma controllers. So the phandle could be different for eac= h dma channel. Also, the client drivers specify the property value for each= dma channel requested (the property value gets assigned to chan->privat= e and then used by the filter function to lookup the dma channel). So chang= ing it the way you have suggested would make things complex.
=A0
> diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
> index 9732995..984dc18 100644
> --- a/drivers/dma/pl330.c
> +++ b/drivers/dma/pl330.c
> @@ -19,6 +19,7 @@
> =A0#include <linux/amba/pl330.h>
> =A0#include <linux/pm_runtime.h>
> =A0#include <linux/scatterlist.h>
> +#include <linux/of.h>
>
> =A0#define NR_DEFAULT_DESC =A0 =A0 =A016
>
> @@ -277,6 +278,20 @@ bool pl330_filter(struct dma_chan *chan, void *pa= ram)
> =A0 =A0 =A0 if (chan->device->dev->driver !=3D &pl330_dri= ver.drv)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false;
>
> +#ifdef CONFIG_OF
> + =A0 =A0 if (chan->device->dev->of_node) {
> + =A0 =A0 =A0 =A0 =A0 =A0 const __be32 *prop_value;
> + =A0 =A0 =A0 =A0 =A0 =A0 phandle phandle;
> + =A0 =A0 =A0 =A0 =A0 =A0 struct device_node *node;
> +
> + =A0 =A0 =A0 =A0 =A0 =A0 prop_value =3D ((struct property *)param)-&g= t;value;
> + =A0 =A0 =A0 =A0 =A0 =A0 phandle =3D be32_to_cpup(prop_value++);
> + =A0 =A0 =A0 =A0 =A0 =A0 node =3D of_find_node_by_phandle(phandle); > + =A0 =A0 =A0 =A0 =A0 =A0 return ((chan->private =3D=3D node) &= &
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (chan->ch= an_id =3D=3D be32_to_cpup(prop_value)));
> + =A0 =A0 }
> +#endif
> +
> =A0 =A0 =A0 peri_id =3D chan->private;
> =A0 =A0 =A0 return *peri_id =3D=3D (unsigned)param;
> =A0}
> @@ -777,6 +792,40 @@ static irqreturn_t pl330_irq_handler(int irq, voi= d *data)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 return IRQ_NONE;
> =A0}
>
> +#ifdef CONFIG_OF
> +static struct dma_pl330_platdata *pl330_parse_dt(struct device *dev)<= br> > +{
> + =A0 =A0 struct dma_pl330_platdata *pdat;
> + =A0 =A0 const void *value;
> +
> + =A0 =A0 pdat =3D devm_kzalloc(dev, sizeof(*pdat), GFP_KERNEL);
> + =A0 =A0 if (!pdat)
> + =A0 =A0 =A0 =A0 =A0 =A0 return NULL;

Ideally, we will get rid of platform_data completely in the fut= ure, so I
don't think filling it in from DT is the right approach.


Ok. I will drop the usage of platform = data.
=A0
> +
> + =A0 =A0 value =3D of_get_property(dev->of_node, "arm,pl330-p= eri-reqs", NULL);
> + =A0 =A0 if (value)
> + =A0 =A0 =A0 =A0 =A0 =A0 pdat->nr_valid_peri =3D be32_to_cpup(valu= e);

Can't you use the u32 helper function here?


This will go away now since the number= of peripherals connected will be read from the configuration register.
= =A0
> +
> + =A0 =A0 if (of_device_is_compatible(dev->of_node, "arm,pl330= -pdma")) {
> + =A0 =A0 =A0 =A0 =A0 =A0 dma_cap_set(DMA_SLAVE, pdat->cap_mask); > + =A0 =A0 =A0 =A0 =A0 =A0 dma_cap_set(DMA_CYCLIC, pdat->cap_mask);<= br> > + =A0 =A0 } else if (of_device_is_compatible(dev->of_node, "ar= m,pl330-mdma")) {
> + =A0 =A0 =A0 =A0 =A0 =A0 dma_cap_set(DMA_MEMCPY, pdat->cap_mask);<= br> > + =A0 =A0 } else if (of_device_is_compatible(dev->of_node, "ar= m,primecell")) {

I don't think the driver should look at this property. This is re= ally
just for the bus code.

The dma capabilities are de= rived from the compatible value by the driver. Sorry, I do not understand y= our suggestion for this.
=A0
Thanks for your help.

Regards, Thomas.


Rob


--000e0cd215e46e1fd904abb8034f-- --===============7393440117496744424== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org https://lists.ozlabs.org/listinfo/devicetree-discuss --===============7393440117496744424==--