Re: [U-Boot] [PATCH v3 2/6] spi: omap3_spi: Full dm conversion

2018-06-04 Thread Jagan Teki
On Sat, Jun 2, 2018 at 2:19 PM, Hannes Schmelzer
 wrote:
> Jagan Teki  schrieb am 07.05.2018 11:17:42:
>
>> Betreff: [PATCH v3 2/6] spi: omap3_spi: Full dm conversion
>>
>> omap3_spi now support dt along with platform data,
>> respective boards need to switch into dm for the same.
>>
>> Tested-by: Adam Ford  #omap3_logic
>> Signed-off-by: Jagan Teki 
>
> Hi Jagan,
>
> Inspired by your patch i made some progess moving my AM335x boards to
> driver model-
> SPI flash isn't working there anymore quite ago.

Did the flash working on this dm-conversion? if not can you paste the issue.

Jagan.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/6] spi: omap3_spi: Full dm conversion

2018-06-02 Thread Hannes Schmelzer
Jagan Teki  schrieb am 07.05.2018 11:17:42:

> Betreff: [PATCH v3 2/6] spi: omap3_spi: Full dm conversion
> 
> omap3_spi now support dt along with platform data,
> respective boards need to switch into dm for the same.
> 
> Tested-by: Adam Ford  #omap3_logic
> Signed-off-by: Jagan Teki 

Hi Jagan,

Inspired by your patch i made some progess moving my AM335x boards to 
driver model-
SPI flash isn't working there anymore quite ago.

I've sent some patches regarding this.

Have a look to:

https://patchwork.ozlabs.org/patch/924433/

Can you please review that?
Maybe we need to get things running again before we cann fully move to DM.


cheers,
Hannes

