Skip to content

Commit 4f50e10

Browse files
bbrezillonambarus
authored andcommitted
mtd: spi-nor: Expose stuctures and functions to manufacturer drivers
Expose the flash_info struct and some function prototypes that will be used by manufacturers. Signed-off-by: Boris Brezillon <bbrezillon@kernel.org> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Reviewed-by: Vignesh Raghavendra <vigneshr@ti.com>
1 parent cb481b9 commit 4f50e10

2 files changed

Lines changed: 169 additions & 158 deletions

File tree

‎drivers/mtd/spi-nor/core.c‎

Lines changed: 11 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -38,101 +38,9 @@
3838
*/
3939
#define CHIP_ERASE_2MB_READY_WAIT_JIFFIES (40UL * HZ)
4040

41-
#define SPI_NOR_MAX_ID_LEN 6
4241
#define SPI_NOR_MAX_ADDR_WIDTH 4
4342

44-
/**
45-
* struct spi_nor_fixups - SPI NOR fixup hooks
46-
* @default_init: called after default flash parameters init. Used to tweak
47-
* flash parameters when information provided by the flash_info
48-
* table is incomplete or wrong.
49-
* @post_bfpt: called after the BFPT table has been parsed
50-
* @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs
51-
* that do not support RDSFDP). Typically used to tweak various
52-
* parameters that could not be extracted by other means (i.e.
53-
* when information provided by the SFDP/flash_info tables are
54-
* incomplete or wrong).
55-
*
56-
* Those hooks can be used to tweak the SPI NOR configuration when the SFDP
57-
* table is broken or not available.
58-
*/
59-
struct spi_nor_fixups {
60-
void (*default_init)(struct spi_nor *nor);
61-
int (*post_bfpt)(struct spi_nor *nor,
62-
const struct sfdp_parameter_header *bfpt_header,
63-
const struct sfdp_bfpt *bfpt,
64-
struct spi_nor_flash_parameter *params);
65-
void (*post_sfdp)(struct spi_nor *nor);
66-
};
67-
68-
struct flash_info {
69-
char *name;
70-
71-
/*
72-
* This array stores the ID bytes.
73-
* The first three bytes are the JEDIC ID.
74-
* JEDEC ID zero means "no ID" (mostly older chips).
75-
*/
76-
u8 id[SPI_NOR_MAX_ID_LEN];
77-
u8 id_len;
78-
79-
/* The size listed here is what works with SPINOR_OP_SE, which isn't
80-
* necessarily called a "sector" by the vendor.
81-
*/
82-
unsigned sector_size;
83-
u16 n_sectors;
84-
85-
u16 page_size;
86-
u16 addr_width;
87-
88-
u32 flags;
89-
#define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */
90-
#define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */
91-
#define SST_WRITE BIT(2) /* use SST byte programming */
92-
#define SPI_NOR_NO_FR BIT(3) /* Can't do fastread */
93-
#define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */
94-
#define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */
95-
#define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */
96-
#define USE_FSR BIT(7) /* use flag status register */
97-
#define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */
98-
#define SPI_NOR_HAS_TB BIT(9) /*
99-
* Flash SR has Top/Bottom (TB) protect
100-
* bit. Must be used with
101-
* SPI_NOR_HAS_LOCK.
102-
*/
103-
#define SPI_NOR_XSR_RDY BIT(10) /*
104-
* S3AN flashes have specific opcode to
105-
* read the status register.
106-
* Flags SPI_NOR_XSR_RDY and SPI_S3AN
107-
* use the same bit as one implies the
108-
* other, but we will get rid of
109-
* SPI_S3AN soon.
110-
*/
111-
#define SPI_S3AN BIT(10) /*
112-
* Xilinx Spartan 3AN In-System Flash
113-
* (MFR cannot be used for probing
114-
* because it has the same value as
115-
* ATMEL flashes)
116-
*/
117-
#define SPI_NOR_4B_OPCODES BIT(11) /*
118-
* Use dedicated 4byte address op codes
119-
* to support memory size above 128Mib.
120-
*/
121-
#define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */
122-
#define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */
123-
#define USE_CLSR BIT(14) /* use CLSR command */
124-
#define SPI_NOR_OCTAL_READ BIT(15) /* Flash supports Octal Read */
125-
#define SPI_NOR_TB_SR_BIT6 BIT(16) /*
126-
* Top/Bottom (TB) is bit 6 of
127-
* status register. Must be used with
128-
* SPI_NOR_HAS_TB.
129-
*/
130-
131-
/* Part specific fixup hooks. */
132-
const struct spi_nor_fixups *fixups;
133-
};
134-
135-
#define JEDEC_MFR(info) ((info)->id[0])
43+
#define JEDEC_MFR(info) ((info)->id[0])
13644

