From patchwork Wed Jul 20 16:22:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2209 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 446E13F046 for ; Wed, 20 Jul 2022 18:22:52 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id y21-20020a056402359500b0043adf65d1a0sf12361545edc.10 for ; Wed, 20 Jul 2022 09:22:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658334172; cv=pass; d=google.com; s=arc-20160816; b=x75FMGt1WoAmWMIT41s9yf73l/iY+ut2aFM5pgN7nk1CsJ34n89zUtYYF+k+myLa6v Pgi+yuHu3AKVgKO7cbZncWTDrBL7hwmdlKmJ+Rk2v96iP1DFpWe+l249ncB9DUSUJLYJ sg2H0HBD9yTIpWcTK/Y+A5tH9kMyi+juCMJ3Yi+3gV4foNHl+axrNZUC5UQsoks+/4oc x/iTYy2IvbGMfQOu908+ZNcyOeAExLzgFfiDd/pKO/UHGCDwWkOLwl0yJOdIWfWhJg0A dVD+dg1GXRyMe85eTN2schfZFHyCJot4RA/D4QaHqmTKOuQRZA96dvuT2colw1pswC0+ IQ1A== 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=Sd80JK/xrZ+p+7m3s3H4QZkYf6lDI9j4A97Oo3iY7sQ=; b=ghT4ABptq8xOd9kmdOKvShimewhvFH4/i+6Wz42rt4gYN9A+DKl+BQaCvsHiA+AbEE 38R0vLeAwbxXsGP2cuUeqJ0+VMtQatda602AqvDhPk2BtYmKb4wsmng/dAIoepSbWi1T FQ47ByzZvp6tCYkDiGj573w8jmnrBpjjfJzAnLoS+zkFDcTtl8oe699CVieonwD5c9Fm go9XB6jDGlE8ooPfQWYop9qAUt/AUSGFJqh5smqJOCbvMKoRlHzeORp6eo33ih5VhGnf Qrw0miIjEsobbbIB/jCklvVERRVyxmfESABlGFIbsey51tm01Um7jVP+9gnrjcYUF/Ik +XyA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Auv8/URB"; 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=Sd80JK/xrZ+p+7m3s3H4QZkYf6lDI9j4A97Oo3iY7sQ=; b=r5CHw+YxwSRKztE3jCmFZmkmzONK4G+/a67zMnmfEs0NmpuI12MA6UxWFG8cMl9E6l 5/TBuTNoHd4pXZWf/SOptJTqpGTGx1x2YtjawbKZ96ybPN8/QsktBoej5opI5xYeJW4h ZeLOwFI23WKnqdDNec0nMhcOQoOEHby+jP9dY= 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=Sd80JK/xrZ+p+7m3s3H4QZkYf6lDI9j4A97Oo3iY7sQ=; b=Grfh3+6xJP06OGGl6KvbJ//B8yy/wiYnDTJ7qjvShS15GHruMpPnfh9tWK8LaaTno7 K3aQ0wPOy1gKt4R7O9wdTyxpJ1PPUmOVdnaGbf3sGs7BV4q84p1weGk0s9nZEftTIVxJ zrDD7PClEtAcolirUqfBlbG1a6jAEKHACYf9dQP26uDMOr8KkPL9TVc6TbKWo08C2lxj tcbJwFUSGQBkLt/vJxh8K5r2i4Z4a1eN/gX011EyJvSVdGWcL1xrtYfAHQf8Xh39SQFi 15/cIXx2X5wyT6lm1olHfmgNdgaxeNw9I0MHmAS4/eSeNvwoR4EIDh4pNS/sZjSQCvEQ Axqg== X-Gm-Message-State: AJIora9/j7bjrLWuuwmUaNULrfL8nPi6dyZ4s7WU2lDtoC+57wKDTwux 78qaZUIcz5weBt3Bt8tqnCaHrzhJ X-Google-Smtp-Source: AGRyM1uNickpwNj6zWCEjWMj3aqML2Q2bQrxmp9cEUI99vg5iIDkgkP/oHCYfDzqIFq3OxO/bK3b7w== X-Received: by 2002:a17:907:2bc6:b0:72e:ceea:862b with SMTP id gv6-20020a1709072bc600b0072eceea862bmr33986404ejc.134.1658334172029; Wed, 20 Jul 2022 09:22:52 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:d0e:b0:425:ff69:1a2d with SMTP id eb14-20020a0564020d0e00b00425ff691a2dls257391edb.1.-pod-prod-gmail; Wed, 20 Jul 2022 09:22:51 -0700 (PDT) X-Received: by 2002:a05:6402:354b:b0:43b:bef0:5b67 with SMTP id f11-20020a056402354b00b0043bbef05b67mr1002355edd.357.1658334170986; Wed, 20 Jul 2022 09:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658334170; cv=none; d=google.com; s=arc-20160816; b=BuxZxR4I9lc8gg6ikf2I9JhO1PGXjTIEkKSlt+QLI/99BTrpj+27CETXcSwLGdqkpI tA/ubpg0TSOFa3+r3pFoO4XaxwaKp4RzCjt+7IGaA5GkhQjwIeQGZcZ8CL6Tqdeex2oE EfTaW5rMBQtrRVsdqQV8xvgBprMC5OILY9aSoqFTcrWO1jpCIXsI8RdKF1nxHwhQd23G 62L/Q3B297pYarcFPTi6+hSTlQmYXx2ez0URwUj3VIAI2OeO4nYbU2OsyWHfi10fh6Vc oNBTZeu8Uw+1O5WirtwBAaK6FpNqBW9fC1F6H8IrDqAZxk1eiCGYm6aV61qFKmUXQKRz nnpQ== 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=hv/HGYTpc1fWngwwSwxD9sfu6nEKm/f/x20cm+QuxFA=; b=z5xZ7ejlXpyXE1TxK0BXOW3vxMiTXDv4Fa+pSnjgE9Rh27Wj6UYk5CRT3Vxn1SVIw/ zauoaffK7Zy32RiZIiEbIzVmMeiAbCIkQhvRCh8RkVP5Ikwylx1bLlIfUd9HAob9K8S3 rC1iSovcEruTYcMqqM1sAcozNHRn+WCUxLd9mV/Zx1zacRhad+ogpTSkewp1CZx0/uSK qxYpSwevglTnWQwV5DPhO0VOAONjbLwr4KC/KNJR86uWerhHHbiBR+yW8/3Y4JPmWIRT 4VkKXp31fR/pz0UgzAAEdhYonIsWU90vJYt0E1dAHo2vUR+9EaRSiUKVQyn1UOdQ8bm0 qw9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Auv8/URB"; 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 10-20020a170906058a00b007033fef81a4sor6153258ejn.56.2022.07.20.09.22.50 for (Google Transport Security); Wed, 20 Jul 2022 09:22:50 -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:906:cc4a:b0:72b:863e:ef7c with SMTP id mm10-20020a170906cc4a00b0072b863eef7cmr35027814ejb.686.1658334170672; Wed, 20 Jul 2022 09:22:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 09:22:50 -0700 (PDT) From: Dario Binacchi To: michael@amarulasolutions.com Cc: Amarula patchwork , Dario Binacchi Subject: [PATCH v3 08/13] mtd: nand: Move Toshiba specific init/detection logic in nand_toshiba.c Date: Wed, 20 Jul 2022 18:22:11 +0200 Message-Id: <20220720162216.2397616-8-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="Auv8/URB"; 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 --- 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;