Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752972AbbH1T4O (ORCPT ); Fri, 28 Aug 2015 15:56:14 -0400 Received: from mail-bl2on0101.outbound.protection.outlook.com ([65.55.169.101]:3136 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752164AbbH1T4M (ORCPT ); Fri, 28 Aug 2015 15:56:12 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=freescale.com; From: Han Xu To: CC: , , , , , , , , , , Subject: [PATCH v3 5/6] mtd: nand: gpmi: correct bitflip for erased NAND page Date: Fri, 28 Aug 2015 14:32:44 -0500 Message-ID: <1440790365-28072-6-git-send-email-b45815@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440790365-28072-1-git-send-email-b45815@freescale.com> References: <1440790365-28072-1-git-send-email-b45815@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD048;1:QU8QrETSHqQ2duTqvqaynazqBqAbksWnwLXpdiV2wZ2lX1ZAwpvlaFFgXeee/ep3VkYGLjzw52gcBWRBp5sudFZ+kd51M+ZiP0xzVe8+ypSDMU67ntHuwl3EiFTZ4h/Gxl8l96NGoVpYJfZBJatTfybSdO2QEysHRU6iadVcFLZYbdwAGkS9ycqTKb+13LKCjGjXjOz9ViC3yRUJuNDNblvKovVjW0hCqYo3Fi8dCv1+5dYPQGDLrKY6M3xmRiGWInfVa+oHCp2n3vM/2L07HlDchBnwTTr3lx4tbRoWQFkm6WS1pAUBGbl2Ehd8GTSft8qFq4fN26y5o8mLpOLXtZkJFsrgZnKfvSEH2QY0rm/ExObgS7fagCSapxpCNrO3L24oSPkOa+q4grYA62TGCqot373O37f0q8InacjkB6M= X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2970300002)(339900001)(3050300001)(199003)(189002)(19580395003)(77156002)(19580405001)(575784001)(62966003)(5003940100001)(68736005)(87936001)(105606002)(85426001)(6806004)(106466001)(50226001)(50466002)(77096005)(5001860100001)(76176999)(50986999)(48376002)(189998001)(2950100001)(5007970100001)(46102003)(33646002)(4001540100001)(104016003)(92566002)(81156007)(97736004)(229853001)(5001920100001)(64706001)(2351001)(5001960100002)(110136002)(5001830100001)(36756003)(47776003);DIR:OUT;SFP:1102;SCL:1;SRVR:BLUPR03MB549;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:3;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB549;2:2Qz8IsyuFUHn9h1Z9bv/iwkRinz0kDnLJLxGq6RX1/GasN+VasG7Uh4IykzhKUehfsKkr1NNFx52ehzZ/k9tK9KYqDKBK0q0pCfzV5o/e2kWpb1jb1Qop2wO0GND8xi/qFCS53nkq+E3cdLP03TV+OLfc/gRoPkMER3sO9VdFRw=;3:VS/29USFS9LeoBhWGHhqUPe59OoWhTzClt68MPCCAvE1Jcm1VkjZ+oA0oaFlIdWYEMbpiBOx+/VDCjsLEHJXmRAwYQ9cONcURmWa6B8Vkm22osUXIng8eL0Ymk+TPRpoVTN0+iB0Pmrg+AtHGcKQtPAW4c1o1rH6NpXbiInkF0THmGypuvta3WnKuBVIfRSstfW0UBWt26PrsZ3R7IJ7JTK1i2PoW1ZHqOf+Yb5opm8=;25:rxbBMs4Knb1ewy7FIo+7PmLvm9wsM2teiJd9wAgdVfAgC4Pwyi2lOG2i1M8NoFABs2cRpgvR4LK1XJFsTLJjegFxARUFQTLWS8CCBDOQ5UFL1YLJkrt+6nH3S5lNgh58nLOaTD6XvtJfOZFCsOFmx/Gz/hW2lFMh6f70YU6Kp7SqgijLMORjFqhW5kANbBj6xU5ZdabULK40gOWbrl7YaKof21pENdPDFVJZsLVwTuhx2EQM1hqLDvdZosOIQjNE X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB549; X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB549;20:bD7e+Er+SCMyZF3g6cokYyd7rFZsAJr4eob8J5u2wBDzC6Gpz/VcyIz2L7f+zUE5rE4HLJAqOB1OTADXhxq9HCQEbNS13Pcabkq1DorRhQ+WvLrHapEVXEYDyIGy5ROp308bRv/JO679oBAdkDo1rE5/jUoy6vCLYNR85JpGqYpAP1KwEPcf0F1a0W+HyZAR8TsPqAI3np6rgsgqBqASggaNHtaAlEBoN/iTo4tCruO+0htLUWQDDgDKDNCWXVymIPt84kUZyU+Di5euBiRGtvMjOlWKv+mQLUBEdZBsX6woWybA4GhXK8+5wyd10+Ra5nWe1S3/jX2xf7Qh8DjeHJtYpkskNmJPNmJ0/7vcmes=;4:n0PV4z9pDWEaQCuk6lbFEOdf/xX5GJlfLzwlLaXmPx1C2Lp9HgTrg2SLyFlBof4r+fZJtV6EKGWgixXYoUlTjPiPqY37lj3aS5grmYTxKd+mR16ltkG4LnuyfeNeyo0R8iVLvkLIfpCUmQ30rmEq29/smhBGJI6HMocQ+qCcxIJCTkcF3hR1iIh9FwAYFa7puqk72MZpQRtWWrVbQ23gFtMFxx+k3IkC0uDTwuNZaaW+ISOq99RfREXzz7N10nzIRJdOn73aJA4Fc9k6GRjsH7wiZa5C0X3JYZYW5aGHVIDjdUrjIV4w8SKky8feZD3N X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(8121501046)(3002001);SRVR:BLUPR03MB549;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB549; X-Forefront-PRVS: 0682FC00E8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BLUPR03MB549;23:WHpbCsjvgYV5IEiDWX3E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ii?Q?DRyjPRDd0mvXIwVGVLUHwpPLDDoJFSnE8nFRSR6T6Ql1DPu690i1AdqVxeBB?= =?us-ascii?Q?XjCo33mcXwVdh8M6ZLoQ86eiaMXqhudISQaTyqrk/kWMpA8lCN4L/woxUoJ5?= =?us-ascii?Q?V9r2Y2ADyRuUYX5bx/j9A1xQ6D7wO7n+K16bcJAtZzmF265U33phkgx2amck?= =?us-ascii?Q?RIhy9qhwi5986Z8zv5tKgRCeLgTZi0nfv+eGC0H3H/uJOpbh63f6y+QdjQL2?= =?us-ascii?Q?O1UIAiUP8DI9Q0gTNrFIuuvgESmGqFClSxOKyvtKME5RSokhg7WZy9T5RCLj?= =?us-ascii?Q?GNfbJjrzIzfa5nHeuyEYtvIkaqN3fNlvWf?= X-Microsoft-Exchange-Diagnostics: 1;BLUPR03MB549;5:kTFZuriPenUHjnBlZWboNEzIvwIYdhHN1JkT1zufuKBeZIYg4WW92iWb3geSPhELqEuG697sfVZlOuDMPBXWM+uGh3tFvGYqeiaB7f4ezKhHEvbqVNGadFI3gsoIuWK1d0rPWf/+8AwGjBBq8J3bVw==;24:Gi5GkLOw0hEc1k/NbFcaylNc4WzsdWutQlHlUnSOyCgimy5861DrinQ8NNtKzYoDynRxJHAAFWSc8FdWM76BvQmUH2K/1syvpI3iaGZpcQQ=;20:d0dn7hHHhvyjjk/InzVNLiMx+yL+3dlnZfRwrBi6am52Gfo/6GB2bzUOa4zuXn4ri0JOv1rKYSc8B2WEzNaHIQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2015 19:41:43.2387 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB549 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5839 Lines: 161 i.MX6QP and i.MX7D BCH module integrated a new feature to detect the bitflip number for erased NAND page. So for these two platform, set the erase threshold to ecc_strength and if bitflip detected, GPMI driver will correct the data to all 0xFF. Signed-off-by: Han Xu --- drivers/mtd/nand/gpmi-nand/bch-regs.h | 10 ++++++++++ drivers/mtd/nand/gpmi-nand/gpmi-lib.c | 5 +++++ drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 24 +++++++++++++++++++++++- drivers/mtd/nand/gpmi-nand/gpmi-nand.h | 5 ++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/gpmi-nand/bch-regs.h b/drivers/mtd/nand/gpmi-nand/bch-regs.h index 53e58bc..a84d72b 100644 --- a/drivers/mtd/nand/gpmi-nand/bch-regs.h +++ b/drivers/mtd/nand/gpmi-nand/bch-regs.h @@ -30,7 +30,13 @@ #define BM_BCH_CTRL_COMPLETE_IRQ (1 << 0) #define HW_BCH_STATUS0 0x00000010 + #define HW_BCH_MODE 0x00000020 +#define BP_BCH_MODE_ERASE_THRESHOLD 0 +#define BM_BCH_MODE_ERASE_THRESHOLD (0xff << BP_BCH_MODE_ERASE_THRESHOLD) +#define BF_BCH_MODE_ERASE_THRESHOLD(v) \ + (((v) << BP_BCH_MODE_ERASE_THRESHOLD) & BM_BCH_MODE_ERASE_THRESHOLD) + #define HW_BCH_ENCODEPTR 0x00000030 #define HW_BCH_DATAPTR 0x00000040 #define HW_BCH_METAPTR 0x00000050 @@ -125,4 +131,8 @@ ) #define HW_BCH_VERSION 0x00000160 +#define HW_BCH_DEBUG1 0x00000170 +#define BP_BCH_DEBUG1_ERASED_ZERO_COUNT 0 +#define BM_BCH_DEBUG1_ERASED_ZERO_COUNT \ + (0x1ff << BP_BCH_DEBUG1_ERASED_ZERO_COUNT) #endif diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c index 6b37414..f00ce90 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-lib.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-lib.c @@ -298,6 +298,11 @@ int bch_set_geometry(struct gpmi_nand_data *this) | BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this), r->bch_regs + HW_BCH_FLASH0LAYOUT1); + /* Set erase threshold to ecc_strength for mx6qp and mx7 */ + if (GPMI_IS_MX6QP(this) || GPMI_IS_MX7(this)) + writel(BF_BCH_MODE_ERASE_THRESHOLD(ecc_strength), + r->bch_regs + HW_BCH_MODE); + /* Set *all* chip selects to use layout 0. */ writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT); diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c index 4e52885..4312de2 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -71,6 +71,12 @@ static const struct gpmi_devdata gpmi_devdata_imx6q = { .max_chain_delay = 12, }; +static const struct gpmi_devdata gpmi_devdata_imx6qp = { + .type = IS_MX6QP, + .bch_max_ecc_strength = 40, + .max_chain_delay = 12, +}; + static const struct gpmi_devdata gpmi_devdata_imx6sx = { .type = IS_MX6SX, .bch_max_ecc_strength = 62, @@ -1010,6 +1016,7 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip, { struct gpmi_nand_data *this = chip->priv; struct bch_geometry *nfc_geo = &this->bch_geometry; + void __iomem *bch_regs = this->resources.bch_regs; void *payload_virt; dma_addr_t payload_phys; void *auxiliary_virt; @@ -1018,6 +1025,7 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip, unsigned char *status; unsigned int max_bitflips = 0; int ret; + int flag = 0; dev_dbg(this->dev, "page number is : %d\n", page); ret = read_page_prepare(this, buf, nfc_geo->payload_size, @@ -1050,9 +1058,16 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip, status = auxiliary_virt + nfc_geo->auxiliary_status_offset; for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) { - if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED)) + if (*status == STATUS_GOOD) continue; + if (*status == STATUS_ERASED) { + if (GPMI_IS_MX6QP(this) || GPMI_IS_MX7(this)) + if (readl(bch_regs + HW_BCH_DEBUG1)) + flag = 1; + continue; + } + if (*status == STATUS_UNCORRECTABLE) { mtd->ecc_stats.failed++; continue; @@ -1081,6 +1096,10 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip, nfc_geo->payload_size, payload_virt, payload_phys); + /* if bitflip occurred in erased page, change data to all 0xff */ + if (flag) + memset(buf, 0xff, nfc_geo->payload_size); + return max_bitflips; } @@ -1991,6 +2010,9 @@ static const struct of_device_id gpmi_nand_id_table[] = { .compatible = "fsl,imx6q-gpmi-nand", .data = &gpmi_devdata_imx6q, }, { + .compatible = "fsl,imx6qp-gpmi-nand", + .data = (void *)&gpmi_devdata_imx6qp, + }, { .compatible = "fsl,imx6sx-gpmi-nand", .data = &gpmi_devdata_imx6sx, }, { diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h index 58b3d69..149a442 100644 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.h +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.h @@ -123,6 +123,7 @@ enum gpmi_type { IS_MX23, IS_MX28, IS_MX6Q, + IS_MX6QP, IS_MX6SX, IS_MX7D, }; @@ -306,9 +307,11 @@ void gpmi_copy_bits(u8 *dst, size_t dst_bit_off, #define GPMI_IS_MX23(x) ((x)->devdata->type == IS_MX23) #define GPMI_IS_MX28(x) ((x)->devdata->type == IS_MX28) #define GPMI_IS_MX6Q(x) ((x)->devdata->type == IS_MX6Q) +#define GPMI_IS_MX6QP(x) ((x)->devdata->type == IS_MX6QP) #define GPMI_IS_MX6SX(x) ((x)->devdata->type == IS_MX6SX) #define GPMI_IS_MX7D(x) ((x)->devdata->type == IS_MX7D) -#define GPMI_IS_MX6(x) (GPMI_IS_MX6Q(x) || GPMI_IS_MX6SX(x)) +#define GPMI_IS_MX6(x) (GPMI_IS_MX6Q(x) || GPMI_IS_MX6QP(x)\ + || GPMI_IS_MX6SX(x)) #define GPMI_IS_MX7(x) (GPMI_IS_MX7D(x)) #endif -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/