ar71xx: disable irq on reboot to fix hang issues (fixes #17839)
[openwrt.git] / target / linux / ar71xx / patches-3.14 / 406-mtd-m25p80-allow-to-specify-max-read-size.patch
1 --- a/drivers/mtd/devices/m25p80.c
2 +++ b/drivers/mtd/devices/m25p80.c
3 @@ -115,6 +115,7 @@ struct m25p {
4         u8                      program_opcode;
5         u8                      *command;
6         enum read_type          flash_read;
7 +       size_t                  max_read_len;
8  };
9  
10  static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
11 @@ -517,6 +518,7 @@ static int m25p80_read(struct mtd_info *
12         struct spi_message m;
13         uint8_t opcode;
14         int dummy;
15 +       loff_t ofs;
16  
17         pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
18                         __func__, (u32)from, len);
19 @@ -534,29 +536,51 @@ static int m25p80_read(struct mtd_info *
20         t[0].len = m25p_cmdsz(flash) + dummy;
21         spi_message_add_tail(&t[0], &m);
22  
23 -       t[1].rx_buf = buf;
24 -       t[1].rx_nbits = m25p80_rx_nbits(flash);
25 -       t[1].len = len;
26         spi_message_add_tail(&t[1], &m);
27  
28         mutex_lock(&flash->lock);
29  
30 -       /* Wait till previous write/erase is done. */
31 -       if (wait_till_ready(flash)) {
32 -               /* REVISIT status return?? */
33 -               mutex_unlock(&flash->lock);
34 -               return 1;
35 -       }
36 -
37         /* Set up the write data buffer. */
38         opcode = flash->read_opcode;
39         flash->command[0] = opcode;
40 -       m25p_addr2cmd(flash, from, flash->command);
41 +       ofs = 0;
42 +       while (len) {
43 +               size_t readlen;
44 +               size_t done;
45 +               int ret;
46  
47 -       spi_sync(flash->spi, &m);
48 +               ret = wait_till_ready(flash);
49 +               if (ret) {
50 +                       mutex_unlock(&flash->lock);
51 +                       return 1;
52 +               }
53 +
54 +               if (flash->max_read_len > 0 &&
55 +                   flash->max_read_len < len)
56 +                       readlen = flash->max_read_len;
57 +               else
58 +                       readlen = len;
59  
60 -       *retlen = m.actual_length - m25p_cmdsz(flash) - dummy;
61 +               t[1].rx_buf = buf + ofs;
62 +               t[1].rx_nbits = m25p80_rx_nbits(flash);
63 +               t[1].len = readlen;
64  
65 +               m25p_addr2cmd(flash, from + ofs, flash->command);
66 +
67 +               spi_sync(flash->spi, &m);
68 +
69 +               done = m.actual_length - m25p_cmdsz(flash) -
70 +                      dummy;
71 +               if (done != readlen) {
72 +                       mutex_unlock(&flash->lock);
73 +                       return 1;
74 +               }
75 +
76 +               ofs += done;
77 +               len -= done;
78 +       }
79 +
80 +       *retlen = ofs;
81         mutex_unlock(&flash->lock);
82  
83         return 0;
84 @@ -1193,6 +1217,12 @@ static int m25p_probe(struct spi_device 
85                 flash->mtd._unlock = m25p80_unlock;
86         }
87  
88 +       if (data && data->max_read_len) {
89 +               flash->max_read_len = data->max_read_len;
90 +               dev_warn(&spi->dev, "max_read_len set to %d bytes\n",
91 +                       flash->max_read_len);
92 +       }
93 +
94         /* sst flash chips use AAI word program */
95         if (info->flags & SST_WRITE)
96                 flash->mtd._write = sst_write;
97 --- a/include/linux/spi/flash.h
98 +++ b/include/linux/spi/flash.h
99 @@ -25,6 +25,7 @@ struct flash_platform_data {
100  
101         char            *type;
102  
103 +       size_t          max_read_len;
104         /* we'll likely add more ... use JEDEC IDs, etc */
105  };
106