Skip to content

Commit 59ee921

Browse files
committed
Merge tag 'spi-nor/for-6.15' into mtd/next
SPI NOR adds support for few flashes. Few cleanup patches for the core driver, where we touched the headers inclusion list and we start using the scope based mutex cleanup helpers.
2 parents 48a2972 + eec3736 commit 59ee921

File tree

5 files changed

+146
-52
lines changed

5 files changed

+146
-52
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
* Copyright (C) 2014, Freescale Semiconductor, Inc.
88
*/
99

10-
#include <linux/err.h>
11-
#include <linux/errno.h>
10+
#include <linux/cleanup.h>
1211
#include <linux/delay.h>
1312
#include <linux/device.h>
13+
#include <linux/err.h>
14+
#include <linux/errno.h>
1415
#include <linux/math64.h>
1516
#include <linux/module.h>
1617
#include <linux/mtd/mtd.h>
1718
#include <linux/mtd/spi-nor.h>
1819
#include <linux/mutex.h>
19-
#include <linux/of_platform.h>
20+
#include <linux/of.h>
2021
#include <linux/regulator/consumer.h>
2122
#include <linux/sched/task_stack.h>
2223
#include <linux/sizes.h>
@@ -639,32 +640,26 @@ static bool spi_nor_use_parallel_locking(struct spi_nor *nor)
639640
static int spi_nor_rww_start_rdst(struct spi_nor *nor)
640641
{
641642
struct spi_nor_rww *rww = &nor->rww;
642-
int ret = -EAGAIN;
643643

644-
mutex_lock(&nor->lock);
644+
guard(mutex)(&nor->lock);
645645

646646
if (rww->ongoing_io || rww->ongoing_rd)
647-
goto busy;
647+
return -EAGAIN;
648648

649649
rww->ongoing_io = true;
650650
rww->ongoing_rd = true;
651-
ret = 0;
652651

653-
busy:
654-
mutex_unlock(&nor->lock);
655-
return ret;
652+
return 0;
656653
}
657654

658655
static void spi_nor_rww_end_rdst(struct spi_nor *nor)
659656
{
660657
struct spi_nor_rww *rww = &nor->rww;
661658

662-
mutex_lock(&nor->lock);
659+
guard(mutex)(&nor->lock);
663660

664661
rww->ongoing_io = false;
665662
rww->ongoing_rd = false;
666-
667-
mutex_unlock(&nor->lock);
668663
}
669664

670665
static int spi_nor_lock_rdst(struct spi_nor *nor)
@@ -1212,26 +1207,21 @@ static void spi_nor_offset_to_banks(u64 bank_size, loff_t start, size_t len,
12121207
static bool spi_nor_rww_start_io(struct spi_nor *nor)
12131208
{
12141209
struct spi_nor_rww *rww = &nor->rww;
1215-
bool start = false;
12161210

1217-
mutex_lock(&nor->lock);
1211+
guard(mutex)(&nor->lock);
12181212

12191213
if (rww->ongoing_io)
1220-
goto busy;
1214+
return false;
12211215

12221216
rww->ongoing_io = true;
1223-
start = true;
12241217

1225-
busy:
1226-
mutex_unlock(&nor->lock);
1227-
return start;
1218+
return true;
12281219
}
12291220

12301221
static void spi_nor_rww_end_io(struct spi_nor *nor)
12311222
{
1232-
mutex_lock(&nor->lock);
1223+
guard(mutex)(&nor->lock);
12331224
nor->rww.ongoing_io = false;
1234-
mutex_unlock(&nor->lock);
12351225
}
12361226

12371227
static int spi_nor_lock_device(struct spi_nor *nor)
@@ -1254,32 +1244,27 @@ static void spi_nor_unlock_device(struct spi_nor *nor)
12541244
static bool spi_nor_rww_start_exclusive(struct spi_nor *nor)
12551245
{
12561246
struct spi_nor_rww *rww = &nor->rww;
1257-
bool start = false;
12581247

12591248
mutex_lock(&nor->lock);
12601249

12611250
if (rww->ongoing_io || rww->ongoing_rd || rww->ongoing_pe)
1262-
goto busy;
1251+
return false;
12631252

12641253
rww->ongoing_io = true;
12651254
rww->ongoing_rd = true;
12661255
rww->ongoing_pe = true;
1267-
start = true;
12681256

1269-
busy:
1270-
mutex_unlock(&nor->lock);
1271-
return start;
1257+
return true;
12721258
}
12731259

12741260
static void spi_nor_rww_end_exclusive(struct spi_nor *nor)
12751261
{
12761262
struct spi_nor_rww *rww = &nor->rww;
12771263

1278-
mutex_lock(&nor->lock);
1264+
guard(mutex)(&nor->lock);
12791265
rww->ongoing_io = false;
12801266
rww->ongoing_rd = false;
12811267
rww->ongoing_pe = false;
1282-
mutex_unlock(&nor->lock);
12831268
}
12841269

12851270
int spi_nor_prep_and_lock(struct spi_nor *nor)
@@ -1316,30 +1301,26 @@ static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len)
13161301
{
13171302
struct spi_nor_rww *rww = &nor->rww;
13181303
unsigned int used_banks = 0;
1319-
bool started = false;
13201304
u8 first, last;
13211305
int bank;
13221306

1323-
mutex_lock(&nor->lock);
1307+
guard(mutex)(&nor->lock);
13241308

13251309
if (rww->ongoing_io || rww->ongoing_rd || rww->ongoing_pe)
1326-
goto busy;
1310+
return false;
13271311

13281312
spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last);
13291313
for (bank = first; bank <= last; bank++) {
13301314
if (rww->used_banks & BIT(bank))
1331-
goto busy;
1315+
return false;
13321316

13331317
used_banks |= BIT(bank);
13341318
}
13351319

