blob: d1358ea24b74f5ac838c6f54ed66a8dbdc3f3509 [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
13/* M25Pxx-specific commands */
Jason McMulland394a772009-10-09 17:12:23 -040014#define CMD_W25_SE 0x20 /* Sector (4K) Erase */
15#define CMD_W25_BE 0xd8 /* Block (64K) Erase */
16#define CMD_W25_CE 0xc7 /* Chip Erase */
Jason McMulland394a772009-10-09 17:12:23 -040017
Jason McMulland394a772009-10-09 17:12:23 -040018struct winbond_spi_flash_params {
19 uint16_t id;
Wojtek Skulski93eab862010-12-07 01:07:45 -050020 uint16_t nr_blocks;
Jason McMulland394a772009-10-09 17:12:23 -040021 const char *name;
22};
23
Jason McMulland394a772009-10-09 17:12:23 -040024static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
25 {
James Le Cuirotad8e3bd2011-07-15 06:12:51 +000026 .id = 0x3013,
James Le Cuirotad8e3bd2011-07-15 06:12:51 +000027 .nr_blocks = 8,
28 .name = "W25X40",
29 },
30 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050031 .id = 0x3015,
Jason McMulland394a772009-10-09 17:12:23 -040032 .nr_blocks = 32,
33 .name = "W25X16",
34 },
35 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050036 .id = 0x3016,
Jason McMulland394a772009-10-09 17:12:23 -040037 .nr_blocks = 64,
38 .name = "W25X32",
39 },
40 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050041 .id = 0x3017,
Jason McMulland394a772009-10-09 17:12:23 -040042 .nr_blocks = 128,
43 .name = "W25X64",
44 },
Graeme Smecher74f9e0d2010-07-29 09:00:02 -040045 {
Stephen Warren1edaf092012-05-24 11:38:34 +000046 .id = 0x4014,
Stephen Warren1edaf092012-05-24 11:38:34 +000047 .nr_blocks = 16,
48 .name = "W25Q80BL",
49 },
50 {
Wojtek Skulski93eab862010-12-07 01:07:45 -050051 .id = 0x4015,
Wojtek Skulski93eab862010-12-07 01:07:45 -050052 .nr_blocks = 32,
53 .name = "W25Q16",
54 },
55 {
56 .id = 0x4016,
Wojtek Skulski93eab862010-12-07 01:07:45 -050057 .nr_blocks = 64,
58 .name = "W25Q32",
59 },
60 {
61 .id = 0x4017,
Graeme Smecher74f9e0d2010-07-29 09:00:02 -040062 .nr_blocks = 128,
63 .name = "W25Q64",
64 },
Wojtek Skulski93eab862010-12-07 01:07:45 -050065 {
66 .id = 0x4018,
Wojtek Skulski93eab862010-12-07 01:07:45 -050067 .nr_blocks = 256,
68 .name = "W25Q128",
69 },
Jason McMulland394a772009-10-09 17:12:23 -040070};
71
Mike Frysingerf8f07572011-04-12 01:51:29 -040072static int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
Jason McMulland394a772009-10-09 17:12:23 -040073{
Richard Retanubun4e6a5152011-02-16 16:37:22 -050074 return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
Jason McMulland394a772009-10-09 17:12:23 -040075}
76
77struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
78{
79 const struct winbond_spi_flash_params *params;
Mike Frysingerb06afa72011-06-28 07:38:10 +000080 struct spi_flash *flash;
Jason McMulland394a772009-10-09 17:12:23 -040081 unsigned int i;
82
83 for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
84 params = &winbond_spi_flash_table[i];
85 if (params->id == ((idcode[1] << 8) | idcode[2]))
86 break;
87 }
88
89 if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
90 debug("SF: Unsupported Winbond ID %02x%02x\n",
91 idcode[1], idcode[2]);
92 return NULL;
93 }
94
Mike Frysingerb06afa72011-06-28 07:38:10 +000095 flash = malloc(sizeof(*flash));
96 if (!flash) {
Jason McMulland394a772009-10-09 17:12:23 -040097 debug("SF: Failed to allocate memory\n");
98 return NULL;
99 }
100
Mike Frysingerb06afa72011-06-28 07:38:10 +0000101 flash->spi = spi;
102 flash->name = params->name;
Jason McMulland394a772009-10-09 17:12:23 -0400103
Mike Frysingerb06afa72011-06-28 07:38:10 +0000104 flash->write = spi_flash_cmd_write_multi;
105 flash->erase = winbond_erase;
106 flash->read = spi_flash_cmd_read_fast;
Mike Frysingera4ed3b62012-03-04 22:56:52 -0500107 flash->page_size = 4096;
108 flash->sector_size = 4096;
109 flash->size = 4096 * 16 * params->nr_blocks;
Jason McMulland394a772009-10-09 17:12:23 -0400110
Mike Frysingerb06afa72011-06-28 07:38:10 +0000111 return flash;
Jason McMulland394a772009-10-09 17:12:23 -0400112}