Driver model uses a different way to find the SPI bus and slave from the
numbered devices given on the command line. Adjust the code to suit.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 common/cmd_spi.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/common/cmd_spi.c b/common/cmd_spi.c
index be5709c..4ebd41b 100644
--- a/common/cmd_spi.c
+++ b/common/cmd_spi.c
@@ -11,6 +11,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <dm.h>
 #include <errno.h>
 #include <spi.h>
 
@@ -42,19 +43,35 @@ static uchar                din[MAX_SPI_BYTES];
 static int do_spi_xfer(int bus, int cs)
 {
        struct spi_slave *slave;
-       int rcode = 0;
+       int ret = 0;
 
+#ifdef CONFIG_DM_SPI
+       struct udevice *dev;
+
+       ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, NULL, 0, &dev,
+                                 &slave);
+       if (ret)
+               return ret;
+#else
        slave = spi_setup_slave(bus, cs, 1000000, mode);
        if (!slave) {
                printf("Invalid device %d:%d\n", bus, cs);
                return -EINVAL;
        }
+#endif
 
-       spi_claim_bus(slave);
-       if (spi_xfer(slave, bitlen, dout, din,
-                    SPI_XFER_BEGIN | SPI_XFER_END) != 0) {
-               printf("Error during SPI transaction\n");
-               rcode = -EIO;
+       ret = spi_claim_bus(slave);
+       if (ret)
+               goto done;
+       ret = spi_xfer(slave, bitlen, dout, din,
+                      SPI_XFER_BEGIN | SPI_XFER_END);
+#ifndef CONFIG_DM_SPI
+       /* We don't get an error code in this case */
+       if (ret)
+               ret = -EIO;
+#endif
+       if (ret) {
+               printf("Error %d during SPI transaction\n", ret);
        } else {
                int j;
 
@@ -62,10 +79,13 @@ static int do_spi_xfer(int bus, int cs)
                        printf("%02X", din[j]);
                printf("\n");
        }
+done:
        spi_release_bus(slave);
+#ifndef CONFIG_DM_SPI
        spi_free_slave(slave);
+#endif
 
-       return rcode;
+       return ret;
 }
 
 /*
-- 
2.0.0.526.g5318336

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to