From patchwork Thu Jul 14 07:51:22 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: 2144 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id C63253F013 for ; Thu, 14 Jul 2022 09:51:39 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id hs16-20020a1709073e9000b0072b73a28465sf422372ejc.17 for ; Thu, 14 Jul 2022 00:51:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657785099; cv=pass; d=google.com; s=arc-20160816; b=IgmoegOWQ64gSeCuwuJvp6AlNQehiE38lxt8zk3rS8lG4q8x0LFM1mjZDpIV09YhmS S/4psvengY2Dxla53Rk6zWlrXyav78CCRLIgdx1sYclr6nOkPd6j/B0CrEbfZC7kqGo8 l+Etildo4lskJzXW9R85Jrs/QhQyw+ulwT+bOJIl7EPl7l2OSSNbPCK/mpNiRFCKi/Dg PmnMITXmG1RI5ru49QsHNU0z6+rMyt34kgShmI0GxDfoJFcAnS35Scob083FGXb5aJlU gF+PsGKlUnfEMnCEkYOrTWjFswBhl0bFfNQSjZGGAjmQ2IDaO7O2bxWuFBLByQh/MnSp BExw== 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=zG6wjqM5pKhjIObcbq+1697BitA63oTxB0xoc3v5vjg=; b=bcBH3hfsxJWGhQNfuNiVWILhbnBeR6vJ++rQvXniGpkV/yFGDh9GyhL4l+/5Y55Qu0 gUYQS5ni4Kn+0rG5WdOS0P2Te0bgbTo1uhck21+/fM9h880RvFrHERXgszcIG4E5sHoM RJqsEaJJU8GWbfNwwWGjH2wu5UPbPZ9jToRx0RAlD9XqGCEsic7o8fDuQ5pDdOuKBTSm QskBTFS27xFcE0MQ6nm/CPg6WTFYl22VzAxVmC7jFIG7+N+BDHS9XHs34SfCaCKZHJjk GKJKUn3S3HTsdeavBnfYiO0YXgGqCL91sS4iZ0fvzLounJgyNp61L7xANbSDWb4f/QT+ WSzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=htSvhErT; 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=zG6wjqM5pKhjIObcbq+1697BitA63oTxB0xoc3v5vjg=; b=T/EVXIFUC+aQTc2uSNYwJFe9vYQf+CKNYn4LEXV1Jw3laXnsaN4aHQC/Lr4PjtlLHd YYSl6RR2dFJtn2PIa4zBkpL/0+MYEfcR3oS+Bvs++e38OFHwVfkxUjQXfA5gC/9ACZrn Rb/VbNeeyqIzUr4WnxOhbJ2Sgvl7nJ+d2TRys= 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=zG6wjqM5pKhjIObcbq+1697BitA63oTxB0xoc3v5vjg=; b=knI+K8Cm/cpXfMexDmVuCE9rD5Jrv+YzmFA1OtbkNOukl1OavY/kF+1nux46jPF1ut L3OVKAAjYf3sdndDqF4VdGoSS1y7jEogi2hM1rgC2wxdbLkWy0G9Lh+ovK54Pw1BfVoa bpUSi29hgpijWjCy19hXzHtKEj9HHmkn6qVsJ9akjBomREi9rLzdbiFfI4WAO/ixdl1Y bwmPRPck6/NT/oS1ezYm3vjDKGvIbgXpyIGIOcp2Wm0f0mmiMHEpWMl5HmoalbAIcWT7 ChF8zlqGalXyWcrZvEe3F/UW92QF4QBFtYRFqbpwAO2nmvQaZJPmUnLbbzvmvTWZLHoy qWFg== X-Gm-Message-State: AJIora83ebFVqwCUYG8Ovtk7e4Bv4U5QJTUiV0xCkKPKezR1dEfR1M+0 taMuQFE2hsECkoEt1G+k/36uE7ZJ X-Google-Smtp-Source: AGRyM1uUWiAajOd7qkOVJkD5v6Xy54lX87YVcGgZIQnBvXCjqjL9tLiivIzJNfD9DCbB3qGvdbN15A== X-Received: by 2002:a05:6402:248f:b0:43a:b89c:20e3 with SMTP id q15-20020a056402248f00b0043ab89c20e3mr10732527eda.335.1657785099437; Thu, 14 Jul 2022 00:51:39 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:35d5:b0:43a:7724:247e with SMTP id z21-20020a05640235d500b0043a7724247els186139edc.2.gmail; Thu, 14 Jul 2022 00:51:38 -0700 (PDT) X-Received: by 2002:a05:6402:2553:b0:43a:caa2:4956 with SMTP id l19-20020a056402255300b0043acaa24956mr10442277edb.406.1657785098061; Thu, 14 Jul 2022 00:51:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657785098; cv=none; d=google.com; s=arc-20160816; b=YjZntV1jEoyc/pKBX+GQMgS8f+GINknTeAPkyiwG0D8X0qQcKMs4KB2IG4toHdsYtz wMIjnJ3Q1t9iI0l8hH1y7OmZXWnr8BlLFzjpj1PSKLhBFZickjhSoVi8H64odpkk3NsP ek0/FEjmz9qpiVnI6t0Qz2ArJXw9SrFjFhrg8p92U1VfG1FHDURIg8b1fNCELTZn/t6D PJ9vP59e+R2Yn3dC8ga/rrRSqMlOLnQ/dwAkmSTHtWLISvLlephQZ4JrC3F5Qe6xnjSp IFC4EqGn6E+V2INvQt/EKrQAMb9BxCOD9mMzU8Pqr8OSddQkpQJM779KgJ8Zi1UMulNt uS9g== 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=Gv8SBLd9l2dLRbvszGJpHjk1PR74fLOlZSaAeCY0NBQ=; b=J6Tab+MMegvD1WXQH+X/W4SWAU9a2dyFzSeMKUGUcswHuJwOIdm0aNsLRvEs/83GQe s5L6UMycEUTA5UtZN/B3aF96C5v0tma/ASSh22bvXZaHcQ+n87PW1PoJ7ZwX5k3jo/nV 2iS2AwBToD+3f0q2SIOPD3unvNnNBqDyGALT/8woELbgwkB0eBZnmJ7C6xurszH99cxU Ty3ZorRbtVqb0M9Mvvj3G2Yyu15gI4/92ieUkS1gs+mWiFgLB/5Z9irSMg1cNknDrkUX zTtl3tBZSZyLsGhZRfStD3odnnOcUZBKQ0SqqAaKZyTYnEEe2bfZO4wQ6xoVx/JLaDRm Z/WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=htSvhErT; 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 dk4-20020a170906f0c400b0071d538ee4dfsor297183ejb.46.2022.07.14.00.51.38 for (Google Transport Security); Thu, 14 Jul 2022 00:51:38 -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:a17:907:948e:b0:72d:3fd2:5da0 with SMTP id dm14-20020a170907948e00b0072d3fd25da0mr5337596ejc.225.1657785097316; Thu, 14 Jul 2022 00:51:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 00:51:36 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 02/11] mtd: nand: Store nand ID in struct nand_chip Date: Thu, 14 Jul 2022 09:51:22 +0200 Message-Id: <20220714075131.411548-2-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=htSvhErT; 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 7f501f0a72036dc29ad9a53811474c393634b401 Store the NAND ID in struct nand_chip to avoid passing id_data and id_len as function parameters. Signed-off-by: Boris Brezillon Acked-by: Richard Weinberger Reviewed-by: Marek Vasut Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 54 ++++++++++++++++---------------- include/linux/mtd/rawnand.h | 15 +++++++++ 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 9244287b10..6e964275e5 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4152,16 +4152,14 @@ static int nand_get_bits_per_cell(u8 cellinfo) * chip. The rest of the parameters must be decoded according to generic or * manufacturer-specific "extended ID" decoding patterns. */ -static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, - u8 id_data[8]) +static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) { int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); + chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); /* The 4th id byte is the important one */ - extid = id_data[3]; - - id_len = nand_id_len(id_data, 8); + extid = chip->id.data[3]; + id_len = chip->id.len; /* * Field definitions are in the following datasheets: @@ -4172,8 +4170,8 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * Check for ID length, non-zero 6th byte, cell type, and Hynix/Samsung * ID to decide what to do. */ - if (id_len == 6 && id_data[0] == NAND_MFR_SAMSUNG && - !nand_is_slc(chip) && id_data[5] != 0x00) { + if (id_len == 6 && chip->id.data[0] == NAND_MFR_SAMSUNG && + !nand_is_slc(chip) && chip->id.data[5] != 0x00) { /* Calc pagesize */ mtd->writesize = 2048 << (extid & 0x03); extid >>= 2; @@ -4206,7 +4204,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, /* Calc blocksize */ mtd->erasesize = (128 * 1024) << (((extid >> 1) & 0x04) | (extid & 0x03)); - } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && + } else if (id_len == 6 && chip->id.data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4270,10 +4268,10 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * 110b -> 24nm * - ID byte 5, bit[7]: 1 -> BENAND, 0 -> raw SLC */ - if (id_len >= 6 && id_data[0] == NAND_MFR_TOSHIBA && + if (id_len >= 6 && chip->id.data[0] == NAND_MFR_TOSHIBA && nand_is_slc(chip) && - (id_data[5] & 0x7) == 0x6 /* 24nm */ && - !(id_data[4] & 0x80) /* !BENAND */) { + (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && + !(chip->id.data[4] & 0x80) /* !BENAND */) { mtd->oobsize = 32 * mtd->writesize >> 9; } @@ -4286,9 +4284,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, * the chip. */ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, - struct nand_flash_dev *type, u8 id_data[8]) + struct nand_flash_dev *type) { - int maf_id = id_data[0]; + int maf_id = chip->id.data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; @@ -4303,11 +4301,11 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, * listed in nand_ids table. * Data sheet (5 byte ID): Spansion S30ML-P ORNAND (p.39) */ - if (maf_id == NAND_MFR_AMD && id_data[4] != 0x00 && id_data[5] == 0x00 - && id_data[6] == 0x00 && id_data[7] == 0x00 + if (maf_id == NAND_MFR_AMD && chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 + && chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 && mtd->writesize == 512) { mtd->erasesize = 128 * 1024; - mtd->erasesize <<= ((id_data[3] & 0x03) << 1); + mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); } } @@ -4317,9 +4315,9 @@ static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, * page size, cell-type information). */ static void nand_decode_bbm_options(struct mtd_info *mtd, - struct nand_chip *chip, u8 id_data[8]) + struct nand_chip *chip) { - int maf_id = id_data[0]; + int maf_id = chip->id.data[0]; /* Set the bad block position */ if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) @@ -4354,14 +4352,14 @@ static inline bool is_full_id_nand(struct nand_flash_dev *type) } static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, - struct nand_flash_dev *type, u8 *id_data) + struct nand_flash_dev *type) { - if (!strncmp((char *)type->id, (char *)id_data, type->id_len)) { + if (!strncmp((char *)type->id, (char *)chip->id.data, type->id_len)) { mtd->writesize = type->pagesize; mtd->erasesize = type->erasesize; mtd->oobsize = type->oobsize; - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); + chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); chip->chipsize = (uint64_t)type->chipsize << 20; chip->options |= type->options; chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); @@ -4387,7 +4385,7 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, { int busw, ret; int maf_idx; - u8 id_data[8]; + u8 *id_data = chip->id.data; /* * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) @@ -4445,9 +4443,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, */ chip->options &= ~NAND_BUSWIDTH_16; + chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); + for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { - if (find_full_id_nand(mtd, chip, type, id_data)) + if (find_full_id_nand(mtd, chip, type)) goto ident_done; } else if (*dev_id == type->dev_id) { break; @@ -4475,9 +4475,9 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, if (!type->pagesize) { /* Decode parameters from extended ID */ - nand_decode_ext_id(mtd, chip, id_data); + nand_decode_ext_id(mtd, chip); } else { - nand_decode_id(mtd, chip, type, id_data); + nand_decode_id(mtd, chip, type); } /* Get chip options */ @@ -4515,7 +4515,7 @@ ident_done: return ERR_PTR(-EINVAL); } - nand_decode_bbm_options(mtd, chip, id_data); + nand_decode_bbm_options(mtd, chip); /* Calculate the address shift from the page size */ chip->page_shift = ffs(mtd->writesize) - 1; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 3417ca2a0d..f2c6a978cb 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -507,6 +507,19 @@ static inline void nand_hw_control_init(struct nand_hw_control *nfc) init_waitqueue_head(&nfc->wq); } +/* The maximum expected count of bytes in the NAND ID sequence */ +#define NAND_MAX_ID_LEN 8 + +/** + * struct nand_id - NAND id structure + * @data: buffer containing the id bytes. + * @len: ID length. + */ +struct nand_id { + u8 data[NAND_MAX_ID_LEN]; + int len; +}; + /** * struct nand_ecc_step_info - ECC step information of ECC engine * @stepsize: data bytes per ECC step @@ -888,6 +901,8 @@ nand_get_sdr_timings(const struct nand_data_interface *conf) struct nand_chip { struct mtd_info mtd; + struct nand_id id; + void __iomem *IO_ADDR_R; void __iomem *IO_ADDR_W;