Skip to contentSkip to conversation

s5pc1xx: support onenand driver

PATCH Superseded Minkyu Kang 3 participants 4 messages Sep 4, 2009

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 s5pc1xx: support onenand driver

This patch includes the onenand driver for s5pc1xx

---
 drivers/mtd/onenand/Makefile     |    2 +
 drivers/mtd/onenand/samsung.c    |  624 ++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/onenand.h      |    1 +
 include/linux/mtd/onenand_regs.h |    4 +
 include/samsung_onenand.h        |   91 ++++++
 5 files changed, 722 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/onenand/samsung.c
 create mode 100644 include/samsung_onenand.h
drivers/mtd/onenand/Makefile +2 -0
index 1d35a57..9317341 100644
@@ -26,6 +26,8 @@ include $(TOPDIR)/config.mk
 LIB	:= $(obj)libonenand.a
 
 COBJS-$(CONFIG_CMD_ONENAND)	:= onenand_uboot.o onenand_base.o onenand_bbt.o
+COBJS-$(CONFIG_S3C64XX)		+= samsung.o
+COBJS-$(CONFIG_S5PC1XX)		+= samsung.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/mtd/onenand/samsung.c new file +624 -0

624 lines not on this page · raw message

include/linux/mtd/onenand.h +1 -0
index 06f7baf..9a6f317 100644
@@ -135,6 +135,7 @@ struct onenand_chip {
 #define ONENAND_HAS_CONT_LOCK		(0x0001)
 #define ONENAND_HAS_UNLOCK_ALL		(0x0002)
 #define ONENAND_HAS_2PLANE		(0x0004)
+#define ONENAND_RUNTIME_BADBLOCK_CHECK	(0x0200)
 #define ONENAND_PAGEBUF_ALLOC		(0x1000)
 #define ONENAND_OOBBUF_ALLOC		(0x2000)
 
include/linux/mtd/onenand_regs.h +4 -0
index fc63380..07fed1c 100644
@@ -121,6 +121,8 @@
 #define ONENAND_CMD_LOCK_TIGHT		(0x2C)
 #define ONENAND_CMD_UNLOCK_ALL		(0x27)
 #define ONENAND_CMD_ERASE		(0x94)
+#define ONENAND_CMD_MULTIBLOCK_ERASE	(0x95)
+#define ONENAND_CMD_ERASE_VERIFY	(0x71)
 #define ONENAND_CMD_RESET		(0xF0)
 #define ONENAND_CMD_READID		(0x90)
 
@@ -184,7 +186,9 @@
  * ECC Status Reigser FF00h (R)
  */
 #define ONENAND_ECC_1BIT		(1 << 0)
+#define ONENAND_ECC_1BIT_ALL		(0x5555)
 #define ONENAND_ECC_2BIT		(1 << 1)
 #define ONENAND_ECC_2BIT_ALL		(0xAAAA)
+#define ONENAND_ECC_4BIT_UNCORRECTABLE	(0x1010)
 
 #endif				/* __ONENAND_REG_H */
include/samsung_onenand.h new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
1.5.4.3
#1 lore raw

PATCH 2/4 s5pc1xx: support onenand driver

Dear Minkyu Kang,

Quoted 4 lines · In message <[email protected]> you wrote:

This patch includes the onenand driver for s5pc1xx

...

Quoted 9 lines
drivers/mtd/onenand/samsung.c new file +9 -0
+static int s3c_read_reg(int offset)
+{
+	return readl(onenand->base + offset);
+}
+
+static void s3c_write_reg(int value, int offset)
+{
+	writel(value, onenand->base + offset);
+}

drivers/mtd/onenand/samsung.c line 112

Quoted 10 lines
drivers/mtd/onenand/samsung.c new file +10 -0
+
+static int s3c_read_cmd(unsigned int cmd)
+{
+	return readl(onenand->ahb_addr + cmd);
+}
+
+static void s3c_write_cmd(int value, unsigned int cmd)
+{
+	writel(value, onenand->ahb_addr + cmd);
+}

PLease see comments to previous patch about usage of register plus offset versus using proper C structures.

Please change this code to use structs, too.

drivers/mtd/onenand/samsung.c line 117

Quoted 4 lines
drivers/mtd/onenand/samsung.c new file +4 -0
+static unsigned int s5pc100_mem_addr(int fba, int fpa, int fsa)
+{
+	return (fba << 13) | (fpa << 7) | (fsa << 5);
+}

This function needs explanation. Please add a comment what it does, and how.

...

drivers/mtd/onenand/samsung.c line 443

Quoted 7 lines
drivers/mtd/onenand/samsung.c new file +7 -0
+static int s3c_onenand_bbt_wait(struct mtd_info *mtd, int state)
+{
+	unsigned int flags = INT_ACT | LOAD_CMP;
+	unsigned int stat;
+	unsigned long timeout = 0x10000;
+
+	while (1 && timeout--) {

Please do not add bogus code. Remove the "1 &&"

...

Quoted 18 lines
drivers/mtd/onenand/samsung.c new file +18 -0
+void s3c_onenand_init(struct mtd_info *mtd)
+{
+	struct onenand_chip *this = mtd->priv;
+
+	onenand = malloc(sizeof(struct s3c_onenand));
+	if (!onenand)
+		return;
+
+	onenand->page_buf = malloc(SZ_4K * sizeof(char));
+	if (!onenand->page_buf)
+		return;
+	memset(onenand->page_buf, 0xFF, SZ_4K);
+
+	onenand->oob_buf = malloc(128 * sizeof(char));
+	if (!onenand->oob_buf)
+		return;
+	memset(onenand->oob_buf, 0xFF, 128);
+

drivers/mtd/onenand/samsung.c line 610

Quoted 10 lines
drivers/mtd/onenand/samsung.c new file +10 -0
+	onenand->mtd = mtd;
+
+#ifdef CONFIG_S5PC1XX
+	/* S5PC100 specific values */
+	onenand->base = (void *) 0xE7100000;
+	onenand->ahb_addr = (void *) 0xB0000000;
+	onenand->mem_addr = s5pc100_mem_addr;
+#else
+#error Please fix it at s3c6410
+#endif

What does this mean?

Quoted 5 lines
include/samsung_onenand.h new file +0 -0
new file mode 100644
index 0000000..91b40e1

...

include/samsung_onenand.h line 38

Quoted 9 lines
include/samsung_onenand.h new file +9 -0
+/*
+ * OneNAND Controller
+ */
+#define MEM_CFG_OFFSET		0x0000
+#define BURST_LEN_OFFSET	0x0010
+#define MEM_RESET_OFFSET	0x0020
+#define INT_ERR_STAT_OFFSET	0x0030
+#define INT_ERR_MASK_OFFSET	0x0040
+#define INT_ERR_ACK_OFFSET	0x0050

Please use a C struct instead.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Lack of skill dictates economy of style.                - Joey Ramone
#2 lore raw

PATCH 2/4 s5pc1xx: support onenand driver

Hi,

Quoted 22 lines · Wolfgang Denk

Dear Minkyu Kang,

Quoted 4 lines · In message <[email protected]> you wrote:

This patch includes the onenand driver for s5pc1xx

...

Quoted 14 lines
drivers/mtd/onenand/samsung.c new file +14 -0
+static int s3c_read_reg(int offset)
+{
+ ? ? return readl(onenand->base + offset);
+}
+
+static void s3c_write_reg(int value, int offset)
+{
+ ? ? writel(value, onenand->base + offset);
+}
+
+static int s3c_read_cmd(unsigned int cmd)
+{
+ ? ? return readl(onenand->ahb_addr + cmd);
+}
Quoted 8 lines

drivers/mtd/onenand/samsung.c line 112

Quoted 5 lines
drivers/mtd/onenand/samsung.c new file +5 -0
+
+static void s3c_write_cmd(int value, unsigned int cmd)
+{
+ ? ? writel(value, onenand->ahb_addr + cmd);
+}

PLease see comments to previous patch about usage of register plus offset versus using proper C structures.

I have different opinion. How much register map is required? I mean in case of read/write cmd, it has about 256MiB range. then how do you cast is as C structures.
Only some small range for example. 1K or less. C structures possible. but more than this. it's too huge to case it.

Quoted 10 lines

Please change this code to use structs, too.

drivers/mtd/onenand/samsung.c line 117

Quoted 4 lines
drivers/mtd/onenand/samsung.c new file +4 -0
+static unsigned int s5pc100_mem_addr(int fba, int fpa, int fsa)
+{
+ ? ? return (fba << 13) | (fpa << 7) | (fsa << 5);
+}

This function needs explanation. Please add a comment what it does, and how.

It's mandatory. no need to shift. It's fixed. with this reason. we covers alomst 256MiB memory range.

Quoted 11 lines

...

Review

Quoted 7 lines
(quoted diff) +7 -0
+static int s3c_onenand_bbt_wait(struct mtd_info *mtd, int state)
+{
+ ? ? unsigned int flags = INT_ACT | LOAD_CMP;
+ ? ? unsigned int stat;
+ ? ? unsigned long timeout = 0x10000;
+
+ ? ? while (1 && timeout--) {

Please do not add bogus code. Remove the "1 &&"

Agreed.

Quoted 24 lines

...

Quoted 22 lines
(quoted diff) +22 -0
+void s3c_onenand_init(struct mtd_info *mtd)
+{
+ ? ? struct onenand_chip *this = mtd->priv;
+
+ ? ? onenand = malloc(sizeof(struct s3c_onenand));
+ ? ? if (!onenand)
+ ? ? ? ? ? ? return;
+
+ ? ? onenand->page_buf = malloc(SZ_4K * sizeof(char));
+ ? ? if (!onenand->page_buf)
+ ? ? ? ? ? ? return;
+ ? ? memset(onenand->page_buf, 0xFF, SZ_4K);
+
+ ? ? onenand->oob_buf = malloc(128 * sizeof(char));
+ ? ? if (!onenand->oob_buf)
+ ? ? ? ? ? ? return;
+ ? ? memset(onenand->oob_buf, 0xFF, 128);
+
+ ? ? onenand->mtd = mtd;
+
+#ifdef CONFIG_S5PC1XX
+ ? ? /* S5PC100 specific values */
Quoted 8 lines

drivers/mtd/onenand/samsung.c line 610

Quoted 6 lines

+ ? ? onenand->base = (void *) 0xE7100000;
+ ? ? onenand->ahb_addr = (void *) 0xB0000000;
+ ? ? onenand->mem_addr = s5pc100_mem_addr;

drivers/mtd/onenand/samsung.c new file +3 -0
+#else
+#error Please fix it at s3c6410
+#endif

What does this mean?

Now we got two version of samsung.c one for s3c6410, another is this one. No problem to add it for s3c6410

Quoted 7 lines
Quoted 6 lines
include/samsung_onenand.h new file +0 -0
new file mode 100644
index 0000000..91b40e1

...

Quoted 11 lines

include/samsung_onenand.h

Quoted 9 lines
include/samsung_onenand.h new file +9 -0
+/*
+ * OneNAND Controller
+ */
+#define MEM_CFG_OFFSET ? ? ? ? ? ? ? 0x0000
+#define BURST_LEN_OFFSET ? ? 0x0010
+#define MEM_RESET_OFFSET ? ? 0x0020
+#define INT_ERR_STAT_OFFSET ?0x0030
+#define INT_ERR_MASK_OFFSET ?0x0040
+#define INT_ERR_ACK_OFFSET ? 0x0050

Please use a C struct instead.

The end address is 0x400. Are you really need it to cast? I don't think so.

Thank you,
Kyungmin Park

#3 lore raw

PATCH 2/4 s5pc1xx: support onenand driver

Dear Kyungmin Park,

Quoted 5 lines · In message <[email protected]> you…
Quoted 3 lines

PLease see comments to previous patch about usage of register plus offset versus using proper C structures.

I have different opinion. How much register map is required? I mean in

Size does actually not matter as you do not create any objects of such type, you just set a pointer to allow the compiler to the arithmetics and type checking for you.

Quoted 2 lines

case of read/write cmd, it has about 256MiB range. then how do you cast is as C structures.

Well, the OneNAND Controller offsets are all withion a single 1 kB range, right?

Quoted 2 lines

Only some small range for example. 1K or less. C structures possible. but more than this. it's too huge to case it.

Where exactly do you think is a data structure too big to be handled this way?

Quoted 10 lines
Quoted 9 lines

Please change this code to use structs, too.

drivers/mtd/onenand/samsung.c line 117

Quoted 4 lines
drivers/mtd/onenand/samsung.c new file +4 -0
+static unsigned int s5pc100_mem_addr(int fba, int fpa, int fsa)
+{
+     return (fba << 13) | (fpa << 7) | (fsa << 5);
+}

This function needs explanation. Please add a comment what it does, and how.

Quoted 2 lines

It's mandatory. no need to shift. It's fixed. with this reason. we covers alomst 256MiB memory range.

You don't understand me.

I asked you to add a comment that documents what this function does, whet the arguments mean, which value it returns, and what the magic constants used in the code mean.

Quoted 11 lines
Quoted 10 lines

drivers/mtd/onenand/samsung.c line 610

Quoted 8 lines
drivers/mtd/onenand/samsung.c new file +8 -0
+#ifdef CONFIG_S5PC1XX
+     /* S5PC100 specific values */
+     onenand->base = (void *) 0xE7100000;
+     onenand->ahb_addr = (void *) 0xB0000000;
+     onenand->mem_addr = s5pc100_mem_addr;
+#else
+#error Please fix it at s3c6410
+#endif

What does this mean?

Quoted 2 lines

Now we got two version of samsung.c one for s3c6410, another is this one. No problem to add it for s3c6410

Ah! Two versions of samsung.c? This is bad. Please avoid such code duplication. Create a common file that covers both systems.

Quoted 12 lines
Quoted 11 lines

include/samsung_onenand.h line 38

Quoted 9 lines
include/samsung_onenand.h new file +9 -0
+/*
+ * OneNAND Controller
+ */
+#define MEM_CFG_OFFSET               0x0000
+#define BURST_LEN_OFFSET     0x0010
+#define MEM_RESET_OFFSET     0x0020
+#define INT_ERR_STAT_OFFSET  0x0030
+#define INT_ERR_MASK_OFFSET  0x0040
+#define INT_ERR_ACK_OFFSET   0x0050

Please use a C struct instead.

Quoted 1 line

The end address is 0x400. Are you really need it to cast? I don't think so.

I don't understand what you complain about. What's wrong about to have a structure for that? That its sparse populated? No problem.

Keep in mind that we do not create any such objects, we just use the defintion to desctibe the structure of your hardware, so the compiler can to the address calculation and typoe checking for us.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Vor allem kein Gedanke! Nichts ist kompromittierender als ein  Gedan-
ke!            - Friedrich Wilhelm Nietzsche _Der Fall Wagner_ (1888)