From patchwork Thu Jul 21 06:44:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2217 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 AF90844190 for ; Thu, 21 Jul 2022 08:44:53 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id h189-20020a1c21c6000000b003a2fdf9bd2asf566822wmh.8 for ; Wed, 20 Jul 2022 23:44:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658385893; cv=pass; d=google.com; s=arc-20160816; b=mPaFzsYXJYyKPCo96g2Il17pPvDQy6mqFXkAC/94R7keZnW9A6a3KAz43LsmKXltw8 DhzTFJV4extgwptHBTJQ2lX03b3leCvRQtlSbJS7ELaGVaoilTKkDOw53Eyslws3IIgM kNqYSudi1aabKk0sASjqAhuKGZ/X0OCzsEH3YyZkZcY2HfdXs+ylRRrmZodC8wv5VjiT oFmwmHjk4Rd2UKAcP4ZKDfNGLF9eMQUV1cbftB2PUJLXFZI4E3WOZGaX6oWpDq/ozXHc VlNbWal2gshtcqmDFm6X1K9LB6eQtFOvodKmMpP4b8t504mXas0gJqqpDs67cRb0gvud atdA== 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:cc:to:from:dkim-signature; bh=2WNAcEUUoJze4mzfnXy11tgihs+EpuTieRVh5uKngWk=; b=Y6hMqD3qmOs+NjIUxorujPsDnBbdcT7hc/z+kP3MslbxR+u8aGgfokyys/el/Wc9Xf +jT2afH4vuK6DaUi3qSjiCvTWtsnohJFXykKnbRFPVwQHo3k3xsP0Zbd2pNHySbnctcM 3S2+K9DBTbPZEHHjIArC9munYpbals2hJvzh8W4SldIbAwatX2tR6t2JfHDZtDjWmXze c2RplQcJhl+p/bqIzPQYhmSZ/WWY74tYjap6UwCZIGRw6iLSs6nsciN93dpoE08z54k0 e6snrKuz34NK/sx/Lmikh2ZyroLB8e5RX963YlMqLBkPo+PvVVXgIPpCuUwAtqlfiG8D RlBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XB4GObuw; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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:cc: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=2WNAcEUUoJze4mzfnXy11tgihs+EpuTieRVh5uKngWk=; b=n5Gx8MNscM3nEG7tUBbmSY3yVrfAEx4LvQLX+CR/WnG0wFie5Vs9bE1vYzbSyrymhW d6u3xasD3Kk72cMXYazisQOcQOzcYe6tx21VveQfP4NqBFM5hGfuIu/hWeKoLQhbx7h8 soVrpCkFl2q2QzS61PtkbxnubYTe5wypRC5Yw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc: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=2WNAcEUUoJze4mzfnXy11tgihs+EpuTieRVh5uKngWk=; b=kLLyWXs8pR2ebcq10chcorD7MmeqvAt5I6rS2eVDL0T3w/PgbBgG4bMsrbRwR1Th9N dznYvecbRxCH1mku/YFt7vnlHYCj7lO68aAngJB5MnmTOX6ye9THpZ2pMA7lxhZjAGCs 7I4XG+j5iA9AhB/EpEZcWPfmpvf72nqJ7okNewTduFjqU1Mc+lKaPvL6qreJ4Qv0JbHq JFHwl6Cs4gZlJiVq/U0QzQUpwYgI/vDSNsShDC2g+R8VApSSEpG5A8eU7bN76Qa0Wdn/ S5Ez4SeCpNu6z0bd4ym+Sbkc1S8mTDxZplFX4201uLvT2qufvgFdb8OlERZz3Izzidpe iRZw== X-Gm-Message-State: AJIora8XkNDb/EjduYB4Ecv9aauf3FGm8dY0d49xacny5d5FYRuC7sV1 G/AqIzEfk0HkI9aw+3znv/E0zMA2 X-Google-Smtp-Source: AGRyM1uhkF+Cvw9DAoexQWJdadZlRLyvNXZNZPI+RpmU6AV/4zcPqiiI1BufBMeRL6RIFBgGbEOMTQ== X-Received: by 2002:adf:e98b:0:b0:21e:3367:cb43 with SMTP id h11-20020adfe98b000000b0021e3367cb43mr9592441wrm.25.1658385893516; Wed, 20 Jul 2022 23:44:53 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a5d:6f03:0:b0:21d:9636:a730 with SMTP id ay3-20020a5d6f03000000b0021d9636a730ls243420wrb.0.-pod-prod-gmail; Wed, 20 Jul 2022 23:44:52 -0700 (PDT) X-Received: by 2002:adf:bc07:0:b0:21e:47fc:4b01 with SMTP id s7-20020adfbc07000000b0021e47fc4b01mr5797516wrg.293.1658385892579; Wed, 20 Jul 2022 23:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658385892; cv=none; d=google.com; s=arc-20160816; b=Gz9p6ufoJjWJ5farFtTyo1s+DjhIwqNyEFgZPV0wXctYKYL4kFJpbEKUIJ+LraE83c j5RTKTZqJj3F0AoJ1i5Z3m8NyjwsRDhEFkj9WJFWPMaBdVi8SowmIboTMwgGvpdzTyDy 3/Pj16BX7EMMnUe/LnZV1sig/SIHzLWY6iCXh6QwvCButf/uYOZfSth5vap95B3vtB39 7QMX45ng0xynwBNQ9JpzG3qbcH+fW0CGljxvoKEnkQG6fQoPvTtC/TMRVtZTXgbObmoP ECFbtTiJc8xqn7ct9eb+ZajXZ2k61JHJzBRfCgXaHDAfrJqzEjdCI5IwqPamddHOV6vI EzTQ== 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:cc:to:from:dkim-signature; bh=xd8eUKK9iYAZXNsfE7I8BnNoJPlhH4IJYqhYXjF2Fiw=; b=foLnwF5dQS33I5Bb5utr2113kqzmJjo9fvp99BDyiM0QzP9NPn0yqW/I9t0K/lDZnu 4OzSEOXHuRxuMHo9vomjlNftbYAoEtrBlnWeidSybP8S5/p84ZEzSE2bsoPdCyNaqzw4 zGuei74fnDCQrAZ9iDOPpyJWz4l6lN0m7XG5WHgZgpe9haP124/6Q52zLlTR/TQyQdm9 q9kde0kAwlGHO9DkJlDI5QwC896joPr7LT6FjVK4L7vDnVAaTT+9lxvAhP5f84141buZ d2OMRO0vJDJ9tl/ZMXCpJJdPUCZnC9I/cHqr5kpHHQCPmH/Sc6gyN33aMVg7DGIdoyxR n+QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XB4GObuw; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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 o12-20020adfca0c000000b0021b902e572esor465288wrh.14.2022.07.20.23.44.52 for (Google Transport Security); Wed, 20 Jul 2022 23:44:52 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a05:6000:992:b0:21d:9240:4337 with SMTP id by18-20020a056000099200b0021d92404337mr33606093wrb.323.1658385892310; Wed, 20 Jul 2022 23:44:52 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-140-42.net.vodafone.it. [5.90.140.42]) by smtp.gmail.com with ESMTPSA id c18-20020a056000105200b0021e4f446d43sm903711wrx.58.2022.07.20.23.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:44:51 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Amarula patchwork , michael@amarulasolutions.com, Dario Binacchi , Patrice Chotard , Simon Glass , Wolfgang Denk Subject: [PATCH v3 02/13] mtd: nand: Store nand ID in struct nand_chip Date: Thu, 21 Jul 2022 08:44:24 +0200 Message-Id: <20220721064435.2456601-3-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220721064435.2456601-1-dario.binacchi@amarulasolutions.com> References: <20220721064435.2456601-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=XB4GObuw; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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: , From: Michael Trimarchi Upstream linux commit 7f501f0a72036d. Store the NAND ID in struct nand_chip to avoid passing id_data and id_len as function parameters. Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi --- Changes in v3: - Use commit sha1 with 13 digits. - Fix code style warnings raised by patman. Changes in v2: - Use short-commit form. - Remove linux info. Uboot seems that backport without add this extra information. drivers/mtd/nand/raw/nand_base.c | 58 ++++++++++++++++---------------- include/linux/mtd/rawnand.h | 15 +++++++++ 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 9a2194ebd3f8..220804c75c87 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 && - nand_is_slc(chip) && - (id_data[5] & 0x7) == 0x6 /* 24nm */ && - !(id_data[4] & 0x80) /* !BENAND */) { + 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; } @@ -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 - && mtd->writesize == 512) { + 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 3417ca2a0d2e..f2c6a978cbf8 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;