Refresh patches
[openwrt.git] / package / boot / uboot-lantiq / patches / 0005-sf-make-calculatiom-of-address-bytes-completely-conf.patch
1 From 6fb5f86b094756d94de8abe7425e3d290ff22dd2 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Sun, 13 Oct 2013 15:09:28 +0200
4 Subject: sf: make calculatiom of address bytes completely configurable
5
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
7
8 --- a/drivers/mtd/spi/sf_ops.c
9 +++ b/drivers/mtd/spi/sf_ops.c
10 @@ -15,12 +15,17 @@
11  
12  #include "sf_internal.h"
13  
14 -static void spi_flash_addr(u32 addr, u8 *cmd)
15 +static void spi_flash_addr(const struct spi_flash *flash, u32 addr, u8 *cmd)
16  {
17         /* cmd[0] is actual command */
18 -       cmd[1] = addr >> 16;
19 -       cmd[2] = addr >> 8;
20 -       cmd[3] = addr >> 0;
21 +       cmd[1] = addr >> (flash->addr_width * 8 - 8);
22 +       cmd[2] = addr >> (flash->addr_width * 8 - 16);
23 +       cmd[3] = addr >> (flash->addr_width * 8 - 24);
24 +}
25 +
26 +static int spi_flash_cmdsz(const struct spi_flash *flash)
27 +{
28 +       return 1 + flash->addr_width;
29  }
30  
31  int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
32 @@ -158,7 +163,7 @@ int spi_flash_write_common(struct spi_fl
33  int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
34  {
35         u32 erase_size;
36 -       u8 cmd[4];
37 +       u8 cmd[4], cmd_len;
38         int ret = -1;
39  
40         erase_size = flash->erase_size;
41 @@ -180,12 +185,13 @@ int spi_flash_cmd_erase_ops(struct spi_f
42                 if (ret < 0)
43                         goto done;
44  #endif
45 -               spi_flash_addr(offset, cmd);
46 +               spi_flash_addr(flash, offset, cmd);
47 +               cmd_len = spi_flash_cmdsz(flash);
48  
49                 debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
50                       cmd[2], cmd[3], offset);
51  
52 -               ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
53 +               ret = spi_flash_write_common(flash, cmd, cmd_len, NULL, 0);
54                 if (ret < 0) {
55                         debug("SF: erase failed\n");
56                         goto done;
57 @@ -206,7 +212,7 @@ int spi_flash_cmd_write_ops(struct spi_f
58  {
59         unsigned long byte_addr, page_size;
60         size_t chunk_len, actual;
61 -       u8 cmd[4];
62 +       u8 cmd[4], cmd_len;
63         int ret = -1;
64  
65         ret = spi_claim_bus(flash->spi);
66 @@ -230,12 +236,13 @@ int spi_flash_cmd_write_ops(struct spi_f
67                 if (flash->spi->max_write_size)
68                         chunk_len = min(chunk_len, flash->spi->max_write_size);
69  
70 -               spi_flash_addr(offset, cmd);
71 +               spi_flash_addr(flash, offset, cmd);
72 +               cmd_len = spi_flash_cmdsz(flash);
73  
74                 debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
75                       buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
76  
77 -               ret = spi_flash_write_common(flash, cmd, sizeof(cmd),
78 +               ret = spi_flash_write_common(flash, cmd, cmd_len,
79                                         buf + actual, chunk_len);
80                 if (ret < 0) {
81                         debug("SF: write failed\n");
82 @@ -269,7 +276,7 @@ int spi_flash_read_common(struct spi_fla
83  int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
84                 size_t len, void *data)
85  {
86 -       u8 cmd[5], bank_sel = 0;
87 +       u8 cmd[5], cmd_len, bank_sel = 0;
88         u32 remain_len, read_len;
89         int ret = -1;
90  
91 @@ -288,7 +295,6 @@ int spi_flash_cmd_read_ops(struct spi_fl
92         }
93  
94         cmd[0] = CMD_READ_ARRAY_FAST;
95 -       cmd[4] = 0x00;
96  
97         while (len) {
98  #ifdef CONFIG_SPI_FLASH_BAR
99 @@ -306,9 +312,11 @@ int spi_flash_cmd_read_ops(struct spi_fl
100                 else
101                         read_len = remain_len;
102  
103 -               spi_flash_addr(offset, cmd);
104 +               spi_flash_addr(flash, offset, cmd);
105 +               cmd_len = spi_flash_cmdsz(flash);
106 +               cmd[cmd_len] = 0x00;
107  
108 -               ret = spi_flash_read_common(flash, cmd, sizeof(cmd),
109 +               ret = spi_flash_read_common(flash, cmd, cmd_len + 1,
110                                                         data, read_len);
111                 if (ret < 0) {
112                         debug("SF: read failed\n");
113 --- a/drivers/mtd/spi/sf_probe.c
114 +++ b/drivers/mtd/spi/sf_probe.c
115 @@ -218,6 +218,9 @@ static int spi_flash_validate_params(str
116                 flash->poll_cmd = CMD_FLAG_STATUS;
117  #endif
118  
119 +       /* Configure default 3-byte addressing */
120 +       flash->addr_width = 3;
121 +
122         /* Configure the BAR - discover bank cmds and read current bank */
123  #ifdef CONFIG_SPI_FLASH_BAR
124         u8 curr_bank = 0;
125 --- a/include/spi_flash.h
126 +++ b/include/spi_flash.h
127 @@ -57,6 +57,7 @@ struct spi_flash {
128  #endif
129         u8 poll_cmd;
130         u8 erase_cmd;
131 +       u8 addr_width;
132  
133         void *memory_map;
134         int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);