summaryrefslogtreecommitdiff
path: root/src/drivers/spi/spansion.c
blob: 05c401959142e08054d27aabe3c30d22c4b73d99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include <commonlib/helpers.h>
#include <spi_flash.h>
#include <spi-generic.h>

#include "spi_flash_internal.h"

/* S25FLxx-specific commands */
#define CMD_S25FLXX_READ	0x03	/* Read Data Bytes */
#define CMD_S25FLXX_FAST_READ	0x0b	/* Read Data Bytes at Higher Speed */
#define CMD_S25FLXX_READID	0x90	/* Read Manufacture ID and Device ID */
#define CMD_S25FLXX_WREN	0x06	/* Write Enable */
#define CMD_S25FLXX_WRDI	0x04	/* Write Disable */
#define CMD_S25FLXX_RDSR	0x05	/* Read Status Register */
#define CMD_S25FLXX_WRSR	0x01	/* Write Status Register */
#define CMD_S25FLXX_PP		0x02	/* Page Program */
#define CMD_S25FLXX_SE		0xd8	/* Sector Erase */
#define CMD_S25FLXX_BE		0xc7	/* Bulk Erase */
#define CMD_S25FLXX_DP		0xb9	/* Deep Power-down */
#define CMD_S25FLXX_RES		0xab	/* Release from DP, and Read Signature */

#define SPSN_ID_S25FL008A	0x0213
#define SPSN_ID_S25FL016A	0x0214
#define SPSN_ID_S25FL032A	0x0215
#define SPSN_ID_S25FL064A	0x0216
#define SPSN_ID_S25FL128S	0x0219
#define SPSN_ID_S25FL128P	0x2018
#define SPSN_ID_S25FL208K	0x4014
#define SPSN_ID_S25FL116K	0x4015
#define SPSN_ID_S25FL132K	0x4016
#define SPSN_ID_S25FL164K	0x4017
#define SPSN_EXT_ID_S25FL128P_256KB	0x0300
#define SPSN_EXT_ID_S25FL128P_64KB	0x0301
#define SPSN_EXT_ID_S25FL032P		0x4d00
#define SPSN_EXT_ID_S25FLXXS_64KB	0x4d01

static const struct spi_flash_part_id flash_table_ext[] = {
	{
		/* S25FL008A */
		.id[0] = SPSN_ID_S25FL008A,
		.nr_sectors_shift = 4,
	},
	{
		/* S25FL016A */
		.id[0] = SPSN_ID_S25FL016A,
		.nr_sectors_shift = 5,
	},
	{
		/* S25FL032A */
		.id[0] = SPSN_ID_S25FL032A,
		.nr_sectors_shift = 6,
	},
	{
		/* S25FL064A */
		.id[0] = SPSN_ID_S25FL064A,
		.nr_sectors_shift = 7,
	},
	{
		/* S25FL128P_64K */
		.id[0] = SPSN_ID_S25FL128P,
		.id[1] = SPSN_EXT_ID_S25FL128P_64KB,
		.nr_sectors_shift = 8,
	},
	{
		/* S25FL128S_256K */
		.id[0] = SPSN_ID_S25FL128S,
		.id[1] = SPSN_EXT_ID_S25FLXXS_64KB,
		.nr_sectors_shift = 9,
	},
	{
		/* S25FL032P */
		.id[0] = SPSN_ID_S25FL032A,
		.id[1] = SPSN_EXT_ID_S25FL032P,
		.nr_sectors_shift = 6,
	},
	{
		/* S25FS128S */
		.id[0] = SPSN_ID_S25FL128P,
		.id[1] = SPSN_EXT_ID_S25FLXXS_64KB,
		.nr_sectors_shift = 8,
	},
};

static const struct spi_flash_part_id flash_table_256k_sector[] = {
	{
		/* S25FL128P_256K */
		.id[0] = SPSN_ID_S25FL128P,
		.id[1] = SPSN_EXT_ID_S25FL128P_256KB,
		.nr_sectors_shift = 6,
	},
};

static const struct spi_flash_part_id flash_table[] = {
	{
		/* S25FL208K */
		.id[0] = SPSN_ID_S25FL208K,
		.nr_sectors_shift = 4,
	},
	{
		/* S25FL116K_16M */
		.id[0] = SPSN_ID_S25FL116K,
		.nr_sectors_shift = 5,
	},
	{
		/* S25FL132K */
		.id[0] = SPSN_ID_S25FL132K,
		.nr_sectors_shift = 6,
	},
	{
		/* S25FL164K */
		.id[0] = SPSN_ID_S25FL164K,
		.nr_sectors_shift = 7,
	},
};

const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi = {
	.id = VENDOR_ID_SPANSION,
	.page_size_shift = 8,
	.sector_size_kib_shift = 6,
	.match_id_mask[0] = 0xffff,
	.match_id_mask[1] = 0xffff,
	.ids = flash_table_ext,
	.nr_part_ids = ARRAY_SIZE(flash_table_ext),
	.desc = &spi_flash_pp_0xd8_sector_desc,
};

const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi = {
	.id = VENDOR_ID_SPANSION,
	.page_size_shift = 8,
	.sector_size_kib_shift = 8,
	.match_id_mask[0] = 0xffff,
	.match_id_mask[1] = 0xffff,
	.ids = flash_table_256k_sector,
	.nr_part_ids = ARRAY_SIZE(flash_table_256k_sector),
	.desc = &spi_flash_pp_0xd8_sector_desc,
};

const struct spi_flash_vendor_info spi_flash_spansion_vi = {
	.id = VENDOR_ID_SPANSION,
	.page_size_shift = 8,
	.sector_size_kib_shift = 6,
	.match_id_mask[0] = 0xffff,
	.ids = flash_table,
	.nr_part_ids = ARRAY_SIZE(flash_table),
	.desc = &spi_flash_pp_0xd8_sector_desc,
};