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 * SPDX-License-Identifier: GPL-2.0+
18 #include <spi_flash.h>
20 #include "spi_flash_internal.h"
22 struct macronix_spi_flash_params {
28 static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
57 .name = "MX25L12805D",
62 .name = "MX25L12855E",
66 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
68 const struct macronix_spi_flash_params *params;
69 struct spi_flash *flash;
71 u16 id = idcode[2] | idcode[1] << 8;
73 for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) {
74 params = ¯onix_spi_flash_table[i];
75 if (params->idcode == id)
79 if (i == ARRAY_SIZE(macronix_spi_flash_table)) {
80 debug("SF: Unsupported Macronix ID %04x\n", id);
84 flash = spi_flash_alloc_base(spi, params->name);
86 debug("SF: Failed to allocate memory\n");
90 flash->page_size = 256;
91 flash->sector_size = 256 * 16 * 16;
92 flash->size = flash->sector_size * params->nr_blocks;
94 /* Clear BP# bits for read-only flash */
95 spi_flash_cmd_write_status(flash, 0);