Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 1 | /* |
| 2 | * SPI flash probing |
| 3 | * |
| 4 | * Copyright (C) 2008 Atmel Corporation |
| 5 | * Copyright (C) 2010 Reinhard Meyer, EMK Elektronik |
| 6 | * Copyright (C) 2013 Jagannadha Sutradharudu Teki, Xilinx Inc. |
| 7 | * |
Jagannadha Sutradharudu Teki | d145270 | 2013-10-10 22:32:55 +0530 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <fdtdec.h> |
| 13 | #include <malloc.h> |
| 14 | #include <spi.h> |
| 15 | #include <spi_flash.h> |
Mike Frysinger | b375ad9 | 2013-12-03 16:43:27 -0700 | [diff] [blame] | 16 | #include <asm/io.h> |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 17 | |
Jagannadha Sutradharudu Teki | ac8242d | 2013-09-26 16:00:15 +0530 | [diff] [blame] | 18 | #include "sf_internal.h" |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 22 | /* Read commands array */ |
| 23 | static u8 spi_read_cmds_array[] = { |
| 24 | CMD_READ_ARRAY_SLOW, |
| 25 | CMD_READ_DUAL_OUTPUT_FAST, |
| 26 | CMD_READ_DUAL_IO_FAST, |
Jagannadha Sutradharudu Teki | e0ebabc | 2014-01-11 15:13:11 +0530 | [diff] [blame] | 27 | CMD_READ_QUAD_OUTPUT_FAST, |
Jagannadha Sutradharudu Teki | 4546230 | 2013-12-24 15:24:31 +0530 | [diff] [blame] | 28 | CMD_READ_QUAD_IO_FAST, |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 29 | }; |
| 30 | |
Jagannadha Sutradharudu Teki | 725c64e | 2013-12-26 13:54:57 +0530 | [diff] [blame] | 31 | static int spi_flash_set_qeb(struct spi_flash *flash, u8 idcode0) |
| 32 | { |
| 33 | switch (idcode0) { |
Jagannadha Sutradharudu Teki | 754c73c | 2013-12-26 14:13:36 +0530 | [diff] [blame^] | 34 | #ifdef CONFIG_SPI_FLASH_MACRONIX |
| 35 | case SPI_FLASH_CFI_MFR_MACRONIX: |
| 36 | return spi_flash_set_qeb_mxic(flash); |
| 37 | #endif |
Jagannadha Sutradharudu Teki | 725c64e | 2013-12-26 13:54:57 +0530 | [diff] [blame] | 38 | #if defined(CONFIG_SPI_FLASH_SPANSION) || defined(CONFIG_SPI_FLASH_WINBOND) |
| 39 | case SPI_FLASH_CFI_MFR_SPANSION: |
| 40 | case SPI_FLASH_CFI_MFR_WINBOND: |
| 41 | return spi_flash_set_qeb_winspan(flash); |
| 42 | #endif |
| 43 | #ifdef CONFIG_SPI_FLASH_STMICRO |
| 44 | case SPI_FLASH_CFI_MFR_STMICRO: |
| 45 | debug("SF: QEB is volatile for %02x flash\n", idcode0); |
| 46 | return 0; |
| 47 | #endif |
| 48 | default: |
| 49 | printf("SF: Need set QEB func for %02x flash\n", idcode0); |
| 50 | return -1; |
| 51 | } |
| 52 | } |
| 53 | |
Jagannadha Sutradharudu Teki | f3b2dd8 | 2013-10-07 19:34:56 +0530 | [diff] [blame] | 54 | static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi, |
| 55 | u8 *idcode) |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 56 | { |
| 57 | const struct spi_flash_params *params; |
| 58 | struct spi_flash *flash; |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 59 | u8 cmd; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 60 | u16 jedec = idcode[1] << 8 | idcode[2]; |
Jagannadha Sutradharudu Teki | 2531553 | 2013-09-28 16:49:37 +0530 | [diff] [blame] | 61 | u16 ext_jedec = idcode[3] << 8 | idcode[4]; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 62 | |
Jagannadha Sutradharudu Teki | 20e45bc | 2013-12-23 23:34:42 +0530 | [diff] [blame] | 63 | params = spi_flash_params_table; |
| 64 | for (; params->name != NULL; params++) { |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 65 | if ((params->jedec >> 16) == idcode[0]) { |
Jagannadha Sutradharudu Teki | 2531553 | 2013-09-28 16:49:37 +0530 | [diff] [blame] | 66 | if ((params->jedec & 0xFFFF) == jedec) { |
| 67 | if (params->ext_jedec == 0) |
| 68 | break; |
| 69 | else if (params->ext_jedec == ext_jedec) |
| 70 | break; |
| 71 | } |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
Jagannadha Sutradharudu Teki | 20e45bc | 2013-12-23 23:34:42 +0530 | [diff] [blame] | 75 | if (!params->name) { |
Jagannadha Sutradharudu Teki | 2531553 | 2013-09-28 16:49:37 +0530 | [diff] [blame] | 76 | printf("SF: Unsupported flash IDs: "); |
| 77 | printf("manuf %02x, jedec %04x, ext_jedec %04x\n", |
| 78 | idcode[0], jedec, ext_jedec); |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 79 | return NULL; |
| 80 | } |
| 81 | |
| 82 | flash = malloc(sizeof(*flash)); |
| 83 | if (!flash) { |
| 84 | debug("SF: Failed to allocate spi_flash\n"); |
| 85 | return NULL; |
| 86 | } |
| 87 | memset(flash, '\0', sizeof(*flash)); |
| 88 | |
Jagannadha Sutradharudu Teki | 84fb863 | 2013-10-10 22:14:09 +0530 | [diff] [blame] | 89 | /* Assign spi data */ |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 90 | flash->spi = spi; |
| 91 | flash->name = params->name; |
Jagannadha Sutradharudu Teki | f3b2dd8 | 2013-10-07 19:34:56 +0530 | [diff] [blame] | 92 | flash->memory_map = spi->memory_map; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 93 | |
| 94 | /* Assign spi_flash ops */ |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 95 | flash->write = spi_flash_cmd_write_ops; |
Jagannadha Sutradharudu Teki | 0803242 | 2013-10-02 19:34:53 +0530 | [diff] [blame] | 96 | #ifdef CONFIG_SPI_FLASH_SST |
| 97 | if (params->flags & SST_WP) |
| 98 | flash->write = sst_write_wp; |
| 99 | #endif |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 100 | flash->erase = spi_flash_cmd_erase_ops; |
| 101 | flash->read = spi_flash_cmd_read_ops; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 102 | |
| 103 | /* Compute the flash size */ |
Jagannadha Sutradharudu Teki | ec53829 | 2013-08-28 12:17:56 +0530 | [diff] [blame] | 104 | flash->page_size = (ext_jedec == 0x4d00) ? 512 : 256; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 105 | flash->sector_size = params->sector_size; |
| 106 | flash->size = flash->sector_size * params->nr_sectors; |
| 107 | |
Jagannadha Sutradharudu Teki | bc0f879 | 2013-10-02 19:36:58 +0530 | [diff] [blame] | 108 | /* Compute erase sector and command */ |
| 109 | if (params->flags & SECT_4K) { |
| 110 | flash->erase_cmd = CMD_ERASE_4K; |
| 111 | flash->erase_size = 4096; |
| 112 | } else if (params->flags & SECT_32K) { |
| 113 | flash->erase_cmd = CMD_ERASE_32K; |
| 114 | flash->erase_size = 32768; |
| 115 | } else { |
| 116 | flash->erase_cmd = CMD_ERASE_64K; |
| 117 | flash->erase_size = flash->sector_size; |
| 118 | } |
| 119 | |
Jagannadha Sutradharudu Teki | 02eee9a | 2014-01-11 15:10:28 +0530 | [diff] [blame] | 120 | /* Look for the fastest read cmd */ |
| 121 | cmd = fls(params->e_rd_cmd & flash->spi->op_mode_rx); |
| 122 | if (cmd) { |
| 123 | cmd = spi_read_cmds_array[cmd - 1]; |
| 124 | flash->read_cmd = cmd; |
| 125 | } else { |
| 126 | /* Go for for default supported read cmd */ |
| 127 | flash->read_cmd = CMD_READ_ARRAY_FAST; |
| 128 | } |
| 129 | |
Jagannadha Sutradharudu Teki | e0ebabc | 2014-01-11 15:13:11 +0530 | [diff] [blame] | 130 | /* Not require to look for fastest only two write cmds yet */ |
| 131 | if (params->flags & WR_QPP && flash->spi->op_mode_tx & SPI_OPM_TX_QPP) |
| 132 | flash->write_cmd = CMD_QUAD_PAGE_PROGRAM; |
| 133 | else |
| 134 | /* Go for default supported write cmd */ |
| 135 | flash->write_cmd = CMD_PAGE_PROGRAM; |
| 136 | |
Jagannadha Sutradharudu Teki | 725c64e | 2013-12-26 13:54:57 +0530 | [diff] [blame] | 137 | /* Set the quad enable bit - only for quad commands */ |
| 138 | if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) || |
Jagannadha Sutradharudu Teki | 4546230 | 2013-12-24 15:24:31 +0530 | [diff] [blame] | 139 | (flash->read_cmd == CMD_READ_QUAD_IO_FAST) || |
Jagannadha Sutradharudu Teki | 725c64e | 2013-12-26 13:54:57 +0530 | [diff] [blame] | 140 | (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) { |
| 141 | if (spi_flash_set_qeb(flash, idcode[0])) { |
| 142 | debug("SF: Fail to set QEB for %02x\n", idcode[0]); |
| 143 | return NULL; |
| 144 | } |
| 145 | } |
| 146 | |
Jagannadha Sutradharudu Teki | ca79986 | 2014-01-11 16:50:45 +0530 | [diff] [blame] | 147 | /* Read dummy_byte: dummy byte is determined based on the |
| 148 | * dummy cycles of a particular command. |
| 149 | * Fast commands - dummy_byte = dummy_cycles/8 |
| 150 | * I/O commands- dummy_byte = (dummy_cycles * no.of lines)/8 |
| 151 | * For I/O commands except cmd[0] everything goes on no.of lines |
| 152 | * based on particular command but incase of fast commands except |
| 153 | * data all go on single line irrespective of command. |
| 154 | */ |
| 155 | switch (flash->read_cmd) { |
| 156 | case CMD_READ_QUAD_IO_FAST: |
| 157 | flash->dummy_byte = 2; |
| 158 | break; |
| 159 | case CMD_READ_ARRAY_SLOW: |
| 160 | flash->dummy_byte = 0; |
| 161 | break; |
| 162 | default: |
| 163 | flash->dummy_byte = 1; |
| 164 | } |
| 165 | |
Jagannadha Sutradharudu Teki | f41fcca | 2013-10-02 19:37:43 +0530 | [diff] [blame] | 166 | /* Poll cmd seclection */ |
| 167 | flash->poll_cmd = CMD_READ_STATUS; |
| 168 | #ifdef CONFIG_SPI_FLASH_STMICRO |
| 169 | if (params->flags & E_FSR) |
| 170 | flash->poll_cmd = CMD_FLAG_STATUS; |
| 171 | #endif |
| 172 | |
Jagannadha Sutradharudu Teki | f3b2dd8 | 2013-10-07 19:34:56 +0530 | [diff] [blame] | 173 | /* Configure the BAR - discover bank cmds and read current bank */ |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 174 | #ifdef CONFIG_SPI_FLASH_BAR |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 175 | u8 curr_bank = 0; |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 176 | if (flash->size > SPI_FLASH_16MB_BOUN) { |
Jagannadha Sutradharudu Teki | 748bd4d | 2013-09-26 14:24:58 +0530 | [diff] [blame] | 177 | flash->bank_read_cmd = (idcode[0] == 0x01) ? |
| 178 | CMD_BANKADDR_BRRD : CMD_EXTNADDR_RDEAR; |
| 179 | flash->bank_write_cmd = (idcode[0] == 0x01) ? |
| 180 | CMD_BANKADDR_BRWR : CMD_EXTNADDR_WREAR; |
| 181 | |
| 182 | if (spi_flash_read_common(flash, &flash->bank_read_cmd, 1, |
| 183 | &curr_bank, 1)) { |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 184 | debug("SF: fail to read bank addr register\n"); |
Jagannadha Sutradharudu Teki | 748bd4d | 2013-09-26 14:24:58 +0530 | [diff] [blame] | 185 | return NULL; |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 186 | } |
| 187 | flash->bank_curr = curr_bank; |
| 188 | } else { |
| 189 | flash->bank_curr = curr_bank; |
| 190 | } |
Jagannadha Sutradharudu Teki | 748bd4d | 2013-09-26 14:24:58 +0530 | [diff] [blame] | 191 | #endif |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 192 | |
Jagannadha Sutradharudu Teki | 748bd4d | 2013-09-26 14:24:58 +0530 | [diff] [blame] | 193 | /* Flash powers up read-only, so clear BP# bits */ |
| 194 | #if defined(CONFIG_SPI_FLASH_ATMEL) || \ |
| 195 | defined(CONFIG_SPI_FLASH_MACRONIX) || \ |
| 196 | defined(CONFIG_SPI_FLASH_SST) |
| 197 | spi_flash_cmd_write_status(flash, 0); |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 198 | #endif |
| 199 | |
Jagannadha Sutradharudu Teki | 748bd4d | 2013-09-26 14:24:58 +0530 | [diff] [blame] | 200 | return flash; |
| 201 | } |
| 202 | |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 203 | #ifdef CONFIG_OF_CONTROL |
| 204 | int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash) |
| 205 | { |
| 206 | fdt_addr_t addr; |
| 207 | fdt_size_t size; |
| 208 | int node; |
| 209 | |
| 210 | /* If there is no node, do nothing */ |
| 211 | node = fdtdec_next_compatible(blob, 0, COMPAT_GENERIC_SPI_FLASH); |
| 212 | if (node < 0) |
| 213 | return 0; |
| 214 | |
| 215 | addr = fdtdec_get_addr_size(blob, node, "memory-map", &size); |
| 216 | if (addr == FDT_ADDR_T_NONE) { |
| 217 | debug("%s: Cannot decode address\n", __func__); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | if (flash->size != size) { |
| 222 | debug("%s: Memory map must cover entire device\n", __func__); |
| 223 | return -1; |
| 224 | } |
Mike Frysinger | b375ad9 | 2013-12-03 16:43:27 -0700 | [diff] [blame] | 225 | flash->memory_map = map_sysmem(addr, size); |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | #endif /* CONFIG_OF_CONTROL */ |
| 230 | |
Simon Glass | 49e9d2c | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 231 | static struct spi_flash *spi_flash_probe_slave(struct spi_slave *spi) |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 232 | { |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 233 | struct spi_flash *flash = NULL; |
Jagannadha Sutradharudu Teki | 748bd4d | 2013-09-26 14:24:58 +0530 | [diff] [blame] | 234 | u8 idcode[5]; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 235 | int ret; |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 236 | |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 237 | /* Setup spi_slave */ |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 238 | if (!spi) { |
| 239 | printf("SF: Failed to set up slave\n"); |
| 240 | return NULL; |
| 241 | } |
| 242 | |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 243 | /* Claim spi bus */ |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 244 | ret = spi_claim_bus(spi); |
| 245 | if (ret) { |
| 246 | debug("SF: Failed to claim SPI bus: %d\n", ret); |
| 247 | goto err_claim_bus; |
| 248 | } |
| 249 | |
| 250 | /* Read the ID codes */ |
| 251 | ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode)); |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 252 | if (ret) { |
| 253 | printf("SF: Failed to get idcodes\n"); |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 254 | goto err_read_id; |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 255 | } |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 256 | |
| 257 | #ifdef DEBUG |
| 258 | printf("SF: Got idcodes\n"); |
| 259 | print_buffer(0, idcode, 1, sizeof(idcode), 0); |
| 260 | #endif |
| 261 | |
Jagannadha Sutradharudu Teki | 25dc86a | 2013-10-02 19:38:49 +0530 | [diff] [blame] | 262 | /* Validate params from spi_flash_params table */ |
| 263 | flash = spi_flash_validate_params(spi, idcode); |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 264 | if (!flash) |
| 265 | goto err_read_id; |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 266 | |
| 267 | #ifdef CONFIG_OF_CONTROL |
| 268 | if (spi_flash_decode_fdt(gd->fdt_blob, flash)) { |
| 269 | debug("SF: FDT decode error\n"); |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 270 | goto err_read_id; |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 271 | } |
| 272 | #endif |
| 273 | #ifndef CONFIG_SPL_BUILD |
| 274 | printf("SF: Detected %s with page size ", flash->name); |
Jagannadha Sutradharudu Teki | 918d6ac | 2013-09-15 23:06:12 +0530 | [diff] [blame] | 275 | print_size(flash->page_size, ", erase size "); |
| 276 | print_size(flash->erase_size, ", total "); |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 277 | print_size(flash->size, ""); |
| 278 | if (flash->memory_map) |
| 279 | printf(", mapped at %p", flash->memory_map); |
| 280 | puts("\n"); |
| 281 | #endif |
| 282 | #ifndef CONFIG_SPI_FLASH_BAR |
| 283 | if (flash->size > SPI_FLASH_16MB_BOUN) { |
| 284 | puts("SF: Warning - Only lower 16MiB accessible,"); |
| 285 | puts(" Full access #define CONFIG_SPI_FLASH_BAR\n"); |
| 286 | } |
| 287 | #endif |
| 288 | |
Jagannadha Sutradharudu Teki | bb30220 | 2013-09-24 16:01:23 +0530 | [diff] [blame] | 289 | /* Release spi bus */ |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 290 | spi_release_bus(spi); |
| 291 | |
| 292 | return flash; |
| 293 | |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 294 | err_read_id: |
| 295 | spi_release_bus(spi); |
| 296 | err_claim_bus: |
| 297 | spi_free_slave(spi); |
| 298 | return NULL; |
| 299 | } |
| 300 | |
Simon Glass | 49e9d2c | 2013-12-03 16:43:24 -0700 | [diff] [blame] | 301 | struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, |
| 302 | unsigned int max_hz, unsigned int spi_mode) |
| 303 | { |
| 304 | struct spi_slave *spi; |
| 305 | |
| 306 | spi = spi_setup_slave(bus, cs, max_hz, spi_mode); |
| 307 | return spi_flash_probe_slave(spi); |
| 308 | } |
| 309 | |
| 310 | #ifdef CONFIG_OF_SPI_FLASH |
| 311 | struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node, |
| 312 | int spi_node) |
| 313 | { |
| 314 | struct spi_slave *spi; |
| 315 | |
| 316 | spi = spi_setup_slave_fdt(blob, slave_node, spi_node); |
| 317 | return spi_flash_probe_slave(spi); |
| 318 | } |
| 319 | #endif |
| 320 | |
Jagannadha Sutradharudu Teki | e9a8b82 | 2013-08-29 19:01:56 +0530 | [diff] [blame] | 321 | void spi_flash_free(struct spi_flash *flash) |
| 322 | { |
| 323 | spi_free_slave(flash->spi); |
| 324 | free(flash); |
| 325 | } |