public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kyungmin Park <kmpark@infradead.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] [OneNAND IPL] OneNAND board init support
Date: Sat, 29 Aug 2009 13:00:59 +0900	[thread overview]
Message-ID: <20090829040059.GA3277@july> (raw)

Some CPU has internal OneNAND controller and use it for access OneNAND

To support these CPU, we provide the onenand_board_init
Also we can override the onenand_read_page.

Some minor fixed:
- Remove unnecessary header file
- Fix wrong access at read interrupt
- The recent OneNAND has 4KiB pagesize

Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
diff --git a/onenand_ipl/onenand_boot.c b/onenand_ipl/onenand_boot.c
index 63995ce..22baebb 100644
--- a/onenand_ipl/onenand_boot.c
+++ b/onenand_ipl/onenand_boot.c
@@ -24,7 +24,6 @@
  */
 
 #include <common.h>
-#include <version.h>
 
 #include "onenand_ipl.h"
 
diff --git a/onenand_ipl/onenand_ipl.h b/onenand_ipl/onenand_ipl.h
index 412572a..2257063 100644
--- a/onenand_ipl/onenand_ipl.h
+++ b/onenand_ipl/onenand_ipl.h
@@ -29,7 +29,14 @@
 #define THIS_ONENAND(a)         (CONFIG_SYS_ONENAND_BASE + (a))
 
 #define READ_INTERRUPT()                                                \
-	onenand_readw(THIS_ONENAND(ONENAND_REG_INTERRUPT))
+				onenand_readw(ONENAND_REG_INTERRUPT)
 
+enum {
+	ONENAND_USE_DEFAULT,
+	ONENAND_USE_GENERIC,
+};
+
+extern int (*onenand_read_page)(ulong block, ulong page,
+				u_char *buf, int pagesize);
 extern int onenand_read_block(unsigned char *buf);
 #endif
diff --git a/onenand_ipl/onenand_read.c b/onenand_ipl/onenand_read.c
index d1a842d..7fc0c62 100644
--- a/onenand_ipl/onenand_read.c
+++ b/onenand_ipl/onenand_read.c
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2005-2008 Samsung Electronis
+ * (C) Copyright 2005-2009 Samsung Electronics
  * Kyungmin Park <kyungmin.park@samsung.com>
  *
  * See file CREDITS for list of people who contributed to this
@@ -37,8 +37,11 @@
 extern void *memcpy32(void *dest, void *src, int size);
 #endif
 
+int (*onenand_read_page)(ulong block, ulong page,
+				u_char *buf, int pagesize);
+
 /* read a page with ECC */
-static inline int onenand_read_page(ulong block, ulong page,
+static int generic_onenand_read_page(ulong block, ulong page,
 				u_char * buf, int pagesize)
 {
 	unsigned long *base;
@@ -89,9 +92,29 @@ static inline int onenand_read_page(ulong block, ulong page,
 	return 0;
 }
 
-#define ONENAND_START_PAGE		1
+#ifndef CONFIG_ONENAND_START_PAGE
+#define CONFIG_ONENAND_START_PAGE	1
+#endif
 #define ONENAND_PAGES_PER_BLOCK		64
 
+#ifndef CONFIG_ONENAND_BOARD_INIT
+static int onenand_generic_init(int *page_is_4KiB, int *page)
+{
+	int dev_id, density;
+
+	if (onenand_readw(ONENAND_REG_TECHNOLOGY))
+		*page_is_4KiB = 1;
+	dev_id = onenand_readw(ONENAND_REG_DEVICE_ID);
+	density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
+	density &= ONENAND_DEVICE_DENSITY_MASK;
+	if (density >= ONENAND_DEVICE_DENSITY_4Gb &&
+	    !(dev_id & ONENAND_DEVICE_IS_DDP))
+		*page_is_4KiB = 1;
+
+	return ONENAND_USE_DEFAULT;
+}
+#endif
+
 /**
  * onenand_read_block - Read CONFIG_SYS_MONITOR_LEN from begining
  *                      of OneNAND, skipping bad blocks
@@ -99,24 +122,31 @@ static inline int onenand_read_page(ulong block, ulong page,
  */
 int onenand_read_block(unsigned char *buf)
 {
-	int block;
-	int page = ONENAND_START_PAGE, offset = 0;
-	int pagesize = 0, erase_shift = 0;
-	int erasesize = 0, nblocks = 0;
+	int block, nblocks;
+	int page = CONFIG_ONENAND_START_PAGE, offset = 0;
+	int pagesize, erasesize, erase_shift;
+	int page_is_4KiB = 0, ret;
+
+	pagesize = 2048; /* OneNAND has 2KiB pagesize */
+	erase_shift = 17;
+	onenand_read_page = generic_onenand_read_page;
+
+#ifdef CONFIG_ONENAND_BOARD_INIT
+	onenand_board_init(&page_is_4KiB, &page);
+#else
+	onenand_generic_init(&page_is_4KiB, &page);
+#endif
 
-	if (onenand_readw(ONENAND_REG_TECHNOLOGY)) {
-		pagesize = 4096; /* MLC OneNAND has 4KiB pagesize */
+	if (page_is_4KiB) {
+		pagesize = 4096; /* OneNAND has 4KiB pagesize */
 		erase_shift = 18;
-	} else {
-		pagesize = 2048;
-		erase_shift = 17;
 	}
 
-	erasesize = ONENAND_PAGES_PER_BLOCK * pagesize;
+	erasesize = (1 << erase_shift);
 	nblocks = (CONFIG_SYS_MONITOR_LEN + erasesize - 1) >> erase_shift;
 
 	/* NOTE: you must read page from page 1 of block 0 */
-	/* read the block page by page*/
+	/* read the block page by page */
 	for (block = 0; block < nblocks; block++) {
 		for (; page < ONENAND_PAGES_PER_BLOCK; page++) {
 			if (onenand_read_page(block, page, buf + offset,

             reply	other threads:[~2009-08-29  4:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-29  4:00 Kyungmin Park [this message]
2009-09-18 19:26 ` [U-Boot] [PATCH] [OneNAND IPL] OneNAND board init support Scott Wood
2009-09-19  1:32   ` Kyungmin Park
2009-09-21 16:15     ` Scott Wood
2009-09-21 23:52       ` Kyungmin Park
  -- strict thread matches above, loose matches on Subject: below --
2009-10-07  1:24 Kyungmin Park
2009-10-07  3:12 ` Kyungmin Park
2009-10-19 19:51   ` Scott Wood

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=20090829040059.GA3277@july \
    --to=kmpark@infradead.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox