]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/spi/winbond.c
Merge branch 'master' of git://git.denx.de/u-boot-mpc5xxx
[karo-tx-uboot.git] / drivers / mtd / spi / winbond.c
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
13 struct winbond_spi_flash_params {
14         uint16_t        id;
15         uint16_t        nr_blocks;
16         const char      *name;
17 };
18
19 static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
20         {
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         {
36                 .id                     = 0x3013,
37                 .nr_blocks              = 8,
38                 .name                   = "W25X40",
39         },
40         {
41                 .id                     = 0x3015,
42                 .nr_blocks              = 32,
43                 .name                   = "W25X16",
44         },
45         {
46                 .id                     = 0x3016,
47                 .nr_blocks              = 64,
48                 .name                   = "W25X32",
49         },
50         {
51                 .id                     = 0x3017,
52                 .nr_blocks              = 128,
53                 .name                   = "W25X64",
54         },
55         {
56                 .id                     = 0x4014,
57                 .nr_blocks              = 16,
58                 .name                   = "W25Q80BL/W25Q80BV",
59         },
60         {
61                 .id                     = 0x4015,
62                 .nr_blocks              = 32,
63                 .name                   = "W25Q16CL/W25Q16DV",
64         },
65         {
66                 .id                     = 0x4016,
67                 .nr_blocks              = 64,
68                 .name                   = "W25Q32BV/W25Q32FV_SPI",
69         },
70         {
71                 .id                     = 0x4017,
72                 .nr_blocks              = 128,
73                 .name                   = "W25Q64CV/W25Q64FV_SPI",
74         },
75         {
76                 .id                     = 0x4018,
77                 .nr_blocks              = 256,
78                 .name                   = "W25Q128BV/W25Q128FV_SPI",
79         },
80         {
81                 .id                     = 0x4019,
82                 .nr_blocks              = 512,
83                 .name                   = "W25Q256",
84         },
85         {
86                 .id                     = 0x5014,
87                 .nr_blocks              = 16,
88                 .name                   = "W25Q80BW",
89         },
90         {
91                 .id                     = 0x6015,
92                 .nr_blocks              = 32,
93                 .name                   = "W25Q16DW",
94         },
95         {
96                 .id                     = 0x6016,
97                 .nr_blocks              = 64,
98                 .name                   = "W25Q32DW/W25Q32FV_QPI",
99         },
100         {
101                 .id                     = 0x6017,
102                 .nr_blocks              = 128,
103                 .name                   = "W25Q64DW/W25Q64FV_QPI",
104         },
105         {
106                 .id                     = 0x6018,
107                 .nr_blocks              = 256,
108                 .name                   = "W25Q128FW/W25Q128FV_QPI",
109         },
110 };
111
112 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
113 {
114         const struct winbond_spi_flash_params *params;
115         struct spi_flash *flash;
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
130         flash = spi_flash_alloc_base(spi, params->name);
131         if (!flash) {
132                 debug("SF: Failed to allocate memory\n");
133                 return NULL;
134         }
135
136         flash->page_size = 256;
137         flash->sector_size = (idcode[1] == 0x20) ? 65536 : 4096;
138         flash->size = 4096 * 16 * params->nr_blocks;
139
140         return flash;
141 }