Message ID | 20230606195128.83432-1-AVKrasnov@sberdevices.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3645186vqr; Tue, 6 Jun 2023 13:14:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4KFyUokmNDCzegZJfwR75Gh6j+F9MisRB6B0A3PudonJPnINrgFw7UN4+kUfLJtZD6QnFw X-Received: by 2002:a05:6a20:2450:b0:10d:1fba:7371 with SMTP id t16-20020a056a20245000b0010d1fba7371mr541911pzc.5.1686082480053; Tue, 06 Jun 2023 13:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686082480; cv=none; d=google.com; s=arc-20160816; b=SJyund/6Sc/nJXyfUuSqXFCVxmbePvirMChCNI9smiik8hQCR+YqS6u+Rkdh1nyG0K FmL4M7q47hbVlTH3hsjCQX47bJ/SUcyZrLAudgnIJNIiG/uRRANmab7exRWaxMsPWidB eTn6DPkF+/8sIBTPgAhwivII+s9sCRVamx8mSZeNjGjQKcJgnq98KyrOyxzS3BPRTbNa A5mRJUL8GkZ9oo4BhGRktd+fo7GxRxoBIv5ybheBgkTioDXfyERx6QeJ2VU2pwjoYAS0 hhTYDK5icU4JJ7+9GmLwmCj4bjO5bLoWFC//KUDVEYG+Md6PriTpXHs6PjzSFe99rA5v CFfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xDJUjgp6TQV9LR69Y8CgT9NmcDiSez9hE02STaqbw+U=; b=dXTWJmWs4j9h/WIsrHVphJCLEu/dmfHbMU/6BNsuQSetgVJ4IIF0Qz4Okj1h+tAVjo fKaBJ6gQhF+Dpty/IO+TAhQjHi93yKeL/gts9IC27kNOCRSLfj0QsFYgYVpAF1E/gKVo YS2fUM7ipK5Ap8EkbVvenJwWZoPFxKp1S8hay7jW2cjkDdMZiLsYkMCaGptPkC7M/C+X W8UkyTruW96wjluTgb0/4rnaSBYs5yB5pkzKpeVC0aiCijReMQ5rJ3+gOBEasAm6y0TA e9YlUglbnVwASQPIzILfTnWvC5FcZj4F+g4aMFI2380dSqTR7zRDxGSDLFmrJyni6MGP LjUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=rF9yDeEO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a170902b49000b001b02fa876c7si7451340plr.578.2023.06.06.13.14.26; Tue, 06 Jun 2023 13:14:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=rF9yDeEO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239576AbjFFT4o (ORCPT <rfc822;xxoosimple@gmail.com> + 99 others); Tue, 6 Jun 2023 15:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234210AbjFFT4m (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Jun 2023 15:56:42 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8694510F1 for <linux-kernel@vger.kernel.org>; Tue, 6 Jun 2023 12:56:40 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 9194B5FD0C; Tue, 6 Jun 2023 22:56:38 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1686081398; bh=xDJUjgp6TQV9LR69Y8CgT9NmcDiSez9hE02STaqbw+U=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=rF9yDeEO8qzX4zf+yvs+qbed3/bdnmtDCius/vEASNxx6YlxKGa9qVNc/tBBWFyfg 4RVizPu3Nslo8yWpSynwYpVzkX7gIDCmlXIxR2ZYswGbYsSw2yOff9Q/fTG0UON3x2 cmvc/rEmF92ryFK39bquZ6yhjNpZXNWk0t8Rlvd136ziJ9tNzTKbw5Uuj2Pd4YBbnN tuD4l4X47TRTL1qXQFTB934ozHe4s6t4t+xU4VKk/lpU0tWzNfdtkPz5O9l+AnZA2z 8YQ6zRq/Jx4LSHYfpAmzzqm7TfXkzaL0MXBqqucthJcScBqYdNROIfhvGEgu48Yb7y erMPoqSQ7XL4Q== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Tue, 6 Jun 2023 22:56:38 +0300 (MSK) From: Arseniy Krasnov <AVKrasnov@sberdevices.ru> To: Liang Yang <liang.yang@amlogic.com>, Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>, Neil Armstrong <neil.armstrong@linaro.org>, Kevin Hilman <khilman@baylibre.com>, Jerome Brunet <jbrunet@baylibre.com>, Martin Blumenstingl <martin.blumenstingl@googlemail.com> CC: <oxffffaa@gmail.com>, <kernel@sberdevices.ru>, Arseniy Krasnov <AVKrasnov@sberdevices.ru>, <linux-mtd@lists.infradead.org>, <linux-arm-kernel@lists.infradead.org>, <linux-amlogic@lists.infradead.org>, <linux-kernel@vger.kernel.org> Subject: [PATCH v1] mtd: rawnand: meson: waiting w/o wired ready/busy pin Date: Tue, 6 Jun 2023 22:51:27 +0300 Message-ID: <20230606195128.83432-1-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/06 14:43:00 #21444531 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767985622308966905?= X-GMAIL-MSGID: =?utf-8?q?1767985622308966905?= |
Series |
[v1] mtd: rawnand: meson: waiting w/o wired ready/busy pin
|
|
Commit Message
Arseniy Krasnov
June 6, 2023, 7:51 p.m. UTC
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>
---
drivers/mtd/nand/raw/meson_nand.c | 58 ++++++++++++++++++++++++++++++-
1 file changed, 57 insertions(+), 1 deletion(-)
Comments
On 06.06.2023 22:51, Arseniy Krasnov wrote: > 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> > --- > drivers/mtd/nand/raw/meson_nand.c | 58 ++++++++++++++++++++++++++++++- > 1 file changed, 57 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c > index 074e14225c06..f4c5309a9527 100644 > --- a/drivers/mtd/nand/raw/meson_nand.c > +++ b/drivers/mtd/nand/raw/meson_nand.c > @@ -38,6 +38,7 @@ > #define NFC_CMD_SCRAMBLER_DISABLE 0 > #define NFC_CMD_SHORTMODE_DISABLE 0 > #define NFC_CMD_RB_INT BIT(14) > +#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16)) > > #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) > > @@ -94,6 +95,7 @@ > > /* nand flash controller delay 3 ns */ > #define NFC_DEFAULT_DELAY 3000 > +#define NFC_NO_RB_PIN_DELAY 5 > > #define ROW_ADDER(page, index) (((page) >> (8 * (index))) & 0xff) > #define MAX_CYCLE_ADDRS 5 > @@ -179,6 +181,7 @@ struct meson_nfc { > u32 info_bytes; > > unsigned long assigned_cs; > + bool no_rb_pin; > }; > > enum { > @@ -392,7 +395,41 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, > } > } > > -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) > +static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms) > +{ > + u32 cmd, cfg; > + > + meson_nfc_cmd_idle(nfc, nfc->timing.twb); > + meson_nfc_drain_cmd(nfc); > + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); > + > + cfg = readl(nfc->reg_base + NFC_REG_CFG); > + cfg |= NFC_RB_IRQ_EN; > + writel(cfg, nfc->reg_base + NFC_REG_CFG); > + > + reinit_completion(&nfc->completion); > + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; > + writel(cmd, nfc->reg_base + NFC_REG_CMD); > + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); ^^^ > + > + /* use the max erase time as the maximum clock for waiting R/B */ > + cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max; > + writel(cmd, nfc->reg_base + NFC_REG_CMD); > + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); ^^^ Liang, I've implemented "new RB_INT" way instead of 'nand_soft_waitrdy()'. There were two numbers 2 and 5 in 'meson_nfc_cmd_idle()' as time argument (here and above). I've replaced both with define of 5 == NFC_NO_RB_PIN_DELAY. Is it correct? 2 and 5 were from doc? Thanks, Arseniy > + > + if (!wait_for_completion_timeout(&nfc->completion, > + msecs_to_jiffies(timeout_ms))) > + return -ETIMEDOUT; > + > + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; > + writel(cmd, nfc->reg_base + NFC_REG_CMD); > + meson_nfc_drain_cmd(nfc); > + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); > + > + return 0; > +} > + > +static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms) > { > u32 cmd, cfg; > int ret = 0; > @@ -420,6 +457,23 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) > return ret; > } > > +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) > +{ > + if (nfc->no_rb_pin) { > + /* This mode is used when there is no wired R/B pin. > + * It works like 'nand_soft_waitrdy()', but instead of > + * polling NAND_CMD_STATUS bit in the software loop, > + * it will wait for interrupt - controllers checks IO > + * bus and when it detects NAND_CMD_STATUS on it, it > + * raises interrupt. After interrupt, NAND_CMD_READ0 is > + * sent as terminator of the ready waiting procedure. > + */ > + return meson_nfc_wait_no_rb_pin(nfc, timeout_ms); > + } else { > + return meson_nfc_wait_rb_pin(nfc, timeout_ms); > + } > +} > + > static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) > { > struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); > @@ -1412,6 +1466,8 @@ static int meson_nfc_probe(struct platform_device *pdev) > return ret; > } > > + nfc->no_rb_pin = !of_property_read_bool(dev->of_node, "nand-rb"); > + > writel(0, nfc->reg_base + NFC_REG_CFG); > ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); > if (ret) {
Hi Arseniy, On 2023/6/7 3:54, Arseniy Krasnov wrote: > [ EXTERNAL EMAIL ] > > On 06.06.2023 22:51, Arseniy Krasnov wrote: >> 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> >> --- >> drivers/mtd/nand/raw/meson_nand.c | 58 ++++++++++++++++++++++++++++++- >> 1 file changed, 57 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c >> index 074e14225c06..f4c5309a9527 100644 >> --- a/drivers/mtd/nand/raw/meson_nand.c >> +++ b/drivers/mtd/nand/raw/meson_nand.c >> @@ -38,6 +38,7 @@ >> #define NFC_CMD_SCRAMBLER_DISABLE 0 >> #define NFC_CMD_SHORTMODE_DISABLE 0 >> #define NFC_CMD_RB_INT BIT(14) >> +#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16)) >> >> #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) >> >> @@ -94,6 +95,7 @@ >> >> /* nand flash controller delay 3 ns */ >> #define NFC_DEFAULT_DELAY 3000 >> +#define NFC_NO_RB_PIN_DELAY 5 >> >> #define ROW_ADDER(page, index) (((page) >> (8 * (index))) & 0xff) >> #define MAX_CYCLE_ADDRS 5 >> @@ -179,6 +181,7 @@ struct meson_nfc { >> u32 info_bytes; >> >> unsigned long assigned_cs; >> + bool no_rb_pin; >> }; >> >> enum { >> @@ -392,7 +395,41 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, >> } >> } >> >> -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >> +static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms) >> +{ >> + u32 cmd, cfg; >> + >> + meson_nfc_cmd_idle(nfc, nfc->timing.twb); >> + meson_nfc_drain_cmd(nfc); >> + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); >> + >> + cfg = readl(nfc->reg_base + NFC_REG_CFG); >> + cfg |= NFC_RB_IRQ_EN; >> + writel(cfg, nfc->reg_base + NFC_REG_CFG); >> + >> + reinit_completion(&nfc->completion); >> + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >> + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); > > ^^^ > >> + >> + /* use the max erase time as the maximum clock for waiting R/B */ >> + cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max; >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >> + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); > > ^^^ > Liang, I've implemented "new RB_INT" way instead of 'nand_soft_waitrdy()'. There were two numbers > 2 and 5 in 'meson_nfc_cmd_idle()' as time argument (here and above). I've replaced both with > define of 5 == NFC_NO_RB_PIN_DELAY. Is it correct? 2 and 5 were from doc? You can do like that. as i know, bigger has no impact. yes, them come from the example code of the controller datasheet; but i think we can delete them also. > > Thanks, Arseniy > >> + >> + if (!wait_for_completion_timeout(&nfc->completion, >> + msecs_to_jiffies(timeout_ms))) >> + return -ETIMEDOUT; >> + >> + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >> + meson_nfc_drain_cmd(nfc); >> + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); >> + >> + return 0; >> +} >> + >> +static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms) >> { >> u32 cmd, cfg; >> int ret = 0; >> @@ -420,6 +457,23 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >> return ret; >> } >> >> +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >> +{ >> + if (nfc->no_rb_pin) { >> + /* This mode is used when there is no wired R/B pin. >> + * It works like 'nand_soft_waitrdy()', but instead of >> + * polling NAND_CMD_STATUS bit in the software loop, >> + * it will wait for interrupt - controllers checks IO >> + * bus and when it detects NAND_CMD_STATUS on it, it >> + * raises interrupt. After interrupt, NAND_CMD_READ0 is >> + * sent as terminator of the ready waiting procedure. >> + */ >> + return meson_nfc_wait_no_rb_pin(nfc, timeout_ms); >> + } else { >> + return meson_nfc_wait_rb_pin(nfc, timeout_ms); >> + } >> +} >> + >> static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) >> { >> struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); >> @@ -1412,6 +1466,8 @@ static int meson_nfc_probe(struct platform_device *pdev) >> return ret; >> } >> >> + nfc->no_rb_pin = !of_property_read_bool(dev->of_node, "nand-rb"); >> + >> writel(0, nfc->reg_base + NFC_REG_CFG); >> ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); >> if (ret) {
Hi Arseniy, On 2023/6/7 3:51, Arseniy Krasnov wrote: > [ EXTERNAL EMAIL ] > > 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> > --- > drivers/mtd/nand/raw/meson_nand.c | 58 ++++++++++++++++++++++++++++++- > 1 file changed, 57 insertions(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c > index 074e14225c06..f4c5309a9527 100644 > --- a/drivers/mtd/nand/raw/meson_nand.c > +++ b/drivers/mtd/nand/raw/meson_nand.c > @@ -38,6 +38,7 @@ > #define NFC_CMD_SCRAMBLER_DISABLE 0 > #define NFC_CMD_SHORTMODE_DISABLE 0 > #define NFC_CMD_RB_INT BIT(14) > +#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16)) > > #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) > > @@ -94,6 +95,7 @@ > > /* nand flash controller delay 3 ns */ > #define NFC_DEFAULT_DELAY 3000 > +#define NFC_NO_RB_PIN_DELAY 5 > > #define ROW_ADDER(page, index) (((page) >> (8 * (index))) & 0xff) > #define MAX_CYCLE_ADDRS 5 > @@ -179,6 +181,7 @@ struct meson_nfc { > u32 info_bytes; > > unsigned long assigned_cs; > + bool no_rb_pin; > }; > > enum { > @@ -392,7 +395,41 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, > } > } > > -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) > +static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms) > +{ > + u32 cmd, cfg; > + > + meson_nfc_cmd_idle(nfc, nfc->timing.twb); > + meson_nfc_drain_cmd(nfc); > + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); > + > + cfg = readl(nfc->reg_base + NFC_REG_CFG); > + cfg |= NFC_RB_IRQ_EN; > + writel(cfg, nfc->reg_base + NFC_REG_CFG); > + > + reinit_completion(&nfc->completion); > + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; > + writel(cmd, nfc->reg_base + NFC_REG_CMD); > + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); > + > + /* use the max erase time as the maximum clock for waiting R/B */ > + cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max; > + writel(cmd, nfc->reg_base + NFC_REG_CMD); > + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); > + > + if (!wait_for_completion_timeout(&nfc->completion, > + msecs_to_jiffies(timeout_ms))) > + return -ETIMEDOUT; > + > + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; NAND_CMD_READ0 should only be needed for reading operation, so we need skip the other operations here, such as programming and erase. > + writel(cmd, nfc->reg_base + NFC_REG_CMD); > + meson_nfc_drain_cmd(nfc); > + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); > + > + return 0; > +} > + > +static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms) > { > u32 cmd, cfg; > int ret = 0; > @@ -420,6 +457,23 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) > return ret; > } > > +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) > +{ > + if (nfc->no_rb_pin) { > + /* This mode is used when there is no wired R/B pin. > + * It works like 'nand_soft_waitrdy()', but instead of > + * polling NAND_CMD_STATUS bit in the software loop, > + * it will wait for interrupt - controllers checks IO > + * bus and when it detects NAND_CMD_STATUS on it, it > + * raises interrupt. After interrupt, NAND_CMD_READ0 is > + * sent as terminator of the ready waiting procedure. > + */ > + return meson_nfc_wait_no_rb_pin(nfc, timeout_ms); > + } else { > + return meson_nfc_wait_rb_pin(nfc, timeout_ms); > + } > +} > + > static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) > { > struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); > @@ -1412,6 +1466,8 @@ static int meson_nfc_probe(struct platform_device *pdev) > return ret; > } > > + nfc->no_rb_pin = !of_property_read_bool(dev->of_node, "nand-rb"); > + > writel(0, nfc->reg_base + NFC_REG_CFG); > ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); > if (ret) { > -- > 2.35.0 >
On 07.06.2023 06:18, Liang Yang wrote: > Hi Arseniy, > > On 2023/6/7 3:51, Arseniy Krasnov wrote: >> [ EXTERNAL EMAIL ] >> >> 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> >> --- >> drivers/mtd/nand/raw/meson_nand.c | 58 ++++++++++++++++++++++++++++++- >> 1 file changed, 57 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c >> index 074e14225c06..f4c5309a9527 100644 >> --- a/drivers/mtd/nand/raw/meson_nand.c >> +++ b/drivers/mtd/nand/raw/meson_nand.c >> @@ -38,6 +38,7 @@ >> #define NFC_CMD_SCRAMBLER_DISABLE 0 >> #define NFC_CMD_SHORTMODE_DISABLE 0 >> #define NFC_CMD_RB_INT BIT(14) >> +#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16)) >> >> #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) >> >> @@ -94,6 +95,7 @@ >> >> /* nand flash controller delay 3 ns */ >> #define NFC_DEFAULT_DELAY 3000 >> +#define NFC_NO_RB_PIN_DELAY 5 >> >> #define ROW_ADDER(page, index) (((page) >> (8 * (index))) & 0xff) >> #define MAX_CYCLE_ADDRS 5 >> @@ -179,6 +181,7 @@ struct meson_nfc { >> u32 info_bytes; >> >> unsigned long assigned_cs; >> + bool no_rb_pin; >> }; >> >> enum { >> @@ -392,7 +395,41 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, >> } >> } >> >> -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >> +static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms) >> +{ >> + u32 cmd, cfg; >> + >> + meson_nfc_cmd_idle(nfc, nfc->timing.twb); >> + meson_nfc_drain_cmd(nfc); >> + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); >> + >> + cfg = readl(nfc->reg_base + NFC_REG_CFG); >> + cfg |= NFC_RB_IRQ_EN; >> + writel(cfg, nfc->reg_base + NFC_REG_CFG); >> + >> + reinit_completion(&nfc->completion); >> + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >> + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); >> + >> + /* use the max erase time as the maximum clock for waiting R/B */ >> + cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max; >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >> + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); >> + >> + if (!wait_for_completion_timeout(&nfc->completion, >> + msecs_to_jiffies(timeout_ms))) >> + return -ETIMEDOUT; >> + >> + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; > > NAND_CMD_READ0 should only be needed for reading operation, so we need skip the other operations here, such as programming and erase. Done, removed in v2. Thanks, Arseniy > >> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >> + meson_nfc_drain_cmd(nfc); >> + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); >> + >> + return 0; >> +} >> + >> +static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms) >> { >> u32 cmd, cfg; >> int ret = 0; >> @@ -420,6 +457,23 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >> return ret; >> } >> >> +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >> +{ >> + if (nfc->no_rb_pin) { >> + /* This mode is used when there is no wired R/B pin. >> + * It works like 'nand_soft_waitrdy()', but instead of >> + * polling NAND_CMD_STATUS bit in the software loop, >> + * it will wait for interrupt - controllers checks IO >> + * bus and when it detects NAND_CMD_STATUS on it, it >> + * raises interrupt. After interrupt, NAND_CMD_READ0 is >> + * sent as terminator of the ready waiting procedure. >> + */ >> + return meson_nfc_wait_no_rb_pin(nfc, timeout_ms); >> + } else { >> + return meson_nfc_wait_rb_pin(nfc, timeout_ms); >> + } >> +} >> + >> static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) >> { >> struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); >> @@ -1412,6 +1466,8 @@ static int meson_nfc_probe(struct platform_device *pdev) >> return ret; >> } >> >> + nfc->no_rb_pin = !of_property_read_bool(dev->of_node, "nand-rb"); >> + >> writel(0, nfc->reg_base + NFC_REG_CFG); >> ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); >> if (ret) { >> -- >> 2.35.0 >>
On 07.06.2023 06:14, Liang Yang wrote: > Hi Arseniy, > > On 2023/6/7 3:54, Arseniy Krasnov wrote: >> [ EXTERNAL EMAIL ] >> >> On 06.06.2023 22:51, Arseniy Krasnov wrote: >>> 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> >>> --- >>> drivers/mtd/nand/raw/meson_nand.c | 58 ++++++++++++++++++++++++++++++- >>> 1 file changed, 57 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c >>> index 074e14225c06..f4c5309a9527 100644 >>> --- a/drivers/mtd/nand/raw/meson_nand.c >>> +++ b/drivers/mtd/nand/raw/meson_nand.c >>> @@ -38,6 +38,7 @@ >>> #define NFC_CMD_SCRAMBLER_DISABLE 0 >>> #define NFC_CMD_SHORTMODE_DISABLE 0 >>> #define NFC_CMD_RB_INT BIT(14) >>> +#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16)) >>> >>> #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) >>> >>> @@ -94,6 +95,7 @@ >>> >>> /* nand flash controller delay 3 ns */ >>> #define NFC_DEFAULT_DELAY 3000 >>> +#define NFC_NO_RB_PIN_DELAY 5 >>> >>> #define ROW_ADDER(page, index) (((page) >> (8 * (index))) & 0xff) >>> #define MAX_CYCLE_ADDRS 5 >>> @@ -179,6 +181,7 @@ struct meson_nfc { >>> u32 info_bytes; >>> >>> unsigned long assigned_cs; >>> + bool no_rb_pin; >>> }; >>> >>> enum { >>> @@ -392,7 +395,41 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, >>> } >>> } >>> >>> -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >>> +static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms) >>> +{ >>> + u32 cmd, cfg; >>> + >>> + meson_nfc_cmd_idle(nfc, nfc->timing.twb); >>> + meson_nfc_drain_cmd(nfc); >>> + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); >>> + >>> + cfg = readl(nfc->reg_base + NFC_REG_CFG); >>> + cfg |= NFC_RB_IRQ_EN; >>> + writel(cfg, nfc->reg_base + NFC_REG_CFG); >>> + >>> + reinit_completion(&nfc->completion); >>> + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; >>> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >>> + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); >> >> ^^^ >> >>> + >>> + /* use the max erase time as the maximum clock for waiting R/B */ >>> + cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max; >>> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >>> + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); >> >> ^^^ >> Liang, I've implemented "new RB_INT" way instead of 'nand_soft_waitrdy()'. There were two numbers >> 2 and 5 in 'meson_nfc_cmd_idle()' as time argument (here and above). I've replaced both with >> define of 5 == NFC_NO_RB_PIN_DELAY. Is it correct? 2 and 5 were from doc? > > You can do like that. as i know, bigger has no impact. > yes, them come from the example code of the controller datasheet; but i think we can delete them also. Done, removed in v2. Thanks, Arseniy > >> >> Thanks, Arseniy >> >>> + >>> + if (!wait_for_completion_timeout(&nfc->completion, >>> + msecs_to_jiffies(timeout_ms))) >>> + return -ETIMEDOUT; >>> + >>> + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; >>> + writel(cmd, nfc->reg_base + NFC_REG_CMD); >>> + meson_nfc_drain_cmd(nfc); >>> + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); >>> + >>> + return 0; >>> +} >>> + >>> +static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms) >>> { >>> u32 cmd, cfg; >>> int ret = 0; >>> @@ -420,6 +457,23 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >>> return ret; >>> } >>> >>> +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) >>> +{ >>> + if (nfc->no_rb_pin) { >>> + /* This mode is used when there is no wired R/B pin. >>> + * It works like 'nand_soft_waitrdy()', but instead of >>> + * polling NAND_CMD_STATUS bit in the software loop, >>> + * it will wait for interrupt - controllers checks IO >>> + * bus and when it detects NAND_CMD_STATUS on it, it >>> + * raises interrupt. After interrupt, NAND_CMD_READ0 is >>> + * sent as terminator of the ready waiting procedure. >>> + */ >>> + return meson_nfc_wait_no_rb_pin(nfc, timeout_ms); >>> + } else { >>> + return meson_nfc_wait_rb_pin(nfc, timeout_ms); >>> + } >>> +} >>> + >>> static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) >>> { >>> struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); >>> @@ -1412,6 +1466,8 @@ static int meson_nfc_probe(struct platform_device *pdev) >>> return ret; >>> } >>> >>> + nfc->no_rb_pin = !of_property_read_bool(dev->of_node, "nand-rb"); >>> + >>> writel(0, nfc->reg_base + NFC_REG_CFG); >>> ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); >>> if (ret) {
diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 074e14225c06..f4c5309a9527 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -38,6 +38,7 @@ #define NFC_CMD_SCRAMBLER_DISABLE 0 #define NFC_CMD_SHORTMODE_DISABLE 0 #define NFC_CMD_RB_INT BIT(14) +#define NFC_CMD_RB_INT_NO_PIN ((0xb << 10) | BIT(18) | BIT(16)) #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) @@ -94,6 +95,7 @@ /* nand flash controller delay 3 ns */ #define NFC_DEFAULT_DELAY 3000 +#define NFC_NO_RB_PIN_DELAY 5 #define ROW_ADDER(page, index) (((page) >> (8 * (index))) & 0xff) #define MAX_CYCLE_ADDRS 5 @@ -179,6 +181,7 @@ struct meson_nfc { u32 info_bytes; unsigned long assigned_cs; + bool no_rb_pin; }; enum { @@ -392,7 +395,41 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, } } -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) +static int meson_nfc_wait_no_rb_pin(struct meson_nfc *nfc, int timeout_ms) +{ + u32 cmd, cfg; + + meson_nfc_cmd_idle(nfc, nfc->timing.twb); + meson_nfc_drain_cmd(nfc); + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); + + cfg = readl(nfc->reg_base + NFC_REG_CFG); + cfg |= NFC_RB_IRQ_EN; + writel(cfg, nfc->reg_base + NFC_REG_CFG); + + reinit_completion(&nfc->completion); + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; + writel(cmd, nfc->reg_base + NFC_REG_CMD); + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); + + /* use the max erase time as the maximum clock for waiting R/B */ + cmd = NFC_CMD_RB | NFC_CMD_RB_INT_NO_PIN | nfc->timing.tbers_max; + writel(cmd, nfc->reg_base + NFC_REG_CMD); + meson_nfc_cmd_idle(nfc, NFC_NO_RB_PIN_DELAY); + + if (!wait_for_completion_timeout(&nfc->completion, + msecs_to_jiffies(timeout_ms))) + return -ETIMEDOUT; + + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; + writel(cmd, nfc->reg_base + NFC_REG_CMD); + meson_nfc_drain_cmd(nfc); + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); + + return 0; +} + +static int meson_nfc_wait_rb_pin(struct meson_nfc *nfc, int timeout_ms) { u32 cmd, cfg; int ret = 0; @@ -420,6 +457,23 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) return ret; } +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) +{ + if (nfc->no_rb_pin) { + /* This mode is used when there is no wired R/B pin. + * It works like 'nand_soft_waitrdy()', but instead of + * polling NAND_CMD_STATUS bit in the software loop, + * it will wait for interrupt - controllers checks IO + * bus and when it detects NAND_CMD_STATUS on it, it + * raises interrupt. After interrupt, NAND_CMD_READ0 is + * sent as terminator of the ready waiting procedure. + */ + return meson_nfc_wait_no_rb_pin(nfc, timeout_ms); + } else { + return meson_nfc_wait_rb_pin(nfc, timeout_ms); + } +} + static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) { struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); @@ -1412,6 +1466,8 @@ static int meson_nfc_probe(struct platform_device *pdev) return ret; } + nfc->no_rb_pin = !of_property_read_bool(dev->of_node, "nand-rb"); + writel(0, nfc->reg_base + NFC_REG_CFG); ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); if (ret) {