13361320
rww->used_banks |= used_banks;
13371321
rww->ongoing_pe = true;
1338-
started = true;
13391322

1340-
busy:
1341-
mutex_unlock(&nor->lock);
1342-
return started;
1323+
return true;
13431324
}
13441325

13451326
static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len)
@@ -1348,15 +1329,13 @@ static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len)
13481329
u8 first, last;
13491330
int bank;
13501331

1351-
mutex_lock(&nor->lock);
1332+
guard(mutex)(&nor->lock);
13521333

13531334
spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last);
13541335
for (bank = first; bank <= last; bank++)
13551336
rww->used_banks &= ~BIT(bank);
13561337

13571338
rww->ongoing_pe = false;
1358-
1359-
mutex_unlock(&nor->lock);
13601339
}
13611340

13621341
static int spi_nor_prep_and_lock_pe(struct spi_nor *nor, loff_t start, size_t len)
@@ -1393,31 +1372,27 @@ static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len)
13931372
{
13941373
struct spi_nor_rww *rww = &nor->rww;
13951374
unsigned int used_banks = 0;
1396-
bool started = false;
13971375
u8 first, last;
13981376
int bank;
13991377

1400-
mutex_lock(&nor->lock);
1378+
guard(mutex)(&nor->lock);
14011379

14021380
if (rww->ongoing_io || rww->ongoing_rd)
1403-
goto busy;
1381+
return false;
14041382

14051383
spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last);
14061384
for (bank = first; bank <= last; bank++) {
14071385
if (rww->used_banks & BIT(bank))
1408-
goto busy;
1386+
return false;
14091387

14101388
used_banks |= BIT(bank);
14111389
}
14121390

14131391
rww->used_banks |= used_banks;
14141392
rww->ongoing_io = true;
14151393
rww->ongoing_rd = true;
1416-
started = true;
14171394

1418-
busy:
1419-
mutex_unlock(&nor->lock);
1420-
return started;
1395+
return true;
14211396
}
14221397

14231398
static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len)
@@ -1426,16 +1401,14 @@ static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len)
14261401
u8 first, last;
14271402
int bank;
14281403

1429-
mutex_lock(&nor->lock);
1404+
guard(mutex)(&nor->lock);
14301405

14311406
spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last);
14321407
for (bank = first; bank <= last; bank++)
14331408
nor->rww.used_banks &= ~BIT(bank);
14341409

14351410
rww->ongoing_io = false;
14361411
rww->ongoing_rd = false;
1437-
1438-
mutex_unlock(&nor->lock);
14391412
}
14401413

