Rebased from upstream / out of band repository.
[librecmc/librecmc.git] / target / linux / generic / pending-4.9 / 450-mtd-m25p80-allow-fallback-from-spi_flash_read-to-reg.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 23 Feb 2018 17:12:16 +0100
3 Subject: [PATCH] mtd: m25p80: allow fallback from spi_flash_read to regular
4  SPI transfer
5
6 Some flash controllers, e.g. on the ath79 platform can support a fast
7 flash read via memory mapping, but only if the flash chip is in
8 3-byte address mode.
9
10 Since spi_flash_read_supported does not have access to the same data as
11 spi_flash_read, the driver can't detect an unsupported call until m25p80
12 has decided to use spi_flash_read.
13
14 Allow the driver to indicate a fallback to a regular SPI transfer by
15 returning -EOPNOTSUPP
16
17 Signed-off-by: Felix Fietkau <nbd@nbd.name>
18 ---
19
20 --- a/drivers/mtd/devices/m25p80.c
21 +++ b/drivers/mtd/devices/m25p80.c
22 @@ -155,9 +155,11 @@ static ssize_t m25p80_read(struct spi_no
23                 msg.data_nbits = m25p80_rx_nbits(nor);
24  
25                 ret = spi_flash_read(spi, &msg);
26 -               if (ret < 0)
27 -                       return ret;
28 -               return msg.retlen;
29 +               if (ret != -EOPNOTSUPP) {
30 +                       if (ret < 0)
31 +                               return ret;
32 +                       return msg.retlen;
33 +               }
34         }
35  
36         spi_message_init(&m);