All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Álvaro Fernández Rojas" <noltari@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC v2 02/15] dma: add channels support
Date: Tue, 20 Feb 2018 20:00:50 +0100	[thread overview]
Message-ID: <03932e12-5b25-861a-3d3f-6027bf6559de@gmail.com> (raw)
In-Reply-To: <CAPnjgZ0G2KrxGnWVzQV6X0CpjYH-eP2h7_uuzTAX4PtP=g8q=w@mail.gmail.com>

Hi Simon,

El 20/02/2018 a las 19:49, Simon Glass escribió:
> Hi Alvaro,
>
> On 20 February 2018 at 10:46, Álvaro Fernández Rojas <noltari@gmail.com> wrote:
>> This adds channels support for dma controllers that have multiple channels
>> which can transfer data to/from different devices (enet, usb...).
>>
>> Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
>> ---
>>   v2: Introduce changes reported by Vignesh:
>>    - Respect current dma implementation.
>>    - Let dma_memcpy find a compatible dma device.
>>
>>   drivers/dma/Kconfig      |   7 ++
>>   drivers/dma/dma-uclass.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++
>>   include/dma-uclass.h     |  77 +++++++++++++++++++++
>>   include/dma.h            | 169 ++++++++++++++++++++++++++++++++++++++++++++
>>   4 files changed, 430 insertions(+)
>>
>> diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
>> index 1b92c7789d..21b2c0dcaa 100644
>> --- a/drivers/dma/Kconfig
>> +++ b/drivers/dma/Kconfig
>> @@ -12,6 +12,13 @@ config DMA
>>            buses that is used to transfer data to and from memory.
>>            The uclass interface is defined in include/dma.h.
>>
>> +config DMA_CHANNELS
>> +       bool "Enable DMA channels support"
>> +       depends on DMA
>> +       help
>> +         Enable channels support for DMA. Some DMA controllers have multiple
>> +         channels which can either transfer data to/from different devices.
>> +
>>   config TI_EDMA3
>>          bool "TI EDMA3 driver"
>>          help
>> diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c
>> index 6fd4e1b35d..a16c3a786c 100644
>> --- a/drivers/dma/dma-uclass.c
>> +++ b/drivers/dma/dma-uclass.c
>> @@ -15,10 +15,187 @@
>>   #include <dm/device-internal.h>
>>   #include <dma.h>
>>   #include <dma-uclass.h>
>> +#include <dt-structs.h>
>>   #include <errno.h>
>>
>>   DECLARE_GLOBAL_DATA_PTR;
>>
>> +#ifdef CONFIG_DMA_CHANNELS
>> +static inline struct dma_ops *dma_dev_ops(struct udevice *dev)
>> +{
>> +       return (struct dma_ops *)dev->driver->ops;
>> +}
>> +
>> +# if CONFIG_IS_ENABLED(OF_CONTROL)
>> +#  if CONFIG_IS_ENABLED(OF_PLATDATA)
>> +int dma_get_by_index_platdata(struct udevice *dev, int index,
>> +                             struct phandle_2_cell *cells, struct dma *dma)
>> +{
>> +       int ret;
>> +
>> +       if (index != 0)
>> +               return -ENOSYS;
>> +       ret = uclass_get_device(UCLASS_DMA, 0, &dma->dev);
>> +       if (ret)
>> +               return ret;
>> +       dma->id = cells[0].id;
>> +
>> +       return 0;
>> +}
>> +#  else
>> +static int dma_of_xlate_default(struct dma *dma,
>> +                               struct fdtdec_phandle_args *args)
>> +{
>> +       debug("%s(dma=%p)\n", __func__, dma);
>> +
>> +       if (args->args_count > 1) {
>> +               pr_err("Invaild args_count: %d\n", args->args_count);
>> +               return -EINVAL;
>> +       }
>> +
>> +       if (args->args_count)
>> +               dma->id = args->args[0];
>> +       else
>> +               dma->id = 0;
>> +
>> +       return 0;
>> +}
>> +
>> +int dma_get_by_index(struct udevice *dev, int index, struct dma *dma)
>> +{
>> +       int ret;
>> +       struct fdtdec_phandle_args args;
>> +       struct udevice *dev_dma;
>> +       struct dma_ops *ops;
>> +
>> +       debug("%s(dev=%p, index=%d, dma=%p)\n", __func__, dev, index, dma);
>> +
>> +       assert(dma);
>> +       ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
>> +                                            "dmas", "#dma-cells", 0, index,
>> +                                            &args);
> Can you please use the livetree API? E.g. see dev_read_phandle_with_args()
>
> Also please move this into an ofdata_to_platdata function rather than
> doing it each time this function is called.
Ok, I did this some time ago and I used an older version of clk-uclass 
as a starting point.
I will switch to livetree in the next patch version.
>
>> +       if (ret) {
>> +               pr_err("%s: fdtdec_parse_phandle_with_args failed: err=%d\n",
>> +                     __func__, ret);
>> +               return ret;
>> +       }
>> +
>> +       ret = uclass_get_device_by_of_offset(UCLASS_DMA, args.node, &dev_dma);
>> +       if (ret) {
>> +               pr_err("%s: uclass_get_device_by_of_offset failed: err=%d\n",
>> +                     __func__, ret);
>> +               return ret;
>> +       }
>> +
>> +       dma->dev = dev_dma;
>> +
>> +       ops = dma_dev_ops(dev_dma);
>> +
>> +       if (ops->of_xlate)
>> +               ret = ops->of_xlate(dma, &args);
>> +       else
>> +               ret = dma_of_xlate_default(dma, &args);
>> +       if (ret) {
>> +               pr_err("of_xlate() failed: %d\n", ret);
>> +               return ret;
>> +       }
>> +
>> +       return dma_request(dev_dma, dma);
>> +}
>> +#  endif /* OF_PLATDATA */
>> +
>> +int dma_get_by_name(struct udevice *dev, const char *name, struct dma *dma)
>> +{
>> +       int index;
>> +
>> +       debug("%s(dev=%p, name=%s, dma=%p)\n", __func__, dev, name, dma);
>> +
>> +       index = fdt_stringlist_search(gd->fdt_blob, dev_of_offset(dev),
>> +                                     "dma-names", name);
> dev_read...
Ok.
>
>> +       if (index < 0) {
>> +               pr_err("fdt_stringlist_search() failed: %d\n", index);
>> +               return index;
>> +       }
>> +
>> +       return dma_get_by_index(dev, index, dma);
>> +}
>> +# endif /* OF_CONTROL */
>> +
>> +int dma_request(struct udevice *dev, struct dma *dma)
>> +{
>> +       struct dma_ops *ops = dma_dev_ops(dev);
>> +
>> +       debug("%s(dev=%p, dma=%p)\n", __func__, dev, dma);
>> +
>> +       dma->dev = dev;
>> +
>> +       if (!ops->request)
>> +               return 0;
>> +
>> +       return ops->request(dma);
>> +}
>> +
>> +int dma_free(struct dma *dma)
>> +{
>> +       struct dma_ops *ops = dma_dev_ops(dma->dev);
>> +
>> +       debug("%s(dma=%p)\n", __func__, dma);
>> +
>> +       if (!ops->free)
>> +               return 0;
>> +
>> +       return ops->free(dma);
>> +}
>> +
>> +int dma_enable(struct dma *dma)
>> +{
>> +       struct dma_ops *ops = dma_dev_ops(dma->dev);
>> +
>> +       debug("%s(dma=%p)\n", __func__, dma);
>> +
>> +       if (!ops->enable)
>> +               return -ENOSYS;
>> +
>> +       return ops->enable(dma);
>> +}
>> +
>> +int dma_disable(struct dma *dma)
>> +{
>> +       struct dma_ops *ops = dma_dev_ops(dma->dev);
>> +
>> +       debug("%s(dma=%p)\n", __func__, dma);
>> +
>> +       if (!ops->disable)
>> +               return -ENOSYS;
>> +
>> +       return ops->disable(dma);
>> +}
>> +
>> +int dma_receive(struct dma *dma, void **dst)
>> +{
>> +       struct dma_ops *ops = dma_dev_ops(dma->dev);
>> +
>> +       debug("%s(dma=%p)\n", __func__, dma);
>> +
>> +       if (!ops->receive)
>> +               return -1;
>> +
>> +       return ops->receive(dma, dst);
>> +}
>> +
>> +int dma_send(struct dma *dma, void *src, size_t len)
>> +{
>> +       struct dma_ops *ops = dma_dev_ops(dma->dev);
>> +
>> +       debug("%s(dma=%p)\n", __func__, dma);
>> +
>> +       if (!ops->send)
>> +               return -1;
>> +
>> +       return ops->send(dma, src, len);
>> +}
>> +#endif /* CONFIG_DMA_CHANNELS */
>> +
>>   int dma_get_device(u32 transfer_type, struct udevice **devp)
>>   {
>>          struct udevice *dev;
>> diff --git a/include/dma-uclass.h b/include/dma-uclass.h
>> index e29ad103f2..5faec69207 100644
>> --- a/include/dma-uclass.h
>> +++ b/include/dma-uclass.h
>> @@ -12,6 +12,7 @@
>>   /* See dma.h for background documentation. */
>>
>>   #include <dma.h>
>> +#include <fdtdec.h>
>>
>>   /*
>>    * struct dma_ops - Driver model DMA operations
>> @@ -20,6 +21,82 @@
>>    * driver model.
>>    */
>>   struct dma_ops {
>> +#ifdef CONFIG_DMA_CHANNELS
>> +       /**
>> +        * of_xlate - Translate a client's device-tree (OF) DMA specifier.
>> +        *
>> +        * The DMA core calls this function as the first step in implementing
>> +        * a client's dma_get_by_*() call.
>> +        *
>> +        * If this function pointer is set to NULL, the DMA core will use a
>> +        * default implementation, which assumes #dma-cells = <1>, and that
>> +        * the DT cell contains a simple integer DMA Channel.
>> +        *
>> +        * At present, the DMA API solely supports device-tree. If this
>> +        * changes, other xxx_xlate() functions may be added to support those
>> +        * other mechanisms.
>> +        *
>> +        * @dma: The dma struct to hold the translation result.
>> +        * @args:       The dma specifier values from device tree.
>> +        * @return 0 if OK, or a negative error code.
>> +        */
>> +       int (*of_xlate)(struct dma *dma,
>> +                       struct fdtdec_phandle_args *args);
> Use new livetree struct here
Ok.
>
> Regards,
> Simon
Regards,
Álvaro.

  reply	other threads:[~2018-02-20 19:00 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-12 16:38 [U-Boot] [RFC 00/14] bmips: add bcm6348-enet support Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 01/14] dma: add dma channels support and improve uclass Álvaro Fernández Rojas
2018-02-20  8:24   ` Vignesh R
2018-02-12 16:38 ` [U-Boot] [RFC 02/14] dma: add bcm6348-iudma support Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 03/14] bmips: bcm6338: " Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 04/14] bmips: bcm6348: " Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 05/14] bmips: bcm6358: " Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 06/14] phy: add support for internal phys Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 07/14] net: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 08/14] bmips: bcm6338: " Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 09/14] bmips: enable f@st1704 enet support Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 10/14] bmips: bcm6348: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 11/14] bmips: enable ct-5361 enet support Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 12/14] bmips: bcm6358: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 13/14] bmips: enable hg556a enet support Álvaro Fernández Rojas
2018-02-12 16:38 ` [U-Boot] [RFC 14/14] bmips: enable nb4-ser " Álvaro Fernández Rojas
2018-02-19 17:26 ` [U-Boot] [RFC 00/14] bmips: add bcm6348-enet support Álvaro Fernández Rojas
2018-02-20 17:46 ` [U-Boot] [RFC v2 00/15] " Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 01/15] dma: move dma_ops to dma-uclass.h Álvaro Fernández Rojas
2018-02-20 18:49     ` Simon Glass
2018-02-20 18:55       ` Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 02/15] dma: add channels support Álvaro Fernández Rojas
2018-02-20 18:49     ` Simon Glass
2018-02-20 19:00       ` Álvaro Fernández Rojas [this message]
2018-02-21 15:51       ` Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 03/15] dma: add bcm6348-iudma support Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 04/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 05/15] bmips: bcm6348: " Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 06/15] bmips: bcm6358: " Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 07/15] phy: add support for internal phys Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 08/15] net: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 09/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 10/15] bmips: enable f@st1704 enet support Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 11/15] bmips: bcm6348: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 12/15] bmips: enable ct-5361 enet support Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 13/15] bmips: bcm6358: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 14/15] bmips: enable hg556a enet support Álvaro Fernández Rojas
2018-02-20 17:46   ` [U-Boot] [RFC v2 15/15] bmips: enable nb4-ser " Álvaro Fernández Rojas
2018-02-21 16:10 ` [U-Boot] [RFC v3 00/15] bmips: add bcm6348-enet support Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 01/15] dma: move dma_ops to dma-uclass.h Álvaro Fernández Rojas
2018-02-22 16:18     ` Simon Glass
2018-03-05 19:35       ` Grygorii Strashko
2018-03-05 20:06         ` Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 02/15] dma: add channels support Álvaro Fernández Rojas
2018-02-22 16:18     ` Simon Glass
2018-02-21 16:10   ` [U-Boot] [RFC v3 03/15] dma: add bcm6348-iudma support Álvaro Fernández Rojas
2018-02-22 19:50     ` Grygorii Strashko
2018-02-22 20:48       ` Álvaro Fernández Rojas
2018-02-23 16:57         ` Grygorii Strashko
2018-03-03  9:06           ` Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 04/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 05/15] bmips: bcm6348: " Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 06/15] bmips: bcm6358: " Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 07/15] phy: add support for internal phys Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 08/15] net: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 09/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 10/15] bmips: enable f@st1704 enet support Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 11/15] bmips: bcm6348: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 12/15] bmips: enable ct-5361 enet support Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 13/15] bmips: bcm6358: add support for bcm6348-enet Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 14/15] bmips: enable hg556a enet support Álvaro Fernández Rojas
2018-02-21 16:10   ` [U-Boot] [RFC v3 15/15] bmips: enable nb4-ser " Álvaro Fernández Rojas
2018-03-03  8:59 ` [U-Boot] [RFC v4 00/15] bmips: add bcm6348-enet support Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 01/15] dma: move dma_ops to dma-uclass.h Álvaro Fernández Rojas
2018-03-05 19:38     ` Grygorii Strashko
2018-03-03  8:59   ` [U-Boot] [RFC v4 02/15] dma: add channels support Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 03/15] dma: add bcm6348-iudma support Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 04/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 05/15] bmips: bcm6348: " Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 06/15] bmips: bcm6358: " Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 07/15] phy: add support for internal phys Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 08/15] net: add support for bcm6348-enet Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 09/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 10/15] bmips: enable f@st1704 enet support Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 11/15] bmips: bcm6348: add support for bcm6348-enet Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 12/15] bmips: enable ct-5361 enet support Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 13/15] bmips: bcm6358: add support for bcm6348-enet Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 14/15] bmips: enable hg556a enet support Álvaro Fernández Rojas
2018-03-03  8:59   ` [U-Boot] [RFC v4 15/15] bmips: enable nb4-ser " Álvaro Fernández Rojas
2018-03-05 20:05 ` [U-Boot] [PATCH v5 00/15] bmips: add bcm6348-enet support Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 01/15] dma: move dma_ops to dma-uclass.h Álvaro Fernández Rojas
2018-03-06 15:10     ` Grygorii Strashko
2018-03-05 20:05   ` [U-Boot] [PATCH v5 02/15] dma: add channels support Álvaro Fernández Rojas
2018-03-07 21:27     ` Joe Hershberger
2018-03-08 19:46       ` Álvaro Fernández Rojas
2018-03-08 23:07     ` Grygorii Strashko
2018-03-09 18:42       ` Álvaro Fernández Rojas
2018-03-11 19:14     ` Daniel Schwierzeck
2018-03-05 20:05   ` [U-Boot] [PATCH v5 03/15] dma: add bcm6348-iudma support Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 04/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 05/15] bmips: bcm6348: " Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 06/15] bmips: bcm6358: " Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 07/15] phy: add support for internal phys Álvaro Fernández Rojas
2018-03-07 20:28     ` Joe Hershberger
2018-03-08 19:38       ` Álvaro Fernández Rojas
2018-03-08 20:11         ` Joe Hershberger
2018-03-05 20:05   ` [U-Boot] [PATCH v5 08/15] net: add support for bcm6348-enet Álvaro Fernández Rojas
2018-03-07 21:46     ` Joe Hershberger
2018-03-08 19:50       ` Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 09/15] bmips: bcm6338: " Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 10/15] bmips: enable f@st1704 enet support Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 11/15] bmips: bcm6348: add support for bcm6348-enet Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 12/15] bmips: enable ct-5361 enet support Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 13/15] bmips: bcm6358: add support for bcm6348-enet Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 14/15] bmips: enable hg556a enet support Álvaro Fernández Rojas
2018-03-05 20:05   ` [U-Boot] [PATCH v5 15/15] bmips: enable nb4-ser " Álvaro Fernández Rojas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=03932e12-5b25-861a-3d3f-6027bf6559de@gmail.com \
    --to=noltari@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.