From patchwork Thu Jul 14 14:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2164 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 90E7F3F013 for ; Thu, 14 Jul 2022 16:02:44 +0200 (CEST) Received: by mail-wr1-f70.google.com with SMTP id v23-20020adfa1d7000000b0021d620f5ef3sf579824wrv.16 for ; Thu, 14 Jul 2022 07:02:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807364; cv=pass; d=google.com; s=arc-20160816; b=h1dkwHxRgDbIwtfEI0gz70+l9PC8lkdhgKmh9bxG8tOqY44xoXuPf5rL2P1CsvpPdZ Jk8mK74irehhk0fUU0XzX6TShA3zLvPQnP6zOjjneGQ0Rgw9TT1pOPP2Em8eMvS+7wmb pTjGG5He3jqE98axbNSWEC2wV2zQ5rEWsMpyW2f+LleMwgasOx+TVkzGfld70pVfYMw5 xRiFTpSb4U0pisMd0heQAIoqNScdy//9Tjjujt2W6ukkYNZKnaaPQbrT0j2ViUzubno/ r9MftZhwLjmpbM40poyyBvUn/FRfW6GzfElgA5YQDc47oZ76dBnki1MmtYrgURS7PO15 B5gg== 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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=f6QIBFVjGIV4+0z+DsmLqSCw+5WSosQ+8CuMbAECk2f8oLpiFwB7yE7G0vh8haeW3w /zIBJqy9k0xF7E5oir1yrfHykRjJM4/G86DDYCo9UuqNfCWmHElZHBobg7IdDE8M9AwX BdwnfO0HZ7TToA7HhCaoFDN5zLLUnSzAstKhRHqCgp8YPK8m6pF41BZV/0xLXPYw5Qcf bpuC6NAOcIFSENRC1CR47Q1ahU2EEvqbcKxqrezoXf5eDY46Px30GzC+Fi/zsFIeIyGe F7Xt7bJfVSQg9mh+4IgeNON0U78mbE8d+zmonJvut2DAXLPlOUdgcn6M8NAb+J4XDHWm 1+RQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RB9h6GGo; 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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=FHVv7gUMlfAmgl156805XCG8DOqZ21NpR/4y8CZ3noY9F3uuYffNywF8HDBY9kdqKF +20CgznhOnumHIopy6kqVu+Tcb17aIz04iQWfEPwC9aNqxlwOOlVyvfjOi894QcfzH7p tP9Q2CYcl/z22M4/9JK7Nwj3wl5canDZsKCxg= 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=aTsW0CwIALv70v5/D0Y2fIhQt8rFfUEfGVmcgty5HDg=; b=0rEJ5J2MlPPj66nMzk3AO+ZHjtM8HAoKkKw9sjuKA/TYxlpvj432fMVbPgrJeqWUyG N1Le2J8GtlE80OAIn+3bAf+6Ym8Ce2ENmusAskvGr8sngKmX4kQpck1hDswLnyec4liC eqcC0TH6TNZpag4EngDolxeMAKlChh8UDSI/4X9YUDUJ5PPu24BZjXy2HAtPRIt+yrKu zORAdK3EGXaL4twEemCbN6TlsUuwj8b+ju7Ti9y4JrqWsem35eFycmrhADAAlh23Ugw5 bduNGmiPLL7dRTu1uMAKwXPWaFqMPZWnKuQaA1vVyemIrR00Yv7UeeqkENxayfywSyEo 9RoA== X-Gm-Message-State: AJIora9IEb2C/YlE8N3n5LkJBWJjlOh4RtGspLJ1krjpmp5ibGt4R5Da t9Uhwlv4ZRz1FkmQvU7byAdwxZda X-Google-Smtp-Source: AGRyM1sNr7MU/KjOxdN4dMxZxGAzNIQAvfip0vVeppTkYWkQb4+Numiezc1T5OsWQToj0h3OauvHxQ== X-Received: by 2002:a05:6000:1883:b0:205:c0cb:33c6 with SMTP id a3-20020a056000188300b00205c0cb33c6mr8675963wri.39.1657807364359; Thu, 14 Jul 2022 07:02:44 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:600c:1da7:b0:3a0:3b20:d119 with SMTP id p39-20020a05600c1da700b003a03b20d119ls21010274wms.1.canary-gmail; Thu, 14 Jul 2022 07:02:42 -0700 (PDT) X-Received: by 2002:a1c:4c0c:0:b0:3a2:ea68:cae7 with SMTP id z12-20020a1c4c0c000000b003a2ea68cae7mr9100264wmf.91.1657807362664; Thu, 14 Jul 2022 07:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807362; cv=none; d=google.com; s=arc-20160816; b=bk7++9Tdk8X7YjYVwmf5hufXjxDh266cGABlzMLmDAwwr2t1XRceZt3JI0J68xYRnG IHJTsI9S7pUB2f/oSY8+HR9Ml04kE3krCxZ6wAb6N1mmu5b8XdgIF9UJPYx3GMXrbh8c qKnZ1vk0SqlFyykhUVMhBjUsI5XkGzToF7MlFaNs7VymGHUVVhM6so9P/xrO4ZBDS4eO 91HIgjKyGgk7NhwDYLkrshT6SeFMuj6sqwn1TiZNTnnULfx4rj1B1LFFYqa9YBMfePXP EmtIcI+UGl1Yxwi7O/u592oIjuYY+ZiYRKKCfztLbJu/Gj7S6b20Jbz1H/5ETi4U/J9c ggMw== 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=5iCwJ3uyZDix/RxLRXQbAC9kUK2qutEG/TqbefHAYE4=; b=YrSQqqZpBPFkIRpreJa+uK/xtArcoL3uIkPZlMBE6QrC/MbLm5JCQ6YwthJOqegPOe hdOvzNDv6+AeTFGlEpNT4Wi7NVzh00kTpFz9baVhG0UZGHBLw6X/Yg//tjNBkjW9eTuq 6XRiB/AVKEJGIYezGr9BCafSLJKsOEVKRO/71EBPShLBwk5wG/LkGlW/TMRUKnAsr3IW jlpACVQeq5FQ7sdUlMBLS7msNyrwhnKiHCYdngmjiWvU+KDv3U4N1Erzo50KR7zoXZUw s6Lw98RLzqVjAyaoQTf0mHvmQ67q9WCHd3wMzO/0tLEAArxoSinRs8D93+LvyjkMgYRB QnCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RB9h6GGo; 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 i27-20020adfa51b000000b0021db6cb4fa1sor893567wrb.42.2022.07.14.07.02.42 for (Google Transport Security); Thu, 14 Jul 2022 07:02:42 -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:adf:f04e:0:b0:21d:6efc:8f9f with SMTP id t14-20020adff04e000000b0021d6efc8f9fmr8404897wro.308.1657807361946; Thu, 14 Jul 2022 07:02:41 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:41 -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 16:02:14 +0200 Message-Id: <20220714140215.444993-11-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-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=RB9h6GGo; 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);