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)
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2009-04-06 15:54:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2013-03-11 06:08:03 +00:00
|
|
|
flash = spi_flash_alloc_base(spi, params->name);
|
2011-06-28 07:38:10 +00:00
|
|
|
if (!flash) {
|
2009-04-06 15:54:43 +00:00
|
|
|
debug("SF: Failed to allocate memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|