2009-04-07 00:54:43 +09: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)
|
|
|
|
*
|
2013-07-08 16:37:19 +09:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2009-04-07 00:54:43 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <spi_flash.h>
|
|
|
|
|
|
|
|
#include "spi_flash_internal.h"
|
|
|
|
|
|
|
|
struct macronix_spi_flash_params {
|
2009-07-06 23:59:15 +09:00
|
|
|
u16 idcode;
|
2009-04-07 00:54:43 +09:00
|
|
|
u16 nr_blocks;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
|
2011-04-21 01:51:39 +09:00
|
|
|
{
|
|
|
|
.idcode = 0x2013,
|
|
|
|
.nr_blocks = 8,
|
|
|
|
.name = "MX25L4005",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.idcode = 0x2014,
|
|
|
|
.nr_blocks = 16,
|
|
|
|
.name = "MX25L8005",
|
|
|
|
},
|
2009-04-07 00:54:43 +09:00
|
|
|
{
|
2009-07-06 23:59:15 +09: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-07 00:54:43 +09:00
|
|
|
.nr_blocks = 256,
|
|
|
|
.name = "MX25L12805D",
|
|
|
|
},
|
2009-07-06 23:59:15 +09:00
|
|
|
{
|
|
|
|
.idcode = 0x2618,
|
|
|
|
.nr_blocks = 256,
|
|
|
|
.name = "MX25L12855E",
|
|
|
|
},
|
2009-04-07 00:54:43 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
|
|
|
|
{
|
|
|
|
const struct macronix_spi_flash_params *params;
|
2011-06-28 16:38:10 +09:00
|
|
|
struct spi_flash *flash;
|
2009-04-07 00:54:43 +09:00
|
|
|
unsigned int i;
|
2009-07-06 23:59:15 +09:00
|
|
|
u16 id = idcode[2] | idcode[1] << 8;
|
2009-04-07 00:54:43 +09:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) {
|
|
|
|
params = ¯onix_spi_flash_table[i];
|
2009-07-06 23:59:15 +09:00
|
|
|
if (params->idcode == id)
|
2009-04-07 00:54:43 +09:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == ARRAY_SIZE(macronix_spi_flash_table)) {
|
2009-07-06 23:59:15 +09:00
|
|
|
debug("SF: Unsupported Macronix ID %04x\n", id);
|
2009-04-07 00:54:43 +09:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-11 15:08:03 +09:00
|
|
|
flash = spi_flash_alloc_base(spi, params->name);
|
2011-06-28 16:38:10 +09:00
|
|
|
if (!flash) {
|
2009-04-07 00:54:43 +09:00
|
|
|
debug("SF: Failed to allocate memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-05 12:56:52 +09:00
|
|
|
flash->page_size = 256;
|
|
|
|
flash->sector_size = 256 * 16 * 16;
|
2011-06-28 16:38:10 +09:00
|
|
|
flash->size = flash->sector_size * params->nr_blocks;
|
2009-04-07 00:54:43 +09:00
|
|
|
|
2011-05-02 20:01:38 +09:00
|
|
|
/* Clear BP# bits for read-only flash */
|
2012-03-05 13:18:17 +09:00
|
|
|
spi_flash_cmd_write_status(flash, 0);
|
2011-05-02 20:01:38 +09:00
|
|
|
|
2011-06-28 16:38:10 +09:00
|
|
|
return flash;
|
2009-04-07 00:54:43 +09:00
|
|
|
}
|