moveconfig: replace unsafe eval with asteval
[oweals/u-boot.git] / drivers / mtd / spi / sandbox.c
index 7fef754c6341c20a6d8919782a52887c79064048..084c66e9840b43c06b8b8b2a14182d0011a577b6 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
@@ -90,7 +92,7 @@ struct sandbox_spi_flash {
        /* The current flash status (see STAT_XXX defines above) */
        u16 status;
        /* Data describing the flash we're emulating */
-       const struct spi_flash_info *data;
+       const struct flash_info *data;
        /* The file on disk to serv up data from */
        int fd;
 };
@@ -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
@@ -112,7 +122,7 @@ static int sandbox_sf_probe(struct udevice *dev)
        /* spec = idcode:file */
        struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
        size_t len, idname_len;
-       const struct spi_flash_info *data;
+       const struct 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;
@@ -145,7 +155,7 @@ static int sandbox_sf_probe(struct udevice *dev)
        idname_len = strlen(spec);
        debug("%s: device='%s'\n", __func__, spec);
 
-       for (data = spi_flash_ids; data->name; data++) {
+       for (data = spi_nor_ids; data->name; data++) {
                len = strlen(data->name);
                if (idname_len != len)
                        continue;
@@ -233,43 +243,43 @@ static int sandbox_sf_process_cmd(struct sandbox_spi_flash *sbsf, const u8 *rx,
 
        sbsf->cmd = rx[0];
        switch (sbsf->cmd) {
-       case CMD_READ_ID:
+       case SPINOR_OP_RDID:
                sbsf->state = SF_ID;
                sbsf->cmd = SF_ID;
                break;
-       case CMD_READ_ARRAY_FAST:
+       case SPINOR_OP_READ_FAST:
                sbsf->pad_addr_bytes = 1;
-       case CMD_READ_ARRAY_SLOW:
-       case CMD_PAGE_PROGRAM:
+       case SPINOR_OP_READ:
+       case SPINOR_OP_PP:
                sbsf->state = SF_ADDR;
                break;
-       case CMD_WRITE_DISABLE:
+       case SPINOR_OP_WRDI:
                debug(" write disabled\n");
                sbsf->status &= ~STAT_WEL;
                break;
-       case CMD_READ_STATUS:
+       case SPINOR_OP_RDSR:
                sbsf->state = SF_READ_STATUS;
                break;
-       case CMD_READ_STATUS1:
+       case SPINOR_OP_RDSR2:
                sbsf->state = SF_READ_STATUS1;
                break;
-       case CMD_WRITE_ENABLE:
+       case SPINOR_OP_WREN:
                debug(" write enabled\n");
                sbsf->status |= STAT_WEL;
                break;
-       case CMD_WRITE_STATUS:
+       case SPINOR_OP_WRSR:
                sbsf->state = SF_WRITE_STATUS;
                break;
        default: {
                int flags = sbsf->data->flags;
 
                /* we only support erase here */
-               if (sbsf->cmd == CMD_ERASE_CHIP) {
+               if (sbsf->cmd == SPINOR_OP_CHIP_ERASE) {
                        sbsf->erase_size = sbsf->data->sector_size *
                                sbsf->data->n_sectors;
-               } else if (sbsf->cmd == CMD_ERASE_4K && (flags & SECT_4K)) {
+               } else if (sbsf->cmd == SPINOR_OP_BE_4K && (flags & SECT_4K)) {
                        sbsf->erase_size = 4 << 10;
-               } else if (sbsf->cmd == CMD_ERASE_64K && !(flags & SECT_4K)) {
+               } else if (sbsf->cmd == SPINOR_OP_SE && !(flags & SECT_4K)) {
                        sbsf->erase_size = 64 << 10;
                } else {
                        debug(" cmd unknown: %#x\n", sbsf->cmd);
@@ -370,11 +380,11 @@ static int sandbox_sf_xfer(struct udevice *dev, unsigned int bitlen,
                                return -EIO;
                        }
                        switch (sbsf->cmd) {
-                       case CMD_READ_ARRAY_FAST:
-                       case CMD_READ_ARRAY_SLOW:
+                       case SPINOR_OP_READ_FAST:
+                       case SPINOR_OP_READ:
                                sbsf->state = SF_READ;
                                break;
-                       case CMD_PAGE_PROGRAM:
+                       case SPINOR_OP_PP:
                                sbsf->state = SF_WRITE;
                                break;
                        default: