xref: /openbmc/linux/drivers/mtd/spi-nor/micron-st.c (revision 15e3ae36)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2005, Intec Automation Inc.
4  * Copyright (C) 2014, Freescale Semiconductor, Inc.
5  */
6 
7 #include <linux/mtd/spi-nor.h>
8 
9 #include "core.h"
10 
11 static const struct flash_info micron_parts[] = {
12 	{ "mt35xu512aba", INFO(0x2c5b1a, 0, 128 * 1024, 512,
13 			       SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ |
14 			       SPI_NOR_4B_OPCODES) },
15 	{ "mt35xu02g", INFO(0x2c5b1c, 0, 128 * 1024, 2048,
16 			    SECT_4K | USE_FSR | SPI_NOR_OCTAL_READ |
17 			    SPI_NOR_4B_OPCODES) },
18 };
19 
20 static const struct flash_info st_parts[] = {
21 	{ "n25q016a",	 INFO(0x20bb15, 0, 64 * 1024,   32,
22 			      SECT_4K | SPI_NOR_QUAD_READ) },
23 	{ "n25q032",	 INFO(0x20ba16, 0, 64 * 1024,   64,
24 			      SPI_NOR_QUAD_READ) },
25 	{ "n25q032a",	 INFO(0x20bb16, 0, 64 * 1024,   64,
26 			      SPI_NOR_QUAD_READ) },
27 	{ "n25q064",     INFO(0x20ba17, 0, 64 * 1024,  128,
28 			      SECT_4K | SPI_NOR_QUAD_READ) },
29 	{ "n25q064a",    INFO(0x20bb17, 0, 64 * 1024,  128,
30 			      SECT_4K | SPI_NOR_QUAD_READ) },
31 	{ "n25q128a11",  INFO(0x20bb18, 0, 64 * 1024,  256,
32 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
33 	{ "n25q128a13",  INFO(0x20ba18, 0, 64 * 1024,  256,
34 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
35 	{ "mt25ql256a",  INFO6(0x20ba19, 0x104400, 64 * 1024,  512,
36 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
37 			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
38 	{ "n25q256a",    INFO(0x20ba19, 0, 64 * 1024,  512, SECT_4K |
39 			      USE_FSR | SPI_NOR_DUAL_READ |
40 			      SPI_NOR_QUAD_READ) },
41 	{ "mt25qu256a",  INFO6(0x20bb19, 0x104400, 64 * 1024,  512,
42 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
43 			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
44 	{ "n25q256ax1",  INFO(0x20bb19, 0, 64 * 1024,  512,
45 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ) },
46 	{ "mt25ql512a",  INFO6(0x20ba20, 0x104400, 64 * 1024, 1024,
47 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
48 			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
49 	{ "n25q512ax3",  INFO(0x20ba20, 0, 64 * 1024, 1024,
50 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
51 			      SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
52 			      SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
53 	{ "mt25qu512a",  INFO6(0x20bb20, 0x104400, 64 * 1024, 1024,
54 			       SECT_4K | USE_FSR | SPI_NOR_DUAL_READ |
55 			       SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) },
56 	{ "n25q512a",    INFO(0x20bb20, 0, 64 * 1024, 1024,
57 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
58 			      SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB |
59 			      SPI_NOR_4BIT_BP | SPI_NOR_BP3_SR_BIT6) },
60 	{ "n25q00",      INFO(0x20ba21, 0, 64 * 1024, 2048,
61 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
62 			      NO_CHIP_ERASE) },
63 	{ "n25q00a",     INFO(0x20bb21, 0, 64 * 1024, 2048,
64 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
65 			      NO_CHIP_ERASE) },
66 	{ "mt25ql02g",   INFO(0x20ba22, 0, 64 * 1024, 4096,
67 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
68 			      NO_CHIP_ERASE) },
69 	{ "mt25qu02g",   INFO(0x20bb22, 0, 64 * 1024, 4096,
70 			      SECT_4K | USE_FSR | SPI_NOR_QUAD_READ |
71 			      NO_CHIP_ERASE) },
72 
73 	{ "m25p05",  INFO(0x202010,  0,  32 * 1024,   2, 0) },
74 	{ "m25p10",  INFO(0x202011,  0,  32 * 1024,   4, 0) },
75 	{ "m25p20",  INFO(0x202012,  0,  64 * 1024,   4, 0) },
76 	{ "m25p40",  INFO(0x202013,  0,  64 * 1024,   8, 0) },
77 	{ "m25p80",  INFO(0x202014,  0,  64 * 1024,  16, 0) },
78 	{ "m25p16",  INFO(0x202015,  0,  64 * 1024,  32, 0) },
79 	{ "m25p32",  INFO(0x202016,  0,  64 * 1024,  64, 0) },
80 	{ "m25p64",  INFO(0x202017,  0,  64 * 1024, 128, 0) },
81 	{ "m25p128", INFO(0x202018,  0, 256 * 1024,  64, 0) },
82 
83 	{ "m25p05-nonjedec",  INFO(0, 0,  32 * 1024,   2, 0) },
84 	{ "m25p10-nonjedec",  INFO(0, 0,  32 * 1024,   4, 0) },
85 	{ "m25p20-nonjedec",  INFO(0, 0,  64 * 1024,   4, 0) },
86 	{ "m25p40-nonjedec",  INFO(0, 0,  64 * 1024,   8, 0) },
87 	{ "m25p80-nonjedec",  INFO(0, 0,  64 * 1024,  16, 0) },
88 	{ "m25p16-nonjedec",  INFO(0, 0,  64 * 1024,  32, 0) },
89 	{ "m25p32-nonjedec",  INFO(0, 0,  64 * 1024,  64, 0) },
90 	{ "m25p64-nonjedec",  INFO(0, 0,  64 * 1024, 128, 0) },
91 	{ "m25p128-nonjedec", INFO(0, 0, 256 * 1024,  64, 0) },
92 
93 	{ "m45pe10", INFO(0x204011,  0, 64 * 1024,    2, 0) },
94 	{ "m45pe80", INFO(0x204014,  0, 64 * 1024,   16, 0) },
95 	{ "m45pe16", INFO(0x204015,  0, 64 * 1024,   32, 0) },
96 
97 	{ "m25pe20", INFO(0x208012,  0, 64 * 1024,  4,       0) },
98 	{ "m25pe80", INFO(0x208014,  0, 64 * 1024, 16,       0) },
99 	{ "m25pe16", INFO(0x208015,  0, 64 * 1024, 32, SECT_4K) },
100 
101 	{ "m25px16",    INFO(0x207115,  0, 64 * 1024, 32, SECT_4K) },
102 	{ "m25px32",    INFO(0x207116,  0, 64 * 1024, 64, SECT_4K) },
103 	{ "m25px32-s0", INFO(0x207316,  0, 64 * 1024, 64, SECT_4K) },
104 	{ "m25px32-s1", INFO(0x206316,  0, 64 * 1024, 64, SECT_4K) },
105 	{ "m25px64",    INFO(0x207117,  0, 64 * 1024, 128, 0) },
106 	{ "m25px80",    INFO(0x207114,  0, 64 * 1024, 16, 0) },
107 };
108 
109 /**
110  * st_micron_set_4byte_addr_mode() - Set 4-byte address mode for ST and Micron
111  * flashes.
112  * @nor:	pointer to 'struct spi_nor'.
113  * @enable:	true to enter the 4-byte address mode, false to exit the 4-byte
114  *		address mode.
115  *
116  * Return: 0 on success, -errno otherwise.
117  */
118 static int st_micron_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
119 {
120 	int ret;
121 
122 	ret = spi_nor_write_enable(nor);
123 	if (ret)
124 		return ret;
125 
126 	ret = spi_nor_set_4byte_addr_mode(nor, enable);
127 	if (ret)
128 		return ret;
129 
130 	return spi_nor_write_disable(nor);
131 }
132 
133 static void micron_st_default_init(struct spi_nor *nor)
134 {
135 	nor->flags |= SNOR_F_HAS_LOCK;
136 	nor->flags &= ~SNOR_F_HAS_16BIT_SR;
137 	nor->params->quad_enable = NULL;
138 	nor->params->set_4byte_addr_mode = st_micron_set_4byte_addr_mode;
139 }
140 
141 static const struct spi_nor_fixups micron_st_fixups = {
142 	.default_init = micron_st_default_init,
143 };
144 
145 const struct spi_nor_manufacturer spi_nor_micron = {
146 	.name = "micron",
147 	.parts = micron_parts,
148 	.nparts = ARRAY_SIZE(micron_parts),
149 	.fixups = &micron_st_fixups,
150 };
151 
152 const struct spi_nor_manufacturer spi_nor_st = {
153 	.name = "st",
154 	.parts = st_parts,
155 	.nparts = ARRAY_SIZE(st_parts),
156 	.fixups = &micron_st_fixups,
157 };
158