Lines Matching refs:info

192 	flash_info_t *info;  in flash_get_info()  local
195 info = &flash_info[i]; in flash_get_info()
196 if (info->size && info->start[0] <= base && in flash_get_info()
197 base <= info->start[0] + info->size - 1) in flash_get_info()
198 return info; in flash_get_info()
205 unsigned long flash_sector_size(flash_info_t *info, flash_sect_t sect) in flash_sector_size() argument
207 if (sect != (info->sector_count - 1)) in flash_sector_size()
208 return info->start[sect + 1] - info->start[sect]; in flash_sector_size()
210 return info->start[0] + info->size - info->start[sect]; in flash_sector_size()
217 flash_map(flash_info_t *info, flash_sect_t sect, uint offset) in flash_map() argument
219 unsigned int byte_offset = offset * info->portwidth; in flash_map()
221 return (void *)(info->start[sect] + byte_offset); in flash_map()
224 static inline void flash_unmap(flash_info_t *info, flash_sect_t sect, in flash_unmap() argument
232 static void flash_make_cmd(flash_info_t *info, u32 cmd, void *cmdbuf) in flash_make_cmd() argument
243 for (i = info->portwidth; i > 0; i--) { in flash_make_cmd()
244 cword_offset = (info->portwidth - i) % info->chipwidth; in flash_make_cmd()
246 cp_offset = info->portwidth - i; in flash_make_cmd()
296 static inline uchar flash_read_uchar(flash_info_t *info, uint offset) in flash_read_uchar() argument
301 cp = flash_map(info, 0, offset); in flash_read_uchar()
305 retval = flash_read8(cp + info->portwidth - 1); in flash_read_uchar()
307 flash_unmap(info, 0, offset, cp); in flash_read_uchar()
314 static inline ushort flash_read_word(flash_info_t *info, uint offset) in flash_read_word() argument
318 addr = flash_map(info, 0, offset); in flash_read_word()
320 flash_unmap(info, 0, offset, addr); in flash_read_word()
328 static ulong flash_read_long (flash_info_t *info, flash_sect_t sect, in flash_read_long() argument
337 addr = flash_map(info, sect, offset); in flash_read_long()
341 info->portwidth); in flash_read_long()
342 for (x = 0; x < 4 * info->portwidth; x++) in flash_read_long()
347 (flash_read8(addr + info->portwidth) << 24) | in flash_read_long()
348 (flash_read8(addr + 2 * info->portwidth)) | in flash_read_long()
349 (flash_read8(addr + 3 * info->portwidth) << 8)); in flash_read_long()
351 retval = ((flash_read8(addr + 2 * info->portwidth - 1) << 24) | in flash_read_long()
352 (flash_read8(addr + info->portwidth - 1) << 16) | in flash_read_long()
353 (flash_read8(addr + 4 * info->portwidth - 1) << 8) | in flash_read_long()
354 (flash_read8(addr + 3 * info->portwidth - 1))); in flash_read_long()
356 flash_unmap(info, sect, offset, addr); in flash_read_long()
364 static void flash_write_cmd(flash_info_t *info, flash_sect_t sect, in flash_write_cmd() argument
370 addr = flash_map(info, sect, offset); in flash_write_cmd()
371 flash_make_cmd(info, cmd, &cword); in flash_write_cmd()
372 switch (info->portwidth) { in flash_write_cmd()
375 cword.w8, info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
381 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
387 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
399 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_write_cmd()
409 flash_unmap(info, sect, offset, addr); in flash_write_cmd()
412 static void flash_unlock_seq(flash_info_t *info, flash_sect_t sect) in flash_unlock_seq() argument
414 flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_UNLOCK_START); in flash_unlock_seq()
415 flash_write_cmd(info, sect, info->addr_unlock2, AMD_CMD_UNLOCK_ACK); in flash_unlock_seq()
420 static int flash_isequal(flash_info_t *info, flash_sect_t sect, uint offset, in flash_isequal() argument
427 addr = flash_map(info, sect, offset); in flash_isequal()
428 flash_make_cmd(info, cmd, &cword); in flash_isequal()
431 switch (info->portwidth) { in flash_isequal()
461 flash_unmap(info, sect, offset, addr); in flash_isequal()
468 static int flash_isset(flash_info_t *info, flash_sect_t sect, uint offset, in flash_isset() argument
475 addr = flash_map(info, sect, offset); in flash_isset()
476 flash_make_cmd(info, cmd, &cword); in flash_isset()
477 switch (info->portwidth) { in flash_isset()
494 flash_unmap(info, sect, offset, addr); in flash_isset()
501 static int flash_toggle(flash_info_t *info, flash_sect_t sect, uint offset, in flash_toggle() argument
508 addr = flash_map(info, sect, offset); in flash_toggle()
509 flash_make_cmd(info, cmd, &cword); in flash_toggle()
510 switch (info->portwidth) { in flash_toggle()
528 flash_unmap(info, sect, offset, addr); in flash_toggle()
539 static int flash_is_busy(flash_info_t *info, flash_sect_t sect) in flash_is_busy() argument
543 switch (info->vendor) { in flash_is_busy()
547 retval = !flash_isset(info, sect, 0, FLASH_STATUS_DONE); in flash_is_busy()
554 if (info->sr_supported) { in flash_is_busy()
555 flash_write_cmd(info, sect, info->addr_unlock1, in flash_is_busy()
557 retval = !flash_isset(info, sect, 0, in flash_is_busy()
560 retval = flash_toggle(info, sect, 0, in flash_is_busy()
576 static int flash_status_check(flash_info_t *info, flash_sect_t sector, in flash_status_check() argument
595 while (flash_is_busy(info, sector)) { in flash_status_check()
598 prompt, info->start[sector], in flash_status_check()
599 flash_read_long(info, sector, 0)); in flash_status_check()
600 flash_write_cmd(info, sector, 0, info->cmd_reset); in flash_status_check()
615 static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, in flash_full_status_check() argument
620 retcode = flash_status_check(info, sector, tout, prompt); in flash_full_status_check()
621 switch (info->vendor) { in flash_full_status_check()
626 !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { in flash_full_status_check()
629 info->start[sector]); in flash_full_status_check()
630 if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | in flash_full_status_check()
633 } else if (flash_isset(info, sector, 0, in flash_full_status_check()
637 } else if (flash_isset(info, sector, 0, in flash_full_status_check()
641 if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) { in flash_full_status_check()
645 if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS)) in flash_full_status_check()
648 flash_write_cmd(info, sector, 0, info->cmd_reset); in flash_full_status_check()
657 static int use_flash_status_poll(flash_info_t *info) in use_flash_status_poll() argument
660 if (info->vendor == CFI_CMDSET_AMD_EXTENDED || in use_flash_status_poll()
661 info->vendor == CFI_CMDSET_AMD_STANDARD) in use_flash_status_poll()
667 static int flash_status_poll(flash_info_t *info, void *src, void *dst, in flash_status_poll() argument
689 switch (info->portwidth) { in flash_status_poll()
721 static void flash_add_byte(flash_info_t *info, cfiword_t *cword, uchar c) in flash_add_byte() argument
729 switch (info->portwidth) { in flash_add_byte()
767 static flash_sect_t find_sector(flash_info_t *info, ulong addr) in find_sector() argument
773 if (info != saved_info || sector >= info->sector_count) in find_sector()
776 while ((sector < info->sector_count - 1) && in find_sector()
777 (info->start[sector] < addr)) in find_sector()
779 while ((info->start[sector] > addr) && (sector > 0)) in find_sector()
787 saved_info = info; in find_sector()
793 static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword) in flash_write_cfiword() argument
801 switch (info->portwidth) { in flash_write_cfiword()
824 switch (info->vendor) { in flash_write_cfiword()
828 flash_write_cmd(info, 0, 0, FLASH_CMD_CLEAR_STATUS); in flash_write_cfiword()
829 flash_write_cmd(info, 0, 0, FLASH_CMD_WRITE); in flash_write_cfiword()
833 sect = find_sector(info, dest); in flash_write_cfiword()
834 flash_unlock_seq(info, sect); in flash_write_cfiword()
835 flash_write_cmd(info, sect, info->addr_unlock1, AMD_CMD_WRITE); in flash_write_cfiword()
840 sect = find_sector(info, dest); in flash_write_cfiword()
841 flash_unlock_seq(info, 0); in flash_write_cfiword()
842 flash_write_cmd(info, 0, info->addr_unlock1, AMD_CMD_WRITE); in flash_write_cfiword()
848 switch (info->portwidth) { in flash_write_cfiword()
868 sect = find_sector(info, dest); in flash_write_cfiword()
870 if (use_flash_status_poll(info)) in flash_write_cfiword()
871 return flash_status_poll(info, &cword, dstaddr, in flash_write_cfiword()
872 info->write_tout, "write"); in flash_write_cfiword()
874 return flash_full_status_check(info, sect, in flash_write_cfiword()
875 info->write_tout, "write"); in flash_write_cfiword()
880 static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, in flash_write_cfibuffer() argument
894 switch (info->portwidth) { in flash_write_cfibuffer()
915 switch (info->portwidth) { in flash_write_cfibuffer()
944 sector = find_sector(info, dest); in flash_write_cfibuffer()
946 switch (info->vendor) { in flash_write_cfibuffer()
950 write_cmd = (info->vendor == CFI_CMDSET_INTEL_PROG_REGIONS) ? in flash_write_cfibuffer()
953 flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); in flash_write_cfibuffer()
954 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); in flash_write_cfibuffer()
955 flash_write_cmd(info, sector, 0, write_cmd); in flash_write_cfibuffer()
956 retcode = flash_status_check(info, sector, in flash_write_cfibuffer()
957 info->buffer_write_tout, in flash_write_cfibuffer()
964 flash_write_cmd(info, sector, 0, cnt - 1); in flash_write_cfibuffer()
966 switch (info->portwidth) { in flash_write_cfibuffer()
988 flash_write_cmd(info, sector, 0, in flash_write_cfibuffer()
991 info, sector, info->buffer_write_tout, in flash_write_cfibuffer()
999 flash_unlock_seq(info, sector); in flash_write_cfibuffer()
1002 offset = ((unsigned long)dst - info->start[sector]) >> shift; in flash_write_cfibuffer()
1004 flash_write_cmd(info, sector, offset, AMD_CMD_WRITE_TO_BUFFER); in flash_write_cfibuffer()
1006 flash_write_cmd(info, sector, offset, cnt - 1); in flash_write_cfibuffer()
1008 switch (info->portwidth) { in flash_write_cfibuffer()
1038 flash_write_cmd(info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM); in flash_write_cfibuffer()
1039 if (use_flash_status_poll(info)) in flash_write_cfibuffer()
1040 retcode = flash_status_poll(info, src - (1 << shift), in flash_write_cfibuffer()
1042 info->buffer_write_tout, in flash_write_cfibuffer()
1045 retcode = flash_full_status_check(info, sector, in flash_write_cfibuffer()
1046 info->buffer_write_tout, in flash_write_cfibuffer()
1063 int flash_erase(flash_info_t *info, int s_first, int s_last) in flash_erase() argument
1070 if (info->flash_id != FLASH_MAN_CFI) { in flash_erase()
1081 if (info->protect[sect]) in flash_erase()
1096 if (info->protect[sect] == 0) { /* not protected */ in flash_erase()
1106 size = flash_sector_size(info, sect); in flash_erase()
1108 flash = (u32 *)info->start[sect]; in flash_erase()
1123 switch (info->vendor) { in flash_erase()
1127 flash_write_cmd(info, sect, 0, in flash_erase()
1129 flash_write_cmd(info, sect, 0, in flash_erase()
1131 flash_write_cmd(info, sect, 0, in flash_erase()
1136 flash_unlock_seq(info, sect); in flash_erase()
1137 flash_write_cmd(info, sect, in flash_erase()
1138 info->addr_unlock1, in flash_erase()
1140 flash_unlock_seq(info, sect); in flash_erase()
1141 flash_write_cmd(info, sect, 0, in flash_erase()
1142 info->cmd_erase_sector); in flash_erase()
1146 flash_unlock_seq(info, 0); in flash_erase()
1147 flash_write_cmd(info, 0, info->addr_unlock1, in flash_erase()
1149 flash_unlock_seq(info, 0); in flash_erase()
1150 flash_write_cmd(info, sect, 0, in flash_erase()
1156 info->vendor); in flash_erase()
1160 if (use_flash_status_poll(info)) { in flash_erase()
1165 dest = flash_map(info, sect, 0); in flash_erase()
1166 st = flash_status_poll(info, &cword, dest, in flash_erase()
1167 info->erase_blk_tout, in flash_erase()
1169 flash_unmap(info, sect, 0, dest); in flash_erase()
1171 st = flash_full_status_check(info, sect, in flash_erase()
1172 info->erase_blk_tout, in flash_erase()
1190 static int sector_erased(flash_info_t *info, int i) in sector_erased() argument
1199 size = flash_sector_size(info, i); in sector_erased()
1200 flash = (u32 *)info->start[i]; in sector_erased()
1213 void flash_print_info(flash_info_t *info) in flash_print_info() argument
1217 if (info->flash_id != FLASH_MAN_CFI) { in flash_print_info()
1223 info->name, in flash_print_info()
1224 (info->portwidth << 3), (info->chipwidth << 3)); in flash_print_info()
1225 if (info->size < 1024 * 1024) in flash_print_info()
1227 info->size >> 10, info->sector_count); in flash_print_info()
1230 info->size >> 20, info->sector_count); in flash_print_info()
1232 switch (info->vendor) { in flash_print_info()
1254 printf("Unknown (%d)", info->vendor); in flash_print_info()
1258 info->manufacturer_id); in flash_print_info()
1259 printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", in flash_print_info()
1260 info->device_id); in flash_print_info()
1261 if ((info->device_id & 0xff) == 0x7E) { in flash_print_info()
1262 printf(info->chipwidth == FLASH_CFI_16BIT ? "%04X" : "%02X", in flash_print_info()
1263 info->device_id2); in flash_print_info()
1265 if (info->vendor == CFI_CMDSET_AMD_STANDARD && info->legacy_unlock) in flash_print_info()
1268 info->erase_blk_tout, info->write_tout); in flash_print_info()
1269 if (info->buffer_size > 1) { in flash_print_info()
1271 info->buffer_write_tout); in flash_print_info()
1272 printf("buffer size: %d bytes\n", info->buffer_size); in flash_print_info()
1276 for (i = 0; i < info->sector_count; ++i) { in flash_print_info()
1284 info->start[i], in flash_print_info()
1285 sector_erased(info, i) ? 'E' : ' ', in flash_print_info()
1286 info->protect[i] ? "RO" : " "); in flash_print_info()
1289 info->start[i], in flash_print_info()
1290 info->protect[i] ? "RO" : " "); in flash_print_info()
1325 int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) in write_buff() argument
1350 wp = (addr & ~(info->portwidth - 1)); in write_buff()
1358 flash_add_byte(info, &cword, flash_read8(p + i)); in write_buff()
1360 for (; (i < info->portwidth) && (cnt > 0); i++) { in write_buff()
1361 flash_add_byte(info, &cword, *src++); in write_buff()
1364 for (; (cnt == 0) && (i < info->portwidth); ++i) in write_buff()
1365 flash_add_byte(info, &cword, flash_read8(p + i)); in write_buff()
1367 rc = flash_write_cfiword(info, wp, cword); in write_buff()
1377 buffered_size = (info->portwidth / info->chipwidth); in write_buff()
1378 buffered_size *= info->buffer_size; in write_buff()
1379 while (cnt >= info->portwidth) { in write_buff()
1381 if (info->buffer_size == 1) { in write_buff()
1383 for (i = 0; i < info->portwidth; i++) in write_buff()
1384 flash_add_byte(info, &cword, *src++); in write_buff()
1385 rc = flash_write_cfiword(info, wp, cword); in write_buff()
1388 wp += info->portwidth; in write_buff()
1389 cnt -= info->portwidth; in write_buff()
1397 rc = flash_write_cfibuffer(info, wp, src, i); in write_buff()
1400 i -= i & (info->portwidth - 1); in write_buff()
1410 while (cnt >= info->portwidth) { in write_buff()
1412 for (i = 0; i < info->portwidth; i++) in write_buff()
1413 flash_add_byte(info, &cword, *src++); in write_buff()
1414 rc = flash_write_cfiword(info, wp, cword); in write_buff()
1417 wp += info->portwidth; in write_buff()
1418 cnt -= info->portwidth; in write_buff()
1419 FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth); in write_buff()
1421 if ((cnt & 0xFFFF) < info->portwidth && ctrlc()) in write_buff()
1434 for (i = 0; (i < info->portwidth) && (cnt > 0); ++i) { in write_buff()
1435 flash_add_byte(info, &cword, *src++); in write_buff()
1438 for (; i < info->portwidth; ++i) in write_buff()
1439 flash_add_byte(info, &cword, flash_read8(p + i)); in write_buff()
1441 return flash_write_cfiword(info, wp, cword); in write_buff()
1444 static inline int manufact_match(flash_info_t *info, u32 manu) in manufact_match() argument
1446 return info->manufacturer_id == ((manu & FLASH_VENDMASK) >> 16); in manufact_match()
1453 static int cfi_protect_bugfix(flash_info_t *info, long sector, int prot) in cfi_protect_bugfix() argument
1455 if (manufact_match(info, INTEL_MANUFACT) && in cfi_protect_bugfix()
1456 info->device_id == NUMONYX_256MBIT) { in cfi_protect_bugfix()
1461 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_ID); in cfi_protect_bugfix()
1462 if (!flash_isequal(info, sector, FLASH_OFFSET_PROTECT, in cfi_protect_bugfix()
1476 flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); in cfi_protect_bugfix()
1477 flash_write_cmd(info, sector, 0, cmd); in cfi_protect_bugfix()
1487 int flash_real_protect(flash_info_t *info, long sector, int prot) in flash_real_protect() argument
1491 switch (info->vendor) { in flash_real_protect()
1495 if (!cfi_protect_bugfix(info, sector, prot)) { in flash_real_protect()
1496 flash_write_cmd(info, sector, 0, in flash_real_protect()
1498 flash_write_cmd(info, sector, 0, in flash_real_protect()
1501 flash_write_cmd(info, sector, 0, in flash_real_protect()
1504 flash_write_cmd(info, sector, 0, in flash_real_protect()
1511 if (manufact_match(info, ATM_MANUFACT)) { in flash_real_protect()
1513 flash_unlock_seq(info, 0); in flash_real_protect()
1514 flash_write_cmd(info, 0, in flash_real_protect()
1515 info->addr_unlock1, in flash_real_protect()
1517 flash_unlock_seq(info, 0); in flash_real_protect()
1518 flash_write_cmd(info, sector, 0, in flash_real_protect()
1521 flash_write_cmd(info, 0, in flash_real_protect()
1522 info->addr_unlock1, in flash_real_protect()
1524 if (info->device_id == ATM_ID_BV6416) in flash_real_protect()
1525 flash_write_cmd(info, sector, in flash_real_protect()
1529 if (info->legacy_unlock) { in flash_real_protect()
1533 flash_unlock_seq(info, 0); in flash_real_protect()
1534 flash_write_cmd(info, 0, info->addr_unlock1, in flash_real_protect()
1536 lock_flag = flash_isset(info, sector, 0, 0x01); in flash_real_protect()
1539 flash_write_cmd(info, sector, 0, in flash_real_protect()
1541 flash_write_cmd(info, sector, 0, in flash_real_protect()
1549 flash_write_cmd(info, 0, 0, in flash_real_protect()
1551 flash_write_cmd(info, 0, 0, in flash_real_protect()
1560 if (flash_status_check(info, sector, in flash_real_protect()
1561 info->erase_blk_tout, in flash_real_protect()
1565 flash_write_cmd(info, 0, 0, in flash_real_protect()
1567 flash_write_cmd(info, 0, 0, in flash_real_protect()
1573 flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS); in flash_real_protect()
1574 flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT); in flash_real_protect()
1576 flash_write_cmd(info, sector, 0, in flash_real_protect()
1579 flash_write_cmd(info, sector, 0, in flash_real_protect()
1588 flash_write_cmd(info, sector, 0, FLASH_CMD_READ_STATUS); in flash_real_protect()
1589 retcode = flash_full_status_check(info, sector, info->erase_blk_tout, in flash_real_protect()
1592 info->protect[sector] = prot; in flash_real_protect()
1598 if (prot == 0 && info->legacy_unlock) { in flash_real_protect()
1601 for (i = 0; i < info->sector_count; i++) { in flash_real_protect()
1602 if (info->protect[i]) in flash_real_protect()
1603 flash_real_protect(info, i, 1); in flash_real_protect()
1613 void flash_read_user_serial(flash_info_t *info, void *buffer, int offset, in flash_read_user_serial() argument
1620 src = flash_map(info, 0, FLASH_OFFSET_USER_PROTECTION); in flash_read_user_serial()
1621 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); in flash_read_user_serial()
1623 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_read_user_serial()
1625 flash_unmap(info, 0, FLASH_OFFSET_USER_PROTECTION, src); in flash_read_user_serial()
1631 void flash_read_factory_serial(flash_info_t *info, void *buffer, int offset, in flash_read_factory_serial() argument
1636 src = flash_map(info, 0, FLASH_OFFSET_INTEL_PROTECTION); in flash_read_factory_serial()
1637 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); in flash_read_factory_serial()
1639 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_read_factory_serial()
1641 flash_unmap(info, 0, FLASH_OFFSET_INTEL_PROTECTION, src); in flash_read_factory_serial()
1670 static void cmdset_intel_read_jedec_ids(flash_info_t *info) in cmdset_intel_read_jedec_ids() argument
1672 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in cmdset_intel_read_jedec_ids()
1674 flash_write_cmd(info, 0, 0, FLASH_CMD_READ_ID); in cmdset_intel_read_jedec_ids()
1676 info->manufacturer_id = flash_read_uchar(info, in cmdset_intel_read_jedec_ids()
1678 info->device_id = (info->chipwidth == FLASH_CFI_16BIT) ? in cmdset_intel_read_jedec_ids()
1679 flash_read_word(info, FLASH_OFFSET_DEVICE_ID) : in cmdset_intel_read_jedec_ids()
1680 flash_read_uchar(info, FLASH_OFFSET_DEVICE_ID); in cmdset_intel_read_jedec_ids()
1681 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in cmdset_intel_read_jedec_ids()
1684 static int cmdset_intel_init(flash_info_t *info, struct cfi_qry *qry) in cmdset_intel_init() argument
1686 info->cmd_reset = FLASH_CMD_RESET; in cmdset_intel_init()
1688 cmdset_intel_read_jedec_ids(info); in cmdset_intel_init()
1689 flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); in cmdset_intel_init()
1693 if (info->ext_addr) { in cmdset_intel_init()
1694 info->legacy_unlock = in cmdset_intel_init()
1695 flash_read_uchar(info, info->ext_addr + 5) & 0x08; in cmdset_intel_init()
1702 static void cmdset_amd_read_jedec_ids(flash_info_t *info) in cmdset_amd_read_jedec_ids() argument
1708 flash_write_cmd(info, 0, 0, AMD_CMD_RESET); in cmdset_amd_read_jedec_ids()
1709 flash_unlock_seq(info, 0); in cmdset_amd_read_jedec_ids()
1710 flash_write_cmd(info, 0, info->addr_unlock1, FLASH_CMD_READ_ID); in cmdset_amd_read_jedec_ids()
1713 manu_id = flash_read_uchar(info, FLASH_OFFSET_MANUFACTURER_ID); in cmdset_amd_read_jedec_ids()
1717 manu_id = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1720 info->manufacturer_id = manu_id; in cmdset_amd_read_jedec_ids()
1723 info->ext_addr, info->cfi_version); in cmdset_amd_read_jedec_ids()
1724 if (info->ext_addr && info->cfi_version >= 0x3134) { in cmdset_amd_read_jedec_ids()
1726 feature = flash_read_uchar(info, info->ext_addr + 0x13); in cmdset_amd_read_jedec_ids()
1728 info->sr_supported = feature & 0x1; in cmdset_amd_read_jedec_ids()
1731 switch (info->chipwidth) { in cmdset_amd_read_jedec_ids()
1733 info->device_id = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1735 if (info->device_id == 0x7E) { in cmdset_amd_read_jedec_ids()
1737 info->device_id2 = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1739 info->device_id2 <<= 8; in cmdset_amd_read_jedec_ids()
1740 info->device_id2 |= flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1745 info->device_id = flash_read_word(info, in cmdset_amd_read_jedec_ids()
1747 if ((info->device_id & 0xff) == 0x7E) { in cmdset_amd_read_jedec_ids()
1749 info->device_id2 = flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1751 info->device_id2 <<= 8; in cmdset_amd_read_jedec_ids()
1752 info->device_id2 |= flash_read_uchar(info, in cmdset_amd_read_jedec_ids()
1759 flash_write_cmd(info, 0, 0, AMD_CMD_RESET); in cmdset_amd_read_jedec_ids()
1763 static int cmdset_amd_init(flash_info_t *info, struct cfi_qry *qry) in cmdset_amd_init() argument
1765 info->cmd_reset = AMD_CMD_RESET; in cmdset_amd_init()
1766 info->cmd_erase_sector = AMD_CMD_ERASE_SECTOR; in cmdset_amd_init()
1768 cmdset_amd_read_jedec_ids(info); in cmdset_amd_init()
1769 flash_write_cmd(info, 0, info->cfi_offset, FLASH_CMD_CFI); in cmdset_amd_init()
1772 if (info->ext_addr) { in cmdset_amd_init()
1774 if (flash_read_uchar(info, info->ext_addr + 9) == 0x8) in cmdset_amd_init()
1775 info->legacy_unlock = 1; in cmdset_amd_init()
1783 static void flash_read_jedec_ids(flash_info_t *info) in flash_read_jedec_ids() argument
1785 info->manufacturer_id = 0; in flash_read_jedec_ids()
1786 info->device_id = 0; in flash_read_jedec_ids()
1787 info->device_id2 = 0; in flash_read_jedec_ids()
1789 switch (info->vendor) { in flash_read_jedec_ids()
1793 cmdset_intel_read_jedec_ids(info); in flash_read_jedec_ids()
1797 cmdset_amd_read_jedec_ids(info); in flash_read_jedec_ids()
1811 flash_info_t *info = &flash_info[banknum]; in flash_detect_legacy() local
1813 if (board_flash_get_legacy(base, banknum, info)) { in flash_detect_legacy()
1817 if (!info->vendor) { in flash_detect_legacy()
1825 info->vendor = modes[i]; in flash_detect_legacy()
1826 info->start[0] = in flash_detect_legacy()
1828 info->portwidth, in flash_detect_legacy()
1830 if (info->portwidth == FLASH_CFI_8BIT && in flash_detect_legacy()
1831 info->interface == FLASH_CFI_X8X16) { in flash_detect_legacy()
1832 info->addr_unlock1 = 0x2AAA; in flash_detect_legacy()
1833 info->addr_unlock2 = 0x5555; in flash_detect_legacy()
1835 info->addr_unlock1 = 0x5555; in flash_detect_legacy()
1836 info->addr_unlock2 = 0x2AAA; in flash_detect_legacy()
1838 flash_read_jedec_ids(info); in flash_detect_legacy()
1840 info->manufacturer_id, in flash_detect_legacy()
1841 info->device_id, in flash_detect_legacy()
1842 info->device_id2); in flash_detect_legacy()
1843 if (jedec_flash_match(info, info->start[0])) in flash_detect_legacy()
1846 unmap_physmem((void *)info->start[0], in flash_detect_legacy()
1847 info->portwidth); in flash_detect_legacy()
1851 switch (info->vendor) { in flash_detect_legacy()
1855 info->cmd_reset = FLASH_CMD_RESET; in flash_detect_legacy()
1860 info->cmd_reset = AMD_CMD_RESET; in flash_detect_legacy()
1863 info->flash_id = FLASH_MAN_CFI; in flash_detect_legacy()
1879 static void flash_read_cfi(flash_info_t *info, void *buf, unsigned int start, in flash_read_cfi() argument
1886 p[i] = flash_read_uchar(info, start + i); in flash_read_cfi()
1889 static void __flash_cmd_reset(flash_info_t *info) in __flash_cmd_reset() argument
1896 flash_write_cmd(info, 0, 0, AMD_CMD_RESET); in __flash_cmd_reset()
1898 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in __flash_cmd_reset()
1901 void flash_cmd_reset(flash_info_t *info)
1904 static int __flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) in __flash_detect_cfi() argument
1909 flash_cmd_reset(info); in __flash_detect_cfi()
1913 flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], in __flash_detect_cfi()
1915 if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') && in __flash_detect_cfi()
1916 flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') && in __flash_detect_cfi()
1917 flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) { in __flash_detect_cfi()
1918 flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP, in __flash_detect_cfi()
1920 info->interface = le16_to_cpu(qry->interface_desc); in __flash_detect_cfi()
1922 info->cfi_offset = flash_offset_cfi[cfi_offset]; in __flash_detect_cfi()
1924 info->interface); in __flash_detect_cfi()
1926 info->portwidth, info->chipwidth); in __flash_detect_cfi()
1928 info->portwidth << CFI_FLASH_SHIFT_WIDTH, in __flash_detect_cfi()
1929 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in __flash_detect_cfi()
1932 info->addr_unlock1 = 0x555; in __flash_detect_cfi()
1933 info->addr_unlock2 = 0x2aa; in __flash_detect_cfi()
1940 (info->chipwidth == FLASH_CFI_BY8 && in __flash_detect_cfi()
1941 info->interface == FLASH_CFI_X8X16) || in __flash_detect_cfi()
1943 (info->chipwidth == FLASH_CFI_BY16 && in __flash_detect_cfi()
1944 info->interface == FLASH_CFI_X16X32)) { in __flash_detect_cfi()
1945 info->addr_unlock1 = 0xaaa; in __flash_detect_cfi()
1946 info->addr_unlock2 = 0x555; in __flash_detect_cfi()
1949 info->name = "CFI conformant"; in __flash_detect_cfi()
1957 static int flash_detect_cfi(flash_info_t *info, struct cfi_qry *qry) in flash_detect_cfi() argument
1961 for (info->portwidth = CONFIG_SYS_FLASH_CFI_WIDTH; in flash_detect_cfi()
1962 info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) { in flash_detect_cfi()
1963 for (info->chipwidth = FLASH_CFI_BY8; in flash_detect_cfi()
1964 info->chipwidth <= info->portwidth; in flash_detect_cfi()
1965 info->chipwidth <<= 1) in flash_detect_cfi()
1966 if (__flash_detect_cfi(info, qry)) in flash_detect_cfi()
1977 static void flash_fixup_amd(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_amd() argument
1982 if (info->cfi_version < 0x3131) { in flash_fixup_amd()
1984 if ((info->device_id & 0x80) != 0) in flash_fixup_amd()
1986 } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { in flash_fixup_amd()
1994 static void flash_fixup_atmel(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_atmel() argument
1999 if (info->ext_addr && !(flash_read_uchar(info, info->ext_addr + 6) & 1)) in flash_fixup_atmel()
2006 if (info->device_id == 0xd6 || info->device_id == 0xd2) in flash_fixup_atmel()
2013 static void flash_fixup_stm(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_stm() argument
2018 if (info->cfi_version < 0x3131) { in flash_fixup_stm()
2020 if (info->device_id == 0x22CA || /* M29W320DT */ in flash_fixup_stm()
2021 info->device_id == 0x2256 || /* M29W320ET */ in flash_fixup_stm()
2022 info->device_id == 0x22D7) { /* M29W800DT */ in flash_fixup_stm()
2025 } else if (flash_read_uchar(info, info->ext_addr + 0xf) == 3) { in flash_fixup_stm()
2033 static void flash_fixup_sst(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_sst() argument
2045 if (info->device_id == 0x5D23 || /* SST39VF3201B */ in flash_fixup_sst()
2046 info->device_id == 0x5C23) { /* SST39VF3202B */ in flash_fixup_sst()
2048 info->cmd_erase_sector = 0x50; in flash_fixup_sst()
2052 static void flash_fixup_num(flash_info_t *info, struct cfi_qry *qry) in flash_fixup_num() argument
2061 info->device_id == 0x7E && in flash_fixup_num()
2062 (info->device_id2 == 0x2201 || in flash_fixup_num()
2063 info->device_id2 == 0x2301 || in flash_fixup_num()
2064 info->device_id2 == 0x2801 || in flash_fixup_num()
2065 info->device_id2 == 0x4801)) { in flash_fixup_num()
2078 flash_info_t *info = &flash_info[banknum]; in flash_get_size() local
2092 info->ext_addr = 0; in flash_get_size()
2093 info->cfi_version = 0; in flash_get_size()
2095 info->legacy_unlock = 0; in flash_get_size()
2098 info->start[0] = (ulong)map_physmem(base, info->portwidth, MAP_NOCACHE); in flash_get_size()
2100 if (flash_detect_cfi(info, &qry)) { in flash_get_size()
2101 info->vendor = le16_to_cpu(get_unaligned(&qry.p_id)); in flash_get_size()
2102 info->ext_addr = le16_to_cpu(get_unaligned(&qry.p_adr)); in flash_get_size()
2105 if (info->ext_addr) { in flash_get_size()
2106 info->cfi_version = (ushort)flash_read_uchar(info, in flash_get_size()
2107 info->ext_addr + 3) << 8; in flash_get_size()
2108 info->cfi_version |= (ushort)flash_read_uchar(info, in flash_get_size()
2109 info->ext_addr + 4); in flash_get_size()
2116 switch (info->vendor) { in flash_get_size()
2120 cmdset_intel_init(info, &qry); in flash_get_size()
2124 cmdset_amd_init(info, &qry); in flash_get_size()
2128 info->vendor); in flash_get_size()
2134 flash_write_cmd(info, 0, 0, FLASH_CMD_RESET); in flash_get_size()
2139 switch (info->manufacturer_id) { in flash_get_size()
2142 flash_fixup_amd(info, &qry); in flash_get_size()
2145 flash_fixup_atmel(info, &qry); in flash_get_size()
2148 flash_fixup_stm(info, &qry); in flash_get_size()
2151 flash_fixup_sst(info, &qry); in flash_get_size()
2154 flash_fixup_num(info, &qry); in flash_get_size()
2158 debug("manufacturer is %d\n", info->vendor); in flash_get_size()
2159 debug("manufacturer id is 0x%x\n", info->manufacturer_id); in flash_get_size()
2160 debug("device id is 0x%x\n", info->device_id); in flash_get_size()
2161 debug("device id2 is 0x%x\n", info->device_id2); in flash_get_size()
2162 debug("cfi version is 0x%04x\n", info->cfi_version); in flash_get_size()
2164 size_ratio = info->portwidth / info->chipwidth; in flash_get_size()
2166 if (info->interface == FLASH_CFI_X8X16 && in flash_get_size()
2167 info->chipwidth == FLASH_CFI_BY8) { in flash_get_size()
2171 size_ratio, info->portwidth << CFI_FLASH_SHIFT_WIDTH, in flash_get_size()
2172 info->chipwidth << CFI_FLASH_SHIFT_WIDTH); in flash_get_size()
2173 info->size = 1 << qry.dev_size; in flash_get_size()
2175 info->size *= size_ratio; in flash_get_size()
2177 if (max_size && info->size > max_size) { in flash_get_size()
2178 debug("[truncated from %ldMiB]", info->size >> 20); in flash_get_size()
2179 info->size = max_size; in flash_get_size()
2202 if (sector - base >= info->size) in flash_get_size()
2208 info->start[sect_cnt] = in flash_get_size()
2210 info->portwidth, in flash_get_size()
2218 switch (info->vendor) { in flash_get_size()
2227 flash_write_cmd(info, sect_cnt, 0, in flash_get_size()
2229 info->protect[sect_cnt] = in flash_get_size()
2230 flash_isset(info, sect_cnt, in flash_get_size()
2233 flash_write_cmd(info, sect_cnt, 0, in flash_get_size()
2238 if (!info->legacy_unlock) { in flash_get_size()
2240 info->protect[sect_cnt] = 0; in flash_get_size()
2245 flash_write_cmd(info, 0, 0, in flash_get_size()
2246 info->cmd_reset); in flash_get_size()
2247 flash_unlock_seq(info, 0); in flash_get_size()
2248 flash_write_cmd(info, 0, in flash_get_size()
2249 info->addr_unlock1, in flash_get_size()
2251 info->protect[sect_cnt] = in flash_get_size()
2253 info, sect_cnt, in flash_get_size()
2259 info->protect[sect_cnt] = 0; in flash_get_size()
2266 info->sector_count = sect_cnt; in flash_get_size()
2267 info->buffer_size = 1 << le16_to_cpu(qry.max_buf_write_size); in flash_get_size()
2269 info->erase_blk_tout = tmp * in flash_get_size()
2275 info->buffer_write_tout = (tmp + 999) / 1000; in flash_get_size()
2279 info->write_tout = (tmp + 999) / 1000; in flash_get_size()
2280 info->flash_id = FLASH_MAN_CFI; in flash_get_size()
2281 if (info->interface == FLASH_CFI_X8X16 && in flash_get_size()
2282 info->chipwidth == FLASH_CFI_BY8) { in flash_get_size()
2284 info->portwidth >>= 1; in flash_get_size()
2287 flash_write_cmd(info, 0, 0, info->cmd_reset); in flash_get_size()
2290 return (info->size); in flash_get_size()