Skip to content

Commit 6e1bf55

Browse files
Pratyush Yadavr-vignesh
authored andcommitted
mtd: spi-nor: add spi_nor_controller_ops_{read_reg, write_reg, erase}()
They are thin wrappers around nor->controller_ops->{read_reg,write_reg,erase}(). In a future commit DTR support will be added. These ops can not be supported by the controller_ops hooks and these helpers will make it easier to reject those calls. Signed-off-by: Pratyush Yadav <[email protected]> Signed-off-by: Vignesh Raghavendra <[email protected]> Reviewed-by: Tudor Ambarus <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 39bdfb7 commit 6e1bf55

File tree

1 file changed

+53
-34
lines changed

1 file changed

+53
-34
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ static int spi_nor_spimem_exec_op(struct spi_nor *nor, struct spi_mem_op *op)
8282
return spi_mem_exec_op(nor->spimem, op);
8383
}
8484

85+
static int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
86+
u8 *buf, size_t len)
87+
{
88+
return nor->controller_ops->read_reg(nor, opcode, buf, len);
89+
}
90+
91+
static int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
92+
const u8 *buf, size_t len)
93+
{
94+
return nor->controller_ops->write_reg(nor, opcode, buf, len);
95+
}
96+
97+
static int spi_nor_controller_ops_erase(struct spi_nor *nor, loff_t offs)
98+
{
99+
return nor->controller_ops->erase(nor, offs);
100+
}
101+
85102
/**
86103
* spi_nor_spimem_read_data() - read data from flash's memory region via
87104
* spi-mem
@@ -229,8 +246,8 @@ int spi_nor_write_enable(struct spi_nor *nor)
229246

230247
ret = spi_mem_exec_op(nor->spimem, &op);
231248
} else {
232-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WREN,
233-
NULL, 0);
249+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREN,
250+
NULL, 0);
234251
}
235252

236253
if (ret)
@@ -258,8 +275,8 @@ int spi_nor_write_disable(struct spi_nor *nor)
258275

259276
ret = spi_mem_exec_op(nor->spimem, &op);
260277
} else {
261-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WRDI,
262-
NULL, 0);
278+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRDI,
279+
NULL, 0);
263280
}
264281

265282
if (ret)
@@ -289,8 +306,8 @@ static int spi_nor_read_sr(struct spi_nor *nor, u8 *sr)
289306

290307
ret = spi_mem_exec_op(nor->spimem, &op);
291308
} else {
292-
ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDSR,
293-
sr, 1);
309+
ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr,
310+
1);
294311
}
295312

296313
if (ret)
@@ -320,8 +337,8 @@ static int spi_nor_read_fsr(struct spi_nor *nor, u8 *fsr)
320337

321338
ret = spi_mem_exec_op(nor->spimem, &op);
322339
} else {
323-
ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDFSR,
324-
fsr, 1);
340+
ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDFSR, fsr,
341+
1);
325342
}
326343

327344
if (ret)
@@ -352,7 +369,8 @@ static int spi_nor_read_cr(struct spi_nor *nor, u8 *cr)
352369

353370
ret = spi_mem_exec_op(nor->spimem, &op);
354371
} else {
355-
ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDCR, cr, 1);
372+
ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDCR, cr,
373+
1);
356374
}
357375

358376
if (ret)
@@ -385,10 +403,10 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
385403

386404
ret = spi_mem_exec_op(nor->spimem, &op);
387405
} else {
388-
ret = nor->controller_ops->write_reg(nor,
389-
enable ? SPINOR_OP_EN4B :
390-
SPINOR_OP_EX4B,
391-
NULL, 0);
406+
ret = spi_nor_controller_ops_write_reg(nor,
407+
enable ? SPINOR_OP_EN4B :
408+
SPINOR_OP_EX4B,
409+
NULL, 0);
392410
}
393411

394412
if (ret)
@@ -421,8 +439,8 @@ static int spansion_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
421439

422440
ret = spi_mem_exec_op(nor->spimem, &op);
423441
} else {
424-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_BRWR,
425-
nor->bouncebuf, 1);
442+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_BRWR,
443+
nor->bouncebuf, 1);
426444
}
427445

428446
if (ret)
@@ -453,8 +471,8 @@ int spi_nor_write_ear(struct spi_nor *nor, u8 ear)
453471

454472
ret = spi_mem_exec_op(nor->spimem, &op);
455473
} else {
456-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WREAR,
457-
nor->bouncebuf, 1);
474+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREAR,
475+
nor->bouncebuf, 1);
458476
}
459477

460478
if (ret)
@@ -484,8 +502,8 @@ int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr)
484502

485503
ret = spi_mem_exec_op(nor->spimem, &op);
486504
} else {
487-
ret = nor->controller_ops->read_reg(nor, SPINOR_OP_XRDSR,
488-
sr, 1);
505+
ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_XRDSR, sr,
506+
1);
489507
}
490508

491509
if (ret)
@@ -529,8 +547,8 @@ static void spi_nor_clear_sr(struct spi_nor *nor)
529547

530548
ret = spi_mem_exec_op(nor->spimem, &op);
531549
} else {
532-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_CLSR,
533-
NULL, 0);
550+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_CLSR,
551+
NULL, 0);
534552
}
535553

536554
if (ret)
@@ -593,8 +611,8 @@ static void spi_nor_clear_fsr(struct spi_nor *nor)
593611

594612
ret = spi_mem_exec_op(nor->spimem, &op);
595613
} else {
596-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_CLFSR,
597-
NULL, 0);
614+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_CLFSR,
615+
NULL, 0);
598616
}
599617

600618
if (ret)
@@ -737,8 +755,8 @@ static int spi_nor_write_sr(struct spi_nor *nor, const u8 *sr, size_t len)
737755

738756
ret = spi_mem_exec_op(nor->spimem, &op);
739757
} else {
740-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WRSR,
741-
sr, len);
758+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR, sr,
759+
len);
742760
}
743761

744762
if (ret) {
@@ -939,8 +957,8 @@ static int spi_nor_write_sr2(struct spi_nor *nor, const u8 *sr2)
939957

940958
ret = spi_mem_exec_op(nor->spimem, &op);
941959
} else {
942-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_WRSR2,
943-
sr2, 1);
960+
ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR2,
961+
sr2, 1);
944962
}
945963

946964
if (ret) {
@@ -973,8 +991,8 @@ static int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2)
973991

974992
ret = spi_mem_exec_op(nor->spimem, &op);
975993
} else {
976-
ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDSR2,
977-
sr2, 1);
994+
ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR2, sr2,
995+
1);
978996
}
979997

980998
if (ret)
@@ -1004,8 +1022,9 @@ static int spi_nor_erase_chip(struct spi_nor *nor)
10041022

10051023
ret = spi_mem_exec_op(nor->spimem, &op);
10061024
} else {
1007-
ret = nor->controller_ops->write_reg(nor, SPINOR_OP_CHIP_ERASE,
1008-
NULL, 0);
1025+
ret = spi_nor_controller_ops_write_reg(nor,
1026+
SPINOR_OP_CHIP_ERASE,
1027+
NULL, 0);
10091028
}
10101029

10111030
if (ret)
@@ -1146,7 +1165,7 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
11461165

11471166
return spi_mem_exec_op(nor->spimem, &op);
11481167
} else if (nor->controller_ops->erase) {
1149-
return nor->controller_ops->erase(nor, addr);
1168+
return spi_nor_controller_ops_erase(nor, addr);
11501169
}
11511170

11521171
/*
@@ -1158,8 +1177,8 @@ static int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
11581177
addr >>= 8;
11591178
}
11601179

1161-
return nor->controller_ops->write_reg(nor, nor->erase_opcode,
1162-
nor->bouncebuf, nor->addr_width);
1180+
return spi_nor_controller_ops_write_reg(nor, nor->erase_opcode,
1181+
nor->bouncebuf, nor->addr_width);
11631182
}
11641183

11651184
/**

0 commit comments

Comments
 (0)