blob: 3560fcb6ba9a0e776af208caa8fb79920105768a [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 {
James Le Cuirotad8e3bd2011-07-15 06:12:51 +000021 .id = 0x3013,
James Le Cuirotad8e3bd2011-07-15 06:12:51 +000022 .nr_blocks = 8,
23 .name = "W25X40",
24 },
25 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050026 .id = 0x3015,
Jason McMulland394a772009-10-09 17:12:23 -040027 .nr_blocks = 32,
28 .name = "W25X16",
29 },
30 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050031 .id = 0x3016,
Jason McMulland394a772009-10-09 17:12:23 -040032 .nr_blocks = 64,
33 .name = "W25X32",
34 },
35 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050036 .id = 0x3017,
Jason McMulland394a772009-10-09 17:12:23 -040037 .nr_blocks = 128,
38 .name = "W25X64",
39 },
Graeme Smecher74f9e0d2010-07-29 09:00:02 -040040 {
Stephen Warren1edaf092012-05-24 11:38:34 +000041 .id = 0x4014,
Stephen Warren1edaf092012-05-24 11:38:34 +000042 .nr_blocks = 16,
43 .name = "W25Q80BL",
44 },
45 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050046 .id = 0x4015,
Wojtek Skulski93eab862010-12-07 01:07:45 -050047 .nr_blocks = 32,
48 .name = "W25Q16",
49 },
50 {
51 .id = 0x4016,
Wojtek Skulski93eab862010-12-07 01:07:45 -050052 .nr_blocks = 64,
53 .name = "W25Q32",
54 },
55 {
56 .id = 0x4017,
Graeme Smecher74f9e0d2010-07-29 09:00:02 -040057 .nr_blocks = 128,
58 .name = "W25Q64",
59 },
Wojtek Skulski93eab862010-12-07 01:07:45 -050060 {
61 .id = 0x4018,
Wojtek Skulski93eab862010-12-07 01:07:45 -050062 .nr_blocks = 256,
63 .name = "W25Q128",
64 },
Rajeshwari Shindec969abc2012-08-02 12:55:05 +053065 {
66 .id = 0x5014,
67 .nr_blocks = 128,
68 .name = "W25Q80",
69 },
Jagannadha Sutradharudu Teki5818a092013-01-23 13:29:29 +010070 {
Allen Martin772ba152013-03-16 18:58:08 +000071 .id = 0x6016,
72 .nr_blocks = 512,
73 .name = "W25Q32DW",
74 },
75 {
Jagannadha Sutradharudu Teki5818a092013-01-23 13:29:29 +010076 .id = 0x6017,
77 .nr_blocks = 128,
78 .name = "W25Q64DW",
79 },
Jason McMulland394a772009-10-09 17:12:23 -040080};
81
Jason McMulland394a772009-10-09 17:12:23 -040082struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
83{
84 const struct winbond_spi_flash_params *params;
Mike Frysingerb06afa72011-06-28 07:38:10 +000085 struct spi_flash *flash;
Jason McMulland394a772009-10-09 17:12:23 -040086 unsigned int i;
87
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 }
93
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 }
99
Mike Frysingerb06afa72011-06-28 07:38:10 +0000100 flash = malloc(sizeof(*flash));
101 if (!flash) {
Jason McMulland394a772009-10-09 17:12:23 -0400102 debug("SF: Failed to allocate memory\n");
103 return NULL;
104 }
105
Mike Frysingerb06afa72011-06-28 07:38:10 +0000106 flash->spi = spi;
107 flash->name = params->name;
Jason McMulland394a772009-10-09 17:12:23 -0400108
Mike Frysingerb06afa72011-06-28 07:38:10 +0000109 flash->write = spi_flash_cmd_write_multi;
Mike Frysingerc4e932c2012-03-04 22:35:50 -0500110 flash->erase = spi_flash_cmd_erase;
Mike Frysingerb06afa72011-06-28 07:38:10 +0000111 flash->read = spi_flash_cmd_read_fast;
Stephen Warrenc75942c2012-08-13 16:46:21 -0600112 flash->page_size = 256;
Mike Frysingera4ed3b62012-03-04 22:56:52 -0500113 flash->sector_size = 4096;
114 flash->size = 4096 * 16 * params->nr_blocks;
Jason McMulland394a772009-10-09 17:12:23 -0400115
Mike Frysingerb06afa72011-06-28 07:38:10 +0000116 return flash;
Jason McMulland394a772009-10-09 17:12:23 -0400117}