From patchwork Wed Jul 20 16:22:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2211 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id CFD543F046 for ; Wed, 20 Jul 2022 18:22:58 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id w15-20020a056402268f00b0043ac600a6bcsf12272226edd.6 for ; Wed, 20 Jul 2022 09:22:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658334178; cv=pass; d=google.com; s=arc-20160816; b=GCT7GHusNmufrLRU/LYpd8NU0uNgTvWWC5YT2pTN+RpeyZKqGg0tCGsrscEOT1/QP7 /s4xpCbfp3ylibERcMu7LOtIRbdzt9squNP8Jb6rxbYJWss4Q2gr4S22aekwJR8yTZZ8 N5kvtuedtg1qCQbXXdHX8kQSzfqFTTZVv8LF5UVTh+MXSXXvjOS/PPHHb/dR9XxuKdoc K2/XebkAeJ1ecBk502/N9HVuuAFCDHZCVSwelBfh5MKzBhuoEZawarJAnRLNtyhbcHl1 5A/32yN1n8iv1a5LkvqVJZtmLQO+YSSz8DjhDWnVvgXyiLieRRPZCC1STeun2NKNtjTm CA7A== 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=aC9Od0hQPKauauCqSC3c5uqP4FcFRlH8O/UZ0hBxE54=; b=OSFHlvGrYznJVMSMwfHTvcJRe68mT3XeCGC9M9Ga7kaXxwaKver9y82et6Yhz9Ao7y Q/KpBNabuOjtCg+0MavVbt/2SC4b18T9PB5PEmG9CtY4pxNpnOcFG5oVBVMUZV1aPp0Q T5eCgFIuGerBpWryHuUbIm84CoDMs+zRgAqdL1kw/oxVL6lab2xQkXph7YRgQPxv1sPL 0ViR51y9hvy2JKhuzywrozZuSS6pWOdSCB5TIRf+4nLs/h6jBOsfWpiL8Fpo3nZIs/Fl Pc2UiPhKfaA9B+/kg8mXNuTrNkiWSYqAjJjhkjuNwIA+Bzb8O8bkF9xiFnvC0cys+QUH BAvQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=m393mXAl; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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=aC9Od0hQPKauauCqSC3c5uqP4FcFRlH8O/UZ0hBxE54=; b=o0ukHLNN1hCoilSthbcrLlaYS/OUQt2h0F3KvHi/Ttc07xyyvTmiDJqxsMsq5myOh6 DGZGPkMAeJp6K0hcqYmhYN8EAN192WXQ0Ezl8QO7Cq5nTNBFzpqfOqRzndWM2HjJRD+A 55fO/vXbgxONb1z4A2VvTWGmtLdNwlQkmV6d4= 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=aC9Od0hQPKauauCqSC3c5uqP4FcFRlH8O/UZ0hBxE54=; b=5y8q9uk2qT7lDAACDz/uArFrrWdKGw0BdC84X6pCtLd2F0UvYhxJkrMY4Cz4CydR/y VCI45Odw2bovFZrGQrcMMPEf43LKiQUAmZxLVF88brnC225y7XrYCIZSI2ITd4mezlaw CoWpgCJ3Xs7XPj9EcjbHZH9gjiFrpx07v8UCWX7nWO2ICQY8PDVNLFcMYmdaFY5k8YSA akmP9PE8EkLELgnvhxZ5FVi3N8uO/x7r5pbieojtAuttSGalDmC9j5nlCa+NwORuWN5I mM9DfXeHqiKqnSCASw/zUwPDQGujXeE7L0rpezjKCD7LLkacYr8+ZnelSTdKmJ0paZzk BtoA== X-Gm-Message-State: AJIora+QmCYt/Q0D4ZTkSETPAQWuM7PJ8rkb2d/7XxhqCu/KvpwxRr/L d5fMhuHdGgud81nxsD/ArV8LsVYM X-Google-Smtp-Source: AGRyM1shoqBpHgdUy8MUx55UKYwjHqSPJjyizKMFQBzhUE7P+6d/HruWFtaSvrsviFlLTLyeBKmdBQ== X-Received: by 2002:a05:6402:1e8c:b0:43a:c57f:2cbb with SMTP id f12-20020a0564021e8c00b0043ac57f2cbbmr52868479edf.97.1658334178663; Wed, 20 Jul 2022 09:22:58 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:7082:b0:6fe:b664:4b5f with SMTP id b2-20020a170906708200b006feb6644b5fls376074ejk.2.-pod-prod-gmail; Wed, 20 Jul 2022 09:22:57 -0700 (PDT) X-Received: by 2002:a17:907:9606:b0:72f:826d:21b4 with SMTP id gb6-20020a170907960600b0072f826d21b4mr1547961ejc.510.1658334177606; Wed, 20 Jul 2022 09:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658334177; cv=none; d=google.com; s=arc-20160816; b=AixfgjFv/HSqmEoVo99TyMUS0JeI16V68jtcGaE0vrmQyB/veSFoGzQn6ayAHJT3hO xmYkPSOsW0xBDvbGs/Zvcy9hIjXQ+CTML7L4aUE2g96WffSdET9KtLprE9x6GmCCm8kr K33GyrOjh7nubIhpkwbQoj3iZzMi9KIsFM6L9yZKsSI1R/Hr7YElCifYkhweYde5CmQ5 yap4C3p1q+7rJCzrSeVowaw/sIV44dbg4skeSslNyZBpLztjNK9vdRmttrAcD0o4YNi1 LWXtpNGrjJOcGm0zvabqhSZWzCWTmIsX6SlGttjGWvRcqUzVRZ9PWcpPcqIUmqR8Fm6k rwbA== 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=akcoLfp54cRGzdnwH5I05Wq5uAksGtC+cqjjY5zmIMY=; b=clAX0A9IYDtDOuoADZGXcOfV5kwgPTKz8lxKelLKVSxSee4XwNqK4nsGbycwC94Klv i01IXSgSzlqD83SrSCwozs1oV5nGF5vfI5eGh17H5L9GK8vbX10ZAtuDXkSVarGongk5 RgpaS+dEF7/RrZVb2CsSMD/zGVD4bmMomxfrbUL4D4t5IQsci0o4YYO2JkMyTKDMGc2i XiDpVjc49zB1rScFbtlt/CuT2hb3Wo1ZedeExGkRfIymMK6n1tV9OxkKdJyWkhcdbaJv ph7RdAaQV+mINB9OhE2KzoSP18ahhPbLRO4xQCVPHIpr3leGXIZkWJDsIqFOlxjn/IF4 YMrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=m393mXAl; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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 e27-20020a170906081b00b0072b616ac648sor6092247ejd.85.2022.07.20.09.22.57 for (Google Transport Security); Wed, 20 Jul 2022 09:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:907:1b16:b0:72b:8c16:dac0 with SMTP id mp22-20020a1709071b1600b0072b8c16dac0mr35135238ejc.286.1658334177307; Wed, 20 Jul 2022 09:22:57 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (host-87-14-98-67.retail.telecomitalia.it. [87.14.98.67]) by smtp.gmail.com with ESMTPSA id jl10-20020a17090775ca00b0072ed9efc9dfsm8057839ejc.48.2022.07.20.09.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 09:22:56 -0700 (PDT) From: Dario Binacchi To: michael@amarulasolutions.com Cc: Amarula patchwork , Dario Binacchi Subject: [PATCH v3 10/13] mtd: nand: Move AMD/Spansion specific init/detection logic in nand_amd.c Date: Wed, 20 Jul 2022 18:22:13 +0200 Message-Id: <20220720162216.2397616-10-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220720162216.2397616-1-dario.binacchi@amarulasolutions.com> References: <20220720162216.2397616-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=m393mXAl; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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: , From: Michael Trimarchi Upstream linux commit 229204da53b31d. 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: Michael Trimarchi Signed-off-by: Dario Binacchi --- Changes in v3: - Use commit sha1 with 13 digits. - Add the SPDX-License-Identifier tag. - Fix code style warnings raised by patman. Changes in v2: - Use short-commit form - Remove linux info. Uboot seems that backport without add this extra information. - Adjust the include file in nand_amd. drivers/mtd/nand/raw/Makefile | 4 ++- drivers/mtd/nand/raw/nand_amd.c | 52 ++++++++++++++++++++++++++++++++ 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, 58 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 8ef30b45fd2d..9c2ced9925d8 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 000000000000..e02b8c79dba2 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_amd.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * 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 + +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 fe7e049d4064..68e6f4f14347 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4200,7 +4200,6 @@ static int nand_manufacturer_init(struct nand_chip *chip) 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; @@ -4208,19 +4207,6 @@ static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) /* 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); - } } /* @@ -4245,8 +4231,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 bb5ac8337fde..c78f2e088040 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 ec0f77b24bd6..bb1a359a9c14 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);