]>
Commit | Line | Data |
---|---|---|
7ce6031a PW |
1 | /* |
2 | * Copyright 2009(C) Marvell International Ltd. and its affiliates | |
3 | * Prafulla Wadaskar <prafulla@marvell.com> | |
4 | * | |
5 | * Based on drivers/mtd/spi/stmicro.c | |
6 | * | |
7 | * Copyright 2008, Network Appliance Inc. | |
8 | * Jason McMullan <mcmullan@netapp.com> | |
9 | * | |
10 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. | |
11 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) | |
12 | * | |
13 | * See file CREDITS for list of people who contributed to this | |
14 | * project. | |
15 | * | |
16 | * This program is free software; you can redistribute it and/or | |
17 | * modify it under the terms of the GNU General Public License as | |
18 | * published by the Free Software Foundation; either version 2 of | |
19 | * the License, or (at your option) any later version. | |
20 | * | |
21 | * This program is distributed in the hope that it will be useful, | |
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | * GNU General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU General Public License | |
27 | * along with this program; if not, write to the Free Software | |
28 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
29 | * MA 02110-1301 USA | |
30 | */ | |
31 | ||
32 | #include <common.h> | |
33 | #include <malloc.h> | |
34 | #include <spi_flash.h> | |
35 | ||
36 | #include "spi_flash_internal.h" | |
37 | ||
7ce6031a | 38 | struct macronix_spi_flash_params { |
2efee52b | 39 | u16 idcode; |
7ce6031a PW |
40 | u16 nr_blocks; |
41 | const char *name; | |
42 | }; | |
43 | ||
7ce6031a | 44 | static const struct macronix_spi_flash_params macronix_spi_flash_table[] = { |
2d722e05 ML |
45 | { |
46 | .idcode = 0x2013, | |
2d722e05 ML |
47 | .nr_blocks = 8, |
48 | .name = "MX25L4005", | |
49 | }, | |
50 | { | |
51 | .idcode = 0x2014, | |
2d722e05 ML |
52 | .nr_blocks = 16, |
53 | .name = "MX25L8005", | |
54 | }, | |
7ce6031a | 55 | { |
2efee52b | 56 | .idcode = 0x2015, |
2efee52b PW |
57 | .nr_blocks = 32, |
58 | .name = "MX25L1605D", | |
59 | }, | |
60 | { | |
61 | .idcode = 0x2016, | |
2efee52b PW |
62 | .nr_blocks = 64, |
63 | .name = "MX25L3205D", | |
64 | }, | |
65 | { | |
66 | .idcode = 0x2017, | |
2efee52b PW |
67 | .nr_blocks = 128, |
68 | .name = "MX25L6405D", | |
69 | }, | |
70 | { | |
71 | .idcode = 0x2018, | |
7ce6031a PW |
72 | .nr_blocks = 256, |
73 | .name = "MX25L12805D", | |
74 | }, | |
2efee52b PW |
75 | { |
76 | .idcode = 0x2618, | |
2efee52b PW |
77 | .nr_blocks = 256, |
78 | .name = "MX25L12855E", | |
79 | }, | |
7ce6031a PW |
80 | }; |
81 | ||
7ce6031a PW |
82 | struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode) |
83 | { | |
84 | const struct macronix_spi_flash_params *params; | |
b06afa75 | 85 | struct spi_flash *flash; |
7ce6031a | 86 | unsigned int i; |
2efee52b | 87 | u16 id = idcode[2] | idcode[1] << 8; |
7ce6031a PW |
88 | |
89 | for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) { | |
90 | params = ¯onix_spi_flash_table[i]; | |
2efee52b | 91 | if (params->idcode == id) |
7ce6031a PW |
92 | break; |
93 | } | |
94 | ||
95 | if (i == ARRAY_SIZE(macronix_spi_flash_table)) { | |
2efee52b | 96 | debug("SF: Unsupported Macronix ID %04x\n", id); |
7ce6031a PW |
97 | return NULL; |
98 | } | |
99 | ||
b06afa75 MF |
100 | flash = malloc(sizeof(*flash)); |
101 | if (!flash) { | |
7ce6031a PW |
102 | debug("SF: Failed to allocate memory\n"); |
103 | return NULL; | |
104 | } | |
105 | ||
b06afa75 MF |
106 | flash->spi = spi; |
107 | flash->name = params->name; | |
7ce6031a | 108 | |
b06afa75 | 109 | flash->write = spi_flash_cmd_write_multi; |
c4e932ce | 110 | flash->erase = spi_flash_cmd_erase; |
b06afa75 | 111 | flash->read = spi_flash_cmd_read_fast; |
a4ed3b65 MF |
112 | flash->page_size = 256; |
113 | flash->sector_size = 256 * 16 * 16; | |
b06afa75 | 114 | flash->size = flash->sector_size * params->nr_blocks; |
7ce6031a | 115 | |
7432ed05 | 116 | /* Clear BP# bits for read-only flash */ |
41e17134 | 117 | spi_flash_cmd_write_status(flash, 0); |
7432ed05 | 118 | |
b06afa75 | 119 | return flash; |
7ce6031a | 120 | } |