From patchwork Mon Sep 16 09:58:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829005 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699563wrb; Mon, 16 Sep 2024 02:59:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWcK8s4QohINvnEOtQCOUqWuo8fXRYwrW607uTeQdRinu8kva525jAnXU7iGGdvMk7CMmzNLA==@linaro.org X-Google-Smtp-Source: AGHT+IGRTEDQ/IQbsZSr0ohojJFI16BbrokvUAuYZXrIlCc/QDEqX3rYm44SD/77ilQTI4IR/zKS X-Received: by 2002:a05:6000:459f:b0:378:7e94:d613 with SMTP id ffacd0b85a97d-378c2d4cd9fmr7449700f8f.42.1726480754224; Mon, 16 Sep 2024 02:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480753; cv=none; d=google.com; s=arc-20240605; b=fYCtYPm6ZaCpnVotO1tE8M8t0uXItvh4T7BpU/PvFOR57iZFTSpk23rkJBX4ZWxSa0 8p6zc35QFxvY7a57yTM7wqCQ9Yw9OniS7KZtHYKR3B8Xfe2unRqfwe1yEIcPUx+7pE5L y2lmNiW4PykszaJ64pVSStPmmnv7w+qL8JR0Mjn5AR4d6rLtbQxOR/zfolWPLbb23nNH cndXo0OgeozxdAd7h8fBUGcQqM721OfCX+oOEcbEW5M8KPat20t5VkRRC7fP4Ei9PXZK uxGHL9La4A0OQZAUEDW9/Amh/ztjtLmuk6wXkcIH6zYHlNeJodggIr6C4Uslh/SZrVu3 8eMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ej78Q2+PYKVgEy5EEJLNV3zuVL9MfHwoOkA0nh6pcxE=; fh=bbSjVJcsz6ma3Arirz+KWNos93PEC62yDVUDN8y6koA=; b=Y6fzf9kQ23f66GgsrRGjSVPmnZQMvuIEQlsK2JuLa4JznfIrRifafbRntxhe+4bNiS 1RL9sPPt3LTFUsgmayypTYzv+pq6aijOC/+0U6LJmqh1pthVWADh8AWHboeu4XL9Gm4i WAW4JXhh2VVpkbgZ/0UrEXUb3AlPYtsiYgyFq9PA62xcstZeNBZNvV90ubEqRnPunbAb MIgJhu+I9cmLDSEVYfYbNL8ddF0MXOGTR6Zoe1i81cIiVI4+4ZlG/IkQ9sFJAvfGzCwt +/uZse8sYVJTG2JLyRygpXrRl0HHkF6t/qNjw97JFpuYWQqOrckg+FaWjlrtL6Xh4Cr8 OXvw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="FdwSN/Lr"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-378e73f60dbsi2087611f8f.269.2024.09.16.02.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:59:13 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="FdwSN/Lr"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8894388EE3; Mon, 16 Sep 2024 11:58:54 +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="FdwSN/Lr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 87F9988EEB; Mon, 16 Sep 2024 11:58:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) (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 2797B88EC2 for ; Mon, 16 Sep 2024 11:58:50 +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-x129.google.com with SMTP id 2adb3069b0e04-53568ffc525so4829051e87.0 for ; Mon, 16 Sep 2024 02:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480729; x=1727085529; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ej78Q2+PYKVgEy5EEJLNV3zuVL9MfHwoOkA0nh6pcxE=; b=FdwSN/Lrw+OgL0QXoK7ytOQoUhj+sPabaDF6VKwEgCI3GVbprDKdFJaeBkdGXHySkf dH6NhKXBJE8MUsaDY9uxkjQ38TvjNJO/wtf9oZiFg4aikF/RiimW2wuH6T/zpTtgmucS I85eDrZku4U6Z/1HTdGH41Mqn+Wx/8m9wzds3HH5hl+3m9+l4b49hWwuUjSeVwCHVw1r une43BG60XpSnBcSVngc45cPIwR886XgE/faMUSVx82G8NixfKf/9aRtDzUiA5zXNQC4 WMi+QLZO8LY/x/02u8Ge5d43cEIqTCsH7d1z+W3u9euYF58+caqb9DuHy4Lrjgl4Vx4X F5sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480729; x=1727085529; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ej78Q2+PYKVgEy5EEJLNV3zuVL9MfHwoOkA0nh6pcxE=; b=kq//d8mRymdMppZVQz9Geq6PQSoCvcgdPN/HjifagDxlt0EJINggWusaV8Iq0LcABB VbEbkFxNnikV1/eKBdT9wJLX8pW0wAcpvF4iG2ZfnEBRDBKKh1OXCnjL4z4fV4PGmJq8 pPywwmZFdQtrzUVdvdZDNOCviKm+ytZGgpRVIf9Z8b8Q9NF8zSDAEeBQfkpQOT9qP10V eHow+/sWPSm9dXvEKR1W79todSWDyFBsp6NNGKX/VaaU2lNSIKxTQWNoTWh/CsG+lPEQ 5yA5McoU4KvxC1MUVRjP22Ozhf35rHLKstwFYUYEkyJ1A0pu124MbdNo5wGSRgayPxJP HusA== X-Gm-Message-State: AOJu0YxiUjOwM2vgpuJcC3u2Wh8IEqq5fOGlDdIWpzzsP7tqCU7qIh6f Zw2QpiQ1XMnEaaVUWioYmLp5vsmTvuty3jXyBpjti2m/7BKf8asglNtjCxfGpco= X-Received: by 2002:a05:6512:2208:b0:52e:7656:a0f4 with SMTP id 2adb3069b0e04-53678feb138mr7455275e87.41.1726480728323; Mon, 16 Sep 2024 02:58:48 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:47 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:43 +0200 Subject: [PATCH v2 1/7] mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-1-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij , Florian Fainelli , Miquel Raynal X-Mailer: b4 0.14.0 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 From: William Zhang Backport from the Linux kernel commit 2ec2839a9062db8a592525a3fdabd42dcd9a3a9b "mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller" v7.2 controller has different ECC level field size and shift in the acc control register than its predecessor and successor controller. It needs to be set specifically. Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20230706182909.79151-2-william.zhang@broadcom.com Signed-off-by: Linus Walleij Reviewed-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 74 ++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index b1af3f717d43..700d1122639f 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -218,6 +218,7 @@ struct brcmnand_controller { const unsigned int *page_sizes; unsigned int page_size_shift; unsigned int max_oob; + u32 ecc_level_shift; u32 features; /* for low-power standby/resume only */ @@ -544,6 +545,34 @@ enum { INTFC_CTLR_READY = BIT(31), }; +/*********************************************************************** + * NAND ACC CONTROL bitfield + * + * Some bits have remained constant throughout hardware revision, while + * others have shifted around. + ***********************************************************************/ + +/* Constant for all versions (where supported) */ +enum { + /* See BRCMNAND_HAS_CACHE_MODE */ + ACC_CONTROL_CACHE_MODE = BIT(22), + + /* See BRCMNAND_HAS_PREFETCH */ + ACC_CONTROL_PREFETCH = BIT(23), + + ACC_CONTROL_PAGE_HIT = BIT(24), + ACC_CONTROL_WR_PREEMPT = BIT(25), + ACC_CONTROL_PARTIAL_PAGE = BIT(26), + ACC_CONTROL_RD_ERASED = BIT(27), + ACC_CONTROL_FAST_PGM_RDIN = BIT(28), + ACC_CONTROL_WR_ECC = BIT(30), + ACC_CONTROL_RD_ECC = BIT(31), +}; + +#define ACC_CONTROL_ECC_SHIFT 16 +/* Only for v7.2 */ +#define ACC_CONTROL_ECC_EXT_SHIFT 13 + static inline u32 nand_readreg(struct brcmnand_controller *ctrl, u32 offs) { return brcmnand_readl(ctrl->nand_base + offs); @@ -675,6 +704,12 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl) #endif /* __UBOOT__ */ ctrl->features |= BRCMNAND_HAS_WP; + /* v7.2 has different ecc level shift in the acc register */ + if (ctrl->nand_version == 0x0702) + ctrl->ecc_level_shift = ACC_CONTROL_ECC_EXT_SHIFT; + else + ctrl->ecc_level_shift = ACC_CONTROL_ECC_SHIFT; + return 0; } @@ -844,30 +879,6 @@ static inline int brcmnand_cmd_shift(struct brcmnand_controller *ctrl) return 0; } -/*********************************************************************** - * NAND ACC CONTROL bitfield - * - * Some bits have remained constant throughout hardware revision, while - * others have shifted around. - ***********************************************************************/ - -/* Constant for all versions (where supported) */ -enum { - /* See BRCMNAND_HAS_CACHE_MODE */ - ACC_CONTROL_CACHE_MODE = BIT(22), - - /* See BRCMNAND_HAS_PREFETCH */ - ACC_CONTROL_PREFETCH = BIT(23), - - ACC_CONTROL_PAGE_HIT = BIT(24), - ACC_CONTROL_WR_PREEMPT = BIT(25), - ACC_CONTROL_PARTIAL_PAGE = BIT(26), - ACC_CONTROL_RD_ERASED = BIT(27), - ACC_CONTROL_FAST_PGM_RDIN = BIT(28), - ACC_CONTROL_WR_ECC = BIT(30), - ACC_CONTROL_RD_ECC = BIT(31), -}; - static inline u32 brcmnand_spare_area_mask(struct brcmnand_controller *ctrl) { if (ctrl->nand_version == 0x0702) @@ -880,18 +891,15 @@ static inline u32 brcmnand_spare_area_mask(struct brcmnand_controller *ctrl) return GENMASK(4, 0); } -#define NAND_ACC_CONTROL_ECC_SHIFT 16 -#define NAND_ACC_CONTROL_ECC_EXT_SHIFT 13 - static inline u32 brcmnand_ecc_level_mask(struct brcmnand_controller *ctrl) { u32 mask = (ctrl->nand_version >= 0x0600) ? 0x1f : 0x0f; - mask <<= NAND_ACC_CONTROL_ECC_SHIFT; + mask <<= ACC_CONTROL_ECC_SHIFT; /* v7.2 includes additional ECC levels */ - if (ctrl->nand_version >= 0x0702) - mask |= 0x7 << NAND_ACC_CONTROL_ECC_EXT_SHIFT; + if (ctrl->nand_version == 0x0702) + mask |= 0x7 << ACC_CONTROL_ECC_EXT_SHIFT; return mask; } @@ -905,8 +913,8 @@ static void brcmnand_set_ecc_enabled(struct brcmnand_host *host, int en) if (en) { acc_control |= ecc_flags; /* enable RD/WR ECC */ - acc_control |= host->hwcfg.ecc_level - << NAND_ACC_CONTROL_ECC_SHIFT; + acc_control &= ~brcmnand_ecc_level_mask(ctrl); + acc_control |= host->hwcfg.ecc_level << ctrl->ecc_level_shift; } else { acc_control &= ~ecc_flags; /* disable RD/WR ECC */ acc_control &= ~brcmnand_ecc_level_mask(ctrl); @@ -2225,7 +2233,7 @@ static int brcmnand_set_cfg(struct brcmnand_host *host, tmp &= ~brcmnand_ecc_level_mask(ctrl); tmp &= ~brcmnand_spare_area_mask(ctrl); if (ctrl->nand_version >= 0x0302) { - tmp |= cfg->ecc_level << NAND_ACC_CONTROL_ECC_SHIFT; + tmp |= cfg->ecc_level << ctrl->ecc_level_shift; tmp |= cfg->spare_area_size; } nand_writereg(ctrl, acc_control_offs, tmp); From patchwork Mon Sep 16 09:58:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829004 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699508wrb; Mon, 16 Sep 2024 02:59:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXl5zVcUFp+X88F1Q5dADnIsGWYjm4YKW5SDfVGlgIwUAUiO3qEzDXzPhvkEpgqIlSSfmEyTw==@linaro.org X-Google-Smtp-Source: AGHT+IEmz6fsL/xgIwwnyArpR1ca60UfVVCU0bhNiRpcMxZkRJNrBnYsCnRtwn8iokffrH/X6YBX X-Received: by 2002:adf:e282:0:b0:376:7dc1:6e91 with SMTP id ffacd0b85a97d-378a8a1c6c5mr12659966f8f.11.1726480743949; Mon, 16 Sep 2024 02:59:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480743; cv=none; d=google.com; s=arc-20240605; b=HfCfKcNZXLw96i+BaY1noTt4YmMri1wR2uO7fOi5ttThsUu+6kIywydGIQWUUeMBzx yFZ2V8umIK2dqF2ymP90W5F+Bpz0iTsib0rqQ3NmBpHCuVsoO9ssNs/9YLdcucV3hGo9 KT6jvzJ4UShA2E68m805N1DRbMHaKisiGqES6Zr9u2urP/0AmBw8XygwDsm3ILiY4ocB hHevEhxuDa5UksKWMgBpQ22JY4JXfYFTh3kPNApaP0yc02hTm4WlsW1fMiuhC7fh2Vk4 rx4b6PBcAjDz7CUZov0tfyQsNWnalGKfVj6bev1iL6yfjLYC48Eu4pmBT62gMnzu/Q7+ O2EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=cy0AelE8X6/ImwZyMOvnLyspFv+MmXcjl2xKIRLZjow=; fh=bbSjVJcsz6ma3Arirz+KWNos93PEC62yDVUDN8y6koA=; b=hFha4kYjN/91oizXVLRwG6lLvuLTE33kGP2tAt96O7A4JVDmIYz8HxvxdlqEBJjq5A IautO0eG3XgSxFSbVwmRaMOFhWV4Es+XotL932aHsM5COFbY0mGtoZ49LViPjGI6C8GS Nkb4nY/y1OuA95knUZHY1z9q38xnhHPCGhE6TygqUh1eiuCsogHXFfmFSME8sB0B3prN ZboPylQTFY0odph36/YBLUJruIcGbEEVnNLp/0R9rbY7Dei8De5HAyAlYdUZsedm5lbm IyWhNVBRi5tyMDPiZFQVscyXKZqqMqafwXopWTBSZo7HSdQ0h4SSeFAqS00QjQEllJKC nziA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gfxXizCd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-378e73dfca1si2050318f8f.198.2024.09.16.02.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:59:03 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gfxXizCd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2D5F388EC4; Mon, 16 Sep 2024 11:58:54 +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="gfxXizCd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA84888EEB; Mon, 16 Sep 2024 11:58:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) (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 9244F8899C for ; Mon, 16 Sep 2024 11:58:50 +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-ej1-x62a.google.com with SMTP id a640c23a62f3a-a8d6ac24a3bso772172966b.1 for ; Mon, 16 Sep 2024 02:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480730; x=1727085530; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cy0AelE8X6/ImwZyMOvnLyspFv+MmXcjl2xKIRLZjow=; b=gfxXizCdUnIT1RtnVQANWiWdHBZBVu9owU/8mB0NInBemf9bxJLq1x4KU3mV84+GrD oI4+CeIkQ3P4rp62C6SUJQzsW5Uzp8C7Bsn2ZNKJku8SMEkYGf7RZyAfZNlkMHmaEnRv TlcZgDpLLHLxtGT5gJiHqdpNPHggwbE6cRkxXb4lSzyPDBfg1K/EL35EJyZJcJ581Yoz t6I9W/l40JE4tfnVkWzBLgO3zlC6gLZhXhLin5EQlI4HIZRUswKFqHR7uqKkL2rPgLr9 Xqc3vBAoT/LgTfMP4tAxmdk0GIXekgvwQqTJkSY8VE83r9K9u287JqlbqAl2Xy/poH55 qzOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480730; x=1727085530; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cy0AelE8X6/ImwZyMOvnLyspFv+MmXcjl2xKIRLZjow=; b=byfyrc4kayu+nWhIVm99yHW+vmYtAkrx+DHPjGSbOIbS+1J/30ZI5pl+CSnMGMoyQU vlXXDgeZAtNb8d3Bo0VAbiSP2Qn3YSJDaYg8Enr6YKczKl42WidQ7FcnoUcqK6wJuWuo uzbGviLg7KZk99xtjnJh9BC/3s82XghzUvmNLf3T5N7fEMCDeMIdSjIKR331wSfhQHJH FoE8nVdyNNQYgEEX+ElkoBt4O8PNFVwok/gJunLRRvy9xraU+xAteW5a6YOgvk90SMjb VVIHFOKj+bOLRd3qfai15unuwzTZRL/q9Zol0Mp29uclL9D3/J8FK8RLWylbG0+dyZXj tw+g== X-Gm-Message-State: AOJu0YxBwnAq4cx8PcQQQqSZiLq1M004V/tGxN7C8i85Gfy678fxd9+f lww9oYfS/dNzBn96OH1wZpU9IMPd8ui9ZFn8jNBcUD+EFwTdJOd46+fyHeFyRJQ= X-Received: by 2002:a17:907:2da3:b0:a8d:63b5:e795 with SMTP id a640c23a62f3a-a8ffaadad47mr2175007666b.3.1726480729350; Mon, 16 Sep 2024 02:58:49 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:49 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:44 +0200 Subject: [PATCH v2 2/7] mtd: rawnand: brcmnand: Fix potential false time out warning MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-2-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij , Florian Fainelli , Miquel Raynal X-Mailer: b4 0.14.0 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 From: William Zhang Backport from the Linux kernel: commit 9cc0a598b944816f2968baf2631757f22721b996 "mtd: rawnand: brcmnand: Fix potential false time out warning" If system is busy during the command status polling function, the driver may not get the chance to poll the status register till the end of time out and return the premature status. Do a final check after time out happens to ensure reading the correct status. Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20230706182909.79151-3-william.zhang@broadcom.com Signed-off-by: Linus Walleij Reviewed-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 700d1122639f..46a4107a83a9 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1011,6 +1011,14 @@ static int bcmnand_ctrl_poll_status(struct brcmnand_controller *ctrl, } while (get_timer(base) < limit); #endif /* __UBOOT__ */ + /* + * do a final check after time out in case the CPU was busy and the driver + * did not get enough time to perform the polling to avoid false alarms + */ + val = brcmnand_read_reg(ctrl, BRCMNAND_INTFC_STATUS); + if ((val & mask) == expected_val) + return 0; + dev_warn(ctrl->dev, "timeout on status poll (expected %x got %x)\n", expected_val, val & mask); From patchwork Mon Sep 16 09:58:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829006 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699587wrb; Mon, 16 Sep 2024 02:59:24 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUyXCEev0GchSKRRs9VxYCasuCYhC4ksjd+xyUXK6E4biCRXNCTpbNCfqo7Wl5uKVJ/qISHzA==@linaro.org X-Google-Smtp-Source: AGHT+IHQKKWHgpA/ypSNuc6XK2z1YpocuHrjK5GVS956Ev4Bg3tik4WOoHsv1PSaKKKq7+OmSiKe X-Received: by 2002:a05:600c:4746:b0:426:6158:962d with SMTP id 5b1f17b1804b1-42d964d8612mr77833425e9.23.1726480764367; Mon, 16 Sep 2024 02:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480764; cv=none; d=google.com; s=arc-20240605; b=EDFe38NVlKVGEttdTB/oE+3C/g6xp7Zd6kQpgZtC9AVga08ErIWwUjvTvvVZvNZcRS 5fJ1mXlalj1fcjYjL21IVmgOxfTIALuj0D41KvosDsgQ8wJlLy3e5hr2ZhEKhDoaPccX XtijbRmBcwh7V4EyYujFUnaV1CGFNSpxixV8ZFb+fRdyESh+KKFdvmDedjv5ACEVdmEq bPx+DS2eXGAV8/4ZpaLXcV/huphlDT8ssmFiB9mBq2fGwro19/Ax3cSLHLCnq0TTWzlf +Rv2TKdjVm/ve/g/22qzZ1N6ce2vsTo5R5hJUvU97CNm2aIrNZaF+XkmGOhKThX6RPkY CXAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=EvEkZF2r2AqggnLWTgwzPhL/JoYelLUDEL1aq/7CH+o=; fh=bbSjVJcsz6ma3Arirz+KWNos93PEC62yDVUDN8y6koA=; b=XckjZlrDjp0CglA5XHXkcLPelI37XQea4mPCEWd2NJp9mIHn3g5ACccOcBWAC5cUUV CFDfRnHPt7B3SZNA1KAX5BB7L8vYJ8tp0H1SItktejrwKy0jphiyo9SGzLJp3Get3Xhn IQ3KGaYLRpjYgH5dA4f5yyvIIKmeS6s5gVZ2IIPPSEtfUquCUA9Y1Hgev/yIRspuHFcv wzJq3NvMFTwxLjRTZrOZUIidqW8zRTD0iBekmsHbi5X9Su9O3v8YsWx9ta4KEkIokRie MtJ/RWKTqshF+nD2XNqQQuP/Q6+WwUcD7X4Xxo6h8XkxNl2yC106HIAb+1LNUCDfDCxA Ud7Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GNE6+d0O; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-378e7802933si2067758f8f.464.2024.09.16.02.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:59:24 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GNE6+d0O; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E91DE88F01; Mon, 16 Sep 2024 11:58:56 +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="GNE6+d0O"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3BD1A88EF8; Mon, 16 Sep 2024 11:58:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 D9D4988EDB for ; Mon, 16 Sep 2024 11:58:51 +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-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8d446adf6eso451331266b.2 for ; Mon, 16 Sep 2024 02:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480731; x=1727085531; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=EvEkZF2r2AqggnLWTgwzPhL/JoYelLUDEL1aq/7CH+o=; b=GNE6+d0OvUvq1QIEWPCNzG7UXgfCVWP4ycbLz2k7uY3D0v3BLCNDm1RxCIOHBrQ6zj rk2eFd5Gj1me41X2rXfokeiWJETX49+DZpsvkh9bCuTFkcpP+b5XMcR8/frPOggFFPbi 5XNcrYsWFagHBeT7Xo9XDgtSU6ODlDGeXYa3CazBB9NBor/11SywqIdv8kiWM0jwlXtd R5NzZHstc79HFXXUjAfURsAtBJ74R6oYNBD0ObPVBezMgp0IXXuBbn/CXIkPBgpjCty3 RRSR5K1B5kiQvLcgPi3c4M7Spy6Df5FF3evkAbHFD84wPFN9U8gDulhiJ6qwFTV8cesq y2Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480731; x=1727085531; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EvEkZF2r2AqggnLWTgwzPhL/JoYelLUDEL1aq/7CH+o=; b=Xe3Q087agOWyIm2TU2g5ChxwUTlaP6imN7Xsr0y3zeoXTa3nC8of6/dxuHn9caGNC7 Ipa7COHHHyBa/+VJQk5hT6C/9Wu5VVYap7DjFLHRy4HCedUX844C8UAXsv3Z83peQzaW S1GlE7OQPl5yQrg5rgDl23SYPdlVAMoSfo6xmmXGLDT9ygRaW63P+UiYB8lP4s+H0/SX NVCnboQxi/WjwbUL1IGPvYyEA3MIf4d9lZ+lHDi1ATE+m0N1nUYtwd4zuQil7HY7uO5P Kk4yCx905I8OoytdctIxFYBkAG69IkCKoWT0K0Tu9Qwzt04F9SFjyfWyZjDVuLr6NabD +SYg== X-Gm-Message-State: AOJu0YyDb5sN/PdB6oOBfkQatO8x3PQX83s2XgmU61icyEGrzN/bA7Jy ZjoSh0MN3rolMJv7BBHFVi9CpjKxk0kaOgh3jtdOUft5gSmyLqs4EfripgtcQE5pGIr5XT/bxOH b X-Received: by 2002:a17:907:f75a:b0:a86:a90f:3025 with SMTP id a640c23a62f3a-a90480ce2a2mr1108324766b.59.1726480730636; Mon, 16 Sep 2024 02:58:50 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:49 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:45 +0200 Subject: [PATCH v2 3/7] mtd: rawnand: brcmnand: Fix potential out-of-bounds access in oob write MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-3-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij , Florian Fainelli , Miquel Raynal X-Mailer: b4 0.14.0 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 From: William Zhang Backport of upstream Linux commit 5d53244186c9ac58cb88d76a0958ca55b83a15cd "mtd: rawnand: brcmnand: Fix potential out-of-bounds access in oob write" When the oob buffer length is not in multiple of words, the oob write function does out-of-bounds read on the oob source buffer at the last iteration. Fix that by always checking length limit on the oob buffer read and fill with 0xff when reaching the end of the buffer to the oob registers. Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20230706182909.79151-5-william.zhang@broadcom.com Signed-off-by: Linus Walleij Reviewed-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 46a4107a83a9..60d34bd21f53 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -1334,19 +1334,33 @@ static int write_oob_to_regs(struct brcmnand_controller *ctrl, int i, const u8 *oob, int sas, int sector_1k) { int tbytes = sas << sector_1k; - int j; + int j, k = 0; + u32 last = 0xffffffff; + u8 *plast = (u8 *)&last; /* Adjust OOB values for 1K sector size */ if (sector_1k && (i & 0x01)) tbytes = max(0, tbytes - (int)ctrl->max_oob); tbytes = min_t(int, tbytes, ctrl->max_oob); - for (j = 0; j < tbytes; j += 4) + /* + * tbytes may not be multiple of words. Make sure we don't read out of + * the boundary and stop at last word. + */ + for (j = 0; (j + 3) < tbytes; j += 4) oob_reg_write(ctrl, j, (oob[j + 0] << 24) | (oob[j + 1] << 16) | (oob[j + 2] << 8) | (oob[j + 3] << 0)); + + /* handle the remaing bytes */ + while (j < tbytes) + plast[k++] = oob[j++]; + + if (tbytes & 0x3) + oob_reg_write(ctrl, (tbytes & ~0x3), (__force u32)cpu_to_be32(last)); + return tbytes; } From patchwork Mon Sep 16 09:58:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829007 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699647wrb; Mon, 16 Sep 2024 02:59:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWFKNoETGZrplr7Qdf/3cYSLudfi2qUU/yQG4RBBjS6gVysOBwbn2NtcnxPzKUarYLwPjDiOQ==@linaro.org X-Google-Smtp-Source: AGHT+IHNmOJeE90umImAFNvOpBp0qV6iVYZVokjTofgHGtdwfVVDBwuXKU5RgWVzzIa13CHpnM5P X-Received: by 2002:adf:fe41:0:b0:374:c328:620a with SMTP id ffacd0b85a97d-378d61f0d5fmr7474501f8f.29.1726480775433; Mon, 16 Sep 2024 02:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480775; cv=none; d=google.com; s=arc-20240605; b=cd8SnDuMxjZJ67wqJLId4gBb2hkgYfxJ9CqeqpigW70sFZ0NzEgCPnr+Y4heNKutYq /QK6YNmqwg7PHvk3q4M2dgnMmSetG/goPIrN7VsQXECr4v3gVO+twtQWQu5vZDEDst/N BrEQXgxC3t6vRLhK8jPtO7XEZfUF/pU2Vcj9MqqXP0aODxNecVVR5hVNxSyFpeetmLkr /zBwPvP5aYVBxNZB0+74zdHsmRdkomqRAch9CwwI5yVGQeFwP90md9F7+DgYfl/PA1ov yvYiQC5A3efaAPwmnd9j+jZwEeTh6FZwcaURkxhAMcQdRN0MWTE+A8GD3ZLFqhHaI8b4 iizA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=yKuLdsLuyes8mnBA3MrU0R/rfIaNO+BeT5q0k2EEnh0=; fh=h9O78uwswjRVdW8Id1esrMzZoEr+njK1me6t0mcjnS0=; b=bTyLzIXo7mgjGhdopXIQX2F6gCKau+XziuCp0L+QNWDnBvwT09HYcPBag/iWxA6obz 94eviy2EaY2H5hP077MH71nvykuj9qmIm4ZqaF2VYcPTdinTs9qv+vtqLxD8vnjUoXZ1 OqrAxPG/td1S/TbXiFkdHV1VHkEc14Qx+o1X/SyPqFgBgoOrW6i5eVVVmePA+WncMLrD HcCIznpxrOyWPEySz1tpOXqZ/U+gyRJ5D14dqZvTqqIjxKh0Mzz7ICIWro0V2XXxV6US SMt4/DNJs0G7eP7f0rm38qizqUh9z+oPjO+ws+aJorji0o6Talh6ZfWzysFYFD0A2YpG i6PA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ODJGwLeH; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-378e781920esi2016868f8f.803.2024.09.16.02.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ODJGwLeH; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 46EC588F12; Mon, 16 Sep 2024 11:58:57 +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="ODJGwLeH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD88B8899C; Mon, 16 Sep 2024 11:58:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 65D8488EE1 for ; Mon, 16 Sep 2024 11:58:52 +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-wr1-x429.google.com with SMTP id ffacd0b85a97d-378c16a4d3eso3143126f8f.1 for ; Mon, 16 Sep 2024 02:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480732; x=1727085532; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yKuLdsLuyes8mnBA3MrU0R/rfIaNO+BeT5q0k2EEnh0=; b=ODJGwLeH2GhZHvTvHoqHC18ZsTeKGxrCGLKb7H3znKE56zxTHkY/mjaz8WHPDtWCT1 j1RZa/P80F3T3/KwRj/Rg/WWV10aPPo2CKVLKdawyLhkBSZvMq7rCWvSBcB0Wp8fFIpT bZW4xclBd6f5fU7zCyxC0BYx/1zZPYR0wYltjrDWdOTXKMLTdk+IqeolUgtLnmo5emHO ldwAu4LDGtipyBJoCS+n2TQZszcyC8mX/hIseVMcT1bOigamfEimEYS59un4zYfPaHLT dgL6P9pswaLs6Df6l/IVwYh2iUg/CAG7E/eUXZ3uhAZYt9hL1OW8WJ3iQ6s+igf4/xxY Ly9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480732; x=1727085532; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yKuLdsLuyes8mnBA3MrU0R/rfIaNO+BeT5q0k2EEnh0=; b=YLSSDxambd5CmLIqBH95q0yPvDtz61iGQ+ap+HKh5R5/almKNkKkPiE0iLZw3kAqo5 itt2ZxoH7pik1o9In2788nIgDMGnAHaAJP/GxZeLeKmkLuc6I8RjRF/wjO9IW+hCXZMl pzxxKcNXAssBma/PBbBs/XfU129Qn24zvC9HC9h37jGV8gGsZ4UlNXGD7Sjks986ogrx ZZDyiCEuF+OoTmH/q/g45cG9z/IvXIFFxYSbdV2GvCnB7zTt9ARE19tTlWcSIKj/+zdV 61KjJAdpXqmqR4kB6ol/YRCHKcybXyb/nsASXu/6wQ295mTQYqP1m2JKUCgkppZfKwhz 5/Iw== X-Gm-Message-State: AOJu0YwreoNUDd0hddzFmsh+YaNMUXW3u+kMSlT7VhK6VQpBye56Q72M nT8d/8xJvM9CzR0ICVgsRFQ3oisLtYTTJ2jx3XMYZQ4debep1UA/MooyJzjIyxQ= X-Received: by 2002:a5d:4585:0:b0:368:7f53:6b57 with SMTP id ffacd0b85a97d-378d61e282dmr8636146f8f.18.1726480731616; Mon, 16 Sep 2024 02:58:51 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:51 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:46 +0200 Subject: [PATCH v2 4/7] mtd: rawnand: brcmnand: Fix mtd oobsize MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-4-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij , Miquel Raynal X-Mailer: b4 0.14.0 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 From: William Zhang Backport from upstream Linux commit 60177390fa061c62d156f4a546e3efd90df3c183 "mtd: rawnand: brcmnand: Fix mtd oobsize" brcmnand controller can only access the flash spare area up to certain bytes based on the ECC level. It can be less than the actual flash spare area size. For example, for many NAND chip supporting ECC BCH-8, it has 226 bytes spare area. But controller can only uses 218 bytes. So brcmand driver overrides the mtd oobsize with the controller's accessible spare area size. When the nand base driver utilizes the nand_device object, it resets the oobsize back to the actual flash spare aprea size from nand_memory_organization structure and controller may not able to access all the oob area as mtd advises. This change fixes the issue by overriding the oobsize in the nand_memory_organization structure to the controller's accessible spare area size. Fixes: a7ab085d7c16 ("mtd: rawnand: Initialize the nand_device object") Signed-off-by: William Zhang Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20230706182909.79151-6-william.zhang@broadcom.com Signed-off-by: Linus Walleij Reviewed-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 60d34bd21f53..552b239b95ae 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -2304,6 +2305,8 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) { struct mtd_info *mtd = nand_to_mtd(&host->chip); struct nand_chip *chip = &host->chip; + struct nand_device *nanddev = mtd_to_nanddev(mtd); + struct nand_memory_organization *memorg = nanddev_get_memorg(nanddev); struct brcmnand_controller *ctrl = host->ctrl; struct brcmnand_cfg *cfg = &host->hwcfg; char msg[128]; @@ -2331,10 +2334,11 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) if (cfg->spare_area_size > ctrl->max_oob) cfg->spare_area_size = ctrl->max_oob; /* - * Set oobsize to be consistent with controller's spare_area_size, as - * the rest is inaccessible. + * Set mtd and memorg oobsize to be consistent with controller's + * spare_area_size, as the rest is inaccessible. */ mtd->oobsize = cfg->spare_area_size * (mtd->writesize >> FC_SHIFT); + memorg->oobsize = mtd->oobsize; cfg->device_size = mtd->size; cfg->block_size = mtd->erasesize; From patchwork Mon Sep 16 09:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829008 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699708wrb; Mon, 16 Sep 2024 02:59:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUsLqi113kpwOhroDlqaiSdh8cmidktpctSM/cpAX3EL3RruxHM9GRFO81DsSvBvZ3A85K6Nw==@linaro.org X-Google-Smtp-Source: AGHT+IEL+v174hEoohhdh6h/jm3bH6gq3WHkzdwJh1Md6iHNWzHlq6qsXyT3baYSwwHNmpOR3cp0 X-Received: by 2002:a05:6512:1106:b0:536:53dd:6584 with SMTP id 2adb3069b0e04-53678fc99aamr6939433e87.34.1726480785488; Mon, 16 Sep 2024 02:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480785; cv=none; d=google.com; s=arc-20240605; b=HjodOF22ap7izsDoRxk+1zdyIvZFrJzUHSki4/dhWeUNgWxL5p7wwAZfKxZ3WqJrJ5 GMH3mySYyzng39MbjrPs5KxB1rz+sPkrBeEppTmH6fPP1diIlMdOZc8ogQsNbIqrCcC9 wXqCB4mQpbyg0L08k6cJG7FjiPQ1nfaFLoouj8Yg+VHgFtuAP17VPW9mXXn40zll5hJY mDPaYPuiAT9BhXgIA/CZivEY7pe/Pve15qgMgS2N4JsR7WwG09P1dOEf+aJSOjt7ygsu bTRkgVms3/MrIlXwGMU2dp/nwD+MSwmPTKYrTjj8p8LV3onGVwXCFuYPPuTyvUWyCbSZ De5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Vqy6PVBHxWJx4+pP+WOa/qhGDCdQPicD1vpW1c3GTF4=; fh=ftQntzGq59ruF58t30aRXV87AbbvorkS2P8ZbONQbrM=; b=CFb9a+uD9ONBElXMzde8Dq+v1fhZypps/Ny80Ow66iVOCJX+BOHg8HrIVBpagU1dbA Mm8jzpwgOZ9sEsCfzkYanmisczAH4bJAtaOytFLvdxj6vuGHnc76vL4eZJXjmXbHkrvi rg+WoxbVzDFvhfQnuidBVkQLcGFXh6AykeyLPobOsCqC+jWz5tp5ui31doYpCMr8CWxx 6UJdn81HUgG0wKVA/FzdntU5FbFwz6sLAD4EY8BqWv0MiWdzuxVsTV3COgGgOKKl6AHB lbEUJTsKREcV41Ukxt9MEfhOZua9Cd/H+3sW75TbvVopRic1gbraS6JFnEpIGd5VPHaI ajIA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zEjZVp8J; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 5b1f17b1804b1-42d9b180d56si35156825e9.146.2024.09.16.02.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:59:45 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zEjZVp8J; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A4760889BD; Mon, 16 Sep 2024 11:59:00 +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="zEjZVp8J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 317C988EFA; Mon, 16 Sep 2024 11:59:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (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 75B6788EF4 for ; Mon, 16 Sep 2024 11:58:54 +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-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c3d209db94so5283061a12.3 for ; Mon, 16 Sep 2024 02:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480734; x=1727085534; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Vqy6PVBHxWJx4+pP+WOa/qhGDCdQPicD1vpW1c3GTF4=; b=zEjZVp8JPbbQ9dJffrI6vKB5GSeWawwFHnOvsqYYaIoSNHxISzhIvhBSkyTPJF+OMB /XgiPOBd70w5IM2Fy1g4foa5jCdLoKZc4afLDbJxnluZ7PvBqI8Mt07kn+0ZQRx8MBRo 2+UnWZzwulDrfYWWSnBpdhTf+YSdEc7fHgHwy73VU4ULpdM2unJVz//5CaprekMXwSWP IeQjum8FrJHLdJWCbeTFAJVjl3fbZvrUtt1r1E5jGH29ywZFWEzdQBL9NGK4GNwnI1kO fdJ4F1HbR3mekysD8kwbcgV69ycWuxZkDR5mehiBuziNpE5euO/Yy5/52FYm2T+h3m+S 2dag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480734; x=1727085534; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vqy6PVBHxWJx4+pP+WOa/qhGDCdQPicD1vpW1c3GTF4=; b=kVwqJ1Yt+aOQtaB/mhno9K6RGhgVq9eyzRUR8KJ5436FfY+EXnotr5thcy2pdwLgLy bp3yfpwZGqq4PlQ5ijrJ09rbSph6l854ivaTAs5ZvJbmqUbljfj88B6ahBxAvJ/rxgjm R6IQt65nX6xBun918e3tR4FgKKx/+gOi4CvQALd7KgfQt1IHBYXWeS1fs6pPdYScWKiK B3E15axDcuZP76fr3CslLnYMNZQVTmAsKPlWVcmmqhTvc22RzfvYfMFhIEgw09KcgA3h QFO5q8fngir/rvKokMIdKIK4P9ro7dzn5m/yvXrojOFGRu5oEINwjNs3i3Yf0NIQxul6 mTHw== X-Gm-Message-State: AOJu0YzWcqwXH21COnWO+ANZ+zO/qb3uxmDG06IDD6pCT3jICMrijD+N 7OmxX3LQjHHbgByWtNPk+iWl4gCqLetzVhWyHFbrGe0SARktIlgGznEloklhYWE= X-Received: by 2002:a17:907:9446:b0:a86:894e:cd09 with SMTP id a640c23a62f3a-a90293c4fe5mr1674501366b.9.1726480733719; Mon, 16 Sep 2024 02:58:53 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:52 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:47 +0200 Subject: [PATCH v2 5/7] mtd: rawnand: brcmnand: Add read data bus interface MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-5-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij X-Mailer: b4 0.14.0 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 This is a port of the read data bus interface from the Linux brcmnand driver, commit 546e425991205f59281e160a0d0daed47b7ca9b3 "mtd: rawnand: brcmnand: Add BCMBCA read data bus interface" This is needed for the BCMBCA RAW NAND driver. Signed-off-by: William Zhang Signed-off-by: Linus Walleij Reviewed-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 20 +++++++++++++++++--- drivers/mtd/nand/raw/brcmnand/brcmnand.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 552b239b95ae..2f786584a1ae 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -769,6 +769,20 @@ static inline void brcmnand_write_fc(struct brcmnand_controller *ctrl, __raw_writel(val, ctrl->nand_fc + word * 4); } +static inline void brcmnand_read_data_bus(struct brcmnand_controller *ctrl, + void __iomem *flash_cache, u32 *buffer, int fc_words) +{ + struct brcmnand_soc *soc = ctrl->soc; + int i; + + if (soc && soc->read_data_bus) { + soc->read_data_bus(soc, flash_cache, buffer, fc_words); + } else { + for (i = 0; i < fc_words; i++) + buffer[i] = brcmnand_read_fc(ctrl, i); + } +} + static void brcmnand_clear_ecc_addr(struct brcmnand_controller *ctrl) { @@ -1812,7 +1826,7 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, { struct brcmnand_host *host = nand_get_controller_data(chip); struct brcmnand_controller *ctrl = host->ctrl; - int i, j, ret = 0; + int i, ret = 0; brcmnand_clear_ecc_addr(ctrl); @@ -1825,8 +1839,8 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, if (likely(buf)) { brcmnand_soc_data_bus_prepare(ctrl->soc, false); - for (j = 0; j < FC_WORDS; j++, buf++) - *buf = brcmnand_read_fc(ctrl, j); + brcmnand_read_data_bus(ctrl, ctrl->nand_fc, buf, FC_WORDS); + buf += FC_WORDS; brcmnand_soc_data_bus_unprepare(ctrl->soc, false); } diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.h b/drivers/mtd/nand/raw/brcmnand/brcmnand.h index 6946a62b0679..3a1d60471361 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.h +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.h @@ -11,6 +11,8 @@ struct brcmnand_soc { void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en); void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare, bool is_param); + void (*read_data_bus)(struct brcmnand_soc *soc, void __iomem *flash_cache, + u32 *buffer, int fc_words); void *ctrl; }; From patchwork Mon Sep 16 09:58:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829009 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699755wrb; Mon, 16 Sep 2024 02:59:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVy1W1O8cWefUWfTNh8/Oao5mKwVin7y52MP6LS6mtANAyY4STkilt8H4WCMLHCTz/UezUt4Q==@linaro.org X-Google-Smtp-Source: AGHT+IGKDP7u5+tzfrdWARnEmrPM2+ogHZ+fFXNFEDh0sMe2rOaSxjkxuO1xYqQ9H3acoi1niX/2 X-Received: by 2002:a5d:50c5:0:b0:374:b35e:ea6c with SMTP id ffacd0b85a97d-378c2d515cemr7882586f8f.40.1726480795989; Mon, 16 Sep 2024 02:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480795; cv=none; d=google.com; s=arc-20240605; b=FSBcXfvmmJoOd5+GbgxAHqEiUkh1Wo+zXkTZ+6gXKbaFrBzBUohVdzHDAiuHr9sGrl XVq4pCXUv8GDpA01JpZpqaQP+RQWxjfRJkPHHF6oV+nXUPg22/wFlKQ9UkPTNfQoO162 P6zssV+5ddqxdBlcKjh1ORml//oKDnnMoOuIkzZAwinSSHaA8+X8/Ik447egVETH6/KL 9oCJVva3S+qkiufotTl0oc+bg0WgdpQIMxfxNwis0IN9D/clM/amPzbD33sSd5BOxnJm kLXroMg5oNGph43pomvkfh24pF82wGYZzY5vC0cpTTr5/75ZWH8uuxon3tILBIOESeUU XZmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=pwjIZKsumLweFU0kBnBpQNPYQFt5jGri6gUp/14tvEY=; fh=LjJWeawkcuYIe1gemXcY1RbqD239cYwgFjJpsG2gko4=; b=d3bDftMWdjfccy3dCLzexSJwHlDbwf5gNy+TS1Aj/vBfPuwdrirXAwWZdpo1Ey96zF 9Wf3gJ7YZdUcYL7vIhYUAcfJY1vPQNPHef0IANYIj7UWdkvaFGDtIRfscRdeA/mnv511 aZRxNT+lDzDn5e8mYkzPLggt7e7gsqzFmMaUAaEYGM9UJ8GncfAlbkUzCa2q0uFAGJYa g49CGOnlthkDMHSOQnl8kWhVaIcHiLkBMgoNWixJRVx8j8d8HN39+cG0a5UwK7YfGkii pWkwKg9odVQKiKBswhhS0zTvLiFkJlljNpxVt0eA91EJEUqXkSdLY3GzZPipulV+/8rU w2BQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dc1EZNuG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-378e7818285si2080782f8f.748.2024.09.16.02.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dc1EZNuG; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 05CD988EF8; Mon, 16 Sep 2024 11:59:01 +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="dc1EZNuG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6CFBF889BD; Mon, 16 Sep 2024 11:59:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (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 34C7F88EF8 for ; Mon, 16 Sep 2024 11:58:56 +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-ej1-x635.google.com with SMTP id a640c23a62f3a-a8d0d0aea3cso592456766b.3 for ; Mon, 16 Sep 2024 02:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480735; x=1727085535; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pwjIZKsumLweFU0kBnBpQNPYQFt5jGri6gUp/14tvEY=; b=dc1EZNuGfveTovVyDPX/8yl2k0sKbdlG7q7J5MxZ626xppmiwiQ9/df3yUNrZH/ZKc 09QiQjh4rdLELY/c3JRp5H+TzXeqgf2BXQX4vRo7hziu8e4X16noLMrq6rrapxE5TQaM SHDZiarme+Qm0Cau5DUWo63kPDlHlQSsPk6/t4mfCUGL3OJDopNve8CpNIpcOJ/uy4z9 /AW2cxU2SwPFHZtAAJPwspX6jDjSnGmz7IwMBXMxheON0kGOLUHlVdtYKfmQz+PvsQJ/ F0X5Iz9wo/PzkibaMrOCQeZqvNM37vBA8EZ0mCudQMl5kw1CRZlGtFV4kzqZg9cdanZH DQlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480735; x=1727085535; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pwjIZKsumLweFU0kBnBpQNPYQFt5jGri6gUp/14tvEY=; b=G430+qq4I+Tt9fJSyzV/mxc+wJnkjKAcyVLTdCR0trY58Q+tZ5djZF/dZ33xkBoOvr mYiIp5QrbsBd+xaxDrWTEjwPsV6cNJ7Kt21fN1hpEi3ct+MFt9NW513NGahA7ZYPoahJ PTvnDFd2UZjhMGVjPwEjJeSM4h1Fd1Qb2xayeSdq0ee+jvkwR3JxPCceKz+NORynVsxR ZyC45koLM2eEiXmkdjENcPkdRkc7l37AEoGiP/YlgGJCZKF8AgPPnJiMjgi4KCGvhI9d e5yFdIMl3J3+v+itG8BkhnkQkQSenfl0+yIDF1Tg6rONTCq9afihPg2vSRj9K6IrxAeH /ShA== X-Gm-Message-State: AOJu0YxFfJ2l8IddeFJ35qwq7/E3nru/XKt/P8gG8mO1+rTiJA71cuxU V3DhtJ0bzXJGZXzH2MMpVyBj95RbERxggAY+16UEi/1bbHNUW03nzjZuld6NsWA= X-Received: by 2002:a17:907:f783:b0:a77:e48d:bae with SMTP id a640c23a62f3a-a902949aec3mr1479023066b.28.1726480735528; Mon, 16 Sep 2024 02:58:55 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:54 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:48 +0200 Subject: [PATCH v2 6/7] mtd: rawnand: brcmnand: Support write protection setting from dts MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-6-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij , Florian Fainelli , Kamal Dasu , David Regan , Miquel Raynal X-Mailer: b4 0.14.0 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 From: William Zhang Backport of upstream Linux commit 8e7daa85641c9559c113f6b217bdc923397de77c "mtd: rawnand: brcmnand: Support write protection setting from dts" Augmented to also support the "write-protect" boolean property. The write protection feature is controlled by the module parameter wp_on with default set to enabled. But not all the board use this feature especially in BCMBCA broadband board. And module parameter is not sufficient as different board can have different option. Add a device tree property and allow this feature to be configured through the board dts on per board basis. Signed-off-by: William Zhang Reviewed-by: Florian Fainelli Reviewed-by: Kamal Dasu Reviewed-by: David Regan Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20240223034758.13753-14-william.zhang@broadcom.com Signed-off-by: Linus Walleij Reviewed-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 2f786584a1ae..071b33951648 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -2844,8 +2844,17 @@ int brcmnand_probe(struct udevice *dev, struct brcmnand_soc *soc) /* Disable XOR addressing */ brcmnand_rmw_reg(ctrl, BRCMNAND_CS_XOR, 0xff, 0, 0); + /* Check if the board connects the WP pin */ +#ifndef __UBOOT__ + if (of_property_read_bool(dn, "brcm,wp-not-connected")) +#else + if (dev_read_bool(ctrl->dev, "brcm,wp-not-connected")) +#endif /* __UBOOT__ */ + wp_on = 0; + /* Read the write-protect configuration in the device tree */ - wp_on = dev_read_u32_default(dev, "write-protect", wp_on); + if (dev_read_bool(ctrl->dev, "write-protect")) + wp_on = dev_read_u32_default(dev, "write-protect", wp_on); if (ctrl->features & BRCMNAND_HAS_WP) { /* Permanently disable write protection */ From patchwork Mon Sep 16 09:58:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 829010 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp699855wrb; Mon, 16 Sep 2024 03:00:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVZ+B5ZpDuYmZtJqgcF5ZMy6MhKmwso8FAquTesmzlMTQa67o5cnAhRmPq83+G5sbJjeWjuCw==@linaro.org X-Google-Smtp-Source: AGHT+IEEqXyNhbly/NaXy3aojsA3G3N9xoJehidyxcbQfFKw8DiASyIX47vjUMAvT4ajOO48rwfV X-Received: by 2002:adf:cd8b:0:b0:374:b5fc:68df with SMTP id ffacd0b85a97d-378d61d4f96mr5869974f8f.4.1726480808606; Mon, 16 Sep 2024 03:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726480808; cv=none; d=google.com; s=arc-20240605; b=g00G/hXzi4ri4mZq+sBInTSiWcplc2NDGuouo56iWKX1tBEd9Iy4rzyWwJKhd2e0/K UAVwoynLNcWo14sY5b/HI+sqfcIjKrfC+Dog7q3aXtC6Upg3uyKwugvhMdd+xIXLEJrQ XfaYJr8ci9E1RPbpUGmUFSM5epm1vDJT7kej+zCLONVuXRmVGP3DqwwCs4i+EcPOv3zr v2eidioBeu6RTYxWimW2oMqDUg+pOJfYQSj2xEGDYk6VG2CLKSSxNk1eD+e+AkkplGbO JFs096LhsjTNNCK+icG/A9+FuKi0f9xoG7F9qOogplcTs02Ka5RM/pofRH9X/XSwqp/D /lfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=qkiBDX/+saVsGPGZuKtDqACV/GhwNNMijBezP/1HGZI=; fh=YTnrfRIYLE/pT3cqoHvYay4qEd2auqJxcPFxhd6I1v4=; b=WPP/ru1v96piTDKO1gVUyurDH1fPA/Gx62ig24Th+n1t0cLlBpP0cmrLJBka62hGDX oBHHiF+wZhHOiM0eY4KqVk9eaoKI0AXqLpOJOSaAQtesDdy2WFXpUFXVpDh3yPQ0F7MH bkQiOeSRwa2fwq3cVpWoZJJG94ukAV3wPOQBHkNh7fe8NemTyFbc+frkYMUbK19DZy2Y D3/oqR0c4COXPQyD6IaYGcjOkdxXL45q1lNBIux3tA6U+4BL7NG7H8QuDg0Ykf6y2Rnt MhpezLDmlY2+LHpv/58Eb4thrHdOuQX7Nd0+g+3rhtTrteRqnhvYMsGpTcemfXD3cjPf sI5w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A5lpU3Qj; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-378e7819a21si2110825f8f.869.2024.09.16.03.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 03:00:08 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A5lpU3Qj; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 78DD588EFF; Mon, 16 Sep 2024 11:59:02 +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="A5lpU3Qj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D4B8888EF4; Mon, 16 Sep 2024 11:59:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) (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 90BE888F18 for ; Mon, 16 Sep 2024 11:58:57 +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-ej1-x636.google.com with SMTP id a640c23a62f3a-a8d446adf6eso451342266b.2 for ; Mon, 16 Sep 2024 02:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726480737; x=1727085537; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qkiBDX/+saVsGPGZuKtDqACV/GhwNNMijBezP/1HGZI=; b=A5lpU3Qj8Q8l/pGBg2sZhn2CeUqQvP+d3N750ttLv43saYazOKTPQB8rVHYBLz9yfh gH0Vl80U5LQ2H0e0ub2uN7PBYygnckGEmUHWGfD13cqRr64+ji+gKUpqj/+HzzYZftGt uzkl0IYVny+m5wUHps0gr5wqGuM5Q4+VRwdQVCE8K6w5jQ77vOjj7ZsVVuFq+pWGGpsl iQDgpOLoPyLcRc2l/mQ9iu5+p9UeoaiLHe35USFcMQiUUX9fEB4A2xx3f7F8b4cn6DGZ KpFlf9ZcINN0uOZXSDNmkt4vrd0HU2wcwk0b5pnNaFf2b0NgXH53FJW3CitNaTrlc4In j6/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726480737; x=1727085537; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qkiBDX/+saVsGPGZuKtDqACV/GhwNNMijBezP/1HGZI=; b=WQGrH4qJ0b8D2RrUGo0jv4Rhu936A+0bevy2R1uIX7WdNPRIaX9BMr0aU2IZGbBoSs o2ZlsbqwpOZnf4YmdegD1bAz4bHgDx5PbXQxQb8gtHgDr2cYhUAn7RnhV/Kd3o0mX+mZ NwUeM0ldlI1EP/tZNA2FKYQJd0l8tDnvQyNtwTXDJzBjFrsvNHp67fIOvjn2W0Sn2epP 46jIOZZRJLCvHPgljFCY2yXco9y1KcXbtxHElJIZRLgw+U2TT19V+6GF+PQ/YZ/SmOrI v0J5Vi2DKcJUNYr1QFXkh9mF5sWjYh75cgcpukteOj5FS4kBAfDVu1E6iRX9nJLvFsGT 0ICA== X-Gm-Message-State: AOJu0Yzt3+k44WvF3OMciRYGCIVeywuLKrJYeg/5Vgk2NWtgVHnIbKjg 6HztwBhK2ofkKOsGzvIBxygvs6ItNf30763cwc5n/5HW+mJV1q+ztVH4zyZYyLk= X-Received: by 2002:a17:907:60d1:b0:a77:c30c:341 with SMTP id a640c23a62f3a-a904758f269mr1141033566b.0.1726480736850; Mon, 16 Sep 2024 02:58:56 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a906109662fsm292862966b.38.2024.09.16.02.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 02:58:56 -0700 (PDT) From: Linus Walleij Date: Mon, 16 Sep 2024 11:58:49 +0200 Subject: [PATCH v2 7/7] mtd: rawnand: brcmnand: Add support for getting ecc setting from strap MIME-Version: 1.0 Message-Id: <20240916-brcmnand-fixes-v2-7-08632f64c8ec@linaro.org> References: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> In-Reply-To: <20240916-brcmnand-fixes-v2-0-08632f64c8ec@linaro.org> To: u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Anand Gore , William Zhang , Kursad Oney , Philippe Reynes Cc: Linus Walleij , David Regan , Miquel Raynal X-Mailer: b4 0.14.0 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 From: William Zhang Backport from the upstream Linux kernel commit c2cf7e25eb2a3c915a420fb8ceed8912add7f36c "mtd: rawnand: brcmnand: Add support for getting ecc setting from strap" Note: the upstream kernel introduces a new bool brcmnand_get_sector_size_1k() function because the int version in U-Boot has been removed in Linux. I kept the old int-returning version that is already in U-Boot as we depend on that in other code. 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 Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20240301173308.226004-1-william.zhang@broadcom.com Signed-off-by: Linus Walleij Reviewed-by: William Zhang Tested-by: William Zhang --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 70 ++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 071b33951648..749553c9df90 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -980,6 +980,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 ***********************************************************************/ @@ -2323,12 +2360,33 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) struct nand_memory_organization *memorg = nanddev_get_memorg(nanddev); struct brcmnand_controller *ctrl = host->ctrl; struct brcmnand_cfg *cfg = &host->hwcfg; - char msg[128]; u32 offs, tmp, oob_sector; + bool use_strap = false; + char msg[128]; int ret; memset(cfg, 0, sizeof(*cfg)); +#ifndef __UBOOT__ + use_strap = of_property_read_bool(nand_get_flash_node(chip), + "brcm,nand-ecc-use-strap"): +#else + use_strap = ofnode_read_bool(nand_get_flash_node(chip), + "brcm,nand-ecc-use-strap"); +#endif /* __UBOOT__ */ + /* + * 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); + #ifndef __UBOOT__ ret = of_property_read_u32(nand_get_flash_node(chip), "brcm,nand-oob-sector-size", @@ -2338,10 +2396,14 @@ static int brcmnand_setup_dev(struct brcmnand_host *host) "brcm,nand-oob-sector-size", &oob_sector); #endif /* __UBOOT__ */ + 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; }