public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: unsik Kim <donari75@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [U-BOOT][PATCH 4/4] mflash : Support word unaligned access
Date: Wed, 18 Feb 2009 19:51:54 +0900	[thread overview]
Message-ID: <499BE84A.4020409@gmail.com> (raw)

Signed-off-by: unsik Kim <donari75@gmail.com>
---
  drivers/block/mg_disk.c     |   38 ++++++++++++++++++++++++++------------
  drivers/block/mg_disk_prv.h |    5 +++++
  2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index 113aa79..b74307a 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -240,6 +240,7 @@ static unsigned int mg_do_read_sects(void *buff, u32 sect_num, u32 sect_cnt)
  {
  	u32 i, j, err;
  	u8 *buff_ptr = buff;
+	union mg_uniwb uniwb;

  	err = mg_out(sect_num, sect_cnt, MG_CMD_RD);
  	if (err)
@@ -250,13 +251,20 @@ static unsigned int mg_do_read_sects(void *buff, u32 sect_num, u32 sect_cnt)
  		if (err)
  			return err;

-		/* TODO : u16 unaligned case */
-		for(j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
-			*(u16 *)buff_ptr =
-				readw(mg_base() + MG_BUFF_OFFSET + (j << 1));
-			buff_ptr += 2;
+		if ((u32)buff_ptr & 1) {
+			for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
+				uniwb.w = readw(mg_base() + MG_BUFF_OFFSET
+						+ (j << 1));
+				*buff_ptr++ = uniwb.b[0];
+				*buff_ptr++ = uniwb.b[1];
+			}
+		} else {
+			for(j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
+				*(u16 *)buff_ptr = readw(mg_base() +
+						MG_BUFF_OFFSET + (j << 1));
+				buff_ptr += 2;
+			}
  		}
-
  		writeb(MG_CMD_RD_CONF, mg_base() + MG_REG_COMMAND);

  		MG_DBG("%u (0x%8.8x) sector read", sect_num + i,
@@ -372,6 +380,7 @@ static int mg_do_write_sects(void *buff, u32 sect_num, u32 sect_cnt)
  {
  	u32 i, j, err;
  	u8 *buff_ptr = buff;
+	union mg_uniwb uniwb;

  	err = mg_out(sect_num, sect_cnt, MG_CMD_WR);
  	if (err)
@@ -382,13 +391,18 @@ static int mg_do_write_sects(void *buff, u32 sect_num, u32 sect_cnt)
  		if (err)
  			return err;

-		/* TODO : u16 unaligned case */
-		for(j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
-			writew(*(u16 *)buff_ptr,
-				mg_base() + MG_BUFF_OFFSET + (j << 1));
-			buff_ptr += 2;
+		if ((u32)buff_ptr & 1) {
+			uniwb.b[0] = *buff_ptr++;
+			uniwb.b[1] = *buff_ptr++;
+			writew(uniwb.w, mg_base() + MG_BUFF_OFFSET + (j << 1));
+		} else {
+			for(j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
+				writew(*(u16 *)buff_ptr,
+						mg_base() + MG_BUFF_OFFSET +
+						(j << 1));
+				buff_ptr += 2;
+			}
  		}
-
  		writeb(MG_CMD_WR_CONF, mg_base() + MG_REG_COMMAND);

  		MG_DBG("%u (0x%8.8x) sector write",
diff --git a/drivers/block/mg_disk_prv.h b/drivers/block/mg_disk_prv.h
index a6b7299..8f22e28 100644
--- a/drivers/block/mg_disk_prv.h
+++ b/drivers/block/mg_disk_prv.h
@@ -120,6 +120,11 @@
  #define MG_CMD_WR_CONF	0x3C
  #define MG_CMD_RD_CONF	0x40

+union mg_uniwb{
+	u16 w;
+	u8 b[2];
+};
+
  /* main structure for mflash driver */
  struct mg_host {
  	struct mg_drv_data *drv_data;
-- 
1.5.6.6

                 reply	other threads:[~2009-02-18 10:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=499BE84A.4020409@gmail.com \
    --to=donari75@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox