kobs-ng: add new package
[openwrt/staging/wigyori.git] / package / boot / uboot-lantiq / patches / 0005-sf-factor-out-the-flash-address-calculation.patch
1 From acb2721e1cd2e7488a7b08a4ed590177369a1689 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Tue, 6 Nov 2012 19:10:40 +0100
4 Subject: sf: factor out the flash address calculation
5
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
7
8 --- a/drivers/mtd/spi/spi_flash.c
9 +++ b/drivers/mtd/spi/spi_flash.c
10 @@ -15,12 +15,22 @@
11
12 #include "spi_flash_internal.h"
13
14 -static void spi_flash_addr(u32 addr, u8 *cmd)
15 +static void spi_flash_addr(struct spi_flash *flash, u32 addr, u8 *cmd, u8 *cmd_len)
16 {
17 /* cmd[0] is actual command */
18 cmd[1] = addr >> 16;
19 cmd[2] = addr >> 8;
20 cmd[3] = addr >> 0;
21 + *cmd_len = 4;
22 +}
23 +
24 +static void spi_flash_page_addr(struct spi_flash *flash, u32 page_addr, u32 byte_addr, u8 *cmd, u8 *cmd_len)
25 +{
26 + /* cmd[0] is actual command */
27 + cmd[1] = page_addr >> 8;
28 + cmd[2] = page_addr >> 0;
29 + cmd[3] = byte_addr;
30 + *cmd_len = 4;
31 }
32
33 static int spi_flash_read_write(struct spi_slave *spi,
34 @@ -71,7 +81,7 @@ int spi_flash_cmd_write_multi(struct spi
35 unsigned long page_addr, byte_addr, page_size;
36 size_t chunk_len, actual;
37 int ret;
38 - u8 cmd[4];
39 + u8 cmd[4], cmd_len;
40
41 page_size = flash->page_size;
42 page_addr = offset / page_size;
43 @@ -87,9 +97,7 @@ int spi_flash_cmd_write_multi(struct spi
44 for (actual = 0; actual < len; actual += chunk_len) {
45 chunk_len = min(len - actual, page_size - byte_addr);
46
47 - cmd[1] = page_addr >> 8;
48 - cmd[2] = page_addr;
49 - cmd[3] = byte_addr;
50 + spi_flash_page_addr(flash, page_addr, byte_addr, cmd, &cmd_len);
51
52 debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
53 buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
54 @@ -100,7 +108,7 @@ int spi_flash_cmd_write_multi(struct spi
55 break;
56 }
57
58 - ret = spi_flash_cmd_write(flash->spi, cmd, 4,
59 + ret = spi_flash_cmd_write(flash->spi, cmd, cmd_len,
60 buf + actual, chunk_len);
61 if (ret < 0) {
62 debug("SF: write failed\n");
63 @@ -138,13 +146,13 @@ int spi_flash_read_common(struct spi_fla
64 int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
65 size_t len, void *data)
66 {
67 - u8 cmd[5];
68 + u8 cmd[5], cmd_len;
69
70 cmd[0] = CMD_READ_ARRAY_FAST;
71 - spi_flash_addr(offset, cmd);
72 - cmd[4] = 0x00;
73 + spi_flash_addr(flash, offset, cmd, &cmd_len);
74 + cmd[cmd_len] = 0x00;
75
76 - return spi_flash_read_common(flash, cmd, sizeof(cmd), data, len);
77 + return spi_flash_read_common(flash, cmd, cmd_len + 1, data, len);
78 }
79
80 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
81 @@ -194,7 +202,7 @@ int spi_flash_cmd_erase(struct spi_flash
82 {
83 u32 start, end, erase_size;
84 int ret;
85 - u8 cmd[4];
86 + u8 cmd[4], cmd_len;
87
88 erase_size = flash->sector_size;
89 if (offset % erase_size || len % erase_size) {
90 @@ -216,7 +224,7 @@ int spi_flash_cmd_erase(struct spi_flash
91 end = start + len;
92
93 while (offset < end) {
94 - spi_flash_addr(offset, cmd);
95 + spi_flash_addr(flash, offset, cmd, &cmd_len);
96 offset += erase_size;
97
98 debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
99 @@ -226,7 +234,7 @@ int spi_flash_cmd_erase(struct spi_flash
100 if (ret)
101 goto out;
102
103 - ret = spi_flash_cmd_write(flash->spi, cmd, sizeof(cmd), NULL, 0);
104 + ret = spi_flash_cmd_write(flash->spi, cmd, cmd_len, NULL, 0);
105 if (ret)
106 goto out;
107