13745
/**
13846
* spi_nor_spimem_bounce() - check if a bounce buffer is needed for the data
@@ -295,8 +203,8 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
295203
*
296204
* Return: number of bytes written successfully, -errno otherwise
297205
*/
298-
static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
299-
const u8 *buf)
206+
ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
207+
const u8 *buf)
300208
{
301209
if (nor->spimem)
302210
return spi_nor_spimem_write_data(nor, to, len, buf);
@@ -310,7 +218,7 @@ static ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len,
310218
*
311219
* Return: 0 on success, -errno otherwise.
312220
*/
313-
static int spi_nor_write_enable(struct spi_nor *nor)
221+
int spi_nor_write_enable(struct spi_nor *nor)
314222
{
315223
int ret;
316224

@@ -339,7 +247,7 @@ static int spi_nor_write_enable(struct spi_nor *nor)
339247
*
340248
* Return: 0 on success, -errno otherwise.
341249
*/
342-
static int spi_nor_write_disable(struct spi_nor *nor)
250+
int spi_nor_write_disable(struct spi_nor *nor)
343251
{
344252
int ret;
345253

@@ -463,7 +371,7 @@ static int spi_nor_read_cr(struct spi_nor *nor, u8 *cr)
463371
*
464372
* Return: 0 on success, -errno otherwise.
465373
*/
466-
static int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
374+
int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
467375
{
468376
int ret;
469377

@@ -556,7 +464,7 @@ static int spansion_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
556464
*
557465
* Return: 0 on success, -errno otherwise.
558466
*/
559-
static int spi_nor_write_ear(struct spi_nor *nor, u8 ear)
467+
int spi_nor_write_ear(struct spi_nor *nor, u8 ear)
560468
{
561469
int ret;
562470

@@ -621,7 +529,7 @@ static int winbond_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
621529
*
622530
* Return: 0 on success, -errno otherwise.
623531
*/
624-
static int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr)
532+
int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr)
625533
{
626534
int ret;
627535

@@ -834,7 +742,7 @@ static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor,
834742
*
835743
* Return: 0 on success, -errno otherwise.
836744
*/
837-
static int spi_nor_wait_till_ready(struct spi_nor *nor)
745+
int spi_nor_wait_till_ready(struct spi_nor *nor)
838746
{
839747
return spi_nor_wait_till_ready_with_timeout(nor,
840748
DEFAULT_READY_WAIT_JIFFIES);
@@ -1142,11 +1050,6 @@ static int spi_nor_erase_chip(struct spi_nor *nor)
11421050
return ret;
11431051
}
11441052

1145-
static struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
1146-
{
1147-
return mtd->priv;
1148-
}
1149-
11501053
static u8 spi_nor_convert_opcode(u8 opcode, const u8 table[][2], size_t size)
11511054
{
11521055
size_t i;
@@ -1225,7 +1128,7 @@ static void spi_nor_set_4byte_opcodes(struct spi_nor *nor)
12251128
}
12261129
}
12271130

1228-
static int spi_nor_lock_and_prep(struct spi_nor *nor)
1131+
int spi_nor_lock_and_prep(struct spi_nor *nor)
12291132
{
12301133
int ret = 0;
12311134

@@ -1241,7 +1144,7 @@ static int spi_nor_lock_and_prep(struct spi_nor *nor)
12411144
return ret;
12421145
}
12431146

1244-
static void spi_nor_unlock_and_unprep(struct spi_nor *nor)
1147+
void spi_nor_unlock_and_unprep(struct spi_nor *nor)
12451148
{
12461149
if (nor->controller_ops && nor->controller_ops->unprepare)
12471150
nor->controller_ops->unprepare(nor);
@@ -2104,56 +2007,6 @@ int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor)
21042007
return 0;
21052008
}
21062009

2107-
/* Used when the "_ext_id" is two bytes at most */
2108-
#define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
2109-
.id = { \
2110-
((_jedec_id) >> 16) & 0xff, \
2111-
((_jedec_id) >> 8) & 0xff, \
2112-
(_jedec_id) & 0xff, \
2113-
((_ext_id) >> 8) & 0xff, \
2114-
(_ext_id) & 0xff, \
2115-
}, \
2116-
.id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))), \
2117-
.sector_size = (_sector_size), \
2118-
.n_sectors = (_n_sectors), \
2119-
.page_size = 256, \
2120-
.flags = (_flags),
2121-
2122-
#define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \
2123-
.id = { \
2124-
((_jedec_id) >> 16) & 0xff, \
2125-
((_jedec_id) >> 8) & 0xff, \
2126-
(_jedec_id) & 0xff, \
2127-
((_ext_id) >> 16) & 0xff, \
2128-
((_ext_id) >> 8) & 0xff, \
2129-
(_ext_id) & 0xff, \
2130-
}, \
2131-
.id_len = 6, \
2132-
.sector_size = (_sector_size), \
2133-
.n_sectors = (_n_sectors), \
2134-
.page_size = 256, \
2135-
.flags = (_flags),
2136-
2137-
#define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width, _flags) \
2138-
.sector_size = (_sector_size), \
2139-
.n_sectors = (_n_sectors), \
2140-
.page_size = (_page_size), \
2141-
.addr_width = (_addr_width), \
2142-
.flags = (_flags),
2143-
2144-
#define S3AN_INFO(_jedec_id, _n_sectors, _page_size) \
2145-
.id = { \
2146-
((_jedec_id) >> 16) & 0xff, \
2147-
((_jedec_id) >> 8) & 0xff, \
2148-
(_jedec_id) & 0xff \
2149-
}, \
2150-
.id_len = 3, \
2151-
.sector_size = (8*_page_size), \
2152-
.n_sectors = (_n_sectors), \
2153-
.page_size = _page_size, \
2154-
.addr_width = 3, \
2155-
.flags = SPI_NOR_NO_FR | SPI_S3AN,
2156-
21572010
static int
21582011
is25lp256_post_bfpt_fixups(struct spi_nor *nor,
21592012
const struct sfdp_parameter_header *bfpt_header,

0 commit comments

Comments
 (0)