From patchwork Thu Jul 14 14:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 2161 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id EFFEB3F013 for ; Thu, 14 Jul 2022 16:02:36 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id c126-20020a1c3584000000b003a02fa133cesf704033wma.2 for ; Thu, 14 Jul 2022 07:02:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807356; cv=pass; d=google.com; s=arc-20160816; b=lvRS8oUlqtsUHItOHCHqNgos0ZYeeHnakSyUkx4i2ei3+aF6Rn+PYAIM1Ett302XEY yyBE3ng9RrU8w1kmvOlZihaLCt1HixwuLO+QYNBXHtaGIZq3Fi6pZd6KSqBdDCyLubSf AvJsZdkMixszRBN97pWNuvkHSLJppbXi3/Toj6EjFLHPLVF6sy4n049NZvfGDEfNzvn5 eQ11V2uN3kX6QZwY9+t3wTqzNLNSPvX6EoFL4GxI1W6167esncaCXHgvlyoIQpSWxtgU kO/ddwZit26Hr862vetzThGTccKaousMG2xmHKvhcDkhNxqZDpSiI1h3ACy05i+z/qJv byCg== 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=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=Au5u4lGk9s5k0A5DQp5otQyVLd8wVS+CXSjiKgOLyy5Z3F10Ox+TTLzQrVQFiKZivM E8s3jJdocSR3xiyiW64gEc8f3I+iMKSNra3LxgZlJZSm8jaWaa/lPIwkLTdzUYtzbOOl 3KuJIhDgdPIGlR8gtRm84redDO63SKtRQ5kggJmHUoZbMSsQGIzvyzFXLzgK+GDz13P2 6LwFb/K7EAtY2OeIYnWfQznxkvvJWs1RjJea1EfUHb2icL8iC4WYKvXvXIPuJ4bG55OK 69wpa09vziaJ9NNLTd4YM5Mdg4E+20jfGG086eOAqtUlDiB8yg1Aw7sVuvYvyIAYHXrN qMLg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ltKrmqfT; 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=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=Ot5tslN+y1KdvCBDVmTe8OSBHKfqI3FvH5RDWC7mMsXqncIqXWtNZZ6EnjsY8r51OD cF1cc4xlHoZ+AEyxyF6KAy3JFDS4nuicBzp5+dIp4Soc5CrODnGXyY+SPDkXtfoLdpzT MaWzvIJ5LP9TicSWsiARHsvIVW4yrzQzsDz1E= 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=EkkmQpa/gOGWpfcQVthVXQX7eF8aki6qBJPMY4FnCyM=; b=8DAViXHvDKY2UJxEgiXKNqyuGnp56tU+Oh6TwrtEfLwMMCLiXjGwWJsAm4d3wElDZg vi2/yuFv5QlqDdCR0fIAqIUGo47heHJ0Ic0FqlNJS2aNVpncb4Fx5Xh27DLsKgz8ThLp g1IxvhK7ttI9Ukp7HxpVXE3D6zI+UBmP0nngzjAr0VQAptE+DR4nEy4M/0AJdAWUjscC 5DK+jTsrR/It3XbtVNl0GXg376DMSenbzAOYY3Z5nCZaEdhbb5PRJP5rtsQ3RcgceKfm Y/IjYgIHbm+cnMK/OtthczbFWTwlnalqgpmRHYEtUJ/Elt3zq/+y6cXobFb4Yfuy+ZvE V2JA== X-Gm-Message-State: AJIora/1DaQ3YAHfbKAGpOH7cr4fzVdk7q+Dbi+nWHKBwZCShu64Hj1n S+yRTA1+QnV+w92Uwd9Fbc95H/B/ X-Google-Smtp-Source: AGRyM1tTZhz3MWDO0w4T+Pq2UbziCerhF900Urr/WBc/ScAe2Y2GMGN6woFKrn/q8dcqGTBJstzvHg== X-Received: by 2002:a5d:634d:0:b0:21d:6789:3e4d with SMTP id b13-20020a5d634d000000b0021d67893e4dmr9041414wrw.321.1657807356757; Thu, 14 Jul 2022 07:02:36 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls109119wrf.0.gmail; Thu, 14 Jul 2022 07:02:35 -0700 (PDT) X-Received: by 2002:a05:6000:2ab:b0:21d:b410:5773 with SMTP id l11-20020a05600002ab00b0021db4105773mr8333211wry.381.1657807355566; Thu, 14 Jul 2022 07:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807355; cv=none; d=google.com; s=arc-20160816; b=MecbhosUxDdkmRhIaRhPODtPovSIfoqwkoyuqTAQb/pdOZdbrjZMWL0AVZEbNWSHCh g3LT6V5IbHPpZuqrCLmaOOkBMNaZ+PUFNmlZ/llr5TtRG20nFVecgIq47HrEw9c3NkZ7 pAZB5lhefczYLs1FTmiM47uVZK8nwh1TiPRnQY0vdMRc8tVT9vwdAr4FmYnr8olJJlUT hSFSYDBH3dwW2+ahxAJ8MgAWtSt0R/t3oC+QA2hGlU1fgCyhAQIfAlSCELiU9Y3bPOog 37XShXRe81ZBACqde0Z4oH2zfpDeqF5Voee/YBKCttnv+IPSEfuUO11cYmJXQMJAP7WF 3nww== 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=N+rtp8PN0e0YtZMlSR1nEf03YbvA1gjyB7LEkd9PWAo=; b=dGdH1XfOKWl3cxqaZAKonsNcss2qVF6gKszmaOGxH69WWDJkj6jaiZ5bR8XVQFd2px Ak7KsEB6PiEFJODf5wESYImnZoH4W3H1I3IP1ufFMBO3oDtTY6bYtZRlpcNGXKUEKCLF SRvcGYOQ1JzLEvjnSuFobZF78++hjPyqw4FPQuamXJ7Td/qheLkpcQCKww6LYSgMoSFi CLVRzOzME2S/HGJBvgSf3pgXA8NG5XHii2GoeCAek3psrzqhA9l70Y0TtDAfXA+gcQZt A9U3jL8Uej9EW7/rHRookzY59Dbicr9QQrhFGZe4eeHm4YvKPqUk/vkDid6b9sAg21iD I1Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ltKrmqfT; 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 o2-20020adfa102000000b0021d765472b4sor832878wro.66.2022.07.14.07.02.35 for (Google Transport Security); Thu, 14 Jul 2022 07:02:35 -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:a05:6000:88:b0:21d:691c:38d5 with SMTP id m8-20020a056000008800b0021d691c38d5mr8650086wrx.450.1657807354645; Thu, 14 Jul 2022 07:02:34 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:34 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 07/11] mtd: nand: Move Hynix specific init/detection logic in nand_hynix.c Date: Thu, 14 Jul 2022 16:02:11 +0200 Message-Id: <20220714140215.444993-8-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=ltKrmqfT; 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 01389b6bd2f4f7649cdbb4a99a15d9e0c05d6f8c Move Hynix specific initialization and detection logic into nand_hynix.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 | 117 ++++++++---------------------- drivers/mtd/nand/raw/nand_hynix.c | 86 ++++++++++++++++++++++ drivers/mtd/nand/raw/nand_ids.c | 2 +- include/linux/mtd/rawnand.h | 1 + 5 files changed, 121 insertions(+), 88 deletions(-) create mode 100644 drivers/mtd/nand/raw/nand_hynix.c diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index 0e3f017bf6..294d131264 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_samsung.o +obj-$(CONFIG_SPL_NAND_BASE) += nand_base.o nand_hynix.o nand_samsung.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 +31,7 @@ obj-y += nand_ids.o obj-y += nand_util.o obj-y += nand_ecc.o obj-y += nand_base.o +obj-y += nand_hynix.o obj-y += nand_samsung.o obj-y += nand_timings.o diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7f41395afe..6ff1a2cb29 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4170,85 +4170,34 @@ void nand_decode_ext_id(struct nand_chip *chip) extid = chip->id.data[3]; id_len = chip->id.len; + /* Calc pagesize */ + mtd->writesize = 1024 << (extid & 0x03); + extid >>= 2; + /* Calc oobsize */ + mtd->oobsize = (8 << (extid & 0x01)) * + (mtd->writesize >> 9); + extid >>= 2; + /* Calc blocksize. Blocksize is multiples of 64KiB */ + mtd->erasesize = (64 * 1024) << (extid & 0x03); + extid >>= 2; + /* Get buswidth information */ + /* Get buswidth information */ + if (extid & 0x1) + chip->options |= NAND_BUSWIDTH_16; + /* - * Field definitions are in the following datasheets: - * Old style (4,5 byte ID): Samsung K9GAG08U0M (p.32) - * Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) - * - * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung - * ID to decide what to do. + * 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_HYNIX && - !nand_is_slc(chip)) { - unsigned int tmp; - - /* Calc pagesize */ - mtd->writesize = 2048 << (extid & 0x03); - extid >>= 2; - /* Calc oobsize */ - switch (((extid >> 2) & 0x04) | (extid & 0x03)) { - case 0: - mtd->oobsize = 128; - break; - case 1: - mtd->oobsize = 224; - break; - case 2: - mtd->oobsize = 448; - break; - case 3: - mtd->oobsize = 64; - break; - case 4: - mtd->oobsize = 32; - break; - case 5: - mtd->oobsize = 16; - break; - default: - mtd->oobsize = 640; - break; - } - extid >>= 2; - /* Calc blocksize */ - tmp = ((extid >> 1) & 0x04) | (extid & 0x03); - if (tmp < 0x03) - mtd->erasesize = (128 * 1024) << tmp; - else if (tmp == 0x03) - mtd->erasesize = 768 * 1024; - else - mtd->erasesize = (64 * 1024) << tmp; - } else { - /* Calc pagesize */ - mtd->writesize = 1024 << (extid & 0x03); - extid >>= 2; - /* Calc oobsize */ - mtd->oobsize = (8 << (extid & 0x01)) * - (mtd->writesize >> 9); - extid >>= 2; - /* Calc blocksize. Blocksize is multiples of 64KiB */ - mtd->erasesize = (64 * 1024) << (extid & 0x03); - extid >>= 2; - /* Get buswidth information */ - /* 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; - } - + 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); @@ -4340,15 +4289,11 @@ 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_HYNIX) - chip->bbt_options |= NAND_BBT_SCANLASTPAGE; - else if ((nand_is_slc(chip) && - (maf_id == NAND_MFR_HYNIX || - maf_id == NAND_MFR_TOSHIBA || - maf_id == NAND_MFR_AMD || - maf_id == NAND_MFR_MACRONIX)) || - (mtd->writesize == 2048 && - maf_id == NAND_MFR_MICRON)) + if ((nand_is_slc(chip) && + (maf_id == NAND_MFR_TOSHIBA || + 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_hynix.c b/drivers/mtd/nand/raw/nand_hynix.c new file mode 100644 index 0000000000..a5b6a61507 --- /dev/null +++ b/drivers/mtd/nand/raw/nand_hynix.c @@ -0,0 +1,86 @@ +/* + * 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 hynix_nand_decode_id(struct nand_chip *chip) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + + /* Hynix MLC (6 byte ID): Hynix H27UBG8T2B (p.22) */ + if (chip->id.len == 6 && !nand_is_slc(chip)) { + u8 tmp, extid = chip->id.data[3]; + + /* Extract pagesize */ + mtd->writesize = 2048 << (extid & 0x03); + extid >>= 2; + + /* Extract oobsize */ + switch (((extid >> 2) & 0x4) | (extid & 0x3)) { + case 0: + mtd->oobsize = 128; + break; + case 1: + mtd->oobsize = 224; + break; + case 2: + mtd->oobsize = 448; + break; + case 3: + mtd->oobsize = 64; + break; + case 4: + mtd->oobsize = 32; + break; + case 5: + mtd->oobsize = 16; + break; + default: + mtd->oobsize = 640; + break; + } + + /* Extract blocksize */ + extid >>= 2; + tmp = ((extid >> 1) & 0x04) | (extid & 0x03); + if (tmp < 0x03) + mtd->erasesize = (128 * 1024) << tmp; + else if (tmp == 0x03) + mtd->erasesize = 768 * 1024; + else + mtd->erasesize = (64 * 1024) << tmp; + } else { + nand_decode_ext_id(chip); + } +} + +static int hynix_nand_init(struct nand_chip *chip) +{ + if (!nand_is_slc(chip)) + chip->bbt_options |= NAND_BBT_SCANLASTPAGE; + else + chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; + + return 0; +} + +const struct nand_manufacturer_ops hynix_nand_manuf_ops = { + .detect = hynix_nand_decode_id, + .init = hynix_nand_init, +}; diff --git a/drivers/mtd/nand/raw/nand_ids.c b/drivers/mtd/nand/raw/nand_ids.c index f4126c3a5a..ec263a4327 100644 --- a/drivers/mtd/nand/raw/nand_ids.c +++ b/drivers/mtd/nand/raw/nand_ids.c @@ -194,7 +194,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_NATIONAL, "National"}, {NAND_MFR_RENESAS, "Renesas"}, {NAND_MFR_STMICRO, "ST Micro"}, - {NAND_MFR_HYNIX, "Hynix"}, + {NAND_MFR_HYNIX, "Hynix", &hynix_nand_manuf_ops}, {NAND_MFR_MICRON, "Micron"}, {NAND_MFR_AMD, "AMD/Spansion"}, {NAND_MFR_MACRONIX, "Macronix"}, diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index d0312e924b..d35277d187 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1159,6 +1159,7 @@ extern struct nand_flash_dev nand_flash_ids[]; extern struct nand_manufacturers nand_manuf_ids[]; extern const struct nand_manufacturer_ops samsung_nand_manuf_ops; +extern const struct nand_manufacturer_ops hynix_nand_manuf_ops; int nand_default_bbt(struct mtd_info *mtd); int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);