From patchwork Thu Jul 14 14:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2156 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 80CBE3F013 for ; Thu, 14 Jul 2022 16:02:26 +0200 (CEST) Received: by mail-wr1-f72.google.com with SMTP id o1-20020adfba01000000b0021b90bd28d2sf576872wrg.14 for ; Thu, 14 Jul 2022 07:02:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807346; cv=pass; d=google.com; s=arc-20160816; b=ju1h4cYwu5NGAECcQcrrY1HH/mQ9FsQxpCiM20URNIfzxPpfV1NsiYprnSid1GNxTe JM0HAW27bhTkhGn35epiLfd1dZ/JIc5nLqumcbZ2iemQs3PcUpSk3yOWZc7/u8wnIOrW k14MMVF8km4EAORUp3W7a21JWABVAmAGu0j65mNJcgshz00WWvZs1nDjNtx9NcLS81+a X4Bo9vl+iduQ0N0B5rvf9+q9mbxVMtgn7++WFfQwedvww83Ipxw0NRDvWFlUup9XKH5m X+5I0kXCXgcsBg6NDZ1E92KdrRi7sOSeU1GZE3PU/OBz/8ElvWae98f+HKQoYTMMdwEm WLRg== 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=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=oYTkM4ouMvepgCl0n046FxCv6dHDRQgAwniLQhC92kP50fFcbeksoWl46q/ypT/+Y9 tEM9heW4k7Ahfk+BQUV3Zttse2VJOMSc0fPNsx676opFfxE+i7YKdLv06ZUp9ZCRNkMH Jm7MD3W516bazrME9v0D7cR3Im/75X4roQFPDik9lmNjAeCMbR3koYEfAPMJh+gdzwAM 23mRrKXWUN6/E/tny96e2Ig0XE0jeMSycccFta8jKLrYGTOq2FZnFrTO8V3SAzJ+71se NTcvMgJrWmiojRQchra83B3KBBW6TC3ubBGJd9SumuM38PIdnMqgyvQV3bSSjZnvYRU2 fU+w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kCJST0gT; 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=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=oA7O46+icsWkYkszfRouTVaRNhST8HktyCQB1rtvzhp3YJbiv2Ju1DFM5mT+DtRmbu 6TGQAdIpL0CJgk3RIb6z5byGUbQms2UpGWY0HkagqOWIPmSk8BNenH+q8YFtd5LXHDu3 RJKNKRiPaqr+2VfeTxjG4xDESH8AM+fOwy1sQ= 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=U6KVHMVhDQfZo32KbkTv2zF8IG0l7kHLolyZ6xRwLFk=; b=y63sARKn5EwJKpOVtnntg4cRfvFCX/DHydA7CcIV0GE6HXm+2yoVeDhDaL18j4U877 qj6RRyNUFqxHRs0SxvTFcdfvsXyMmL83AfFEwxHoa2tBml8K17Ht+X68TmcM3k70DE0d jInu5H45Jf3p+g22+tA6OnLgc5yxI9L84Lw+1fJvF5evCBVhYsKHjyHhm8CA+kuy9rqP yJFlYjog3iK2wk0p1+OgUeow7xYn4W70Q8AEEb4ixOeYnkankjquvlIo4Ttmns8uF/yo dqmwWQDg6ZHXeDKisoc0nvProamTfiyhDRiykvZYSnIlPz6EhK5VA5jsCghzEQYKY034 Sqcw== X-Gm-Message-State: AJIora/+WqwYXAYF2ukgpIUVRGO1yjFasc1eEmcQy3LOGM+0jWDgYgus y2zNNKcCHv60v3mMCWmBoQSJdqwp X-Google-Smtp-Source: AGRyM1ubfW5rjphmpOpayS48sKNadm4dnCzPsyYhbBlmc0o6L74gWlBsf8P0yKIeLuSB533B9fE5pQ== X-Received: by 2002:a1c:4487:0:b0:3a2:fb76:7981 with SMTP id r129-20020a1c4487000000b003a2fb767981mr8880003wma.98.1657807346104; Thu, 14 Jul 2022 07:02:26 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:588d:0:b0:21d:339f:dc1 with SMTP id n13-20020a5d588d000000b0021d339f0dc1ls108198wrf.0.gmail; Thu, 14 Jul 2022 07:02:24 -0700 (PDT) X-Received: by 2002:adf:c64c:0:b0:21a:7a3:54a4 with SMTP id u12-20020adfc64c000000b0021a07a354a4mr8488717wrg.163.1657807344773; Thu, 14 Jul 2022 07:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807344; cv=none; d=google.com; s=arc-20160816; b=rshVvMifG/0Ls1E/tCokZ9SN7QEZbsAygTIa7HU/pPSaeY+Mv5c9QSCMHirB3zwOvP z7BhIuyVET6AxyB+vptjpEPyEhby4AHKkufqXSynpZEBouUYs1rbIRJp5v+WYZsTsAsX y8vTTDf2Ckrgqr8c+szi8CudLmBJO5vepZQETdDWSTbCi6PrSWQhZdyZmM9cDJ3XHENu iGXyODZZMnhZm8u6ZwU3+MBk1E+h2q2zRmyZC7p73SJF7GsdY7reFvg1qB9TAyIm/3OD qqFoLco5JgOuLByn7PEMxKungySI2Ro/MiEuO8WhVz5OB5hqZ/g9dO5AJclLVxOIXkgs avtg== 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=diK71uX3lIh/YgoKebxDYbelkMlwygsjJFrjrAg4a/M=; b=jFF5nAKEy0p7OMoeY2Va81N8p6+C55vPizQTB6+vRhBZjQClTTEn5pHRQTLS53eC7F k9gXMufMjfmQaOvQoW6XzB5dOyaU16jkPuKc1LbfAzzq0LIqpFqkMPjDjDMlaZL5wQUB s+JilDMrae0i4jguRK8gFTNKSmRj5EsDj6Dm+/m+yd/Xjo8i672SKa7266qPtYI8kig8 Xx4lPM8RcCibpftIedevTEzYQekBXDHulxsbtEOjyMc6R48CDR6x4PdVcG2lTPaDOeUX 9+EJuiQYkj6b4QSJnT1iSuMsUOddD4EE70jprtVdHlfVILf6KAfP2AsUXNUhejFIfWwH nofg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=kCJST0gT; 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 o14-20020a5d47ce000000b0021d7b3aaca7sor815957wrc.78.2022.07.14.07.02.24 for (Google Transport Security); Thu, 14 Jul 2022 07:02:24 -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:68c:b0:21d:868a:7f2e with SMTP id bo12-20020a056000068c00b0021d868a7f2emr8500283wrb.335.1657807343932; Thu, 14 Jul 2022 07:02:23 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:23 -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 16:02:06 +0200 Message-Id: <20220714140215.444993-3-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=kCJST0gT; 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 9a2194ebd3..4a78770a25 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4160,16 +4160,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: @@ -4180,8 +4178,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; @@ -4214,7 +4212,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; @@ -4278,10 +4276,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; } @@ -4294,9 +4292,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; @@ -4311,11 +4309,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); } } @@ -4325,9 +4323,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)) @@ -4362,14 +4360,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); @@ -4395,7 +4393,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) @@ -4453,9 +4451,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; @@ -4483,9 +4483,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 */ @@ -4523,7 +4523,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;