Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-24 Thread Amit Tomar
Well, you tell me! At the moment I don't see much preventing people from

> enabling it on the S900, and your compatible string listing in the
> driver includes the S900 one.
>

I just checked, it's DMA descriptor structure that differs between two but
I think
This is not relevant here.

Only thing is , it would be great if Mani or someone with S900 based board
can test it.

Thanks
-Amit


Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread André Przywara
On 23/12/2020 12:29, Amit Tomar wrote:
> Hi,
> 
> Thanks again for the detailed review
> 
> +
> 
> >  3 files changed, 407 insertions(+)
> >  create mode 100644 drivers/mmc/owl_mmc.c
> >
> > diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> > index 14d7913..61f9c67 100644
> > --- a/drivers/mmc/Kconfig
> > +++ b/drivers/mmc/Kconfig
> > @@ -289,6 +289,13 @@ config MMC_MXC
> > 
> >         If unsure, say N.
> > 
> > +config MMC_OWL
> > +     bool "Actions OWL Multimedia Card Interface support"
> > +     depends on ARCH_OWL && DM_MMC && BLK
> > +     help
> > +       This selects the OWL SD/MMC host controller found on board
> > +       based on Actions S700 SoC.
> 
> And S900 as well?
> 
> But as you aware S900 has different DMA requirements, would it be
> okay to claim that this works for S900 as well ?

Well, you tell me! At the moment I don't see much preventing people from
enabling it on the S900, and your compatible string listing in the
driver includes the S900 one.

What are the different DMA requirements? Aren't the controllers the same
as far as we are concerned, for the purpose of MMC?
And even if not, how much would it take to adapt the code?

Cheers,
Andre

> 
> > +
> >  config MMC_MXS
> >       bool "Freescale MXS Multimedia Card Interface support"
> >       depends on MX23 || MX28 || MX6 || MX7
> > diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
> > index 1c849cb..f270f6c 100644
> > --- a/drivers/mmc/Makefile
> > +++ b/drivers/mmc/Makefile
> > @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)           += omap_hsmmc.o
> >  obj-$(CONFIG_MMC_MXC)                        += mxcmmc.o
> >  obj-$(CONFIG_MMC_MXS)                        += mxsmmc.o
> >  obj-$(CONFIG_MMC_OCTEONTX)           += octeontx_hsmmc.o
> > +obj-$(CONFIG_MMC_OWL)                        += owl_mmc.o
> >  obj-$(CONFIG_MMC_PCI)                        += pci_mmc.o
> >  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
> >  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
> > diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
> > new file mode 100644
> > index 000..5c48307
> > --- /dev/null
> > +++ b/drivers/mmc/owl_mmc.c
> > @@ -0,0 +1,399 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2020 Amit Singh Tomar  >
> > + *
> > + * Driver for SD/MMC controller present on Actions Semi S700 SoC,
> based
> > + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
> > + *
> > + * Though, there is a bit (BSEL, BUS or DMA Special Channel
> Selection) that
> > + * controls the data transfer from SDx_DAT register either using
> CPU AHB Bus
> > + * or DMA channel, but seems like, it only works correctly using
> external DMA
> > + * channel, and those special bits used in this driver is picked
> from vendor
> > + * source exclusively for MMC/SD.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*
> > + * SDC registers
> > + */
> > +#define OWL_REG_SD_EN                   0x
> > +#define OWL_REG_SD_CTL                  0x0004
> > +#define OWL_REG_SD_STATE                0x0008
> > +#define OWL_REG_SD_CMD                  0x000c
> > +#define OWL_REG_SD_ARG                  0x0010
> > +#define OWL_REG_SD_RSPBUF0              0x0014
> > +#define OWL_REG_SD_RSPBUF1              0x0018
> > +#define OWL_REG_SD_RSPBUF2              0x001c
> > +#define OWL_REG_SD_RSPBUF3              0x0020
> > +#define OWL_REG_SD_RSPBUF4              0x0024
> > +#define OWL_REG_SD_DAT                  0x0028
> > +#define OWL_REG_SD_BLK_SIZE             0x002c
> > +#define OWL_REG_SD_BLK_NUM              0x0030
> > +#define OWL_REG_SD_BUF_SIZE             0x0034
> > +
> > +/* SD_EN Bits */
> > +#define OWL_SD_EN_RANE                  BIT(31)
> > +#define OWL_SD_EN_RESE                  BIT(10)
> > +#define OWL_SD_ENABLE                   BIT(7)
> > +#define OWL_SD_EN_BSEL                  BIT(6)
> > +#define OWL_SD_EN_DATAWID(x)            (((x) & 0x3) << 0)
> > +#define OWL_SD_EN_DATAWID_MASK               0x03
> > +
> > +/* SD_CTL Bits */
> > +#define OWL_SD_CTL_TOUTEN               BIT(31)
> > +#define OWL_SD_CTL_DELAY_MSK            GENMASK(23, 16)
> > +#define OWL_SD_CTL_RDELAY(x)            (((x) & 0xf) << 20)
> > +#define OWL_SD_CTL_WDELAY(x)            (((x) & 0xf) << 16)
> > +#define OWL_SD_CTL_TS                   BIT(7)
> > +#define OWL_SD_CTL_LBE                  BIT(6)
> > 

Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread Amit Tomar
Hi,

Thanks again for the detailed review

+

> >  3 files changed, 407 insertions(+)
> >  create mode 100644 drivers/mmc/owl_mmc.c
> >
> > diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> > index 14d7913..61f9c67 100644
> > --- a/drivers/mmc/Kconfig
> > +++ b/drivers/mmc/Kconfig
> > @@ -289,6 +289,13 @@ config MMC_MXC
> >
> > If unsure, say N.
> >
> > +config MMC_OWL
> > + bool "Actions OWL Multimedia Card Interface support"
> > + depends on ARCH_OWL && DM_MMC && BLK
> > + help
> > +   This selects the OWL SD/MMC host controller found on board
> > +   based on Actions S700 SoC.
>
> And S900 as well?
>
> But as you aware S900 has different DMA requirements, would it be
okay to claim that this works for S900 as well ?

