From patchwork Thu Jul 14 07:51:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2152 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 6F19A3F013 for ; Thu, 14 Jul 2022 09:51:58 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id s17-20020a056402521100b0043ade613038sf969598edd.17 for ; Thu, 14 Jul 2022 00:51:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657785118; cv=pass; d=google.com; s=arc-20160816; b=NVeDr8/NnOQlgRmd3fk7dJJPD/pOFwIyuas4t64TIN4ln3rgVm4ktIUuZi1HQ8vj8c P4jFKrCz7L7l039bcKByQHXerDRkqIZFQKilwtpSDOWDNInNUGC7BmLaiXJ+K2EFi4W6 annAQ75UoJ3jL2/8b6sSMxSJ5FeFp3sEXkqET8eX2UZzm8AA3KGAigvBiA9j1ARjrvbM vTcE4FwvGx1ZwnGOHflNtYs4Dol2VmAVPdZjDMUkDX6erigJ43UungtwOaiGAyKeAv8n Otb2EDu43GF4gOyHQ1FLgxdcYkV69RmY7IGdDgX2+MJYJF45SY4peavikWv4cXB5N8mM +qxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=gqT29FCCkJRcL4pI2o3Zjl0mgFzpTIepUGlxsujYces=; b=yp2bzUNAfNVKI/V8lWXnvlDa/zHc3kGqkPmBRB7aK9DmWCFIVfrnmoFoHl/Rid1XDp m//k6TveA9y4xT9wP44iA43oQ/UI49lzU45MQZTD/rCyhCR17UYXTz+37Ms+Np9d7lKN BUGoYOhRGHonR5HnNx490NWKIrxDBMkzGjL++rrkb/Mg+4oFIb+aJ/1HVyjfUznrLzZr U6v45DX1HnaBfVPdcbtfZL9XI4p4Ag1xSWUHf4w7ZPYSr24eU0dzpDM3D3yDfMq6v0yb J2pir0LGDyyWid4O73iCy3GKwag1fPoSF214QksSLmxxZNCdtQQqSE6aL6w1HPGjhgmC xbEw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=o7KrrUvm; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=gqT29FCCkJRcL4pI2o3Zjl0mgFzpTIepUGlxsujYces=; b=F1sxSP858v57ZLC+0ccr4o9WPggJKmsRel5OgC3iGbSyQ9UdlCZoHWRUwQA+F2eH2j IzeqNAPmbhN+EuKXnE36KEEq59vPq7W6U3W8QxYYvTlBZk5dhKikpPgLZTtd2fSgUIFc Q54IAM20SyOLO6/YYoqh23lfQ32cTArR5SWck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=gqT29FCCkJRcL4pI2o3Zjl0mgFzpTIepUGlxsujYces=; b=uAPsoyQ1fzNB4wijTyRq/+pAezFaDuqTrRmz02rAuAQ1EL65/5x7ub+vCJ/a4G5aOs jDomzTELEl2R9VHzDeGesXcjFFx5gGNMtA/xse98frKs4iEL6xAzUUP4L4KO6IfyPrj8 u2x/HXMNncvU4UZkpOOd1CYsX2fm0n4NEJcyA7wBCzVCW6lRJ87dGiZaFbQmnim7+hoo 19RsdMtAgEY2zP+5cu5KcTHqyOmji/OrkyTtVEd1vL44gaRdv/DEEy2SJeU0SEHhqsd8 AhvR9/VKIacLhmLPYyG3S/lPudG7/m7k84WwswjG8t/ZsU9kZbizkgvIrCDC8NNMlF1J 8lGg== X-Gm-Message-State: AJIora+g5646Wn2g18/4b6uuP+RoK/tXslBtnXNJV/dT3sJCqsCZHlM5 TFee2Mmt1nLXmPyf+IbcS7vDQM8B X-Google-Smtp-Source: AGRyM1t62Ev0+7NciFNomVCone/3Fes4N4r+DtWrkZrRb7dRi2WAwQiHM6VDnf08ylbhHz7QOk6JHg== X-Received: by 2002:a17:907:e90:b0:72b:d0a7:9dd5 with SMTP id ho16-20020a1709070e9000b0072bd0a79dd5mr6693885ejc.18.1657785118158; Thu, 14 Jul 2022 00:51:58 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:1c89:b0:72b:5b68:a7e with SMTP id nb9-20020a1709071c8900b0072b5b680a7els1730974ejc.1.gmail; Thu, 14 Jul 2022 00:51:57 -0700 (PDT) X-Received: by 2002:a17:906:974c:b0:72b:8cea:95c2 with SMTP id o12-20020a170906974c00b0072b8cea95c2mr7476877ejy.65.1657785116723; Thu, 14 Jul 2022 00:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657785116; cv=none; d=google.com; s=arc-20160816; b=bF0IKgvC+sZo53lgBy08CIsuyK0/Y00fnEqKK04ydozZFVXlkO6VZBJhrtG4Qep7d3 Q+iK1c7ORsuo/FVfMH3iPnP8DyzAS8JyoF7z4QrTUuiKmKCUraowSgtnuPtXoGw6uOIc wgBJGcXqrPIyEA5Q16itTkAp8MiezHxYUKpbhRnBf+44//ETElYGPZjm5yPVrqU0j28g eJFcIat0TLOdsiYW/QyRWitEXzoWxFl0HL5vwLheHzqFaIHdsF8JCQTYFgQHywx83Dlq ky/XIwmUjwSZ7rlP9t3sH8MdXjSfABuqb4F3ugH8R8//JkhkPjwmmyXT2ok9uEXjaQ+Y W/LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=c811TSPnRtdsguqzLEDKEgLrXxq7i3L2gV2EHdYemL4=; b=jGj12ZFx0ulW4arAPS4FSCua6gy83chnNGm2xlnTrk8jYTMUcGRfu4g2zygTJmMf1n obQ1XEtVfyJqJ0VDIlSh2OzTsPaNhJgLsq37vail226oZ0IH9ncP4888Jkgu+/IcGHyA Hs404zWMvvQ40tSupMSnc6uKQgLoDNuWkPD1XF30dWp9++YfR6z3KSpTq35VNYrKvGbZ AglubAHTK32MhaHw3Jm6sifehV/wNEiDBCjSirF1VRGCEVR6EJ+bXGOhZy1IQyAUwmcx mny0ZQgRJCk+QDNU/AeHkkoi5Mt8JrAImwuAwyM1jZ+YvnAtE8Uh0ciqmBkEP6wuXeeR GkGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=o7KrrUvm; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id yk19-20020a17090770d300b0072b8fc09908sor272473ejb.133.2022.07.14.00.51.56 for (Google Transport Security); Thu, 14 Jul 2022 00:51:56 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:2808:b0:72b:4d49:b2e9 with SMTP id eb8-20020a170907280800b0072b4d49b2e9mr7889053ejc.176.1657785116031; Thu, 14 Jul 2022 00:51:56 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id r23-20020a170906a21700b0072b616ade26sm369252ejy.216.2022.07.14.00.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 00:51:55 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 10/11] mtd: nand: Move AMD/Spansion specific init/detection logic in nand_amd.c Date: Thu, 14 Jul 2022 09:51:30 +0200 Message-Id: <20220714075131.411548-10-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714075131.411548-1-michael@amarulasolutions.com> References: <20220714075131.411548-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=o7KrrUvm; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Upstream commit 229204da53b31d576fcc1c93a33626943ea8202c Move AMD/Spansion specific initialization/detection logic into nand_amd.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/Makefile | 4 ++- drivers/mtd/nand/raw/nand_amd.c | 53 ++++++++++++++++++++++++++++++++ drivers/mtd/nand/raw/nand_base.c | 17 +--------- drivers/mtd/nand/raw/nand_ids.c | 2 +- include/linux/mtd/rawnand.h | 1 + 5 files changed, 59 insertions(+), 18 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_amd.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index bb20a04616..090bb413f7 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,8 @@ obj-$(CONFIG_SPL_NAND_DENALI) += denali_spl.o obj-$(CONFIG_SPL_NAND_SIMPLE) += nand_spl_simple.o obj-$(CONFIG_SPL_NAND_LOAD) += nand_spl_load.o obj-$(CONFIG_SPL_NAND_ECC) += nand_ecc.o -obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_micron.o nand_samsung.o nand_toshiba.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_amd.o nand_hynix.o nand_micron.o \ + nand_samsung.o nand_toshiba.o obj-$(CONFIG_SPL_NAND_IDENT) += nand_ids.o nand_timings.o obj-$(CONFIG_SPL_NAND_INIT) += nand.o ifeq ($(CONFIG_SPL_ENV_SUPPORT),y) @@ -31,6 +32,7 @@ obj-y += nand_ids.o obj-y += nand_util.o obj-y += nand_ecc.o obj-y += nand_base.o +obj-y += nand_amd.o obj-y += nand_hynix.o obj-y += nand_micron.o obj-y += nand_samsung.o diff --git a/drivers/mtd/nand/raw/nand_amd.c b/drivers/mtd/nand/raw/nand_amd.c new file mode 100644 index 0000000000..f11166f361 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_amd.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2017 Free Electrons + * Copyright (C) 2017 NextThing Co + * + * Author: Boris Brezillon + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +static void amd_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + nand_decode_ext_id(chip); + + /* + * Check for Spansion/AMD ID + repeating 5th, 6th byte since + * some Spansion chips have erasesize that conflicts with size + * listed in nand_ids table. + * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) + */ + if (chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 && + chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 && + mtd->writesize == 512) { + mtd->erasesize = 128 * 1024; + mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); + } +} + +static int amd_nand_init(struct nand_chip *chip) +{ + if (nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops amd_nand_manuf_ops = { + .detect = amd_nand_decode_id, + .init = amd_nand_init, +}; diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 9024948ded..baa7618923 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4193,7 +4193,6 @@ static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) { struct mtd_info *mtd = &chip->mtd; - int maf_id = chip->id.data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; @@ -4201,19 +4200,6 @@ static void nand_decode_id(struct nand_chip *chip, /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; - - /* - * Check for Spansion/AMD ID + repeating 5th, 6th byte since - * some Spansion chips have erasesize that conflicts with size - * listed in nand_ids table. - * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) - */ - if (maf_id == NAND_MFR_AMD && chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 - && chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 - && mtd->writesize == 512) { - mtd->erasesize = 128 * 1024; - mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); - } } /* @@ -4238,8 +4224,7 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * Micron devices with 2KiB pages and on SLC Samsung, Hynix, Toshiba, * AMD/Spansion, and Macronix. All others scan only the first page. */ - if (nand_is_slc(chip) && - (maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX)) + if (nand_is_slc(chip) && maf_id == NAND_MFR_MACRONIX) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; } diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index bb5ac8337f..c78f2e0880 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -196,7 +196,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_STMICRO, "ST Micro"}, {NAND_MFR_HYNIX, "Hynix", &hynix_nand_manuf_ops}, {NAND_MFR_MICRON, "Micron", µn_nand_manuf_ops}, - {NAND_MFR_AMD, "AMD/Spansion"}, + {NAND_MFR_AMD, "AMD/Spansion", &amd_nand_manuf_ops}, {NAND_MFR_MACRONIX, "Macronix"}, {NAND_MFR_EON, "Eon"}, {NAND_MFR_SANDISK, "SanDisk"}, diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index ec0f77b24b..bb1a359a9c 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1142,6 +1142,7 @@ extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops; extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; extern const struct nand_manufacturer_ops micron_nand_manuf_ops; +extern const struct nand_manufacturer_ops amd_nand_manuf_ops; int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);