181b20cccSMichael Schwingen /* 281b20cccSMichael Schwingen * (C) Copyright 2007 381b20cccSMichael Schwingen * Michael Schwingen, <michael@schwingen.org> 481b20cccSMichael Schwingen * 581b20cccSMichael Schwingen * based in great part on jedec_probe.c from linux kernel: 681b20cccSMichael Schwingen * (C) 2000 Red Hat. GPL'd. 781b20cccSMichael Schwingen * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com 881b20cccSMichael Schwingen * 9*1a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 1081b20cccSMichael Schwingen */ 1181b20cccSMichael Schwingen 1281b20cccSMichael Schwingen /* The DEBUG define must be before common to enable debugging */ 1381b20cccSMichael Schwingen /*#define DEBUG*/ 1481b20cccSMichael Schwingen 1581b20cccSMichael Schwingen #include <common.h> 1681b20cccSMichael Schwingen #include <asm/processor.h> 1781b20cccSMichael Schwingen #include <asm/io.h> 1881b20cccSMichael Schwingen #include <asm/byteorder.h> 1981b20cccSMichael Schwingen #include <environment.h> 2081b20cccSMichael Schwingen 2181b20cccSMichael Schwingen #define P_ID_AMD_STD CFI_CMDSET_AMD_LEGACY 2281b20cccSMichael Schwingen 2381b20cccSMichael Schwingen /* AMD */ 240192d7d5SStefan Roese #define AM29DL800BB 0x22CB 2581b20cccSMichael Schwingen #define AM29DL800BT 0x224A 2681b20cccSMichael Schwingen 273b8b240dSDavid Müller #define AM29F400BB 0x22AB 2881b20cccSMichael Schwingen #define AM29F800BB 0x2258 2981b20cccSMichael Schwingen #define AM29F800BT 0x22D6 3081b20cccSMichael Schwingen #define AM29LV400BB 0x22BA 3181b20cccSMichael Schwingen #define AM29LV400BT 0x22B9 3281b20cccSMichael Schwingen #define AM29LV800BB 0x225B 3381b20cccSMichael Schwingen #define AM29LV800BT 0x22DA 3481b20cccSMichael Schwingen #define AM29LV160DT 0x22C4 3581b20cccSMichael Schwingen #define AM29LV160DB 0x2249 3681b20cccSMichael Schwingen #define AM29F017D 0x003D 3781b20cccSMichael Schwingen #define AM29F016D 0x00AD 3881b20cccSMichael Schwingen #define AM29F080 0x00D5 3981b20cccSMichael Schwingen #define AM29F040 0x00A4 4081b20cccSMichael Schwingen #define AM29LV040B 0x004F 4181b20cccSMichael Schwingen #define AM29F032B 0x0041 4281b20cccSMichael Schwingen #define AM29F002T 0x00B0 4381b20cccSMichael Schwingen 4481b20cccSMichael Schwingen /* SST */ 4581b20cccSMichael Schwingen #define SST39LF800 0x2781 4681b20cccSMichael Schwingen #define SST39LF160 0x2782 4781b20cccSMichael Schwingen #define SST39VF1601 0x234b 4881b20cccSMichael Schwingen #define SST39LF512 0x00D4 4981b20cccSMichael Schwingen #define SST39LF010 0x00D5 5081b20cccSMichael Schwingen #define SST39LF020 0x00D6 5181b20cccSMichael Schwingen #define SST39LF040 0x00D7 5281b20cccSMichael Schwingen #define SST39SF010A 0x00B5 5381b20cccSMichael Schwingen #define SST39SF020A 0x00B6 5481b20cccSMichael Schwingen 555e72ef08SDavid Müller (ELSOFT AG) /* STM */ 565e72ef08SDavid Müller (ELSOFT AG) #define STM29F400BB 0x00D6 575e72ef08SDavid Müller (ELSOFT AG) 583a7b2c21SNiklaus Giger /* MXIC */ 593a7b2c21SNiklaus Giger #define MX29LV040 0x004F 603a7b2c21SNiklaus Giger 613a7b2c21SNiklaus Giger /* WINBOND */ 623a7b2c21SNiklaus Giger #define W39L040A 0x00D6 633a7b2c21SNiklaus Giger 643a7b2c21SNiklaus Giger /* AMIC */ 653a7b2c21SNiklaus Giger #define A29L040 0x0092 663a7b2c21SNiklaus Giger 673a7b2c21SNiklaus Giger /* EON */ 683a7b2c21SNiklaus Giger #define EN29LV040A 0x004F 6981b20cccSMichael Schwingen 7081b20cccSMichael Schwingen /* 7181b20cccSMichael Schwingen * Unlock address sets for AMD command sets. 7281b20cccSMichael Schwingen * Intel command sets use the MTD_UADDR_UNNECESSARY. 7381b20cccSMichael Schwingen * Each identifier, except MTD_UADDR_UNNECESSARY, and 7481b20cccSMichael Schwingen * MTD_UADDR_NO_SUPPORT must be defined below in unlock_addrs[]. 7581b20cccSMichael Schwingen * MTD_UADDR_NOT_SUPPORTED must be 0 so that structure 7681b20cccSMichael Schwingen * initialization need not require initializing all of the 7781b20cccSMichael Schwingen * unlock addresses for all bit widths. 7881b20cccSMichael Schwingen */ 7981b20cccSMichael Schwingen enum uaddr { 8081b20cccSMichael Schwingen MTD_UADDR_NOT_SUPPORTED = 0, /* data width not supported */ 8181b20cccSMichael Schwingen MTD_UADDR_0x0555_0x02AA, 8281b20cccSMichael Schwingen MTD_UADDR_0x0555_0x0AAA, 8381b20cccSMichael Schwingen MTD_UADDR_0x5555_0x2AAA, 8481b20cccSMichael Schwingen MTD_UADDR_0x0AAA_0x0555, 8581b20cccSMichael Schwingen MTD_UADDR_DONT_CARE, /* Requires an arbitrary address */ 8681b20cccSMichael Schwingen MTD_UADDR_UNNECESSARY, /* Does not require any address */ 8781b20cccSMichael Schwingen }; 8881b20cccSMichael Schwingen 8981b20cccSMichael Schwingen 9081b20cccSMichael Schwingen struct unlock_addr { 9181b20cccSMichael Schwingen u32 addr1; 9281b20cccSMichael Schwingen u32 addr2; 9381b20cccSMichael Schwingen }; 9481b20cccSMichael Schwingen 9581b20cccSMichael Schwingen 9681b20cccSMichael Schwingen /* 9781b20cccSMichael Schwingen * I don't like the fact that the first entry in unlock_addrs[] 9881b20cccSMichael Schwingen * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore, 9981b20cccSMichael Schwingen * should not be used. The problem is that structures with 10081b20cccSMichael Schwingen * initializers have extra fields initialized to 0. It is _very_ 10181b20cccSMichael Schwingen * desireable to have the unlock address entries for unsupported 10281b20cccSMichael Schwingen * data widths automatically initialized - that means that 10381b20cccSMichael Schwingen * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here 10481b20cccSMichael Schwingen * must go unused. 10581b20cccSMichael Schwingen */ 10681b20cccSMichael Schwingen static const struct unlock_addr unlock_addrs[] = { 10781b20cccSMichael Schwingen [MTD_UADDR_NOT_SUPPORTED] = { 10881b20cccSMichael Schwingen .addr1 = 0xffff, 10981b20cccSMichael Schwingen .addr2 = 0xffff 11081b20cccSMichael Schwingen }, 11181b20cccSMichael Schwingen 11281b20cccSMichael Schwingen [MTD_UADDR_0x0555_0x02AA] = { 11381b20cccSMichael Schwingen .addr1 = 0x0555, 11481b20cccSMichael Schwingen .addr2 = 0x02aa 11581b20cccSMichael Schwingen }, 11681b20cccSMichael Schwingen 11781b20cccSMichael Schwingen [MTD_UADDR_0x0555_0x0AAA] = { 11881b20cccSMichael Schwingen .addr1 = 0x0555, 11981b20cccSMichael Schwingen .addr2 = 0x0aaa 12081b20cccSMichael Schwingen }, 12181b20cccSMichael Schwingen 12281b20cccSMichael Schwingen [MTD_UADDR_0x5555_0x2AAA] = { 12381b20cccSMichael Schwingen .addr1 = 0x5555, 12481b20cccSMichael Schwingen .addr2 = 0x2aaa 12581b20cccSMichael Schwingen }, 12681b20cccSMichael Schwingen 12781b20cccSMichael Schwingen [MTD_UADDR_0x0AAA_0x0555] = { 12881b20cccSMichael Schwingen .addr1 = 0x0AAA, 12981b20cccSMichael Schwingen .addr2 = 0x0555 13081b20cccSMichael Schwingen }, 13181b20cccSMichael Schwingen 13281b20cccSMichael Schwingen [MTD_UADDR_DONT_CARE] = { 13381b20cccSMichael Schwingen .addr1 = 0x0000, /* Doesn't matter which address */ 13481b20cccSMichael Schwingen .addr2 = 0x0000 /* is used - must be last entry */ 13581b20cccSMichael Schwingen }, 13681b20cccSMichael Schwingen 13781b20cccSMichael Schwingen [MTD_UADDR_UNNECESSARY] = { 13881b20cccSMichael Schwingen .addr1 = 0x0000, 13981b20cccSMichael Schwingen .addr2 = 0x0000 14081b20cccSMichael Schwingen } 14181b20cccSMichael Schwingen }; 14281b20cccSMichael Schwingen 14381b20cccSMichael Schwingen 14481b20cccSMichael Schwingen struct amd_flash_info { 14581b20cccSMichael Schwingen const __u16 mfr_id; 14681b20cccSMichael Schwingen const __u16 dev_id; 14781b20cccSMichael Schwingen const char *name; 14881b20cccSMichael Schwingen const int DevSize; 14981b20cccSMichael Schwingen const int NumEraseRegions; 15081b20cccSMichael Schwingen const int CmdSet; 15181b20cccSMichael Schwingen const __u8 uaddr[4]; /* unlock addrs for 8, 16, 32, 64 */ 15281b20cccSMichael Schwingen const ulong regions[6]; 15381b20cccSMichael Schwingen }; 15481b20cccSMichael Schwingen 15581b20cccSMichael Schwingen #define ERASEINFO(size,blocks) (size<<8)|(blocks-1) 15681b20cccSMichael Schwingen 15781b20cccSMichael Schwingen #define SIZE_64KiB 16 15881b20cccSMichael Schwingen #define SIZE_128KiB 17 15981b20cccSMichael Schwingen #define SIZE_256KiB 18 16081b20cccSMichael Schwingen #define SIZE_512KiB 19 16181b20cccSMichael Schwingen #define SIZE_1MiB 20 16281b20cccSMichael Schwingen #define SIZE_2MiB 21 16381b20cccSMichael Schwingen #define SIZE_4MiB 22 16481b20cccSMichael Schwingen #define SIZE_8MiB 23 16581b20cccSMichael Schwingen 16681b20cccSMichael Schwingen static const struct amd_flash_info jedec_table[] = { 1676d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FLASH_LEGACY_256Kx8 16881b20cccSMichael Schwingen { 16928745db9SStefan Roese .mfr_id = (u16)SST_MANUFACT, 17081b20cccSMichael Schwingen .dev_id = SST39LF020, 17181b20cccSMichael Schwingen .name = "SST 39LF020", 17281b20cccSMichael Schwingen .uaddr = { 17381b20cccSMichael Schwingen [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */ 17481b20cccSMichael Schwingen }, 17581b20cccSMichael Schwingen .DevSize = SIZE_256KiB, 17681b20cccSMichael Schwingen .CmdSet = P_ID_AMD_STD, 17781b20cccSMichael Schwingen .NumEraseRegions= 1, 17881b20cccSMichael Schwingen .regions = { 17981b20cccSMichael Schwingen ERASEINFO(0x01000,64), 18081b20cccSMichael Schwingen } 18181b20cccSMichael Schwingen }, 18281b20cccSMichael Schwingen #endif 1836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FLASH_LEGACY_512Kx8 18481b20cccSMichael Schwingen { 18528745db9SStefan Roese .mfr_id = (u16)AMD_MANUFACT, 18681b20cccSMichael Schwingen .dev_id = AM29LV040B, 18781b20cccSMichael Schwingen .name = "AMD AM29LV040B", 18881b20cccSMichael Schwingen .uaddr = { 18981b20cccSMichael Schwingen [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ 19081b20cccSMichael Schwingen }, 19181b20cccSMichael Schwingen .DevSize = SIZE_512KiB, 19281b20cccSMichael Schwingen .CmdSet = P_ID_AMD_STD, 19381b20cccSMichael Schwingen .NumEraseRegions= 1, 19481b20cccSMichael Schwingen .regions = { 19581b20cccSMichael Schwingen ERASEINFO(0x10000,8), 19681b20cccSMichael Schwingen } 19781b20cccSMichael Schwingen }, 19881b20cccSMichael Schwingen { 19928745db9SStefan Roese .mfr_id = (u16)SST_MANUFACT, 20081b20cccSMichael Schwingen .dev_id = SST39LF040, 20181b20cccSMichael Schwingen .name = "SST 39LF040", 20281b20cccSMichael Schwingen .uaddr = { 20381b20cccSMichael Schwingen [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */ 20481b20cccSMichael Schwingen }, 20581b20cccSMichael Schwingen .DevSize = SIZE_512KiB, 20681b20cccSMichael Schwingen .CmdSet = P_ID_AMD_STD, 20781b20cccSMichael Schwingen .NumEraseRegions= 1, 20881b20cccSMichael Schwingen .regions = { 20981b20cccSMichael Schwingen ERASEINFO(0x01000,128), 21081b20cccSMichael Schwingen } 21181b20cccSMichael Schwingen }, 21294f9279fSNiklaus Giger { 21328745db9SStefan Roese .mfr_id = (u16)STM_MANUFACT, 21494f9279fSNiklaus Giger .dev_id = STM_ID_M29W040B, 21594f9279fSNiklaus Giger .name = "ST Micro M29W040B", 21694f9279fSNiklaus Giger .uaddr = { 21794f9279fSNiklaus Giger [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ 21894f9279fSNiklaus Giger }, 21994f9279fSNiklaus Giger .DevSize = SIZE_512KiB, 22094f9279fSNiklaus Giger .CmdSet = P_ID_AMD_STD, 22194f9279fSNiklaus Giger .NumEraseRegions= 1, 22294f9279fSNiklaus Giger .regions = { 22394f9279fSNiklaus Giger ERASEINFO(0x10000,8), 22494f9279fSNiklaus Giger } 22594f9279fSNiklaus Giger }, 2263a7b2c21SNiklaus Giger { 2273a7b2c21SNiklaus Giger .mfr_id = (u16)MX_MANUFACT, 2283a7b2c21SNiklaus Giger .dev_id = MX29LV040, 2293a7b2c21SNiklaus Giger .name = "MXIC MX29LV040", 2303a7b2c21SNiklaus Giger .uaddr = { 2313a7b2c21SNiklaus Giger [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ 2323a7b2c21SNiklaus Giger }, 2333a7b2c21SNiklaus Giger .DevSize = SIZE_512KiB, 2343a7b2c21SNiklaus Giger .CmdSet = P_ID_AMD_STD, 2353a7b2c21SNiklaus Giger .NumEraseRegions= 1, 2363a7b2c21SNiklaus Giger .regions = { 2373a7b2c21SNiklaus Giger ERASEINFO(0x10000, 8), 2383a7b2c21SNiklaus Giger } 2393a7b2c21SNiklaus Giger }, 2403a7b2c21SNiklaus Giger { 2413a7b2c21SNiklaus Giger .mfr_id = (u16)WINB_MANUFACT, 2423a7b2c21SNiklaus Giger .dev_id = W39L040A, 2433a7b2c21SNiklaus Giger .name = "WINBOND W39L040A", 2443a7b2c21SNiklaus Giger .uaddr = { 2453a7b2c21SNiklaus Giger [0] = MTD_UADDR_0x5555_0x2AAA /* x8 */ 2463a7b2c21SNiklaus Giger }, 2473a7b2c21SNiklaus Giger .DevSize = SIZE_512KiB, 2483a7b2c21SNiklaus Giger .CmdSet = P_ID_AMD_STD, 2493a7b2c21SNiklaus Giger .NumEraseRegions= 1, 2503a7b2c21SNiklaus Giger .regions = { 2513a7b2c21SNiklaus Giger ERASEINFO(0x10000, 8), 2523a7b2c21SNiklaus Giger } 2533a7b2c21SNiklaus Giger }, 2543a7b2c21SNiklaus Giger { 2553a7b2c21SNiklaus Giger .mfr_id = (u16)AMIC_MANUFACT, 2563a7b2c21SNiklaus Giger .dev_id = A29L040, 2573a7b2c21SNiklaus Giger .name = "AMIC A29L040", 2583a7b2c21SNiklaus Giger .uaddr = { 2593a7b2c21SNiklaus Giger [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ 2603a7b2c21SNiklaus Giger }, 2613a7b2c21SNiklaus Giger .DevSize = SIZE_512KiB, 2623a7b2c21SNiklaus Giger .CmdSet = P_ID_AMD_STD, 2633a7b2c21SNiklaus Giger .NumEraseRegions= 1, 2643a7b2c21SNiklaus Giger .regions = { 2653a7b2c21SNiklaus Giger ERASEINFO(0x10000, 8), 2663a7b2c21SNiklaus Giger } 2673a7b2c21SNiklaus Giger }, 2683a7b2c21SNiklaus Giger { 2693a7b2c21SNiklaus Giger .mfr_id = (u16)EON_MANUFACT, 2703a7b2c21SNiklaus Giger .dev_id = EN29LV040A, 2713a7b2c21SNiklaus Giger .name = "EON EN29LV040A", 2723a7b2c21SNiklaus Giger .uaddr = { 2733a7b2c21SNiklaus Giger [0] = MTD_UADDR_0x0555_0x02AA /* x8 */ 2743a7b2c21SNiklaus Giger }, 2753a7b2c21SNiklaus Giger .DevSize = SIZE_512KiB, 2763a7b2c21SNiklaus Giger .CmdSet = P_ID_AMD_STD, 2773a7b2c21SNiklaus Giger .NumEraseRegions= 1, 2783a7b2c21SNiklaus Giger .regions = { 2793a7b2c21SNiklaus Giger ERASEINFO(0x10000, 8), 2803a7b2c21SNiklaus Giger } 2813a7b2c21SNiklaus Giger }, 28281b20cccSMichael Schwingen #endif 2836d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_FLASH_LEGACY_512Kx16 28490447ecbSTor Krill { 28528745db9SStefan Roese .mfr_id = (u16)AMD_MANUFACT, 2863b8b240dSDavid Müller .dev_id = AM29F400BB, 2873b8b240dSDavid Müller .name = "AMD AM29F400BB", 2883b8b240dSDavid Müller .uaddr = { 2893b8b240dSDavid Müller [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ 2903b8b240dSDavid Müller }, 2913b8b240dSDavid Müller .DevSize = SIZE_512KiB, 2923b8b240dSDavid Müller .CmdSet = CFI_CMDSET_AMD_LEGACY, 2933b8b240dSDavid Müller .NumEraseRegions= 4, 2943b8b240dSDavid Müller .regions = { 2953b8b240dSDavid Müller ERASEINFO(0x04000, 1), 2963b8b240dSDavid Müller ERASEINFO(0x02000, 2), 2973b8b240dSDavid Müller ERASEINFO(0x08000, 1), 2983b8b240dSDavid Müller ERASEINFO(0x10000, 7), 2993b8b240dSDavid Müller } 3003b8b240dSDavid Müller }, 3013b8b240dSDavid Müller { 3023b8b240dSDavid Müller .mfr_id = (u16)AMD_MANUFACT, 30390447ecbSTor Krill .dev_id = AM29LV400BB, 30490447ecbSTor Krill .name = "AMD AM29LV400BB", 30590447ecbSTor Krill .uaddr = { 30690447ecbSTor Krill [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ 30790447ecbSTor Krill }, 30890447ecbSTor Krill .DevSize = SIZE_512KiB, 30990447ecbSTor Krill .CmdSet = CFI_CMDSET_AMD_LEGACY, 31090447ecbSTor Krill .NumEraseRegions= 4, 31190447ecbSTor Krill .regions = { 31290447ecbSTor Krill ERASEINFO(0x04000,1), 31390447ecbSTor Krill ERASEINFO(0x02000,2), 31490447ecbSTor Krill ERASEINFO(0x08000,1), 31590447ecbSTor Krill ERASEINFO(0x10000,7), 31690447ecbSTor Krill } 31790447ecbSTor Krill }, 3187949839eSGuennadi Liakhovetski { 31928745db9SStefan Roese .mfr_id = (u16)AMD_MANUFACT, 3207949839eSGuennadi Liakhovetski .dev_id = AM29LV800BB, 3217949839eSGuennadi Liakhovetski .name = "AMD AM29LV800BB", 3227949839eSGuennadi Liakhovetski .uaddr = { 3237949839eSGuennadi Liakhovetski [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ 3247949839eSGuennadi Liakhovetski }, 3257949839eSGuennadi Liakhovetski .DevSize = SIZE_1MiB, 3267949839eSGuennadi Liakhovetski .CmdSet = CFI_CMDSET_AMD_LEGACY, 3277949839eSGuennadi Liakhovetski .NumEraseRegions= 4, 3287949839eSGuennadi Liakhovetski .regions = { 3297949839eSGuennadi Liakhovetski ERASEINFO(0x04000, 1), 3307949839eSGuennadi Liakhovetski ERASEINFO(0x02000, 2), 3317949839eSGuennadi Liakhovetski ERASEINFO(0x08000, 1), 3327949839eSGuennadi Liakhovetski ERASEINFO(0x10000, 15), 3337949839eSGuennadi Liakhovetski } 3347949839eSGuennadi Liakhovetski }, 3355e72ef08SDavid Müller (ELSOFT AG) { 3365e72ef08SDavid Müller (ELSOFT AG) .mfr_id = (u16)STM_MANUFACT, 3375e72ef08SDavid Müller (ELSOFT AG) .dev_id = STM29F400BB, 3385e72ef08SDavid Müller (ELSOFT AG) .name = "ST Micro M29F400BB", 3395e72ef08SDavid Müller (ELSOFT AG) .uaddr = { 3405e72ef08SDavid Müller (ELSOFT AG) [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ 3415e72ef08SDavid Müller (ELSOFT AG) }, 3425e72ef08SDavid Müller (ELSOFT AG) .DevSize = SIZE_512KiB, 3435e72ef08SDavid Müller (ELSOFT AG) .CmdSet = CFI_CMDSET_AMD_LEGACY, 3445e72ef08SDavid Müller (ELSOFT AG) .NumEraseRegions = 4, 3455e72ef08SDavid Müller (ELSOFT AG) .regions = { 3465e72ef08SDavid Müller (ELSOFT AG) ERASEINFO(0x04000, 1), 3475e72ef08SDavid Müller (ELSOFT AG) ERASEINFO(0x02000, 2), 3485e72ef08SDavid Müller (ELSOFT AG) ERASEINFO(0x08000, 1), 3495e72ef08SDavid Müller (ELSOFT AG) ERASEINFO(0x10000, 7), 3505e72ef08SDavid Müller (ELSOFT AG) } 3515e72ef08SDavid Müller (ELSOFT AG) }, 35290447ecbSTor Krill #endif 35381b20cccSMichael Schwingen }; 35481b20cccSMichael Schwingen 35581b20cccSMichael Schwingen static inline void fill_info(flash_info_t *info, const struct amd_flash_info *jedec_entry, ulong base) 35681b20cccSMichael Schwingen { 35781b20cccSMichael Schwingen int i,j; 35881b20cccSMichael Schwingen int sect_cnt; 35981b20cccSMichael Schwingen int size_ratio; 36081b20cccSMichael Schwingen int total_size; 36181b20cccSMichael Schwingen enum uaddr uaddr_idx; 36281b20cccSMichael Schwingen 36381b20cccSMichael Schwingen size_ratio = info->portwidth / info->chipwidth; 36481b20cccSMichael Schwingen 36581b20cccSMichael Schwingen debug("Found JEDEC Flash: %s\n", jedec_entry->name); 36681b20cccSMichael Schwingen info->vendor = jedec_entry->CmdSet; 36781b20cccSMichael Schwingen /* Todo: do we need device-specific timeouts? */ 36881b20cccSMichael Schwingen info->erase_blk_tout = 30000; 36981b20cccSMichael Schwingen info->buffer_write_tout = 1000; 37081b20cccSMichael Schwingen info->write_tout = 100; 37181b20cccSMichael Schwingen info->name = jedec_entry->name; 37281b20cccSMichael Schwingen 37381b20cccSMichael Schwingen /* copy unlock addresses from device table to CFI info struct. This 37481b20cccSMichael Schwingen is just here because the addresses are in the table anyway - if 37581b20cccSMichael Schwingen the flash is not detected due to wrong unlock addresses, 37681b20cccSMichael Schwingen flash_detect_legacy would have to try all of them before we even 37781b20cccSMichael Schwingen get here. */ 37881b20cccSMichael Schwingen switch(info->chipwidth) { 37981b20cccSMichael Schwingen case FLASH_CFI_8BIT: 38081b20cccSMichael Schwingen uaddr_idx = jedec_entry->uaddr[0]; 38181b20cccSMichael Schwingen break; 38281b20cccSMichael Schwingen case FLASH_CFI_16BIT: 38381b20cccSMichael Schwingen uaddr_idx = jedec_entry->uaddr[1]; 38481b20cccSMichael Schwingen break; 38581b20cccSMichael Schwingen case FLASH_CFI_32BIT: 38681b20cccSMichael Schwingen uaddr_idx = jedec_entry->uaddr[2]; 38781b20cccSMichael Schwingen break; 38881b20cccSMichael Schwingen default: 38981b20cccSMichael Schwingen uaddr_idx = MTD_UADDR_NOT_SUPPORTED; 39081b20cccSMichael Schwingen break; 39181b20cccSMichael Schwingen } 39281b20cccSMichael Schwingen 39381b20cccSMichael Schwingen debug("unlock address index %d\n", uaddr_idx); 39481b20cccSMichael Schwingen info->addr_unlock1 = unlock_addrs[uaddr_idx].addr1; 39581b20cccSMichael Schwingen info->addr_unlock2 = unlock_addrs[uaddr_idx].addr2; 396f382b7c5SMarek Vasut debug("unlock addresses are 0x%lx/0x%lx\n", 397f382b7c5SMarek Vasut info->addr_unlock1, info->addr_unlock2); 39881b20cccSMichael Schwingen 39981b20cccSMichael Schwingen sect_cnt = 0; 40081b20cccSMichael Schwingen total_size = 0; 40181b20cccSMichael Schwingen for (i = 0; i < jedec_entry->NumEraseRegions; i++) { 40281b20cccSMichael Schwingen ulong erase_region_size = jedec_entry->regions[i] >> 8; 40381b20cccSMichael Schwingen ulong erase_region_count = (jedec_entry->regions[i] & 0xff) + 1; 40481b20cccSMichael Schwingen 40581b20cccSMichael Schwingen total_size += erase_region_size * erase_region_count; 406f382b7c5SMarek Vasut debug("erase_region_count = %ld erase_region_size = %ld\n", 40781b20cccSMichael Schwingen erase_region_count, erase_region_size); 40881b20cccSMichael Schwingen for (j = 0; j < erase_region_count; j++) { 4096d0f6bcfSJean-Christophe PLAGNIOL-VILLARD if (sect_cnt >= CONFIG_SYS_MAX_FLASH_SECT) { 41081b20cccSMichael Schwingen printf("ERROR: too many flash sectors\n"); 41181b20cccSMichael Schwingen break; 41281b20cccSMichael Schwingen } 41381b20cccSMichael Schwingen info->start[sect_cnt] = base; 41481b20cccSMichael Schwingen base += (erase_region_size * size_ratio); 41581b20cccSMichael Schwingen sect_cnt++; 41681b20cccSMichael Schwingen } 41781b20cccSMichael Schwingen } 41881b20cccSMichael Schwingen info->sector_count = sect_cnt; 41981b20cccSMichael Schwingen info->size = total_size * size_ratio; 42081b20cccSMichael Schwingen } 42181b20cccSMichael Schwingen 42281b20cccSMichael Schwingen /*----------------------------------------------------------------------- 42381b20cccSMichael Schwingen * match jedec ids against table. If a match is found, fill flash_info entry 42481b20cccSMichael Schwingen */ 42581b20cccSMichael Schwingen int jedec_flash_match(flash_info_t *info, ulong base) 42681b20cccSMichael Schwingen { 42781b20cccSMichael Schwingen int ret = 0; 42881b20cccSMichael Schwingen int i; 42981b20cccSMichael Schwingen ulong mask = 0xFFFF; 43081b20cccSMichael Schwingen if (info->chipwidth == 1) 43181b20cccSMichael Schwingen mask = 0xFF; 43281b20cccSMichael Schwingen 43381b20cccSMichael Schwingen for (i = 0; i < ARRAY_SIZE(jedec_table); i++) { 43481b20cccSMichael Schwingen if ((jedec_table[i].mfr_id & mask) == (info->manufacturer_id & mask) && 43581b20cccSMichael Schwingen (jedec_table[i].dev_id & mask) == (info->device_id & mask)) { 43681b20cccSMichael Schwingen fill_info(info, &jedec_table[i], base); 43781b20cccSMichael Schwingen ret = 1; 43881b20cccSMichael Schwingen break; 43981b20cccSMichael Schwingen } 44081b20cccSMichael Schwingen } 44181b20cccSMichael Schwingen return ret; 44281b20cccSMichael Schwingen } 443