kernel: bump 4.9 to 4.9.77
[openwrt/openwrt.git] / target / linux / ramips / patches-4.9 / 0054-mtd-add-chunked-read-io-to-m25p80.patch
1 --- a/drivers/mtd/spi-nor/spi-nor.c
2 +++ b/drivers/mtd/spi-nor/spi-nor.c
3 @@ -1453,6 +1453,67 @@ write_err:
4 return ret;
5 }
6
7 +static int spi_nor_chunked_write(struct mtd_info *mtd, loff_t _to, size_t _len,
8 + size_t *_retlen, const u_char *_buf)
9 +{
10 + struct spi_nor *nor = mtd_to_spi_nor(mtd);
11 + u32 addr_width = nor->addr_width + !!(nor->flags & SNOR_F_4B_EXT_ADDR);
12 + int chunk_size;
13 + int retlen = 0;
14 + int ret;
15 +
16 + chunk_size = nor->chunk_size;
17 + if (!chunk_size)
18 + chunk_size = _len;
19 +
20 + if (addr_width > 3)
21 + chunk_size -= addr_width - 3;
22 +
23 + while (retlen < _len) {
24 + size_t len = min_t(int, chunk_size, _len - retlen);
25 + const u_char *buf = _buf + retlen;
26 + loff_t to = _to + retlen;
27 +
28 + if (nor->flags & SNOR_F_SST)
29 + ret = sst_write(mtd, to, len, &retlen, buf);
30 + else
31 + ret = spi_nor_write(mtd, to, len, &retlen, buf);
32 + if (ret)
33 + return ret;
34 + }
35 +
36 + *_retlen += retlen;
37 + return 0;
38 +}
39 +
40 +static int spi_nor_chunked_read(struct mtd_info *mtd, loff_t _from, size_t _len,
41 + size_t *_retlen, u_char *_buf)
42 +{
43 + struct spi_nor *nor = mtd_to_spi_nor(mtd);
44 + int chunk_size;
45 + int ret;
46 +
47 + chunk_size = nor->chunk_size;
48 + if (!chunk_size)
49 + chunk_size = _len;
50 +
51 + *_retlen = 0;
52 + while (*_retlen < _len) {
53 + size_t len = min_t(int, chunk_size, _len - *_retlen);
54 + u_char *buf = _buf + *_retlen;
55 + loff_t from = _from + *_retlen;
56 + int retlen = 0;
57 +
58 + ret = spi_nor_read(mtd, from, len, &retlen, buf);
59 + if (ret)
60 + return ret;
61 +
62 + *_retlen += retlen;
63 + }
64 +
65 + return 0;
66 +}
67 +
68 static int macronix_quad_enable(struct spi_nor *nor)
69 {
70 int ret, val;
71 @@ -1704,10 +1765,12 @@ int spi_nor_scan(struct spi_nor *nor, co
72 }
73
74 /* sst nor chips use AAI word program */
75 - if (info->flags & SST_WRITE)
76 + if (info->flags & SST_WRITE) {
77 mtd->_write = sst_write;
78 - else
79 + nor->flags |= SNOR_F_SST;
80 + } else {
81 mtd->_write = spi_nor_write;
82 + }
83
84 if (info->flags & USE_FSR)
85 nor->flags |= SNOR_F_USE_FSR;
86 @@ -1739,11 +1802,20 @@ int spi_nor_scan(struct spi_nor *nor, co
87 mtd->writebufsize = nor->page_size;
88
89 if (np) {
90 + u32 val;
91 +
92 /* If we were instantiated by DT, use it */
93 if (of_property_read_bool(np, "m25p,fast-read"))
94 nor->flash_read = SPI_NOR_FAST;
95 else
96 nor->flash_read = SPI_NOR_NORMAL;
97 +
98 + if (!of_property_read_u32(np, "m25p,chunked-io", &val)) {
99 + dev_info(dev, "using chunked io (size=%d)\n", val);
100 + mtd->_read = spi_nor_chunked_read;
101 + mtd->_write = spi_nor_chunked_write;
102 + nor->chunk_size = val;
103 + }
104 } else {
105 /* If we weren't instantiated by DT, default to fast-read */
106 nor->flash_read = SPI_NOR_FAST;
107 --- a/include/linux/mtd/spi-nor.h
108 +++ b/include/linux/mtd/spi-nor.h
109 @@ -143,6 +143,7 @@ enum spi_nor_option_flags {
110 SNOR_F_S3AN_ADDR_DEFAULT = BIT(3),
111 SNOR_F_READY_XSR_RDY = BIT(4),
112 SNOR_F_4B_EXT_ADDR = BIT(5),
113 + SNOR_F_SST = BIT(6),
114 };
115
116 /**
117 @@ -182,6 +183,7 @@ struct spi_nor {
118 struct mutex lock;
119 struct device *dev;
120 u32 page_size;
121 + u16 chunk_size;
122 u8 addr_width;
123 u8 erase_opcode;
124 u8 read_opcode;