Lines Matching +full:spi +full:- +full:flash

2  * SPI Flash Core
9 * SPDX-License-Identifier: GPL-2.0+
16 #include <spi.h>
34 static int read_sr(struct spi_flash *flash, u8 *rs) in read_sr() argument
40 ret = spi_flash_read_common(flash, &cmd, 1, rs, 1); in read_sr()
49 static int read_fsr(struct spi_flash *flash, u8 *fsr) in read_fsr() argument
54 ret = spi_flash_read_common(flash, &cmd, 1, fsr, 1); in read_fsr()
63 static int write_sr(struct spi_flash *flash, u8 ws) in write_sr() argument
69 ret = spi_flash_write_common(flash, &cmd, 1, &ws, 1); in write_sr()
79 static int read_cr(struct spi_flash *flash, u8 *rc) in read_cr() argument
85 ret = spi_flash_read_common(flash, &cmd, 1, rc, 1); in read_cr()
94 static int write_cr(struct spi_flash *flash, u8 wc) in write_cr() argument
100 ret = read_sr(flash, &data[0]); in write_cr()
106 ret = spi_flash_write_common(flash, &cmd, 1, &data, 2); in write_cr()
116 int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash) in spi_flash_cmd_get_sw_write_prot() argument
121 ret = read_sr(flash, &status); in spi_flash_cmd_get_sw_write_prot()
131 * spi flash memory > 16 MiB by using Bank Address Register's BA24 bit.
139 static int clean_bar(struct spi_flash *flash) in clean_bar() argument
143 if (flash->bank_curr == 0) in clean_bar()
145 cmd = flash->bank_write_cmd; in clean_bar()
146 flash->bank_curr = 0; in clean_bar()
148 return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1); in clean_bar()
151 static int write_bar(struct spi_flash *flash, u32 offset) in write_bar() argument
156 bank_sel = offset / (SPI_FLASH_16MB_BOUN << flash->shift); in write_bar()
157 if (bank_sel == flash->bank_curr) in write_bar()
160 cmd = flash->bank_write_cmd; in write_bar()
161 ret = spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1); in write_bar()
168 flash->bank_curr = bank_sel; in write_bar()
169 return flash->bank_curr; in write_bar()
172 static int read_bar(struct spi_flash *flash, const struct spi_flash_info *info) in read_bar() argument
177 if (flash->size <= SPI_FLASH_16MB_BOUN) in read_bar()
182 flash->bank_read_cmd = CMD_BANKADDR_BRRD; in read_bar()
183 flash->bank_write_cmd = CMD_BANKADDR_BRWR; in read_bar()
186 flash->bank_read_cmd = CMD_EXTNADDR_RDEAR; in read_bar()
187 flash->bank_write_cmd = CMD_EXTNADDR_WREAR; in read_bar()
190 ret = spi_flash_read_common(flash, &flash->bank_read_cmd, 1, in read_bar()
198 flash->bank_curr = curr_bank; in read_bar()
204 static void spi_flash_dual(struct spi_flash *flash, u32 *addr) in spi_flash_dual() argument
206 switch (flash->dual_flash) { in spi_flash_dual()
208 if (*addr >= (flash->size >> 1)) { in spi_flash_dual()
209 *addr -= flash->size >> 1; in spi_flash_dual()
210 flash->flags |= SNOR_F_USE_UPAGE; in spi_flash_dual()
212 flash->flags &= ~SNOR_F_USE_UPAGE; in spi_flash_dual()
216 *addr >>= flash->shift; in spi_flash_dual()
219 debug("SF: Unsupported dual_flash=%d\n", flash->dual_flash); in spi_flash_dual()
225 static int spi_flash_sr_ready(struct spi_flash *flash) in spi_flash_sr_ready() argument
230 ret = read_sr(flash, &sr); in spi_flash_sr_ready()
237 static int spi_flash_fsr_ready(struct spi_flash *flash) in spi_flash_fsr_ready() argument
242 ret = read_fsr(flash, &fsr); in spi_flash_fsr_ready()
249 static int spi_flash_ready(struct spi_flash *flash) in spi_flash_ready() argument
253 sr = spi_flash_sr_ready(flash); in spi_flash_ready()
258 if (flash->flags & SNOR_F_USE_FSR) { in spi_flash_ready()
259 fsr = spi_flash_fsr_ready(flash); in spi_flash_ready()
267 static int spi_flash_wait_till_ready(struct spi_flash *flash, in spi_flash_wait_till_ready() argument
276 ret = spi_flash_ready(flash); in spi_flash_wait_till_ready()
285 return -ETIMEDOUT; in spi_flash_wait_till_ready()
288 int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd, in spi_flash_write_common() argument
291 struct spi_slave *spi = flash->spi; in spi_flash_write_common() local
298 ret = spi_claim_bus(spi); in spi_flash_write_common()
300 debug("SF: unable to claim SPI bus\n"); in spi_flash_write_common()
304 ret = spi_flash_cmd_write_enable(flash); in spi_flash_write_common()
310 ret = spi_flash_cmd_write(spi, cmd, cmd_len, buf, buf_len); in spi_flash_write_common()
316 ret = spi_flash_wait_till_ready(flash, timeout); in spi_flash_write_common()
324 spi_release_bus(spi); in spi_flash_write_common()
329 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len) in spi_flash_cmd_erase_ops() argument
333 int ret = -1; in spi_flash_cmd_erase_ops()
335 erase_size = flash->erase_size; in spi_flash_cmd_erase_ops()
338 return -1; in spi_flash_cmd_erase_ops()
341 if (flash->flash_is_locked) { in spi_flash_cmd_erase_ops()
342 if (flash->flash_is_locked(flash, offset, len) > 0) { in spi_flash_cmd_erase_ops()
345 return -EINVAL; in spi_flash_cmd_erase_ops()
349 cmd[0] = flash->erase_cmd; in spi_flash_cmd_erase_ops()
354 if (flash->dual_flash > SF_SINGLE_FLASH) in spi_flash_cmd_erase_ops()
355 spi_flash_dual(flash, &erase_addr); in spi_flash_cmd_erase_ops()
358 ret = write_bar(flash, erase_addr); in spi_flash_cmd_erase_ops()
367 ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0); in spi_flash_cmd_erase_ops()
374 len -= erase_size; in spi_flash_cmd_erase_ops()
378 ret = clean_bar(flash); in spi_flash_cmd_erase_ops()
384 int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset, in spi_flash_cmd_write_ops() argument
387 struct spi_slave *spi = flash->spi; in spi_flash_cmd_write_ops() local
392 int ret = -1; in spi_flash_cmd_write_ops()
394 page_size = flash->page_size; in spi_flash_cmd_write_ops()
396 if (flash->flash_is_locked) { in spi_flash_cmd_write_ops()
397 if (flash->flash_is_locked(flash, offset, len) > 0) { in spi_flash_cmd_write_ops()
400 return -EINVAL; in spi_flash_cmd_write_ops()
404 cmd[0] = flash->write_cmd; in spi_flash_cmd_write_ops()
409 if (flash->dual_flash > SF_SINGLE_FLASH) in spi_flash_cmd_write_ops()
410 spi_flash_dual(flash, &write_addr); in spi_flash_cmd_write_ops()
413 ret = write_bar(flash, write_addr); in spi_flash_cmd_write_ops()
418 chunk_len = min(len - actual, (size_t)(page_size - byte_addr)); in spi_flash_cmd_write_ops()
420 if (spi->max_write_size) in spi_flash_cmd_write_ops()
422 spi->max_write_size - sizeof(cmd)); in spi_flash_cmd_write_ops()
429 ret = spi_flash_write_common(flash, cmd, sizeof(cmd), in spi_flash_cmd_write_ops()
440 ret = clean_bar(flash); in spi_flash_cmd_write_ops()
446 int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd, in spi_flash_read_common() argument
449 struct spi_slave *spi = flash->spi; in spi_flash_read_common() local
452 ret = spi_claim_bus(spi); in spi_flash_read_common()
454 debug("SF: unable to claim SPI bus\n"); in spi_flash_read_common()
458 ret = spi_flash_cmd_read(spi, cmd, cmd_len, data, data_len); in spi_flash_read_common()
464 spi_release_bus(spi); in spi_flash_read_common()
482 int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset, in spi_flash_cmd_read_ops() argument
485 struct spi_slave *spi = flash->spi; in spi_flash_cmd_read_ops() local
491 /* Handle memory-mapped SPI */ in spi_flash_cmd_read_ops()
492 if (flash->memory_map) { in spi_flash_cmd_read_ops()
493 ret = spi_claim_bus(spi); in spi_flash_cmd_read_ops()
495 debug("SF: unable to claim SPI bus\n"); in spi_flash_cmd_read_ops()
498 spi_xfer(spi, 0, NULL, NULL, SPI_XFER_MMAP); in spi_flash_cmd_read_ops()
499 spi_flash_copy_mmap(data, flash->memory_map + offset, len); in spi_flash_cmd_read_ops()
500 spi_xfer(spi, 0, NULL, NULL, SPI_XFER_MMAP_END); in spi_flash_cmd_read_ops()
501 spi_release_bus(spi); in spi_flash_cmd_read_ops()
505 cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte; in spi_flash_cmd_read_ops()
508 cmd[0] = flash->read_cmd; in spi_flash_cmd_read_ops()
513 if (flash->dual_flash > SF_SINGLE_FLASH) in spi_flash_cmd_read_ops()
514 spi_flash_dual(flash, &read_addr); in spi_flash_cmd_read_ops()
517 ret = write_bar(flash, read_addr); in spi_flash_cmd_read_ops()
520 bank_sel = flash->bank_curr; in spi_flash_cmd_read_ops()
522 remain_len = ((SPI_FLASH_16MB_BOUN << flash->shift) * in spi_flash_cmd_read_ops()
523 (bank_sel + 1)) - offset; in spi_flash_cmd_read_ops()
529 if (spi->max_read_size) in spi_flash_cmd_read_ops()
530 read_len = min(read_len, spi->max_read_size); in spi_flash_cmd_read_ops()
534 ret = spi_flash_read_common(flash, cmd, cmdsz, data, read_len); in spi_flash_cmd_read_ops()
541 len -= read_len; in spi_flash_cmd_read_ops()
546 ret = clean_bar(flash); in spi_flash_cmd_read_ops()
557 cmd[bpr_size - (bit / 8) - 1] |= BIT(bit % 8); in sst26_process_bpr()
560 cmd[bpr_size - (bit / 8) - 1] &= ~BIT(bit % 8); in sst26_process_bpr()
563 return !!(cmd[bpr_size - (bit / 8) - 1] & BIT(bit % 8)); in sst26_process_bpr()
571 * 4x - 8 KByte blocks - read & write protection bits - upper addresses
572 * 1x - 32 KByte blocks - write protection bits
573 * rest - 64 KByte blocks - write protection bits
574 * 1x - 32 KByte blocks - write protection bits
575 * 4x - 8 KByte blocks - read & write protection bits - lower addresses
582 * Lock, unlock or check lock status of the flash region of the flash (depending
585 static int sst26_lock_ctl(struct spi_flash *flash, u32 ofs, size_t len, enum lock_ctl ctl) in sst26_lock_ctl() argument
593 if ((ofs & (SZ_64K - 1)) || (len & (SZ_64K - 1))) in sst26_lock_ctl()
594 return -EINVAL; in sst26_lock_ctl()
596 if (ofs + len > flash->size) in sst26_lock_ctl()
597 return -EINVAL; in sst26_lock_ctl()
600 if (flash->size != SZ_2M && in sst26_lock_ctl()
601 flash->size != SZ_4M && in sst26_lock_ctl()
602 flash->size != SZ_8M) in sst26_lock_ctl()
603 return -EINVAL; in sst26_lock_ctl()
605 bpr_size = 2 + (flash->size / SZ_64K / 8); in sst26_lock_ctl()
608 ret = spi_flash_read_common(flash, &cmd, 1, bpr_buff, bpr_size); in sst26_lock_ctl()
610 printf("SF: fail to read block-protection register\n"); in sst26_lock_ctl()
614 rptr_64k = min_t(u32, ofs + len , flash->size - SST26_BOUND_REG_SIZE); in sst26_lock_ctl()
617 upper_64k = ((ofs + len) > (flash->size - SST26_BOUND_REG_SIZE)); in sst26_lock_ctl()
620 /* Lower bits in block-protection register are about 64k region */ in sst26_lock_ctl()
621 bpr_ptr = lptr_64k / SZ_64K - 1; in sst26_lock_ctl()
633 bpr_ptr = (flash->size - 2 * SST26_BOUND_REG_SIZE) / SZ_64K; in sst26_lock_ctl()
674 ret = spi_flash_write_common(flash, &cmd, 1, bpr_buff, bpr_size); in sst26_lock_ctl()
676 printf("SF: fail to write block-protection register\n"); in sst26_lock_ctl()
683 static int sst26_unlock(struct spi_flash *flash, u32 ofs, size_t len) in sst26_unlock() argument
685 return sst26_lock_ctl(flash, ofs, len, SST26_CTL_UNLOCK); in sst26_unlock()
688 static int sst26_lock(struct spi_flash *flash, u32 ofs, size_t len) in sst26_lock() argument
690 return sst26_lock_ctl(flash, ofs, len, SST26_CTL_LOCK); in sst26_lock()
697 static int sst26_is_locked(struct spi_flash *flash, u32 ofs, size_t len) in sst26_is_locked() argument
700 * is_locked function is used for check before reading or erasing flash in sst26_is_locked()
705 ofs -= ofs & (SZ_64K - 1); in sst26_is_locked()
706 len = len & (SZ_64K - 1) ? (len & ~(SZ_64K - 1)) + SZ_64K : len; in sst26_is_locked()
708 return sst26_lock_ctl(flash, ofs, len, SST26_CTL_CHECK); in sst26_is_locked()
711 static int sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf) in sst_byte_write() argument
713 struct spi_slave *spi = flash->spi; in sst_byte_write() local
723 spi_w8r8(spi, CMD_READ_STATUS), buf, cmd[0], offset); in sst_byte_write()
725 ret = spi_flash_cmd_write_enable(flash); in sst_byte_write()
729 ret = spi_flash_cmd_write(spi, cmd, sizeof(cmd), buf, 1); in sst_byte_write()
733 return spi_flash_wait_till_ready(flash, SPI_FLASH_PROG_TIMEOUT); in sst_byte_write()
736 int sst_write_wp(struct spi_flash *flash, u32 offset, size_t len, in sst_write_wp() argument
739 struct spi_slave *spi = flash->spi; in sst_write_wp() local
744 ret = spi_claim_bus(spi); in sst_write_wp()
746 debug("SF: Unable to claim SPI bus\n"); in sst_write_wp()
753 ret = sst_byte_write(flash, offset, buf); in sst_write_wp()
759 ret = spi_flash_cmd_write_enable(flash); in sst_write_wp()
769 for (; actual < len - 1; actual += 2) { in sst_write_wp()
771 spi_w8r8(spi, CMD_READ_STATUS), buf + actual, in sst_write_wp()
774 ret = spi_flash_cmd_write(spi, cmd, cmd_len, in sst_write_wp()
781 ret = spi_flash_wait_till_ready(flash, SPI_FLASH_PROG_TIMEOUT); in sst_write_wp()
790 ret = spi_flash_cmd_write_disable(flash); in sst_write_wp()
794 ret = sst_byte_write(flash, offset, buf + actual); in sst_write_wp()
798 ret ? "failure" : "success", len, offset - actual); in sst_write_wp()
800 spi_release_bus(spi); in sst_write_wp()
804 int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len, in sst_write_bp() argument
807 struct spi_slave *spi = flash->spi; in sst_write_bp() local
811 ret = spi_claim_bus(spi); in sst_write_bp()
813 debug("SF: Unable to claim SPI bus\n"); in sst_write_bp()
818 ret = sst_byte_write(flash, offset, buf + actual); in sst_write_bp()
827 ret = spi_flash_cmd_write_disable(flash); in sst_write_bp()
830 ret ? "failure" : "success", len, offset - actual); in sst_write_bp()
832 spi_release_bus(spi); in sst_write_bp()
838 static void stm_get_locked_range(struct spi_flash *flash, u8 sr, loff_t *ofs, in stm_get_locked_range() argument
842 int shift = ffs(mask) - 1; in stm_get_locked_range()
851 *len = flash->size >> pow; in stm_get_locked_range()
852 *ofs = flash->size - *len; in stm_get_locked_range()
859 static int stm_is_locked_sr(struct spi_flash *flash, loff_t ofs, u64 len, in stm_is_locked_sr() argument
865 stm_get_locked_range(flash, sr, &lock_offs, &lock_len); in stm_is_locked_sr()
871 * Check if a region of the flash is (completely) locked. See stm_lock() for
877 int stm_is_locked(struct spi_flash *flash, u32 ofs, size_t len) in stm_is_locked() argument
882 status = read_sr(flash, &sr); in stm_is_locked()
886 return stm_is_locked_sr(flash, ofs, len, sr); in stm_is_locked()
890 * Lock a region of the flash. Compatible with ST Micro and similar flash.
893 * - TB: top/bottom protect - only handle TB=0 (top protect)
894 * - SEC: sector/block protect - only handle SEC=0 (block protect)
895 * - CMP: complement protect - only support CMP=0 (range is not complemented)
897 * Sample table portion for 8MB flash (Winbond w25q64fw):
900 * --------------------------------------------------------------------------
912 int stm_lock(struct spi_flash *flash, u32 ofs, size_t len) in stm_lock() argument
916 u8 shift = ffs(mask) - 1, pow, val; in stm_lock()
919 ret = read_sr(flash, &status_old); in stm_lock()
923 /* SPI NOR always locks to the end */ in stm_lock()
924 if (ofs + len != flash->size) { in stm_lock()
926 if (!stm_is_locked_sr(flash, ofs + len, flash->size - ofs - len, in stm_lock()
928 return -EINVAL; in stm_lock()
929 len = flash->size - ofs; in stm_lock()
937 * so (assuming power-of-2 size) we do: in stm_lock()
939 * pow = ceil(log2(size / len)) = log2(size) - floor(log2(len)) in stm_lock()
941 pow = ilog2(flash->size) - ilog2(len); in stm_lock()
942 val = mask - (pow << shift); in stm_lock()
944 return -EINVAL; in stm_lock()
948 return -EINVAL; in stm_lock()
954 return -EINVAL; in stm_lock()
956 write_sr(flash, status_new); in stm_lock()
962 * Unlock a region of the flash. See stm_lock() for more info
966 int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len) in stm_unlock() argument
970 u8 shift = ffs(mask) - 1, pow, val; in stm_unlock()
973 ret = read_sr(flash, &status_old); in stm_unlock()
978 if (stm_is_locked_sr(flash, ofs - flash->erase_size, flash->erase_size, in stm_unlock()
980 return -EINVAL; in stm_unlock()
986 * so (assuming power-of-2 size) we do: in stm_unlock()
988 * pow = floor(log2(size / len)) = log2(size) - ceil(log2(len)) in stm_unlock()
990 pow = ilog2(flash->size) - order_base_2(flash->size - (ofs + len)); in stm_unlock()
991 if (ofs + len == flash->size) { in stm_unlock()
994 val = mask - (pow << shift); in stm_unlock()
995 /* Some power-of-two sizes are not supported */ in stm_unlock()
997 return -EINVAL; in stm_unlock()
1004 return -EINVAL; in stm_unlock()
1006 write_sr(flash, status_new); in stm_unlock()
1014 static int macronix_quad_enable(struct spi_flash *flash) in macronix_quad_enable() argument
1019 ret = read_sr(flash, &qeb_status); in macronix_quad_enable()
1026 ret = write_sr(flash, qeb_status | STATUS_QEB_MXIC); in macronix_quad_enable()
1031 ret = read_sr(flash, &qeb_status); in macronix_quad_enable()
1034 return -EINVAL; in macronix_quad_enable()
1042 static int spansion_quad_enable(struct spi_flash *flash) in spansion_quad_enable() argument
1047 ret = read_cr(flash, &qeb_status); in spansion_quad_enable()
1054 ret = write_cr(flash, qeb_status | STATUS_QEB_WINSPAN); in spansion_quad_enable()
1059 ret = read_cr(flash, &qeb_status); in spansion_quad_enable()
1062 return -EINVAL; in spansion_quad_enable()
1069 static const struct spi_flash_info *spi_flash_read_id(struct spi_flash *flash) in spi_flash_read_id() argument
1075 tmp = spi_flash_cmd(flash->spi, CMD_READ_ID, id, SPI_FLASH_MAX_ID_LEN); in spi_flash_read_id()
1082 for (; info->name != NULL; info++) { in spi_flash_read_id()
1083 if (info->id_len) { in spi_flash_read_id()
1084 if (!memcmp(info->id, id, info->id_len)) in spi_flash_read_id()
1091 return ERR_PTR(-ENODEV); in spi_flash_read_id()
1094 static int set_quad_mode(struct spi_flash *flash, in set_quad_mode() argument
1101 return macronix_quad_enable(flash); in set_quad_mode()
1106 return spansion_quad_enable(flash); in set_quad_mode()
1111 debug("SF: QEB is volatile for %02x flash\n", JEDEC_MFR(info)); in set_quad_mode()
1115 printf("SF: Need set QEB func for %02x flash\n", in set_quad_mode()
1117 return -1; in set_quad_mode()
1122 int spi_flash_decode_fdt(struct spi_flash *flash) in spi_flash_decode_fdt() argument
1128 addr = dev_read_addr_size(flash->dev, "memory-map", &size); in spi_flash_decode_fdt()
1134 if (flash->size > size) { in spi_flash_decode_fdt()
1136 return -1; in spi_flash_decode_fdt()
1138 flash->memory_map = map_sysmem(addr, size); in spi_flash_decode_fdt()
1145 int spi_flash_scan(struct spi_flash *flash) in spi_flash_scan() argument
1147 struct spi_slave *spi = flash->spi; in spi_flash_scan() local
1151 info = spi_flash_read_id(flash); in spi_flash_scan()
1153 return -ENOENT; in spi_flash_scan()
1156 * Flash powers up read-only, so clear BP# bits. in spi_flash_scan()
1158 * Note on some flash (like Macronix), QE (quad enable) bit is in the in spi_flash_scan()
1161 * (like Intel ICH SPI controller working under descriptor mode). in spi_flash_scan()
1169 read_sr(flash, &sr); in spi_flash_scan()
1172 write_sr(flash, sr); in spi_flash_scan()
1175 flash->name = info->name; in spi_flash_scan()
1176 flash->memory_map = spi->memory_map; in spi_flash_scan()
1178 if (info->flags & SST_WR) in spi_flash_scan()
1179 flash->flags |= SNOR_F_SST_WR; in spi_flash_scan()
1182 flash->write = spi_flash_cmd_write_ops; in spi_flash_scan()
1184 if (flash->flags & SNOR_F_SST_WR) { in spi_flash_scan()
1185 if (spi->mode & SPI_TX_BYTE) in spi_flash_scan()
1186 flash->write = sst_write_bp; in spi_flash_scan()
1188 flash->write = sst_write_wp; in spi_flash_scan()
1191 flash->erase = spi_flash_cmd_erase_ops; in spi_flash_scan()
1192 flash->read = spi_flash_cmd_read_ops; in spi_flash_scan()
1200 flash->flash_lock = stm_lock; in spi_flash_scan()
1201 flash->flash_unlock = stm_unlock; in spi_flash_scan()
1202 flash->flash_is_locked = stm_is_locked; in spi_flash_scan()
1208 if (JEDEC_MFR(info) == SPI_FLASH_CFI_MFR_SST && info->id[1] == 0x26) { in spi_flash_scan()
1209 flash->flash_lock = sst26_lock; in spi_flash_scan()
1210 flash->flash_unlock = sst26_unlock; in spi_flash_scan()
1211 flash->flash_is_locked = sst26_is_locked; in spi_flash_scan()
1215 /* Compute the flash size */ in spi_flash_scan()
1216 flash->shift = (flash->dual_flash & SF_DUAL_PARALLEL_FLASH) ? 1 : 0; in spi_flash_scan()
1217 flash->page_size = info->page_size; in spi_flash_scan()
1228 flash->page_size = 512; in spi_flash_scan()
1230 flash->page_size <<= flash->shift; in spi_flash_scan()
1231 flash->sector_size = info->sector_size << flash->shift; in spi_flash_scan()
1232 flash->size = flash->sector_size * info->n_sectors << flash->shift; in spi_flash_scan()
1234 if (flash->dual_flash & SF_DUAL_STACKED_FLASH) in spi_flash_scan()
1235 flash->size <<= 1; in spi_flash_scan()
1240 if (info->flags & SECT_4K) { in spi_flash_scan()
1241 flash->erase_cmd = CMD_ERASE_4K; in spi_flash_scan()
1242 flash->erase_size = 4096 << flash->shift; in spi_flash_scan()
1246 flash->erase_cmd = CMD_ERASE_64K; in spi_flash_scan()
1247 flash->erase_size = flash->sector_size; in spi_flash_scan()
1251 flash->sector_size = flash->erase_size; in spi_flash_scan()
1254 flash->read_cmd = CMD_READ_ARRAY_FAST; in spi_flash_scan()
1255 if (spi->mode & SPI_RX_SLOW) in spi_flash_scan()
1256 flash->read_cmd = CMD_READ_ARRAY_SLOW; in spi_flash_scan()
1257 else if (spi->mode & SPI_RX_QUAD && info->flags & RD_QUAD) in spi_flash_scan()
1258 flash->read_cmd = CMD_READ_QUAD_OUTPUT_FAST; in spi_flash_scan()
1259 else if (spi->mode & SPI_RX_DUAL && info->flags & RD_DUAL) in spi_flash_scan()
1260 flash->read_cmd = CMD_READ_DUAL_OUTPUT_FAST; in spi_flash_scan()
1263 if (info->flags & WR_QPP && spi->mode & SPI_TX_QUAD) in spi_flash_scan()
1264 flash->write_cmd = CMD_QUAD_PAGE_PROGRAM; in spi_flash_scan()
1267 flash->write_cmd = CMD_PAGE_PROGRAM; in spi_flash_scan()
1269 /* Set the quad enable bit - only for quad commands */ in spi_flash_scan()
1270 if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) || in spi_flash_scan()
1271 (flash->read_cmd == CMD_READ_QUAD_IO_FAST) || in spi_flash_scan()
1272 (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) { in spi_flash_scan()
1273 ret = set_quad_mode(flash, info); in spi_flash_scan()
1277 return -EINVAL; in spi_flash_scan()
1283 * Fast commands - dummy_byte = dummy_cycles/8 in spi_flash_scan()
1284 * I/O commands- dummy_byte = (dummy_cycles * no.of lines)/8 in spi_flash_scan()
1289 switch (flash->read_cmd) { in spi_flash_scan()
1291 flash->dummy_byte = 2; in spi_flash_scan()
1294 flash->dummy_byte = 0; in spi_flash_scan()
1297 flash->dummy_byte = 1; in spi_flash_scan()
1301 if (info->flags & E_FSR) in spi_flash_scan()
1302 flash->flags |= SNOR_F_USE_FSR; in spi_flash_scan()
1305 /* Configure the BAR - discover bank cmds and read current bank */ in spi_flash_scan()
1307 ret = read_bar(flash, info); in spi_flash_scan()
1313 ret = spi_flash_decode_fdt(flash); in spi_flash_scan()
1316 return -EINVAL; in spi_flash_scan()
1321 printf("SF: Detected %s with page size ", flash->name); in spi_flash_scan()
1322 print_size(flash->page_size, ", erase size "); in spi_flash_scan()
1323 print_size(flash->erase_size, ", total "); in spi_flash_scan()
1324 print_size(flash->size, ""); in spi_flash_scan()
1325 if (flash->memory_map) in spi_flash_scan()
1326 printf(", mapped at %p", flash->memory_map); in spi_flash_scan()
1331 if (((flash->dual_flash == SF_SINGLE_FLASH) && in spi_flash_scan()
1332 (flash->size > SPI_FLASH_16MB_BOUN)) || in spi_flash_scan()
1333 ((flash->dual_flash > SF_SINGLE_FLASH) && in spi_flash_scan()
1334 (flash->size > SPI_FLASH_16MB_BOUN << 1))) { in spi_flash_scan()
1335 puts("SF: Warning - Only lower 16MiB accessible,"); in spi_flash_scan()