From patchwork Thu Jul 14 07:51:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2150 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 79BC33F013 for ; Thu, 14 Jul 2022 09:51:53 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id m13-20020a056402430d00b0043ac2f27d83sf984501edc.20 for ; Thu, 14 Jul 2022 00:51:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657785113; cv=pass; d=google.com; s=arc-20160816; b=y4Q0dkcvUsfZBtGhpUq7HXiGiGY4hIV9UMo+IiKHe0olb5O0ISX7BOppLZBaEUKM93 K3+s9SF7/HobBW2slGDUdmx6DrpWunzA9Nx869sDAuhLP2b4h1eGKbYuZ3UMvEZtSz6G oYUXEhvBVmu3JUUBA04sCMRXR/ylboqntjod5XZurVK8uBifTsnCVrFCvhDiQePhLDPN uc09KuCO01FFUNU6cExSTXDtnoqfOR5YIsq7jiFWzm02ozvwnOI7NMqHXjfUrx3odKZa Hf7RpT6TkCnbcU26xmaMJp5U9DZyU7a8EBfLOub7zy+08ZuZoviYiE1HoZfW74reQ8bA GN1A== 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=5UlBYJvcxSJd72uwza9H7OPBTUq37ecz8UQhkVW70Uc=; b=f4+TwmtPBTVCtHN5STl7atKGEsCIzBEH86Iawc0OdGF7VRJbxGhl96EXvvHeZjp891 CwNqo+hitovu19UHtRJqJZp5OQKfjU+Y0dG3wmwcB9/RQ0sc+K22a+CfOQgRlZb2RIQE ZqMZxtH79Eysg3dWNK4IHqLq4QOA6wfVDKCAQ0lcAOMLdf7hbxhqmpVy6Pag1nOcYDSO xMs5+y7B9rPYWwtZhJN7ufFI1JfrLuyLCApbf3/Co/dMojivC//Hent4vIz2LIA0F9Yg yKkwtKvXZMa3MZc4lX7m/n4XGp9Q0Ei7jcK0gSl2IrZQ57z19FZK1SsmhYIXk7DnIqK6 5MGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=L+lk2DHl; 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=5UlBYJvcxSJd72uwza9H7OPBTUq37ecz8UQhkVW70Uc=; b=izd9GYYv00TlMWD5QZUrkJbAOFcH9tXKkBy0o6rsXfayb6uzGETdr1Rw8oZ7e1xZHj RLUXOgJM4pTEhzBYJ7JLZM1DFw4fsvVS8WsXEeIIEbfPgBtqzej7dKtHAzSI8Sx7WTtL TgQYqsDmKlFF+WrfcDG4WqYA7XIZ4Fey8FqrM= 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=5UlBYJvcxSJd72uwza9H7OPBTUq37ecz8UQhkVW70Uc=; b=GbuBoyfa4Uh3CurlAbx0EWtLreoxrPjh3/Qs/u1r0Fj45+PgCY1kH/K/iJ/0LY8Isd Q7sdAWjEGvBTc5Q00iBkm7stgjL1typZGBwvoHxJmgq5+ieLPIGYHWVHj8eP7CQ0usCP sdk0//9ECcVMDW1WwlShJnabRlMAavOfsSG4DlHlIdR/4KguUT1Sq8s+wqS+8/KOo8zI yljLuACAq7aAqXA1cyUblQNsNU7wyotH0d20ZtI1sPmIxLqvDlr+VmrVw+80nfuWDWfF SejpPhIYwj557xoCqtcscMGIYIs+AXwaSDnDZvXHrkkcUpxpAh4dhSm6sGiTlB/EEdFW BZKg== X-Gm-Message-State: AJIora+1wtIybTjlEsgPNfyIkNL2xvQ3YcNbEb5EoESwv5vZp6+acOqz V4/rhTpvUJuST2eenXNTd25saXtp X-Google-Smtp-Source: AGRyM1vqJHUp/dcXUIq5UtxGXA+KiOwo4dd9vf8NTWk0QyRHJyB0uXWYQl3jyvTcbBMUjJYB1e40Eg== X-Received: by 2002:a17:907:160a:b0:72b:51e0:d90b with SMTP id hb10-20020a170907160a00b0072b51e0d90bmr7146849ejc.609.1657785113332; Thu, 14 Jul 2022 00:51:53 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:95c1:b0:6ff:45d:c05d with SMTP id n1-20020a17090695c100b006ff045dc05dls4167332ejy.5.gmail; Thu, 14 Jul 2022 00:51:52 -0700 (PDT) X-Received: by 2002:a17:907:6287:b0:6e1:6ac:c769 with SMTP id nd7-20020a170907628700b006e106acc769mr7646609ejc.388.1657785112045; Thu, 14 Jul 2022 00:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657785112; cv=none; d=google.com; s=arc-20160816; b=CN1vSa7Y3HJbaZKaSs1UgVBm84jLshppmCVfzlXk51Gjjqdk55hQs4kB1yS7OlrWm5 hz/jkRb6VAq/nB6woZfj4NyHNR4dDG+7uKPTidZgRcabNNxn/pPjBWm/be6AfiG3Ozf7 cqhGO5ImiVLVp6Eu3pKmdt762+H+rzBx6VjBdb4OFzKrELeSsZbUEfdNHQ2miIybC50o 88QfDofum/F6CEuD+njc8JsUmZm4bZaNDugKEd9CHgkO9f4ulnOR+nwYypYBhoaijcxn ojagpWS9lT/YCYEPxHYQ+J24IC7vYMCl174pDCFOfDv7ez2ff07SD6P5RORV+pr/YXrV XfIw== 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=7WJQ34WHiB9ZcLkc6WULNrMmO5gkck6lDeSVwV+13/E=; b=opxhq/Z50je313vMPyL9nZw47+6VEeV4TO2gBwkhVuT+I2WCBRdJUF8t7zbfa/d4Fd /WAtLkOxD+NNUGqYFkglTyc7x98XkUgjwIPrwegF3F1x5xAMogtAEQ9NW3VxwGgb9vYM JtE8Rff0o23ShYHJY7QfGDt77vHxJWMaRdSylV13zjFzGJjl8eu0Nzu9eJviCiGkFvaX IKc7O/uG56K5zAsCb606yk/AlIhgmloqnGPw6kMs7V9XEuwHxNDFa7CX1j7ZUvUd1JBY k8oTmfW099RxFhEI/AjCF+Jj1GFioGTRulmP6JWRLnng6aZeD0l3zelGAgNbSx93Y371 MpuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=L+lk2DHl; 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 a12-20020a50858c000000b00437bf0baa39sor445872edh.27.2022.07.14.00.51.52 for (Google Transport Security); Thu, 14 Jul 2022 00:51:52 -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:6402:35cf:b0:43a:d139:ea2b with SMTP id z15-20020a05640235cf00b0043ad139ea2bmr10455468edc.415.1657785111326; Thu, 14 Jul 2022 00:51:51 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id r23-20020a170906a21700b0072b616ade26sm369252ejy.216.2022.07.14.00.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 00:51:50 -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 09:51:28 +0200 Message-Id: <20220714075131.411548-8-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714075131.411548-1-michael@amarulasolutions.com> References: <20220714075131.411548-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=L+lk2DHl; 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 d6ba111ab2..2eb08c1a9f 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_SPL_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 da22cf6e79..c5a5c22b12 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4155,12 +4155,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); @@ -4176,21 +4175,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); @@ -4282,8 +4266,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;