Skip to content

Commit 88b0e35

Browse files
committed
mtd: spinand: Make use of the operation templates through SPINAND_OP()
Create a SPINAND_OP() macro to which we give the name of the operation we want. This macro retrieves the correct operation template based on the current bus interface (currently only single SDR, will soon be extended to octal DTR) and fills it with the usual parameters. This macro makes the transition from calling directly the low-level macros into using the (bus interface dependent) templates very smooth. Use it in all places that can be trivially converted. At this stage there is no functional change expected, until octal DTR support gets added. Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 4080150 commit 88b0e35

8 files changed

Lines changed: 121 additions & 27 deletions

File tree

drivers/mtd/nand/spi/core.c

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,94 @@
2020
#include <linux/spi/spi.h>
2121
#include <linux/spi/spi-mem.h>
2222

23+
static struct spi_mem_op
24+
spinand_fill_reset_op(struct spinand_device *spinand)
25+
{
26+
return spinand->op_templates->reset;
27+
}
28+
29+
static struct spi_mem_op
30+
spinand_fill_readid_op(struct spinand_device *spinand,
31+
u8 naddr, u8 ndummy, void *buf, unsigned int len)
32+
{
33+
struct spi_mem_op op = spinand->op_templates->readid;
34+
35+
op.addr.nbytes = naddr;
36+
op.dummy.nbytes = ndummy;
37+
op.data.buf.in = buf;
38+
op.data.nbytes = len;
39+
40+
return op;
41+
}
42+
43+
struct spi_mem_op
44+
spinand_fill_wr_en_op(struct spinand_device *spinand)
45+
{
46+
return spinand->op_templates->wr_en;
47+
}
48+
49+
static __maybe_unused struct spi_mem_op
50+
spinand_fill_wr_dis_op(struct spinand_device *spinand)
51+
{
52+
return spinand->op_templates->wr_dis;
53+
}
54+
55+
struct spi_mem_op
56+
spinand_fill_set_feature_op(struct spinand_device *spinand, u64 reg, const void *valptr)
57+
{
58+
struct spi_mem_op op = spinand->op_templates->set_feature;
59+
60+
op.addr.val = reg;
61+
op.data.buf.out = valptr;
62+
63+
return op;
64+
}
65+
66+
struct spi_mem_op
67+
spinand_fill_get_feature_op(struct spinand_device *spinand, u64 reg, void *valptr)
68+
{
69+
struct spi_mem_op op = spinand->op_templates->get_feature;
70+
71+
op.addr.val = reg;
72+
op.data.buf.in = valptr;
73+
74+
return op;
75+
}
76+
77+
static struct spi_mem_op
78+
spinand_fill_blk_erase_op(struct spinand_device *spinand, u64 addr)
79+
{
80+
struct spi_mem_op op = spinand->op_templates->blk_erase;
81+
82+
op.addr.val = addr;
83+
84+
return op;
85+
}
86+
87+
static struct spi_mem_op
88+
spinand_fill_page_read_op(struct spinand_device *spinand, u64 addr)
89+
{
90+
struct spi_mem_op op = spinand->op_templates->page_read;
91+
92+
op.addr.val = addr;
93+
94+
return op;
95+
}
96+
97+
struct spi_mem_op
98+
spinand_fill_prog_exec_op(struct spinand_device *spinand, u64 addr)
99+
{
100+
struct spi_mem_op op = spinand->op_templates->prog_exec;
101+
102+
op.addr.val = addr;
103+
104+
return op;
105+
}
106+
23107
int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
24108
{
25-
struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(reg,
26-
spinand->scratchbuf);
109+
struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
110+
reg, spinand->scratchbuf);
27111
int ret;
28112

29113
ret = spi_mem_exec_op(spinand->spimem, &op);
@@ -36,8 +120,8 @@ int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
36120

37121
int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val)
38122
{
39-
struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(reg,
40-
spinand->scratchbuf);
123+
struct spi_mem_op op = SPINAND_OP(spinand, set_feature,
124+
reg, spinand->scratchbuf);
41125

42126
*spinand->scratchbuf = val;
43127
return spi_mem_exec_op(spinand->spimem, &op);
@@ -362,7 +446,7 @@ static void spinand_ondie_ecc_save_status(struct nand_device *nand, u8 status)
362446

363447
int spinand_write_enable_op(struct spinand_device *spinand)
364448
{
365-
struct spi_mem_op op = SPINAND_WR_EN_1S_0_0_OP;
449+
struct spi_mem_op op = SPINAND_OP(spinand, wr_en);
366450

367451
return spi_mem_exec_op(spinand->spimem, &op);
368452
}
@@ -372,7 +456,7 @@ static int spinand_load_page_op(struct spinand_device *spinand,
372456
{
373457
struct nand_device *nand = spinand_to_nand(spinand);
374458
unsigned int row = nanddev_pos_to_row(nand, &req->pos);
375-
struct spi_mem_op op = SPINAND_PAGE_READ_1S_1S_0_OP(row);
459+
struct spi_mem_op op = SPINAND_OP(spinand, page_read, row);
376460

377461
return spi_mem_exec_op(spinand->spimem, &op);
378462
}
@@ -527,7 +611,7 @@ static int spinand_program_op(struct spinand_device *spinand,
527611
{
528612
struct nand_device *nand = spinand_to_nand(spinand);
529613
unsigned int row = nanddev_pos_to_row(nand, &req->pos);
530-
struct spi_mem_op op = SPINAND_PROG_EXEC_1S_1S_0_OP(row);
614+
struct spi_mem_op op = SPINAND_OP(spinand, prog_exec, row);
531615

532616
return spi_mem_exec_op(spinand->spimem, &op);
533617
}
@@ -537,7 +621,7 @@ static int spinand_erase_op(struct spinand_device *spinand,
537621
{
538622
struct nand_device *nand = spinand_to_nand(spinand);
539623
unsigned int row = nanddev_pos_to_row(nand, pos);
540-
struct spi_mem_op op = SPINAND_BLK_ERASE_1S_1S_0_OP(row);
624+
struct spi_mem_op op = SPINAND_OP(spinand, blk_erase, row);
541625

542626
return spi_mem_exec_op(spinand->spimem, &op);
543627
}
@@ -557,8 +641,8 @@ static int spinand_erase_op(struct spinand_device *spinand,
557641
int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us,
558642
unsigned long poll_delay_us, u8 *s)
559643
{
560-
struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(REG_STATUS,
561-
spinand->scratchbuf);
644+
struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
645+
REG_STATUS, spinand->scratchbuf);
562646
u8 status;
563647
int ret;
564648

@@ -591,8 +675,8 @@ int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us,
591675
static int spinand_read_id_op(struct spinand_device *spinand, u8 naddr,
592676
u8 ndummy, u8 *buf)
593677
{
594-
struct spi_mem_op op = SPINAND_READID_1S_1S_1S_OP(
595-
naddr, ndummy, spinand->scratchbuf, SPINAND_MAX_ID_LEN);
678+
struct spi_mem_op op = SPINAND_OP(spinand, readid,
679+
naddr, ndummy, spinand->scratchbuf, SPINAND_MAX_ID_LEN);
596680
int ret;
597681

598682
ret = spi_mem_exec_op(spinand->spimem, &op);
@@ -604,7 +688,7 @@ static int spinand_read_id_op(struct spinand_device *spinand, u8 naddr,
604688

605689
static int spinand_reset_op(struct spinand_device *spinand)
606690
{
607-
struct spi_mem_op op = SPINAND_RESET_1S_0_0_OP;
691+
struct spi_mem_op op = SPINAND_OP(spinand, reset);
608692
int ret;
609693

610694
ret = spi_mem_exec_op(spinand->spimem, &op);

drivers/mtd/nand/spi/esmt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ static int f50l1g41lb_user_otp_info(struct spinand_device *spinand, size_t len,
138138
static int f50l1g41lb_otp_lock(struct spinand_device *spinand, loff_t from,
139139
size_t len)
140140
{
141-
struct spi_mem_op write_op = SPINAND_WR_EN_1S_0_0_OP;
142-
struct spi_mem_op exec_op = SPINAND_PROG_EXEC_1S_1S_0_OP(0);
141+
struct spi_mem_op write_op = SPINAND_OP(spinand, wr_en);
142+
struct spi_mem_op exec_op = SPINAND_OP(spinand, prog_exec, 0);
143143
u8 status;
144144
int ret;
145145

drivers/mtd/nand/spi/gigadevice.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ static int gd5fxgq4uexxg_ecc_get_status(struct spinand_device *spinand,
266266
u8 status)
267267
{
268268
u8 status2;
269-
struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(GD5FXGQXXEXXG_REG_STATUS2,
270-
spinand->scratchbuf);
269+
struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
270+
GD5FXGQXXEXXG_REG_STATUS2, spinand->scratchbuf);
271271
int ret;
272272

273273
switch (status & STATUS_ECC_MASK) {
@@ -309,8 +309,8 @@ static int gd5fxgq5xexxg_ecc_get_status(struct spinand_device *spinand,
309309
u8 status)
310310
{
311311
u8 status2;
312-
struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(GD5FXGQXXEXXG_REG_STATUS2,
313-
spinand->scratchbuf);
312+
struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
313+
GD5FXGQXXEXXG_REG_STATUS2, spinand->scratchbuf);
314314
int ret;
315315

316316
switch (status & STATUS_ECC_MASK) {

drivers/mtd/nand/spi/macronix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ static int macronix_set_cont_read(struct spinand_device *spinand, bool enable)
148148
static int macronix_set_read_retry(struct spinand_device *spinand,
149149
unsigned int retry_mode)
150150
{
151-
struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MACRONIX_FEATURE_ADDR_READ_RETRY,
152-
spinand->scratchbuf);
151+
struct spi_mem_op op = SPINAND_OP(spinand, set_feature,
152+
MACRONIX_FEATURE_ADDR_READ_RETRY, spinand->scratchbuf);
153153

154154
*spinand->scratchbuf = retry_mode;
155155
return spi_mem_exec_op(spinand->spimem, &op);

drivers/mtd/nand/spi/micron.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ static const struct mtd_ooblayout_ops micron_4_ooblayout = {
137137
static int micron_select_target(struct spinand_device *spinand,
138138
unsigned int target)
139139
{
140-
struct spi_mem_op op = SPINAND_SET_FEATURE_1S_1S_1S_OP(MICRON_DIE_SELECT_REG,
141-
spinand->scratchbuf);
140+
struct spi_mem_op op = SPINAND_OP(spinand, set_feature,
141+
MICRON_DIE_SELECT_REG, spinand->scratchbuf);
142142

143143
if (target > 1)
144144
return -EINVAL;
@@ -251,8 +251,8 @@ static int mt29f2g01abagd_user_otp_info(struct spinand_device *spinand,
251251
static int mt29f2g01abagd_otp_lock(struct spinand_device *spinand, loff_t from,
252252
size_t len)
253253
{
254-
struct spi_mem_op write_op = SPINAND_WR_EN_1S_0_0_OP;
255-
struct spi_mem_op exec_op = SPINAND_PROG_EXEC_1S_1S_0_OP(0);
254+
struct spi_mem_op write_op = SPINAND_OP(spinand, wr_en);
255+
struct spi_mem_op exec_op = SPINAND_OP(spinand, prog_exec, 0);
256256
u8 status;
257257
int ret;
258258

drivers/mtd/nand/spi/toshiba.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
7373
{
7474
struct nand_device *nand = spinand_to_nand(spinand);
7575
u8 mbf = 0;
76-
struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(0x30, spinand->scratchbuf);
76+
struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
77+
0x30, spinand->scratchbuf);
7778

7879
switch (status & STATUS_ECC_MASK) {
7980
case STATUS_ECC_NO_BITFLIPS:

drivers/mtd/nand/spi/winbond.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
251251
{
252252
struct nand_device *nand = spinand_to_nand(spinand);
253253
u8 mbf = 0;
254-
struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(0x30, spinand->scratchbuf);
254+
struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
255+
0x30, spinand->scratchbuf);
255256

256257
switch (status & STATUS_ECC_MASK) {
257258
case STATUS_ECC_NO_BITFLIPS:

include/linux/mtd/spinand.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,14 @@ struct spinand_device {
703703
unsigned int retry_mode);
704704
};
705705

706+
struct spi_mem_op spinand_fill_wr_en_op(struct spinand_device *spinand);
707+
struct spi_mem_op spinand_fill_set_feature_op(struct spinand_device *spinand, u64 reg, const void *valptr);
708+
struct spi_mem_op spinand_fill_get_feature_op(struct spinand_device *spinand, u64 reg, void *valptr);
709+
struct spi_mem_op spinand_fill_prog_exec_op(struct spinand_device *spinand, u64 addr);
710+
711+
#define SPINAND_OP(spinand, op_name, ...) \
712+
spinand_fill_ ## op_name ## _op(spinand, ##__VA_ARGS__)
713+
706714
/**
707715
* mtd_to_spinand() - Get the SPI NAND device attached to an MTD instance
708716
* @mtd: MTD instance

0 commit comments

Comments
 (0)