Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp738752rdb; Thu, 22 Feb 2024 19:51:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVMOtT2QdqZXPquq6iC6eL9TkdBDDYTN8B3p9WqMAem+dbFeKP/oCoANVboGhUaoUkcmJd7SNv+MZzc8BA2faU+xgvNJ/emX737OPiNxw== X-Google-Smtp-Source: AGHT+IEpPJF6MzU11flA5fFPOkIlxmCAvDQeBSGeX4edzw5I5Wnj05xRiidcVGQrHlDY/+fQ7OQ2 X-Received: by 2002:a05:6830:441f:b0:6e4:2b7a:eb26 with SMTP id q31-20020a056830441f00b006e42b7aeb26mr1089736otv.26.1708660263726; Thu, 22 Feb 2024 19:51:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708660263; cv=pass; d=google.com; s=arc-20160816; b=lcv3YIyFajOzd55ODqa+IXzJtHXMfpRl7kdPqfOypwLsmqrxPsqTqHF183QWtYjdT4 Rk6yY9YpamEJzkJ+SRb0M2fS8ny9sa7X0PZjGD1RCfzbIcluMpuZPbANuq17a3T7QXzy kZ56RYKBP780YCYmccJnLgFqTAncVBQuElwUym7cFCj9p17QtTK5T6J4AdOqNt4vUmC9 dVvS1cODpjzWIdhuLJjKFI+avf8fcmqvoJtCyCUcy790MrUyqCv7iV4n8sQ5LRC/YkPq yWBzrqZJEJnRSLLoYIbX1NAAfFVkzEOmerFlvcttI1LGiL/1U59lTY6dNYoSurc6u6nF b1bA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=w1qvlQTZQhAKermGBdJ/ks4nnfQJQEbBP2rr0ew/UKw=; fh=AfxaAzSp1DGD3XdToJr/VCDlKCO4I16NfwhTjdXKtp8=; b=qs2VbmWSfjbkGqPMYeouwieoSx43AcDlqR1D00dZpf2Eyfu2jek0HPireFKWvz2TaW clSDnSxlyrLv+Zv13YccqsTZ6f45/aCYmD0lYHUx8x4yfGT2VBLgIpHwDQTPIu9ea9i8 TU7lDEbjMXAFQIvmm8G0fiB+oNOuRS2v1w/pm0q3OIGLrm23zCQ08Rq4kcGEAU/hDYek GEMehKvTxztivW19lnm+EnBBm0bGz4ziNUWoR71G78nBhKb0vZtEwBmRTL8PEs0hBwFj MrK90guQnN0kEHP6ZxZ2jEF+GimemkbRbTFQmcXu4tCtiAzCncWiWFqOFluzdTLkwmfi vuNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=g1Ut55jy; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-77737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77737-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q21-20020a638c55000000b005dc97d88897si11655960pgn.698.2024.02.22.19.51.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 19:51:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=g1Ut55jy; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-77737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77737-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9C95B287A78 for ; Fri, 23 Feb 2024 03:50:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1E1117BD8; Fri, 23 Feb 2024 03:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="g1Ut55jy" Received: from relay.smtp-ext.broadcom.com (relay.smtp-ext.broadcom.com [192.19.144.205]) (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 1922314000 for ; Fri, 23 Feb 2024 03:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.19.144.205 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708660116; cv=none; b=eMfqwaBfJqnBObwOykRNIEG/uVpiYyUqm+oSJAiseDLsb8a7JEXdD1+r1qsFd2Ih24K2aTovNjlS2SztVLfF0UJGd34umt4Em7Oy9K0iRf3bQVb6YBNMIOZ8c6IuKspXMks2SwBS1nG4R2b3f7JExy6wtFwa3E0c00KHqZkp350= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708660116; c=relaxed/simple; bh=IlWBsnu227JMFpQncv19RcNKiY0NO3wmso1R4ya+F6I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hZE4RGqtg/3X45xdj67tzCAYVbzdeFggA+ihsjhU+YzHQ0kTY7v7r6G+PPOBTEiowjgrJz8TyMx6uwDfbvmR+gEAvuFczj68gY5CORW531sToa/JFWAOlFA+TWdfBeGJETqipw2YN2bnFZKrk0OIp1fHPh93A7kC1VSZb3gn99I= 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=g1Ut55jy; arc=none smtp.client-ip=192.19.144.205 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 E3789C0000F9; Thu, 22 Feb 2024 19:48:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com E3789C0000F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1708660114; bh=IlWBsnu227JMFpQncv19RcNKiY0NO3wmso1R4ya+F6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g1Ut55jy+SWzboCGgdsV/AhcWxf1oTIzCWx0rFPTe8RRlW5ahTG5A7yBtiV4QZfMu +H0d2HyIcSQTt8yeKMdRXXfh/8sa4dy8M4OQHlyZUiAisR+SEuGlj2xli70fIGxWXf 59HJlpmP9YPWw6QK6I6PBvESc0X6jYOfXlEyYmKU= 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 36B9E18041CAC4; Thu, 22 Feb 2024 19:48:32 -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, anand.gore@broadcom.com, dregan@mail.com, kamal.dasu@broadcom.com, tomer.yacoby@broadcom.com, dan.beygelman@broadcom.com, William Zhang , David Regan , Miquel Raynal , linux-kernel@vger.kernel.org, Vignesh Raghavendra , Brian Norris , Richard Weinberger Subject: [PATCH v6 12/13] mtd: rawnand: brcmnand: Add support for getting ecc setting from strap Date: Thu, 22 Feb 2024 19:47:57 -0800 Message-Id: <20240223034758.13753-13-william.zhang@broadcom.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20240223034758.13753-1-william.zhang@broadcom.com> References: <20240223034758.13753-1-william.zhang@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 v5: None Changes in v4: - Update the comments for ecc setting selection Changes in v3: None 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..e8ffc283b365 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 int 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 0; + + acc_control = nand_readreg(ctrl, acc_control_offs); + + return (acc_control & BIT(sector_size_bit)) >> sector_size_bit; +} + 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); + int 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 < 0) + chip->ecc.size = 512; + else + chip->ecc.size = 512 << sector_size_1k; + } +} + /*********************************************************************** * 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, + "nand ecc and strap ecc settings can't be set at the same time\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; } -- 2.37.3