Re: [PATCH v2 3/3] DMA: shdma: add DT support

2013-06-18 Thread Guennadi Liakhovetski
Hi Arnd

On Mon, 17 Jun 2013, Arnd Bergmann wrote:

 On Thursday 06 June 2013, Guennadi Liakhovetski wrote:
  +Required properties:
  +- dmas:a list of [DMA controller phandle] [MID/RID value] 
  pairs
  +- dma-names:   a list of DMA channel names, one per dmas entry
 
 Looks ok to me, although it might be helpful to clarify what MID/RID means,
 by expanding the acronym and describing whether one needs to pass both
 or just one of them. If both, what is the bit pattern?

One word: magic. MID/RID is what that value is called in the datasheet. 
E.g. on APE6 (r8a73a4) it is indeed divided into 2 fields - 2 and 6 bits 
for RID and MID respectively, I _guess_ 2 bits are to select a channel 
within a slave device and 6 bits to pick up one of slaves, but that 
doesn't fit with a slave with 8 channels (HSI), there are also slave 
devices with different MID values, so, those values are really better 
considered as a single magic value - an 8-bit channel request handle, 
which is also how they are listed in a reference table.

* services would have to provide their own filters, which first would 
  check
* the device driver, similar to how other DMAC drivers, e.g., 
  sa11x0-dma.c, do
* this, and only then, in case of a match, call this common filter.
  + * NOTE 2: This filter function is also used in the DT case by 
  shdma_xlate().
  + * In that case the MID-RID value is used for slave channel filtering and 
  is
  + * passed to this function in the arg parameter.
*/
   bool shdma_chan_filter(struct dma_chan *chan, void *arg)
   {
  struct shdma_chan *schan = to_shdma_chan(chan);
  struct shdma_dev *sdev = to_shdma_dev(schan-dma_chan.device);
  const struct shdma_ops *ops = sdev-ops;
  -   int slave_id = (int)arg;
  +   int match = (int)arg;
  int ret;
   
  -   if (slave_id  0)
  +   if (match  0)
  /* No slave requested - arbitrary channel */
  return true;
   
  -   if (slave_id = slave_num)
  +   if (!schan-dev-of_node  match = slave_num)
  return false;
   
  -   ret = ops-set_slave(schan, slave_id, true);
  +   ret = ops-set_slave(schan, match, true);
  if (ret  0)
  return false;
 
 This is complicated by the fact that you are using the same function for
 two entirely different purposes. It would be easier to have a separate
 filter for the DT case, rather than reusing the one that uses the slave_id
 as an argument.

Hm, yes, I was considering either making 2 functions or reusing one, but 
it's really the same code with only difference - the DT version wouldn't 
have the  slave_num check. So, I decided to use a single function 
renaming slave_id to a neutral match. You really think it's become too 
complex and should be copied for clarity?

  @@ -867,6 +883,29 @@ void shdma_chan_remove(struct shdma_chan *schan)
   }
   EXPORT_SYMBOL(shdma_chan_remove);
   
  +struct dma_chan *shdma_xlate(struct of_phandle_args *dma_spec,
  +struct of_dma *ofdma)
  +{
  +   struct shdma_dev *sdev = ofdma-of_dma_data;
  +   u32 id = dma_spec-args[0];
  +   dma_cap_mask_t mask;
  +   struct dma_chan *chan;
  +
  +   if (dma_spec-args_count != 1 || !sdev)
  +   return NULL;
  +
  +   dma_cap_zero(mask);
  +   /* Only slave DMA channels can be allocated via DT */
  +   dma_cap_set(DMA_SLAVE, mask);
  +
  +   chan = dma_request_channel(mask, shdma_chan_filter, (void *)id);
  +   if (chan)
  +   to_shdma_chan(chan)-hw_req = id;
  +
  +   return chan;
  +}
  +EXPORT_SYMBOL(shdma_xlate);
 
 I would suggest keeping this to the drivers/dma/sh/shdma.c file
 and not exporting it. The sudma would use a different binding anyway.

