Merge tag 'dm-pull-29oct19' of git://git.denx.de/u-boot-dm
[oweals/u-boot.git] / drivers / spi / spi-uclass.c
index 88cb2a126227156d18342796d4022f25c3aefbba..947516073ea99650b1703a9fc5fcc854b5496a81 100644 (file)
@@ -108,6 +108,30 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
        return dm_spi_xfer(slave->dev, bitlen, dout, din, flags);
 }
 
+int spi_write_then_read(struct spi_slave *slave, const u8 *opcode,
+                       size_t n_opcode, const u8 *txbuf, u8 *rxbuf,
+                       size_t n_buf)
+{
+       unsigned long flags = SPI_XFER_BEGIN;
+       int ret;
+
+       if (n_buf == 0)
+               flags |= SPI_XFER_END;
+
+       ret = spi_xfer(slave, n_opcode * 8, opcode, NULL, flags);
+       if (ret) {
+               debug("spi: failed to send command (%zu bytes): %d\n",
+                     n_opcode, ret);
+       } else if (n_buf != 0) {
+               ret = spi_xfer(slave, n_buf * 8, txbuf, rxbuf, SPI_XFER_END);
+               if (ret)
+                       debug("spi: failed to transfer %zu bytes of data: %d\n",
+                             n_buf, ret);
+       }
+
+       return ret;
+}
+
 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
 static int spi_child_post_bind(struct udevice *dev)
 {
@@ -237,11 +261,10 @@ int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info)
                return ops->cs_info(bus, cs, info);
 
        /*
-        * We could assume there is at least one valid chip select, but best
-        * to be sure and return an error in this case. The driver didn't
-        * care enough to tell us.
+        * We could assume there is at least one valid chip select.
+        * The driver didn't care enough to tell us.
         */
-       return -ENODEV;
+       return 0;
 }
 
 int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp,
@@ -275,7 +298,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
        bool created = false;
        int ret;
 
-#if CONFIG_IS_ENABLED(OF_PLATDATA) || CONFIG_IS_ENABLED(OF_PRIOR_STAGE)
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
        ret = uclass_first_device_err(UCLASS_SPI, &bus);
 #else
        ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus);