From patchwork Tue Feb 27 20:12:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 207482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3004725dyb; Tue, 27 Feb 2024 14:41:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUX9xChA09EyrJVm48+poLgZYkFzj1k/0R7fPuEW96nfB4Uh1ftvDsPMJtsxVhGsgwUFQV7kyxusGdTdcEeUePrZ4lcqA== X-Google-Smtp-Source: AGHT+IEFZSU4VlB2Be5NyJpcF0z3tUyHcuogwhDYt99UvJwPDU9fVTR2q7uqpYySGXEoKCB1oC2P X-Received: by 2002:aa7:d3c1:0:b0:566:4ed2:4dd4 with SMTP id o1-20020aa7d3c1000000b005664ed24dd4mr1299836edr.27.1709073716901; Tue, 27 Feb 2024 14:41:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709073716; cv=pass; d=google.com; s=arc-20160816; b=qfLHHG5GeZl/GHmXZNlRiwlNDCbTR30HhpwA53fClvPRvGAzya/PRAvdGTBcHS0i+B j+z1DED4PTIh0B+JpWs3/2Ws9xPvGEfdZCNsw5QIKitsOiLBVQG9GM7BGIK4jfpUwTNA zAXUIzPUPuHR1SdqFxPOTl0nc/65McO4roHEtlaTLjW07qyy6y6bpOxaw6FU1shrZjnz gRtCwpbNvPdWXRGGD8mNsUjDaEG/OGwXt0SO7NlGJwDjrmuvnLPC80p/KxQ7vpObCQ6u UXWEQaiKDXI+7ZcwjoAA/5HZO3311aJdxHRa3ixZ162LA8YwwI3hwkM98nN/uiKEvBRm Uu7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=2uE+6OrkLaRm6G+JS5VRzbj6+x/eB4qeU0cHt/YOJfA=; fh=l53zL0HDELqwbuS965LS7Qxc5u+2LLFWQJyweHfQkmI=; b=tKVgNMi+7yfOWCFcYww/+4JvbBPNd9CgCv1M1BOwO8J2VAlXiPWq6LlEcN026KOLe/ yJmauWtIRSA+9pFTcXcv0xYpiZ3gtDuyuIZ8I+jo1MflohKLoHrIkkOjmZLDhKDGCnlG AIf5Jj6LRgD1yz+9EcnQXJznO+8nvYyBXYaJzmaS4ESLewSGQEKdgPu3Jx7+19aKp3V/ NLjaCy/gQKDkoCxM9lwKeg8EwpN4JGIevcQuTl8FogffpqMINCWgM4eWl1wuyC3wbiYJ nkHyh59oM2hB5E+DYgW0vFsL+j/Ma6Fw2pns85mXMMg+hmU5nmx1jFxGmRBe4TiCawVE +ALA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=KJ3s0Dz9; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-83968-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83968-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h30-20020a50cdde000000b00563889e7972si1063090edj.420.2024.02.27.14.41.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 14:41:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83968-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=KJ3s0Dz9; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-83968-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83968-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E64561F2CCD9 for ; Tue, 27 Feb 2024 20:13:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D44D14A0A2; Tue, 27 Feb 2024 20:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="KJ3s0Dz9" Received: from relay.smtp-ext.broadcom.com (unknown [192.19.166.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF64D4D5A2 for ; Tue, 27 Feb 2024 20:13:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.19.166.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709064792; cv=none; b=LgXF9Ra3fxYH6Iyp5x8oI7lAFvwU6/nKIP/NbAwkEc3eZMUFHGQA9si5dLUhRJaqGmnpB9fbv6ItLG+1F0cLOjh7s3iw3rvfIZ9lb+h1v3/kc0Ok5nm60wObeB9os3BgjzuwYWAuU4HXWhVaDcjNcKJFWZ+4tMpJlwBLT57Ii3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709064792; c=relaxed/simple; bh=runYaBF2pYMEMu+6B25HpZw1MLSebHRVgIOUr6N7Lvw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=jzEXxaozlRBEsZfYJzyaH7MQqT5zXVABApDjEngz5jTx98iCZ3M2SaXnXPujqQOrvpT9nmLPhZYhaZH0xhQ4RpBkrKgwVjUxhqTi7OemH5oRMA5kw47VvNruI3Mi33caa3jeuyEpNO3N+DZhjigOPhcNmmPmxw4/xi1hcOVJGTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=KJ3s0Dz9; arc=none smtp.client-ip=192.19.166.228 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: from mail-lvn-it-01.lvn.broadcom.net (mail-lvn-it-01.lvn.broadcom.net [10.36.132.253]) by relay.smtp-ext.broadcom.com (Postfix) with ESMTP id AF664C0032A5; Tue, 27 Feb 2024 12:13:09 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com AF664C0032A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1709064789; bh=runYaBF2pYMEMu+6B25HpZw1MLSebHRVgIOUr6N7Lvw=; h=From:To:Cc:Subject:Date:From; b=KJ3s0Dz9bNNOakieG/zt5CrPTIxSwm7SVwhkvAvMeI6i/gDF/RVzeC7HnDYUMLd2h 8dqa3T3Pfy0P1JRxl24e1nV86bVAcxC5yy7t2+y+PXO4JLk1AsZVY1wJpmeXNgxzH7 Oo2yIcLt0YpqaPvI9vaiDONPvuMMjRoOnYF0ez50= Received: from bcacpedev-irv-3.lvn.broadcom.net (bcacpedev-irv-3.lvn.broadcom.net [10.173.232.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail-lvn-it-01.lvn.broadcom.net (Postfix) with ESMTPSA id 450C318041CAC4; Tue, 27 Feb 2024 12:13:08 -0800 (PST) From: William Zhang To: Linux MTD List , Linux ARM List , Broadcom Kernel List Cc: f.fainelli@gmail.com, kursad.oney@broadcom.com, joel.peshkin@broadcom.com, miquel.raynal@bootlin.com, anand.gore@broadcom.com, dregan@mail.com, kamal.dasu@broadcom.com, tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com, William Zhang , David Regan , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Brian Norris , Richard Weinberger Subject: [PATCH v7] mtd: rawnand: brcmnand: Add support for getting ecc setting from strap Date: Tue, 27 Feb 2024 12:12:52 -0800 Message-Id: <20240227201253.31978-1-william.zhang@broadcom.com> X-Mailer: git-send-email 2.37.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792093681789714074 X-GMAIL-MSGID: 1792093681789714074 This is the update to the patch 12 in the original series [1] that was applied to nand-next except this patch. BCMBCA broadband SoC based board design does not specify ecc setting in dts but rather use the SoC NAND strap info to obtain the ecc strength and spare area size setting. Add brcm,nand-ecc-use-strap dts propety for this purpose and update driver to support this option. However these two options can not be used at the same time. Signed-off-by: William Zhang Reviewed-by: David Regan [1] https://lore.kernel.org/lkml/20240223034758.13753-1-william.zhang@broadcom.com/ --- Changes in v7: - Simply the logic for sector size detection - Update the error message Changes in v6: - Combine the ecc step size and ecc strength into one get function - Treat it as error condition if both brcm,nand-ecc-use-strap and nand ecc dts properties are set - Add intermediate steps to get the sector size bitfield Changes in v4: - Update the comments for ecc setting selection Changes in v2: - Minor cosmetic fixes drivers/mtd/nand/raw/brcmnand/brcmnand.c | 83 ++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index ef7d340475be..8a26ff97c8e2 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1038,6 +1038,22 @@ static inline int brcmnand_sector_1k_shift(struct brcmnand_controller *ctrl) return -1; } +static bool brcmnand_get_sector_size_1k(struct brcmnand_host *host) +{ + struct brcmnand_controller *ctrl = host->ctrl; + int sector_size_bit = brcmnand_sector_1k_shift(ctrl); + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs, + BRCMNAND_CS_ACC_CONTROL); + u32 acc_control; + + if (sector_size_bit < 0) + return false; + + acc_control = nand_readreg(ctrl, acc_control_offs); + + return ((acc_control & BIT(sector_size_bit)) != 0); +} + static void brcmnand_set_sector_size_1k(struct brcmnand_host *host, int val) { struct brcmnand_controller *ctrl = host->ctrl; @@ -1055,6 +1071,43 @@ static void brcmnand_set_sector_size_1k(struct brcmnand_host *host, int val) nand_writereg(ctrl, acc_control_offs, tmp); } +static int brcmnand_get_spare_size(struct brcmnand_host *host) +{ + struct brcmnand_controller *ctrl = host->ctrl; + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs, + BRCMNAND_CS_ACC_CONTROL); + u32 acc = nand_readreg(ctrl, acc_control_offs); + + return (acc & brcmnand_spare_area_mask(ctrl)); +} + +static void brcmnand_get_ecc_settings(struct brcmnand_host *host, struct nand_chip *chip) +{ + struct brcmnand_controller *ctrl = host->ctrl; + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs, + BRCMNAND_CS_ACC_CONTROL); + bool sector_size_1k = brcmnand_get_sector_size_1k(host); + int spare_area_size, ecc_level; + u32 acc; + + spare_area_size = brcmnand_get_spare_size(host); + acc = nand_readreg(ctrl, acc_control_offs); + ecc_level = (acc & brcmnand_ecc_level_mask(ctrl)) >> ctrl->ecc_level_shift; + if (sector_size_1k) + chip->ecc.strength = ecc_level * 2; + else if (spare_area_size == 16 && ecc_level == 15) + chip->ecc.strength = 1; /* hamming */ + else + chip->ecc.strength = ecc_level; + + if (chip->ecc.size == 0) { + if (sector_size_1k) + chip->ecc.size = 1024; + else + chip->ecc.size = 512; + } +} + /*********************************************************************** * CS_NAND_SELECT ***********************************************************************/ @@ -2625,19 +2678,37 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) nanddev_get_memorg(&chip->base); struct brcmnand_controller *ctrl = host->ctrl; struct brcmnand_cfg *cfg = &host->hwcfg; - char msg[128]; + struct device_node *np = nand_get_flash_node(chip); u32 offs, tmp, oob_sector; + bool use_strap = false; + char msg[128]; int ret; memset(cfg, 0, sizeof(*cfg)); + use_strap = of_property_read_bool(np, "brcm,nand-ecc-use-strap"); - ret = of_property_read_u32(nand_get_flash_node(chip), - "brcm,nand-oob-sector-size", + /* + * Either nand-ecc-xxx or brcm,nand-ecc-use-strap can be set. Error out + * if both exist. + */ + if (chip->ecc.strength && use_strap) { + dev_err(ctrl->dev, + "ECC strap and DT ECC configuration properties are mutually exclusive\n"); + return -EINVAL; + } + + if (use_strap) + brcmnand_get_ecc_settings(host, chip); + + ret = of_property_read_u32(np, "brcm,nand-oob-sector-size", &oob_sector); if (ret) { - /* Use detected size */ - cfg->spare_area_size = mtd->oobsize / - (mtd->writesize >> FC_SHIFT); + if (use_strap) + cfg->spare_area_size = brcmnand_get_spare_size(host); + else + /* Use detected size */ + cfg->spare_area_size = mtd->oobsize / + (mtd->writesize >> FC_SHIFT); } else { cfg->spare_area_size = oob_sector; }