]> git.sur5r.net Git - u-boot/blobdiff - drivers/spi/omap3_spi.c
spi: omap3: fix claim/release bus within DM
[u-boot] / drivers / spi / omap3_spi.c
index 60e9d6e82552c8d18711a3667508d794545b880b..ecf54bb7148e7d8ca9b80b3d850b92e5e8cd1289 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2016 Jagan Teki <jteki@openedev.com>
  *                   Christophe Ricard <christophe.ricard@gmail.com>
@@ -13,8 +14,6 @@
  * Copyright (C) 2005, 2006 Nokia Corporation
  *
  * Modified by Ruslan Araslanov <ruslan.araslanov@vitecmm.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -444,9 +443,6 @@ static void spi_reset(struct mcspi *regs)
 static void _omap3_spi_claim_bus(struct omap3_spi_priv *priv)
 {
        unsigned int conf;
-
-       spi_reset(priv->regs);
-
        /*
         * setup when switching from (reset default) slave mode
         * to single-channel master mode
@@ -456,9 +452,6 @@ static void _omap3_spi_claim_bus(struct omap3_spi_priv *priv)
        conf |= OMAP3_MCSPI_MODULCTRL_SINGLE;
 
        writel(conf, &priv->regs->modulctrl);
-
-       _omap3_spi_set_mode(priv);
-       _omap3_spi_set_speed(priv);
 }
 
 #ifndef CONFIG_DM_SPI
@@ -484,6 +477,8 @@ int spi_claim_bus(struct spi_slave *slave)
 {
        struct omap3_spi_priv *priv = to_omap3_spi(slave);
 
+       spi_reset(priv->regs);
+
        _omap3_spi_claim_bus(priv);
        _omap3_spi_set_wordlen(priv);
        _omap3_spi_set_mode(priv);
@@ -496,8 +491,7 @@ void spi_release_bus(struct spi_slave *slave)
 {
        struct omap3_spi_priv *priv = to_omap3_spi(slave);
 
-       /* Reset the SPI hardware */
-       spi_reset(priv->regs);
+       writel(OMAP3_MCSPI_MODULCTRL_MS, &priv->regs->modulctrl);
 }
 
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
@@ -548,7 +542,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        }
 
        if (max_hz > OMAP3_MCSPI_MAX_FREQ) {
-               printf("SPI error: unsupported frequency %i Hz. Max frequency is 48 Mhz\n", max_hz);
+               printf("SPI error: unsupported frequency %i Hz. Max frequency is 48 MHz\n",
+                      max_hz);
                return NULL;
        }
 
@@ -568,7 +563,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
        priv->freq = max_hz;
        priv->mode = mode;
        priv->wordlen = priv->slave.wordlen;
-#ifdef CONFIG_OMAP3_SPI_D0_D1_SWAPPED
+#if 0
+       /* Please migrate to DM_SPI support for this feature. */
        priv->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
 #endif
 
@@ -592,8 +588,8 @@ static int omap3_spi_claim_bus(struct udevice *dev)
        struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
 
        priv->cs = slave_plat->cs;
-       priv->mode = slave_plat->mode;
        priv->freq = slave_plat->max_hz;
+
        _omap3_spi_claim_bus(priv);
 
        return 0;
@@ -604,8 +600,7 @@ static int omap3_spi_release_bus(struct udevice *dev)
        struct udevice *bus = dev->parent;
        struct omap3_spi_priv *priv = dev_get_priv(bus);
 
-       /* Reset the SPI hardware */
-       spi_reset(priv->regs);
+       writel(OMAP3_MCSPI_MODULCTRL_MS, &priv->regs->modulctrl);
 
        return 0;
 }
@@ -627,15 +622,20 @@ static int omap3_spi_probe(struct udevice *dev)
 {
        struct omap3_spi_priv *priv = dev_get_priv(dev);
        const void *blob = gd->fdt_blob;
-       int node = dev->of_offset;
+       int node = dev_of_offset(dev);
 
        struct omap2_mcspi_platform_config* data =
                (struct omap2_mcspi_platform_config*)dev_get_driver_data(dev);
 
-       priv->regs = (struct mcspi *)(dev_get_addr(dev) + data->regs_offset);
-       priv->pin_dir = fdtdec_get_uint(blob, node, "ti,pindir-d0-out-d1-in",
-                                           MCSPI_PINDIR_D0_IN_D1_OUT);
+       priv->regs = (struct mcspi *)(devfdt_get_addr(dev) + data->regs_offset);
+       if (fdtdec_get_bool(blob, node, "ti,pindir-d0-out-d1-in"))
+               priv->pin_dir = MCSPI_PINDIR_D0_OUT_D1_IN;
+       else
+               priv->pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT;
        priv->wordlen = SPI_DEFAULT_WORDLEN;
+
+       spi_reset(priv->regs);
+
        return 0;
 }
 
@@ -648,13 +648,25 @@ static int omap3_spi_xfer(struct udevice *dev, unsigned int bitlen,
        return _spi_xfer(priv, bitlen, dout, din, flags);
 }
 
-static int omap3_spi_set_speed(struct udevice *bus, unsigned int speed)
+static int omap3_spi_set_speed(struct udevice *dev, unsigned int speed)
 {
+
+       struct omap3_spi_priv *priv = dev_get_priv(dev);
+
+       priv->freq = speed;
+       _omap3_spi_set_speed(priv);
+
        return 0;
 }
 
-static int omap3_spi_set_mode(struct udevice *bus, uint mode)
+static int omap3_spi_set_mode(struct udevice *dev, uint mode)
 {
+       struct omap3_spi_priv *priv = dev_get_priv(dev);
+
+       priv->mode = mode;
+
+       _omap3_spi_set_mode(priv);
+
        return 0;
 }
 
@@ -692,6 +704,5 @@ U_BOOT_DRIVER(omap3_spi) = {
        .probe = omap3_spi_probe,
        .ops    = &omap3_spi_ops,
        .priv_auto_alloc_size = sizeof(struct omap3_spi_priv),
-       .probe = omap3_spi_probe,
 };
 #endif