tools: install a fake empty ldconfig script to prevent the system ldconfig from messi...
[openwrt.git] / target / linux / ramips / patches-3.10 / 0131-mtd-add-chunked-read-io-to-m25p80.patch
1 From f85e6dacdb7d7a9bc37f33cf8770006ab64286f7 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 27 Nov 2013 20:58:16 +0100
4 Subject: [PATCH 131/133] mtd: add chunked read io to m25p80
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
8  drivers/mtd/devices/m25p80.c |  127 ++++++++++++++++++++++++++++++++++++++++++
9  1 file changed, 127 insertions(+)
10
11 --- a/drivers/mtd/devices/m25p80.c
12 +++ b/drivers/mtd/devices/m25p80.c
13 @@ -392,6 +392,58 @@ static int m25p80_read(struct mtd_info *
14         return 0;
15  }
16  
17 +static int m25p80_read_chunked(struct mtd_info *mtd, loff_t from, size_t len,
18 +       size_t *retlen, u_char *buf)
19 +{
20 +       struct m25p *flash = mtd_to_m25p(mtd);
21 +       struct spi_transfer t[2];
22 +       struct spi_message m;
23 +       uint8_t opcode;
24 +       int idx = 0;
25 +
26 +       pr_debug("%s: %s from 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
27 +                       __func__, (u32)from, len);
28 +
29 +       spi_message_init(&m);
30 +       memset(t, 0, (sizeof t));
31 +
32 +       t[0].tx_buf = flash->command;
33 +       t[0].len = m25p_cmdsz(flash);
34 +       spi_message_add_tail(&t[0], &m);
35 +       spi_message_add_tail(&t[1], &m);
36 +
37 +       *retlen = 0;
38 +
39 +       while (idx < len) {
40 +               int rlen = (len - idx > 4) ? (4) : (len - idx);
41 +
42 +               t[1].rx_buf = &buf[idx];
43 +               t[1].len = rlen;
44 +
45 +               mutex_lock(&flash->lock);
46 +
47 +               /* Wait till previous write/erase is done. */
48 +               if (wait_till_ready(flash)) {
49 +                       /* REVISIT status return?? */
50 +                       mutex_unlock(&flash->lock);
51 +                       return 1;
52 +               }
53 +
54 +               /* Set up the write data buffer. */
55 +               opcode = OPCODE_NORM_READ;
56 +               flash->command[0] = opcode;
57 +               m25p_addr2cmd(flash, from + idx, flash->command);
58 +
59 +               spi_sync(flash->spi, &m);
60 +
61 +               *retlen += m.actual_length - m25p_cmdsz(flash);
62 +
63 +               mutex_unlock(&flash->lock);
64 +               idx += rlen;
65 +       }
66 +       return 0;
67 +}
68 +
69  /*
70   * Write an address range to the flash chip.  Data must be written in
71   * FLASH_PAGESIZE chunks.  The address range may be any size provided
72 @@ -479,6 +531,76 @@ static int m25p80_write(struct mtd_info
73         return 0;
74  }
75  
76 +static int m25p80_write_chunked(struct mtd_info *mtd, loff_t to, size_t len,
77 +       size_t *retlen, const u_char *buf)
78 +{
79 +       struct m25p *flash = mtd_to_m25p(mtd);
80 +       struct spi_transfer t;
81 +       struct spi_message m;
82 +       u32 i, page_size;
83 +       u8 tmp[8];
84 +
85 +       pr_debug("%s: %s to 0x%08x, len %zd\n", dev_name(&flash->spi->dev),
86 +                       __func__, (u32)to, len);
87 +
88 +       spi_message_init(&m);
89 +       memset(&t, 0, (sizeof t));
90 +
91 +       t.tx_buf = tmp;
92 +       t.len = 8;
93 +       spi_message_add_tail(&t, &m);
94 +
95 +       mutex_lock(&flash->lock);
96 +
97 +       /* Wait until finished previous write command. */
98 +       if (wait_till_ready(flash)) {
99 +               mutex_unlock(&flash->lock);
100 +               return 1;
101 +       }
102 +
103 +       write_enable(flash);
104 +
105 +       /* Set up the opcode in the write buffer. */
106 +       flash->command[0] = OPCODE_PP;
107 +       m25p_addr2cmd(flash, to, flash->command);
108 +
109 +       t.len = 4 + (to & 0x3);
110 +       if (t.len == 4)
111 +               t.len = 8;
112 +       memcpy(tmp, flash->command, 4);
113 +       memcpy(&tmp[4], buf, t.len - 4);
114 +       spi_sync(flash->spi, &m);
115 +       page_size = t.len - 4;
116 +
117 +       *retlen = m.actual_length - m25p_cmdsz(flash);
118 +
119 +       /* write everything in flash->page_size chunks */
120 +       for (i = page_size; i < len; i += page_size) {
121 +               page_size = len - i;
122 +               if (page_size > 4)
123 +                       page_size = 4;
124 +
125 +               /* write the next page to flash */
126 +               m25p_addr2cmd(flash, to + i, flash->command);
127 +
128 +               memcpy(tmp, flash->command, 4);
129 +               memcpy(&tmp[4], buf + i, page_size);
130 +               t.len = 4 + page_size;
131 +
132 +               wait_till_ready(flash);
133 +
134 +               write_enable(flash);
135 +
136 +               spi_sync(flash->spi, &m);
137 +
138 +               *retlen += m.actual_length - m25p_cmdsz(flash);
139 +       }
140 +
141 +       mutex_unlock(&flash->lock);
142 +
143 +       return 0;
144 +}
145 +
146  static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
147                 size_t *retlen, const u_char *buf)
148  {
149 @@ -1059,6 +1181,12 @@ static int m25p_probe(struct spi_device
150                 flash->fast_read = true;
151  #endif
152  
153 +       if (np && of_property_read_bool(np, "m25p,chunked-io")) {
154 +               dev_warn(&spi->dev, "using chunked io\n");
155 +               flash->mtd._read = m25p80_read_chunked;
156 +               flash->mtd._write = m25p80_write_chunked;
157 +       }
158 +
159  #ifdef CONFIG_M25PXX_USE_FAST_READ
160         flash->fast_read = true;
161  #endif