14411414
static int spi_nor_prep_and_lock_rd(struct spi_nor *nor, loff_t start, size_t len)

drivers/mtd/spi-nor/macronix.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,26 @@ mx25l25635_post_bfpt_fixups(struct spi_nor *nor,
4545
return 0;
4646
}
4747

48+
static int
49+
macronix_qpp4b_post_sfdp_fixups(struct spi_nor *nor)
50+
{
51+
/* PP_1_1_4_4B is supported but missing in 4BAIT. */
52+
struct spi_nor_flash_parameter *params = nor->params;
53+
54+
params->hwcaps.mask |= SNOR_HWCAPS_PP_1_1_4;
55+
spi_nor_set_pp_settings(&params->page_programs[SNOR_CMD_PP_1_1_4],
56+
SPINOR_OP_PP_1_1_4_4B, SNOR_PROTO_1_1_4);
57+
58+
return 0;
59+
}
60+
4861
static const struct spi_nor_fixups mx25l25635_fixups = {
4962
.post_bfpt = mx25l25635_post_bfpt_fixups,
63+
.post_sfdp = macronix_qpp4b_post_sfdp_fixups,
64+
};
65+
66+
static const struct spi_nor_fixups macronix_qpp4b_fixups = {
67+
.post_sfdp = macronix_qpp4b_post_sfdp_fixups,
5068
};
5169

5270
static const struct flash_info macronix_nor_parts[] = {
@@ -102,11 +120,17 @@ static const struct flash_info macronix_nor_parts[] = {
102120
.size = SZ_64M,
103121
.no_sfdp_flags = SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
104122
.fixup_flags = SPI_NOR_4B_OPCODES,
123+
.fixups = &macronix_qpp4b_fixups,
105124
}, {
106125
.id = SNOR_ID(0xc2, 0x20, 0x1b),
107126
.name = "mx66l1g45g",
108127
.size = SZ_128M,
109128
.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
129+
.fixups = &macronix_qpp4b_fixups,
130+
}, {
131+
/* MX66L2G45G */
132+
.id = SNOR_ID(0xc2, 0x20, 0x1c),
133+
.fixups = &macronix_qpp4b_fixups,
110134
}, {
111135
.id = SNOR_ID(0xc2, 0x23, 0x14),
112136
.name = "mx25v8035f",
@@ -148,18 +172,25 @@ static const struct flash_info macronix_nor_parts[] = {
148172
.size = SZ_64M,
149173
.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
150174
.fixup_flags = SPI_NOR_4B_OPCODES,
175+
.fixups = &macronix_qpp4b_fixups,
151176
}, {
152177
.id = SNOR_ID(0xc2, 0x25, 0x3a),
153178
.name = "mx66u51235f",
154179
.size = SZ_64M,
155180
.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
156181
.fixup_flags = SPI_NOR_4B_OPCODES,
182+
.fixups = &macronix_qpp4b_fixups,
183+
}, {
184+
/* MX66U1G45G */
185+
.id = SNOR_ID(0xc2, 0x25, 0x3b),
186+
.fixups = &macronix_qpp4b_fixups,
157187
}, {
158188
.id = SNOR_ID(0xc2, 0x25, 0x3c),
159189
.name = "mx66u2g45g",
160190
.size = SZ_256M,
161191
.no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
162192
.fixup_flags = SPI_NOR_4B_OPCODES,
193+
.fixups = &macronix_qpp4b_fixups,
163194
}, {
164195
.id = SNOR_ID(0xc2, 0x26, 0x18),
165196
.name = "mx25l12855e",

drivers/mtd/spi-nor/otp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <linux/log2.h>
9+
#include <linux/math64.h>
910
#include <linux/mtd/mtd.h>
1011
#include <linux/mtd/spi-nor.h>
1112

drivers/mtd/spi-nor/swp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright (C) 2005, Intec Automation Inc.
66
* Copyright (C) 2014, Freescale Semiconductor, Inc.
77
*/
8+
#include <linux/math64.h>
89
#include <linux/mtd/mtd.h>
910
#include <linux/mtd/spi-nor.h>
1011

0 commit comments

Comments
 (0)