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 | { |
Kuo-Jung Su | 5c54bb2 | 2013-05-23 15:09:49 +0000 | [diff] [blame] | 21 | .id = 0x2014, |
| 22 | .nr_blocks = 16, |
| 23 | .name = "W25P80", |
| 24 | }, |
| 25 | { |
| 26 | .id = 0x2015, |
| 27 | .nr_blocks = 32, |
| 28 | .name = "W25P16", |
| 29 | }, |
| 30 | { |
| 31 | .id = 0x2016, |
| 32 | .nr_blocks = 64, |
| 33 | .name = "W25P32", |
| 34 | }, |
| 35 | { |
James Le Cuirot | 7e921dc | 2011-07-15 06:12:51 +0000 | [diff] [blame] | 36 | .id = 0x3013, |
James Le Cuirot | 7e921dc | 2011-07-15 06:12:51 +0000 | [diff] [blame] | 37 | .nr_blocks = 8, |
| 38 | .name = "W25X40", |
| 39 | }, |
| 40 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 41 | .id = 0x3015, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 42 | .nr_blocks = 32, |
| 43 | .name = "W25X16", |
| 44 | }, |
| 45 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 46 | .id = 0x3016, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 47 | .nr_blocks = 64, |
| 48 | .name = "W25X32", |
| 49 | }, |
| 50 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 51 | .id = 0x3017, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 52 | .nr_blocks = 128, |
| 53 | .name = "W25X64", |
| 54 | }, |
Graeme Smecher | a448bce | 2010-07-29 09:00:02 -0400 | [diff] [blame] | 55 | { |
Stephen Warren | 5f96364 | 2012-05-24 11:38:34 +0000 | [diff] [blame] | 56 | .id = 0x4014, |
Stephen Warren | 5f96364 | 2012-05-24 11:38:34 +0000 | [diff] [blame] | 57 | .nr_blocks = 16, |
Jagannadha Sutradharudu Teki | 038baca | 2013-05-28 00:41:58 +0530 | [diff] [blame] | 58 | .name = "W25Q80BL/W25Q80BV", |
Stephen Warren | 5f96364 | 2012-05-24 11:38:34 +0000 | [diff] [blame] | 59 | }, |
| 60 | { |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 61 | .id = 0x4015, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 62 | .nr_blocks = 32, |
Jagannadha Sutradharudu Teki | 038baca | 2013-05-28 00:41:58 +0530 | [diff] [blame] | 63 | .name = "W25Q16CL/W25Q16DV", |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 64 | }, |
| 65 | { |
| 66 | .id = 0x4016, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 67 | .nr_blocks = 64, |
Jagannadha Sutradharudu Teki | e624009 | 2013-05-30 16:34:19 +0530 | [diff] [blame] | 68 | .name = "W25Q32BV/W25Q32FV_SPI", |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 69 | }, |
| 70 | { |
| 71 | .id = 0x4017, |
Graeme Smecher | a448bce | 2010-07-29 09:00:02 -0400 | [diff] [blame] | 72 | .nr_blocks = 128, |
Jagannadha Sutradharudu Teki | e624009 | 2013-05-30 16:34:19 +0530 | [diff] [blame] | 73 | .name = "W25Q64CV/W25Q64FV_SPI", |
Graeme Smecher | a448bce | 2010-07-29 09:00:02 -0400 | [diff] [blame] | 74 | }, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 75 | { |
| 76 | .id = 0x4018, |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 77 | .nr_blocks = 256, |
Jagannadha Sutradharudu Teki | e624009 | 2013-05-30 16:34:19 +0530 | [diff] [blame] | 78 | .name = "W25Q128BV/W25Q128FV_SPI", |
Wojtek Skulski | b1637e5 | 2010-12-07 01:07:45 -0500 | [diff] [blame] | 79 | }, |
Rajeshwari Shinde | 703b1c3 | 2012-08-02 12:55:05 +0530 | [diff] [blame] | 80 | { |
Jagannadha Sutradharudu Teki | 6c712e6 | 2013-02-23 01:39:01 +0000 | [diff] [blame] | 81 | .id = 0x4019, |
| 82 | .nr_blocks = 512, |
| 83 | .name = "W25Q256", |
| 84 | }, |
| 85 | { |
Rajeshwari Shinde | 703b1c3 | 2012-08-02 12:55:05 +0530 | [diff] [blame] | 86 | .id = 0x5014, |
Jagannadha Sutradharudu Teki | 80cb2bd | 2013-05-27 12:50:50 +0530 | [diff] [blame] | 87 | .nr_blocks = 16, |
| 88 | .name = "W25Q80BW", |
Rajeshwari Shinde | 703b1c3 | 2012-08-02 12:55:05 +0530 | [diff] [blame] | 89 | }, |
Jagannadha Sutradharudu Teki | e05b2a9 | 2013-01-23 13:29:29 +0100 | [diff] [blame] | 90 | { |
Jagannadha Sutradharudu Teki | ee23b6e | 2013-05-28 00:55:00 +0530 | [diff] [blame] | 91 | .id = 0x6015, |
| 92 | .nr_blocks = 32, |
| 93 | .name = "W25Q16DW", |
| 94 | }, |
| 95 | { |
Allen Martin | 737b4b9 | 2013-03-16 18:58:08 +0000 | [diff] [blame] | 96 | .id = 0x6016, |
Jagannadha Sutradharudu Teki | 1449bab | 2013-05-25 02:13:41 +0530 | [diff] [blame] | 97 | .nr_blocks = 64, |
Jagannadha Sutradharudu Teki | e624009 | 2013-05-30 16:34:19 +0530 | [diff] [blame] | 98 | .name = "W25Q32DW/W25Q32FV_QPI", |
Allen Martin | 737b4b9 | 2013-03-16 18:58:08 +0000 | [diff] [blame] | 99 | }, |
| 100 | { |
Jagannadha Sutradharudu Teki | e05b2a9 | 2013-01-23 13:29:29 +0100 | [diff] [blame] | 101 | .id = 0x6017, |
| 102 | .nr_blocks = 128, |
Jagannadha Sutradharudu Teki | e624009 | 2013-05-30 16:34:19 +0530 | [diff] [blame] | 103 | .name = "W25Q64DW/W25Q64FV_QPI", |
Jagannadha Sutradharudu Teki | e05b2a9 | 2013-01-23 13:29:29 +0100 | [diff] [blame] | 104 | }, |
Jagannadha Sutradharudu Teki | 78922ab | 2013-05-28 00:49:26 +0530 | [diff] [blame] | 105 | { |
| 106 | .id = 0x6018, |
| 107 | .nr_blocks = 256, |
Jagannadha Sutradharudu Teki | e624009 | 2013-05-30 16:34:19 +0530 | [diff] [blame] | 108 | .name = "W25Q128FW/W25Q128FV_QPI", |
Jagannadha Sutradharudu Teki | 78922ab | 2013-05-28 00:49:26 +0530 | [diff] [blame] | 109 | }, |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 110 | }; |
| 111 | |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 112 | struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode) |
| 113 | { |
| 114 | const struct winbond_spi_flash_params *params; |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 115 | struct spi_flash *flash; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 116 | unsigned int i; |
| 117 | |
| 118 | for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) { |
| 119 | params = &winbond_spi_flash_table[i]; |
| 120 | if (params->id == ((idcode[1] << 8) | idcode[2])) |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | if (i == ARRAY_SIZE(winbond_spi_flash_table)) { |
| 125 | debug("SF: Unsupported Winbond ID %02x%02x\n", |
| 126 | idcode[1], idcode[2]); |
| 127 | return NULL; |
| 128 | } |
| 129 | |
Simon Glass | f7e55f2 | 2013-03-11 06:08:03 +0000 | [diff] [blame] | 130 | flash = spi_flash_alloc_base(spi, params->name); |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 131 | if (!flash) { |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 132 | debug("SF: Failed to allocate memory\n"); |
| 133 | return NULL; |
| 134 | } |
| 135 | |
Stephen Warren | ce8670c | 2012-08-13 16:46:21 -0600 | [diff] [blame] | 136 | flash->page_size = 256; |
Kuo-Jung Su | 5c54bb2 | 2013-05-23 15:09:49 +0000 | [diff] [blame] | 137 | flash->sector_size = (idcode[1] == 0x20) ? 65536 : 4096; |
Mike Frysinger | a494078 | 2012-03-04 22:56:52 -0500 | [diff] [blame] | 138 | flash->size = 4096 * 16 * params->nr_blocks; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 139 | |
Mike Frysinger | ce7cc04 | 2011-06-28 07:38:10 +0000 | [diff] [blame] | 140 | return flash; |
Jason McMullan | 64e5f3a | 2009-10-09 17:12:23 -0400 | [diff] [blame] | 141 | } |