]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/mtd/spi/macronix.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[karo-tx-uboot.git] / drivers / mtd / spi / macronix.c
1 /*
2  * Copyright 2009(C) Marvell International Ltd. and its affiliates
3  * Prafulla Wadaskar <prafulla@marvell.com>
4  *
5  * Based on drivers/mtd/spi/stmicro.c
6  *
7  * Copyright 2008, Network Appliance Inc.
8  * Jason McMullan <mcmullan@netapp.com>
9  *
10  * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
11  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
12  *
13  * SPDX-License-Identifier:     GPL-2.0+
14  */
15
16 #include <common.h>
17 #include <malloc.h>
18 #include <spi_flash.h>
19
20 #include "spi_flash_internal.h"
21
22 struct macronix_spi_flash_params {
23         u16 idcode;
24         u16 nr_blocks;
25         const char *name;
26 };
27
28 static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
29         {
30                 .idcode = 0x2013,
31                 .nr_blocks = 8,
32                 .name = "MX25L4005",
33         },
34         {
35                 .idcode = 0x2014,
36                 .nr_blocks = 16,
37                 .name = "MX25L8005",
38         },
39         {
40                 .idcode = 0x2015,
41                 .nr_blocks = 32,
42                 .name = "MX25L1605D",
43         },
44         {
45                 .idcode = 0x2016,
46                 .nr_blocks = 64,
47                 .name = "MX25L3205D",
48         },
49         {
50                 .idcode = 0x2017,
51                 .nr_blocks = 128,
52                 .name = "MX25L6405D",
53         },
54         {
55                 .idcode = 0x2018,
56                 .nr_blocks = 256,
57                 .name = "MX25L12805D",
58         },
59         {
60                 .idcode = 0x2618,
61                 .nr_blocks = 256,
62                 .name = "MX25L12855E",
63         },
64 };
65
66 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
67 {
68         const struct macronix_spi_flash_params *params;
69         struct spi_flash *flash;
70         unsigned int i;
71         u16 id = idcode[2] | idcode[1] << 8;
72
73         for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) {
74                 params = &macronix_spi_flash_table[i];
75                 if (params->idcode == id)
76                         break;
77         }
78
79         if (i == ARRAY_SIZE(macronix_spi_flash_table)) {
80                 debug("SF: Unsupported Macronix ID %04x\n", id);
81                 return NULL;
82         }
83
84         flash = spi_flash_alloc_base(spi, params->name);
85         if (!flash) {
86                 debug("SF: Failed to allocate memory\n");
87                 return NULL;
88         }
89
90         flash->page_size = 256;
91         flash->sector_size = 256 * 16 * 16;
92         flash->size = flash->sector_size * params->nr_blocks;
93
94         /* Clear BP# bits for read-only flash */
95         spi_flash_cmd_write_status(flash, 0);
96
97         return flash;
98 }