> ---
>  drivers/spi/Kconfig  |  14 +-
>  drivers/spi/omap3_spi.c  | 337 
+++
>  include/dm/platform_data/spi_omap3.h |  16 ++
>  3 files changed, 125 insertions(+), 242 deletions(-)
>  create mode 100644 include/dm/platform_data/spi_omap3.h
> 
> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> index d93f7d0049..72423beebf 100644
> --- a/drivers/spi/Kconfig
> +++ b/drivers/spi/Kconfig
> @@ -111,6 +111,13 @@ config MVEBU_A3700_SPI
>   used to access the SPI NOR flash on platforms embedding this
>   Marvell IP core.
> 
> +config OMAP3_SPI
> +   bool "McSPI driver for OMAP"
> +   help
> + SPI master controller for OMAP24XX and later Multichannel SPI
> + (McSPI). This driver be used to access SPI chips on platforms
> + embedding this OMAP3 McSPI IP core.
> +
>  config PIC32_SPI
> bool "Microchip PIC32 SPI driver"
> depends on MACH_PIC32
> @@ -305,11 +312,4 @@ config MXS_SPI
>   Enable the MXS SPI controller driver. This driver can be used
>   on the i.MX23 and i.MX28 SoCs.
> 
> -config OMAP3_SPI
> -   bool "McSPI driver for OMAP"
> -   help
> - SPI master controller for OMAP24XX and later Multichannel SPI
> - (McSPI). This driver be used to access SPI chips on platforms
> - embedding this OMAP3 McSPI IP core.
> -
>  endmenu # menu "SPI Support"
> diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
> index 1ac691a68e..4108dcabbf 100644
> --- a/drivers/spi/omap3_spi.c
> +++ b/drivers/spi/omap3_spi.c
> @@ -22,6 +22,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  DECLARE_GLOBAL_DATA_PTR;
> 
> @@ -109,9 +110,6 @@ struct mcspi {
>  };
> 
>  struct omap3_spi_priv {
> -#ifndef CONFIG_DM_SPI
> -   struct spi_slave slave;
> -#endif
> struct mcspi *regs;
> unsigned int cs;
> unsigned int freq;
> @@ -312,12 +310,16 @@ static int omap3_spi_txrx(struct omap3_spi_priv 
*priv, 
> unsigned int len,
> return 0;
>  }
> 
> -static int _spi_xfer(struct omap3_spi_priv *priv, unsigned int bitlen,
> -   const void *dout, void *din, unsigned long flags)
> +static int omap3_spi_xfer(struct udevice *dev, unsigned int bitlen,
> +   const void *dout, void *din, unsigned long flags)
>  {
> -   unsigned int   len;
> +   struct udevice *bus = dev->parent;
> +   struct omap3_spi_priv *priv = dev_get_priv(bus);
> +   struct dm_spi_slave_platdata *slave_plat = 
dev_get_parent_platdata(dev);
> +   unsigned int len;
> int ret = -1;
> 
> +   priv->cs = slave_plat->cs;
> if (priv->wordlen < 4 || priv->wordlen > 32) {
>printf("omap3_spi: invalid wordlen %d\n", priv->wordlen);
>return -1;
> @@ -353,78 +355,6 @@ static int _spi_xfer(struct omap3_spi_priv *priv, 
> unsigned int bitlen,
> return ret;
>  }
> 
> -static void _omap3_spi_set_speed(struct omap3_spi_priv *priv)
> -{
> -   uint32_t confr, div = 0;
> -
> -   confr = readl(&priv->regs->channel[priv->cs].chconf);
> -
> -   /* Calculate clock divisor. Valid range: 0x0 - 0xC ( /1 - /4096 ) */
> -   if (priv->freq) {
> -  while (div <= 0xC && (OMAP3_MCSPI_MAX_FREQ / (1 << div))
> -   > priv->freq)
> - div++;
> -   } else {
> -   div = 0xC;
> -   }
> -
> -   /* set clock divisor */
> -   confr &= ~OMAP3_MCSPI_CHCONF_CLKD_MASK;
> -   confr |= div << 2;
> -
> -   omap3_spi_write_chconf(priv, confr);
> -}
> -
> -static void _omap3_spi_set_mode(struct omap3_spi_priv *priv)
> -{
> -   uint32_t confr;
> -
> -   confr = readl(&priv->regs->channel[priv->cs].chconf);
> -
> -   /* standard 4-wire master mode:  SCK, MOSI/out, MISO/in, nCS
> -* REVISIT: this controller could support SPI_3WIRE mode.
> -*/
> -   if (priv->pin_dir == MCSPI_PINDIR_D0_IN_D1_OUT) {
> -  confr &= ~(OMAP3_MCSPI_CHCONF_IS|OMAP3_MCSPI_CHCONF_DPE1);
> -  confr |= OMAP3_MCSPI_CHCONF_DPE0;
> -   } else {
> -  confr &= ~OMAP3_MCSPI_CHCONF_DPE0;
> -  confr |= OMAP3_MCSPI_CHCONF_IS|OMAP3_MCSPI_CHCONF_DPE1;
> -   }
> -
> -   /* set SPI mode 0..3 */
> -   confr &= ~(OMAP3_MCSPI_CHCONF_POL | OMAP3_MCSPI_CHCONF_PHA);
> -   if (priv->mode & SPI_CPHA)
> -  confr |= OMAP3_MCSPI_CHCONF_PHA;
> -   if (priv->mode & SPI_CPOL)
> -  confr |= OMAP3_MCSPI_CHCONF_POL;
> -
> -   /* set chipselect polarity; manage with FORCE */
> -   if (!(priv->mode & SPI_CS_H

[U-Boot] [PATCH v3 2/6] spi: omap3_spi: Full dm conversion

2018-05-07 Thread Jagan Teki
omap3_spi now support dt along with platform data,
respective boards need to switch into dm for the same.

Tested-by: Adam Ford  #omap3_logic
Signed-off-by: Jagan Teki 
---
 drivers/spi/Kconfig  |  14 +-
 drivers/spi/omap3_spi.c  | 337 +++
 include/dm/platform_data/spi_omap3.h |  16 ++
 3 files changed, 125 insertions(+), 242 deletions(-)
 create mode 100644 include/dm/platform_data/spi_omap3.h

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index d93f7d0049..72423beebf 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -111,6 +111,13 @@ config MVEBU_A3700_SPI
  used to access the SPI NOR flash on platforms embedding this
  Marvell IP core.
 
+config OMAP3_SPI
+   bool "McSPI driver for OMAP"
+   help
+ SPI master controller for OMAP24XX and later Multichannel SPI
+ (McSPI). This driver be used to access SPI chips on platforms
+ embedding this OMAP3 McSPI IP core.
+
 config PIC32_SPI
bool "Microchip PIC32 SPI driver"
depends on MACH_PIC32
@@ -305,11 +312,4 @@ config MXS_SPI
  Enable the MXS SPI controller driver. This driver can be used
  on the i.MX23 and i.MX28 SoCs.
 
-config OMAP3_SPI
-   bool "McSPI driver for OMAP"
-   help
- SPI master controller for OMAP24XX and later Multichannel SPI
- (McSPI). This driver be used to access SPI chips on platforms
- embedding this OMAP3 McSPI IP core.
-
 endmenu # menu "SPI Support"
diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 1ac691a68e..4108dcabbf 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -109,9 +110,6 @@ struct mcspi {
 };
 
 struct omap3_spi_priv {
-#ifndef CONFIG_DM_SPI
-   struct spi_slave slave;
-#endif
struct mcspi *regs;
unsigned int cs;
unsigned int freq;
@@ -312,12 +310,16 @@ static int omap3_spi_txrx(struct omap3_spi_priv *priv, 
unsigned int len,
return 0;
 }
 
-static int _spi_xfer(struct omap3_spi_priv *priv, unsigned int bitlen,
-const void *dout, void *din, unsigned long flags)
+static int omap3_spi_xfer(struct udevice *dev, unsigned int bitlen,
+ const void *dout, void *din, unsigned long flags)
 {
-   unsigned intlen;
+   struct udevice *bus = dev->parent;
+   struct omap3_spi_priv *priv = dev_get_priv(bus);
+   struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
+   unsigned int len;
int ret = -1;
 
+   priv->cs = slave_plat->cs;
if (priv->wordlen < 4 || priv->wordlen > 32) {
printf("omap3_spi: invalid wordlen %d\n", priv->wordlen);
return -1;
@@ -353,78 +355,6 @@ static int _spi_xfer(struct omap3_spi_priv *priv, unsigned 
int bitlen,
return ret;
 }
 
-static void _omap3_spi_set_speed(struct omap3_spi_priv *priv)
-{
-   uint32_t confr, div = 0;
-
-   confr = readl(&priv->regs->channel[priv->cs].chconf);
-
-   /* Calculate clock divisor. Valid range: 0x0 - 0xC ( /1 - /4096 ) */
-   if (priv->freq) {
-   while (div <= 0xC && (OMAP3_MCSPI_MAX_FREQ / (1 << div))
-   > priv->freq)
-   div++;
-   } else {
-div = 0xC;
-   }
-
-   /* set clock divisor */
-   confr &= ~OMAP3_MCSPI_CHCONF_CLKD_MASK;
-   confr |= div << 2;
-
-   omap3_spi_write_chconf(priv, confr);
-}
-
-static void _omap3_spi_set_mode(struct omap3_spi_priv *priv)
-{
-   uint32_t confr;
-
-   confr = readl(&priv->regs->channel[priv->cs].chconf);
-
-   /* standard 4-wire master mode:  SCK, MOSI/out, MISO/in, nCS
-* REVISIT: this controller could support SPI_3WIRE mode.
-*/
-   if (priv->pin_dir == MCSPI_PINDIR_D0_IN_D1_OUT) {
-   confr &= ~(OMAP3_MCSPI_CHCONF_IS|OMAP3_MCSPI_CHCONF_DPE1);
-   confr |= OMAP3_MCSPI_CHCONF_DPE0;
-   } else {
-   confr &= ~OMAP3_MCSPI_CHCONF_DPE0;
-   confr |= OMAP3_MCSPI_CHCONF_IS|OMAP3_MCSPI_CHCONF_DPE1;
-   }
-
-   /* set SPI mode 0..3 */
-   confr &= ~(OMAP3_MCSPI_CHCONF_POL | OMAP3_MCSPI_CHCONF_PHA);
-   if (priv->mode & SPI_CPHA)
-   confr |= OMAP3_MCSPI_CHCONF_PHA;
-   if (priv->mode & SPI_CPOL)
-   confr |= OMAP3_MCSPI_CHCONF_POL;
-
-   /* set chipselect polarity; manage with FORCE */
-   if (!(priv->mode & SPI_CS_HIGH))
-   confr |= OMAP3_MCSPI_CHCONF_EPOL; /* active-low; normal */
-   else
-   confr &= ~OMAP3_MCSPI_CHCONF_EPOL;
-
-   /* Transmit & receive mode */
-   confr &= ~OMAP3_MCSPI_CHCONF_TRM_MASK;
-
-   omap3_spi_write_chconf(priv, confr);
-}
-
-static void _omap3_spi_set_wordlen(struct omap3_spi_priv *priv)
-{
-   unsigned int confr;
-