From patchwork Wed Jul 13 06:54:37 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: 2121 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id F04A33F1F7 for ; Wed, 13 Jul 2022 08:54:47 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id hp13-20020a1709073e0d00b0072b812bc5e9sf1389705ejc.9 for ; Tue, 12 Jul 2022 23:54:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657695287; cv=pass; d=google.com; s=arc-20160816; b=tLzoE+zXSxeVvwJ2yts453WomP5hEiHeunpq5AexZm2uWq/Br2HbMzSMBDsZM50G6n XG+TSRHRjM+0pHQVvISeo+SWC42UBZsriK02QgZ9at9PvqYmnzQNRXNjKYs1S8Qso7XT uZ9jDkH3nWDr3UHsXk4+OGCuEYvGdCZGmCu0EtQ/tf4+pYN7T8AEJzV0TnZG1OYh7rs7 ks+3RfPUprQ9t/mryNrQYkbxafOxTN6vE8paIh8dkPC8zbVup+BKN50hIKZ48hOk0C1o ynrLphawpocciCpR/h9yd4N4HTr1FHLl32sK2MRdpNl+7sHuFIrpjykU4tnwyTSRlSBA Z9/g== 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=aW6GEdkD8zcDfiJNDIOT456mXapIcpvstleGv6GjrXo=; b=rKnH9b5u5PderAQ7Byj3sy2aFbdK5TQPsGdWTmvtsH8CpqYQeHP8bJY+19zbtXj06s XoCuHZMdI9NpYnm94lbsFNCBIuBI1ICWnUEY3xv4trg+Hn6wWGKF8WyhmNeGJ6KzfqH7 izNz07Qr+n9e5YVoSlplcaVv6GtEMEfIdDjPMetVNJMEZEBeudpvGr23k/McveosY43b r6+apKosHiyNO7V3fLw/NTK9hGpK6ZoVYYaybq5FraxsxmNygsnTnBVuy05ERuJfaBvd WFEC5W8iHl8D/d8/EVIuUnlk1j9adlPV28pSJceq1Xd3UG4ZqUaNWWRLpUCjtnuUF99w Iudg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GjYRNG49; 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=aW6GEdkD8zcDfiJNDIOT456mXapIcpvstleGv6GjrXo=; b=fbWTHdSl56if5hAK022r8tEnG5s0UW4NR6iSVWyeVMgqHV3JXIQQ8O3zH17zeEGw1G Go1vWYBiVZqLfkwuq/mA3Rek0tov2G7Q0vxaqAbth2ZpCimKrZaM5Sutdb8u1T343K96 QDrpffOxUmgqXjWJtEbDqAi5Odyl0xwTm0FZQ= 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=aW6GEdkD8zcDfiJNDIOT456mXapIcpvstleGv6GjrXo=; b=21sk5NI8vjSSMM+Q4JFpxSgParoCr5d2dsXbdjGSMzdalq3nLyYFJKwtRLidcrQN4F eJu4Z7gvQG/zfC+2kLBjpEYkQyoz5be0AZbBRId++I2d/+Kk9xvyLoreX7FJNlltm2Ez Eo2tEjrI5Fwi7aPMcfhw8KDQZV8dTt17wzq7/bFfdJsmp5MhM7N77IFADhcLrupwctgM MWrKQ30QC5xq0msqnIl5iKwhrdpsHZN0G3JCTV1jmahm8qF41Tw4iolvwA6Pgt6kk48W KHerLYR/14OpaqYZmO1Y/eLTPEqmJJ6cdWGO3MP5jXzjtwsPsO3gdw8kYI/hVLl13Ak7 ilPw== X-Gm-Message-State: AJIora/eNFCvxfgRJJv2wSGYuAsIDJLhmJHMgjm1oUf2YFKX54YHp8fj PgFg150OZORClscjCiWWReMKdg71 X-Google-Smtp-Source: AGRyM1saujN1XGB3KpipUoDjPF0ICNe7PqqMm7Wn4ldom3z3+ldlL0sXVAE1xrbOnpX+JkhCbRcUJw== X-Received: by 2002:a05:6402:278e:b0:43a:9cf5:6608 with SMTP id b14-20020a056402278e00b0043a9cf56608mr2842714ede.76.1657695287819; Tue, 12 Jul 2022 23:54:47 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:5ac1:b0:6ff:ab8:e8f with SMTP id x1-20020a1709065ac100b006ff0ab80e8fls2506522ejs.6.gmail; Tue, 12 Jul 2022 23:54:46 -0700 (PDT) X-Received: by 2002:a17:907:75f1:b0:72b:9e40:c1a9 with SMTP id jz17-20020a17090775f100b0072b9e40c1a9mr1034605ejc.523.1657695286450; Tue, 12 Jul 2022 23:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657695286; cv=none; d=google.com; s=arc-20160816; b=LpKSstBb4hfV8aQ295gep9eMUQQmNnUo6WoqCAhSHoFqnhsOMNHTNF820oiaCnggz+ pAPovA/NbAZcVJCQOwKhygzJfLSs+xQxBtOj0wCCrkiCvkoTFSZB0BCbuOclURiyCaeH 3HxE4sEpE1yyVPgi7LGr0/7NOLASE/EQTzitpOtzxGtqfvKEsxVHoNx19+mdrnsk15NF /GkQuYG52Nbah4OJDO0rtxl6rXcXFFNIel2QEpNzEWW18a8zy44PFMGhJ8fwdTmhQZnx 5PEgN9JcNVcLQXCjevGuM/Od98+bC/oPMBNi7KPWfeaHdevJFvGGvqxTngm48Rwf0Hsi wggA== 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=2YfxGQzkFFT0sbnfqrBh3TwpjufxYi7kY4AAw9T7MuE=; b=FRqQV1DIh7RcLm1nDise6mPgL+Kgy85VNhisvEOl08XHAONpN7Y+T+QG1gKm2qNSkp x+P25u618JC8T7I3Eg/IxJF9ROGp70pZqeSp4lYHiIgtSePi8uZP87qBK7hrQ+K7RqAy yCv13fV5tipihgoSEwLAF0bvcsPo6NFWNJrGEqZYx4bru3TYAIj/HsOf1648fLwtKS+k f5sM8Rtt52Q2oFZxydMw36Fcz9VJwlCWnZozcIKoo7wZOcm1UIGJWH3QFVZeUhvPro1z DjiCNLvQHkSFxPWTzxritfbUOVXZLmsnn1iN6aQp7CEgJwBW97uhgOzS9Kn3wjq1nzLg qAAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GjYRNG49; 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 qh20-20020a170906ecb400b006f3afcd1b7bsor3645046ejb.115.2022.07.12.23.54.46 for (Google Transport Security); Tue, 12 Jul 2022 23:54:46 -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:1c11:b0:726:851e:179e with SMTP id nc17-20020a1709071c1100b00726851e179emr1933435ejc.39.1657695286101; Tue, 12 Jul 2022 23:54:46 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id lz21-20020a170906fb1500b0072aa38d768esm4635263ejb.64.2022.07.12.23.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 23:54:45 -0700 (PDT) From: Michael Trimarchi To: Dario Binacchi , linux-amarula@amarulasolutions.com, Tommaso Merciai Subject: [PATCH 2/4] mtd: nand: Store nand ID in struct nand_chip Date: Wed, 13 Jul 2022 08:54:37 +0200 Message-Id: <20220713065439.272149-2-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713065439.272149-1-michael@amarulasolutions.com> References: <20220713065439.272149-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=GjYRNG49; 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 cb22e0ec13..6d8b892288 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; @@ -4268,10 +4266,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; } @@ -4284,9 +4282,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; @@ -4302,11 +4300,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); } } @@ -4316,9 +4314,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)) @@ -4353,14 +4351,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); @@ -4388,7 +4386,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) @@ -4446,9 +4444,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; @@ -4476,9 +4476,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 */ @@ -4516,7 +4516,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;