2017-02-13 11:38:27 +00:00
|
|
|
--- a/drivers/mtd/spi-nor/spi-nor.c
|
|
|
|
+++ b/drivers/mtd/spi-nor/spi-nor.c
|
2017-07-20 10:57:44 +00:00
|
|
|
@@ -1453,6 +1453,67 @@ write_err:
|
2017-02-13 11:38:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int spi_nor_chunked_write(struct mtd_info *mtd, loff_t _to, size_t _len,
|
|
|
|
+ size_t *_retlen, const u_char *_buf)
|
|
|
|
+{
|
|
|
|
+ struct spi_nor *nor = mtd_to_spi_nor(mtd);
|
2017-07-20 10:57:44 +00:00
|
|
|
+ u32 addr_width = nor->addr_width + !!(nor->flags & SNOR_F_4B_EXT_ADDR);
|
2017-02-13 11:38:27 +00:00
|
|
|
+ int chunk_size;
|
|
|
|
+ int retlen = 0;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ chunk_size = nor->chunk_size;
|
|
|
|
+ if (!chunk_size)
|
|
|
|
+ chunk_size = _len;
|
|
|
|
+
|
2017-07-20 10:57:44 +00:00
|
|
|
+ if (addr_width > 3)
|
|
|
|
+ chunk_size -= addr_width - 3;
|
2017-02-13 11:38:27 +00:00
|
|
|
+
|
|
|
|
+ while (retlen < _len) {
|
|
|
|
+ size_t len = min_t(int, chunk_size, _len - retlen);
|
|
|
|
+ const u_char *buf = _buf + retlen;
|
|
|
|
+ loff_t to = _to + retlen;
|
|
|
|
+
|
|
|
|
+ if (nor->flags & SNOR_F_SST)
|
|
|
|
+ ret = sst_write(mtd, to, len, &retlen, buf);
|
|
|
|
+ else
|
|
|
|
+ ret = spi_nor_write(mtd, to, len, &retlen, buf);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *_retlen += retlen;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int spi_nor_chunked_read(struct mtd_info *mtd, loff_t _from, size_t _len,
|
|
|
|
+ size_t *_retlen, u_char *_buf)
|
|
|
|
+{
|
|
|
|
+ struct spi_nor *nor = mtd_to_spi_nor(mtd);
|
|
|
|
+ int chunk_size;
|
|
|
|
+ int ret;
|
|
|
|
+
|
|
|
|
+ chunk_size = nor->chunk_size;
|
|
|
|
+ if (!chunk_size)
|
|
|
|
+ chunk_size = _len;
|
|
|
|
+
|
|
|
|
+ *_retlen = 0;
|
|
|
|
+ while (*_retlen < _len) {
|
|
|
|
+ size_t len = min_t(int, chunk_size, _len - *_retlen);
|
|
|
|
+ u_char *buf = _buf + *_retlen;
|
|
|
|
+ loff_t from = _from + *_retlen;
|
|
|
|
+ int retlen = 0;
|
|
|
|
+
|
|
|
|
+ ret = spi_nor_read(mtd, from, len, &retlen, buf);
|
|
|
|
+ if (ret)
|
|
|
|
+ return ret;
|
|
|
|
+
|
|
|
|
+ *_retlen += retlen;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int macronix_quad_enable(struct spi_nor *nor)
|
|
|
|
{
|
|
|
|
int ret, val;
|
2017-07-20 10:57:44 +00:00
|
|
|
@@ -1702,10 +1763,12 @@ int spi_nor_scan(struct spi_nor *nor, co
|
2017-02-13 11:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sst nor chips use AAI word program */
|
|
|
|
- if (info->flags & SST_WRITE)
|
|
|
|
+ if (info->flags & SST_WRITE) {
|
|
|
|
mtd->_write = sst_write;
|
|
|
|
- else
|
|
|
|
+ nor->flags |= SNOR_F_SST;
|
|
|
|
+ } else {
|
|
|
|
mtd->_write = spi_nor_write;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (info->flags & USE_FSR)
|
|
|
|
nor->flags |= SNOR_F_USE_FSR;
|
2017-11-20 09:51:09 +00:00
|
|
|
@@ -1737,11 +1800,20 @@ int spi_nor_scan(struct spi_nor *nor, co
|
2017-02-13 11:38:27 +00:00
|
|
|
mtd->writebufsize = nor->page_size;
|
|
|
|
|
|
|
|
if (np) {
|
|
|
|
+ u32 val;
|
|
|
|
+
|
|
|
|
/* If we were instantiated by DT, use it */
|
|
|
|
if (of_property_read_bool(np, "m25p,fast-read"))
|
|
|
|
nor->flash_read = SPI_NOR_FAST;
|
|
|
|
else
|
|
|
|
nor->flash_read = SPI_NOR_NORMAL;
|
|
|
|
+
|
|
|
|
+ if (!of_property_read_u32(np, "m25p,chunked-io", &val)) {
|
|
|
|
+ dev_info(dev, "using chunked io (size=%d)\n", val);
|
|
|
|
+ mtd->_read = spi_nor_chunked_read;
|
|
|
|
+ mtd->_write = spi_nor_chunked_write;
|
|
|
|
+ nor->chunk_size = val;
|
|
|
|
+ }
|
|
|
|
} else {
|
|
|
|
/* If we weren't instantiated by DT, default to fast-read */
|
|
|
|
nor->flash_read = SPI_NOR_FAST;
|
|
|
|
--- a/include/linux/mtd/spi-nor.h
|
|
|
|
+++ b/include/linux/mtd/spi-nor.h
|
2017-07-20 10:57:44 +00:00
|
|
|
@@ -143,6 +143,7 @@ enum spi_nor_option_flags {
|
2017-02-13 11:38:27 +00:00
|
|
|
SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
|
|
|
|
SNOR_F_READY_XSR_RDY = BIT(4),
|
2017-07-20 10:57:44 +00:00
|
|
|
SNOR_F_4B_EXT_ADDR = BIT(5),
|
|
|
|
+ SNOR_F_SST = BIT(6),
|
2017-02-13 11:38:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-07-20 10:57:44 +00:00
|
|
|
@@ -182,6 +183,7 @@ struct spi_nor {
|
2017-02-13 11:38:27 +00:00
|
|
|
struct mutex lock;
|
|
|
|
struct device *dev;
|
|
|
|
u32 page_size;
|
|
|
|
+ u16 chunk_size;
|
|
|
|
u8 addr_width;
|
|
|
|
u8 erase_opcode;
|
|
|
|
u8 read_opcode;
|