From patchwork Sun Jan 15 19:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 642960 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp251341pvb; Sun, 15 Jan 2023 11:56:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXuuAVwZ9ezbAGA2Exwcfst2bmdg29pyP1ybcbiBS0FtGA9km/AB5a0WsNzrI+kFbYTaTGHl X-Received: by 2002:a05:6830:204e:b0:684:a327:589c with SMTP id f14-20020a056830204e00b00684a327589cmr10773767otp.6.1673812571354; Sun, 15 Jan 2023 11:56:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673812571; cv=none; d=google.com; s=arc-20160816; b=NHXd02USS0/ox00bVlakLsdV8NOR5Wh0BBdvB0gzHwpsT/vgej20KOSX++CR+n7K2m oCVysWkLPZgbBDTl5vwiNvRSQ8luYlqMNerhCBdcR84ZnlbX3QHhUJyvDu8jtiRZ/gm/ urV3YPUxJFkx7QRJ0M7RFlpJDt1ezR/IFjnXn4YCcqrrsg81nWu+wuhXkBKtnvWtkdAv 4GBWIGoeXjfEvusg5LdajKByskUulqYHZ3hG1ScF+zHSxELmYa07CPV80+nWPONhWgSF IlZkcPL+0ntcgNOwJ/g1V6vCwk9ufC8RNQ9mtT3+oH+UF9VUNqnoSsqxKxXLk0hx6dTh ifvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6BtRk0Ya7oo4tGMqcvjkrG5TrM/LbtGhSZTnDbiag+o=; b=WHsn9DdJoqrT7YL0KJJcSPs0ZSDS11rab9qjc5HFQkaRv4cyH2slgdeZYFGTwTGy+e oVitJUeiwrS7y5B9c2AMzE4IAIKbBDxFwTuUsE4DKl2KyNR6gnTv8Kcy0WQV1AfGlfN1 +3NfyV6uz6l551snwouvVmZlhuuRgaP+jFYCnoDPpJ+Yx46IyPCrJC7rRPPaj8izHgMT f8Rmyfdf2BjLJG17+vNL+HHPngT6QmAobTOtVqmYTiO+vVgSsZ6b0ghSh9UPjggWVfgv Z3FOaprE9brf8klS8sEVpl4Juo4ohxGK1pMXvH8/cT/KsBuDOaeP7gX1AY7bRRfOgTsm yU2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="E5V/fqir"; 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 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 cr12-20020a056830670c00b00637376f4c4bsi25947944otb.109.2023.01.15.11.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 11:56:11 -0800 (PST) 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="E5V/fqir"; 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 Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42AB0855D7; Sun, 15 Jan 2023 20:54:40 +0100 (CET) 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="E5V/fqir"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 10CD885592; Sun, 15 Jan 2023 20:53:56 +0100 (CET) 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-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) (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 019AB8559B for ; Sun, 15 Jan 2023 20:53:51 +0100 (CET) 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-x12e.google.com with SMTP id x40so6030245lfu.12 for ; Sun, 15 Jan 2023 11:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=6BtRk0Ya7oo4tGMqcvjkrG5TrM/LbtGhSZTnDbiag+o=; b=E5V/fqir75TM/nnM3Dr8U3RjWH58iFi+ms1sbadh0PGYicbYOex8tYfBI+MmpHxO6C 5clLJPrvCbXO7VxbqMpn7OB9UlZB184lWQPQGo6EXkkpe+uPqeoR4CmfEhj+qjAbMKnh 9Bt77xwWpW4T5s17I8uNxNvF6jvSjuJZ/NvUEo/ty5YWebhHFcyzixLy2/W06OpEd94M LFszJ8A34XLvYx2QG+j0JQUnv1vNRXi8fOV1miyyIUwx92Z4HtvnsP+y5mFalSvdAS1y cUe4kbT9BLTn+hXrsh3dY7Vo4PnJRQB913VVlq9STMDVJSm8Co6oZ4lkNuXd7Q/BwNFc gdLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=6BtRk0Ya7oo4tGMqcvjkrG5TrM/LbtGhSZTnDbiag+o=; b=FpDysbbzUDf/G2twOZM5IN/CcUVk7sU0xzHQtiteqGYmK4ZGZsIY9bfI++RXBjar47 IK3ju/uU9DDeBYRGMNn8sWLlv4ZdjntJa6zPFK1SZlTr7KUpvqPVB5quuqCzpzSs2mLX KheAHRLBAQpDbPHokANZP/Y2YlKwES0K7wlMScspKvb+OIJQbT9LniUFw8uaEoxEqJFt ynAHOfZP3Ern6tH5zAsogEAQOb+1ANOAeKJz8/mCKap3XIjVmXDZYsvaCAVYazPt2apg l0ASZ3AVTBG9dxgekpq+rWm2EbTsDSbWqyya37CxO8TzfB+TLOunT5pEbkT9hlw6BFdJ eXwA== X-Gm-Message-State: AFqh2kp/7IAlTmrMAXZQXXZVhs2QA/R33RS+X78Jb8Tgn7fHp+lrTI5O c9mfNW4xfBr8w7hEo+Ib0pwR2NnrnBSC8l8I X-Received: by 2002:a05:6512:90d:b0:4b5:b18b:8966 with SMTP id e13-20020a056512090d00b004b5b18b8966mr2056430lft.49.1673812431359; Sun, 15 Jan 2023 11:53:51 -0800 (PST) Received: from localhost.localdomain (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id r12-20020ac252ac000000b004aab0ca795csm4780439lfm.211.2023.01.15.11.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 11:53:50 -0800 (PST) From: Linus Walleij To: u-boot@lists.denx.de, Tom Rini Cc: Anand Gore , William Zhang , Kursad Oney , Joel Peshkin , Philippe Reynes , =?utf-8?q?=C3=81lvaro_Fer?= =?utf-8?q?n=C3=A1ndez_Rojas?= , Florian Fainelli , Miquel Raynal , Linus Walleij Subject: [PATCH 13/14] mtd: rawnand: brcmnand: support v2.1-v2.2 controllers Date: Sun, 15 Jan 2023 20:53:11 +0100 Message-Id: <20230115195312.1477845-14-linus.walleij@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230115195312.1477845-1-linus.walleij@linaro.org> References: <20230115195312.1477845-1-linus.walleij@linaro.org> MIME-Version: 1.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.6 at phobos.denx.de X-Virus-Status: Clean From: Álvaro Fernández Rojas v2.1: tested on Netgear DGND3700v1 (BCM6368) v2.2: tested on Netgear DGND3700v2 (BCM6362) Signed-off-by: Álvaro Fernández Rojas Acked-by: Florian Fainelli Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20200522121524.4161539-6-noltari@gmail.com [Ported to U-Boot from the Linux kernel] Signed-off-by: Linus Walleij --- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 85 +++++++++++++++++++++--- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c index 934981e2f3fe..2cca897ab3c9 100644 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c @@ -217,6 +217,7 @@ struct brcmnand_controller { const unsigned int *block_sizes; unsigned int max_page_size; const unsigned int *page_sizes; + unsigned int page_size_shift; unsigned int max_oob; u32 features; @@ -293,6 +294,36 @@ enum brcmnand_reg { BRCMNAND_FC_BASE, }; +/* BRCMNAND v2.1-v2.2 */ +static const u16 brcmnand_regs_v21[] = { + [BRCMNAND_CMD_START] = 0x04, + [BRCMNAND_CMD_EXT_ADDRESS] = 0x08, + [BRCMNAND_CMD_ADDRESS] = 0x0c, + [BRCMNAND_INTFC_STATUS] = 0x5c, + [BRCMNAND_CS_SELECT] = 0x14, + [BRCMNAND_CS_XOR] = 0x18, + [BRCMNAND_LL_OP] = 0, + [BRCMNAND_CS0_BASE] = 0x40, + [BRCMNAND_CS1_BASE] = 0, + [BRCMNAND_CORR_THRESHOLD] = 0, + [BRCMNAND_CORR_THRESHOLD_EXT] = 0, + [BRCMNAND_UNCORR_COUNT] = 0, + [BRCMNAND_CORR_COUNT] = 0, + [BRCMNAND_CORR_EXT_ADDR] = 0x60, + [BRCMNAND_CORR_ADDR] = 0x64, + [BRCMNAND_UNCORR_EXT_ADDR] = 0x68, + [BRCMNAND_UNCORR_ADDR] = 0x6c, + [BRCMNAND_SEMAPHORE] = 0x50, + [BRCMNAND_ID] = 0x54, + [BRCMNAND_ID_EXT] = 0, + [BRCMNAND_LL_RDATA] = 0, + [BRCMNAND_OOB_READ_BASE] = 0x20, + [BRCMNAND_OOB_READ_10_BASE] = 0, + [BRCMNAND_OOB_WRITE_BASE] = 0x30, + [BRCMNAND_OOB_WRITE_10_BASE] = 0, + [BRCMNAND_FC_BASE] = 0x200, +}; + /* BRCMNAND v3.3-v4.0 */ static const u16 brcmnand_regs_v33[] = { [BRCMNAND_CMD_START] = 0x04, @@ -491,6 +522,9 @@ enum { CFG_BUS_WIDTH = BIT(CFG_BUS_WIDTH_SHIFT), CFG_DEVICE_SIZE_SHIFT = 24, + /* Only for v2.1 */ + CFG_PAGE_SIZE_SHIFT_v2_1 = 30, + /* Only for pre-v7.1 (with no CFG_EXT register) */ CFG_PAGE_SIZE_SHIFT = 20, CFG_BLK_SIZE_SHIFT = 28, @@ -526,12 +560,16 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl) { static const unsigned int block_sizes_v6[] = { 8, 16, 128, 256, 512, 1024, 2048, 0 }; static const unsigned int block_sizes_v4[] = { 16, 128, 8, 512, 256, 1024, 2048, 0 }; + static const unsigned int block_sizes_v2_2[] = { 16, 128, 8, 512, 256, 0 }; + static const unsigned int block_sizes_v2_1[] = { 16, 128, 8, 512, 0 }; static const unsigned int page_sizes_v3_4[] = { 512, 2048, 4096, 8192, 0 }; + static const unsigned int page_sizes_v2_2[] = { 512, 2048, 4096, 0 }; + static const unsigned int page_sizes_v2_1[] = { 512, 2048, 0 }; ctrl->nand_version = nand_readreg(ctrl, 0) & 0xffff; - /* Only support v4.0+? */ - if (ctrl->nand_version < 0x0400) { + /* Only support v2.1+ */ + if (ctrl->nand_version < 0x0201) { dev_err(ctrl->dev, "version %#x not supported\n", ctrl->nand_version); return -ENODEV; @@ -548,6 +586,8 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl) ctrl->reg_offsets = brcmnand_regs_v50; else if (ctrl->nand_version >= 0x0303) ctrl->reg_offsets = brcmnand_regs_v33; + else if (ctrl->nand_version >= 0x0201) + ctrl->reg_offsets = brcmnand_regs_v21; /* Chip-select stride */ if (ctrl->nand_version >= 0x0701) @@ -573,14 +613,32 @@ static int brcmnand_revision_init(struct brcmnand_controller *ctrl) ctrl->max_page_size = 16 * 1024; ctrl->max_block_size = 2 * 1024 * 1024; } else { - ctrl->page_sizes = page_sizes_v3_4; + if (ctrl->nand_version >= 0x0304) + ctrl->page_sizes = page_sizes_v3_4; + else if (ctrl->nand_version >= 0x0202) + ctrl->page_sizes = page_sizes_v2_2; + else + ctrl->page_sizes = page_sizes_v2_1; + + if (ctrl->nand_version >= 0x0202) + ctrl->page_size_shift = CFG_PAGE_SIZE_SHIFT; + else + ctrl->page_size_shift = CFG_PAGE_SIZE_SHIFT_v2_1; + if (ctrl->nand_version >= 0x0600) ctrl->block_sizes = block_sizes_v6; - else + else if (ctrl->nand_version >= 0x0400) ctrl->block_sizes = block_sizes_v4; + else if (ctrl->nand_version >= 0x0202) + ctrl->block_sizes = block_sizes_v2_2; + else + ctrl->block_sizes = block_sizes_v2_1; if (ctrl->nand_version < 0x0400) { - ctrl->max_page_size = 4096; + if (ctrl->nand_version < 0x0202) + ctrl->max_page_size = 2048; + else + ctrl->max_page_size = 4096; ctrl->max_block_size = 512 * 1024; } } @@ -756,6 +814,9 @@ static void brcmnand_wr_corr_thresh(struct brcmnand_host *host, u8 val) enum brcmnand_reg reg = BRCMNAND_CORR_THRESHOLD; int cs = host->cs; + if (!ctrl->reg_offsets[reg]) + return; + if (ctrl->nand_version == 0x0702) bits = 7; else if (ctrl->nand_version >= 0x0600) @@ -814,8 +875,10 @@ static inline u32 brcmnand_spare_area_mask(struct brcmnand_controller *ctrl) return GENMASK(7, 0); else if (ctrl->nand_version >= 0x0600) return GENMASK(6, 0); - else + else if (ctrl->nand_version >= 0x0303) return GENMASK(5, 0); + else + return GENMASK(4, 0); } #define NAND_ACC_CONTROL_ECC_SHIFT 16 @@ -2201,7 +2264,7 @@ static int brcmnand_set_cfg(struct brcmnand_host *host, (!!(cfg->device_width == 16) << CFG_BUS_WIDTH_SHIFT) | (device_size << CFG_DEVICE_SIZE_SHIFT); if (cfg_offs == cfg_ext_offs) { - tmp |= (page_size << CFG_PAGE_SIZE_SHIFT) | + tmp |= (page_size << ctrl->page_size_shift) | (block_size << CFG_BLK_SIZE_SHIFT); nand_writereg(ctrl, cfg_offs, tmp); } else { @@ -2213,9 +2276,11 @@ static int brcmnand_set_cfg(struct brcmnand_host *host, tmp = nand_readreg(ctrl, acc_control_offs); tmp &= ~brcmnand_ecc_level_mask(ctrl); - tmp |= cfg->ecc_level << NAND_ACC_CONTROL_ECC_SHIFT; tmp &= ~brcmnand_spare_area_mask(ctrl); - tmp |= cfg->spare_area_size; + if (ctrl->nand_version >= 0x0302) { + tmp |= cfg->ecc_level << NAND_ACC_CONTROL_ECC_SHIFT; + tmp |= cfg->spare_area_size; + } nand_writereg(ctrl, acc_control_offs, tmp); brcmnand_set_sector_size_1k(host, cfg->sector_size_1k); @@ -2595,6 +2660,8 @@ const struct dev_pm_ops brcmnand_pm_ops = { EXPORT_SYMBOL_GPL(brcmnand_pm_ops); static const struct of_device_id brcmnand_of_match[] = { + { .compatible = "brcm,brcmnand-v2.1" }, + { .compatible = "brcm,brcmnand-v2.2" }, { .compatible = "brcm,brcmnand-v4.0" }, { .compatible = "brcm,brcmnand-v5.0" }, { .compatible = "brcm,brcmnand-v6.0" },