From patchwork Fri Jan 15 10:35:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Izard X-Patchwork-Id: 568025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AF59B140BFD for ; Fri, 15 Jan 2016 21:38:23 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=n72pfnb5; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aK1kA-0004cS-10; Fri, 15 Jan 2016 10:36:34 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aK1jW-0004AZ-Ll for linux-mtd@lists.infradead.org; Fri, 15 Jan 2016 10:35:59 +0000 Received: by mail-wm0-x241.google.com with SMTP id l65so2124906wmf.3 for ; Fri, 15 Jan 2016 02:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GW/KeX6TcovVoAT4J/BnYbJ/iIjg/12g6mfgkcNPONA=; b=n72pfnb5VUhSACa+PNf5qq83Vbs/TAeulb2HxQ+LW6jhBky7Cg3WSPSFdToKsR5xqY 1CyXZaXMPRLiUj//hHRLkxkQmWpo5LVTtmJITeTAxYcgnEj22ofubegToTeuJE9P06oC nUocCsvyWRkPi/g4EUweSdl9i7VvhM6ta+BPyy2+Mql71OrOC1XnOPn8od4W9zHJBfFG Xv6alzKRlEaXj2dXbKqPmDxaPTFU+W/k0ua2mgN3X9Vkbo1NFdRaBm9lyE4nfXzv9+ok jefK3vMOzISsPFS/Sf5ehScROTxqk6W9LQ4qid03k+cFrFYX/5cRI/Ao1Hex84rlB6dU ENfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GW/KeX6TcovVoAT4J/BnYbJ/iIjg/12g6mfgkcNPONA=; b=ggS0AskmuBJ0kxXFkSU/VCP78pr+EYwOtq5Mat4fDGLGRFyqHQP0TE+g1PaRXHpNof WqMG4BIcvUCRlrwIwYE0VBW7Q55CJS14kGzAq6bCp7oop5X671cJODyKXBHA0ZTq0KMF 1SPYCdO7Z2XhahtvDYoiRTD3dftetwouMiqgaJ7khwjc7G9XyUJJg7o46HM6thmZXDyy 3HxeU0PR0CTWhx5se1IH7EOYf6f85itfZOUw18GZZnjdLNoY5Jv3tyyBtl6Gpo65iysA f/+XirTKPF76mOl8xtTWyyvXmoQ2MP9fFjNxJbXZY899SEE8Gv0WtAhv8R8bnhRyGeY/ FJSA== X-Gm-Message-State: ALoCoQlBOzt/3ZPdfQ8A7u+PmsrfMyqZBhbRD5pir15U734A99dN0nPEIO/DACpTpfPs8xYS2spcOkQ3cRXYffHWO2AfjA93+A== X-Received: by 10.194.79.8 with SMTP id f8mr9187444wjx.6.1452854135096; Fri, 15 Jan 2016 02:35:35 -0800 (PST) Received: from localhost.localdomain (ram94-11-88-187-113-157.fbx.proxad.net. [88.187.113.157]) by smtp.gmail.com with ESMTPSA id w1sm1945189wmd.2.2016.01.15.02.35.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jan 2016 02:35:34 -0800 (PST) From: Romain Izard To: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org Subject: [PATCH v2 6/8] mtd: atmel_nand: Support PMECC on SAMA5D2 Date: Fri, 15 Jan 2016 11:35:00 +0100 Message-Id: <1452854102-6125-7-git-send-email-romain.izard.pro@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452854102-6125-1-git-send-email-romain.izard.pro@gmail.com> References: <1452854102-6125-1-git-send-email-romain.izard.pro@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160115_023555_287637_173AC112 X-CRM114-Status: GOOD ( 19.53 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.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 [2a00:1450:400c:c09:0:0:0:241 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (romain.izard.pro[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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Josh Wu , Romain Izard , Nicolas Ferre , Yang Wenyou MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Starting with the SAMA5D2, there is a new revision of the Atmel PMECC controller that can correct 32 bits in each sector. This controller is not 100% compatible with the previous revision that corrected a maximum of 24 bits by sector, as some register addresses overlap. Using information from the device tree, we can configure the driver to work with both versions. Signed-off-by: Romain Izard Acked-by: Rob Herring --- v2: Split rewording of the binding into its own patch .../devicetree/bindings/mtd/atmel-nand.txt | 5 ++++- drivers/mtd/nand/atmel_nand.c | 23 +++++++++++++++++++++- drivers/mtd/nand/atmel_nand_ecc.h | 8 ++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/atmel-nand.txt b/Documentation/devicetree/bindings/mtd/atmel-nand.txt index e68ab404d912..e1887b7d7e53 100644 --- a/Documentation/devicetree/bindings/mtd/atmel-nand.txt +++ b/Documentation/devicetree/bindings/mtd/atmel-nand.txt @@ -1,7 +1,10 @@ Atmel NAND flash Required properties: -- compatible : should be "atmel,at91rm9200-nand" or "atmel,sama5d4-nand". +- compatible: The possible values are: + "atmel,at91rm9200-nand" + "atmel,sama5d2-nand" + "atmel,sama5d4-nand" - reg : should specify localbus address and size used for the chip, and hardware ECC controller if available. If the hardware ECC is PMECC, it should contain address and size for diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c index 0599f3c5ad3b..f73037a3b51d 100644 --- a/drivers/mtd/nand/atmel_nand.c +++ b/drivers/mtd/nand/atmel_nand.c @@ -65,6 +65,7 @@ module_param(on_flash_bbt, int, 0); struct atmel_nand_caps { bool pmecc_correct_erase_page; + uint8_t pmecc_max_correction; }; struct atmel_nand_nfc_caps { @@ -146,6 +147,7 @@ struct atmel_nand_host { int pmecc_cw_len; /* Length of codeword */ void __iomem *pmerrloc_base; + void __iomem *pmerrloc_el_base; void __iomem *pmecc_rom_base; /* lookup table for alpha_to and index_of */ @@ -817,7 +819,7 @@ static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc, sector_size = host->pmecc_sector_size; while (err_nbr) { - tmp = pmerrloc_readl_el_relaxed(host->pmerrloc_base, i) - 1; + tmp = pmerrloc_readl_el_relaxed(host->pmerrloc_el_base, i) - 1; byte_pos = tmp / 8; bit_pos = tmp % 8; @@ -1209,6 +1211,8 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev, err_no = PTR_ERR(host->pmerrloc_base); goto err; } + host->pmerrloc_el_base = host->pmerrloc_base + ATMEL_PMERRLOC_SIGMAx + + (host->caps->pmecc_max_correction + 1) * 4; if (!host->has_no_lookup_table) { regs_rom = platform_get_resource(pdev, IORESOURCE_MEM, 3); @@ -2307,17 +2311,34 @@ static int atmel_nand_remove(struct platform_device *pdev) return 0; } +/* + * AT91RM9200 does not have PMECC or PMECC Errloc peripherals for + * BCH ECC. Combined with the "atmel,has-pmecc", it is used to describe + * devices from the SAM9 family that have those. + */ static struct atmel_nand_caps at91rm9200_caps = { .pmecc_correct_erase_page = false, + .pmecc_max_correction = 24, }; static struct atmel_nand_caps sama5d4_caps = { .pmecc_correct_erase_page = true, + .pmecc_max_correction = 24, +}; + +/* + * The PMECC Errloc controller starting in SAMA5D2 is not compatible, + * as the increased correction strength requires more registers. + */ +static struct atmel_nand_caps sama5d2_caps = { + .pmecc_correct_erase_page = true, + .pmecc_max_correction = 32, }; static const struct of_device_id atmel_nand_dt_ids[] = { { .compatible = "atmel,at91rm9200-nand", .data = &at91rm9200_caps }, { .compatible = "atmel,sama5d4-nand", .data = &sama5d4_caps }, + { .compatible = "atmel,sama5d2-nand", .data = &sama5d2_caps }, { /* sentinel */ } }; diff --git a/drivers/mtd/nand/atmel_nand_ecc.h b/drivers/mtd/nand/atmel_nand_ecc.h index 668e7358f19b..ec964c43c932 100644 --- a/drivers/mtd/nand/atmel_nand_ecc.h +++ b/drivers/mtd/nand/atmel_nand_ecc.h @@ -108,7 +108,11 @@ #define PMERRLOC_ERR_NUM_MASK (0x1f << 8) #define PMERRLOC_CALC_DONE (1 << 0) #define ATMEL_PMERRLOC_SIGMAx 0x028 /* Error location SIGMA x */ -#define ATMEL_PMERRLOC_ELx 0x08c /* Error location x */ + +/* + * The ATMEL_PMERRLOC_ELx register location depends from the number of + * bits corrected by the PMECC controller. Do not use it. + */ /* Register access macros for PMECC */ #define pmecc_readl_relaxed(addr, reg) \ @@ -136,7 +140,7 @@ readl_relaxed((addr) + ATMEL_PMERRLOC_SIGMAx + ((n) * 4)) #define pmerrloc_readl_el_relaxed(addr, n) \ - readl_relaxed((addr) + ATMEL_PMERRLOC_ELx + ((n) * 4)) + readl_relaxed((addr) + ((n) * 4)) /* Galois field dimension */ #define PMECC_GF_DIMENSION_13 13