diff options
author | Lee Jones <lee.jones@linaro.org> | 2014-03-20 05:20:41 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2014-03-20 07:17:15 -0400 |
commit | 24fec651d1cc396e6e24631386e0d5dd5f329fbc (patch) | |
tree | 74073d5715be15601bd61c16e06a8b6c7c0e8414 /drivers/mtd/devices | |
parent | 11d7f826639baa25e7930d2b34c84c2d67f85ddc (diff) |
mtd: st_spi_fsm: Dynamically setup flash device based on JEDEC ID
Using previously added infrastructure we can now extract a device's JEDEC
ID, compare it to a list of known and supported devices and make assumptions
based on known characteristics of a given chip.
Acked-by Angus Clark <angus.clark@st.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r-- | drivers/mtd/devices/st_spi_fsm.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/drivers/mtd/devices/st_spi_fsm.c b/drivers/mtd/devices/st_spi_fsm.c index 29da52284dfd..9467585fcfda 100644 --- a/drivers/mtd/devices/st_spi_fsm.c +++ b/drivers/mtd/devices/st_spi_fsm.c | |||
@@ -204,6 +204,7 @@ struct stfsm { | |||
204 | struct resource *region; | 204 | struct resource *region; |
205 | struct mtd_info mtd; | 205 | struct mtd_info mtd; |
206 | struct mutex lock; | 206 | struct mutex lock; |
207 | struct flash_info *info; | ||
207 | 208 | ||
208 | uint32_t fifo_dir_delay; | 209 | uint32_t fifo_dir_delay; |
209 | }; | 210 | }; |
@@ -477,6 +478,7 @@ static void stfsm_read_jedec(struct stfsm *fsm, uint8_t *const jedec) | |||
477 | 478 | ||
478 | static struct flash_info *stfsm_jedec_probe(struct stfsm *fsm) | 479 | static struct flash_info *stfsm_jedec_probe(struct stfsm *fsm) |
479 | { | 480 | { |
481 | struct flash_info *info; | ||
480 | u16 ext_jedec; | 482 | u16 ext_jedec; |
481 | u32 jedec; | 483 | u32 jedec; |
482 | u8 id[5]; | 484 | u8 id[5]; |
@@ -494,6 +496,15 @@ static struct flash_info *stfsm_jedec_probe(struct stfsm *fsm) | |||
494 | dev_dbg(fsm->dev, "JEDEC = 0x%08x [%02x %02x %02x %02x %02x]\n", | 496 | dev_dbg(fsm->dev, "JEDEC = 0x%08x [%02x %02x %02x %02x %02x]\n", |
495 | jedec, id[0], id[1], id[2], id[3], id[4]); | 497 | jedec, id[0], id[1], id[2], id[3], id[4]); |
496 | 498 | ||
499 | for (info = flash_types; info->name; info++) { | ||
500 | if (info->jedec_id == jedec) { | ||
501 | if (info->ext_id && info->ext_id != ext_jedec) | ||
502 | continue; | ||
503 | return info; | ||
504 | } | ||
505 | } | ||
506 | dev_err(fsm->dev, "Unrecognized JEDEC id %06x\n", jedec); | ||
507 | |||
497 | return NULL; | 508 | return NULL; |
498 | } | 509 | } |
499 | 510 | ||
@@ -588,6 +599,7 @@ static int stfsm_init(struct stfsm *fsm) | |||
588 | static int stfsm_probe(struct platform_device *pdev) | 599 | static int stfsm_probe(struct platform_device *pdev) |
589 | { | 600 | { |
590 | struct device_node *np = pdev->dev.of_node; | 601 | struct device_node *np = pdev->dev.of_node; |
602 | struct flash_info *info; | ||
591 | struct resource *res; | 603 | struct resource *res; |
592 | struct stfsm *fsm; | 604 | struct stfsm *fsm; |
593 | int ret; | 605 | int ret; |
@@ -627,13 +639,25 @@ static int stfsm_probe(struct platform_device *pdev) | |||
627 | } | 639 | } |
628 | 640 | ||
629 | /* Detect SPI FLASH device */ | 641 | /* Detect SPI FLASH device */ |
630 | stfsm_jedec_probe(fsm); | 642 | info = stfsm_jedec_probe(fsm); |
643 | if (!info) | ||
644 | return -ENODEV; | ||
645 | fsm->info = info; | ||
631 | 646 | ||
632 | fsm->mtd.dev.parent = &pdev->dev; | 647 | fsm->mtd.dev.parent = &pdev->dev; |
633 | fsm->mtd.type = MTD_NORFLASH; | 648 | fsm->mtd.type = MTD_NORFLASH; |
634 | fsm->mtd.writesize = 4; | 649 | fsm->mtd.writesize = 4; |
635 | fsm->mtd.writebufsize = fsm->mtd.writesize; | 650 | fsm->mtd.writebufsize = fsm->mtd.writesize; |
636 | fsm->mtd.flags = MTD_CAP_NORFLASH; | 651 | fsm->mtd.flags = MTD_CAP_NORFLASH; |
652 | fsm->mtd.size = info->sector_size * info->n_sectors; | ||
653 | fsm->mtd.erasesize = info->sector_size; | ||
654 | |||
655 | dev_err(&pdev->dev, | ||
656 | "Found serial flash device: %s\n" | ||
657 | " size = %llx (%lldMiB) erasesize = 0x%08x (%uKiB)\n", | ||
658 | info->name, | ||
659 | (long long)fsm->mtd.size, (long long)(fsm->mtd.size >> 20), | ||
660 | fsm->mtd.erasesize, (fsm->mtd.erasesize >> 10)); | ||
637 | 661 | ||
638 | return mtd_device_parse_register(&fsm->mtd, NULL, NULL, NULL, 0); | 662 | return mtd_device_parse_register(&fsm->mtd, NULL, NULL, NULL, 0); |
639 | } | 663 | } |