ar71xx: improve support for the My Net Wi-Fi Range Extender device
[openwrt.git] / target / linux / ar71xx / patches-3.10 / 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 @@ -93,6 +93,7 @@ struct m25p {
4         u8                      erase_opcode;
5         u8                      *command;
6         bool                    fast_read;
7 +       size_t                  max_read_len;
8  };
9  
10  static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
11 @@ -344,6 +345,7 @@ static int m25p80_read(struct mtd_info *
12         struct spi_transfer t[2];
13         struct spi_message m;
14         uint8_t opcode;
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 @@ -359,19 +361,10 @@ static int m25p80_read(struct mtd_info *
20         t[0].len = m25p_cmdsz(flash) + (flash->fast_read ? 1 : 0);
21         spi_message_add_tail(&t[0], &m);
22  
23 -       t[1].rx_buf = buf;
24 -       t[1].len = len;
25         spi_message_add_tail(&t[1], &m);
26  
27         mutex_lock(&flash->lock);
28  
29 -       /* Wait till previous write/erase is done. */
30 -       if (wait_till_ready(flash)) {
31 -               /* REVISIT status return?? */
32 -               mutex_unlock(&flash->lock);
33 -               return 1;
34 -       }
35 -
36         /* FIXME switch to OPCODE_FAST_READ.  It's required for higher
37          * clocks; and at this writing, every chip this driver handles
38          * supports that opcode.
39 @@ -380,13 +373,43 @@ static int m25p80_read(struct mtd_info *
40         /* Set up the write data buffer. */
41         opcode = flash->fast_read ? OPCODE_FAST_READ : OPCODE_NORM_READ;
42         flash->command[0] = opcode;
43 -       m25p_addr2cmd(flash, from, flash->command);
44 +       ofs = 0;
45 +       while (len) {
46 +               size_t readlen;
47 +               size_t done;
48 +               int ret;
49 +
50 +               ret = wait_till_ready(flash);
51 +               if (ret) {
52 +                       mutex_unlock(&flash->lock);
53 +                       return 1;
54 +               }
55 +
56 +               if (flash->max_read_len > 0 &&
57 +                   flash->max_read_len < len)
58 +                       readlen = flash->max_read_len;
59 +               else
60 +                       readlen = len;
61 +
62 +               t[1].rx_buf = buf + ofs;
63 +               t[1].len = readlen;
64 +
65 +               m25p_addr2cmd(flash, from + ofs, flash->command);
66 +
67 +               spi_sync(flash->spi, &m);
68  
69 -       spi_sync(flash->spi, &m);
70 +               done = m.actual_length - m25p_cmdsz(flash) -
71 +                      (flash->fast_read ? 1 : 0);
72 +               if (done != readlen) {
73 +                       mutex_unlock(&flash->lock);
74 +                       return 1;
75 +               }
76  
77 -       *retlen = m.actual_length - m25p_cmdsz(flash) -
78 -                       (flash->fast_read ? 1 : 0);
79 +               ofs += done;
80 +               len -= done;
81 +       }
82  
83 +       *retlen = ofs;
84         mutex_unlock(&flash->lock);
85  
86         return 0;
87 @@ -1020,6 +1043,12 @@ static int m25p_probe(struct spi_device
88                 flash->mtd._unlock = m25p80_unlock;
89         }
90  
91 +       if (data && data->max_read_len) {
92 +               flash->max_read_len = data->max_read_len;
93 +               dev_warn(&spi->dev, "max_read_len set to %d bytes\n",
94 +                       flash->max_read_len);
95 +       }
96 +
97         /* sst flash chips use AAI word program */
98         if (info->flags & SST_WRITE)
99                 flash->mtd._write = sst_write;
100 --- a/include/linux/spi/flash.h
101 +++ b/include/linux/spi/flash.h
102 @@ -25,6 +25,7 @@ struct flash_platform_data {
103  
104         char            *type;
105  
106 +       size_t          max_read_len;
107         /* we'll likely add more ... use JEDEC IDs, etc */
108  };
109