Lines Matching refs:info
184 flash_info_t *info; in flash_get_info() local
187 info = &flash_info[i]; in flash_get_info()
188 if (info->size && info->start[0] <= base && in flash_get_info()
189 base <= info->start[0] + info->size - 1) in flash_get_info()
190 return info; in flash_get_info()
197 unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect) in flash_sector_size() argument
199 if (sect != (info->sector_count - 1)) in flash_sector_size()
200 return info->start[sect + 1] - info->start[sect]; in flash_sector_size()
202 return info->start[0] + info->size - info->start[sect]; in flash_sector_size()
209 flash_map(flash_info_t *info, flash_sect_t sect, uint offset) in flash_map() argument
211 unsigned int byte_offset = offset * info->portwidth; in flash_map()
213 return (void *)(info->start[sect] + byte_offset); in flash_map()
216 static inline void flash_unmap(flash_info_t *info, flash_sect_t sect, in flash_unmap() argument
224 static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) in flash_make_cmd() argument
235 for (i = info->portwidth; i > 0; i--) { in flash_make_cmd()
236 cword_offset = (info->portwidth - i) % info->chipwidth; in flash_make_cmd()
238 cp_offset = info->portwidth - i; in flash_make_cmd()
288 static inline uchar flash_read_uchar(flash_info_t *info, uint offset) in flash_read_uchar() argument
293 cp = flash_map(info, 0, offset); in flash_read_uchar()
297 retval = flash_read8(cp + info->portwidth - 1); in flash_read_uchar()
299 flash_unmap(info, 0, offset, cp); in flash_read_uchar()
306 static inline ushort flash_read_word(flash_info_t *info, uint offset) in flash_read_word() argument
310 addr = flash_map(info, 0, offset); in flash_read_word()
312 flash_unmap(info, 0, offset, addr); in flash_read_word()
320 static ulong flash_read_long (flash_info_t *info, flash_sect_t sect, in flash_read_long() argument
329 addr = flash_map(info, sect, offset); in flash_read_long()
333 info->portwidth); in flash_read_long()
334 for (x = 0; x < 4 * info->portwidth; x++) in flash_read_long()
339 (flash_read8(addr + info->portwidth) << 24) | in flash_read_long()
340 (flash_read8(addr + 2 * info->portwidth)) | in flash_read_long()
341 (flash_read8(addr + 3 * info->portwidth) << 8)); in flash_read_long()
343 retval = ((flash_read8(addr + 2 * info->portwidth - 1) << 24) | in flash_read_long()
344 (flash_read8(addr + info->portwidth - 1) << 16) | in flash_read_long()
345 (flash_read8(addr + 4 * info->portwidth - 1) << 8) | in flash_read_long()
346 (flash_read8(addr + 3 * info->portwidth - 1))); in flash_read_long()
348 flash_unmap(info, sect, offset, addr); in flash_read_long()
356 static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, in flash_write_cmd() argument
362 addr = flash_map(info, sect, offset); in flash_write_cmd()
363 flash_make_cmd(info, cmd, &cword); in flash_write_cmd()
364 switch (info->portwidth) { in flash_write_cmd()
367 cword.w8, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
373 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
379 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
391 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
401 flash_unmap(info, sect, offset, addr); in flash_write_cmd()
404 static void flash_unlock_seq(flash_info_t *info, flash_sect_t sect) in flash_unlock_seq() argument
406 flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START); in flash_unlock_seq()
407 flash_write_cmd(info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK); in flash_unlock_seq()
412 static int flash_isequal(flash_info_t *info, flash_sect_t sect, uint offset, in flash_isequal() argument
419 addr = flash_map(info, sect, offset); in flash_isequal()
420 flash_make_cmd(info, cmd, &cword); in flash_isequal()
423 switch (info->portwidth) { in flash_isequal()
453 flash_unmap(info, sect, offset, addr); in flash_isequal()
460 static int flash_isset(flash_info_t *info, flash_sect_t sect, uint offset, in flash_isset() argument
467 addr = flash_map(info, sect, offset); in flash_isset()
468 flash_make_cmd(info, cmd, &cword); in flash_isset()
469 switch (info->portwidth) { in flash_isset()
486 flash_unmap(info, sect, offset, addr); in flash_isset()
493 static int flash_toggle(flash_info_t *info, flash_sect_t sect, uint offset, in flash_toggle() argument
500 addr = flash_map(info, sect, offset); in flash_toggle()
501 flash_make_cmd(info, cmd, &cword); in flash_toggle()
502 switch (info->portwidth) { in flash_toggle()
520 flash_unmap(info, sect, offset, addr); in flash_toggle()
531 static int flash_is_busy(flash_info_t *info, flash_sect_t sect) in flash_is_busy() argument
535 switch (info->vendor) { in flash_is_busy()
539 retval = !flash_isset(info, sect, 0, FLASH_STATUS_DONE); in flash_is_busy()
546 if (info->sr_supported) { in flash_is_busy()
547 flash_write_cmd(info, sect, info->addr_unlock1, in flash_is_busy()
549 retval = !flash_isset(info, sect, 0, in flash_is_busy()
552 retval = flash_toggle(info, sect, 0, in flash_is_busy()
568 static int flash_status_check(flash_info_t *info, flash_sect_t sector, in flash_status_check() argument
587 while (flash_is_busy(info, sector)) { in flash_status_check()
590 prompt, info->start[sector], in flash_status_check()
591 flash_read_long(info, sector, 0)); in flash_status_check()
592 flash_write_cmd(info, sector, 0, info->cmd_reset); in flash_status_check()
607 static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, in flash_full_status_check() argument
612 retcode = flash_status_check(info, sector, tout, prompt); in flash_full_status_check()
613 switch (info->vendor) { in flash_full_status_check()
618 !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { in flash_full_status_check()
621 info->start[sector]); in flash_full_status_check()
622 if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | in flash_full_status_check()
625 } else if (flash_isset(info, sector, 0, in flash_full_status_check()
629 } else if (flash_isset(info, sector, 0, in flash_full_status_check()
633 if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) { in flash_full_status_check()
637 if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS)) in flash_full_status_check()
640 flash_write_cmd(info, sector, 0, info->cmd_reset); in flash_full_status_check()
649 static int use_flash_status_poll(flash_info_t *info) in use_flash_status_poll() argument
652 if (info->vendor == CFI_CMDSET_AMD_EXTENDED || in use_flash_status_poll()
653 info->vendor == CFI_CMDSET_AMD_STANDARD) in use_flash_status_poll()
659 static int flash_status_poll(flash_info_t *info, void *src, void *dst, in flash_status_poll() argument
681 switch (info->portwidth) { in flash_status_poll()
713 static void flash_add_byte(flash_info_t *info, cfiword_t *cword, uchar c) in flash_add_byte() argument
721 switch (info->portwidth) { in flash_add_byte()
759 static flash_sect_t find_sector(flash_info_t *info, ulong addr) in find_sector() argument
765 if (info != saved_info || sector >= info->sector_count) in find_sector()
768 while ((sector < info->sector_count - 1) && in find_sector()
769 (info->start[sector] < addr)) in find_sector()
771 while ((info->start[sector] > addr) && (sector > 0)) in find_sector()
779 saved_info = info; in find_sector()
785 static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword) in flash_write_cfiword() argument
793 switch (info->portwidth) { in flash_write_cfiword()
816 switch (info->vendor) { in flash_write_cfiword()
820 flash_write_cmd(info, 0, 0, FLASH_CMD_CLEAR_STATUS); in flash_write_cfiword()
821 flash_write_cmd(info, 0, 0, FLASH_CMD_WRITE); in flash_write_cfiword()
825 sect = find_sector(info, dest); in flash_write_cfiword()
826 flash_unlock_seq(info, sect); in flash_write_cfiword()
827 flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_WRITE); in flash_write_cfiword()
832 sect = find_sector(info, dest); in flash_write_cfiword()
833 flash_unlock_seq(info, 0); in flash_write_cfiword()
834 flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_WRITE); in flash_write_cfiword()
840 switch (info->portwidth) { in flash_write_cfiword()
860 sect = find_sector(info, dest); in flash_write_cfiword()
862 if (use_flash_status_poll(info)) in flash_write_cfiword()
863 return flash_status_poll(info, &cword, dstaddr, in flash_write_cfiword()
864 info->write_tout, "write"); in flash_write_cfiword()
866 return flash_full_status_check(info, sect, in flash_write_cfiword()
867 info->write_tout, "write"); in flash_write_cfiword()
872 static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, in flash_write_cfibuffer() argument
886 switch (info->portwidth) { in flash_write_cfibuffer()
907 switch (info->portwidth) { in flash_write_cfibuffer()
936 sector = find_sector(info, dest); in flash_write_cfibuffer()
938 switch (info->vendor) { in flash_write_cfibuffer()
942 write_cmd = (info->vendor == CFI_CMDSET_INTEL_PROG_REGIONS) ? in flash_write_cfibuffer()
945 flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); in flash_write_cfibuffer()
946 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); in flash_write_cfibuffer()
947 flash_write_cmd(info, sector, 0, write_cmd); in flash_write_cfibuffer()
948 retcode = flash_status_check(info, sector, in flash_write_cfibuffer()
949 info->buffer_write_tout, in flash_write_cfibuffer()
956 flash_write_cmd(info, sector, 0, cnt - 1); in flash_write_cfibuffer()
958 switch (info->portwidth) { in flash_write_cfibuffer()
980 flash_write_cmd(info, sector, 0, in flash_write_cfibuffer()
983 info, sector, info->buffer_write_tout, in flash_write_cfibuffer()
991 flash_unlock_seq(info, sector); in flash_write_cfibuffer()
994 offset = ((unsigned long)dst - info->start[sector]) >> shift; in flash_write_cfibuffer()
996 flash_write_cmd(info, sector, offset, AMD_CMD_WRITE_TO_BUFFER); in flash_write_cfibuffer()
998 flash_write_cmd(info, sector, offset, cnt - 1); in flash_write_cfibuffer()
1000 switch (info->portwidth) { in flash_write_cfibuffer()
1030 flash_write_cmd(info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM); in flash_write_cfibuffer()
1031 if (use_flash_status_poll(info)) in flash_write_cfibuffer()
1032 retcode = flash_status_poll(info, src - (1 << shift), in flash_write_cfibuffer()
1034 info->buffer_write_tout, in flash_write_cfibuffer()
1037 retcode = flash_full_status_check(info, sector, in flash_write_cfibuffer()
1038 info->buffer_write_tout, in flash_write_cfibuffer()
1055 int flash_erase(flash_info_t *info, int s_first, int s_last) in flash_erase() argument
1062 if (info->flash_id != FLASH_MAN_CFI) { in flash_erase()
1073 if (info->protect[sect]) in flash_erase()
1088 if (info->protect[sect] == 0) { /* not protected */ in flash_erase()
1098 size = flash_sector_size(info, sect); in flash_erase()
1100 flash = (u32 *)info->start[sect]; in flash_erase()
1115 switch (info->vendor) { in flash_erase()
1119 flash_write_cmd(info, sect, 0, in flash_erase()
1121 flash_write_cmd(info, sect, 0, in flash_erase()
1123 flash_write_cmd(info, sect, 0, in flash_erase()
1128 flash_unlock_seq(info, sect); in flash_erase()
1129 flash_write_cmd(info, sect, in flash_erase()
1130 info->addr_unlock1, in flash_erase()
1132 flash_unlock_seq(info, sect); in flash_erase()
1133 flash_write_cmd(info, sect, 0, in flash_erase()
1134 info->cmd_erase_sector); in flash_erase()
1138 flash_unlock_seq(info, 0); in flash_erase()
1139 flash_write_cmd(info, 0, info->addr_unlock1, in flash_erase()
1141 flash_unlock_seq(info, 0); in flash_erase()
1142 flash_write_cmd(info, sect, 0, in flash_erase()
1148 info->vendor); in flash_erase()
1152 if (use_flash_status_poll(info)) { in flash_erase()
1157 dest = flash_map(info, sect, 0); in flash_erase()
1158 st = flash_status_poll(info, &cword, dest, in flash_erase()
1159 info->erase_blk_tout, in flash_erase()
1161 flash_unmap(info, sect, 0, dest); in flash_erase()
1163 st = flash_full_status_check(info, sect, in flash_erase()
1164 info->erase_blk_tout, in flash_erase()
1182 static int sector_erased(flash_info_t *info, int i) in sector_erased() argument
1191 size = flash_sector_size(info, i); in sector_erased()
1192 flash = (u32 *)info->start[i]; in sector_erased()
1205 void flash_print_info(flash_info_t *info) in flash_print_info() argument
1209 if (info->flash_id != FLASH_MAN_CFI) { in flash_print_info()
1215 info->name, in flash_print_info()
1216 (info->portwidth << 3), (info->chipwidth << 3)); in flash_print_info()
1217 if (info->size < 1024 * 1024) in flash_print_info()
1219 info->size >> 10, info->sector_count); in flash_print_info()
1222 info->size >> 20, info->sector_count); in flash_print_info()
1224 switch (info->vendor) { in flash_print_info()
1246 printf("Unknown (%d)", info->vendor); in flash_print_info()
1250 info->manufacturer_id); in flash_print_info()
1251 printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", in flash_print_info()
1252 info->device_id); in flash_print_info()
1253 if ((info->device_id & 0xff) == 0x7E) { in flash_print_info()
1254 printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", in flash_print_info()
1255 info->device_id2); in flash_print_info()
1257 if (info->vendor == CFI_CMDSET_AMD_STANDARD && info->legacy_unlock) in flash_print_info()
1260 info->erase_blk_tout, info->write_tout); in flash_print_info()
1261 if (info->buffer_size > 1) { in flash_print_info()
1263 info->buffer_write_tout); in flash_print_info()
1264 printf("buffer size: %d bytes\n", info->buffer_size); in flash_print_info()
1268 for (i = 0; i < info->sector_count; ++i) { in flash_print_info()
1276 info->start[i], in flash_print_info()
1277 sector_erased(info, i) ? 'E' : ' ', in flash_print_info()
1278 info->protect[i] ? "RO" : " "); in flash_print_info()
1281 info->start[i], in flash_print_info()
1282 info->protect[i] ? "RO" : " "); in flash_print_info()
1317 int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) in write_buff() argument
1342 wp = (addr & ~(info->portwidth - 1)); in write_buff()
1350 flash_add_byte(info, &cword, flash_read8(p + i)); in write_buff()
1352 for (; (i < info->portwidth) && (cnt > 0); i++) { in write_buff()
1353 flash_add_byte(info, &cword, *src++); in write_buff()
1356 for (; (cnt == 0) && (i < info->portwidth); ++i) in write_buff()
1357 flash_add_byte(info, &cword, flash_read8(p + i)); in write_buff()
1359 rc = flash_write_cfiword(info, wp, cword); in write_buff()
1369 buffered_size = (info->portwidth / info->chipwidth); in write_buff()
1370 buffered_size *= info->buffer_size; in write_buff()
1371 while (cnt >= info->portwidth) { in write_buff()
1373 if (info->buffer_size == 1) { in write_buff()
1375 for (i = 0; i < info->portwidth; i++) in write_buff()
1376 flash_add_byte(info, &cword, *src++); in write_buff()
1377 rc = flash_write_cfiword(info, wp, cword); in write_buff()
1380 wp += info->portwidth; in write_buff()
1381 cnt -= info->portwidth; in write_buff()
1389 rc = flash_write_cfibuffer(info, wp, src, i); in write_buff()
1392 i -= i & (info->portwidth - 1); in write_buff()
1402 while (cnt >= info->portwidth) { in write_buff()
1404 for (i = 0; i < info->portwidth; i++) in write_buff()
1405 flash_add_byte(info, &cword, *src++); in write_buff()
1406 rc = flash_write_cfiword(info, wp, cword); in write_buff()
1409 wp += info->portwidth; in write_buff()
1410 cnt -= info->portwidth; in write_buff()
1411 FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth); in write_buff()
1413 if ((cnt & 0xFFFF) < info->portwidth && ctrlc()) in write_buff()
1426 for (i = 0; (i < info->portwidth) && (cnt > 0); ++i) { in write_buff()
1427 flash_add_byte(info, &cword, *src++); in write_buff()
1430 for (; i < info->portwidth; ++i) in write_buff()
1431 flash_add_byte(info, &cword, flash_read8(p + i)); in write_buff()
1433 return flash_write_cfiword(info, wp, cword); in write_buff()
1436 static inline int manufact_match(flash_info_t *info, u32 manu) in manufact_match() argument
1438 return info->manufacturer_id == ((manu & FLASH_VENDMASK) >> 16); in manufact_match()
1445 static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) in cfi_protect_bugfix() argument
1447 if (manufact_match(info, INTEL_MANUFACT) && in cfi_protect_bugfix()
1448 info->device_id == NUMONYX_256MBIT) { in cfi_protect_bugfix()
1453 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_ID); in cfi_protect_bugfix()
1454 if (!flash_isequal(info, sector, FLASH_OFFSET_PROTECT, in cfi_protect_bugfix()
1468 flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); in cfi_protect_bugfix()
1469 flash_write_cmd(info, sector, 0, cmd); in cfi_protect_bugfix()
1479 int flash_real_protect(flash_info_t *info, long sector, int prot) in flash_real_protect() argument
1483 switch (info->vendor) { in flash_real_protect()
1487 if (!cfi_protect_bugfix(info, sector, prot)) { in flash_real_protect()
1488 flash_write_cmd(info, sector, 0, in flash_real_protect()
1490 flash_write_cmd(info, sector, 0, in flash_real_protect()
1493 flash_write_cmd(info, sector, 0, in flash_real_protect()
1496 flash_write_cmd(info, sector, 0, in flash_real_protect()
1503 if (manufact_match(info, ATM_MANUFACT)) { in flash_real_protect()
1505 flash_unlock_seq(info, 0); in flash_real_protect()
1506 flash_write_cmd(info, 0, in flash_real_protect()
1507 info->addr_unlock1, in flash_real_protect()
1509 flash_unlock_seq(info, 0); in flash_real_protect()
1510 flash_write_cmd(info, sector, 0, in flash_real_protect()
1513 flash_write_cmd(info, 0, in flash_real_protect()
1514 info->addr_unlock1, in flash_real_protect()
1516 if (info->device_id == ATM_ID_BV6416) in flash_real_protect()
1517 flash_write_cmd(info, sector, in flash_real_protect()
1521 if (info->legacy_unlock) { in flash_real_protect()
1525 flash_unlock_seq(info, 0); in flash_real_protect()
1526 flash_write_cmd(info, 0, info->addr_unlock1, in flash_real_protect()
1528 lock_flag = flash_isset(info, sector, 0, 0x01); in flash_real_protect()
1531 flash_write_cmd(info, sector, 0, in flash_real_protect()
1533 flash_write_cmd(info, sector, 0, in flash_real_protect()
1541 flash_write_cmd(info, 0, 0, in flash_real_protect()
1543 flash_write_cmd(info, 0, 0, in flash_real_protect()
1552 if (flash_status_check(info, sector, in flash_real_protect()
1553 info->erase_blk_tout, in flash_real_protect()
1557 flash_write_cmd(info, 0, 0, in flash_real_protect()
1559 flash_write_cmd(info, 0, 0, in flash_real_protect()
1565 flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); in flash_real_protect()
1566 flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); in flash_real_protect()
1568 flash_write_cmd(info, sector, 0, in flash_real_protect()
1571 flash_write_cmd(info, sector, 0, in flash_real_protect()
1580 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); in flash_real_protect()
1581 retcode = flash_full_status_check(info, sector, info->erase_blk_tout, in flash_real_protect()
1584 info->protect[sector] = prot; in flash_real_protect()
1590 if (prot == 0 && info->legacy_unlock) { in flash_real_protect()
1593 for (i = 0; i < info->sector_count; i++) { in flash_real_protect()
1594 if (info->protect[i]) in flash_real_protect()
1595 flash_real_protect(info, i, 1); in flash_real_protect()
1605 void flash_read_user_serial(flash_info_t *info, void *buffer, int offset, in flash_read_user_serial() argument
1612 src = flash_map(info, 0, FLASH_OFFSET_USER_PROTECTION); in flash_read_user_serial()
1613 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); in flash_read_user_serial()
1615 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_read_user_serial()
1617 flash_unmap(info, 0, FLASH_OFFSET_USER_PROTECTION, src); in flash_read_user_serial()
1623 void flash_read_factory_serial(flash_info_t *info, void *buffer, int offset, in flash_read_factory_serial() argument
1628 src = flash_map(info, 0, FLASH_OFFSET_INTEL_PROTECTION); in flash_read_factory_serial()
1629 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); in flash_read_factory_serial()
1631 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_read_factory_serial()
1633 flash_unmap(info, 0, FLASH_OFFSET_INTEL_PROTECTION, src); in flash_read_factory_serial()
1662 static void cmdset_intel_read_jedec_ids(flash_info_t *info) in cmdset_intel_read_jedec_ids() argument
1664 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in cmdset_intel_read_jedec_ids()
1666 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); in cmdset_intel_read_jedec_ids()
1668 info->manufacturer_id = flash_read_uchar(info, in cmdset_intel_read_jedec_ids()
1670 info->device_id = (info->chipwidth == FLASH_CFI_16BIT) ? in cmdset_intel_read_jedec_ids()
1671 flash_read_word(info, FLASH_OFFSET_DEVICE_ID) : in cmdset_intel_read_jedec_ids()
1672 flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID); in cmdset_intel_read_jedec_ids()
1673 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in cmdset_intel_read_jedec_ids()
1676 static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry) in cmdset_intel_init() argument
1678 info->cmd_reset = FLASH_CMD_RESET; in cmdset_intel_init()
1680 cmdset_intel_read_jedec_ids(info); in cmdset_intel_init()
1681 flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); in cmdset_intel_init()
1685 if (info->ext_addr) { in cmdset_intel_init()
1686 info->legacy_unlock = in cmdset_intel_init()
1687 flash_read_uchar(info, info->ext_addr + 5) & 0x08; in cmdset_intel_init()
1694 static void cmdset_amd_read_jedec_ids(flash_info_t *info) in cmdset_amd_read_jedec_ids() argument
1700 flash_write_cmd(info, 0, 0, AMD_CMD_RESET); in cmdset_amd_read_jedec_ids()
1701 flash_unlock_seq(info, 0); in cmdset_amd_read_jedec_ids()
1702 flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); in cmdset_amd_read_jedec_ids()
1705 manu_id = flash_read_uchar(info, FLASH_OFFSET_MANUFACTURER_ID); in cmdset_amd_read_jedec_ids()
1709 manu_id = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1712 info->manufacturer_id = manu_id; in cmdset_amd_read_jedec_ids()
1715 info->ext_addr, info->cfi_version); in cmdset_amd_read_jedec_ids()
1716 if (info->ext_addr && info->cfi_version >= 0x3134) { in cmdset_amd_read_jedec_ids()
1718 feature = flash_read_uchar(info, info->ext_addr + 0x13); in cmdset_amd_read_jedec_ids()
1720 info->sr_supported = feature & 0x1; in cmdset_amd_read_jedec_ids()
1723 switch (info->chipwidth) { in cmdset_amd_read_jedec_ids()
1725 info->device_id = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1727 if (info->device_id == 0x7E) { in cmdset_amd_read_jedec_ids()
1729 info->device_id2 = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1731 info->device_id2 <<= 8; in cmdset_amd_read_jedec_ids()
1732 info->device_id2 |= flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1737 info->device_id = flash_read_word(info, in cmdset_amd_read_jedec_ids()
1739 if ((info->device_id & 0xff) == 0x7E) { in cmdset_amd_read_jedec_ids()
1741 info->device_id2 = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1743 info->device_id2 <<= 8; in cmdset_amd_read_jedec_ids()
1744 info->device_id2 |= flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1751 flash_write_cmd(info, 0, 0, AMD_CMD_RESET); in cmdset_amd_read_jedec_ids()
1755 static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry) in cmdset_amd_init() argument
1757 info->cmd_reset = AMD_CMD_RESET; in cmdset_amd_init()
1758 info->cmd_erase_sector = AMD_CMD_ERASE_SECTOR; in cmdset_amd_init()
1760 cmdset_amd_read_jedec_ids(info); in cmdset_amd_init()
1761 flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); in cmdset_amd_init()
1764 if (info->ext_addr) { in cmdset_amd_init()
1766 if (flash_read_uchar(info, info->ext_addr + 9) == 0x8) in cmdset_amd_init()
1767 info->legacy_unlock = 1; in cmdset_amd_init()
1775 static void flash_read_jedec_ids(flash_info_t *info) in flash_read_jedec_ids() argument
1777 info->manufacturer_id = 0; in flash_read_jedec_ids()
1778 info->device_id = 0; in flash_read_jedec_ids()
1779 info->device_id2 = 0; in flash_read_jedec_ids()
1781 switch (info->vendor) { in flash_read_jedec_ids()
1785 cmdset_intel_read_jedec_ids(info); in flash_read_jedec_ids()
1789 cmdset_amd_read_jedec_ids(info); in flash_read_jedec_ids()
1803 flash_info_t *info = &flash_info[banknum]; in flash_detect_legacy() local
1805 if (board_flash_get_legacy(base, banknum, info)) { in flash_detect_legacy()
1809 if (!info->vendor) { in flash_detect_legacy()
1817 info->vendor = modes[i]; in flash_detect_legacy()
1818 info->start[0] = in flash_detect_legacy()
1820 info->portwidth, in flash_detect_legacy()
1822 if (info->portwidth == FLASH_CFI_8BIT && in flash_detect_legacy()
1823 info->interface == FLASH_CFI_X8X16) { in flash_detect_legacy()
1824 info->addr_unlock1 = 0x2AAA; in flash_detect_legacy()
1825 info->addr_unlock2 = 0x5555; in flash_detect_legacy()
1827 info->addr_unlock1 = 0x5555; in flash_detect_legacy()
1828 info->addr_unlock2 = 0x2AAA; in flash_detect_legacy()
1830 flash_read_jedec_ids(info); in flash_detect_legacy()
1832 info->manufacturer_id, in flash_detect_legacy()
1833 info->device_id, in flash_detect_legacy()
1834 info->device_id2); in flash_detect_legacy()
1835 if (jedec_flash_match(info, info->start[0])) in flash_detect_legacy()
1838 unmap_physmem((void *)info->start[0], in flash_detect_legacy()
1839 info->portwidth); in flash_detect_legacy()
1843 switch (info->vendor) { in flash_detect_legacy()
1847 info->cmd_reset = FLASH_CMD_RESET; in flash_detect_legacy()
1852 info->cmd_reset = AMD_CMD_RESET; in flash_detect_legacy()
1855 info->flash_id = FLASH_MAN_CFI; in flash_detect_legacy()
1871 static void flash_read_cfi(flash_info_t *info, void *buf, unsigned int start, in flash_read_cfi() argument
1878 p[i] = flash_read_uchar(info, start + i); in flash_read_cfi()
1881 static void __flash_cmd_reset(flash_info_t *info) in __flash_cmd_reset() argument
1888 flash_write_cmd(info, 0, 0, AMD_CMD_RESET); in __flash_cmd_reset()
1890 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in __flash_cmd_reset()
1893 void flash_cmd_reset(flash_info_t *info)
1896 static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) in __flash_detect_cfi() argument
1901 flash_cmd_reset(info); in __flash_detect_cfi()
1905 flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], in __flash_detect_cfi()
1907 if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') && in __flash_detect_cfi()
1908 flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && in __flash_detect_cfi()
1909 flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { in __flash_detect_cfi()
1910 flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, in __flash_detect_cfi()
1912 info->interface = le16_to_cpu(qry->interface_desc); in __flash_detect_cfi()
1914 info->cfi_offset = flash_offset_cfi[cfi_offset]; in __flash_detect_cfi()
1916 info->interface); in __flash_detect_cfi()
1918 info->portwidth, info->chipwidth); in __flash_detect_cfi()
1920 info->portwidth << CFI_FLASH_SHIFT_WIDTH, in __flash_detect_cfi()
1921 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in __flash_detect_cfi()
1924 info->addr_unlock1 = 0x555; in __flash_detect_cfi()
1925 info->addr_unlock2 = 0x2aa; in __flash_detect_cfi()
1932 (info->chipwidth == FLASH_CFI_BY8 && in __flash_detect_cfi()
1933 info->interface == FLASH_CFI_X8X16) || in __flash_detect_cfi()
1935 (info->chipwidth == FLASH_CFI_BY16 && in __flash_detect_cfi()
1936 info->interface == FLASH_CFI_X16X32)) { in __flash_detect_cfi()
1937 info->addr_unlock1 = 0xaaa; in __flash_detect_cfi()
1938 info->addr_unlock2 = 0x555; in __flash_detect_cfi()
1941 info->name = "CFI conformant"; in __flash_detect_cfi()
1949 static int flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) in flash_detect_cfi() argument
1953 for (info->portwidth = CONFIG_SYS_FLASH_CFI_WIDTH; in flash_detect_cfi()
1954 info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) { in flash_detect_cfi()
1955 for (info->chipwidth = FLASH_CFI_BY8; in flash_detect_cfi()
1956 info->chipwidth <= info->portwidth; in flash_detect_cfi()
1957 info->chipwidth <<= 1) in flash_detect_cfi()
1958 if (__flash_detect_cfi(info, qry)) in flash_detect_cfi()
1969 static void flash_fixup_amd(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_amd() argument
1974 if (info->cfi_version < 0x3131) { in flash_fixup_amd()
1976 if ((info->device_id & 0x80) != 0) in flash_fixup_amd()
1978 } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { in flash_fixup_amd()
1986 static void flash_fixup_atmel(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_atmel() argument
1991 if (info->ext_addr && !(flash_read_uchar(info, info->ext_addr + 6) & 1)) in flash_fixup_atmel()
1998 if (info->device_id == 0xd6 || info->device_id == 0xd2) in flash_fixup_atmel()
2005 static void flash_fixup_stm(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_stm() argument
2010 if (info->cfi_version < 0x3131) { in flash_fixup_stm()
2012 if (info->device_id == 0x22CA || /* M29W320DT */ in flash_fixup_stm()
2013 info->device_id == 0x2256 || /* M29W320ET */ in flash_fixup_stm()
2014 info->device_id == 0x22D7) { /* M29W800DT */ in flash_fixup_stm()
2017 } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { in flash_fixup_stm()
2025 static void flash_fixup_sst(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_sst() argument
2037 if (info->device_id == 0x5D23 || /* SST39VF3201B */ in flash_fixup_sst()
2038 info->device_id == 0x5C23) { /* SST39VF3202B */ in flash_fixup_sst()
2040 info->cmd_erase_sector = 0x50; in flash_fixup_sst()
2044 static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_num() argument
2053 info->device_id == 0x7E && in flash_fixup_num()
2054 (info->device_id2 == 0x2201 || in flash_fixup_num()
2055 info->device_id2 == 0x2301 || in flash_fixup_num()
2056 info->device_id2 == 0x2801 || in flash_fixup_num()
2057 info->device_id2 == 0x4801)) { in flash_fixup_num()
2070 flash_info_t *info = &flash_info[banknum]; in flash_get_size() local
2084 info->ext_addr = 0; in flash_get_size()
2085 info->cfi_version = 0; in flash_get_size()
2087 info->legacy_unlock = 0; in flash_get_size()
2090 info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE); in flash_get_size()
2092 if (flash_detect_cfi(info, &qry)) { in flash_get_size()
2093 info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); in flash_get_size()
2094 info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); in flash_get_size()
2097 if (info->ext_addr) { in flash_get_size()
2098 info->cfi_version = (ushort)flash_read_uchar(info, in flash_get_size()
2099 info->ext_addr + 3) << 8; in flash_get_size()
2100 info->cfi_version |= (ushort)flash_read_uchar(info, in flash_get_size()
2101 info->ext_addr + 4); in flash_get_size()
2108 switch (info->vendor) { in flash_get_size()
2112 cmdset_intel_init(info, &qry); in flash_get_size()
2116 cmdset_amd_init(info, &qry); in flash_get_size()
2120 info->vendor); in flash_get_size()
2126 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in flash_get_size()
2131 switch (info->manufacturer_id) { in flash_get_size()
2134 flash_fixup_amd(info, &qry); in flash_get_size()
2137 flash_fixup_atmel(info, &qry); in flash_get_size()
2140 flash_fixup_stm(info, &qry); in flash_get_size()
2143 flash_fixup_sst(info, &qry); in flash_get_size()
2146 flash_fixup_num(info, &qry); in flash_get_size()
2150 debug("manufacturer is %d\n", info->vendor); in flash_get_size()
2151 debug("manufacturer id is 0x%x\n", info->manufacturer_id); in flash_get_size()
2152 debug("device id is 0x%x\n", info->device_id); in flash_get_size()
2153 debug("device id2 is 0x%x\n", info->device_id2); in flash_get_size()
2154 debug("cfi version is 0x%04x\n", info->cfi_version); in flash_get_size()
2156 size_ratio = info->portwidth / info->chipwidth; in flash_get_size()
2158 if (info->interface == FLASH_CFI_X8X16 && in flash_get_size()
2159 info->chipwidth == FLASH_CFI_BY8) { in flash_get_size()
2163 size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH, in flash_get_size()
2164 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_get_size()
2165 info->size = 1 << qry.dev_size; in flash_get_size()
2167 info->size *= size_ratio; in flash_get_size()
2169 if (max_size && info->size > max_size) { in flash_get_size()
2170 debug("[truncated from %ldMiB]", info->size >> 20); in flash_get_size()
2171 info->size = max_size; in flash_get_size()
2194 if (sector - base >= info->size) in flash_get_size()
2200 info->start[sect_cnt] = in flash_get_size()
2202 info->portwidth, in flash_get_size()
2210 switch (info->vendor) { in flash_get_size()
2219 flash_write_cmd(info, sect_cnt, 0, in flash_get_size()
2221 info->protect[sect_cnt] = in flash_get_size()
2222 flash_isset(info, sect_cnt, in flash_get_size()
2225 flash_write_cmd(info, sect_cnt, 0, in flash_get_size()
2230 if (!info->legacy_unlock) { in flash_get_size()
2232 info->protect[sect_cnt] = 0; in flash_get_size()
2237 flash_write_cmd(info, 0, 0, in flash_get_size()
2238 info->cmd_reset); in flash_get_size()
2239 flash_unlock_seq(info, 0); in flash_get_size()
2240 flash_write_cmd(info, 0, in flash_get_size()
2241 info->addr_unlock1, in flash_get_size()
2243 info->protect[sect_cnt] = in flash_get_size()
2245 info, sect_cnt, in flash_get_size()
2251 info->protect[sect_cnt] = 0; in flash_get_size()
2258 info->sector_count = sect_cnt; in flash_get_size()
2259 info->buffer_size = 1 << le16_to_cpu(qry.max_buf_write_size); in flash_get_size()
2261 info->erase_blk_tout = tmp * in flash_get_size()
2267 info->buffer_write_tout = (tmp + 999) / 1000; in flash_get_size()
2271 info->write_tout = (tmp + 999) / 1000; in flash_get_size()
2272 info->flash_id = FLASH_MAN_CFI; in flash_get_size()
2273 if (info->interface == FLASH_CFI_X8X16 && in flash_get_size()
2274 info->chipwidth == FLASH_CFI_BY8) { in flash_get_size()
2276 info->portwidth >>= 1; in flash_get_size()
2279 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_get_size()
2282 return (info->size); in flash_get_size()