+- write_enable(flash);
+-
+ /* Set up the opcode in the write buffer. */
+ flash->command[0] = flash->program_opcode;
+- m25p_addr2cmd(flash, to, flash->command);
+
+ page_offset = to & (flash->page_size - 1);
+
+@@ -608,9 +689,7 @@ static int m25p80_write(struct mtd_info
+ if (page_offset + len <= flash->page_size) {
+ t[1].len = len;
+
+- spi_sync(flash->spi, &m);
+-
+- *retlen = m.actual_length - m25p_cmdsz(flash);
++ *retlen = m25p80_write_data(flash, &m, &t[1], to);
+ } else {
+ u32 i;
+
+@@ -618,9 +697,7 @@ static int m25p80_write(struct mtd_info
+ page_size = flash->page_size - page_offset;
+
+ t[1].len = page_size;
+- spi_sync(flash->spi, &m);
+-
+- *retlen = m.actual_length - m25p_cmdsz(flash);
++ *retlen = m25p80_write_data(flash, &m, &t[1], to);
+
+ /* write everything in flash->page_size chunks */
+ for (i = page_size; i < len; i += page_size) {
+@@ -628,19 +705,12 @@ static int m25p80_write(struct mtd_info
+ if (page_size > flash->page_size)
+ page_size = flash->page_size;
+
+- /* write the next page to flash */
+- m25p_addr2cmd(flash, to + i, flash->command);
+-
+ t[1].tx_buf = buf + i;
+ t[1].len = page_size;
+
+ wait_till_ready(flash);
+
+- write_enable(flash);
+-
+- spi_sync(flash->spi, &m);
+-
+- *retlen += m.actual_length - m25p_cmdsz(flash);
++ *retlen += m25p80_write_data(flash, &m, &t[1], to + i);
+ }
+ }
+
+@@ -1105,6 +1175,7 @@ static int m25p_probe(struct spi_device
+ struct mtd_part_parser_data ppdata;
+ struct device_node *np = spi->dev.of_node;
+ int ret;
++ u32 val;
+
+ /* Platform data helps sort out which chip type we have, as
+ * well as how this board partitions it. If we don't have
+@@ -1187,6 +1258,12 @@ static int m25p_probe(struct spi_device
+ flash->mtd._erase = m25p80_erase;
+ flash->mtd._read = m25p80_read;
+
++ if (np && !of_property_read_u32(np, "m25p,chunked-io", &val)) {