From 1bc1314180bad7c821dfb464b35f0fbaa4445afb Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Tue, 6 Mar 2012 01:26:28 +0100
Subject: [PATCH 3/7] nand wrs: our nand is 16-bit connected: fix accordingly

---
 arch/arm/boards/pm9g45/init.c |    6 +++---
 drivers/mtd/nand/atmel_nand.c |   26 ++++++++++++++++++++++----
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/arch/arm/boards/pm9g45/init.c b/arch/arm/boards/pm9g45/init.c
index 9b22276..9ecd628 100644
--- a/arch/arm/boards/pm9g45/init.c
+++ b/arch/arm/boards/pm9g45/init.c
@@ -44,9 +44,9 @@ static struct atmel_nand_data nand_pdata = {
 	.ale		= 21,
 	.cle		= 22,
 /*	.det_pin	= ... not connected */
-	.rdy_pin	= AT91_PIN_PD3,
+	.rdy_pin	= AT91_PIN_PC8,
 	.enable_pin	= AT91_PIN_PC14,
-	.bus_width_16	= 0,
+	.bus_width_16	= 1,
 };
 
 static struct sam9_smc_config pm_nand_smc_config = {
@@ -69,7 +69,7 @@ static struct sam9_smc_config pm_nand_smc_config = {
 
 static void pm_add_device_nand(void)
 {
-	pm_nand_smc_config.mode |= AT91_SMC_DBW_8;
+	pm_nand_smc_config.mode |= AT91_SMC_DBW_16;
 
 	/* configure chip-select 3 (NAND) */
 	sam9_smc_configure(3, &pm_nand_smc_config);
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 96624a1..bad75a9 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -141,6 +141,13 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 	memcpy_fromio(buf, chip->IO_ADDR_R, len);
 }
 
+static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
+{
+	struct nand_chip	*nand_chip = mtd->priv;
+
+	readsw(nand_chip->IO_ADDR_R, buf, len / 2);
+}
+
 static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 {
 	struct nand_chip *chip = mtd->priv;
@@ -148,6 +155,14 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 	memcpy_toio(chip->IO_ADDR_W, buf, len);
 }
 
+static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len)
+{
+	struct nand_chip	*nand_chip = mtd->priv;
+
+	writesw(nand_chip->IO_ADDR_W, buf, len / 2);
+}
+
+
 /*
  * Calculate HW ECC
  *
@@ -391,11 +406,14 @@ static int __init atmel_nand_probe(struct device_d *dev)
 
 	nand_chip->chip_delay = 20;		/* 20us command delay time */
 
-	if (host->board->bus_width_16)		/* 16-bit bus width */
+	if (host->board->bus_width_16) {	/* 16-bit bus width */
 		nand_chip->options |= NAND_BUSWIDTH_16;
-
-	nand_chip->read_buf = atmel_read_buf;
-	nand_chip->write_buf = atmel_write_buf;
+		nand_chip->read_buf = atmel_read_buf16;
+		nand_chip->write_buf = atmel_write_buf16;
+	} else {
+		nand_chip->read_buf = atmel_read_buf;
+		nand_chip->write_buf = atmel_write_buf;
+	}
 
 	atmel_nand_enable(host);
 
-- 
1.7.7.2

