]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/glsdk-u-boot.git/blob - drivers/mtd/spi/winbond.c
Merge branch 'u-boot/master' into 'u-boot-arm/master'
[glsdk/glsdk-u-boot.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  */
7 #include <common.h>
8 #include <malloc.h>
9 #include <spi_flash.h>
11 #include "spi_flash_internal.h"
13 struct winbond_spi_flash_params {
14         uint16_t        id;
15         uint16_t        nr_blocks;
16         const char      *name;
17 };
19 static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
20         {
21                 .id                     = 0x3013,
22                 .nr_blocks              = 8,
23                 .name                   = "W25X40",
24         },
25         {
26                 .id                     = 0x3015,
27                 .nr_blocks              = 32,
28                 .name                   = "W25X16",
29         },
30         {
31                 .id                     = 0x3016,
32                 .nr_blocks              = 64,
33                 .name                   = "W25X32",
34         },
35         {
36                 .id                     = 0x3017,
37                 .nr_blocks              = 128,
38                 .name                   = "W25X64",
39         },
40         {
41                 .id                     = 0x4014,
42                 .nr_blocks              = 16,
43                 .name                   = "W25Q80BL",
44         },
45         {
46                 .id                     = 0x4015,
47                 .nr_blocks              = 32,
48                 .name                   = "W25Q16",
49         },
50         {
51                 .id                     = 0x4016,
52                 .nr_blocks              = 64,
53                 .name                   = "W25Q32",
54         },
55         {
56                 .id                     = 0x4017,
57                 .nr_blocks              = 128,
58                 .name                   = "W25Q64",
59         },
60         {
61                 .id                     = 0x4018,
62                 .nr_blocks              = 256,
63                 .name                   = "W25Q128",
64         },
65         {
66                 .id                     = 0x5014,
67                 .nr_blocks              = 128,
68                 .name                   = "W25Q80",
69         },
70         {
71                 .id                     = 0x6016,
72                 .nr_blocks              = 512,
73                 .name                   = "W25Q32DW",
74         },
75         {
76                 .id                     = 0x6017,
77                 .nr_blocks              = 128,
78                 .name                   = "W25Q64DW",
79         },
80 };
82 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
83 {
84         const struct winbond_spi_flash_params *params;
85         struct spi_flash *flash;
86         unsigned int i;
88         for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
89                 params = &winbond_spi_flash_table[i];
90                 if (params->id == ((idcode[1] << 8) | idcode[2]))
91                         break;
92         }
94         if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
95                 debug("SF: Unsupported Winbond ID %02x%02x\n",
96                                 idcode[1], idcode[2]);
97                 return NULL;
98         }
100         flash = spi_flash_alloc_base(spi, params->name);
101         if (!flash) {
102                 debug("SF: Failed to allocate memory\n");
103                 return NULL;
104         }
106         flash->page_size = 256;
107         flash->sector_size = 4096;
108         flash->size = 4096 * 16 * params->nr_blocks;
110         return flash;