diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-16 13:23:43 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-16 13:23:43 -0500 |
commit | 60d9aa758c00f20ade0cb1951f6a934f628dd2d7 (patch) | |
tree | e3bdfa4ec0d3f9a29a822810b8b9188c7d613cbd /drivers/mtd/devices/m25p80.c | |
parent | b2adf0cbec4cf0934c63f48f893e0cebde380d0c (diff) | |
parent | 2e16cfca6e17ae37ae21feca080a6f2eca9087dc (diff) |
Merge git://git.infradead.org/mtd-2.6
* git://git.infradead.org/mtd-2.6: (90 commits)
jffs2: Fix long-standing bug with symlink garbage collection.
mtd: OneNAND: Fix test of unsigned in onenand_otp_walk()
mtd: cfi_cmdset_0002, fix lock imbalance
Revert "mtd: move mxcnd_remove to .exit.text"
mtd: m25p80: add support for Macronix MX25L4005A
kmsg_dump: fix build for CONFIG_PRINTK=n
mtd: nandsim: add support for 4KiB pages
mtd: mtdoops: refactor as a kmsg_dumper
mtd: mtdoops: make record size configurable
mtd: mtdoops: limit the maximum mtd partition size
mtd: mtdoops: keep track of used/unused pages in an array
mtd: mtdoops: several minor cleanups
core: Add kernel message dumper to call on oopses and panics
mtd: add ARM pismo support
mtd: pxa3xx_nand: Fix PIO data transfer
mtd: nand: fix multi-chip suspend problem
mtd: add support for switching old SST chips into QRY mode
mtd: fix M29W800D dev_id and uaddr
mtd: don't use PF_MEMALLOC
mtd: Add bad block table overrides to Davinci NAND driver
...
Fixed up conflicts (mostly trivial) in
drivers/mtd/devices/m25p80.c
drivers/mtd/maps/pcmciamtd.c
drivers/mtd/nand/pxa3xx_nand.c
kernel/printk.c
Diffstat (limited to 'drivers/mtd/devices/m25p80.c')
-rw-r--r-- | drivers/mtd/devices/m25p80.c | 334 |
1 files changed, 196 insertions, 138 deletions
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 4c19269de91a..f3f4768d6e18 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
23 | #include <linux/math64.h> | 23 | #include <linux/math64.h> |
24 | #include <linux/sched.h> | 24 | #include <linux/sched.h> |
25 | #include <linux/mod_devicetable.h> | ||
25 | 26 | ||
26 | #include <linux/mtd/mtd.h> | 27 | #include <linux/mtd/mtd.h> |
27 | #include <linux/mtd/partitions.h> | 28 | #include <linux/mtd/partitions.h> |
@@ -29,9 +30,6 @@ | |||
29 | #include <linux/spi/spi.h> | 30 | #include <linux/spi/spi.h> |
30 | #include <linux/spi/flash.h> | 31 | #include <linux/spi/flash.h> |
31 | 32 | ||
32 | |||
33 | #define FLASH_PAGESIZE 256 | ||
34 | |||
35 | /* Flash opcodes. */ | 33 | /* Flash opcodes. */ |
36 | #define OPCODE_WREN 0x06 /* Write enable */ | 34 | #define OPCODE_WREN 0x06 /* Write enable */ |
37 | #define OPCODE_RDSR 0x05 /* Read status register */ | 35 | #define OPCODE_RDSR 0x05 /* Read status register */ |
@@ -61,7 +59,7 @@ | |||
61 | 59 | ||
62 | /* Define max times to check status register before we give up. */ | 60 | /* Define max times to check status register before we give up. */ |
63 | #define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */ | 61 | #define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */ |
64 | #define CMD_SIZE 4 | 62 | #define MAX_CMD_SIZE 4 |
65 | 63 | ||
66 | #ifdef CONFIG_M25PXX_USE_FAST_READ | 64 | #ifdef CONFIG_M25PXX_USE_FAST_READ |
67 | #define OPCODE_READ OPCODE_FAST_READ | 65 | #define OPCODE_READ OPCODE_FAST_READ |
@@ -78,8 +76,10 @@ struct m25p { | |||
78 | struct mutex lock; | 76 | struct mutex lock; |
79 | struct mtd_info mtd; | 77 | struct mtd_info mtd; |
80 | unsigned partitioned:1; | 78 | unsigned partitioned:1; |
79 | u16 page_size; | ||
80 | u16 addr_width; | ||
81 | u8 erase_opcode; | 81 | u8 erase_opcode; |
82 | u8 command[CMD_SIZE + FAST_READ_DUMMY_BYTE]; | 82 | u8 *command; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) | 85 | static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) |
@@ -198,6 +198,19 @@ static int erase_chip(struct m25p *flash) | |||
198 | return 0; | 198 | return 0; |
199 | } | 199 | } |
200 | 200 | ||
201 | static void m25p_addr2cmd(struct m25p *flash, unsigned int addr, u8 *cmd) | ||
202 | { | ||
203 | /* opcode is in cmd[0] */ | ||
204 | cmd[1] = addr >> (flash->addr_width * 8 - 8); | ||
205 | cmd[2] = addr >> (flash->addr_width * 8 - 16); | ||
206 | cmd[3] = addr >> (flash->addr_width * 8 - 24); | ||
207 | } | ||
208 | |||
209 | static int m25p_cmdsz(struct m25p *flash) | ||
210 | { | ||
211 | return 1 + flash->addr_width; | ||
212 | } | ||
213 | |||
201 | /* | 214 | /* |
202 | * Erase one sector of flash memory at offset ``offset'' which is any | 215 | * Erase one sector of flash memory at offset ``offset'' which is any |
203 | * address within the sector which should be erased. | 216 | * address within the sector which should be erased. |
@@ -219,11 +232,9 @@ static int erase_sector(struct m25p *flash, u32 offset) | |||
219 | 232 | ||
220 | /* Set up command buffer. */ | 233 | /* Set up command buffer. */ |
221 | flash->command[0] = flash->erase_opcode; | 234 | flash->command[0] = flash->erase_opcode; |
222 | flash->command[1] = offset >> 16; | 235 | m25p_addr2cmd(flash, offset, flash->command); |
223 | flash->command[2] = offset >> 8; | ||
224 | flash->command[3] = offset; | ||
225 | 236 | ||
226 | spi_write(flash->spi, flash->command, CMD_SIZE); | 237 | spi_write(flash->spi, flash->command, m25p_cmdsz(flash)); |
227 | 238 | ||
228 | return 0; | 239 | return 0; |
229 | } | 240 | } |
@@ -325,7 +336,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
325 | * Should add 1 byte DUMMY_BYTE. | 336 | * Should add 1 byte DUMMY_BYTE. |
326 | */ | 337 | */ |
327 | t[0].tx_buf = flash->command; | 338 | t[0].tx_buf = flash->command; |
328 | t[0].len = CMD_SIZE + FAST_READ_DUMMY_BYTE; | 339 | t[0].len = m25p_cmdsz(flash) + FAST_READ_DUMMY_BYTE; |
329 | spi_message_add_tail(&t[0], &m); | 340 | spi_message_add_tail(&t[0], &m); |
330 | 341 | ||
331 | t[1].rx_buf = buf; | 342 | t[1].rx_buf = buf; |
@@ -352,13 +363,11 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
352 | 363 | ||
353 | /* Set up the write data buffer. */ | 364 | /* Set up the write data buffer. */ |
354 | flash->command[0] = OPCODE_READ; | 365 | flash->command[0] = OPCODE_READ; |
355 | flash->command[1] = from >> 16; | 366 | m25p_addr2cmd(flash, from, flash->command); |
356 | flash->command[2] = from >> 8; | ||
357 | flash->command[3] = from; | ||
358 | 367 | ||
359 | spi_sync(flash->spi, &m); | 368 | spi_sync(flash->spi, &m); |
360 | 369 | ||
361 | *retlen = m.actual_length - CMD_SIZE - FAST_READ_DUMMY_BYTE; | 370 | *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE; |
362 | 371 | ||
363 | mutex_unlock(&flash->lock); | 372 | mutex_unlock(&flash->lock); |
364 | 373 | ||
@@ -396,7 +405,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
396 | memset(t, 0, (sizeof t)); | 405 | memset(t, 0, (sizeof t)); |
397 | 406 | ||
398 | t[0].tx_buf = flash->command; | 407 | t[0].tx_buf = flash->command; |
399 | t[0].len = CMD_SIZE; | 408 | t[0].len = m25p_cmdsz(flash); |
400 | spi_message_add_tail(&t[0], &m); | 409 | spi_message_add_tail(&t[0], &m); |
401 | 410 | ||
402 | t[1].tx_buf = buf; | 411 | t[1].tx_buf = buf; |
@@ -414,41 +423,36 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
414 | 423 | ||
415 | /* Set up the opcode in the write buffer. */ | 424 | /* Set up the opcode in the write buffer. */ |
416 | flash->command[0] = OPCODE_PP; | 425 | flash->command[0] = OPCODE_PP; |
417 | flash->command[1] = to >> 16; | 426 | m25p_addr2cmd(flash, to, flash->command); |
418 | flash->command[2] = to >> 8; | ||
419 | flash->command[3] = to; | ||
420 | 427 | ||
421 | /* what page do we start with? */ | 428 | page_offset = to & (flash->page_size - 1); |
422 | page_offset = to % FLASH_PAGESIZE; | ||
423 | 429 | ||
424 | /* do all the bytes fit onto one page? */ | 430 | /* do all the bytes fit onto one page? */ |
425 | if (page_offset + len <= FLASH_PAGESIZE) { | 431 | if (page_offset + len <= flash->page_size) { |
426 | t[1].len = len; | 432 | t[1].len = len; |
427 | 433 | ||
428 | spi_sync(flash->spi, &m); | 434 | spi_sync(flash->spi, &m); |
429 | 435 | ||
430 | *retlen = m.actual_length - CMD_SIZE; | 436 | *retlen = m.actual_length - m25p_cmdsz(flash); |
431 | } else { | 437 | } else { |
432 | u32 i; | 438 | u32 i; |
433 | 439 | ||
434 | /* the size of data remaining on the first page */ | 440 | /* the size of data remaining on the first page */ |
435 | page_size = FLASH_PAGESIZE - page_offset; | 441 | page_size = flash->page_size - page_offset; |
436 | 442 | ||
437 | t[1].len = page_size; | 443 | t[1].len = page_size; |
438 | spi_sync(flash->spi, &m); | 444 | spi_sync(flash->spi, &m); |
439 | 445 | ||
440 | *retlen = m.actual_length - CMD_SIZE; | 446 | *retlen = m.actual_length - m25p_cmdsz(flash); |
441 | 447 | ||
442 | /* write everything in PAGESIZE chunks */ | 448 | /* write everything in flash->page_size chunks */ |
443 | for (i = page_size; i < len; i += page_size) { | 449 | for (i = page_size; i < len; i += page_size) { |
444 | page_size = len - i; | 450 | page_size = len - i; |
445 | if (page_size > FLASH_PAGESIZE) | 451 | if (page_size > flash->page_size) |
446 | page_size = FLASH_PAGESIZE; | 452 | page_size = flash->page_size; |
447 | 453 | ||
448 | /* write the next page to flash */ | 454 | /* write the next page to flash */ |
449 | flash->command[1] = (to + i) >> 16; | 455 | m25p_addr2cmd(flash, to + i, flash->command); |
450 | flash->command[2] = (to + i) >> 8; | ||
451 | flash->command[3] = (to + i); | ||
452 | 456 | ||
453 | t[1].tx_buf = buf + i; | 457 | t[1].tx_buf = buf + i; |
454 | t[1].len = page_size; | 458 | t[1].len = page_size; |
@@ -460,7 +464,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
460 | spi_sync(flash->spi, &m); | 464 | spi_sync(flash->spi, &m); |
461 | 465 | ||
462 | if (retlen) | 466 | if (retlen) |
463 | *retlen += m.actual_length - CMD_SIZE; | 467 | *retlen += m.actual_length - m25p_cmdsz(flash); |
464 | } | 468 | } |
465 | } | 469 | } |
466 | 470 | ||
@@ -492,7 +496,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
492 | memset(t, 0, (sizeof t)); | 496 | memset(t, 0, (sizeof t)); |
493 | 497 | ||
494 | t[0].tx_buf = flash->command; | 498 | t[0].tx_buf = flash->command; |
495 | t[0].len = CMD_SIZE; | 499 | t[0].len = m25p_cmdsz(flash); |
496 | spi_message_add_tail(&t[0], &m); | 500 | spi_message_add_tail(&t[0], &m); |
497 | 501 | ||
498 | t[1].tx_buf = buf; | 502 | t[1].tx_buf = buf; |
@@ -511,9 +515,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
511 | /* Start write from odd address. */ | 515 | /* Start write from odd address. */ |
512 | if (actual) { | 516 | if (actual) { |
513 | flash->command[0] = OPCODE_BP; | 517 | flash->command[0] = OPCODE_BP; |
514 | flash->command[1] = to >> 16; | 518 | m25p_addr2cmd(flash, to, flash->command); |
515 | flash->command[2] = to >> 8; | ||
516 | flash->command[3] = to; | ||
517 | 519 | ||
518 | /* write one byte. */ | 520 | /* write one byte. */ |
519 | t[1].len = 1; | 521 | t[1].len = 1; |
@@ -521,17 +523,15 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
521 | ret = wait_till_ready(flash); | 523 | ret = wait_till_ready(flash); |
522 | if (ret) | 524 | if (ret) |
523 | goto time_out; | 525 | goto time_out; |
524 | *retlen += m.actual_length - CMD_SIZE; | 526 | *retlen += m.actual_length - m25p_cmdsz(flash); |
525 | } | 527 | } |
526 | to += actual; | 528 | to += actual; |
527 | 529 | ||
528 | flash->command[0] = OPCODE_AAI_WP; | 530 | flash->command[0] = OPCODE_AAI_WP; |
529 | flash->command[1] = to >> 16; | 531 | m25p_addr2cmd(flash, to, flash->command); |
530 | flash->command[2] = to >> 8; | ||
531 | flash->command[3] = to; | ||
532 | 532 | ||
533 | /* Write out most of the data here. */ | 533 | /* Write out most of the data here. */ |
534 | cmd_sz = CMD_SIZE; | 534 | cmd_sz = m25p_cmdsz(flash); |
535 | for (; actual < len - 1; actual += 2) { | 535 | for (; actual < len - 1; actual += 2) { |
536 | t[0].len = cmd_sz; | 536 | t[0].len = cmd_sz; |
537 | /* write two bytes. */ | 537 | /* write two bytes. */ |
@@ -555,10 +555,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
555 | if (actual != len) { | 555 | if (actual != len) { |
556 | write_enable(flash); | 556 | write_enable(flash); |
557 | flash->command[0] = OPCODE_BP; | 557 | flash->command[0] = OPCODE_BP; |
558 | flash->command[1] = to >> 16; | 558 | m25p_addr2cmd(flash, to, flash->command); |
559 | flash->command[2] = to >> 8; | 559 | t[0].len = m25p_cmdsz(flash); |
560 | flash->command[3] = to; | ||
561 | t[0].len = CMD_SIZE; | ||
562 | t[1].len = 1; | 560 | t[1].len = 1; |
563 | t[1].tx_buf = buf + actual; | 561 | t[1].tx_buf = buf + actual; |
564 | 562 | ||
@@ -566,7 +564,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
566 | ret = wait_till_ready(flash); | 564 | ret = wait_till_ready(flash); |
567 | if (ret) | 565 | if (ret) |
568 | goto time_out; | 566 | goto time_out; |
569 | *retlen += m.actual_length - CMD_SIZE; | 567 | *retlen += m.actual_length - m25p_cmdsz(flash); |
570 | write_disable(flash); | 568 | write_disable(flash); |
571 | } | 569 | } |
572 | 570 | ||
@@ -582,8 +580,6 @@ time_out: | |||
582 | */ | 580 | */ |
583 | 581 | ||
584 | struct flash_info { | 582 | struct flash_info { |
585 | char *name; | ||
586 | |||
587 | /* JEDEC id zero means "no ID" (most older chips); otherwise it has | 583 | /* JEDEC id zero means "no ID" (most older chips); otherwise it has |
588 | * a high byte of zero plus three data bytes: the manufacturer id, | 584 | * a high byte of zero plus three data bytes: the manufacturer id, |
589 | * then a two byte device id. | 585 | * then a two byte device id. |
@@ -597,87 +593,119 @@ struct flash_info { | |||
597 | unsigned sector_size; | 593 | unsigned sector_size; |
598 | u16 n_sectors; | 594 | u16 n_sectors; |
599 | 595 | ||
596 | u16 page_size; | ||
597 | u16 addr_width; | ||
598 | |||
600 | u16 flags; | 599 | u16 flags; |
601 | #define SECT_4K 0x01 /* OPCODE_BE_4K works uniformly */ | 600 | #define SECT_4K 0x01 /* OPCODE_BE_4K works uniformly */ |
601 | #define M25P_NO_ERASE 0x02 /* No erase command needed */ | ||
602 | }; | 602 | }; |
603 | 603 | ||
604 | #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ | ||
605 | ((kernel_ulong_t)&(struct flash_info) { \ | ||
606 | .jedec_id = (_jedec_id), \ | ||
607 | .ext_id = (_ext_id), \ | ||
608 | .sector_size = (_sector_size), \ | ||
609 | .n_sectors = (_n_sectors), \ | ||
610 | .page_size = 256, \ | ||
611 | .addr_width = 3, \ | ||
612 | .flags = (_flags), \ | ||
613 | }) | ||
614 | |||
615 | #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width) \ | ||
616 | ((kernel_ulong_t)&(struct flash_info) { \ | ||
617 | .sector_size = (_sector_size), \ | ||
618 | .n_sectors = (_n_sectors), \ | ||
619 | .page_size = (_page_size), \ | ||
620 | .addr_width = (_addr_width), \ | ||
621 | .flags = M25P_NO_ERASE, \ | ||
622 | }) | ||
604 | 623 | ||
605 | /* NOTE: double check command sets and memory organization when you add | 624 | /* NOTE: double check command sets and memory organization when you add |
606 | * more flash chips. This current list focusses on newer chips, which | 625 | * more flash chips. This current list focusses on newer chips, which |
607 | * have been converging on command sets which including JEDEC ID. | 626 | * have been converging on command sets which including JEDEC ID. |
608 | */ | 627 | */ |
609 | static struct flash_info __devinitdata m25p_data [] = { | 628 | static const struct spi_device_id m25p_ids[] = { |
610 | |||
611 | /* Atmel -- some are (confusingly) marketed as "DataFlash" */ | 629 | /* Atmel -- some are (confusingly) marketed as "DataFlash" */ |
612 | { "at25fs010", 0x1f6601, 0, 32 * 1024, 4, SECT_4K, }, | 630 | { "at25fs010", INFO(0x1f6601, 0, 32 * 1024, 4, SECT_4K) }, |
613 | { "at25fs040", 0x1f6604, 0, 64 * 1024, 8, SECT_4K, }, | 631 | { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K) }, |
614 | 632 | ||
615 | { "at25df041a", 0x1f4401, 0, 64 * 1024, 8, SECT_4K, }, | 633 | { "at25df041a", INFO(0x1f4401, 0, 64 * 1024, 8, SECT_4K) }, |
616 | { "at25df641", 0x1f4800, 0, 64 * 1024, 128, SECT_4K, }, | 634 | { "at25df641", INFO(0x1f4800, 0, 64 * 1024, 128, SECT_4K) }, |
617 | 635 | ||
618 | { "at26f004", 0x1f0400, 0, 64 * 1024, 8, SECT_4K, }, | 636 | { "at26f004", INFO(0x1f0400, 0, 64 * 1024, 8, SECT_4K) }, |
619 | { "at26df081a", 0x1f4501, 0, 64 * 1024, 16, SECT_4K, }, | 637 | { "at26df081a", INFO(0x1f4501, 0, 64 * 1024, 16, SECT_4K) }, |
620 | { "at26df161a", 0x1f4601, 0, 64 * 1024, 32, SECT_4K, }, | 638 | { "at26df161a", INFO(0x1f4601, 0, 64 * 1024, 32, SECT_4K) }, |
621 | { "at26df321", 0x1f4701, 0, 64 * 1024, 64, SECT_4K, }, | 639 | { "at26df321", INFO(0x1f4701, 0, 64 * 1024, 64, SECT_4K) }, |
622 | 640 | ||
623 | /* Macronix */ | 641 | /* Macronix */ |
624 | { "mx25l3205d", 0xc22016, 0, 64 * 1024, 64, }, | 642 | { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) }, |
625 | { "mx25l6405d", 0xc22017, 0, 64 * 1024, 128, }, | 643 | { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) }, |
626 | { "mx25l12805d", 0xc22018, 0, 64 * 1024, 256, }, | 644 | { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) }, |
627 | { "mx25l12855e", 0xc22618, 0, 64 * 1024, 256, }, | 645 | { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, |
646 | { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) }, | ||
628 | 647 | ||
629 | /* Spansion -- single (large) sector size only, at least | 648 | /* Spansion -- single (large) sector size only, at least |
630 | * for the chips listed here (without boot sectors). | 649 | * for the chips listed here (without boot sectors). |
631 | */ | 650 | */ |
632 | { "s25sl004a", 0x010212, 0, 64 * 1024, 8, }, | 651 | { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) }, |
633 | { "s25sl008a", 0x010213, 0, 64 * 1024, 16, }, | 652 | { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) }, |
634 | { "s25sl016a", 0x010214, 0, 64 * 1024, 32, }, | 653 | { "s25sl016a", INFO(0x010214, 0, 64 * 1024, 32, 0) }, |
635 | { "s25sl032a", 0x010215, 0, 64 * 1024, 64, }, | 654 | { "s25sl032a", INFO(0x010215, 0, 64 * 1024, 64, 0) }, |
636 | { "s25sl064a", 0x010216, 0, 64 * 1024, 128, }, | 655 | { "s25sl064a", INFO(0x010216, 0, 64 * 1024, 128, 0) }, |
637 | { "s25sl12800", 0x012018, 0x0300, 256 * 1024, 64, }, | 656 | { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, |
638 | { "s25sl12801", 0x012018, 0x0301, 64 * 1024, 256, }, | 657 | { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) }, |
639 | { "s25fl129p0", 0x012018, 0x4d00, 256 * 1024, 64, }, | 658 | { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, 0) }, |
640 | { "s25fl129p1", 0x012018, 0x4d01, 64 * 1024, 256, }, | 659 | { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, 0) }, |
641 | 660 | ||
642 | /* SST -- large erase sizes are "overlays", "sectors" are 4K */ | 661 | /* SST -- large erase sizes are "overlays", "sectors" are 4K */ |
643 | { "sst25vf040b", 0xbf258d, 0, 64 * 1024, 8, SECT_4K, }, | 662 | { "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024, 8, SECT_4K) }, |
644 | { "sst25vf080b", 0xbf258e, 0, 64 * 1024, 16, SECT_4K, }, | 663 | { "sst25vf080b", INFO(0xbf258e, 0, 64 * 1024, 16, SECT_4K) }, |
645 | { "sst25vf016b", 0xbf2541, 0, 64 * 1024, 32, SECT_4K, }, | 664 | { "sst25vf016b", INFO(0xbf2541, 0, 64 * 1024, 32, SECT_4K) }, |
646 | { "sst25vf032b", 0xbf254a, 0, 64 * 1024, 64, SECT_4K, }, | 665 | { "sst25vf032b", INFO(0xbf254a, 0, 64 * 1024, 64, SECT_4K) }, |
647 | { "sst25wf512", 0xbf2501, 0, 64 * 1024, 1, SECT_4K, }, | 666 | { "sst25wf512", INFO(0xbf2501, 0, 64 * 1024, 1, SECT_4K) }, |
648 | { "sst25wf010", 0xbf2502, 0, 64 * 1024, 2, SECT_4K, }, | 667 | { "sst25wf010", INFO(0xbf2502, 0, 64 * 1024, 2, SECT_4K) }, |
649 | { "sst25wf020", 0xbf2503, 0, 64 * 1024, 4, SECT_4K, }, | 668 | { "sst25wf020", INFO(0xbf2503, 0, 64 * 1024, 4, SECT_4K) }, |
650 | { "sst25wf040", 0xbf2504, 0, 64 * 1024, 8, SECT_4K, }, | 669 | { "sst25wf040", INFO(0xbf2504, 0, 64 * 1024, 8, SECT_4K) }, |
651 | 670 | ||
652 | /* ST Microelectronics -- newer production may have feature updates */ | 671 | /* ST Microelectronics -- newer production may have feature updates */ |
653 | { "m25p05", 0x202010, 0, 32 * 1024, 2, }, | 672 | { "m25p05", INFO(0x202010, 0, 32 * 1024, 2, 0) }, |
654 | { "m25p10", 0x202011, 0, 32 * 1024, 4, }, | 673 | { "m25p10", INFO(0x202011, 0, 32 * 1024, 4, 0) }, |
655 | { "m25p20", 0x202012, 0, 64 * 1024, 4, }, | 674 | { "m25p20", INFO(0x202012, 0, 64 * 1024, 4, 0) }, |
656 | { "m25p40", 0x202013, 0, 64 * 1024, 8, }, | 675 | { "m25p40", INFO(0x202013, 0, 64 * 1024, 8, 0) }, |
657 | { "m25p80", 0, 0, 64 * 1024, 16, }, | 676 | { "m25p80", INFO(0x202014, 0, 64 * 1024, 16, 0) }, |
658 | { "m25p16", 0x202015, 0, 64 * 1024, 32, }, | 677 | { "m25p16", INFO(0x202015, 0, 64 * 1024, 32, 0) }, |
659 | { "m25p32", 0x202016, 0, 64 * 1024, 64, }, | 678 | { "m25p32", INFO(0x202016, 0, 64 * 1024, 64, 0) }, |
660 | { "m25p64", 0x202017, 0, 64 * 1024, 128, }, | 679 | { "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) }, |
661 | { "m25p128", 0x202018, 0, 256 * 1024, 64, }, | 680 | { "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) }, |
662 | 681 | ||
663 | { "m45pe10", 0x204011, 0, 64 * 1024, 2, }, | 682 | { "m45pe10", INFO(0x204011, 0, 64 * 1024, 2, 0) }, |
664 | { "m45pe80", 0x204014, 0, 64 * 1024, 16, }, | 683 | { "m45pe80", INFO(0x204014, 0, 64 * 1024, 16, 0) }, |
665 | { "m45pe16", 0x204015, 0, 64 * 1024, 32, }, | 684 | { "m45pe16", INFO(0x204015, 0, 64 * 1024, 32, 0) }, |
666 | 685 | ||
667 | { "m25pe80", 0x208014, 0, 64 * 1024, 16, }, | 686 | { "m25pe80", INFO(0x208014, 0, 64 * 1024, 16, 0) }, |
668 | { "m25pe16", 0x208015, 0, 64 * 1024, 32, SECT_4K, }, | 687 | { "m25pe16", INFO(0x208015, 0, 64 * 1024, 32, SECT_4K) }, |
669 | 688 | ||
670 | /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ | 689 | /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ |
671 | { "w25x10", 0xef3011, 0, 64 * 1024, 2, SECT_4K, }, | 690 | { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) }, |
672 | { "w25x20", 0xef3012, 0, 64 * 1024, 4, SECT_4K, }, | 691 | { "w25x20", INFO(0xef3012, 0, 64 * 1024, 4, SECT_4K) }, |
673 | { "w25x40", 0xef3013, 0, 64 * 1024, 8, SECT_4K, }, | 692 | { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) }, |
674 | { "w25x80", 0xef3014, 0, 64 * 1024, 16, SECT_4K, }, | 693 | { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) }, |
675 | { "w25x16", 0xef3015, 0, 64 * 1024, 32, SECT_4K, }, | 694 | { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) }, |
676 | { "w25x32", 0xef3016, 0, 64 * 1024, 64, SECT_4K, }, | 695 | { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) }, |
677 | { "w25x64", 0xef3017, 0, 64 * 1024, 128, SECT_4K, }, | 696 | { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, |
697 | |||
698 | /* Catalyst / On Semiconductor -- non-JEDEC */ | ||
699 | { "cat25c11", CAT25_INFO( 16, 8, 16, 1) }, | ||
700 | { "cat25c03", CAT25_INFO( 32, 8, 16, 2) }, | ||
701 | { "cat25c09", CAT25_INFO( 128, 8, 32, 2) }, | ||
702 | { "cat25c17", CAT25_INFO( 256, 8, 32, 2) }, | ||
703 | { "cat25128", CAT25_INFO(2048, 8, 64, 2) }, | ||
704 | { }, | ||
678 | }; | 705 | }; |
706 | MODULE_DEVICE_TABLE(spi, m25p_ids); | ||
679 | 707 | ||
680 | static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | 708 | static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi) |
681 | { | 709 | { |
682 | int tmp; | 710 | int tmp; |
683 | u8 code = OPCODE_RDID; | 711 | u8 code = OPCODE_RDID; |
@@ -702,18 +730,24 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | |||
702 | jedec = jedec << 8; | 730 | jedec = jedec << 8; |
703 | jedec |= id[2]; | 731 | jedec |= id[2]; |
704 | 732 | ||
733 | /* | ||
734 | * Some chips (like Numonyx M25P80) have JEDEC and non-JEDEC variants, | ||
735 | * which depend on technology process. Officially RDID command doesn't | ||
736 | * exist for non-JEDEC chips, but for compatibility they return ID 0. | ||
737 | */ | ||
738 | if (jedec == 0) | ||
739 | return NULL; | ||
740 | |||
705 | ext_jedec = id[3] << 8 | id[4]; | 741 | ext_jedec = id[3] << 8 | id[4]; |
706 | 742 | ||
707 | for (tmp = 0, info = m25p_data; | 743 | for (tmp = 0; tmp < ARRAY_SIZE(m25p_ids) - 1; tmp++) { |
708 | tmp < ARRAY_SIZE(m25p_data); | 744 | info = (void *)m25p_ids[tmp].driver_data; |
709 | tmp++, info++) { | ||
710 | if (info->jedec_id == jedec) { | 745 | if (info->jedec_id == jedec) { |
711 | if (info->ext_id != 0 && info->ext_id != ext_jedec) | 746 | if (info->ext_id != 0 && info->ext_id != ext_jedec) |
712 | continue; | 747 | continue; |
713 | return info; | 748 | return &m25p_ids[tmp]; |
714 | } | 749 | } |
715 | } | 750 | } |
716 | dev_err(&spi->dev, "unrecognized JEDEC id %06x\n", jedec); | ||
717 | return NULL; | 751 | return NULL; |
718 | } | 752 | } |
719 | 753 | ||
@@ -725,6 +759,7 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | |||
725 | */ | 759 | */ |
726 | static int __devinit m25p_probe(struct spi_device *spi) | 760 | static int __devinit m25p_probe(struct spi_device *spi) |
727 | { | 761 | { |
762 | const struct spi_device_id *id = spi_get_device_id(spi); | ||
728 | struct flash_platform_data *data; | 763 | struct flash_platform_data *data; |
729 | struct m25p *flash; | 764 | struct m25p *flash; |
730 | struct flash_info *info; | 765 | struct flash_info *info; |
@@ -737,50 +772,65 @@ static int __devinit m25p_probe(struct spi_device *spi) | |||
737 | */ | 772 | */ |
738 | data = spi->dev.platform_data; | 773 | data = spi->dev.platform_data; |
739 | if (data && data->type) { | 774 | if (data && data->type) { |
740 | for (i = 0, info = m25p_data; | 775 | const struct spi_device_id *plat_id; |
741 | i < ARRAY_SIZE(m25p_data); | ||
742 | i++, info++) { | ||
743 | if (strcmp(data->type, info->name) == 0) | ||
744 | break; | ||
745 | } | ||
746 | 776 | ||
747 | /* unrecognized chip? */ | 777 | for (i = 0; i < ARRAY_SIZE(m25p_ids) - 1; i++) { |
748 | if (i == ARRAY_SIZE(m25p_data)) { | 778 | plat_id = &m25p_ids[i]; |
749 | DEBUG(MTD_DEBUG_LEVEL0, "%s: unrecognized id %s\n", | 779 | if (strcmp(data->type, plat_id->name)) |
750 | dev_name(&spi->dev), data->type); | 780 | continue; |
751 | info = NULL; | 781 | break; |
752 | |||
753 | /* recognized; is that chip really what's there? */ | ||
754 | } else if (info->jedec_id) { | ||
755 | struct flash_info *chip = jedec_probe(spi); | ||
756 | |||
757 | if (!chip || chip != info) { | ||
758 | dev_warn(&spi->dev, "found %s, expected %s\n", | ||
759 | chip ? chip->name : "UNKNOWN", | ||
760 | info->name); | ||
761 | info = NULL; | ||
762 | } | ||
763 | } | 782 | } |
764 | } else | ||
765 | info = jedec_probe(spi); | ||
766 | 783 | ||
767 | if (!info) | 784 | if (plat_id) |
768 | return -ENODEV; | 785 | id = plat_id; |
786 | else | ||
787 | dev_warn(&spi->dev, "unrecognized id %s\n", data->type); | ||
788 | } | ||
789 | |||
790 | info = (void *)id->driver_data; | ||
791 | |||
792 | if (info->jedec_id) { | ||
793 | const struct spi_device_id *jid; | ||
794 | |||
795 | jid = jedec_probe(spi); | ||
796 | if (!jid) { | ||
797 | dev_info(&spi->dev, "non-JEDEC variant of %s\n", | ||
798 | id->name); | ||
799 | } else if (jid != id) { | ||
800 | /* | ||
801 | * JEDEC knows better, so overwrite platform ID. We | ||
802 | * can't trust partitions any longer, but we'll let | ||
803 | * mtd apply them anyway, since some partitions may be | ||
804 | * marked read-only, and we don't want to lose that | ||
805 | * information, even if it's not 100% accurate. | ||
806 | */ | ||
807 | dev_warn(&spi->dev, "found %s, expected %s\n", | ||
808 | jid->name, id->name); | ||
809 | id = jid; | ||
810 | info = (void *)jid->driver_data; | ||
811 | } | ||
812 | } | ||
769 | 813 | ||
770 | flash = kzalloc(sizeof *flash, GFP_KERNEL); | 814 | flash = kzalloc(sizeof *flash, GFP_KERNEL); |
771 | if (!flash) | 815 | if (!flash) |
772 | return -ENOMEM; | 816 | return -ENOMEM; |
817 | flash->command = kmalloc(MAX_CMD_SIZE + FAST_READ_DUMMY_BYTE, GFP_KERNEL); | ||
818 | if (!flash->command) { | ||
819 | kfree(flash); | ||
820 | return -ENOMEM; | ||
821 | } | ||
773 | 822 | ||
774 | flash->spi = spi; | 823 | flash->spi = spi; |
775 | mutex_init(&flash->lock); | 824 | mutex_init(&flash->lock); |
776 | dev_set_drvdata(&spi->dev, flash); | 825 | dev_set_drvdata(&spi->dev, flash); |
777 | 826 | ||
778 | /* | 827 | /* |
779 | * Atmel serial flash tend to power up | 828 | * Atmel and SST serial flash tend to power |
780 | * with the software protection bits set | 829 | * up with the software protection bits set |
781 | */ | 830 | */ |
782 | 831 | ||
783 | if (info->jedec_id >> 16 == 0x1f) { | 832 | if (info->jedec_id >> 16 == 0x1f || |
833 | info->jedec_id >> 16 == 0xbf) { | ||
784 | write_enable(flash); | 834 | write_enable(flash); |
785 | write_sr(flash, 0); | 835 | write_sr(flash, 0); |
786 | } | 836 | } |
@@ -812,9 +862,14 @@ static int __devinit m25p_probe(struct spi_device *spi) | |||
812 | flash->mtd.erasesize = info->sector_size; | 862 | flash->mtd.erasesize = info->sector_size; |
813 | } | 863 | } |
814 | 864 | ||
865 | if (info->flags & M25P_NO_ERASE) | ||
866 | flash->mtd.flags |= MTD_NO_ERASE; | ||
867 | |||
815 | flash->mtd.dev.parent = &spi->dev; | 868 | flash->mtd.dev.parent = &spi->dev; |
869 | flash->page_size = info->page_size; | ||
870 | flash->addr_width = info->addr_width; | ||
816 | 871 | ||
817 | dev_info(&spi->dev, "%s (%lld Kbytes)\n", info->name, | 872 | dev_info(&spi->dev, "%s (%lld Kbytes)\n", id->name, |
818 | (long long)flash->mtd.size >> 10); | 873 | (long long)flash->mtd.size >> 10); |
819 | 874 | ||
820 | DEBUG(MTD_DEBUG_LEVEL2, | 875 | DEBUG(MTD_DEBUG_LEVEL2, |
@@ -888,8 +943,10 @@ static int __devexit m25p_remove(struct spi_device *spi) | |||
888 | status = del_mtd_partitions(&flash->mtd); | 943 | status = del_mtd_partitions(&flash->mtd); |
889 | else | 944 | else |
890 | status = del_mtd_device(&flash->mtd); | 945 | status = del_mtd_device(&flash->mtd); |
891 | if (status == 0) | 946 | if (status == 0) { |
947 | kfree(flash->command); | ||
892 | kfree(flash); | 948 | kfree(flash); |
949 | } | ||
893 | return 0; | 950 | return 0; |
894 | } | 951 | } |
895 | 952 | ||
@@ -900,6 +957,7 @@ static struct spi_driver m25p80_driver = { | |||
900 | .bus = &spi_bus_type, | 957 | .bus = &spi_bus_type, |
901 | .owner = THIS_MODULE, | 958 | .owner = THIS_MODULE, |
902 | }, | 959 | }, |
960 | .id_table = m25p_ids, | ||
903 | .probe = m25p_probe, | 961 | .probe = m25p_probe, |
904 | .remove = __devexit_p(m25p_remove), | 962 | .remove = __devexit_p(m25p_remove), |
905 | 963 | ||