From patchwork Fri Jul 22 16:10:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2238 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 8B2213F047 for ; Fri, 22 Jul 2022 18:11:19 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id h15-20020a056402280f00b0043bd8412fe0sf286470ede.16 for ; Fri, 22 Jul 2022 09:11:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658506279; cv=pass; d=google.com; s=arc-20160816; b=Fbv35xoJLMib+Uww3KaRiv7wJYiOUkAARYOvIMDT9TR/SVAl8UJTG0jNzYzmur2Fol JIdG78vXP5vwvPhOFGhFQglGVhpI4hvhJmAQ3Og47co1i6AP1bFPXS9tR9OTP5C4CqEV j7F2g4evT0i9VNIPZaFMz/ED6XaBxKOGaOUszAp9SSGoiAJmFgSQv0Jd+3JYsPKlU1Cw WX5hV9TJOxG8oG+ZdeHUIM9l7Kic+G8jvr2CYWSUrqzfiCFykHhIgY0d8NXMIXUk9vfs xlotCvumNiv+xSIBPVG/9RE9gvmy3Nq/4brcd5wlnt7cIKiIq5KTCAdI7ncB00kkAzE4 Va0g== 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=ewGf6eOjiLTiCqAcH5LWvGQJpLhWabhte5dm7qE5oV8=; b=ZF5ZVGoMG1a8ndZSTSiHGRRB3rwD7IoXdNTJhuFouCe3WPrm8gFY1P8LTM0EC/JpKx 5/j/FkXV+3ApT+h9ln0TiWMgUL4Jr42mMT3jBSYZ/iY5xxafCLB/lhJnuqRYHYymQcq/ EKpOIUI1S6+UqcecDsOOzWm3lbe5jVhiHbzVwzZh+weIET3+i+2l8o2kLFit13adQr7l /d6FadBuza6SjTT0gH1q7erxSS9T/4GxU9rhaMXrN1spivE6m/QKdPPoCqp+V9H1s6qw 8r9WCJGzkRKDqXX7Krucn/4IRg6KkuZheiVY1knuqvpvPr5T8XzHa/IHrcKvGxeYUbC3 AhWA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=qZFlH+bs; 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=ewGf6eOjiLTiCqAcH5LWvGQJpLhWabhte5dm7qE5oV8=; b=mJJ2jGdWNGmK5DGFw7eYW7gy3w8lmbVR/+E+anws3K3ULhNddW4NQu8fdxM1qg1tUJ ZQnhT0VOnSMEULwSTrhr057z0izxOhSTPgFjYceSeLGr00DONT7oW7TQrg97TzqigcuG bpZuGTUHGIPDhgOc8BgXMrlOCy4Ec3qLYLht8= 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=ewGf6eOjiLTiCqAcH5LWvGQJpLhWabhte5dm7qE5oV8=; b=mj8FuGbxjAy6VOtqocZItyIfgFDVnf+agIPVHCvPCDS6VpKLnaoaST8KWFeKppGDTG 4H5MO/3g4s16JLyluMXRROGXgcd280nAQGd0P1wWQLCCq/xvW5Ljo46q+QWBFweyZyti QPDaCagZxFKe9Uwga/OU0VRoVm0CSr3WtP6HcBlIhE6eGD08iSsLQA2xK/T0u36TVXG/ 32JP2wN5Qs944pbBTZwcREAuHq91yS5MsZGTb5T0pgjtOEOxG6ilkSZxgCXgt53FwDzG 3b1YV688EmUpKrVljnvnZZjryIPbKJ/9VCC3mdKpiJBzSNc5GeVGJMdqUp7NNLXbk89R xlaw== X-Gm-Message-State: AJIora8NORkGapGqfihxg+Z2VJqwZb9CVSy/cKFMkzV5EDGA9ea4aLWO hrXhMY40D1SQUDONp6s3Kso2HFMn X-Google-Smtp-Source: AGRyM1tiIWV0dcxN6sht5wEEzCrb4NAMtfMxINLiVK5CUpIV4Dhjeg/9NjogNNIxsL1uvmyG3tyJWw== X-Received: by 2002:a17:907:94d0:b0:72f:269c:3aa3 with SMTP id dn16-20020a17090794d000b0072f269c3aa3mr443547ejc.695.1658506279365; Fri, 22 Jul 2022 09:11:19 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:6cf:b0:72f:5c1f:1852 with SMTP id v15-20020a17090606cf00b0072f5c1f1852ls3071955ejb.0.-pod-prod-gmail; Fri, 22 Jul 2022 09:11:18 -0700 (PDT) X-Received: by 2002:a17:907:9706:b0:72b:4b0d:86a2 with SMTP id jg6-20020a170907970600b0072b4b0d86a2mr484861ejc.242.1658506278176; Fri, 22 Jul 2022 09:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658506278; cv=none; d=google.com; s=arc-20160816; b=zSpLaROpHuxYQNsomHOgw2oso1FzsSSivwJs5e0S4dg4YweTeEvJUjOQ91R2wIQUr+ 4kiBz+jfkVJXUY87FD9TH5WvOcR6f8xML6oUzuWCnDG3Iyqv1JELFnznob/CV5AuU5F8 QTP5LK5Cc3uUgRj1zqIwng53m4WtzRBAkBE2H/Dm4lVSBNN+KHqgXtpMImRHTIKZdrb+ 951c435h5YqYJ9fixWzOGfX2+hRsvIAe/stgMskRimh4Iq6hvDPuLsBlb5iPwhxfcAQI EcQvFmi9L0yfj0A3fIDnTnnNWPXkEtn4W+d6RF/Jyq5oUDSrVe+bI8KM6SZSmAkFI6p/ RdKQ== 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=cSB0BpiXJDkvrgFoBXhS8Ii1tPQoOHvkzPEATYktly4=; b=OT+gYIF84nGgLlutjKxJSEbB+zEqc7PfQn3tFJYVIuXR5sby+VKPZBifDGmAm4N01N sjqwah3e3NoXd0C0YuVHVsgl0+NnKuk0dEHxTbsdUrFOGcWECNGU4KSZ8rgipBW7IG/6 L5APST6RpUgP+dZ/OaoNFjNVc73quBwQcOsvrhjmqoHQeKyYDZuosg/aVc6eqUpr/mPS mwwOZ2fUBLAJoPAxKWfYQ+3bjAdrRjEfT2oZVTpyriZONnoC45Q0/9mX0b7v5CdclHzC W69r3rXAuUxCX5fa2l61zig189N2sJHvoHsSNpIyILCefOljI1kJqZdKMj0IDqDLsRGw 4V/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=qZFlH+bs; 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 g27-20020a170906199b00b0072ae770fd83sor2233081ejd.38.2022.07.22.09.11.18 for (Google Transport Security); Fri, 22 Jul 2022 09:11:18 -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:970c:b0:72e:e972:5c73 with SMTP id jg12-20020a170907970c00b0072ee9725c73mr489754ejc.352.1658506277897; Fri, 22 Jul 2022 09:11:17 -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 d19-20020a170906305300b006fe8ac6bc69sm2174025ejd.140.2022.07.22.09.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:11:17 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Amarula patchwork , michael@amarulasolutions.com, Dario Binacchi , Patrice Chotard , Simon Glass , Wolfgang Denk Subject: [PATCH v4 09/14] mtd: nand: Move Toshiba specific init/detection logic in nand_toshiba.c Date: Fri, 22 Jul 2022 18:10:03 +0200 Message-Id: <20220722161009.2686504-10-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220722161009.2686504-1-dario.binacchi@amarulasolutions.com> References: <20220722161009.2686504-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=qZFlH+bs; 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 9b2d61f80b060c. Move Toshiba specific initialization and detection logic into nand_toshiba.c. This is part of the "separate vendor specific code from core" cleanup process. Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi --- (no changes since v3) 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_toshiba. drivers/mtd/nand/raw/Makefile | 3 +- drivers/mtd/nand/raw/nand_base.c | 21 ++---------- drivers/mtd/nand/raw/nand_ids.c | 2 +- drivers/mtd/nand/raw/nand_toshiba.c | 53 +++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 1 + 5 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_toshiba.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index 86d9b8e8beb8..16e0775395a2 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -14,7 +14,7 @@ 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_samsung.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.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) @@ -33,6 +33,7 @@ obj-y += nand_ecc.o obj-y += nand_base.o obj-y += nand_hynix.o obj-y += nand_samsung.o +obj-y += nand_toshiba.o obj-y += nand_timings.o endif # not spl diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 5698c1e6a229..4ea7f10a06fc 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4163,12 +4163,11 @@ static int nand_get_bits_per_cell(u8 cellinfo) void nand_decode_ext_id(struct nand_chip *chip) { struct mtd_info *mtd = &chip->mtd; - int extid, id_len; + int extid; /* The 3rd id byte holds MLC / multichip data */ chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); /* The 4th id byte is the important one */ extid = chip->id.data[3]; - id_len = chip->id.len; /* Calc pagesize */ mtd->writesize = 1024 << (extid & 0x03); @@ -4184,21 +4183,6 @@ void nand_decode_ext_id(struct nand_chip *chip) /* Get buswidth information */ if (extid & 0x1) chip->options |= NAND_BUSWIDTH_16; - - /* - * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per - * 512B page. For Toshiba SLC, we decode the 5th/6th byte as - * follows: - * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, - * 110b -> 24nm - * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC - */ - if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA && - nand_is_slc(chip) && - (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && - !(chip->id.data[4] & 0x80) /* !BENAND */) { - mtd->oobsize = 32 * mtd->writesize >> 9; - } } EXPORT_SYMBOL_GPL(nand_decode_ext_id); @@ -4289,8 +4273,7 @@ static void nand_decode_bbm_options(struct mtd_info *mtd, * AMD/Spansion, and Macronix. All others scan only the first page. */ if ((nand_is_slc(chip) && - (maf_id == NAND_MFR_TOSHIBA || - maf_id == NAND_MFR_AMD || + (maf_id == NAND_MFR_AMD || maf_id == NAND_MFR_MACRONIX)) || (mtd->writesize == 2048 && maf_id == NAND_MFR_MICRON)) 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 ec263a43279a..509652c8e26c 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -188,7 +188,7 @@ struct nand_flash_dev nand_flash_ids[] = { /* Manufacturer IDs */ struct nand_manufacturers nand_manuf_ids[] = { - {NAND_MFR_TOSHIBA, "Toshiba"}, + {NAND_MFR_TOSHIBA, "Toshiba", &toshiba_nand_manuf_ops}, {NAND_MFR_SAMSUNG, "Samsung", &samsung_nand_manuf_ops}, {NAND_MFR_FUJITSU, "Fujitsu"}, {NAND_MFR_NATIONAL, "National"}, diff --git a/drivers/mtd/nand/raw/nand_toshiba.c b/drivers/mtd/nand/raw/nand_toshiba.c new file mode 100644 index 000000000000..f7426fa59f51 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_toshiba.c @@ -0,0 +1,53 @@ +// 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 +#include + +static void toshiba_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + nand_decode_ext_id(chip); + + /* + * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per + * 512B page. For Toshiba SLC, we decode the 5th/6th byte as + * follows: + * - ID byte 6, bits[2:0]: 100b -> 43nm, 101b -> 32nm, + * 110b -> 24nm + * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC + */ + if (chip->id.len >= 6 && nand_is_slc(chip) && + (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && + !(chip->id.data[4] & 0x80) /* !BENAND */) + mtd->oobsize = 32 * mtd->writesize >> 9; +} + +static int toshiba_nand_init(struct nand_chip *chip) +{ + if (nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops toshiba_nand_manuf_ops = { + .detect = toshiba_nand_decode_id, + .init = toshiba_nand_init, +}; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index d35277d18799..73abb3401649 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1158,6 +1158,7 @@ struct nand_manufacturers { extern struct nand_flash_dev nand_flash_ids[]; extern struct nand_manufacturers nand_manuf_ids[]; +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;