From patchwork Fri Aug 24 16:17:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: gcembed X-Patchwork-Id: 1372081 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 1EA963FC81 for ; Fri, 24 Aug 2012 16:22:02 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T4wb2-0006iX-5b; Fri, 24 Aug 2012 16:18:56 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T4wau-0006hy-Uy; Fri, 24 Aug 2012 16:18:49 +0000 Received: by wibhn17 with SMTP id hn17so796235wib.0 for ; Fri, 24 Aug 2012 09:18:45 -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:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=rDK4i5rcVHlyZPgCQ/FL61TgywxvU0V4mgXD5Dfy/dY=; b=LcAVNssENOjUkTpt1/3v7frUV2GfjBxhPj138Zzn1K6FqdM0KNb6TycFYDm+6Gz8KM zgfaJy9AEmhKg5j02IBfreRZABxMxvtLTmMpoMtmcT8RsYFmwfBPgPKQU5I5TEdbZ0P9 loNp7cr/ITTIfjRZV5j/l960i2ACuCHCBowfCZz3/9rBc2HmPefBHDtSrIQ56ocz4npa IiFV6zrZ81ZMCiTRWsamdTltfRPvmn6Bea6Z/mxDhkFTVuvd39eoPwTCsGy7+UT4I2rI spNSOibNvbUuJ/W7lNxDBPorlUXWKtfv4AioHO5K2c+7oRJdmA+442wMDkQhBRzc5SYF qtXA== Received: by 10.180.109.166 with SMTP id ht6mr6695884wib.11.1345825125503; Fri, 24 Aug 2012 09:18:45 -0700 (PDT) Received: from t410.TRUMP (34.16-66-87.adsl-static.isp.belgacom.be. [87.66.16.34]) by mx.google.com with ESMTPS id l6sm392435wiz.4.2012.08.24.09.18.44 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Aug 2012 09:18:44 -0700 (PDT) From: =?UTF-8?q?Ga=C3=ABtan=20Carlier?= To: linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Artem Bityutskiy Subject: [PATCH 1/1] mxc_nand : allow swapping the Bad block Indicator for NFC v1. Date: Fri, 24 Aug 2012 18:17:44 +0200 Message-Id: <1345825064-9147-1-git-send-email-gcembed@gmail.com> X-Mailer: git-send-email 1.7.7.4 In-Reply-To: <1345811288.2848.308.camel@sauron.fi.intel.com> References: <1345811288.2848.308.camel@sauron.fi.intel.com> 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 [209.85.212.177 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: Russell King , J.Lambrecht@TELEVIC.com, David Woodhouse , 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. v3: - use accessor function for I/O memory accesses as suggested by Artem Bityutskiy - rename function name as suggested by Artem Bityutskiy v2: - Use a flag in a mxc_nand_platform structure instead of adding option in Kconfig v1: - Original patch "Add 'config IMX_NFC_V1_BISWAP'" by Jürgen Lambrecht 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..24fc9e1 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 nfcv1_bi_swap_quirk(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 = ioread16(host->main_area0 + 0x7D0); + temp2 = ioread16(host->main_area0 + 0x834); + new_temp1 = (temp1 & 0xFF00) | (temp2 >> 8); + temp2 = (temp2 & 0x00FF) | (temp1 << 8); + iowrite16(new_temp1, host->main_area0 + 0x7D0); + iowrite16(temp2, host->main_area0 + 0x834); +} + 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) + nfcv1_bi_swap_quirk(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) + nfcv1_bi_swap_quirk(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);