blob: a7cd51f5625ee39de7d86b16b94eced55febb9ae [file] [log] [blame]
Jason McMulland394a772009-10-09 17:12:23 -04001/*
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 McMulland394a772009-10-09 17:12:23 -040013struct winbond_spi_flash_params {
14 uint16_t id;
Wojtek Skulski93eab862010-12-07 01:07:45 -050015 uint16_t nr_blocks;
Jason McMulland394a772009-10-09 17:12:23 -040016 const char *name;
17};
18
Jason McMulland394a772009-10-09 17:12:23 -040019static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
20 {
Kuo-Jung Sued03f412013-05-23 15:09:49 +000021 .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 Cuirotad8e3bd2011-07-15 06:12:51 +000036 .id = 0x3013,
James Le Cuirotad8e3bd2011-07-15 06:12:51 +000037 .nr_blocks = 8,
38 .name = "W25X40",
39 },
40 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050041 .id = 0x3015,
Jason McMulland394a772009-10-09 17:12:23 -040042 .nr_blocks = 32,
43 .name = "W25X16",
44 },
45 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050046 .id = 0x3016,
Jason McMulland394a772009-10-09 17:12:23 -040047 .nr_blocks = 64,
48 .name = "W25X32",
49 },
50 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050051 .id = 0x3017,
Jason McMulland394a772009-10-09 17:12:23 -040052 .nr_blocks = 128,
53 .name = "W25X64",
54 },
Graeme Smecher74f9e0d2010-07-29 09:00:02 -040055 {
Stephen Warren1edaf092012-05-24 11:38:34 +000056 .id = 0x4014,
Stephen Warren1edaf092012-05-24 11:38:34 +000057 .nr_blocks = 16,
58 .name = "W25Q80BL",
59 },
60 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050061 .id = 0x4015,
Wojtek Skulski93eab862010-12-07 01:07:45 -050062 .nr_blocks = 32,
63 .name = "W25Q16",
64 },
65 {
66 .id = 0x4016,
Wojtek Skulski93eab862010-12-07 01:07:45 -050067 .nr_blocks = 64,
68 .name = "W25Q32",
69 },
70 {
71 .id = 0x4017,
Graeme Smecher74f9e0d2010-07-29 09:00:02 -040072 .nr_blocks = 128,
73 .name = "W25Q64",
74 },
Wojtek Skulski93eab862010-12-07 01:07:45 -050075 {
76 .id = 0x4018,
Wojtek Skulski93eab862010-12-07 01:07:45 -050077 .nr_blocks = 256,
78 .name = "W25Q128",
79 },
Rajeshwari Shindec969abc2012-08-02 12:55:05 +053080 {
Jagannadha Sutradharudu Teki47ccaa22013-02-23 01:39:01 +000081 .id = 0x4019,
82 .nr_blocks = 512,
83 .name = "W25Q256",
84 },
85 {
Rajeshwari Shindec969abc2012-08-02 12:55:05 +053086 .id = 0x5014,
Jagannadha Sutradharudu Tekifc2d7212013-05-27 12:50:50 +053087 .nr_blocks = 16,
88 .name = "W25Q80BW",
Rajeshwari Shindec969abc2012-08-02 12:55:05 +053089 },
Jagannadha Sutradharudu Teki5818a092013-01-23 13:29:29 +010090 {
Allen Martin772ba152013-03-16 18:58:08 +000091 .id = 0x6016,
92 .nr_blocks = 512,
93 .name = "W25Q32DW",
94 },
95 {
Jagannadha Sutradharudu Teki5818a092013-01-23 13:29:29 +010096 .id = 0x6017,
97 .nr_blocks = 128,
98 .name = "W25Q64DW",
99 },
Jason McMulland394a772009-10-09 17:12:23 -0400100};
101
Jason McMulland394a772009-10-09 17:12:23 -0400102struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
103{
104 const struct winbond_spi_flash_params *params;
Mike Frysingerb06afa72011-06-28 07:38:10 +0000105 struct spi_flash *flash;
Jason McMulland394a772009-10-09 17:12:23 -0400106 unsigned int i;
107
108 for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
109 params = &winbond_spi_flash_table[i];
110 if (params->id == ((idcode[1] << 8) | idcode[2]))
111 break;
112 }
113
114 if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
115 debug("SF: Unsupported Winbond ID %02x%02x\n",
116 idcode[1], idcode[2]);
117 return NULL;
118 }
119
Simon Glassc0f87dd2013-03-11 06:08:03 +0000120 flash = spi_flash_alloc_base(spi, params->name);
Mike Frysingerb06afa72011-06-28 07:38:10 +0000121 if (!flash) {
Jason McMulland394a772009-10-09 17:12:23 -0400122 debug("SF: Failed to allocate memory\n");
123 return NULL;
124 }
125
Stephen Warrenc75942c2012-08-13 16:46:21 -0600126 flash->page_size = 256;
Kuo-Jung Sued03f412013-05-23 15:09:49 +0000127 flash->sector_size = (idcode[1] == 0x20) ? 65536 : 4096;
Mike Frysingera4ed3b62012-03-04 22:56:52 -0500128 flash->size = 4096 * 16 * params->nr_blocks;
Jason McMulland394a772009-10-09 17:12:23 -0400129
Mike Frysingerb06afa72011-06-28 07:38:10 +0000130 return flash;
Jason McMulland394a772009-10-09 17:12:23 -0400131}