mtd: spi: sf_probe: Add "jedec, spi-nor" compatible string
[oweals/u-boot.git] / drivers / mtd / spi / sandbox.c
index 514484eba06639628687ee66fc9c9dfcbe75e57b..7b9891cb981c224b3c061f9b0649129059a95a96 100644 (file)
@@ -57,6 +57,8 @@ static const char *sandbox_sf_state_name(enum sandbox_sf_state state)
 /* Bits for the status register */
 #define STAT_WIP       (1 << 0)
 #define STAT_WEL       (1 << 1)
+#define STAT_BP_SHIFT  2
+#define STAT_BP_MASK   (7 << STAT_BP_SHIFT)
 
 /* Assume all SPI flashes have 3 byte addresses since they do atm */
 #define SF_ADDR_LEN    3
@@ -102,6 +104,14 @@ struct sandbox_spi_flash_plat_data {
        int cs;
 };
 
+void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask)
+{
+       struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
+
+       sbsf->status &= ~STAT_BP_MASK;
+       sbsf->status |= bp_mask << STAT_BP_SHIFT;
+}
+
 /**
  * This is a very strange probe function. If it has platform data (which may
  * have come from the device tree) then this function gets the filename and
@@ -115,24 +125,22 @@ static int sandbox_sf_probe(struct udevice *dev)
        const struct spi_flash_info *data;
        struct sandbox_spi_flash_plat_data *pdata = dev_get_platdata(dev);
        struct sandbox_state *state = state_get_current();
+       struct dm_spi_slave_platdata *slave_plat;
        struct udevice *bus = dev->parent;
        const char *spec = NULL;
+       struct udevice *emul;
        int ret = 0;
        int cs = -1;
-       int i;
 
        debug("%s: bus %d, looking for emul=%p: ", __func__, bus->seq, dev);
-       if (bus->seq >= 0 && bus->seq < CONFIG_SANDBOX_SPI_MAX_BUS) {
-               for (i = 0; i < CONFIG_SANDBOX_SPI_MAX_CS; i++) {
-                       if (state->spi[bus->seq][i].emul == dev)
-                               cs = i;
-               }
-       }
-       if (cs == -1) {
+       ret = sandbox_spi_get_emul(state, bus, dev, &emul);
+       if (ret) {
                printf("Error: Unknown chip select for device '%s'\n",
-                      dev->name);
-               return -EINVAL;
+                       dev->name);
+               return ret;
        }
+       slave_plat = dev_get_parent_platdata(dev);
+       cs = slave_plat->cs;
        debug("found at cs %d\n", cs);
 
        if (!pdata->filename) {