> +
> >  config MMC_MXS
> >   bool "Freescale MXS Multimedia Card Interface support"
> >   depends on MX23 || MX28 || MX6 || MX7
> > diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
> > index 1c849cb..f270f6c 100644
> > --- a/drivers/mmc/Makefile
> > +++ b/drivers/mmc/Makefile
> > @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
> >  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
> >  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
> >  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
> > +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
> >  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
> >  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
> >  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
> > diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
> > new file mode 100644
> > index 000..5c48307
> > --- /dev/null
> > +++ b/drivers/mmc/owl_mmc.c
> > @@ -0,0 +1,399 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2020 Amit Singh Tomar 
> > + *
> > + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
> > + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
> > + *
> > + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection)
> that
> > + * controls the data transfer from SDx_DAT register either using CPU
> AHB Bus
> > + * or DMA channel, but seems like, it only works correctly using
> external DMA
> > + * channel, and those special bits used in this driver is picked from
> vendor
> > + * source exclusively for MMC/SD.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*
> > + * SDC registers
> > + */
> > +#define OWL_REG_SD_EN   0x
> > +#define OWL_REG_SD_CTL  0x0004
> > +#define OWL_REG_SD_STATE0x0008
> > +#define OWL_REG_SD_CMD  0x000c
> > +#define OWL_REG_SD_ARG  0x0010
> > +#define OWL_REG_SD_RSPBUF0  0x0014
> > +#define OWL_REG_SD_RSPBUF1  0x0018
> > +#define OWL_REG_SD_RSPBUF2  0x001c
> > +#define OWL_REG_SD_RSPBUF3  0x0020
> > +#define OWL_REG_SD_RSPBUF4  0x0024
> > +#define OWL_REG_SD_DAT  0x0028
> > +#define OWL_REG_SD_BLK_SIZE 0x002c
> > +#define OWL_REG_SD_BLK_NUM  0x0030
> > +#define OWL_REG_SD_BUF_SIZE 0x0034
> > +
> > +/* SD_EN Bits */
> > +#define OWL_SD_EN_RANE  BIT(31)
> > +#define OWL_SD_EN_RESE  BIT(10)
> > +#define OWL_SD_ENABLE   BIT(7)
> > +#define OWL_SD_EN_BSEL  BIT(6)
> > +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
> > +#define OWL_SD_EN_DATAWID_MASK   0x03
> > +
> > +/* SD_CTL Bits */
> > +#define OWL_SD_CTL_TOUTEN   BIT(31)
> > +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
> > +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
> > +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
> > +#define OWL_SD_CTL_TS   BIT(7)
> > +#define OWL_SD_CTL_LBE  BIT(6)
> > +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
> > +
> > +#define OWL_SD_DELAY_LOW_CLK0x0f
> > +#define OWL_SD_DELAY_MID_CLK0x0a
> > +#define OWL_SD_RDELAY_HIGH   0x08
> > +#define OWL_SD_WDELAY_HIGH   0x09
>
> w/s? Here and elsewhere. I would use tabs everywhere instead.
>

Yeah, just checked I was not consistent with tabs here, will fix it in the
next version.

>
> > +
> > +/* SD_STATE Bits */
> > +#define OWL_SD_STATE_DAT0S  BIT(7)
> > +#define OWL_SD_STATE_CLNR   BIT(4)
> > +#define OWL_SD_STATE_CRC7ER BIT(0)
> > +
> > +#define OWL_MMC_OCR (MMC_VDD_32_33 | MMC_VDD_33_34
> | \
> > +  MMC_VDD_165_195)
> > +
> > +#define DATA_TRANSFER_TIMEOUT3
> > +
> > +/*
> > + * Simple DMA transfer operations defines for MMC/SD 

Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread André Przywara
On 23/12/2020 04:25, Jaehoon Chung wrote:
> On 12/23/20 11:22 AM, Amit Tomer wrote:
>> On Wed, Dec 23, 2020 at 5:57 AM André Przywara  
>> wrote:
>>>
>>> On 19/12/2020 14:51, Amit Singh Tomar wrote:
 From: Amit Singh Tomar 

 This commit adds support for MMC controllers found on Actions OWL
 S700 SoC platform.

 Signed-off-by: Amit Singh Tomar 
 ---
 Changes since previous version
   * Corrected block count to 512.
   * Changed the command timeout value to 30ms.
   * Used readl_poll_timeout.
   * Read DMA parameters from DT instead of hardcoding it.
   * Reduced number of arguments passed to own_dma_cofig.
   * Removed debug leftover.
   * Used mmc_of_parse().
 ---
  drivers/mmc/Kconfig   |   7 +
  drivers/mmc/Makefile  |   1 +
  drivers/mmc/owl_mmc.c | 399 
 ++
  3 files changed, 407 insertions(+)
  create mode 100644 drivers/mmc/owl_mmc.c

 diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
 index 14d7913..61f9c67 100644
 --- a/drivers/mmc/Kconfig
 +++ b/drivers/mmc/Kconfig
 @@ -289,6 +289,13 @@ config MMC_MXC

 If unsure, say N.

 +config MMC_OWL
 + bool "Actions OWL Multimedia Card Interface support"
 + depends on ARCH_OWL && DM_MMC && BLK
 + help
 +   This selects the OWL SD/MMC host controller found on board
 +   based on Actions S700 SoC.
>>>
>>> And S900 as well?
>>>
 +
  config MMC_MXS
   bool "Freescale MXS Multimedia Card Interface support"
   depends on MX23 || MX28 || MX6 || MX7
 diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
 index 1c849cb..f270f6c 100644
 --- a/drivers/mmc/Makefile
 +++ b/drivers/mmc/Makefile
 @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
 +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
 diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
 new file mode 100644
 index 000..5c48307
 --- /dev/null
 +++ b/drivers/mmc/owl_mmc.c
 @@ -0,0 +1,399 @@
 +// SPDX-License-Identifier: GPL-2.0+
 +/*
 + * Copyright (C) 2020 Amit Singh Tomar 
 + *
 + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
 + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
 + *
 + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) 
 that
 + * controls the data transfer from SDx_DAT register either using CPU AHB 
 Bus
 + * or DMA channel, but seems like, it only works correctly using external 
 DMA
 + * channel, and those special bits used in this driver is picked from 
 vendor
 + * source exclusively for MMC/SD.
 + */
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +
 +/*
 + * SDC registers
 + */
 +#define OWL_REG_SD_EN   0x
 +#define OWL_REG_SD_CTL  0x0004
 +#define OWL_REG_SD_STATE0x0008
 +#define OWL_REG_SD_CMD  0x000c
 +#define OWL_REG_SD_ARG  0x0010
 +#define OWL_REG_SD_RSPBUF0  0x0014
 +#define OWL_REG_SD_RSPBUF1  0x0018
 +#define OWL_REG_SD_RSPBUF2  0x001c
 +#define OWL_REG_SD_RSPBUF3  0x0020
 +#define OWL_REG_SD_RSPBUF4  0x0024
 +#define OWL_REG_SD_DAT  0x0028
 +#define OWL_REG_SD_BLK_SIZE 0x002c
 +#define OWL_REG_SD_BLK_NUM  0x0030
 +#define OWL_REG_SD_BUF_SIZE 0x0034
 +
 +/* SD_EN Bits */
 +#define OWL_SD_EN_RANE  BIT(31)
 +#define OWL_SD_EN_RESE  BIT(10)
 +#define OWL_SD_ENABLE   BIT(7)
 +#define OWL_SD_EN_BSEL  BIT(6)
 +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
 +#define OWL_SD_EN_DATAWID_MASK   0x03
 +
 +/* SD_CTL Bits */
 +#define OWL_SD_CTL_TOUTEN   BIT(31)
 +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
 +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
 +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
 +#define OWL_SD_CTL_TS   BIT(7)
 +#define OWL_SD_CTL_LBE  BIT(6)
 +#define OWL_SD_CTL_TM(x)(((x) & 

