From: Alexander Dahl <ada@thorsis.com>
To: Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Michael Trimarchi <michael@amarulasolutions.com>
Cc: Balamanikandan Gunasundar
<balamanikandan.gunasundar@microchip.com>,
Eugen Hristev <eugen.hristev@collabora.com>,
Mihai Sain <mihai.sain@microchip.com>,
Li Bin <bin.li@microchip.com>,
u-boot@lists.denx.de
Subject: [PATCH v2 6/6] cmd: nand: Add new optional sub-command 'onfi'
Date: Wed, 20 Mar 2024 10:02:14 +0100 [thread overview]
Message-ID: <20240320090214.40465-7-ada@thorsis.com> (raw)
In-Reply-To: <20240320090214.40465-1-ada@thorsis.com>
Override the ONFI timing mode at runtime.
Signed-off-by: Alexander Dahl <ada@thorsis.com>
---
Notes:
v2:
- initial patch version (not present in v1)
cmd/Kconfig | 10 ++++++
cmd/nand.c | 61 ++++++++++++++++++++++++++++++++
drivers/mtd/nand/raw/nand_base.c | 2 +-
include/linux/mtd/rawnand.h | 1 +
4 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 61e280fb1a4..c39cc297306 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1421,6 +1421,7 @@ config CMD_NAND
NAND support.
if CMD_NAND
+
config CMD_NAND_TRIMFFS
bool "nand write.trimffs"
default y if ARCH_SUNXI
@@ -1437,6 +1438,15 @@ config CMD_NAND_TORTURE
help
NAND torture support.
+config CMD_NAND_ONFI
+ bool "nand onfi"
+ help
+ Set ONFI timing modes explicitly.
+ This is a debugging command to switch to slower ONFI timing
+ modes for testing.
+ In normal operation determining the timing mode automatically
+ should work fine, and you don't need this.
+
endif # CMD_NAND
config CMD_NVME
diff --git a/cmd/nand.c b/cmd/nand.c
index fe834c4ac5c..2b83a5ad1b8 100644
--- a/cmd/nand.c
+++ b/cmd/nand.c
@@ -494,6 +494,48 @@ static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
}
}
+#ifdef CONFIG_CMD_NAND_ONFI
+static int do_nand_onfi(struct mtd_info *mtd, int mode)
+{
+ struct nand_chip *chip;
+ int ret;
+ int i;
+
+ if (mtd->type != MTD_NANDFLASH) {
+ printf("MTD device is no NAND flash!\n");
+ return CMD_RET_FAILURE;
+ }
+
+ chip = mtd_to_nand(mtd);
+
+ if (mode < 0) {
+ printf("Reporting current ONFI settings not yet supported!\n");
+ return CMD_RET_FAILURE;
+ }
+
+ ret = onfi_init_data_interface(chip, chip->data_interface,
+ NAND_SDR_IFACE, mode);
+ if (ret) {
+ printf("onfi_init_data_interface() for mode %d failed with error %d\n",
+ mode, ret);
+ return CMD_RET_FAILURE;
+ }
+
+ for (i = 0; i < chip->numchips; i++) {
+ chip->select_chip(mtd, i);
+ ret = nand_setup_data_interface(chip, i);
+ chip->select_chip(mtd, -1);
+ if (ret) {
+ printf("nand_setup_data_interface() for mode %d failed with error %d\n",
+ mode, ret);
+ return CMD_RET_FAILURE;
+ }
+ }
+
+ return CMD_RET_SUCCESS;
+}
+#endif
+
static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
@@ -919,6 +961,21 @@ static int do_nand(struct cmd_tbl *cmdtp, int flag, int argc,
}
#endif
+#ifdef CONFIG_CMD_NAND_ONFI
+ /*
+ * Syntax is:
+ * 0 1 2
+ * nand onfi [mode]
+ */
+ if (strcmp(cmd, "onfi") == 0) {
+ int mode = -1;
+
+ if (argc > 2)
+ mode = dectoul(argv[2], NULL);
+ return do_nand_onfi(mtd, mode);
+ }
+#endif
+
usage:
return CMD_RET_USAGE;
}
@@ -961,6 +1018,10 @@ U_BOOT_LONGHELP(nand,
" bring nand to lock state or display locked pages\n"
"nand unlock[.allexcept] [offset] [size] - unlock section"
#endif
+#ifdef CONFIG_CMD_NAND_ONFI
+ "\n"
+ "nand onfi [mode] - set ONFI mode\n"
+#endif
#ifdef CONFIG_ENV_OFFSET_OOB
"\n"
"nand env.oob - environment offset in OOB of block 0 of"
diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 688d17ba3c2..2384425a746 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -983,7 +983,7 @@ static int nand_onfi_set_timings(struct mtd_info *mtd, struct nand_chip *chip)
*
* Returns 0 for success or negative error code otherwise.
*/
-static int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
+int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
{
struct mtd_info *mtd = nand_to_mtd(chip);
int ret;
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index 4abaf4734cf..07bc4cc9051 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -1315,6 +1315,7 @@ void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len);
void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len);
void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len);
uint8_t nand_read_byte(struct mtd_info *mtd);
+int nand_setup_data_interface(struct nand_chip *chip, int chipnr);
/* get timing characteristics from ONFI timing mode. */
const struct nand_sdr_timings *onfi_async_timing_mode_to_sdr_timings(int mode);
--
2.39.2
next prev parent reply other threads:[~2024-03-20 9:03 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 9:02 [PATCH v2 0/6] mtd: nand: raw: Collected improvements Alexander Dahl
2024-03-20 9:02 ` [PATCH v2 1/6] mtd: nand: raw: Use macro nand_to_mtd() where appropriate Alexander Dahl
2024-03-20 9:02 ` [PATCH v2 2/6] mtd: nand: raw: Port another option flag from Linux Alexander Dahl
2024-03-20 9:02 ` [PATCH v2 3/6] mtd: nand: raw: Fix (most) Kconfig indentation Alexander Dahl
2024-03-20 9:02 ` [PATCH v2 4/6] mtd: nand: raw: atmel: Introduce optional debug commands Alexander Dahl
2024-03-20 9:02 ` [PATCH v2 5/6] mtd: nand: raw: atmel: Fix comment in timings preparation Alexander Dahl
2024-03-20 12:25 ` Michael Nazzareno Trimarchi
2024-03-20 9:02 ` Alexander Dahl [this message]
2024-03-20 12:48 ` [PATCH v2 6/6] cmd: nand: Add new optional sub-command 'onfi' Mihai.Sain
2024-03-20 14:08 ` Mihai.Sain
2024-03-21 9:16 ` Michael Nazzareno Trimarchi
2024-03-22 10:02 ` Mihai.Sain
2024-03-22 11:46 ` Alexander Dahl
2024-03-22 11:54 ` Michael Nazzareno Trimarchi
2024-03-22 12:02 ` Alexander Dahl
2024-03-22 12:34 ` Michael Nazzareno Trimarchi
2024-04-14 13:41 ` [PATCH v2 0/6] mtd: nand: raw: Collected improvements Dario Binacchi
2024-04-15 6:13 ` Alexander Dahl
2024-04-15 6:32 ` Dario Binacchi
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=20240320090214.40465-7-ada@thorsis.com \
--to=ada@thorsis.com \
--cc=balamanikandan.gunasundar@microchip.com \
--cc=bin.li@microchip.com \
--cc=dario.binacchi@amarulasolutions.com \
--cc=eugen.hristev@collabora.com \
--cc=michael@amarulasolutions.com \
--cc=mihai.sain@microchip.com \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.