Skip to content

Commit c17a90a

Browse files
Arseniy Krasnovmiquelraynal
authored andcommitted
mtd: rawnand: meson: waiting w/o wired ready/busy pin
If there is no wired ready/busy pin, classic way to wait for command completion is to use function 'nand_soft_waitrdy()'. Meson NAND has special command which allows to wait for NAND_STATUS_READY bit without reading status in a software loop (as 'nand_soft_waitrdy()' does). To use it send this command along with NAND_CMD_STATUS, then wait for an interrupt, and after interrupt send NAND_CMD_READ0. So this feature allows to use interrupt driven waiting without wired ready/busy pin. Suggested-by: Liang Yang <liang.yang@amlogic.com> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20230608044728.1328506-3-AVKrasnov@sberdevices.ru
1 parent 262bc00 commit c17a90a

1 file changed

Lines changed: 73 additions & 4 deletions

File tree

drivers/mtd/nand/raw/meson_nand.c

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define NFC_CMD_SCRAMBLER_DISABLE 0
3939
#define NFC_CMD_SHORTMODE_DISABLE 0
4040
#define NFC_CMD_RB_INT BIT(14)
41+
#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16))
4142

4243
#define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0))
4344

@@ -182,6 +183,7 @@ struct meson_nfc {
182183
u32 info_bytes;
183184

184185
unsigned long assigned_cs;
186+
bool no_rb_pin;
185187
};
186188

187189
enum {
@@ -395,7 +397,42 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand,
395397
}
396398
}
397399

398-
static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms)
400+
static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms,
401+
bool need_cmd_read0)
402+
{
403+
u32 cmd, cfg;
404+
405+
meson_nfc_cmd_idle(nfc, nfc->timing.twb);
406+
meson_nfc_drain_cmd(nfc);
407+
meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT);
408+
409+
cfg = readl(nfc->reg_base + NFC_REG_CFG);
410+
cfg |= NFC_RB_IRQ_EN;
411+
writel(cfg, nfc->reg_base + NFC_REG_CFG);
412+
413+
reinit_completion(&nfc->completion);
414+
cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS;
415+
writel(cmd, nfc->reg_base + NFC_REG_CMD);
416+
417+
/* use the max erase time as the maximum clock for waiting R/B */
418+
cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max;
419+
writel(cmd, nfc->reg_base + NFC_REG_CMD);
420+
421+
if (!wait_for_completion_timeout(&nfc->completion,
422+
msecs_to_jiffies(timeout_ms)))
423+
return -ETIMEDOUT;
424+
425+
if (need_cmd_read0) {
426+
cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0;
427+
writel(cmd, nfc->reg_base + NFC_REG_CMD);
428+
meson_nfc_drain_cmd(nfc);
429+
meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT);
430+
}
431+
432+
return 0;
433+
}
434+
435+
static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms)
399436
{
400437
u32 cmd, cfg;
401438
int ret = 0;
@@ -423,6 +460,27 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms)
423460
return ret;
424461
}
425462

463+
static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms,
464+
bool need_cmd_read0)
465+
{
466+
if (nfc->no_rb_pin) {
467+
/* This mode is used when there is no wired R/B pin.
468+
* It works like 'nand_soft_waitrdy()', but instead of
469+
* polling NAND_CMD_STATUS bit in the software loop,
470+
* it will wait for interrupt - controllers checks IO
471+
* bus and when it detects NAND_CMD_STATUS on it, it
472+
* raises interrupt. After interrupt, NAND_CMD_READ0 is
473+
* sent as terminator of the ready waiting procedure if
474+
* needed (for all cases except page programming - this
475+
* is reason of 'need_cmd_read0' flag).
476+
*/
477+
return meson_nfc_wait_no_rb_pin(nfc, timeout_ms,
478+
need_cmd_read0);
479+
} else {
480+
return meson_nfc_wait_rb_pin(nfc, timeout_ms);
481+
}
482+
}
483+
426484
static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
427485
{
428486
struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand);
@@ -626,7 +684,7 @@ static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand,
626684
if (in) {
627685
nfc->cmdfifo.rw.cmd1 = cs | NFC_CMD_CLE | NAND_CMD_READSTART;
628686
writel(nfc->cmdfifo.rw.cmd1, nfc->reg_base + NFC_REG_CMD);
629-
meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tR_max));
687+
meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tR_max), true);
630688
} else {
631689
meson_nfc_cmd_idle(nfc, nfc->timing.tadl);
632690
}
@@ -672,7 +730,7 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand,
672730

673731
cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_PAGEPROG;
674732
writel(cmd, nfc->reg_base + NFC_REG_CMD);
675-
meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tPROG_max));
733+
meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tPROG_max), false);
676734

677735
meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_TO_DEVICE);
678736

@@ -955,7 +1013,8 @@ static int meson_nfc_exec_op(struct nand_chip *nand,
9551013
break;
9561014

9571015
case NAND_OP_WAITRDY_INSTR:
958-
meson_nfc_queue_rb(nfc, instr->ctx.waitrdy.timeout_ms);
1016+
meson_nfc_queue_rb(nfc, instr->ctx.waitrdy.timeout_ms,
1017+
true);
9591018
if (instr->delay_ns)
9601019
meson_nfc_cmd_idle(nfc, delay_idle);
9611020
break;
@@ -1251,6 +1310,7 @@ meson_nfc_nand_chip_init(struct device *dev,
12511310
struct mtd_info *mtd;
12521311
int ret, i;
12531312
u32 tmp, nsels;
1313+
u32 nand_rb_val = 0;
12541314

12551315
nsels = of_property_count_elems_of_size(np, "reg", sizeof(u32));
12561316
if (!nsels || nsels > MAX_CE_NUM) {
@@ -1290,6 +1350,15 @@ meson_nfc_nand_chip_init(struct device *dev,
12901350
mtd->owner = THIS_MODULE;
12911351
mtd->dev.parent = dev;
12921352

1353+
ret = of_property_read_u32(np, "nand-rb", &nand_rb_val);
1354+
if (ret == -EINVAL)
1355+
nfc->no_rb_pin = true;
1356+
else if (ret)
1357+
return ret;
1358+
1359+
if (nand_rb_val)
1360+
return -EINVAL;
1361+
12931362
ret = nand_scan(nand, nsels);
12941363
if (ret)
12951364
return ret;

0 commit comments

Comments
 (0)