RE: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-23 Thread Peng Fan
Thanks for Cc.

> Subject: Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL
> S700
> 
> Hi Amit,
> 
> On 12/23/20 2:59 PM, Amit Tomar wrote:
> > Hi Jaehoon
> >
> > I had already mentioned about making more readable than now.
> >
> >>
> >> if (rate <= 100) {
> >> rdelay = wdelay = OWL_SD_DELAY_LOW_CLK; } else if ( ...) {
> >> rdelay = wdelay = OWL_SD_DELAY_MID_CLK; } else if () {
> >> rdelay = OWL_SD_RDELAY_HIGH;
> >> wdelay = OWL_SD_WDELAY_HIGH;
> >> }
> >>
> >> writel(reg | OWL_SD_CTRL_RDELAY(rdelay) |
> >> OWL_SD_CTL_WDELAY(wdelay)...);
> >>
> >> There are many approach to make readable..but Amit mentioned it's
> >> using same code in Linux kernel driver.
> >>
> >> To be honest, this is *not* the reason but if you see controller also
> >> supports DDR50 mode(which we may support in future)
> >
> >where we have different values for read and write delays and we may
> > need that many variables to write it cleanly.
> >
> >But if this is not the problem , I will implement the changes as
> > suggested by you.
> 
> Frankly, i don't have any objection about your patch. :) Just curious about
> other driver what using same code with kernel, not only this driver.
> 
> I will follow Peng's opinion.

I am fine if the driver follows Linux kernel driver implementation.

Thanks,
Peng.

> 
> 
> Best Regards,
> Jaehoon Chung
> 
> >
> >>
> >>> Thanks
> >>> -Amit
> >>>
> >>
> >>
> >



Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread Jaehoon Chung
Hi Amit,

On 12/23/20 2:59 PM, Amit Tomar wrote:
> Hi Jaehoon
> 
> I had already mentioned about making more readable than now.
> 
>>
>> if (rate <= 100) {
>> rdelay = wdelay = OWL_SD_DELAY_LOW_CLK;
>> } else if ( ...) {
>> rdelay = wdelay = OWL_SD_DELAY_MID_CLK;
>> } else if () {
>> rdelay = OWL_SD_RDELAY_HIGH;
>> wdelay = OWL_SD_WDELAY_HIGH;
>> }
>>
>> writel(reg | OWL_SD_CTRL_RDELAY(rdelay) | OWL_SD_CTL_WDELAY(wdelay)...);
>>
>> There are many approach to make readable..but Amit mentioned it's using
>> same code in Linux kernel driver.
>>
>> To be honest, this is *not* the reason but if you see controller also
>> supports DDR50 mode(which we may support in future)
> 
>where we have different values for read and write delays and we may need
> that many variables to write it cleanly.
> 
>But if this is not the problem , I will implement the changes as
> suggested by you.

Frankly, i don't have any objection about your patch. :)
Just curious about other driver what using same code with kernel, not only this 
driver.

I will follow Peng's opinion.


Best Regards,
Jaehoon Chung

> 
>>
>>> Thanks
>>> -Amit
>>>
>>
>>
> 



Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread Amit Tomar
Hi Jaehoon

I had already mentioned about making more readable than now.

>
> if (rate <= 100) {
> rdelay = wdelay = OWL_SD_DELAY_LOW_CLK;
> } else if ( ...) {
> rdelay = wdelay = OWL_SD_DELAY_MID_CLK;
> } else if () {
> rdelay = OWL_SD_RDELAY_HIGH;
> wdelay = OWL_SD_WDELAY_HIGH;
> }
>
> writel(reg | OWL_SD_CTRL_RDELAY(rdelay) | OWL_SD_CTL_WDELAY(wdelay)...);
>
> There are many approach to make readable..but Amit mentioned it's using
> same code in Linux kernel driver.
>
> To be honest, this is *not* the reason but if you see controller also
> supports DDR50 mode(which we may support in future)

   where we have different values for read and write delays and we may need
