Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008, Network Appliance Inc. |
| 3 | * Author: Jason McMullan <mcmullan <at> netapp.com> |
| 4 | * Licensed under the GPL-2 or later. |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <malloc.h> |
| 9 | #include <spi_flash.h> |
| 10 | |
| 11 | #include "spi_flash_internal.h" |
| 12 | |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 13 | struct winbond_spi_flash_params { |
| 14 | uint16_t id; |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 15 | uint16_t nr_blocks; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 16 | const char *name; |
| 17 | }; |
| 18 | |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 19 | static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { |
| 20 | { |
James Le Cuirot | 7e921dc | 2011-07-15 06:12:51 +0000 | [diff] [blame] | 21 | .id = 0x3013, |
James Le Cuirot | 7e921dc | 2011-07-15 06:12:51 +0000 | [diff] [blame] | 22 | .nr_blocks = 8, |
| 23 | .name = "W25X40", |
| 24 | }, |
| 25 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 26 | .id = 0x3015, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 27 | .nr_blocks = 32, |
| 28 | .name = "W25X16", |
| 29 | }, |
| 30 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 31 | .id = 0x3016, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 32 | .nr_blocks = 64, |
| 33 | .name = "W25X32", |
| 34 | }, |
| 35 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 36 | .id = 0x3017, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 37 | .nr_blocks = 128, |
| 38 | .name = "W25X64", |
| 39 | }, |
Graeme Smecher | a448bce | 2010-07-29 09:00:02 -0400 | [diff] [blame] | 40 | { |
Stephen Warren | 5f96364 | 2012-05-24 11:38:34 +0000 | [diff] [blame] | 41 | .id = 0x4014, |
Stephen Warren | 5f96364 | 2012-05-24 11:38:34 +0000 | [diff] [blame] | 42 | .nr_blocks = 16, |
| 43 | .name = "W25Q80BL", |
| 44 | }, |
| 45 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 46 | .id = 0x4015, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 47 | .nr_blocks = 32, |
| 48 | .name = "W25Q16", |
| 49 | }, |
| 50 | { |
| 51 | .id = 0x4016, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 52 | .nr_blocks = 64, |
| 53 | .name = "W25Q32", |
| 54 | }, |
| 55 | { |
| 56 | .id = 0x4017, |
Graeme Smecher | a448bce | 2010-07-29 09:00:02 -0400 | [diff] [blame] | 57 | .nr_blocks = 128, |
| 58 | .name = "W25Q64", |
| 59 | }, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 60 | { |
| 61 | .id = 0x4018, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 62 | .nr_blocks = 256, |
| 63 | .name = "W25Q128", |
| 64 | }, |
Rajeshwari Shinde | 703b1c3 | 2012-08-02 12:55:05 +0530 | [diff] [blame] | 65 | { |
| 66 | .id = 0x5014, |
| 67 | .nr_blocks = 128, |
| 68 | .name = "W25Q80", |
| 69 | }, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 70 | }; |
| 71 | |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 72 | struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode) |
| 73 | { |
| 74 | const struct winbond_spi_flash_params *params; |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 75 | struct spi_flash *flash; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 76 | unsigned int i; |
| 77 | |
| 78 | for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) { |
| 79 | params = &winbond_spi_flash_table[i]; |
| 80 | if (params->id == ((idcode[1] << 8) | idcode[2])) |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | if (i == ARRAY_SIZE(winbond_spi_flash_table)) { |
| 85 | debug("SF: Unsupported Winbond ID %02x%02x\n", |
| 86 | idcode[1], idcode[2]); |
| 87 | return NULL; |
| 88 | } |
| 89 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 90 | flash = malloc(sizeof(*flash)); |
| 91 | if (!flash) { |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 92 | debug("SF: Failed to allocate memory\n"); |
| 93 | return NULL; |
| 94 | } |
| 95 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 96 | flash->spi = spi; |
| 97 | flash->name = params->name; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 98 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 99 | flash->write = spi_flash_cmd_write_multi; |
Mike Frysinger | 4147798 | 2012-03-04 22:35:50 -0500 | [diff] [blame] | 100 | flash->erase = spi_flash_cmd_erase; |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 101 | flash->read = spi_flash_cmd_read_fast; |
Stephen Warren | ce8670c | 2012-08-13 16:46:21 -0600 | [diff] [blame] | 102 | flash->page_size = 256; |
Mike Frysinger | a494078 | 2012-03-04 22:56:52 -0500 | [diff] [blame] | 103 | flash->sector_size = 4096; |
| 104 | flash->size = 4096 * 16 * params->nr_blocks; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 105 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 106 | return flash; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 107 | } |