},
};
-static int macronix_write_status(struct spi_flash *flash, u8 sr)
-{
- u8 cmd;
- int ret;
-
- ret = spi_flash_cmd_write_enable(flash);
- if (ret < 0) {
- debug("SF: enabling write failed\n");
- return ret;
- }
-
- cmd = CMD_WRITE_STATUS;
- ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &sr, 1);
- if (ret) {
- debug("SF: fail to write status register\n");
- return ret;
- }
-
- ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
- if (ret < 0) {
- debug("SF: write status register timed out\n");
- return ret;
- }
-
- return 0;
-}
-
-static int macronix_unlock(struct spi_flash *flash)
-{
- int ret;
-
- /* Enable status register writing and clear BP# bits */
- ret = macronix_write_status(flash, 0);
- if (ret)
- debug("SF: fail to disable write protection\n");
-
- return ret;
-}
-
struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
{
const struct macronix_spi_flash_params *params;
flash->size = flash->sector_size * params->nr_blocks;
/* Clear BP# bits for read-only flash */
- macronix_unlock(flash);
+ spi_flash_cmd_write_status(flash, 0);
return flash;
}
return ret;
}
+int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
+{
+ u8 cmd;
+ int ret;
+
+ ret = spi_flash_cmd_write_enable(flash);
+ if (ret < 0) {
+ debug("SF: enabling write failed\n");
+ return ret;
+ }
+
+ cmd = CMD_WRITE_STATUS;
+ ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &sr, 1);
+ if (ret) {
+ debug("SF: fail to write status register\n");
+ return ret;
+ }
+
+ ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT);
+ if (ret < 0) {
+ debug("SF: write status register timed out\n");
+ return ret;
+ }
+
+ return 0;
+}
+
/*
* The following table holds all device probe functions
*
return spi_flash_cmd(flash->spi, CMD_WRITE_DISABLE, NULL, 0);
}
+/* Program the status register. */
+int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr);
+
/*
* Same as spi_flash_cmd_read() except it also claims/releases the SPI
* bus. Used as common part of the ->read() operation.
return ret;
}
-static int
-sst_unlock(struct spi_flash *flash)
-{
- int ret;
- u8 cmd, status;
-
- ret = spi_flash_cmd_write_enable(flash);
- if (ret)
- return ret;
-
- cmd = CMD_WRITE_STATUS;
- status = 0;
- ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &status, 1);
- if (ret)
- debug("SF: Unable to set status byte\n");
-
- debug("SF: sst: status = %x\n", spi_w8r8(flash->spi, CMD_READ_STATUS));
-
- return ret;
-}
-
struct spi_flash *
spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
{
stm->flash.size = stm->flash.sector_size * params->nr_sectors;
/* Flash powers up read-only, so clear BP# bits */
- sst_unlock(&stm->flash);
+ spi_flash_cmd_write_status(&stm->flash, 0);
return &stm->flash;
}