that many variables to write it cleanly.

   But if this is not the problem , I will implement the changes as
suggested by you.

>
> > Thanks
> > -Amit
> >
>
>


Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread Jaehoon Chung
On 12/23/20 11:22 AM, Amit Tomer wrote:
> On Wed, Dec 23, 2020 at 5:57 AM André Przywara  wrote:
>>
>> On 19/12/2020 14:51, Amit Singh Tomar wrote:
>>> From: Amit Singh Tomar 
>>>
>>> This commit adds support for MMC controllers found on Actions OWL
>>> S700 SoC platform.
>>>
>>> Signed-off-by: Amit Singh Tomar 
>>> ---
>>> Changes since previous version
>>>   * Corrected block count to 512.
>>>   * Changed the command timeout value to 30ms.
>>>   * Used readl_poll_timeout.
>>>   * Read DMA parameters from DT instead of hardcoding it.
>>>   * Reduced number of arguments passed to own_dma_cofig.
>>>   * Removed debug leftover.
>>>   * Used mmc_of_parse().
>>> ---
>>>  drivers/mmc/Kconfig   |   7 +
>>>  drivers/mmc/Makefile  |   1 +
>>>  drivers/mmc/owl_mmc.c | 399 
>>> ++
>>>  3 files changed, 407 insertions(+)
>>>  create mode 100644 drivers/mmc/owl_mmc.c
>>>
>>> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
>>> index 14d7913..61f9c67 100644
>>> --- a/drivers/mmc/Kconfig
>>> +++ b/drivers/mmc/Kconfig
>>> @@ -289,6 +289,13 @@ config MMC_MXC
>>>
>>> If unsure, say N.
>>>
>>> +config MMC_OWL
>>> + bool "Actions OWL Multimedia Card Interface support"
>>> + depends on ARCH_OWL && DM_MMC && BLK
>>> + help
>>> +   This selects the OWL SD/MMC host controller found on board
>>> +   based on Actions S700 SoC.
>>
>> And S900 as well?
>>
>>> +
>>>  config MMC_MXS
>>>   bool "Freescale MXS Multimedia Card Interface support"
>>>   depends on MX23 || MX28 || MX6 || MX7
>>> diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
>>> index 1c849cb..f270f6c 100644
>>> --- a/drivers/mmc/Makefile
>>> +++ b/drivers/mmc/Makefile
>>> @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
>>>  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
>>>  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
>>>  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
>>> +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
>>>  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
>>>  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
>>>  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
>>> diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
>>> new file mode 100644
>>> index 000..5c48307
>>> --- /dev/null
>>> +++ b/drivers/mmc/owl_mmc.c
>>> @@ -0,0 +1,399 @@
>>> +// SPDX-License-Identifier: GPL-2.0+
>>> +/*
>>> + * Copyright (C) 2020 Amit Singh Tomar 
>>> + *
>>> + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
>>> + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
>>> + *
>>> + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
>>> + * controls the data transfer from SDx_DAT register either using CPU AHB 
>>> Bus
>>> + * or DMA channel, but seems like, it only works correctly using external 
>>> DMA
>>> + * channel, and those special bits used in this driver is picked from 
>>> vendor
>>> + * source exclusively for MMC/SD.
>>> + */
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +/*
>>> + * SDC registers
>>> + */
>>> +#define OWL_REG_SD_EN   0x
>>> +#define OWL_REG_SD_CTL  0x0004
>>> +#define OWL_REG_SD_STATE0x0008
>>> +#define OWL_REG_SD_CMD  0x000c
>>> +#define OWL_REG_SD_ARG  0x0010
>>> +#define OWL_REG_SD_RSPBUF0  0x0014
>>> +#define OWL_REG_SD_RSPBUF1  0x0018
>>> +#define OWL_REG_SD_RSPBUF2  0x001c
>>> +#define OWL_REG_SD_RSPBUF3  0x0020
>>> +#define OWL_REG_SD_RSPBUF4  0x0024
>>> +#define OWL_REG_SD_DAT  0x0028
>>> +#define OWL_REG_SD_BLK_SIZE 0x002c
>>> +#define OWL_REG_SD_BLK_NUM  0x0030
>>> +#define OWL_REG_SD_BUF_SIZE 0x0034
>>> +
>>> +/* SD_EN Bits */
>>> +#define OWL_SD_EN_RANE  BIT(31)
>>> +#define OWL_SD_EN_RESE  BIT(10)
>>> +#define OWL_SD_ENABLE   BIT(7)
>>> +#define OWL_SD_EN_BSEL  BIT(6)
>>> +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
>>> +#define OWL_SD_EN_DATAWID_MASK   0x03
>>> +
>>> +/* SD_CTL Bits */
>>> +#define OWL_SD_CTL_TOUTEN   BIT(31)
>>> +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
>>> +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
>>> +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
>>> +#define OWL_SD_CTL_TS   BIT(7)
>>> +#define OWL_SD_CTL_LBE  BIT(6)
>>> +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
>>> +
>>> +#define OWL_SD_DELAY_LOW_CLK0x0f
>>> +#define OWL_SD_DELAY_MID_CLK0x0a
>>> +#define OWL_SD_RDELAY_HIGH   0x08
>>> +#define 

Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread Amit Tomer
On Wed, Dec 23, 2020 at 5:57 AM André Przywara  wrote:
>
> On 19/12/2020 14:51, Amit Singh Tomar wrote:
> > From: Amit Singh Tomar 
> >
> > This commit adds support for MMC controllers found on Actions OWL
> > S700 SoC platform.
> >
> > Signed-off-by: Amit Singh Tomar 
> > ---
> > Changes since previous version
> >   * Corrected block count to 512.
> >   * Changed the command timeout value to 30ms.
> >   * Used readl_poll_timeout.
> >   * Read DMA parameters from DT instead of hardcoding it.
> >   * Reduced number of arguments passed to own_dma_cofig.
> >   * Removed debug leftover.
> >   * Used mmc_of_parse().
> > ---
> >  drivers/mmc/Kconfig   |   7 +
> >  drivers/mmc/Makefile  |   1 +
> >  drivers/mmc/owl_mmc.c | 399 
> > ++
> >  3 files changed, 407 insertions(+)
> >  create mode 100644 drivers/mmc/owl_mmc.c
> >
> > diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> > index 14d7913..61f9c67 100644
> > --- a/drivers/mmc/Kconfig
> > +++ b/drivers/mmc/Kconfig
> > @@ -289,6 +289,13 @@ config MMC_MXC
> >
> > If unsure, say N.
> >
> > +config MMC_OWL
> > + bool "Actions OWL Multimedia Card Interface support"
> > + depends on ARCH_OWL && DM_MMC && BLK
> > + help
> > +   This selects the OWL SD/MMC host controller found on board
> > +   based on Actions S700 SoC.
>
> And S900 as well?
>
> > +
> >  config MMC_MXS
> >   bool "Freescale MXS Multimedia Card Interface support"
> >   depends on MX23 || MX28 || MX6 || MX7
> > diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
> > index 1c849cb..f270f6c 100644
> > --- a/drivers/mmc/Makefile
> > +++ b/drivers/mmc/Makefile
> > @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
> >  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
> >  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
> >  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
> > +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
> >  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
> >  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
> >  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
> > diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
> > new file mode 100644
> > index 000..5c48307
> > --- /dev/null
> > +++ b/drivers/mmc/owl_mmc.c
> > @@ -0,0 +1,399 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (C) 2020 Amit Singh Tomar 
> > + *
> > + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
> > + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
> > + *
> > + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
> > + * controls the data transfer from SDx_DAT register either using CPU AHB 
> > Bus
> > + * or DMA channel, but seems like, it only works correctly using external 
> > DMA
> > + * channel, and those special bits used in this driver is picked from 
> > vendor
> > + * source exclusively for MMC/SD.
> > + */
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*
> > + * SDC registers
> > + */
> > +#define OWL_REG_SD_EN   0x
> > +#define OWL_REG_SD_CTL  0x0004
> > +#define OWL_REG_SD_STATE0x0008
> > +#define OWL_REG_SD_CMD  0x000c
> > +#define OWL_REG_SD_ARG  0x0010
> > +#define OWL_REG_SD_RSPBUF0  0x0014
> > +#define OWL_REG_SD_RSPBUF1  0x0018
> > +#define OWL_REG_SD_RSPBUF2  0x001c
> > +#define OWL_REG_SD_RSPBUF3  0x0020
> > +#define OWL_REG_SD_RSPBUF4  0x0024
> > +#define OWL_REG_SD_DAT  0x0028
> > +#define OWL_REG_SD_BLK_SIZE 0x002c
> > +#define OWL_REG_SD_BLK_NUM  0x0030
> > +#define OWL_REG_SD_BUF_SIZE 0x0034
> > +
> > +/* SD_EN Bits */
> > +#define OWL_SD_EN_RANE  BIT(31)
> > +#define OWL_SD_EN_RESE  BIT(10)
> > +#define OWL_SD_ENABLE   BIT(7)
> > +#define OWL_SD_EN_BSEL  BIT(6)
> > +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
> > +#define OWL_SD_EN_DATAWID_MASK   0x03
> > +
> > +/* SD_CTL Bits */
> > +#define OWL_SD_CTL_TOUTEN   BIT(31)
> > +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
> > +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
> > +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
> > +#define OWL_SD_CTL_TS   BIT(7)
> > +#define OWL_SD_CTL_LBE  BIT(6)
> > +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
> > +
> > +#define OWL_SD_DELAY_LOW_CLK0x0f
> > +#define OWL_SD_DELAY_MID_CLK0x0a
> > +#define OWL_SD_RDELAY_HIGH   0x08
> > +#define OWL_SD_WDELAY_HIGH   0x09
>
> w/s? Here and 

Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread André Przywara
On 19/12/2020 14:51, Amit Singh Tomar wrote:
> From: Amit Singh Tomar 
> 
> This commit adds support for MMC controllers found on Actions OWL
> S700 SoC platform.
> 
> Signed-off-by: Amit Singh Tomar 
> ---
> Changes since previous version
>   * Corrected block count to 512.
>   * Changed the command timeout value to 30ms.
>   * Used readl_poll_timeout. 
>   * Read DMA parameters from DT instead of hardcoding it.
>   * Reduced number of arguments passed to own_dma_cofig.
>   * Removed debug leftover.
>   * Used mmc_of_parse().
> ---
>  drivers/mmc/Kconfig   |   7 +
>  drivers/mmc/Makefile  |   1 +
>  drivers/mmc/owl_mmc.c | 399 
> ++
>  3 files changed, 407 insertions(+)
>  create mode 100644 drivers/mmc/owl_mmc.c
> 
> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> index 14d7913..61f9c67 100644
> --- a/drivers/mmc/Kconfig
> +++ b/drivers/mmc/Kconfig
> @@ -289,6 +289,13 @@ config MMC_MXC
>  
> If unsure, say N.
>  
> +config MMC_OWL
> + bool "Actions OWL Multimedia Card Interface support"
> + depends on ARCH_OWL && DM_MMC && BLK
> + help
> +   This selects the OWL SD/MMC host controller found on board
> +   based on Actions S700 SoC.

And S900 as well?

> +
>  config MMC_MXS
>   bool "Freescale MXS Multimedia Card Interface support"
>   depends on MX23 || MX28 || MX6 || MX7
> diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
> index 1c849cb..f270f6c 100644
> --- a/drivers/mmc/Makefile
> +++ b/drivers/mmc/Makefile
> @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
>  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
>  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
>  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
> +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
>  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
>  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
>  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
> diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
> new file mode 100644
> index 000..5c48307
> --- /dev/null
> +++ b/drivers/mmc/owl_mmc.c
> @@ -0,0 +1,399 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2020 Amit Singh Tomar 
> + *
> + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
> + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
> + *
> + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
> + * controls the data transfer from SDx_DAT register either using CPU AHB Bus
> + * or DMA channel, but seems like, it only works correctly using external DMA
> + * channel, and those special bits used in this driver is picked from vendor
> + * source exclusively for MMC/SD.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * SDC registers
> + */
> +#define OWL_REG_SD_EN   0x
> +#define OWL_REG_SD_CTL  0x0004
> +#define OWL_REG_SD_STATE0x0008
> +#define OWL_REG_SD_CMD  0x000c
> +#define OWL_REG_SD_ARG  0x0010
> +#define OWL_REG_SD_RSPBUF0  0x0014
> +#define OWL_REG_SD_RSPBUF1  0x0018
> +#define OWL_REG_SD_RSPBUF2  0x001c
> +#define OWL_REG_SD_RSPBUF3  0x0020
> +#define OWL_REG_SD_RSPBUF4  0x0024
> +#define OWL_REG_SD_DAT  0x0028
> +#define OWL_REG_SD_BLK_SIZE 0x002c
> +#define OWL_REG_SD_BLK_NUM  0x0030
> +#define OWL_REG_SD_BUF_SIZE 0x0034
> +
> +/* SD_EN Bits */
> +#define OWL_SD_EN_RANE  BIT(31)
> +#define OWL_SD_EN_RESE  BIT(10)
> +#define OWL_SD_ENABLE   BIT(7)
> +#define OWL_SD_EN_BSEL  BIT(6)
> +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
> +#define OWL_SD_EN_DATAWID_MASK   0x03
> +
> +/* SD_CTL Bits */
> +#define OWL_SD_CTL_TOUTEN   BIT(31)
> +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
> +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
> +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
> +#define OWL_SD_CTL_TS   BIT(7)
> +#define OWL_SD_CTL_LBE  BIT(6)
> +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
> +
> +#define OWL_SD_DELAY_LOW_CLK0x0f
> +#define OWL_SD_DELAY_MID_CLK0x0a
> +#define OWL_SD_RDELAY_HIGH   0x08
> +#define OWL_SD_WDELAY_HIGH   0x09

