]> git.sur5r.net Git - u-boot/blobdiff - drivers/spi/spi-uclass.c
Merge git://git.denx.de/u-boot-dm
[u-boot] / drivers / spi / spi-uclass.c
index 5561f36762f9c6e45eff240c5e377920b96a0482..247abfa72ba1c28f904bd8df846df2e17464e441 100644 (file)
@@ -12,7 +12,6 @@
 #include <spi.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
-#include <dm/root.h>
 #include <dm/lists.h>
 #include <dm/util.h>
 
@@ -45,12 +44,12 @@ static int spi_set_speed_mode(struct udevice *bus, int speed, int mode)
        return 0;
 }
 
-int spi_claim_bus(struct spi_slave *slave)
+int dm_spi_claim_bus(struct udevice *dev)
 {
-       struct udevice *dev = slave->dev;
        struct udevice *bus = dev->parent;
        struct dm_spi_ops *ops = spi_get_ops(bus);
        struct dm_spi_bus *spi = dev_get_uclass_priv(bus);
+       struct spi_slave *slave = dev_get_parent_priv(dev);
        int speed;
        int ret;
 
@@ -73,9 +72,8 @@ int spi_claim_bus(struct spi_slave *slave)
        return ops->claim_bus ? ops->claim_bus(dev) : 0;
 }
 
-void spi_release_bus(struct spi_slave *slave)
+void dm_spi_release_bus(struct udevice *dev)
 {
-       struct udevice *dev = slave->dev;
        struct udevice *bus = dev->parent;
        struct dm_spi_ops *ops = spi_get_ops(bus);
 
@@ -83,10 +81,9 @@ void spi_release_bus(struct spi_slave *slave)
                ops->release_bus(dev);
 }
 
-int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
-            const void *dout, void *din, unsigned long flags)
+int dm_spi_xfer(struct udevice *dev, unsigned int bitlen,
+               const void *dout, void *din, unsigned long flags)
 {
-       struct udevice *dev = slave->dev;
        struct udevice *bus = dev->parent;
 
        if (bus->uclass->uc_drv->id != UCLASS_SPI)
@@ -95,10 +92,20 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
        return spi_get_ops(bus)->xfer(dev, bitlen, dout, din, flags);
 }
 
-static int spi_post_bind(struct udevice *dev)
+int spi_claim_bus(struct spi_slave *slave)
+{
+       return dm_spi_claim_bus(slave->dev);
+}
+
+void spi_release_bus(struct spi_slave *slave)
 {
-       /* Scan the bus for devices */
-       return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
+       dm_spi_release_bus(slave->dev);
+}
+
+int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
+            const void *dout, void *din, unsigned long flags)
+{
+       return dm_spi_xfer(slave->dev, bitlen, dout, din, flags);
 }
 
 static int spi_child_post_bind(struct udevice *dev)
@@ -264,6 +271,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
                       struct udevice **busp, struct spi_slave **devp)
 {
        struct udevice *bus, *dev;
+       struct dm_spi_slave_platdata *plat;
        bool created = false;
        int ret;
 
@@ -280,8 +288,6 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
         * SPI flash chip - we will bind to the correct driver.
         */
        if (ret == -ENODEV && drv_name) {
-               struct dm_spi_slave_platdata *plat;
-
                debug("%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n",
                      __func__, dev_name, busnum, cs, drv_name);
                ret = device_bind_driver(bus, drv_name, dev_name, &dev);
@@ -308,6 +314,11 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
                slave->dev = dev;
        }
 
+       plat = dev_get_parent_platdata(dev);
+       if (!speed) {
+               speed = plat->max_hz;
+               mode = plat->mode;
+       }
        ret = spi_set_speed_mode(bus, speed, mode);
        if (ret)
                goto err;
@@ -319,7 +330,7 @@ int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode,
        return 0;
 
 err:
-       debug("%s: Error path, credted=%d, device '%s'\n", __func__,
+       debug("%s: Error path, created=%d, device '%s'\n", __func__,
              created, dev->name);
        if (created) {
                device_remove(dev);
@@ -428,7 +439,7 @@ UCLASS_DRIVER(spi) = {
        .id             = UCLASS_SPI,
        .name           = "spi",
        .flags          = DM_UC_FLAG_SEQ_ALIAS,
-       .post_bind      = spi_post_bind,
+       .post_bind      = dm_scan_fdt_dev,
        .post_probe     = spi_post_probe,
        .child_pre_probe = spi_child_pre_probe,
        .per_device_auto_alloc_size = sizeof(struct dm_spi_bus),