]> git.sur5r.net Git - u-boot/blobdiff - drivers/spi/spi-uclass.c
Revert "x86: broadwell: gpio: Remove the codes to set up pin control"
[u-boot] / drivers / spi / spi-uclass.c
index 84b6786517cc667ebd04d6542003bac26dc85175..d9c49e4e8c208a5f8474427726c53a89871cf976 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>
 
@@ -109,12 +108,6 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
        return dm_spi_xfer(slave->dev, bitlen, dout, din, flags);
 }
 
-static int spi_post_bind(struct udevice *dev)
-{
-       /* Scan the bus for devices */
-       return dm_scan_fdt_node(dev, gd->fdt_blob, dev->of_offset, false);
-}
-
 static int spi_child_post_bind(struct udevice *dev)
 {
        struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev);
@@ -171,7 +164,6 @@ static int spi_child_pre_probe(struct udevice *dev)
 
        slave->max_hz = plat->max_hz;
        slave->mode = plat->mode;
-       slave->mode_rx = plat->mode_rx;
        slave->wordlen = SPI_DEFAULT_WORDLEN;
 
        return 0;
@@ -278,6 +270,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;
 
@@ -294,8 +287,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);
@@ -322,6 +313,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;
@@ -333,7 +329,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);
@@ -384,7 +380,7 @@ void spi_free_slave(struct spi_slave *slave)
 int spi_slave_ofdata_to_platdata(const void *blob, int node,
                                 struct dm_spi_slave_platdata *plat)
 {
-       int mode = 0, mode_rx = 0;
+       int mode = 0;
        int value;
 
        plat->cs = fdtdec_get_int(blob, node, "reg", -1);
@@ -416,24 +412,22 @@ int spi_slave_ofdata_to_platdata(const void *blob, int node,
                break;
        }
 
-       plat->mode = mode;
-
        value = fdtdec_get_uint(blob, node, "spi-rx-bus-width", 1);
        switch (value) {
        case 1:
                break;
        case 2:
-               mode_rx |= SPI_RX_DUAL;
+               mode |= SPI_RX_DUAL;
                break;
        case 4:
-               mode_rx |= SPI_RX_QUAD;
+               mode |= SPI_RX_QUAD;
                break;
        default:
                error("spi-rx-bus-width %d not supported\n", value);
                break;
        }
 
-       plat->mode_rx = mode_rx;
+       plat->mode = mode;
 
        return 0;
 }
@@ -442,7 +436,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),