From patchwork Thu Jul 14 14:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2176 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 134BE3F066 for ; Thu, 14 Jul 2022 16:36:25 +0200 (CEST) Received: by mail-wm1-f71.google.com with SMTP id r82-20020a1c4455000000b003a300020352sf135531wma.5 for ; Thu, 14 Jul 2022 07:36:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657809384; cv=pass; d=google.com; s=arc-20160816; b=Yr8zNbkP+H/kv0tIFIXNWrlRseXqeMpH2pAaj0TNCmlCLxlGu4i9KJZyf/ikeYcIJc DV/Ms/opd1BB5KVpXiMDg25I2L/MyZpDl9VvmL1kWTqs0P3nIyFVpsalEkyq2dQbjes5 ZlGsaH0ziFHWo9yMaHeQgLhRoXvQePodpf7gQcH59xiTWSjRhRHRXchFj65+9GmcXmvs CMsOXr97K+NI1o8CUZrtFuFeVIitPDCXX0qtLpdLfbamXap5qHZP2HxYfjr6USgGqcEd VRCxSFJf3Qc7Eoqd1aYa275qjcbFzavxN8/UZtIPbYW7tOz3Sh4pmVrDpICcv8hXQOBO J1RQ== 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:cc:to:from:dkim-signature; bh=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=h4YHBtZAYx+k5isSegxPG7tbRwoP6/20FRfal0spvalUcjlfiMV9DXaEf3ssXaCoB9 y81BL/GX8gDV9r8b0g+A4CyY+m40Kkp8ma/dUYj6lV7nDVd+0dPCgFStfisqv/yrM9q2 eXtPlsrIQ8ZzOQ8NcqEeTlR5eyKLGC4KpEl+lus1bTdaOLm+5hu8Uzd3ZNtAu4RaOxpw ger9ctCC6mOOHAmjoX+h50FhMcteCn6MeULb4KGKfVZU0/0V6jO+LedlgEkxeE/2QxNW gnIQgdOtMop1OH4S7wmmKwfU8xZZ2w+kgo/lF9PPZpF/itEnYl2qzjPGzty8fFeM5k8k f88Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kuZ2q7jz; 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:cc: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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=e6VpW3ecuuVj44pXtKVA7Yk54cq4TqwXQGyrnRZT+8Hg4+qLxd1H+9NwU5edIfKgPI Xzc2f3gfUfDZ5gHs9utjQgfXo+TBNhYRu5BCo8End5ZMfOGhh+yuqt4n0Z9EsD8MTK4+ utpZ/wx1/CS4H+zif5j/fNz1sYPR2igYUI0Cg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc: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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=Mdg/v076Q27izeO6aEQFRqA3nZGkBqFzggKSXzeUa4xxhadNzsrgWR8z+i0qD+gIEj JDvbmWYm8WmtYb7Q7g5i5SWLyNrG8kVcUaC0lMho/5WdCHaDXMdEiyjh1s88D9fXNbDc YHKStELLyrs0tKTzjV3k+UCbpQCR123WzbKaqkCk7DKTdjBeF7jN71gHepq5TMW4MbeE r15vnVS1U9z7Mh4wt/1wH6UbAjL7nKwzgghOCqDusZVNs9ts0GV7hqSEgnC//NRmhFrn pQL71zkBtZDv2Mwnuj5V9eKqMCl/Iy0KeNnXC9tx+Eb7oqRPVfII+QxUxAmaJuIJv5em VgOA== X-Gm-Message-State: AJIora9pM0GK98Oll9GCemno0U3kXfsf/L6xg9hV9VjXiNMp8bVUMPrV XQmM429U+s+LSTeh4OUjknUtsAwT X-Google-Smtp-Source: AGRyM1s+1wLpqGG77Iu0wLEoYcyyver3998XuF2v/A/FKz4UfurwTj4vbeSxbklQE5/UcceIm4baYw== X-Received: by 2002:a1c:4c0c:0:b0:3a2:ea68:cae7 with SMTP id z12-20020a1c4c0c000000b003a2ea68cae7mr9261339wmf.91.1657809384873; Thu, 14 Jul 2022 07:36:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:3b17:b0:3a0:2da0:3609 with SMTP id m23-20020a05600c3b1700b003a02da03609ls4512439wms.1.gmail; Thu, 14 Jul 2022 07:36:23 -0700 (PDT) X-Received: by 2002:a05:600c:4e01:b0:3a3:342:5f55 with SMTP id b1-20020a05600c4e0100b003a303425f55mr2440718wmq.150.1657809383699; Thu, 14 Jul 2022 07:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809383; cv=none; d=google.com; s=arc-20160816; b=Xb3hPsRIDDlR2j+58QkCKk+ht4MV6NBjX+ZFq5jlTI5o56UOWMhpG2MbtfyJ+/yhSq zEbasMeg3O/Q8etmSlepE/eas7Ypfn5XecpLYt0wqN6gKIuuPUDiFkXEW21Y7lD+OvrO ZvVS1Yt7xfuZ21bhRPkc3Ib1D854+zLe57WfjYnHu3Xwc7733WmbFkLStT6tipDXdPEM 7Yow9A3TBJg7WYeT52T+nXj9q7zX+LtWa1wwpBhcZ/XAFqWkZZZ6yoyv2QdY1Ma3hbLC dY03HCKZ+QiZuk6TNS+uDXe3RJ7nW1Hk0+mavjD4iTfIZ3m4MctkQQc9TVWFRcT7ATSj oRWg== 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:cc:to:from:dkim-signature; bh=5iCwJ3uyZDix/RxLRXQbAC9kUK2qutEG/TqbefHAYE4=; b=YClUfUrvL8K7j0iIe71oC+zGCAPmniQiLfW36aJ+rGjJMKy36mOSSxCiodXBrVYWWl /f+XgfBDHBVAkuefQw5DtHKu8OvLY2DMfGPHNuu6BFzc/aq1ZXOXGxsdqr0SPcvDNp2B qqCIgWcD8VZy7/Ivq8yTwnZDqKBdCWsYPuav/nkv1rD3I1+qb8XJGFJgSxNWAbiK/JVo O9Ho6bb2tRCWnQftpgiNBiS/m5R0Fj3YqEVf6yGR3ejvYUTju5qx/+kiaHOkspdzz+yw /dyBTCp8zR1NlCWd7i6lruI7maiBBWGGSN/wpfE6HYuvUd/O1wBmBxsgyzRaVQMeNmhS DbVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kuZ2q7jz; 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 w1-20020adfe041000000b0021d6c50028bsor873685wrh.60.2022.07.14.07.36.23 for (Google Transport Security); Thu, 14 Jul 2022 07:36:23 -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:a5d:47ab:0:b0:21d:b2b1:59b1 with SMTP id 11-20020a5d47ab000000b0021db2b159b1mr8371824wrb.99.1657809382991; Thu, 14 Jul 2022 07:36:22 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b003973c54bd69sm5712357wmq.1.2022.07.14.07.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:36:22 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai , Boris Brezillon , Richard Weinberger , Patrice Chotard , Wolfgang Denk , u-boot@lists.denx.de (open list) Cc: Boris Brezillon , Simon Glass , u-boot@lists.denx.de (open list) Subject: [PATCH 10/11] mtd: nand: Move AMD/Spansion specific init/detection logic in nand_amd.c Date: Thu, 14 Jul 2022 16:35:42 +0200 Message-Id: <20220714143543.448991-11-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714143543.448991-1-michael@amarulasolutions.com> References: <20220714143543.448991-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=kuZ2q7jz; 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 e8fb451076..e1d511c12c 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_TPL_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 d2079c73fb..f79e57b9fb 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4201,7 +4201,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; @@ -4209,19 +4208,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); - } } /* @@ -4246,8 +4232,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);