ar71xx: enable UART function for early_printk/console
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / patches-3.3 / 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 @@ -100,6 +100,7 @@ struct m25p {
4 u16 addr_width;
5 u8 erase_opcode;
6 u8 *command;
7 + size_t max_read_len;
8 };
9
10 static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
11 @@ -352,6 +353,7 @@ static int m25p80_read(struct mtd_info *
12 struct m25p *flash = mtd_to_m25p(mtd);
13 struct spi_transfer t[2];
14 struct spi_message m;
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 @@ -374,8 +376,6 @@ static int m25p80_read(struct mtd_info *
20 t[0].len = m25p_cmdsz(flash) + FAST_READ_DUMMY_BYTE;
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 /* Byte count starts at zero. */
28 @@ -383,13 +383,6 @@ static int m25p80_read(struct mtd_info *
29
30 mutex_lock(&flash->lock);
31
32 - /* Wait till previous write/erase is done. */
33 - if (wait_till_ready(flash)) {
34 - /* REVISIT status return?? */
35 - mutex_unlock(&flash->lock);
36 - return 1;
37 - }
38 -
39 /* FIXME switch to OPCODE_FAST_READ. It's required for higher
40 * clocks; and at this writing, every chip this driver handles
41 * supports that opcode.
42 @@ -397,11 +390,44 @@ static int m25p80_read(struct mtd_info *
43
44 /* Set up the write data buffer. */
45 flash->command[0] = OPCODE_READ;
46 - m25p_addr2cmd(flash, from, flash->command);
47
48 - spi_sync(flash->spi, &m);
49 + ofs = 0;
50 + while (len) {
51 + size_t readlen;
52 + size_t done;
53 + int ret;
54 +
55 + ret = wait_till_ready(flash);
56 + if (ret) {
57 + mutex_unlock(&flash->lock);
58 + return 1;
59 + }
60 +
61 + if (flash->max_read_len > 0 &&
62 + flash->max_read_len < len)
63 + readlen = flash->max_read_len;
64 + else
65 + readlen = len;
66 +
67 + t[1].rx_buf = buf + ofs;
68 + t[1].len = readlen;
69 +
70 + m25p_addr2cmd(flash, from + ofs, flash->command);
71 +
72 + spi_sync(flash->spi, &m);
73
74 - *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE;
75 + done = m.actual_length - m25p_cmdsz(flash) -
76 + FAST_READ_DUMMY_BYTE;
77 + if (done != readlen) {
78 + mutex_unlock(&flash->lock);
79 + return 1;
80 + }
81 +
82 + ofs += done;
83 + len -= done;
84 + }
85 +
86 + *retlen = ofs;
87
88 mutex_unlock(&flash->lock);
89
90 @@ -924,6 +950,12 @@ static int __devinit m25p_probe(struct s
91 flash->mtd.erase = m25p80_erase;
92 flash->mtd.read = m25p80_read;
93
94 + if (data && data->max_read_len) {
95 + flash->max_read_len = data->max_read_len;
96 + dev_warn(&spi->dev, "max_read_len set to %d bytes\n",
97 + flash->max_read_len);
98 + }
99 +
100 /* sst flash chips use AAI word program */
101 if (JEDEC_MFR(info->jedec_id) == CFI_MFR_SST)
102 flash->mtd.write = sst_write;
103 --- a/include/linux/spi/flash.h
104 +++ b/include/linux/spi/flash.h
105 @@ -25,6 +25,7 @@ struct flash_platform_data {
106
107 char *type;
108
109 + size_t max_read_len;
110 /* we'll likely add more ... use JEDEC IDs, etc */
111 };
112