From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A874FC6FD1D for ; Fri, 7 Apr 2023 13:40:53 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B24B8619A; Fri, 7 Apr 2023 15:40:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rkShaQ0O"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09ECD86065; Fri, 7 Apr 2023 15:40:27 +0200 (CEST) Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 27B1386177 for ; Fri, 7 Apr 2023 15:40:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=linus.walleij@linaro.org Received: by mail-lf1-x132.google.com with SMTP id k37so54606629lfv.0 for ; Fri, 07 Apr 2023 06:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680874821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=61zoUXN+tmQMmv4NeWPQkg+uqdaL82AzLpTjY7to9UY=; b=rkShaQ0OfLo1IfgN9KEVHFHYcWyutbpzkmzl4onGlhyZ8K//Pc6c1xg5lXpm7W/IXY SMac/dnS3wScSZeE7CZmr8a0UADgsV3jQrr2nGGjmJSf122n4wy1loEiffLBpkLwI7cf QDRHgxjzpUI0uDo6GtM0h4x1Vo7FHc+fwYLWgmCcVqbpK38K60Z8LD1qB7cbT1XiyPX+ 7yNZSga1ObI5h7OIMOLXxM2AZWYnIMrp+BtK/7oykikhOi29nuvs4EOYgaX8u0BexF4G jkoZuj1e3FjFJkMLmJGmpdq+M4NTQWnhqhqHBIqZr48cvcqslbWh1DieOQcY/qLqP7l1 lLww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680874821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=61zoUXN+tmQMmv4NeWPQkg+uqdaL82AzLpTjY7to9UY=; b=qp84Eeklto5oQj9j0npRQ21vVEFnZl51po8JKd87lpB4Vdn+8JEOh+/IIZdMxz0JGj SKqHT7vcaMzwWOyJXK/DFE3JwKF8Ow+idufSrW+Gsd2EaowYaoR8IXShRjeaeRbjHtHM ilPUnOHHMy6FZYnC4SjSygtHmJp1ccZoxbPt7RJC/kA4bID5V5M5hgiTiETUZpQUMMWa +2cEkiX3ueoAIjf/s2WVYrCudEgnIRQwSk/vsSmHTRHy5dI7CSHuEcwmfee5SHBLQAGk 59B9VcPorhCF7hgYVWI0HMq4hTwrD0seSZwK9s9l6FBthXSV1xH43n1vyoYsRrkoaro5 biXA== X-Gm-Message-State: AAQBX9eughX1hAiC6rRg5Pu6UdwSJm6rQrzVEsEerFbZ6m445yMQ3PPH HYrm/1S6oWk2VhU9FRUVTmv0F6tTkVnII+LEz6g= X-Google-Smtp-Source: AKy350YzCu6YUeTpcgOuBnBLGTstk48rNSn10roCFcy1TS7BIo+qHmPDJ80KYKCo1bUQuE/cM34UiA== X-Received: by 2002:a05:6512:3053:b0:4eb:40d4:c1f7 with SMTP id b19-20020a056512305300b004eb40d4c1f7mr493025lfb.6.1680874821226; Fri, 07 Apr 2023 06:40:21 -0700 (PDT) Received: from Fecusia.lan (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id 23-20020ac24857000000b00492c663bba2sm711064lfy.124.2023.04.07.06.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Apr 2023 06:40:20 -0700 (PDT) From: Linus Walleij To: u-boot@lists.denx.de, Tom Rini , Michael Nazzareno Trimarchi , William Zhang Cc: Anand Gore , Kursad Oney , Joel Peshkin , Philippe Reynes , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Linus Walleij Subject: [PATCH v4 2/5] mtd: rawnand: nand_base: Handle algorithm selection Date: Fri, 7 Apr 2023 15:40:05 +0200 Message-Id: <20230407134008.1939717-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230407134008.1939717-1-linus.walleij@linaro.org> References: <20230407134008.1939717-1-linus.walleij@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the D-Link DIR-885L and DIR-890L routers, we need to explicitly select the ECC like this in the device tree: nand-ecc-algo = "bch"; nand-ecc-strength = <1>; nand-ecc-step-size = <512>; This is handled by the Linux kernel but U-Boot core does not respect this. Fix it up by parsing the algorithm and preserve the behaviour using this property to select software BCH as far as possible. Reviewed-by: Michael Trimarchi Acked-by: William Zhang Signed-off-by: Linus Walleij --- ChangeLog v3->v4: - After a bug report from Tom, be more careful when assigning algorithm: only overwrite the chip default when something other than undefined was actually detected. ChangeLog v2->v3: - Collect review tags from Michael and William - Resend with the NorthStar enablement patches ChangeLog v1->v2: - Drop pointless check for ecc_algo >= 0, it is always >= 0. --- drivers/mtd/nand/raw/nand_base.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 9eba360d55f3..6b4adcf6bdc9 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4487,6 +4487,7 @@ EXPORT_SYMBOL(nand_detect); static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node) { int ret, ecc_mode = -1, ecc_strength, ecc_step; + int ecc_algo = NAND_ECC_UNKNOWN; const char *str; ret = ofnode_read_s32_default(node, "nand-bus-width", -1); @@ -4512,10 +4513,22 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod ecc_mode = NAND_ECC_SOFT_BCH; } - if (ecc_mode == NAND_ECC_SOFT) { - str = ofnode_read_string(node, "nand-ecc-algo"); - if (str && !strcmp(str, "bch")) - ecc_mode = NAND_ECC_SOFT_BCH; + str = ofnode_read_string(node, "nand-ecc-algo"); + if (str) { + /* + * If we are in NAND_ECC_SOFT mode, just alter the + * soft mode to BCH here. No change of algorithm. + */ + if (ecc_mode == NAND_ECC_SOFT) { + if (!strcmp(str, "bch")) + ecc_mode = NAND_ECC_SOFT_BCH; + } else { + if (!strcmp(str, "bch")) { + ecc_algo = NAND_ECC_BCH; + } else if (!strcmp(str, "hamming")) { + ecc_algo = NAND_ECC_HAMMING; + } + } } ecc_strength = ofnode_read_s32_default(node, @@ -4529,6 +4542,14 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod return -EINVAL; } + /* + * Chip drivers may have assigned default algorithms here, + * onlt override it if we have found something explicitly + * specified in the device tree. + */ + if (ecc_algo != NAND_ECC_UNKNOWN) + chip->ecc.algo = ecc_algo; + if (ecc_mode >= 0) chip->ecc.mode = ecc_mode; -- 2.39.2