2 * Copyright 2009(C) Marvell International Ltd. and its affiliates
3 * Prafulla Wadaskar <prafulla@marvell.com>
5 * Based on drivers/mtd/spi/stmicro.c
7 * Copyright 2008, Network Appliance Inc.
8 * Jason McMullan <mcmullan@netapp.com>
10 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
11 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
13 * See file CREDITS for list of people who contributed to this
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.
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.
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,
34 #include <spi_flash.h>
36 #include "spi_flash_internal.h"
38 /* MX25xx-specific commands */
39 #define CMD_MX25XX_WREN 0x06 /* Write Enable */
40 #define CMD_MX25XX_WRDI 0x04 /* Write Disable */
41 #define CMD_MX25XX_RDSR 0x05 /* Read Status Register */
42 #define CMD_MX25XX_WRSR 0x01 /* Write Status Register */
43 #define CMD_MX25XX_READ 0x03 /* Read Data Bytes */
44 #define CMD_MX25XX_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
45 #define CMD_MX25XX_PP 0x02 /* Page Program */
46 #define CMD_MX25XX_SE 0x20 /* Sector Erase */
47 #define CMD_MX25XX_BE 0xD8 /* Block Erase */
48 #define CMD_MX25XX_CE 0xc7 /* Chip Erase */
49 #define CMD_MX25XX_DP 0xb9 /* Deep Power-down */
50 #define CMD_MX25XX_RES 0xab /* Release from DP, and Read Signature */
52 struct macronix_spi_flash_params {
56 u16 sectors_per_block;
61 static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
65 .pages_per_sector = 16,
66 .sectors_per_block = 16,
73 .pages_per_sector = 16,
74 .sectors_per_block = 16,
81 .pages_per_sector = 16,
82 .sectors_per_block = 16,
89 .pages_per_sector = 16,
90 .sectors_per_block = 16,
92 .name = "MX25L12805D",
97 .pages_per_sector = 16,
98 .sectors_per_block = 16,
100 .name = "MX25L12855E",
104 static int macronix_erase(struct spi_flash *flash, u32 offset, size_t len)
106 return spi_flash_cmd_erase(flash, CMD_MX25XX_BE, offset, len);
109 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
111 const struct macronix_spi_flash_params *params;
112 struct spi_flash *flash;
114 u16 id = idcode[2] | idcode[1] << 8;
116 for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) {
117 params = ¯onix_spi_flash_table[i];
118 if (params->idcode == id)
122 if (i == ARRAY_SIZE(macronix_spi_flash_table)) {
123 debug("SF: Unsupported Macronix ID %04x\n", id);
127 flash = malloc(sizeof(*flash));
129 debug("SF: Failed to allocate memory\n");
134 flash->name = params->name;
136 flash->write = spi_flash_cmd_write_multi;
137 flash->erase = macronix_erase;
138 flash->read = spi_flash_cmd_read_fast;
139 flash->page_size = params->page_size;
140 flash->sector_size = params->page_size * params->pages_per_sector
141 * params->sectors_per_block;
142 flash->size = flash->sector_size * params->nr_blocks;