w/s? Here and elsewhere. I would use tabs everywhere instead.

> +
> +/* SD_STATE Bits */
> +#define OWL_SD_STATE_DAT0S  BIT(7)
> +#define OWL_SD_STATE_CLNR   BIT(4)
> +#define OWL_SD_STATE_CRC7ER BIT(0)
> +
> +#define OWL_MMC_OCR (MMC_VDD_32_33 | MMC_VDD_33_34 | \
> +  

Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread André Przywara
On 22/12/2020 23:37, Jaehoon Chung wrote:
> On 12/19/20 11:51 PM, Amit Singh Tomar wrote:
>> From: Amit Singh Tomar 
>>
>> This commit adds support for MMC controllers found on Actions OWL
>> S700 SoC platform.
>>
>> Signed-off-by: Amit Singh Tomar 
>> ---
>> Changes since previous version
>>  * Corrected block count to 512.
>>  * Changed the command timeout value to 30ms.
>>  * Used readl_poll_timeout. 
>>  * Read DMA parameters from DT instead of hardcoding it.
>>  * Reduced number of arguments passed to own_dma_cofig.
>>  * Removed debug leftover.
>>  * Used mmc_of_parse().
>> ---
>>  drivers/mmc/Kconfig   |   7 +
>>  drivers/mmc/Makefile  |   1 +
>>  drivers/mmc/owl_mmc.c | 399 
>> ++
>>  3 files changed, 407 insertions(+)
>>  create mode 100644 drivers/mmc/owl_mmc.c
>>
>> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
>> index 14d7913..61f9c67 100644
>> --- a/drivers/mmc/Kconfig
>> +++ b/drivers/mmc/Kconfig
>> @@ -289,6 +289,13 @@ config MMC_MXC
>>  
>>If unsure, say N.
>>  
>> +config MMC_OWL
>> +bool "Actions OWL Multimedia Card Interface support"
>> +depends on ARCH_OWL && DM_MMC && BLK
>> +help
>> +  This selects the OWL SD/MMC host controller found on board
>> +  based on Actions S700 SoC.
>> +
>>  config MMC_MXS
>>  bool "Freescale MXS Multimedia Card Interface support"
>>  depends on MX23 || MX28 || MX6 || MX7
>> diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
>> index 1c849cb..f270f6c 100644
>> --- a/drivers/mmc/Makefile
>> +++ b/drivers/mmc/Makefile
>> @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)  += omap_hsmmc.o
>>  obj-$(CONFIG_MMC_MXC)   += mxcmmc.o
>>  obj-$(CONFIG_MMC_MXS)   += mxsmmc.o
>>  obj-$(CONFIG_MMC_OCTEONTX)  += octeontx_hsmmc.o
>> +obj-$(CONFIG_MMC_OWL)   += owl_mmc.o
>>  obj-$(CONFIG_MMC_PCI)   += pci_mmc.o
>>  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
>>  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
>> diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
>> new file mode 100644
>> index 000..5c48307
>> --- /dev/null
>> +++ b/drivers/mmc/owl_mmc.c
>> @@ -0,0 +1,399 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (C) 2020 Amit Singh Tomar 
>> + *
>> + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
>> + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
>> + *
>> + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
>> + * controls the data transfer from SDx_DAT register either using CPU AHB Bus
>> + * or DMA channel, but seems like, it only works correctly using external 
>> DMA
>> + * channel, and those special bits used in this driver is picked from vendor
>> + * source exclusively for MMC/SD.
>> + */
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +/*
>> + * SDC registers
>> + */
>> +#define OWL_REG_SD_EN   0x
>> +#define OWL_REG_SD_CTL  0x0004
>> +#define OWL_REG_SD_STATE0x0008
>> +#define OWL_REG_SD_CMD  0x000c
>> +#define OWL_REG_SD_ARG  0x0010
>> +#define OWL_REG_SD_RSPBUF0  0x0014
>> +#define OWL_REG_SD_RSPBUF1  0x0018
>> +#define OWL_REG_SD_RSPBUF2  0x001c
>> +#define OWL_REG_SD_RSPBUF3  0x0020
>> +#define OWL_REG_SD_RSPBUF4  0x0024
>> +#define OWL_REG_SD_DAT  0x0028
>> +#define OWL_REG_SD_BLK_SIZE 0x002c
>> +#define OWL_REG_SD_BLK_NUM  0x0030
>> +#define OWL_REG_SD_BUF_SIZE 0x0034
>> +
>> +/* SD_EN Bits */
>> +#define OWL_SD_EN_RANE  BIT(31)
>> +#define OWL_SD_EN_RESE  BIT(10)
>> +#define OWL_SD_ENABLE   BIT(7)
>> +#define OWL_SD_EN_BSEL  BIT(6)
>> +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
>> +#define OWL_SD_EN_DATAWID_MASK  0x03
>> +
>> +/* SD_CTL Bits */
>> +#define OWL_SD_CTL_TOUTEN   BIT(31)
>> +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
>> +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
>> +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
>> +#define OWL_SD_CTL_TS   BIT(7)
>> +#define OWL_SD_CTL_LBE  BIT(6)
>> +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
>> +
>> +#define OWL_SD_DELAY_LOW_CLK0x0f
>> +#define OWL_SD_DELAY_MID_CLK0x0a
>> +#define OWL_SD_RDELAY_HIGH  0x08
>> +#define OWL_SD_WDELAY_HIGH  0x09
>> +
>> +/* SD_STATE Bits */
>> +#define OWL_SD_STATE_DAT0S  BIT(7)
>> +#define OWL_SD_STATE_CLNR   BIT(4)
>> +#define OWL_SD_STATE_CRC7ER BIT(0)
>> +
>> +#define OWL_MMC_OCR

