From patchwork Thu Jul 14 14:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2162 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 05AEB3F013 for ; Thu, 14 Jul 2022 16:02:39 +0200 (CEST) Received: by mail-wm1-f72.google.com with SMTP id h65-20020a1c2144000000b003a2cf5b5aabsf2692218wmh.8 for ; Thu, 14 Jul 2022 07:02:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807358; cv=pass; d=google.com; s=arc-20160816; b=seBsAqM3Bvt2xAH3lBT7tJd5pjZG55CMKwU/Fslub17QfmYsI76f77QIJ39GiR6LKs Um8yIOLeSKs6J3atP2BZw7b7i2+YVfnhF4vEynBKWL3j+GVVGjXQxdmD4kz/Q/lEwD7M X+pGE5D6hnYjh65eJXKkeKwytesV1jWeLHSTZyDJDFxzCNnpRW3Tx5FbCFent2SRv144 d/36ouo8QNYKhTl1D12xh3notY4+Ffr4oRn36gabyRuV0ZKZR8P6/RZhkx8jjiZtgP3h pK/cadyIhPpvjcLGb8TlXHweqgAWD7aONZ7UdNbMWJPdF+lrJUZfig80L25nvX6oiL7g DoqQ== 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=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=w8UOLF2TD/sTIlB91Ns2/304iVbrAhwaHkLmY0Lx/Yfh87fRhV9ClS8ApVk98rE4cf 9g3QsEYia+ScoXWgm5yaI2WZrQeLi2xbG7hGq6XIqlIKH/YljLfW16OykMC78pte7+Pb 8H7uE6FJF4prXD6pS44azxlw2Bl4e3hpxkopN59zAAxi815DIFvWPOKwgCe/e4Qva64r mwL+7MKBCDYElRHG+oh4fGL3dY3YTWX9Imxo9ZVfsW4wP5/SBm8t/EhWviijCAMDJYwe 2uJBDkKd0GV1V9fGKX4fVGBuYpaXP7zhCLoP7+dI7y1F1xcfgIKZqx4AQZ6LrnlSVPxT blaQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=efxgs6QV; 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=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=o6tjtzEUVvqJVT1D/4RDsYXrsHEpKwoBfzZ1l6JI4TAWN0YCcUiqJQKl0lGKdE1F0Y g9IMFLh+d1I7+Axf5BhckTxwGkMQcLH3G7glM4/Q6XYYCJSWmcLDajqpJurffN36X6ng mnH/4kVkHmE5i70PuoDAIMvpbxpK/twJxjIJs= 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=vmVx0z3Ubo58SrdMiS1PVaibssXAk6ZsNS2GtJ/YPc4=; b=gv2uCQZxiMoHeq5zS4V121QBnEcy83u8TeVjTibwYdNcQrNo+5+AszcOvNbmwm4kiF O3zcWQAKwqQrgbgCR2EsbbuyFQ5zIsFzVvK6Y3Xz+MXzv3lJ01/MkbgfcLulI9Jxfhwo +GfbNU+ZawZenKYYnWAgAHVLUgi/o0O9orAbeepyZ4wMOh181123tCusywdKRGB6/Gul ACcs/wy2cMjsmA/TUpB7Jn5gzHx9/qRhu31TOuqGNv+Ix+PnsB5wysP0WUzOrINpvqY1 P4V6kWhXUBss5//Rc5u0wv7tSt1gz+ZHSIkw+0+SkL9P/HzcHWE8TfqktMo6zcLQvfMe EwVw== X-Gm-Message-State: AJIora/pBiDjboNueZYvHVn+GjaNJf3k5Za6ddkGcpQnPeiS5tL/haOH to5tyDPUjs/x3UtGnwZBWRxGlYqP X-Google-Smtp-Source: AGRyM1uFen7uyM4pr3ySQVNanA9DUvTqzfCb3CZVIkpop0zVYjAdO2G0fzfEWdP4vTFCbC3/AzhRCg== X-Received: by 2002:a5d:468a:0:b0:21d:6dc8:9e60 with SMTP id u10-20020a5d468a000000b0021d6dc89e60mr8840899wrq.595.1657807358788; Thu, 14 Jul 2022 07:02:38 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls109309wrf.0.gmail; Thu, 14 Jul 2022 07:02:37 -0700 (PDT) X-Received: by 2002:a05:6000:1d1:b0:21d:6673:9894 with SMTP id t17-20020a05600001d100b0021d66739894mr8388279wrx.640.1657807357494; Thu, 14 Jul 2022 07:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807357; cv=none; d=google.com; s=arc-20160816; b=PjhSnkcq7GtefXREUMuyr0ryd5b/8WhuNQV+7PQLvhC9zgI86YjsEUxXPfE/YjeErO lxICNAux49R5wghhzBnNseLy+EVrdhgMdeATEjBvPSq6OdFogf/UrDUdc6QbE2WKR8mP TJMo4O18Bx01BwFI29lq9uf0GkVKRJavsOqFEZuhnfEWjBC8S6UA+u/FF8jD6YJkivuU lTZ+Jth8AkPOGXtN6JuLYKNIQvyIY8uJgA18l02gbgzSHGi6fp18KRBKPio7r6WZUF2g QLtyCrQoYa7//w7RWKX+q0Nt+45rHUIIbyoN8Gjn57e1yIQrtUThgl0C34KYpVSYjaOz wKDg== 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=bUAelgxhRmK6KYlzb4SR7SBVjPUr+bul0VwHLDW2c3U=; b=lycB4B6EbSeAYNC9Qvz8UnW2SCz7iFtO/TmPFk02f7J/7romGQDoELjBpWLK3xzLir uW0vvJnJP+uQza//rYaf/oj8HyyHUG75/ZI7S4ftjsgzsEAlNnNAcyfrS405X6bS+GE9 LMTlPwR6Dfl3simfRNIJAfF2FCYEWXRxjBakALhyngqBf019CL32D0EEmKNM0W3M3P+j X/HMunS7Ljj4DARIuPhAhIBNPzTPcHlPkXgLoylUdbMusLO3WOMcuVW4ZE6E5dL/2vtB utohJgF73Q0rdRSzsHad3lkjmKJqxhcXYgfAlgzWOH6ylKDvFI4PSIdiJLGBbAZQOP69 KK1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=efxgs6QV; 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 o3-20020a05600c060300b0039c348c0fa5sor480532wmm.22.2022.07.14.07.02.37 for (Google Transport Security); Thu, 14 Jul 2022 07:02:37 -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:a7b:cd84:0:b0:3a2:ddbe:220a with SMTP id y4-20020a7bcd84000000b003a2ddbe220amr9274664wmj.128.1657807356646; Thu, 14 Jul 2022 07:02:36 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:35 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 08/11] mtd: nand: Move Toshiba specific init/detection logic in nand_toshiba.c Date: Thu, 14 Jul 2022 16:02:12 +0200 Message-Id: <20220714140215.444993-9-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=efxgs6QV; 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 9b2d61f80b060ce3ea5af2a99e148b0b214932b2 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: Boris Brezillon Acked-by: Richard Weinberger Signed-off-by: Michael Trimarchi --- 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 294d131264..db608a2830 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 6ff1a2cb29..8c06b1c530 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); @@ -4290,8 +4274,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 ec263a4327..509652c8e2 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 0000000000..1ac80df651 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_toshiba.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 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 d35277d187..73abb34016 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;