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>,
Yixun Lan <yixun.lan@amlogic.com>,
Jianxin Pan <jianxin.pan@amlogic.com>
Cc: <oxffffaa@gmail.com>, <kernel@sberdevices.ru>,
<linux-mtd@lists.infradead.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-amlogic@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 1/5] mtd: rawnand: meson: fix NAND access for read/write
Date: Thu, 13 Apr 2023 08:10:31 +0300 [thread overview]
Message-ID: <68f3bea8-4b79-db48-172f-712dcabce65b@sberdevices.ru> (raw)
In-Reply-To: <dc690524-51d5-7bb9-a106-fa153c4e6250@amlogic.com>
On 12.04.2023 16:30, Liang Yang wrote:
> Hi,
>
> On 2023/4/12 20:03, Arseniy Krasnov wrote:
>> [ EXTERNAL EMAIL ]
>>
>>
>>
>> On 12.04.2023 13:24, Arseniy Krasnov wrote:
>>>
>>>
>>> On 12.04.2023 12:37, Liang Yang wrote:
>>>> Hi Arseniy,
>>>>
>>>> Thanks for pointing out this problem. also comment inline.
>>>>
>>>> On 2023/4/12 14:16, Arseniy Krasnov wrote:
>>>>> [ EXTERNAL EMAIL ]
>>>>>
>>>>> This fixes read/write functionality. New command sequences were ported
>>>>> from old vendor's driver. Without this patch driver works unstable. This
>>>>> change is tested with 'nanddump'/'nandwrite' utilities and mounting
>>>>> JFFS2 filesystem on AXG family (A113X SoC).
>>>>>
>>>>> Fixes: 8fae856c5350 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller")
>>>>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>>>>> ---
>>>>> drivers/mtd/nand/raw/meson_nand.c | 116 ++++++++++++++++++++++++++----
>>>>> 1 file changed, 101 insertions(+), 15 deletions(-)
>>>>>
>>>>> diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c
>>>>> index 074e14225c06..256c37c76526 100644
>>>>> --- a/drivers/mtd/nand/raw/meson_nand.c
>>>>> +++ b/drivers/mtd/nand/raw/meson_nand.c
>>>>> @@ -26,6 +26,7 @@
>>>>> #define NFC_CMD_IDLE (0xc << 14)
>>>>> #define NFC_CMD_CLE (0x5 << 14)
>>>>> #define NFC_CMD_ALE (0x6 << 14)
>>>>> +#define NFC_CMD_DRD (0x8 << 14)
>>>>> #define NFC_CMD_ADL ((0 << 16) | (3 << 20))
>>>>> #define NFC_CMD_ADH ((1 << 16) | (3 << 20))
>>>>> #define NFC_CMD_AIL ((2 << 16) | (3 << 20))
>>>>> @@ -84,6 +85,7 @@
>>>>> #define DMA_BUSY_TIMEOUT 0x100000
>>>>> #define CMD_FIFO_EMPTY_TIMEOUT 1000
>>>>> +#define DEVICE_READY_TIMEOUT 1000
>>>>> #define MAX_CE_NUM 2
>>>>> @@ -255,8 +257,26 @@ static void meson_nfc_select_chip(struct nand_chip *nand, int chip)
>>>>> }
>>>>> }
>>>>> +static int meson_nfc_wait_cmd_finish(struct meson_nfc *nfc,
>>>>> + unsigned int timeout_ms)
>>>>> +{
>>>>> + u32 cmd_size = 0;
>>>>> + int ret;
>>>>> +
>>>>> + /* wait cmd fifo is empty */
>>>>> + ret = readl_relaxed_poll_timeout(nfc->reg_base + NFC_REG_CMD, cmd_size,
>>>>> + !NFC_CMD_GET_SIZE(cmd_size),
>>>>> + 10, timeout_ms * 1000);
>>>>> + if (ret)
>>>>> + dev_err(nfc->dev, "wait for empty CMD FIFO timed out\n");
>>>>> +
>>>>> + return ret;
>>>>> +}
>>>>> +
>>>>> static void meson_nfc_cmd_idle(struct meson_nfc *nfc, u32 time)
>>>>> {
>>>>> + meson_nfc_wait_cmd_finish(nfc, 0);
>>>>> +
>>>>> writel(nfc->param.chip_select | NFC_CMD_IDLE | (time & 0x3ff),
>>>>> nfc->reg_base + NFC_REG_CMD);
>>>>> }
>>>>> @@ -308,23 +328,9 @@ static void meson_nfc_drain_cmd(struct meson_nfc *nfc)
>>>>> */
>>>>> meson_nfc_cmd_idle(nfc, 0);
>>>>> meson_nfc_cmd_idle(nfc, 0);
>>>>> + meson_nfc_wait_cmd_finish(nfc, 1000);
>>>>> }
>>>>> -static int meson_nfc_wait_cmd_finish(struct meson_nfc *nfc,
>>>>> - unsigned int timeout_ms)
>>>>> -{
>>>>> - u32 cmd_size = 0;
>>>>> - int ret;
>>>>> -
>>>>> - /* wait cmd fifo is empty */
>>>>> - ret = readl_relaxed_poll_timeout(nfc->reg_base + NFC_REG_CMD, cmd_size,
>>>>> - !NFC_CMD_GET_SIZE(cmd_size),
>>>>> - 10, timeout_ms * 1000);
>>>>> - if (ret)
>>>>> - dev_err(nfc->dev, "wait for empty CMD FIFO time out\n");
>>>>> -
>>>>> - return ret;
>>>>> -}
>>>>> static int meson_nfc_wait_dma_finish(struct meson_nfc *nfc)
>>>>> {
>>>>> @@ -631,6 +637,48 @@ static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand,
>>>>> return 0;
>>>>> }
>>>>> +static uint8_t meson_nfc_read_byte(struct nand_chip *nand)
>>>>> +{
>>>>> + struct meson_nfc *nfc = nand_get_controller_data(nand);
>>>>> +
>>>>> + writel(NFC_CMD_DRD, nfc->reg_base + NFC_REG_CMD);
>>>>> + meson_nfc_cmd_idle(nfc, nfc->timing.twb);
>>>>> + meson_nfc_drain_cmd(nfc);
>>>>> +
>>>>> + return readl(nfc->reg_base + NFC_REG_BUF);
>>>>> +}
>>>>> +
>>>>> +static int meson_nfc_wait_dev_ready(struct nand_chip *nand)
>>>>> +{
>>>>> + struct meson_nfc *nfc = nand_get_controller_data(nand);
>>>>> + u32 cs = nfc->param.chip_select;
>>>>> + unsigned long cnt = 0;
>>>>> +
>>>>> + meson_nfc_drain_cmd(nfc);
>>>>> +
>>>>> + writel(cs | NFC_CMD_CLE | NAND_CMD_STATUS, nfc->reg_base + NFC_REG_CMD);
>>>>> +
>>>>> + /* 10 ms. */
>>>>> + while (cnt < DEVICE_READY_TIMEOUT) {
>>>>> + uint8_t status;
>>>>> +
>>>>> + status = meson_nfc_read_byte(nand);
>>>>> +
>>>>> + if (status & NAND_STATUS_READY)
>>>>> + break;
>>>>> +
>>>>> + usleep_range(10, 11);
>>>>> + cnt++;
>>>>> + }
>>>>> +
>>>>> + if (cnt == DEVICE_READY_TIMEOUT) {
>>>>> + dev_err(nfc->dev, "device ready timeout\n");
>>>>> + return -ETIMEDOUT;
>>>>> + }
>>>>> +
>>>>> + return 0;
>>>>> +}
>>>>> +
>>>>> static int meson_nfc_write_page_sub(struct nand_chip *nand,
>>>>> int page, int raw)
>>>>> {
>>>>> @@ -643,6 +691,10 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand,
>>>>> u32 cmd;
>>>>> int ret;
>>>>> + ret = meson_nfc_wait_dev_ready(nand);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> meson_nfc_select_chip(nand, nand->cur_cs);
>>>>> data_len = mtd->writesize + mtd->oobsize;
>>>>> @@ -667,12 +719,20 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand,
>>>>> NFC_CMD_SCRAMBLER_DISABLE);
>>>>> }
>>>>> + ret = meson_nfc_wait_dma_finish(nfc);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_PAGEPROG;
>>>>> writel(cmd, nfc->reg_base + NFC_REG_CMD);
>>>>> meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tPROG_max));
>>>>> meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_TO_DEVICE);
>>>>> + ret = meson_nfc_wait_dev_ready(nand);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> return ret;
>>>>> }
>>>>> @@ -720,6 +780,21 @@ static void meson_nfc_check_ecc_pages_valid(struct meson_nfc *nfc,
>>>>> } while (!ret);
>>>>> }
>>>>> +static inline int meson_nfc_send_read(struct nand_chip *nand)
>>>>> +{
>>>>> + struct meson_nfc *nfc = nand_get_controller_data(nand);
>>>>> + u32 cs = nfc->param.chip_select;
>>>>> + int ret;
>>>>> +
>>>>> + ret = meson_nfc_wait_dev_ready(nand);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> + writel(cs | NFC_CMD_CLE | NAND_CMD_READ0, nfc->reg_base + NFC_REG_CMD);
>>>>> +
>>>>> + return 0;
>>>>> +}
>>>>> +
>>>>
>>>> it already calls meson_nfc_queue_rb() in meson_nfc_rw_cmd_prepare_and_execute(). Could you implements this in meson_nfc_queue_rb()? and we can use the irq method.
>>>> also without Ready/Busy pin, the meson_nfc_queue_rb() should change like below:
>>>> ......
>>>> #define NFC_CMD_RB_INT ((0xb << 10) | BIT(18))
>>
>> Sorry, I can see this define as (and it is used in the driver):
>> #define NFC_CMD_RB_INT BIT(14)
>>
>> in drivers/mtd/nand/raw/meson_nand.c
>>
>> Which one is correct ?
>
> we need to modify the define 'NFC_CMD_RB_INT' as ((0xb << 10) | BIT(18)).
>
Ok, NFC_CMD_RB_INT - it is "Ready/Busy_Interrupt" ? You suppose that currently it is
defined incorrectly, so irq waiting does not work?
Thanks, Arseniy
>>
>> Thanks, Arseniy
>>
>>>>
>>>> meson_nfc_cmd_idle(nfc, 0);
>>>> cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS;
>>>> writel(cmd, nfc->reg_base + NFC_REG_CMD);
>>>> meson_nfc_cmd_idle(nfc, 5);
>>>> cmd = NFC_CMD_RB | NFC_CMD_RB_INT | nfc->timing.tbers_max;
>>>> writel(cmd, nfc->reg_base + NFC_REG_CMD);
>>>>
>>>> ret = wait_for_completion_timeout(&nfc->completion,
>>>> msecs_to_jiffies(timeout_ms));
>>>> if (ret == 0)
>>>> ret = -1;
>>>>
>>>> writel(cs | NFC_CMD_CLE | NAND_CMD_READ0, nfc->reg_base + NFC_REG_CMD);
>>>> ......
>>>>
>>>
>>> Thanks for reply! I'll try this code! One more question about OOB processing in this
>>> driver (as You are author of it):
>>>
>>> OOB size is 64 bytes, but for example if I have 1K ECC, 2 bytes user bytes and 14
>>> bytes for ECC code for each 1K. In this case I have access to only 32 bytes of OOB:
>>> 2 x (2 user bytes + 14 ECC bytes). Correct me if i'm wrong, but rest of OOB (next
>>> 32 bytes) become unavailable (in both raw and ECC modes) ?
>>>
>>> Thanks, Arseniy
>>>
>>>>> static int meson_nfc_read_page_sub(struct nand_chip *nand,
>>>>> int page, int raw)
>>>>> {
>>>>> @@ -734,10 +809,18 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand,
>>>>> data_len = mtd->writesize + mtd->oobsize;
>>>>> info_len = nand->ecc.steps * PER_INFO_BYTE;
>>>>> + ret = meson_nfc_wait_dev_ready(nand);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> ret = meson_nfc_rw_cmd_prepare_and_execute(nand, page, DIRREAD);
>>>>> if (ret)
>>>>> return ret;
>>>>> + ret = meson_nfc_send_read(nand);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf,
>>>>> data_len, meson_chip->info_buf,
>>>>> info_len, DMA_FROM_DEVICE);
>>>>> @@ -754,6 +837,9 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand,
>>>>> }
>>>>> ret = meson_nfc_wait_dma_finish(nfc);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> meson_nfc_check_ecc_pages_valid(nfc, nand, raw);
>>>>> meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_FROM_DEVICE);
>>>>
>>
>
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2023-04-13 5:14 UTC|newest]
Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-12 6:16 [PATCH v1 0/5] refactoring and fix for Meson NAND Arseniy Krasnov
2023-04-12 6:16 ` [PATCH v1 1/5] mtd: rawnand: meson: fix NAND access for read/write Arseniy Krasnov
2023-04-12 9:37 ` Liang Yang
2023-04-12 10:24 ` Arseniy Krasnov
2023-04-12 12:03 ` Arseniy Krasnov
2023-04-12 13:30 ` Liang Yang
2023-04-13 5:10 ` Arseniy Krasnov [this message]
2023-04-13 5:57 ` Liang Yang
2023-04-17 6:47 ` Arseniy Krasnov
2023-04-17 13:54 ` Liang Yang
2023-04-17 14:10 ` Arseniy Krasnov
2023-04-19 19:43 ` Arseniy Krasnov
2023-04-20 14:22 ` Liang Yang
2023-04-21 5:57 ` Arseniy Krasnov
2023-04-26 7:53 ` Arseniy Krasnov
2023-04-26 12:17 ` Liang Yang
2023-04-26 14:47 ` Arseniy Krasnov
2023-05-04 6:16 ` Arseniy Krasnov
2023-05-10 11:34 ` Arseniy Krasnov
2023-05-11 10:43 ` Arseniy Krasnov
2023-04-12 6:16 ` [PATCH v1 2/5] mtd: rawnand: meson: replace GENMASK() macro with define Arseniy Krasnov
2023-04-12 7:37 ` Neil Armstrong
2023-04-12 10:06 ` David Laight
2023-04-12 10:11 ` Arseniy Krasnov
2023-04-12 6:16 ` [PATCH v1 3/5] mtd: rawnand: meson: check buffer length Arseniy Krasnov
2023-04-12 7:39 ` Miquel Raynal
2023-04-12 6:16 ` [PATCH v1 4/5] mtd: rawnand: meson: clear OOB buffer before read Arseniy Krasnov
2023-04-12 7:44 ` Miquel Raynal
2023-04-12 7:47 ` Miquel Raynal
2023-04-12 9:20 ` Arseniy Krasnov
2023-04-12 9:36 ` Miquel Raynal
2023-04-12 10:14 ` Arseniy Krasnov
2023-04-12 10:51 ` Liang Yang
2023-04-12 11:36 ` Liang Yang
2023-04-12 11:43 ` Dmitry Rokosov
2023-04-12 11:47 ` Arseniy Krasnov
2023-04-12 12:28 ` Liang Yang
2023-04-12 12:18 ` Miquel Raynal
2023-04-12 12:22 ` Arseniy Krasnov
2023-04-12 12:57 ` Miquel Raynal
2023-04-12 14:04 ` Liang Yang
2023-04-12 14:32 ` Miquel Raynal
2023-04-13 5:32 ` Liang Yang
2023-04-13 6:11 ` Liang Yang
2023-04-13 7:00 ` Arseniy Krasnov
2023-04-13 8:22 ` Miquel Raynal
2023-04-13 9:36 ` Arseniy Krasnov
2023-04-13 10:22 ` Miquel Raynal
2023-04-13 10:35 ` Arseniy Krasnov
2023-04-18 5:12 ` Arseniy Krasnov
2023-04-18 12:24 ` Liang Yang
2023-04-18 12:44 ` Arseniy Krasnov
2023-04-18 13:25 ` Miquel Raynal
2023-04-18 14:57 ` Arseniy Krasnov
2023-04-18 15:07 ` Arseniy Krasnov
2023-04-19 3:05 ` Liang Yang
2023-04-19 6:41 ` Arseniy Krasnov
2023-04-20 9:37 ` Arseniy Krasnov
2023-04-26 13:51 ` Liang Yang
2023-04-26 14:46 ` Arseniy Krasnov
2023-05-02 9:59 ` Miquel Raynal
2023-05-02 10:11 ` Arseniy Krasnov
2023-05-02 11:27 ` Miquel Raynal
2023-05-02 11:32 ` Arseniy Krasnov
2023-05-02 12:17 ` Miquel Raynal
2023-05-02 12:24 ` Arseniy Krasnov
2023-05-02 13:05 ` Miquel Raynal
2023-05-02 16:13 ` Arseniy Krasnov
2023-05-03 8:03 ` Miquel Raynal
2023-05-03 10:23 ` Arseniy Krasnov
2023-05-04 11:37 ` Arseniy Krasnov
2023-05-04 12:17 ` Miquel Raynal
2023-05-04 12:31 ` Arseniy Krasnov
2023-05-03 19:48 ` Richard Weinberger
2023-05-04 11:40 ` Arseniy Krasnov
2023-04-13 8:22 ` Miquel Raynal
2023-04-12 19:15 ` Dmitry Rokosov
2023-04-12 20:56 ` Miquel Raynal
2023-04-13 9:27 ` Dmitry Rokosov
2023-04-13 10:29 ` Miquel Raynal
2023-04-13 14:03 ` Dmitry Rokosov
2023-04-12 6:16 ` [PATCH v1 5/5] mtd: rawnand: meson: remove unneeded bitwise OR with zeroes Arseniy Krasnov
2023-04-12 7:45 ` [PATCH v1 0/5] refactoring and fix for Meson NAND Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68f3bea8-4b79-db48-172f-712dcabce65b@sberdevices.ru \
--to=avkrasnov@sberdevices.ru \
--cc=jbrunet@baylibre.com \
--cc=jianxin.pan@amlogic.com \
--cc=kernel@sberdevices.ru \
--cc=khilman@baylibre.com \
--cc=liang.yang@amlogic.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=miquel.raynal@bootlin.com \
--cc=neil.armstrong@linaro.org \
--cc=oxffffaa@gmail.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=yixun.lan@amlogic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox