2009-04-06 15:54:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2009(C) Marvell International Ltd. and its affiliates
|
|
|
|
* Prafulla Wadaskar <prafulla@marvell.com>
|
|
|
|
*
|
|
|
|
* Based on drivers/mtd/spi/stmicro.c
|
|
|
|
*
|
|
|
|
* Copyright 2008, Network Appliance Inc.
|
|
|
|
* Jason McMullan <mcmullan@netapp.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
|
|
|
|
* TsiChung Liew (Tsi-Chung.Liew@freescale.com)
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <spi_flash.h>
|
|
|
|
|
|
|
|
#include "spi_flash_internal.h"
|
|
|
|
|
|
|
|
struct macronix_spi_flash_params {
|
2009-07-06 14:59:15 +00:00
|
|
|
u16 idcode;
|
2009-04-06 15:54:43 +00:00
|
|
|
u16 nr_blocks;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
|
2011-04-20 16:51:39 +00:00
|
|
|
{
|
|
|
|
.idcode = 0x2013,
|
|
|
|
.nr_blocks = 8,
|
|
|
|
.name = "MX25L4005",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.idcode = 0x2014,
|
|
|
|
.nr_blocks = 16,
|
|
|
|
.name = "MX25L8005",
|
|
|
|
},
|
2009-04-06 15:54:43 +00:00
|
|
|
{
|
2009-07-06 14:59:15 +00:00
|
|
|
.idcode = 0x2015,
|
|
|
|
.nr_blocks = 32,
|
|
|
|
.name = "MX25L1605D",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.idcode = 0x2016,
|
|
|
|
.nr_blocks = 64,
|
|
|
|
.name = "MX25L3205D",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.idcode = 0x2017,
|
|
|
|
.nr_blocks = 128,
|
|
|
|
.name = "MX25L6405D",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.idcode = 0x2018,
|
2009-04-06 15:54:43 +00:00
|
|
|
.nr_blocks = 256,
|
|
|
|
.name = "MX25L12805D",
|
|
|
|
},
|
2009-07-06 14:59:15 +00:00
|
|
|
{
|
|
|
|
.idcode = 0x2618,
|
|
|
|
.nr_blocks = 256,
|
|
|
|
.name = "MX25L12855E",
|
|
|
|
},
|
2009-04-06 15:54:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
|
|
|
|
{
|
|
|
|
const struct macronix_spi_flash_params *params;
|
2011-06-28 07:38:10 +00:00
|
|
|
struct spi_flash *flash;
|
2009-04-06 15:54:43 +00:00
|
|
|
unsigned int i;
|
2009-07-06 14:59:15 +00:00
|
|
|
u16 id = idcode[2] | idcode[1] << 8;
|
2009-04-06 15:54:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) {
|
|
|
|
params = ¯onix_spi_flash_table[i];
|
2009-07-06 14:59:15 +00:00
|
|
|
if (params->idcode == id)
|
2009-04-06 15:54:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == ARRAY_SIZE(macronix_spi_flash_table)) {
|
2009-07-06 14:59:15 +00:00
|
|
|
debug("SF: Unsupported Macronix ID %04x\n", id);
|
2009-04-06 15:54:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-28 07:38:10 +00:00
|
|
|
flash = malloc(sizeof(*flash));
|
|
|
|
if (!flash) {
|
2009-04-06 15:54:43 +00:00
|
|
|
debug("SF: Failed to allocate memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-28 07:38:10 +00:00
|
|
|
flash->spi = spi;
|
|
|
|
flash->name = params->name;
|
2009-04-06 15:54:43 +00:00
|
|
|
|
2011-06-28 07:38:10 +00:00
|
|
|
flash->write = spi_flash_cmd_write_multi;
|
2012-03-05 03:35:50 +00:00
|
|
|
flash->erase = spi_flash_cmd_erase;
|
2011-06-28 07:38:10 +00:00
|
|
|
flash->read = spi_flash_cmd_read_fast;
|
2012-03-05 03:56:52 +00:00
|
|
|
flash->page_size = 256;
|
|
|
|
flash->sector_size = 256 * 16 * 16;
|
2011-06-28 07:38:10 +00:00
|
|
|
flash->size = flash->sector_size * params->nr_blocks;
|
2009-04-06 15:54:43 +00:00
|
|
|
|
2011-05-02 11:01:38 +00:00
|
|
|
/* Clear BP# bits for read-only flash */
|
2012-03-05 04:18:17 +00:00
|
|
|
spi_flash_cmd_write_status(flash, 0);
|
2011-05-02 11:01:38 +00:00
|
|
|
|
2011-06-28 07:38:10 +00:00
|
|
|
return flash;
|
2009-04-06 15:54:43 +00:00
|
|
|
}
|