Ok, can do that and then see, how different sudma's .xlate() function will 
be. If it's the same we can make this common again.

  +/*
  + * Find a slave channel configuration from the contoller list by either a 
  slave
  + * ID in the non-DT case, or by a MID/RID value in the DT case
  + */
   static const struct sh_dmae_slave_config *dmae_find_slave(
  -   struct sh_dmae_chan *sh_chan, int slave_id)
  +   struct sh_dmae_chan *sh_chan, int match)
   {
  struct sh_dmae_device *shdev = to_sh_dev(sh_chan);
  struct sh_dmae_pdata *pdata = shdev-pdata;
  const struct sh_dmae_slave_config *cfg;
  int i;
   
  -   if (slave_id = SH_DMA_SLAVE_NUMBER)
  -   return NULL;
  +   if (!sh_chan-shdma_chan.dev-of_node) {
  +   if (match = SH_DMA_SLAVE_NUMBER)
  +   return NULL;
   
  -   for (i = 0, cfg = pdata-slave; i  pdata-slave_num; i++, cfg++)
  -   if (cfg-slave_id == slave_id)
  -   return cfg;
  +   for (i = 0, cfg = pdata-slave; i  pdata-slave_num; i++, 
  cfg++)
  +   if (cfg-slave_id == match)
  +   return cfg;
  +   } else {
  +   for (i = 0, cfg = pdata-slave; i  pdata-slave_num; i++, 
  cfg++)
  +   if (cfg-mid_rid == match) {
  

Re: [PATCH v2 3/3] DMA: shdma: add DT support

2013-06-18 Thread Arnd Bergmann
On Tuesday 18 June 2013, Guennadi Liakhovetski wrote:
 Hi Arnd
 
 On Mon, 17 Jun 2013, Arnd Bergmann wrote:
 
  On Thursday 06 June 2013, Guennadi Liakhovetski wrote:
   +Required properties:
   +- dmas:  a list of [DMA controller phandle] [MID/RID value] 
   pairs
   +- dma-names: a list of DMA channel names, one per dmas entry
  
  Looks ok to me, although it might be helpful to clarify what MID/RID means,
  by expanding the acronym and describing whether one needs to pass both
  or just one of them. If both, what is the bit pattern?
 
 One word: magic. MID/RID is what that value is called in the datasheet. 
 E.g. on APE6 (r8a73a4) it is indeed divided into 2 fields - 2 and 6 bits 
 for RID and MID respectively, I _guess_ 2 bits are to select a channel 
 within a slave device and 6 bits to pick up one of slaves, but that 
 doesn't fit with a slave with 8 channels (HSI), there are also slave 
 devices with different MID values, so, those values are really better 
 considered as a single magic value - an 8-bit channel request handle, 
 which is also how they are listed in a reference table.

Ok.

 * services would have to provide their own filters, which first would 
   check
 * the device driver, similar to how other DMAC drivers, e.g., 
   sa11x0-dma.c, do
 * this, and only then, in case of a match, call this common filter.
   + * NOTE 2: This filter function is also used in the DT case by 
   shdma_xlate().
   + * In that case the MID-RID value is used for slave channel filtering 
   and is
   + * passed to this function in the arg parameter.
 */
bool shdma_chan_filter(struct dma_chan *chan, void *arg)
{
 struct shdma_chan *schan = to_shdma_chan(chan);
 struct shdma_dev *sdev = to_shdma_dev(schan-dma_chan.device);
 const struct shdma_ops *ops = sdev-ops;
   - int slave_id = (int)arg;
   + int match = (int)arg;
 int ret;

   - if (slave_id  0)
   + if (match  0)
 /* No slave requested - arbitrary channel */
 return true;

   - if (slave_id = slave_num)
   + if (!schan-dev-of_node  match = slave_num)
 return false;

   - ret = ops-set_slave(schan, slave_id, true);
   + ret = ops-set_slave(schan, match, true);
 if (ret  0)
 return false;
  
  This is complicated by the fact that you are using the same function for
  two entirely different purposes. It would be easier to have a separate
  filter for the DT case, rather than reusing the one that uses the slave_id
  as an argument.
 
 Hm, yes, I was considering either making 2 functions or reusing one, but 
 it's really the same code with only difference - the DT version wouldn't 
 have the  slave_num check. So, I decided to use a single function 
 renaming slave_id to a neutral match. You really think it's become too 
 complex and should be copied for clarity?

I think it would be easier to understand if you have two functions, but
it's not very important. Especially if you make the new function specific
to shdma, that would be clearer.

   @@ -867,6 +883,29 @@ void shdma_chan_remove(struct shdma_chan *schan)
}
EXPORT_SYMBOL(shdma_chan_remove);

   +struct dma_chan *shdma_xlate(struct of_phandle_args *dma_spec,
   +  struct of_dma *ofdma)
   +{
   + struct shdma_dev *sdev = ofdma-of_dma_data;
   + u32 id = dma_spec-args[0];
   + dma_cap_mask_t mask;
   + struct dma_chan *chan;
   +
   + if (dma_spec-args_count != 1 || !sdev)
   + return NULL;
   +
   + dma_cap_zero(mask);
   + /* Only slave DMA channels can be allocated via DT */
   + dma_cap_set(DMA_SLAVE, mask);
   +
   + chan = dma_request_channel(mask, shdma_chan_filter, (void *)id);
   + if (chan)
   + to_shdma_chan(chan)-hw_req = id;
   +
   + return chan;
   +}
   +EXPORT_SYMBOL(shdma_xlate);
  
  I would suggest keeping this to the drivers/dma/sh/shdma.c file
  and not exporting it. The sudma would use a different binding anyway.
 
 Ok, can do that and then see, how different sudma's .xlate() function will 
 be. If it's the same we can make this common again.

I hope we can get rid of the need for calling dma_request_channel() from
xlate soon, since that is a bit silly anyway. Ideally you would just pick
the right channel of the dma_device (or the first free one, depending on
the driver) and return that from xlate.

  The pdata and slave_id should really not be needed here for the lookup in 
  the DT
  case. Is this just temporary until all slave drivers use 
  dmaenging_slave_config
  to pass the address? That should be clarified in a comment.
 
 Also with DT we still use platform data, passed to the driver using 
 auxdata. This function finds a suitable struct sh_dmae_slave_config 
 channel configuration entry in the platform data and returns it to the 
 caller. I don't think this can be avoided without carrying all the 
 platform data over to DT.

I think that should be done anyway. A lot of the data can just be hardcoded
in the 

Re: [PATCH v2 3/3] DMA: shdma: add DT support

2013-06-17 Thread Arnd Bergmann
On Thursday 06 June 2013, Guennadi Liakhovetski wrote:
 +Required properties:
 +- dmas:  a list of [DMA controller phandle] [MID/RID value] 
 pairs
 +- dma-names: a list of DMA channel names, one per dmas entry

Looks ok to me, although it might be helpful to clarify what MID/RID means,
by expanding the acronym and describing whether one needs to pass both
or just one of them. If both, what is the bit pattern?

   * services would have to provide their own filters, which first would check
   * the device driver, similar to how other DMAC drivers, e.g., sa11x0-dma.c, 
 do
   * this, and only then, in case of a match, call this common filter.
 + * NOTE 2: This filter function is also used in the DT case by shdma_xlate().
 + * In that case the MID-RID value is used for slave channel filtering and is
 + * passed to this function in the arg parameter.
   */
  bool shdma_chan_filter(struct dma_chan *chan, void *arg)
  {
   struct shdma_chan *schan = to_shdma_chan(chan);
   struct shdma_dev *sdev = to_shdma_dev(schan-dma_chan.device);
   const struct shdma_ops *ops = sdev-ops;
 - int slave_id = (int)arg;
 + int match = (int)arg;
   int ret;
  
 - if (slave_id  0)
 + if (match  0)
   /* No slave requested - arbitrary channel */
   return true;
  
 - if (slave_id = slave_num)
 + if (!schan-dev-of_node  match = slave_num)
   return false;
  
 - ret = ops-set_slave(schan, slave_id, true);
 + ret = ops-set_slave(schan, match, true);
   if (ret  0)
   return false;

This is complicated by the fact that you are using the same function for
two entirely different purposes. It would be easier to have a separate
filter for the DT case, rather than reusing the one that uses the slave_id
as an argument.

 @@ -867,6 +883,29 @@ void shdma_chan_remove(struct shdma_chan *schan)
  }
  EXPORT_SYMBOL(shdma_chan_remove);
  
 +struct dma_chan *shdma_xlate(struct of_phandle_args *dma_spec,
 +  struct of_dma *ofdma)
 +{
 + struct shdma_dev *sdev = ofdma-of_dma_data;
 + u32 id = dma_spec-args[0];
 + dma_cap_mask_t mask;
 + struct dma_chan *chan;
 +
 + if (dma_spec-args_count != 1 || !sdev)
 + return NULL;
 +
 + dma_cap_zero(mask);
 + /* Only slave DMA channels can be allocated via DT */
 + dma_cap_set(DMA_SLAVE, mask);
 +
 + chan = dma_request_channel(mask, shdma_chan_filter, (void *)id);
 + if (chan)
 + to_shdma_chan(chan)-hw_req = id;
 +
 + return chan;
 +}
 +EXPORT_SYMBOL(shdma_xlate);

I would suggest keeping this to the drivers/dma/sh/shdma.c file
and not exporting it. The sudma would use a different binding anyway.

 +/*
 + * Find a slave channel configuration from the contoller list by either a 
 slave
 + * ID in the non-DT case, or by a MID/RID value in the DT case
 + */
  static const struct sh_dmae_slave_config *dmae_find_slave(
 - struct sh_dmae_chan *sh_chan, int slave_id)
 + struct sh_dmae_chan *sh_chan, int match)
  {
   struct sh_dmae_device *shdev = to_sh_dev(sh_chan);
   struct sh_dmae_pdata *pdata = shdev-pdata;
   const struct sh_dmae_slave_config *cfg;
   int i;
  
 - if (slave_id = SH_DMA_SLAVE_NUMBER)
 - return NULL;
 + if (!sh_chan-shdma_chan.dev-of_node) {
 + if (match = SH_DMA_SLAVE_NUMBER)
 + return NULL;
  
 - for (i = 0, cfg = pdata-slave; i  pdata-slave_num; i++, cfg++)
 - if (cfg-slave_id == slave_id)
 - return cfg;
 + for (i = 0, cfg = pdata-slave; i  pdata-slave_num; i++, 
 cfg++)
 + if (cfg-slave_id == match)
 + return cfg;
 + } else {
 + for (i = 0, cfg = pdata-slave; i  pdata-slave_num; i++, 
 cfg++)
 + if (cfg-mid_rid == match) {
 + sh_chan-shdma_chan.slave_id = cfg-slave_id;
 + return cfg;
 + }
 + }

The pdata and slave_id should really not be needed here for the lookup in the DT
case. Is this just temporary until all slave drivers use dmaenging_slave_config
to pass the address? That should be clarified in a comment.

Arnd
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[PATCH v2 3/3] DMA: shdma: add DT support

2013-06-06 Thread Guennadi Liakhovetski
This patch adds Device Tree support to the shdma driver. No special DT
properties are used, only standard DMA DT bindings are implemented. Since
shdma controllers reside on SoCs, their configuration is SoC-specific and
shall be passed to the driver from the SoC platform data, using the
auxdata procedure.

Signed-off-by: Guennadi Liakhovetski g.liakhovetski+rene...@gmail.com
---

v2: merge DT binding documentation into the patch

 Documentation/devicetree/bindings/dma/shdma.txt |   61 +++
 drivers/dma/sh/shdma-base.c |   51 +--
 drivers/dma/sh/shdma.c  |   44 ++--
 include/linux/shdma-base.h  |5 ++
 4 files changed, 149 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/shdma.txt

diff --git a/Documentation/devicetree/bindings/dma/shdma.txt 
b/Documentation/devicetree/bindings/dma/shdma.txt
new file mode 100644
index 000..f99618e
--- /dev/null
+++ b/Documentation/devicetree/bindings/dma/shdma.txt
@@ -0,0 +1,61 @@
+* SHDMA Device Tree bindings
+
+Only generic DMA controller bindings are used for SHDMA DT nodes.
+
+* DMA controller
+
+Required properties:
+- compatible:  should be renesas,shdma
+- #dma-cells:  should be 1, see dmas property below
+
+Optional properties (currently unused):
+- dma-channels:number of DMA channels
+- dma-requests:number of DMA request signals
+
+Example:
+   dma0: shdma@fe20 {
+   compatible = renesas,shdma;
+   reg = 0xfe20 0x89e0;
+   interrupt-parent = gic;
+   interrupts = 0 129 4
+   0 109 4
+   0 110 4
+   0 111 4
+   0 112 4
+   0 113 4
+   0 114 4
+   0 115 4
+   0 116 4
+   0 117 4
+   0 118 4
+   0 119 4
+   0 120 4
+   0 121 4
+   0 122 4
+   0 123 4
+   0 124 4
+   0 125 4
+   0 126 4
+   0 127 4
+   0 128 4;
+   interrupt-names = error,
+   ch0, ch1, ch2, ch3,
+   ch4, ch5, ch6, ch7,
+   ch8, ch9, ch10, ch11,
+   ch12, ch13, ch14, ch15,
+   ch16, ch17, ch18, ch19;
+   #dma-cells = 1;
+   dma-channels = 20;
+   dma-requests = 256;
+   };
+
+* DMA client
+
+Required properties:
+- dmas:a list of [DMA controller phandle] [MID/RID value] 
pairs
+- dma-names:   a list of DMA channel names, one per dmas entry
+
+Example:
+   dmas = dma0 0xd1
+   dma0 0xd2;
+   dma-names = tx, rx;
diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
index 4acb85a..4fd8293 100644
--- a/drivers/dma/sh/shdma-base.c
+++ b/drivers/dma/sh/shdma-base.c
@@ -14,6 +14,8 @@
  */
 
 #include linux/delay.h
+#include linux/of.h
+#include linux/of_dma.h
 #include linux/shdma-base.h
 #include linux/dmaengine.h
 #include linux/init.h
@@ -175,7 +177,18 @@ static int shdma_setup_slave(struct shdma_chan *schan, int 
slave_id)
 {
struct shdma_dev *sdev = to_shdma_dev(schan-dma_chan.device);
const struct shdma_ops *ops = sdev-ops;
-   int ret;
+   int ret, match;
+
+   if (schan-dev-of_node) {
+   match = schan-hw_req;
+   ret = ops-set_slave(schan, match, true);
+   if (ret  0)
+   return ret;
+
+   slave_id = schan-slave_id;
+   } else {
+   match = slave_id;
+   }
 
if (slave_id  0 || slave_id = slave_num)
return -EINVAL;
@@ -183,7 +196,7 @@ static int shdma_setup_slave(struct shdma_chan *schan, int 
slave_id)
if (test_and_set_bit(slave_id, shdma_slave_used))
return -EBUSY;
 
-   ret = ops-set_slave(schan, slave_id, false);
+   ret = ops-set_slave(schan, match, false);
if (ret  0) {
clear_bit(slave_id, shdma_slave_used);
return ret;
@@ -206,23 +219,26 @@ static int shdma_setup_slave(struct shdma_chan *schan, 
int slave_id)
  * services would have to provide their own filters, which first would check
  * the device driver, similar to how other DMAC drivers, e.g., sa11x0-dma.c, do
  * this, and only then, in case of a match, call this common filter.
+ * NOTE 2: This filter function is also used in the DT case by shdma_xlate().
+ * In that case the MID-RID value is used for slave