From patchwork Wed Feb 7 20:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Zhang X-Patchwork-Id: 198130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2568726dyb; Wed, 7 Feb 2024 15:33:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWJVP+tT81lfHEu5uKelavpXK9Z/KDDGeh0dhdKELL3UAEH3BEzYE4g+HIYhDEdA1Ki2eB8/QosZPkWwzr+UT+VFwy0Cw== X-Google-Smtp-Source: AGHT+IENeRbodA0ayJZatxVUikmIv87X2SHL/b2SVL7ZGtp5B4LUUe89MDHB0+V1YoZkAR1Ml3R9 X-Received: by 2002:a17:903:110f:b0:1d9:8def:6942 with SMTP id n15-20020a170903110f00b001d98def6942mr7895127plh.23.1707348838493; Wed, 07 Feb 2024 15:33:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707348838; cv=pass; d=google.com; s=arc-20160816; b=bYq6ZP2G4IyDbIoiirhXLbhfq1Lpj8MV3k2J+ZSWTVVLV3xOTmHKTJ10S5Frmp7knZ gu8bQZ/qYDoUvYK9Zd8n0gJZ117pZ5rXZhFlkoZkxP5dVL1ux85as1R4V4swYv4cakZF Q7cC9DxcW8U8V0NhjyilIafufXKnoCb8vSu4/B0mGMWVS2jFpu4zMZFuWeIkQ5ir/6VB USe/XUJA8EMZbDy8EDdk3PHzW99mf/eX17IZEQuc0YFgpmaCZHWfnpK0kCWEYoEjl3Jr woCWiFq2panlWFXdhvJyoCEm6pdXQXkzR+kXim+LJVwCKzOCtTN3zd/FdMWA9vjn8sNm Pdhw== 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=XWNXPoTLfBmZ6reuM8Ik87ILflJ/ymsfKs853LMeyMs=; fh=CajMFkvJOEazDsfalXgWszYVVVOVKFdasoSCSra28vA=; b=ddOJQxQJGShTvzfkGMdyjmpbunwvWiplFJwPW3qT6unCAIq+W8MvId3Un66PiVv+xs 8Pq/Ifz30T1kxbi/gejBM7DnoNmeAjnukrh5b3gI7VHD/S214j45QshtqqrM6S+I3CM5 tlIz44u3fK2V7yhmJ7tJyG+w4bSoqmU2O4mbyo/90FvtDbGiWs4/8y8i8d4N3+1/bAs1 h6eepXgCmur+MkFFJHmGX9MSYC1jLUcAOio5ezzjdju+UoK5VWQ7tBfWuE9HZ3wJhLIE WNL+CPnOYrl0gmV65VppQ+GycwUIwkKgY4wQzG2xZn+RIOlRtvrMJy3ijj5vzutg41j0 ovqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=mh5eTHW3; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-57020-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57020-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com X-Forwarded-Encrypted: i=2; AJvYcCWMXWIB07a/lmIRga5bc+2s5uTZ7dTOguZVMB3agc8qBUfVCZ8rY6uchkB9K1o9uLhPRPHaz0qEFaInN2Z3UdML/XdRzA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d20-20020a170903209400b001d99735ed7dsi2482467plc.435.2024.02.07.15.33.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 15:33:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57020-ouuuleilei=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=mh5eTHW3; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-57020-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57020-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 3C6A528D30A for ; Wed, 7 Feb 2024 20:26:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9737212E1EE; Wed, 7 Feb 2024 20:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="mh5eTHW3" 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 9C8AF12C53C for ; Wed, 7 Feb 2024 20:24:08 +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=1707337450; cv=none; b=EsqJMllxC1eqz2jrfLpuS72XNRR6rP5Eb+iPJ76iocSrTW6HB1C3WKTN9ZalpzhbPKJ2759SnW4XH4P0ILRmJr2jbSEtJlId9BJeKfT3zgjI5IiQ3fXbISHJcsoJervmMQtTE1taJ3mMmNo8mY/nYnjUoX6xVFI0IYqIpNM7ZPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707337450; c=relaxed/simple; bh=1Yh76Q4bafQj8j8zmFp3LQ71wEoIHitjS2PH4qKEFkw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JfHtdIthiwQpbTRkQooVrwbmmcdzV+1G3s5lXpW7CSo3mLSogPrAlgg/q5YCsF7jCY8qOGzodOFSo/RQKFYsPHFgzWaXKY9WXWVAG51V4zwBFTAMuU6Jn+YeGGUBwBNbq4Bg0YS86l8PcD2VKwrWnkTP7MF0HduCR3JwzlWRrkA= 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=mh5eTHW3; 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 DCBC9C0094CA; Wed, 7 Feb 2024 12:24:07 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com DCBC9C0094CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1707337447; bh=1Yh76Q4bafQj8j8zmFp3LQ71wEoIHitjS2PH4qKEFkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mh5eTHW3ecA8+Yd5hfuEAI6bzxkyankIbx4jjFcQK5LNCrnYe8YT5HgfHSByl+OMW Mp5X/1wxKS8XM0lm4MxP1zUwOTvZidsNnkB7frF+6AMMmquNlUHUixMkQG7g48gmMa JsPb7d+uovlY1Q9FMVvmDNaIDFxEzDT8Y2mSBMTE= 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 6B45618041CAC4; Wed, 7 Feb 2024 12:24:06 -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 v5 09/12] mtd: rawnand: brcmnand: Add support for getting ecc setting from strap Date: Wed, 7 Feb 2024 12:22:54 -0800 Message-Id: <20240207202257.271784-10-william.zhang@broadcom.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20240207202257.271784-1-william.zhang@broadcom.com> References: <20240207202257.271784-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790285015959145001 X-GMAIL-MSGID: 1790285015959145001 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. The generic nand ecc settings still take precedence over this flag. For example, if nand-ecc-strength is set in the dts, the driver ignores the strap setting and falls back to original behavior. This makes sure that the existing BCMBCA board dts still works the old way even the strap flag is set in the BCMBCA chip dtsi. Signed-off-by: William Zhang Reviewed-by: David Regan --- 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, 76 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 73fdf7ce21aa..efeee9e80213 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1038,6 +1038,19 @@ 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 shift = brcmnand_sector_1k_shift(ctrl); + u16 acc_control_offs = brcmnand_cs_offset(ctrl, host->cs, + BRCMNAND_CS_ACC_CONTROL); + + if (shift < 0) + return 0; + + return (nand_readreg(ctrl, acc_control_offs) >> shift) & 0x1; +} + static void brcmnand_set_sector_size_1k(struct brcmnand_host *host, int val) { struct brcmnand_controller *ctrl = host->ctrl; @@ -1055,6 +1068,38 @@ 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 int brcmnand_get_ecc_strength(struct brcmnand_host *host) +{ + 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, ecc_strength; + 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) + ecc_strength = ecc_level * 2; + else if (spare_area_size == 16 && ecc_level == 15) + ecc_strength = 1; /* hamming */ + else + ecc_strength = ecc_level; + + return ecc_strength; +} + /*********************************************************************** * CS_NAND_SELECT ***********************************************************************/ @@ -2622,19 +2667,43 @@ 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; - int ret; + int ret, sector_size_1k = 0; + bool use_strap = false; + char msg[128]; 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", + /* + * Set ECC size and strength based on hw configuration from strap + * if brcm,nand-ecc-use-strap is set. However if nand-ecc-strength + * is set, its value will be used and ignore the strap setting. + */ + if (chip->ecc.strength) + use_strap = 0; + + if (use_strap) { + chip->ecc.strength = brcmnand_get_ecc_strength(host); + sector_size_1k = brcmnand_get_sector_size_1k(host); + if (chip->ecc.size == 0) { + if (sector_size_1k < 0) + chip->ecc.size = 512; + else + chip->ecc.size = 512 << sector_size_1k; + } + } + + 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; }