Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SPI flash interface |
| 3 | * |
| 4 | * Copyright (C) 2008 Atmel Corporation |
| 5 | * Copyright (C) 2010 Reinhard Meyer, EMK Elektronik |
| 6 | * |
| 7 | * Licensed under the GPL-2 or later. |
| 8 | */ |
| 9 | |
Edward O'Callaghan | c4561e2 | 2014-06-26 15:02:40 +1000 | [diff] [blame] | 10 | #include <cpu/x86/smm.h> |
| 11 | #include <delay.h> |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
Zheng Bao | 600784e | 2013-02-07 17:30:23 +0800 | [diff] [blame] | 14 | #include <spi-generic.h> |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 15 | #include <spi_flash.h> |
Edward O'Callaghan | c4561e2 | 2014-06-26 15:02:40 +1000 | [diff] [blame] | 16 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 17 | #include "spi_flash_internal.h" |
Dave Frodin | c50c0ab | 2014-06-11 12:53:47 -0600 | [diff] [blame] | 18 | #include <timer.h> |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 19 | |
| 20 | static void spi_flash_addr(u32 addr, u8 *cmd) |
| 21 | { |
| 22 | /* cmd[0] is actual command */ |
| 23 | cmd[1] = addr >> 16; |
| 24 | cmd[2] = addr >> 8; |
| 25 | cmd[3] = addr >> 0; |
| 26 | } |
| 27 | |
David Hendricks | f101bbe | 2014-03-21 19:13:34 -0700 | [diff] [blame] | 28 | /* |
| 29 | * If atomic sequencing is used, the cycle type is known to the SPI |
| 30 | * controller so that it can perform consecutive transfers and arbitrate |
| 31 | * automatically. Otherwise the SPI controller transfers whatever the |
| 32 | * user requests immediately, without regard to sequence. Atomic |
| 33 | * sequencing is commonly used on x86 platforms. |
| 34 | * |
| 35 | * SPI flash commands are simple two-step sequences. The command byte is |
| 36 | * always written first and may be followed by an address. Then data is |
| 37 | * either read or written. For atomic sequencing we'll pass everything into |
| 38 | * spi_xfer() at once and let the controller handle the details. Otherwise |
| 39 | * we will write all output bytes first and then read if necessary. |
| 40 | * |
| 41 | * FIXME: This really should be abstracted better, but that will |
| 42 | * require overhauling the entire SPI infrastructure. |
| 43 | */ |
| 44 | static int do_spi_flash_cmd(struct spi_slave *spi, const void *dout, |
| 45 | unsigned int bytes_out, void *din, unsigned int bytes_in) |
| 46 | { |
| 47 | int ret = 1; |
| 48 | |
David Hendricks | 032c843 | 2014-04-11 19:48:55 -0700 | [diff] [blame] | 49 | if (spi_claim_bus(spi)) |
| 50 | return ret; |
| 51 | |
David Hendricks | f101bbe | 2014-03-21 19:13:34 -0700 | [diff] [blame] | 52 | #if CONFIG_SPI_ATOMIC_SEQUENCING == 1 |
| 53 | if (spi_xfer(spi, dout, bytes_out, din, bytes_in) < 0) |
| 54 | goto done; |
| 55 | #else |
| 56 | if (dout && bytes_out) { |
| 57 | if (spi_xfer(spi, dout, bytes_out, NULL, 0) < 0) |
| 58 | goto done; |
| 59 | } |
| 60 | |
| 61 | if (din && bytes_in) { |
| 62 | if (spi_xfer(spi, NULL, 0, din, bytes_in) < 0) |
| 63 | goto done; |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | ret = 0; |
| 68 | done: |
David Hendricks | 032c843 | 2014-04-11 19:48:55 -0700 | [diff] [blame] | 69 | spi_release_bus(spi); |
David Hendricks | f101bbe | 2014-03-21 19:13:34 -0700 | [diff] [blame] | 70 | return ret; |
| 71 | } |
| 72 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 73 | int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len) |
| 74 | { |
David Hendricks | f101bbe | 2014-03-21 19:13:34 -0700 | [diff] [blame] | 75 | int ret = do_spi_flash_cmd(spi, &cmd, sizeof(cmd), response, len); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 76 | if (ret) |
| 77 | printk(BIOS_WARNING, "SF: Failed to send command %02x: %d\n", cmd, ret); |
| 78 | |
| 79 | return ret; |
| 80 | } |
| 81 | |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 82 | static int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd, |
| 83 | size_t cmd_len, void *data, size_t data_len) |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 84 | { |
David Hendricks | f101bbe | 2014-03-21 19:13:34 -0700 | [diff] [blame] | 85 | int ret = do_spi_flash_cmd(spi, cmd, cmd_len, data, data_len); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 86 | if (ret) { |
| 87 | printk(BIOS_WARNING, "SF: Failed to send read command (%zu bytes): %d\n", |
| 88 | data_len, ret); |
| 89 | } |
| 90 | |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len, |
| 95 | const void *data, size_t data_len) |
| 96 | { |
| 97 | int ret; |
| 98 | u8 buff[cmd_len + data_len]; |
| 99 | memcpy(buff, cmd, cmd_len); |
| 100 | memcpy(buff + cmd_len, data, data_len); |
| 101 | |
David Hendricks | f101bbe | 2014-03-21 19:13:34 -0700 | [diff] [blame] | 102 | ret = do_spi_flash_cmd(spi, buff, cmd_len + data_len, NULL, 0); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 103 | if (ret) { |
| 104 | printk(BIOS_WARNING, "SF: Failed to send write command (%zu bytes): %d\n", |
| 105 | data_len, ret); |
| 106 | } |
| 107 | |
| 108 | return ret; |
| 109 | } |
| 110 | |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 111 | static int spi_flash_cmd_read_array(struct spi_slave *spi, u8 *cmd, |
| 112 | size_t cmd_len, u32 offset, |
| 113 | size_t len, void *data) |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 114 | { |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 115 | while (len) { |
| 116 | size_t transfer_size; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 117 | |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 118 | if (spi->max_transfer_size) |
| 119 | transfer_size = min(len, spi->max_transfer_size); |
| 120 | else |
| 121 | transfer_size = len; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 122 | |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 123 | spi_flash_addr(offset, cmd); |
| 124 | |
| 125 | if (spi_flash_cmd_read(spi, cmd, cmd_len, data, transfer_size)) |
| 126 | break; |
| 127 | |
| 128 | offset += transfer_size; |
| 129 | data = (void *)((uintptr_t)data + transfer_size); |
| 130 | len -= transfer_size; |
| 131 | } |
| 132 | |
| 133 | return len != 0; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, |
| 137 | size_t len, void *data) |
| 138 | { |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 139 | u8 cmd[5]; |
| 140 | |
| 141 | cmd[0] = CMD_READ_ARRAY_FAST; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 142 | cmd[4] = 0x00; |
| 143 | |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 144 | return spi_flash_cmd_read_array(flash->spi, cmd, sizeof(cmd), |
| 145 | offset, len, data); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | int spi_flash_cmd_read_slow(struct spi_flash *flash, u32 offset, |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 149 | size_t len, void *data) |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 150 | { |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 151 | u8 cmd[4]; |
| 152 | |
| 153 | cmd[0] = CMD_READ_ARRAY_SLOW; |
Vadim Bendebury | f9ff353 | 2014-11-29 15:06:26 -0800 | [diff] [blame^] | 154 | return spi_flash_cmd_read_array(flash->spi, cmd, sizeof(cmd), |
| 155 | offset, len, data); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout, |
| 159 | u8 cmd, u8 poll_bit) |
| 160 | { |
| 161 | struct spi_slave *spi = flash->spi; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 162 | int ret; |
| 163 | u8 status; |
Dave Frodin | c50c0ab | 2014-06-11 12:53:47 -0600 | [diff] [blame] | 164 | struct mono_time current, end; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 165 | |
Dave Frodin | c50c0ab | 2014-06-11 12:53:47 -0600 | [diff] [blame] | 166 | timer_monotonic_get(¤t); |
| 167 | end = current; |
| 168 | mono_time_add_msecs(&end, timeout); |
| 169 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 170 | do { |
| 171 | ret = spi_flash_cmd_read(spi, &cmd, 1, &status, 1); |
| 172 | if (ret) |
| 173 | return -1; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 174 | if ((status & poll_bit) == 0) |
Dave Frodin | c50c0ab | 2014-06-11 12:53:47 -0600 | [diff] [blame] | 175 | return 0; |
| 176 | timer_monotonic_get(¤t); |
| 177 | } while (!mono_time_after(¤t, &end)); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 178 | |
Dave Frodin | c50c0ab | 2014-06-11 12:53:47 -0600 | [diff] [blame] | 179 | printk(BIOS_DEBUG, "SF: timeout at %ld msec\n",timeout); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 180 | return -1; |
| 181 | } |
| 182 | |
| 183 | int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout) |
| 184 | { |
| 185 | return spi_flash_cmd_poll_bit(flash, timeout, |
| 186 | CMD_READ_STATUS, STATUS_WIP); |
| 187 | } |
| 188 | |
| 189 | int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd, |
| 190 | u32 offset, size_t len) |
| 191 | { |
| 192 | u32 start, end, erase_size; |
| 193 | int ret; |
| 194 | u8 cmd[4]; |
| 195 | |
| 196 | erase_size = flash->sector_size; |
| 197 | if (offset % erase_size || len % erase_size) { |
| 198 | printk(BIOS_WARNING, "SF: Erase offset/length not multiple of erase size\n"); |
| 199 | return -1; |
| 200 | } |
| 201 | |
Martin Roth | 3316cf2 | 2012-12-05 16:22:54 -0700 | [diff] [blame] | 202 | flash->spi->rw = SPI_WRITE_FLAG; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 203 | |
| 204 | cmd[0] = erase_cmd; |
| 205 | start = offset; |
| 206 | end = start + len; |
| 207 | |
| 208 | while (offset < end) { |
| 209 | spi_flash_addr(offset, cmd); |
| 210 | offset += erase_size; |
| 211 | |
Marc Jones | 747127d | 2012-12-03 22:16:29 -0700 | [diff] [blame] | 212 | #if CONFIG_DEBUG_SPI_FLASH |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 213 | printk(BIOS_SPEW, "SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1], |
| 214 | cmd[2], cmd[3], offset); |
Marc Jones | 747127d | 2012-12-03 22:16:29 -0700 | [diff] [blame] | 215 | #endif |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 216 | ret = spi_flash_cmd(flash->spi, CMD_WRITE_ENABLE, NULL, 0); |
| 217 | if (ret) |
| 218 | goto out; |
| 219 | |
| 220 | ret = spi_flash_cmd_write(flash->spi, cmd, sizeof(cmd), NULL, 0); |
| 221 | if (ret) |
| 222 | goto out; |
| 223 | |
| 224 | ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PAGE_ERASE_TIMEOUT); |
| 225 | if (ret) |
| 226 | goto out; |
| 227 | } |
| 228 | |
| 229 | printk(BIOS_DEBUG, "SF: Successfully erased %zu bytes @ %#x\n", len, start); |
| 230 | |
Patrick Georgi | 20959ba | 2012-05-12 23:30:36 +0200 | [diff] [blame] | 231 | out: |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | * The following table holds all device probe functions |
| 237 | * |
| 238 | * shift: number of continuation bytes before the ID |
| 239 | * idcode: the expected IDCODE or 0xff for non JEDEC devices |
| 240 | * probe: the function to call |
| 241 | * |
| 242 | * Non JEDEC devices should be ordered in the table such that |
| 243 | * the probe functions with best detection algorithms come first. |
| 244 | * |
| 245 | * Several matching entries are permitted, they will be tried |
| 246 | * in sequence until a probe function returns non NULL. |
| 247 | * |
| 248 | * IDCODE_CONT_LEN may be redefined if a device needs to declare a |
| 249 | * larger "shift" value. IDCODE_PART_LEN generally shouldn't be |
| 250 | * changed. This is the max number of bytes probe functions may |
| 251 | * examine when looking up part-specific identification info. |
| 252 | * |
| 253 | * Probe functions will be given the idcode buffer starting at their |
| 254 | * manu id byte (the "idcode" in the table below). In other words, |
| 255 | * all of the continuation bytes will be skipped (the "shift" below). |
| 256 | */ |
| 257 | #define IDCODE_CONT_LEN 0 |
| 258 | #define IDCODE_PART_LEN 5 |
Duncan Laurie | 181bbdd | 2012-06-23 16:53:57 -0700 | [diff] [blame] | 259 | static struct { |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 260 | const u8 shift; |
| 261 | const u8 idcode; |
| 262 | struct spi_flash *(*probe) (struct spi_slave *spi, u8 *idcode); |
| 263 | } flashes[] = { |
| 264 | /* Keep it sorted by define name */ |
Idwer Vollering | 73a1018 | 2014-02-16 00:32:13 +0000 | [diff] [blame] | 265 | #if CONFIG_SPI_FLASH_AMIC |
| 266 | { 0, 0x37, spi_flash_probe_amic, }, |
| 267 | #endif |
Kyösti Mälkki | 96d9276 | 2014-11-11 15:04:38 +0200 | [diff] [blame] | 268 | #if CONFIG_SPI_FLASH_ATMEL |
| 269 | { 0, 0x1f, spi_flash_probe_atmel, }, |
| 270 | #endif |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 271 | #if CONFIG_SPI_FLASH_EON |
| 272 | { 0, 0x1c, spi_flash_probe_eon, }, |
| 273 | #endif |
Martin Roth | bceaf7f | 2012-09-07 15:02:35 -0600 | [diff] [blame] | 274 | #if CONFIG_SPI_FLASH_GIGADEVICE |
| 275 | { 0, 0xc8, spi_flash_probe_gigadevice, }, |
| 276 | #endif |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 277 | #if CONFIG_SPI_FLASH_MACRONIX |
| 278 | { 0, 0xc2, spi_flash_probe_macronix, }, |
| 279 | #endif |
| 280 | #if CONFIG_SPI_FLASH_SPANSION |
| 281 | { 0, 0x01, spi_flash_probe_spansion, }, |
| 282 | #endif |
| 283 | #if CONFIG_SPI_FLASH_SST |
| 284 | { 0, 0xbf, spi_flash_probe_sst, }, |
| 285 | #endif |
| 286 | #if CONFIG_SPI_FLASH_STMICRO |
| 287 | { 0, 0x20, spi_flash_probe_stmicro, }, |
| 288 | #endif |
| 289 | #if CONFIG_SPI_FLASH_WINBOND |
| 290 | { 0, 0xef, spi_flash_probe_winbond, }, |
| 291 | #endif |
| 292 | /* Keep it sorted by best detection */ |
| 293 | #if CONFIG_SPI_FLASH_STMICRO |
| 294 | { 0, 0xff, spi_flash_probe_stmicro, }, |
| 295 | #endif |
Chris Douglass | b34739b | 2014-02-14 13:51:26 -0500 | [diff] [blame] | 296 | #if CONFIG_SPI_FLASH_ADESTO |
| 297 | { 0, 0x1f, spi_flash_probe_adesto, }, |
| 298 | #endif |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 299 | }; |
| 300 | #define IDCODE_LEN (IDCODE_CONT_LEN + IDCODE_PART_LEN) |
| 301 | |
Gabe Black | 1e18735 | 2014-03-27 20:37:03 -0700 | [diff] [blame] | 302 | struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs) |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 303 | { |
| 304 | struct spi_slave *spi; |
| 305 | struct spi_flash *flash = NULL; |
| 306 | int ret, i, shift; |
| 307 | u8 idcode[IDCODE_LEN], *idp; |
| 308 | |
Gabe Black | 1e18735 | 2014-03-27 20:37:03 -0700 | [diff] [blame] | 309 | spi = spi_setup_slave(bus, cs); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 310 | if (!spi) { |
| 311 | printk(BIOS_WARNING, "SF: Failed to set up slave\n"); |
| 312 | return NULL; |
| 313 | } |
| 314 | |
Martin Roth | 3316cf2 | 2012-12-05 16:22:54 -0700 | [diff] [blame] | 315 | spi->rw = SPI_READ_FLAG; |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 316 | |
Vladimir Serbinenko | e23bd0e | 2014-01-18 17:45:32 +0100 | [diff] [blame] | 317 | if (spi->force_programmer_specific && spi->programmer_specific_probe) { |
| 318 | flash = spi->programmer_specific_probe (spi); |
| 319 | if (!flash) |
| 320 | goto err_read_id; |
| 321 | goto flash_detected; |
| 322 | } |
| 323 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 324 | /* Read the ID codes */ |
| 325 | ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode)); |
| 326 | if (ret) |
| 327 | goto err_read_id; |
| 328 | |
| 329 | #if CONFIG_DEBUG_SPI_FLASH |
David Hendricks | b598bb3 | 2014-03-21 19:32:09 -0700 | [diff] [blame] | 330 | printk(BIOS_SPEW, "SF: Got idcode: "); |
| 331 | for (i = 0; i < sizeof(idcode); i++) |
| 332 | printk(BIOS_SPEW, "%02x ", idcode[i]); |
| 333 | printk(BIOS_SPEW, "\n"); |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 334 | #endif |
| 335 | |
| 336 | /* count the number of continuation bytes */ |
| 337 | for (shift = 0, idp = idcode; |
| 338 | shift < IDCODE_CONT_LEN && *idp == 0x7f; |
| 339 | ++shift, ++idp) |
| 340 | continue; |
| 341 | |
| 342 | /* search the table for matches in shift and id */ |
| 343 | for (i = 0; i < ARRAY_SIZE(flashes); ++i) |
| 344 | if (flashes[i].shift == shift && flashes[i].idcode == *idp) { |
Duncan Laurie | 23b0053 | 2012-10-10 14:21:23 -0700 | [diff] [blame] | 345 | #if CONFIG_SMM_TSEG && defined(__SMM__) |
Duncan Laurie | 181bbdd | 2012-06-23 16:53:57 -0700 | [diff] [blame] | 346 | /* Need to relocate this function */ |
| 347 | tseg_relocate((void **)&flashes[i].probe); |
| 348 | #endif |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 349 | /* we have a match, call probe */ |
| 350 | flash = flashes[i].probe(spi, idp); |
| 351 | if (flash) |
| 352 | break; |
| 353 | } |
| 354 | |
Vladimir Serbinenko | e23bd0e | 2014-01-18 17:45:32 +0100 | [diff] [blame] | 355 | if (!flash && spi->programmer_specific_probe) { |
| 356 | #if CONFIG_SMM_TSEG && defined(__SMM__) |
| 357 | /* Need to relocate this function */ |
| 358 | tseg_relocate((void **)&spi->programmer_specific_probe); |
| 359 | #endif |
| 360 | flash = spi->programmer_specific_probe (spi); |
| 361 | } |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 362 | if (!flash) { |
| 363 | printk(BIOS_WARNING, "SF: Unsupported manufacturer %02x\n", *idp); |
| 364 | goto err_manufacturer_probe; |
| 365 | } |
| 366 | |
Vladimir Serbinenko | e23bd0e | 2014-01-18 17:45:32 +0100 | [diff] [blame] | 367 | flash_detected: |
Duncan Laurie | 23b0053 | 2012-10-10 14:21:23 -0700 | [diff] [blame] | 368 | #if CONFIG_SMM_TSEG && defined(__SMM__) |
| 369 | /* Ensure flash handlers are valid for TSEG */ |
| 370 | tseg_relocate((void **)&flash->read); |
| 371 | tseg_relocate((void **)&flash->write); |
| 372 | tseg_relocate((void **)&flash->erase); |
| 373 | tseg_relocate((void **)&flash->name); |
| 374 | #endif |
| 375 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 376 | printk(BIOS_INFO, "SF: Detected %s with page size %x, total %x\n", |
| 377 | flash->name, flash->sector_size, flash->size); |
| 378 | |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 379 | return flash; |
| 380 | |
| 381 | err_manufacturer_probe: |
| 382 | err_read_id: |
Stefan Reinauer | 1c56d9b | 2012-05-10 11:27:32 -0700 | [diff] [blame] | 383 | return NULL; |
| 384 | } |