We need these values and macro to correctly write "bootloader"
partition in Optimus protocol, so let's export them to arch-meson
header and also provide more detailed information about each
macro.

Signed-off-by: Arseniy Krasnov <avkras...@salutedevices.com>
---
 arch/arm/include/asm/arch-meson/rawnand.h | 38 +++++++++++++++++++++++
 drivers/mtd/nand/raw/meson_nand.c         | 13 +-------
 2 files changed, 39 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-meson/rawnand.h

diff --git a/arch/arm/include/asm/arch-meson/rawnand.h 
b/arch/arm/include/asm/arch-meson/rawnand.h
new file mode 100644
index 00000000000..81bf6ef7e37
--- /dev/null
+++ b/arch/arm/include/asm/arch-meson/rawnand.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2025 SaluteDevices, Inc.
+ */
+
+#ifndef __MESON_RAWNAND_H__
+#define __MESON_RAWNAND_H__
+
+#include <asm/arch/nand.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/rawnand.h>
+
+/* M2N means 'memory to NAND', e.g. write. */
+#define NFC_CMD_M2N    ((0 << 17) | BIT(21))
+/* N2M means 'NAND to memory', e.g. read. */
+#define NFC_CMD_N2M    ((1 << 17) | BIT(21))
+
+/*
+ * Macro to create value for read/write command.
+ *
+ * 'cmd_dir' - direction, e.g. read or write.
+ * 'ran' - scrambler mode (enabled or not).
+ * 'bch' - ECC mode (strength and size).
+ * 'short_mode' - short mode (enabled or not).
+ * 'page_size' - size of page.
+ * 'pages' - number of pages to access.
+ */
+#define CMDRWGEN(cmd_dir, ran, bch, short_mode, page_size, pages)      \
+       (                                                               \
+               (cmd_dir)                       |                       \
+               ((ran))                         |                       \
+               ((bch) << 14)                   |                       \
+               ((short_mode) << 13)            |                       \
+               (((page_size) & 0x7F) << 6)     |                       \
+               ((pages) & 0x3F)                                        \
+       )
+
+#endif
diff --git a/drivers/mtd/nand/raw/meson_nand.c 
b/drivers/mtd/nand/raw/meson_nand.c
index 28c851f103b..81122315f45 100644
--- a/drivers/mtd/nand/raw/meson_nand.c
+++ b/drivers/mtd/nand/raw/meson_nand.c
@@ -11,6 +11,7 @@
 
 #include <nand.h>
 #include <asm/io.h>
+#include <asm/arch/rawnand.h>
 #include <dm.h>
 #include <dm/device_compat.h>
 #include <dm/ofnode.h>
@@ -34,8 +35,6 @@
 #define NFC_CMD_AIL                    ((2 << 16) | (3 << 20))
 #define NFC_CMD_AIH                    ((3 << 16) | (3 << 20))
 #define NFC_CMD_SEED                   ((8 << 16) | (3 << 20))
-#define NFC_CMD_M2N                    ((0 << 17) | (2 << 20))
-#define NFC_CMD_N2M                    ((1 << 17) | (2 << 20))
 #define NFC_CMD_RB                     BIT(20)
 #define NFC_CMD_SCRAMBLER_ENABLE       BIT(19)
 #define NFC_CMD_SCRAMBLER_DISABLE      0
@@ -61,16 +60,6 @@
 #define NFC_REG_PINS           0x30
 #define NFC_REG_VER            0x38
 
-#define CMDRWGEN(cmd_dir, ran, bch, short_mode, page_size, pages)      \
-       (                                                               \
-               (cmd_dir)                       |                       \
-               (ran)                           |                       \
-               ((bch) << 14)                   |                       \
-               ((short_mode) << 13)            |                       \
-               (((page_size) & 0x7f) << 6)     |                       \
-               ((pages) & 0x3f)                                        \
-       )
-
 #define GENCMDDADDRL(adl, addr)                ((adl) | ((addr) & 0xffff))
 #define GENCMDDADDRH(adh, addr)                ((adh) | (((addr) >> 16) & 
0xffff))
 #define GENCMDIADDRL(ail, addr)                ((ail) | ((addr) & 0xffff))
-- 
2.30.1

Reply via email to