Skip to content

Commit 0a331a1

Browse files
committed
mtd: spinand: Give the bus interface to the configuration helper
The chip configuration hook is the one responsible to actually switch the switch between bus interfaces. It is natural to give it the bus interface we expect with a new parameter. For now the only value we can give is SSDR, but this is subject to change in the future, so add a bit of extra logic in the implementations of this callback to make sure both the core and the chip driver are aligned on the request. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 8e7face commit 0a331a1

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

drivers/mtd/nand/spi/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ static int spinand_configure_chip(struct spinand_device *spinand)
16041604
return ret;
16051605

16061606
if (spinand->configure_chip) {
1607-
ret = spinand->configure_chip(spinand);
1607+
ret = spinand->configure_chip(spinand, SSDR);
16081608
if (ret)
16091609
return ret;
16101610
}

drivers/mtd/nand/spi/winbond.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,17 @@ static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
311311
return -EINVAL;
312312
}
313313

314-
static int w25n0xjw_hs_cfg(struct spinand_device *spinand)
314+
static int w25n0xjw_hs_cfg(struct spinand_device *spinand,
315+
enum spinand_bus_interface iface)
315316
{
316317
const struct spi_mem_op *op;
317318
bool hs;
318319
u8 sr4;
319320
int ret;
320321

322+
if (iface != SSDR)
323+
return -EOPNOTSUPP;
324+
321325
op = spinand->op_templates->read_cache;
322326
if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
323327
hs = false;
@@ -371,17 +375,25 @@ static int w35n0xjw_write_vcr(struct spinand_device *spinand, u8 reg, u8 val)
371375
return 0;
372376
}
373377

374-
static int w35n0xjw_vcr_cfg(struct spinand_device *spinand)
378+
static int w35n0xjw_vcr_cfg(struct spinand_device *spinand,
379+
enum spinand_bus_interface iface)
375380
{
376-
const struct spi_mem_op *op;
381+
const struct spi_mem_op *ref_op;
377382
unsigned int dummy_cycles;
378383
bool dtr, single;
379384
u8 io_mode;
380385
int ret;
381386

382-
op = spinand->op_templates->read_cache;
387+
switch (iface) {
388+
case SSDR:
389+
ref_op = spinand->ssdr_op_templates.read_cache;
390+
break;
391+
default:
392+
return -EOPNOTSUPP;
393+
};
383394

384-
dummy_cycles = ((op->dummy.nbytes * 8) / op->dummy.buswidth) / (op->dummy.dtr ? 2 : 1);
395+
dummy_cycles = ((ref_op->dummy.nbytes * 8) / ref_op->dummy.buswidth) /
396+
(ref_op->dummy.dtr ? 2 : 1);
385397
switch (dummy_cycles) {
386398
case 8:
387399
case 12:
@@ -398,8 +410,10 @@ static int w35n0xjw_vcr_cfg(struct spinand_device *spinand)
398410
if (ret)
399411
return ret;
400412

401-
single = (op->cmd.buswidth == 1 && op->addr.buswidth == 1 && op->data.buswidth == 1);
402-
dtr = (op->cmd.dtr && op->addr.dtr && op->data.dtr);
413+
single = (ref_op->cmd.buswidth == 1 &&
414+
ref_op->addr.buswidth == 1 &&
415+
ref_op->data.buswidth == 1);
416+
dtr = (ref_op->cmd.dtr && ref_op->addr.dtr && ref_op->data.dtr);
403417
if (single && !dtr)
404418
io_mode = W35N01JW_VCR_IO_MODE_SINGLE_SDR;
405419
else if (!single && !dtr)

include/linux/mtd/spinand.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ struct spinand_info {
530530
const struct spinand_op_variants *vendor_ops;
531531
int (*select_target)(struct spinand_device *spinand,
532532
unsigned int target);
533-
int (*configure_chip)(struct spinand_device *spinand);
533+
int (*configure_chip)(struct spinand_device *spinand,
534+
enum spinand_bus_interface iface);
534535
int (*set_cont_read)(struct spinand_device *spinand,
535536
bool enable);
536537
struct spinand_fact_otp fact_otp;
@@ -705,7 +706,8 @@ struct spinand_device {
705706
const struct spinand_manufacturer *manufacturer;
706707
void *priv;
707708

708-
int (*configure_chip)(struct spinand_device *spinand);
709+
int (*configure_chip)(struct spinand_device *spinand,
710+
enum spinand_bus_interface iface);
709711
bool cont_read_possible;
710712
int (*set_cont_read)(struct spinand_device *spinand,
711713
bool enable);

0 commit comments

Comments
 (0)