Skip to content

Commit da55809

Browse files
committed
mtd: spinand: Add a ->configure_chip() hook
There is already a manufacturer hook, which is manufacturer specific but not chip specific. We no longer have access to the actual NAND identity at this stage so let's add a per-chip configuration hook to align the chip configuration (if any) with the core's setting. Signed-off-by: Miquel Raynal <[email protected]>
1 parent d81ad9d commit da55809

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

drivers/mtd/nand/spi/core.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,19 @@ static int spinand_id_detect(struct spinand_device *spinand)
12531253

12541254
static int spinand_manufacturer_init(struct spinand_device *spinand)
12551255
{
1256-
if (spinand->manufacturer->ops->init)
1257-
return spinand->manufacturer->ops->init(spinand);
1256+
int ret;
1257+
1258+
if (spinand->manufacturer->ops->init) {
1259+
ret = spinand->manufacturer->ops->init(spinand);
1260+
if (ret)
1261+
return ret;
1262+
}
1263+
1264+
if (spinand->configure_chip) {
1265+
ret = spinand->configure_chip(spinand);
1266+
if (ret)
1267+
return ret;
1268+
}
12581269

12591270
return 0;
12601271
}
@@ -1349,6 +1360,7 @@ int spinand_match_and_init(struct spinand_device *spinand,
13491360
spinand->flags = table[i].flags;
13501361
spinand->id.len = 1 + table[i].devid.len;
13511362
spinand->select_target = table[i].select_target;
1363+
spinand->configure_chip = table[i].configure_chip;
13521364
spinand->set_cont_read = table[i].set_cont_read;
13531365
spinand->fact_otp = &table[i].fact_otp;
13541366
spinand->user_otp = &table[i].user_otp;

include/linux/mtd/spinand.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ struct spinand_user_otp {
493493
* @op_variants.update_cache: variants of the update-cache operation
494494
* @select_target: function used to select a target/die. Required only for
495495
* multi-die chips
496+
* @configure_chip: Align the chip configuration with the core settings
496497
* @set_cont_read: enable/disable continuous cached reads
497498
* @fact_otp: SPI NAND factory OTP info.
498499
* @user_otp: SPI NAND user OTP info.
@@ -516,6 +517,7 @@ struct spinand_info {
516517
} op_variants;
517518
int (*select_target)(struct spinand_device *spinand,
518519
unsigned int target);
520+
int (*configure_chip)(struct spinand_device *spinand);
519521
int (*set_cont_read)(struct spinand_device *spinand,
520522
bool enable);
521523
struct spinand_fact_otp fact_otp;
@@ -548,6 +550,9 @@ struct spinand_info {
548550
#define SPINAND_SELECT_TARGET(__func) \
549551
.select_target = __func
550552

553+
#define SPINAND_CONFIGURE_CHIP(__configure_chip) \
554+
.configure_chip = __configure_chip
555+
551556
#define SPINAND_CONT_READ(__set_cont_read) \
552557
.set_cont_read = __set_cont_read
553558

@@ -616,6 +621,7 @@ struct spinand_dirmap {
616621
* passed in spi_mem_op be DMA-able, so we can't based the bufs on
617622
* the stack
618623
* @manufacturer: SPI NAND manufacturer information
624+
* @configure_chip: Align the chip configuration with the core settings
619625
* @cont_read_possible: Field filled by the core once the whole system
620626
* configuration is known to tell whether continuous reads are
621627
* suitable to use or not in general with this chip/configuration.
@@ -656,6 +662,7 @@ struct spinand_device {
656662
const struct spinand_manufacturer *manufacturer;
657663
void *priv;
658664

665+
int (*configure_chip)(struct spinand_device *spinand);
659666
bool cont_read_possible;
660667
int (*set_cont_read)(struct spinand_device *spinand,
661668
bool enable);

0 commit comments

Comments
 (0)