Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | Common Flash Interface probe code. |
| 3 | (C) 2000 Red Hat. GPL'd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/module.h> |
| 7 | #include <linux/types.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/byteorder.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | |
| 16 | #include <linux/mtd/xip.h> |
| 17 | #include <linux/mtd/map.h> |
| 18 | #include <linux/mtd/cfi.h> |
| 19 | #include <linux/mtd/gen_probe.h> |
| 20 | |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 21 | //#define DEBUG_CFI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #ifdef DEBUG_CFI |
| 24 | static void print_cfi_ident(struct cfi_ident *); |
| 25 | #endif |
| 26 | |
| 27 | static int cfi_probe_chip(struct map_info *map, __u32 base, |
| 28 | unsigned long *chip_map, struct cfi_private *cfi); |
| 29 | static int cfi_chip_setup(struct map_info *map, struct cfi_private *cfi); |
| 30 | |
| 31 | struct mtd_info *cfi_probe(struct map_info *map); |
| 32 | |
| 33 | #ifdef CONFIG_MTD_XIP |
| 34 | |
| 35 | /* only needed for short periods, so this is rather simple */ |
| 36 | #define xip_disable() local_irq_disable() |
| 37 | |
| 38 | #define xip_allowed(base, map) \ |
| 39 | do { \ |
| 40 | (void) map_read(map, base); \ |
Paulius Zaleckas | ca5c23c | 2008-02-27 01:42:39 +0200 | [diff] [blame] | 41 | xip_iprefetch(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | local_irq_enable(); \ |
| 43 | } while (0) |
| 44 | |
| 45 | #define xip_enable(base, map, cfi) \ |
| 46 | do { \ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 47 | cfi_qry_mode_off(base, map, cfi); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | xip_allowed(base, map); \ |
| 49 | } while (0) |
| 50 | |
| 51 | #define xip_disable_qry(base, map, cfi) \ |
| 52 | do { \ |
| 53 | xip_disable(); \ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 54 | cfi_qry_mode_on(base, map, cfi); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } while (0) |
| 56 | |
| 57 | #else |
| 58 | |
| 59 | #define xip_disable() do { } while (0) |
| 60 | #define xip_allowed(base, map) do { } while (0) |
| 61 | #define xip_enable(base, map, cfi) do { } while (0) |
| 62 | #define xip_disable_qry(base, map, cfi) do { } while (0) |
| 63 | |
| 64 | #endif |
| 65 | |
| 66 | /* check for QRY. |
| 67 | in: interleave,type,mode |
| 68 | ret: table index, <0 for error |
| 69 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | static int __xipram cfi_probe_chip(struct map_info *map, __u32 base, |
| 72 | unsigned long *chip_map, struct cfi_private *cfi) |
| 73 | { |
| 74 | int i; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if ((base + 0) >= map->size) { |
| 77 | printk(KERN_NOTICE |
| 78 | "Probe at base[0x00](0x%08lx) past the end of the map(0x%08lx)\n", |
| 79 | (unsigned long)base, map->size -1); |
| 80 | return 0; |
| 81 | } |
| 82 | if ((base + 0xff) >= map->size) { |
| 83 | printk(KERN_NOTICE |
| 84 | "Probe at base[0x55](0x%08lx) past the end of the map(0x%08lx)\n", |
| 85 | (unsigned long)base + 0x55, map->size -1); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | xip_disable(); |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 90 | if (!cfi_qry_mode_on(base, map, cfi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | xip_enable(base, map, cfi); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | if (!cfi->numchips) { |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 96 | /* This is the first time we're called. Set up the CFI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | stuff accordingly and return */ |
| 98 | return cfi_chip_setup(map, cfi); |
| 99 | } |
| 100 | |
| 101 | /* Check each previous chip to see if it's an alias */ |
| 102 | for (i=0; i < (base >> cfi->chipshift); i++) { |
| 103 | unsigned long start; |
| 104 | if(!test_bit(i, chip_map)) { |
| 105 | /* Skip location; no valid chip at this address */ |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 106 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | start = i << cfi->chipshift; |
| 109 | /* This chip should be in read mode if it's one |
| 110 | we've already touched. */ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 111 | if (cfi_qry_present(map, start, cfi)) { |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 112 | /* Eep. This chip also had the QRY marker. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * Is it an alias for the new one? */ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 114 | cfi_qry_mode_off(start, map, cfi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | /* If the QRY marker goes away, it's an alias */ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 117 | if (!cfi_qry_present(map, start, cfi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | xip_allowed(base, map); |
| 119 | printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", |
| 120 | map->name, base, start); |
| 121 | return 0; |
| 122 | } |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 123 | /* Yes, it's actually got QRY for data. Most |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * unfortunate. Stick the new chip in read mode |
| 125 | * too and if it's the same, assume it's an alias. */ |
| 126 | /* FIXME: Use other modes to do a proper check */ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 127 | cfi_qry_mode_off(base, map, cfi); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 128 | |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 129 | if (cfi_qry_present(map, base, cfi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | xip_allowed(base, map); |
| 131 | printk(KERN_DEBUG "%s: Found an alias at 0x%x for the chip at 0x%lx\n", |
| 132 | map->name, base, start); |
| 133 | return 0; |
| 134 | } |
| 135 | } |
| 136 | } |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* OK, if we got to here, then none of the previous chips appear to |
| 139 | be aliases for the current one. */ |
| 140 | set_bit((base >> cfi->chipshift), chip_map); /* Update chip map */ |
| 141 | cfi->numchips++; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /* Put it back into Read Mode */ |
David Woodhouse | c314dfd | 2008-08-07 11:55:07 +0100 | [diff] [blame] | 144 | cfi_qry_mode_off(base, map, cfi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | xip_allowed(base, map); |
| 146 | |
| 147 | printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", |
| 148 | map->name, cfi->interleave, cfi->device_type*8, base, |
| 149 | map->bankwidth*8); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return 1; |
| 152 | } |
| 153 | |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 154 | static int __xipram cfi_chip_setup(struct map_info *map, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | struct cfi_private *cfi) |
| 156 | { |
| 157 | int ofs_factor = cfi->interleave*cfi->device_type; |
| 158 | __u32 base = 0; |
| 159 | int num_erase_regions = cfi_read_query(map, base + (0x10 + 28)*ofs_factor); |
| 160 | int i; |
Guillaume LECERF | ad7026f | 2010-04-24 17:57:57 +0200 | [diff] [blame^] | 161 | int addr_unlock1 = 0x555, addr_unlock2 = 0x2AA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | xip_enable(base, map, cfi); |
| 164 | #ifdef DEBUG_CFI |
| 165 | printk("Number of erase regions: %d\n", num_erase_regions); |
| 166 | #endif |
| 167 | if (!num_erase_regions) |
| 168 | return 0; |
| 169 | |
| 170 | cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL); |
| 171 | if (!cfi->cfiq) { |
| 172 | printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name); |
| 173 | return 0; |
| 174 | } |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 175 | |
| 176 | memset(cfi->cfiq,0,sizeof(struct cfi_ident)); |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | cfi->cfi_mode = CFI_MODE_CFI; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* Read the CFI info structure */ |
| 181 | xip_disable_qry(base, map, cfi); |
| 182 | for (i=0; i<(sizeof(struct cfi_ident) + num_erase_regions * 4); i++) |
| 183 | ((unsigned char *)cfi->cfiq)[i] = cfi_read_query(map,base + (0x10 + i)*ofs_factor); |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* Do any necessary byteswapping */ |
| 186 | cfi->cfiq->P_ID = le16_to_cpu(cfi->cfiq->P_ID); |
| 187 | |
| 188 | cfi->cfiq->P_ADR = le16_to_cpu(cfi->cfiq->P_ADR); |
| 189 | cfi->cfiq->A_ID = le16_to_cpu(cfi->cfiq->A_ID); |
| 190 | cfi->cfiq->A_ADR = le16_to_cpu(cfi->cfiq->A_ADR); |
| 191 | cfi->cfiq->InterfaceDesc = le16_to_cpu(cfi->cfiq->InterfaceDesc); |
| 192 | cfi->cfiq->MaxBufWriteSize = le16_to_cpu(cfi->cfiq->MaxBufWriteSize); |
| 193 | |
| 194 | #ifdef DEBUG_CFI |
| 195 | /* Dump the information therein */ |
| 196 | print_cfi_ident(cfi->cfiq); |
| 197 | #endif |
| 198 | |
| 199 | for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { |
| 200 | cfi->cfiq->EraseRegionInfo[i] = le32_to_cpu(cfi->cfiq->EraseRegionInfo[i]); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 201 | |
| 202 | #ifdef DEBUG_CFI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | printk(" Erase Region #%d: BlockSize 0x%4.4X bytes, %d blocks\n", |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 204 | i, (cfi->cfiq->EraseRegionInfo[i] >> 8) & ~0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | (cfi->cfiq->EraseRegionInfo[i] & 0xffff) + 1); |
| 206 | #endif |
| 207 | } |
| 208 | |
Guillaume LECERF | 8473044 | 2010-04-24 17:57:52 +0200 | [diff] [blame] | 209 | /* |
| 210 | * Note we put the device back into Read Mode BEFORE going into Auto |
| 211 | * Select Mode, as some devices support nesting of modes, others |
| 212 | * don't. This way should always work. |
| 213 | * On cmdset 0001 the writes of 0xaa and 0x55 are not needed, and |
| 214 | * so should be treated as nops or illegal (and so put the device |
| 215 | * back into Read Mode, which is a nop in this case). |
| 216 | */ |
| 217 | cfi_send_gen_cmd(0xf0, 0, base, map, cfi, cfi->device_type, NULL); |
Guillaume LECERF | ad7026f | 2010-04-24 17:57:57 +0200 | [diff] [blame^] | 218 | cfi_send_gen_cmd(0xaa, addr_unlock1, base, map, cfi, cfi->device_type, NULL); |
| 219 | cfi_send_gen_cmd(0x55, addr_unlock2, base, map, cfi, cfi->device_type, NULL); |
| 220 | cfi_send_gen_cmd(0x90, addr_unlock1, base, map, cfi, cfi->device_type, NULL); |
Guillaume LECERF | 8473044 | 2010-04-24 17:57:52 +0200 | [diff] [blame] | 221 | cfi->mfr = cfi_read_query16(map, base); |
| 222 | cfi->id = cfi_read_query16(map, base + ofs_factor); |
| 223 | |
| 224 | /* Get AMD/Spansion extended JEDEC ID */ |
| 225 | if (cfi->mfr == CFI_MFR_AMD && (cfi->id & 0xff) == 0x7e) |
| 226 | cfi->id = cfi_read_query(map, base + 0xe * ofs_factor) << 8 | |
| 227 | cfi_read_query(map, base + 0xf * ofs_factor); |
| 228 | |
| 229 | /* Put it back into Read Mode */ |
| 230 | cfi_qry_mode_off(base, map, cfi); |
| 231 | xip_allowed(base, map); |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | printk(KERN_INFO "%s: Found %d x%d devices at 0x%x in %d-bit bank\n", |
| 234 | map->name, cfi->interleave, cfi->device_type*8, base, |
| 235 | map->bankwidth*8); |
| 236 | |
| 237 | return 1; |
| 238 | } |
| 239 | |
| 240 | #ifdef DEBUG_CFI |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 241 | static char *vendorname(__u16 vendor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | switch (vendor) { |
| 244 | case P_ID_NONE: |
| 245 | return "None"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | case P_ID_INTEL_EXT: |
| 248 | return "Intel/Sharp Extended"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | case P_ID_AMD_STD: |
| 251 | return "AMD/Fujitsu Standard"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | case P_ID_INTEL_STD: |
| 254 | return "Intel/Sharp Standard"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | case P_ID_AMD_EXT: |
| 257 | return "AMD/Fujitsu Extended"; |
| 258 | |
| 259 | case P_ID_WINBOND: |
| 260 | return "Winbond Standard"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | case P_ID_ST_ADV: |
| 263 | return "ST Advanced"; |
| 264 | |
| 265 | case P_ID_MITSUBISHI_STD: |
| 266 | return "Mitsubishi Standard"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | case P_ID_MITSUBISHI_EXT: |
| 269 | return "Mitsubishi Extended"; |
| 270 | |
| 271 | case P_ID_SST_PAGE: |
| 272 | return "SST Page Write"; |
| 273 | |
| 274 | case P_ID_INTEL_PERFORMANCE: |
| 275 | return "Intel Performance Code"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | case P_ID_INTEL_DATA: |
| 278 | return "Intel Data"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | case P_ID_RESERVED: |
| 281 | return "Not Allowed / Reserved for Future Use"; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | default: |
| 284 | return "Unknown"; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | |
| 289 | static void print_cfi_ident(struct cfi_ident *cfip) |
| 290 | { |
| 291 | #if 0 |
| 292 | if (cfip->qry[0] != 'Q' || cfip->qry[1] != 'R' || cfip->qry[2] != 'Y') { |
| 293 | printk("Invalid CFI ident structure.\n"); |
| 294 | return; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 295 | } |
| 296 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | printk("Primary Vendor Command Set: %4.4X (%s)\n", cfip->P_ID, vendorname(cfip->P_ID)); |
| 298 | if (cfip->P_ADR) |
| 299 | printk("Primary Algorithm Table at %4.4X\n", cfip->P_ADR); |
| 300 | else |
| 301 | printk("No Primary Algorithm Table\n"); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | printk("Alternative Vendor Command Set: %4.4X (%s)\n", cfip->A_ID, vendorname(cfip->A_ID)); |
| 304 | if (cfip->A_ADR) |
| 305 | printk("Alternate Algorithm Table at %4.4X\n", cfip->A_ADR); |
| 306 | else |
| 307 | printk("No Alternate Algorithm Table\n"); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 308 | |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | printk("Vcc Minimum: %2d.%d V\n", cfip->VccMin >> 4, cfip->VccMin & 0xf); |
| 311 | printk("Vcc Maximum: %2d.%d V\n", cfip->VccMax >> 4, cfip->VccMax & 0xf); |
| 312 | if (cfip->VppMin) { |
| 313 | printk("Vpp Minimum: %2d.%d V\n", cfip->VppMin >> 4, cfip->VppMin & 0xf); |
| 314 | printk("Vpp Maximum: %2d.%d V\n", cfip->VppMax >> 4, cfip->VppMax & 0xf); |
| 315 | } |
| 316 | else |
| 317 | printk("No Vpp line\n"); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 318 | |
David Woodhouse | 151e765 | 2006-05-14 01:51:54 +0100 | [diff] [blame] | 319 | printk("Typical byte/word write timeout: %d µs\n", 1<<cfip->WordWriteTimeoutTyp); |
| 320 | printk("Maximum byte/word write timeout: %d µs\n", (1<<cfip->WordWriteTimeoutMax) * (1<<cfip->WordWriteTimeoutTyp)); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (cfip->BufWriteTimeoutTyp || cfip->BufWriteTimeoutMax) { |
David Woodhouse | 151e765 | 2006-05-14 01:51:54 +0100 | [diff] [blame] | 323 | printk("Typical full buffer write timeout: %d µs\n", 1<<cfip->BufWriteTimeoutTyp); |
| 324 | printk("Maximum full buffer write timeout: %d µs\n", (1<<cfip->BufWriteTimeoutMax) * (1<<cfip->BufWriteTimeoutTyp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
| 326 | else |
| 327 | printk("Full buffer write not supported\n"); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | printk("Typical block erase timeout: %d ms\n", 1<<cfip->BlockEraseTimeoutTyp); |
| 330 | printk("Maximum block erase timeout: %d ms\n", (1<<cfip->BlockEraseTimeoutMax) * (1<<cfip->BlockEraseTimeoutTyp)); |
| 331 | if (cfip->ChipEraseTimeoutTyp || cfip->ChipEraseTimeoutMax) { |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 332 | printk("Typical chip erase timeout: %d ms\n", 1<<cfip->ChipEraseTimeoutTyp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | printk("Maximum chip erase timeout: %d ms\n", (1<<cfip->ChipEraseTimeoutMax) * (1<<cfip->ChipEraseTimeoutTyp)); |
| 334 | } |
| 335 | else |
| 336 | printk("Chip erase not supported\n"); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | printk("Device size: 0x%X bytes (%d MiB)\n", 1 << cfip->DevSize, 1<< (cfip->DevSize - 20)); |
| 339 | printk("Flash Device Interface description: 0x%4.4X\n", cfip->InterfaceDesc); |
| 340 | switch(cfip->InterfaceDesc) { |
Bartlomiej Sieka | de7921f | 2007-11-26 18:55:18 +0100 | [diff] [blame] | 341 | case CFI_INTERFACE_X8_ASYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | printk(" - x8-only asynchronous interface\n"); |
| 343 | break; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 344 | |
Bartlomiej Sieka | de7921f | 2007-11-26 18:55:18 +0100 | [diff] [blame] | 345 | case CFI_INTERFACE_X16_ASYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | printk(" - x16-only asynchronous interface\n"); |
| 347 | break; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 348 | |
Bartlomiej Sieka | de7921f | 2007-11-26 18:55:18 +0100 | [diff] [blame] | 349 | case CFI_INTERFACE_X8_BY_X16_ASYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | printk(" - supports x8 and x16 via BYTE# with asynchronous interface\n"); |
| 351 | break; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 352 | |
Bartlomiej Sieka | de7921f | 2007-11-26 18:55:18 +0100 | [diff] [blame] | 353 | case CFI_INTERFACE_X32_ASYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | printk(" - x32-only asynchronous interface\n"); |
| 355 | break; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 356 | |
Bartlomiej Sieka | de7921f | 2007-11-26 18:55:18 +0100 | [diff] [blame] | 357 | case CFI_INTERFACE_X16_BY_X32_ASYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | printk(" - supports x16 and x32 via Word# with asynchronous interface\n"); |
| 359 | break; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 360 | |
Bartlomiej Sieka | de7921f | 2007-11-26 18:55:18 +0100 | [diff] [blame] | 361 | case CFI_INTERFACE_NOT_ALLOWED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | printk(" - Not Allowed / Reserved\n"); |
| 363 | break; |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | default: |
| 366 | printk(" - Unknown\n"); |
| 367 | break; |
| 368 | } |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | printk("Max. bytes in buffer write: 0x%x\n", 1<< cfip->MaxBufWriteSize); |
| 371 | printk("Number of Erase Block Regions: %d\n", cfip->NumEraseRegions); |
Thomas Gleixner | 1f948b4 | 2005-11-07 11:15:37 +0000 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | #endif /* DEBUG_CFI */ |
| 375 | |
| 376 | static struct chip_probe cfi_chip_probe = { |
| 377 | .name = "CFI", |
| 378 | .probe_chip = cfi_probe_chip |
| 379 | }; |
| 380 | |
| 381 | struct mtd_info *cfi_probe(struct map_info *map) |
| 382 | { |
| 383 | /* |
| 384 | * Just use the generic probe stuff to call our CFI-specific |
| 385 | * chip_probe routine in all the possible permutations, etc. |
| 386 | */ |
| 387 | return mtd_do_chip_probe(map, &cfi_chip_probe); |
| 388 | } |
| 389 | |
| 390 | static struct mtd_chip_driver cfi_chipdrv = { |
| 391 | .probe = cfi_probe, |
| 392 | .name = "cfi_probe", |
| 393 | .module = THIS_MODULE |
| 394 | }; |
| 395 | |
Adrian Bunk | 2b9175c | 2005-11-29 14:49:38 +0000 | [diff] [blame] | 396 | static int __init cfi_probe_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
| 398 | register_mtd_chip_driver(&cfi_chipdrv); |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static void __exit cfi_probe_exit(void) |
| 403 | { |
| 404 | unregister_mtd_chip_driver(&cfi_chipdrv); |
| 405 | } |
| 406 | |
| 407 | module_init(cfi_probe_init); |
| 408 | module_exit(cfi_probe_exit); |
| 409 | |
| 410 | MODULE_LICENSE("GPL"); |
| 411 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al."); |
| 412 | MODULE_DESCRIPTION("Probe code for CFI-compliant flash chips"); |