From patchwork Wed Aug 15 13:04:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: gcembed X-Patchwork-Id: 1325501 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id BA257DFFED for ; Wed, 15 Aug 2012 13:09:22 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T1dJ3-0007kE-FV; Wed, 15 Aug 2012 13:06:41 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T1dIt-0007gJ-St; Wed, 15 Aug 2012 13:06:32 +0000 Received: by wgbez12 with SMTP id ez12so966270wgb.18 for ; Wed, 15 Aug 2012 06:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; bh=xNMF4E2RbRRcEAo4UVIOVPz1SEJFgLIqG6ug1P87rMQ=; b=wTZG/nfFaF9slG792NkYMBiXry0qS8ytwZHyMW7lPIAH1iwETYyyQkS2F6rZkgN4AP P80/R9olxWF7grmuDS3KNB61/vu4MTrDlRpLWIrze/fH47Ih91X4ig/zhZ2/eJWkLdri qtrFITzYDlkRnzU3JO8vATmSXXJTqgYPMxQPR6VOhZHeWftJxigLs8qorGI5/021rmMd fz8VM7UZhKmzQcPZrenj4yzxchyHxmKUAXfSABcygudrprdIO5TxXlRoOkpo1nG29EOp 8gM5MAJFTf3rbhiSOwAAayptY9ohLyTdvO5zKTsjdcbZHRVKalQZc8b6ChXlZMmnolBH 4wYw== Received: by 10.216.119.6 with SMTP id m6mr3671003weh.215.1345035985546; Wed, 15 Aug 2012 06:06:25 -0700 (PDT) Received: from t410.gcnet.mrs (ip-83-134-58-239.dsl.scarlet.be. [83.134.58.239]) by mx.google.com with ESMTPS id cu1sm28534854wib.6.2012.08.15.06.06.21 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Aug 2012 06:06:25 -0700 (PDT) From: =?UTF-8?q?Ga=C3=ABtan=20Carlier?= To: linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] mxc_nand : allow swapping the Bad block Indicator for NFC v1. Date: Wed, 15 Aug 2012 15:04:32 +0200 Message-Id: <1345035872-11314-1-git-send-email-gcembed@gmail.com> X-Mailer: git-send-email 1.7.7.4 MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.49 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (gcembed[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: David Woodhouse , J.Lambrecht@TELEVIC.com, Russell King , Sascha Hauer , =?UTF-8?q?Ga=C3=ABtan=20Carlier?= X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Swap the BI-byte on position 0x7D0 with a data byte at 0x835. To fix a bug in Freescale imx NFC v1 SoC's for 2K page NAND flashes: imx27 and imx31. Warning: The same solution needs to be applied to the boot loader and the flash programmer. This is a modified version of patch sent by Jürgen Lambrecht : [PATCH] Add 'config IMX_NFC_V1_BISWAP' to swap the Bad block Indicator, and use for imx27pdk nand support. Signed-off-by: Gaëtan Carlier --- arch/arm/plat-mxc/include/mach/mxc_nand.h | 2 ++ drivers/mtd/nand/mxc_nand.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/arch/arm/plat-mxc/include/mach/mxc_nand.h b/arch/arm/plat-mxc/include/mach/mxc_nand.h index 6bb96ef..7c04437 100644 --- a/arch/arm/plat-mxc/include/mach/mxc_nand.h +++ b/arch/arm/plat-mxc/include/mach/mxc_nand.h @@ -26,6 +26,8 @@ struct mxc_nand_platform_data { unsigned int width; /* data bus width in bytes */ unsigned int hw_ecc:1; /* 0 if suppress hardware ECC */ unsigned int flash_bbt:1; /* set to 1 to use a flash based bbt */ + unsigned int biswap:1; /* set to 1 to swap the Bad Block Indicator + NFC v1 workaround */ struct mtd_partition *parts; /* partition table */ int nr_parts; /* size of parts */ }; diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 3f94e1f..7f5847a 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -682,6 +682,26 @@ static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, return 0; } +/* + * Swap the BI-byte on position 0x7D0 with a data byte at 0x835. + * To fix a bug in NFC v1 SoC's for 2K page NAND flashes: imx27 and imx31. + * Warning: The same solution needs to be applied to the boot loader and the + * flash programmer. + */ +static void imx_bi_swap(struct mtd_info *mtd) +{ + struct nand_chip *nand_chip = mtd->priv; + struct mxc_nand_host *host = nand_chip->priv; + unsigned short temp1, temp2, new_temp1; + + temp1 = *((volatile unsigned short*)(host->main_area0 + 0x7D0)); + temp2 = *((volatile unsigned short*)(host->main_area0 + 0x834)); + new_temp1 = (temp1 & 0xFF00) | (temp2 >> 8); + temp2 = (temp2 & 0x00FF) | (temp1 << 8); + *((volatile unsigned short*)(host->main_area0 + 0x7D0)) = new_temp1; + *((volatile unsigned short*)(host->main_area0 + 0x834)) = temp2; +} + static u_char mxc_nand_read_byte(struct mtd_info *mtd) { struct nand_chip *nand_chip = mtd->priv; @@ -1093,6 +1113,9 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command, host->devtype_data->send_page(mtd, NFC_OUTPUT); + if ((mtd->writesize > 512) && nfc_is_v1() && host->pdata.biswap) + imx_bi_swap(mtd); + memcpy32_fromio(host->data_buf, host->main_area0, mtd->writesize); copy_spare(mtd, true); @@ -1112,6 +1135,9 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command, case NAND_CMD_PAGEPROG: memcpy32_toio(host->main_area0, host->data_buf, mtd->writesize); copy_spare(mtd, false); + if ((mtd->writesize > 512) && nfc_is_v1() && host->pdata.biswap) + imx_bi_swap(mtd); + host->devtype_data->send_page(mtd, NFC_INPUT); host->devtype_data->send_cmd(host, command, true); mxc_do_addr_cycle(mtd, column, page_addr);