Re: [PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-22 Thread Jaehoon Chung
On 12/19/20 11:51 PM, Amit Singh Tomar wrote:
> From: Amit Singh Tomar 
> 
> This commit adds support for MMC controllers found on Actions OWL
> S700 SoC platform.
> 
> Signed-off-by: Amit Singh Tomar 
> ---
> Changes since previous version
>   * Corrected block count to 512.
>   * Changed the command timeout value to 30ms.
>   * Used readl_poll_timeout. 
>   * Read DMA parameters from DT instead of hardcoding it.
>   * Reduced number of arguments passed to own_dma_cofig.
>   * Removed debug leftover.
>   * Used mmc_of_parse().
> ---
>  drivers/mmc/Kconfig   |   7 +
>  drivers/mmc/Makefile  |   1 +
>  drivers/mmc/owl_mmc.c | 399 
> ++
>  3 files changed, 407 insertions(+)
>  create mode 100644 drivers/mmc/owl_mmc.c
> 
> diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
> index 14d7913..61f9c67 100644
> --- a/drivers/mmc/Kconfig
> +++ b/drivers/mmc/Kconfig
> @@ -289,6 +289,13 @@ config MMC_MXC
>  
> If unsure, say N.
>  
> +config MMC_OWL
> + bool "Actions OWL Multimedia Card Interface support"
> + depends on ARCH_OWL && DM_MMC && BLK
> + help
> +   This selects the OWL SD/MMC host controller found on board
> +   based on Actions S700 SoC.
> +
>  config MMC_MXS
>   bool "Freescale MXS Multimedia Card Interface support"
>   depends on MX23 || MX28 || MX6 || MX7
> diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
> index 1c849cb..f270f6c 100644
> --- a/drivers/mmc/Makefile
> +++ b/drivers/mmc/Makefile
> @@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS)   += omap_hsmmc.o
>  obj-$(CONFIG_MMC_MXC)+= mxcmmc.o
>  obj-$(CONFIG_MMC_MXS)+= mxsmmc.o
>  obj-$(CONFIG_MMC_OCTEONTX)   += octeontx_hsmmc.o
> +obj-$(CONFIG_MMC_OWL)+= owl_mmc.o
>  obj-$(CONFIG_MMC_PCI)+= pci_mmc.o
>  obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
>  obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
> diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
> new file mode 100644
> index 000..5c48307
> --- /dev/null
> +++ b/drivers/mmc/owl_mmc.c
> @@ -0,0 +1,399 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2020 Amit Singh Tomar 
> + *
> + * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
> + * on Linux Driver "drivers/mmc/host/owl-mmc.c".
> + *
> + * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
> + * controls the data transfer from SDx_DAT register either using CPU AHB Bus
> + * or DMA channel, but seems like, it only works correctly using external DMA
> + * channel, and those special bits used in this driver is picked from vendor
> + * source exclusively for MMC/SD.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +/*
> + * SDC registers
> + */
> +#define OWL_REG_SD_EN   0x
> +#define OWL_REG_SD_CTL  0x0004
> +#define OWL_REG_SD_STATE0x0008
> +#define OWL_REG_SD_CMD  0x000c
> +#define OWL_REG_SD_ARG  0x0010
> +#define OWL_REG_SD_RSPBUF0  0x0014
> +#define OWL_REG_SD_RSPBUF1  0x0018
> +#define OWL_REG_SD_RSPBUF2  0x001c
> +#define OWL_REG_SD_RSPBUF3  0x0020
> +#define OWL_REG_SD_RSPBUF4  0x0024
> +#define OWL_REG_SD_DAT  0x0028
> +#define OWL_REG_SD_BLK_SIZE 0x002c
> +#define OWL_REG_SD_BLK_NUM  0x0030
> +#define OWL_REG_SD_BUF_SIZE 0x0034
> +
> +/* SD_EN Bits */
> +#define OWL_SD_EN_RANE  BIT(31)
> +#define OWL_SD_EN_RESE  BIT(10)
> +#define OWL_SD_ENABLE   BIT(7)
> +#define OWL_SD_EN_BSEL  BIT(6)
> +#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
> +#define OWL_SD_EN_DATAWID_MASK   0x03
> +
> +/* SD_CTL Bits */
> +#define OWL_SD_CTL_TOUTEN   BIT(31)
> +#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
> +#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
> +#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
> +#define OWL_SD_CTL_TS   BIT(7)
> +#define OWL_SD_CTL_LBE  BIT(6)
> +#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
> +
> +#define OWL_SD_DELAY_LOW_CLK0x0f
> +#define OWL_SD_DELAY_MID_CLK0x0a
> +#define OWL_SD_RDELAY_HIGH   0x08
> +#define OWL_SD_WDELAY_HIGH   0x09
> +
> +/* SD_STATE Bits */
> +#define OWL_SD_STATE_DAT0S  BIT(7)
> +#define OWL_SD_STATE_CLNR   BIT(4)
> +#define OWL_SD_STATE_CRC7ER BIT(0)
> +
> +#define OWL_MMC_OCR (MMC_VDD_32_33 | MMC_VDD_33_34 | \
> +  MMC_VDD_165_195)
> +
> +#define DATA_TRANSFER_TIMEOUT  

[PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This commit adds support for MMC controllers found on Actions OWL
S700 SoC platform.

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version
* Corrected block count to 512.
* Changed the command timeout value to 30ms.
* Used readl_poll_timeout. 
* Read DMA parameters from DT instead of hardcoding it.
* Reduced number of arguments passed to own_dma_cofig.
* Removed debug leftover.
* Used mmc_of_parse().
---
 drivers/mmc/Kconfig   |   7 +
 drivers/mmc/Makefile  |   1 +
 drivers/mmc/owl_mmc.c | 399 ++
 3 files changed, 407 insertions(+)
 create mode 100644 drivers/mmc/owl_mmc.c

diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 14d7913..61f9c67 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -289,6 +289,13 @@ config MMC_MXC
 
  If unsure, say N.
 
+config MMC_OWL
+   bool "Actions OWL Multimedia Card Interface support"
+   depends on ARCH_OWL && DM_MMC && BLK
+   help
+ This selects the OWL SD/MMC host controller found on board
+ based on Actions S700 SoC.
+
 config MMC_MXS
bool "Freescale MXS Multimedia Card Interface support"
depends on MX23 || MX28 || MX6 || MX7
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 1c849cb..f270f6c 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS) += omap_hsmmc.o
 obj-$(CONFIG_MMC_MXC)  += mxcmmc.o
 obj-$(CONFIG_MMC_MXS)  += mxsmmc.o
 obj-$(CONFIG_MMC_OCTEONTX) += octeontx_hsmmc.o
+obj-$(CONFIG_MMC_OWL)  += owl_mmc.o
 obj-$(CONFIG_MMC_PCI)  += pci_mmc.o
 obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
 obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
new file mode 100644
index 000..5c48307
--- /dev/null
+++ b/drivers/mmc/owl_mmc.c
@@ -0,0 +1,399 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Amit Singh Tomar 
+ *
+ * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
+ * on Linux Driver "drivers/mmc/host/owl-mmc.c".
+ *
+ * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
+ * controls the data transfer from SDx_DAT register either using CPU AHB Bus
+ * or DMA channel, but seems like, it only works correctly using external DMA
+ * channel, and those special bits used in this driver is picked from vendor
+ * source exclusively for MMC/SD.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SDC registers
+ */
+#define OWL_REG_SD_EN   0x
+#define OWL_REG_SD_CTL  0x0004
+#define OWL_REG_SD_STATE0x0008
+#define OWL_REG_SD_CMD  0x000c
+#define OWL_REG_SD_ARG  0x0010
+#define OWL_REG_SD_RSPBUF0  0x0014
+#define OWL_REG_SD_RSPBUF1  0x0018
+#define OWL_REG_SD_RSPBUF2  0x001c
+#define OWL_REG_SD_RSPBUF3  0x0020
+#define OWL_REG_SD_RSPBUF4  0x0024
+#define OWL_REG_SD_DAT  0x0028
+#define OWL_REG_SD_BLK_SIZE 0x002c
+#define OWL_REG_SD_BLK_NUM  0x0030
+#define OWL_REG_SD_BUF_SIZE 0x0034
+
+/* SD_EN Bits */
+#define OWL_SD_EN_RANE  BIT(31)
+#define OWL_SD_EN_RESE  BIT(10)
+#define OWL_SD_ENABLE   BIT(7)
+#define OWL_SD_EN_BSEL  BIT(6)
+#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
+#define OWL_SD_EN_DATAWID_MASK 0x03
+
+/* SD_CTL Bits */
+#define OWL_SD_CTL_TOUTEN   BIT(31)
+#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
+#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
+#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
+#define OWL_SD_CTL_TS   BIT(7)
+#define OWL_SD_CTL_LBE  BIT(6)
+#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
+
+#define OWL_SD_DELAY_LOW_CLK0x0f
+#define OWL_SD_DELAY_MID_CLK0x0a
+#define OWL_SD_RDELAY_HIGH 0x08
+#define OWL_SD_WDELAY_HIGH 0x09
+
+/* SD_STATE Bits */
+#define OWL_SD_STATE_DAT0S  BIT(7)
+#define OWL_SD_STATE_CLNR   BIT(4)
+#define OWL_SD_STATE_CRC7ER BIT(0)
+
+#define OWL_MMC_OCR (MMC_VDD_32_33 | MMC_VDD_33_34 | \
+MMC_VDD_165_195)
+
+#define DATA_TRANSFER_TIMEOUT  3
+
+/*
+ * Simple DMA transfer operations defines for MMC/SD card
+ */
+#define SD_DMA_CHANNEL(base, channel)   ((base) + 0x100 * (channel))
+
+#define DMA_MODE   0x
+#define DMA_SOURCE 0x0004
+#define DMA_DESTINATION0x0008