From patchwork Thu Jul 14 07:51:21 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: 2143 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 CD45D3F013 for ; Thu, 14 Jul 2022 09:51:37 +0200 (CEST) Received: by mail-ej1-f69.google.com with SMTP id nb10-20020a1709071c8a00b006e8f89863cesf423821ejc.18 for ; Thu, 14 Jul 2022 00:51:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657785097; cv=pass; d=google.com; s=arc-20160816; b=E+oZwpdDEg6g89N5nl3T4E1DTpvAmfmixMLlva3C/Li1a+5LEGeu1PYMOMNEs0pGWf giNuZH7E+TwU9YP3xKYVsA0B5+cgJsW3f043vHkTxBEvhw92DvxDD7FLtqH7Rro/oiEu TmQQWCDhc08Wr54i4AQjk/pUm/6q8GPZq1SzK0+xjNNC5kGwSEcyGMhy+5arSoIccYuW uU7NZQ6RRhJ24TQVEbmrMyzFN/Hn51N/YN19+BgFYKUi8NJ9HYl8g+AtmYW749SmNPTN dPhmZr2tzUqrJ8s6GXS/2v9QrELIV1CnUPJHm6qAWyb4VM1LzHp5nB54Bh1OktxLA2TE SOFw== 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:message-id:date:subject:to :from:dkim-signature; bh=68Fw0VstvOJ5KRce9Fl2UJr5HAM04X4dIRBClvxSJGU=; b=ucGVyzTNpoGqiNws1AJtawredhWCMOzHAQPrYpjy0eFEIJWr/2s60IXSoE3pF45y5/ JopLaYq3yorcAvIM8Bz+c4/1a8+2zeWvweE7HX+maWND8bN9kDFxvLStzk3YpXCdZhx6 FWDqYZYexryo3oIybduorwNADAbiDVFohNB3mYcyFEoIeHC6xtKYcwJ4k9YG1Sw+1S5H dO8UP7Qpitgx/yHXnyznbDVGURwtvpHqs0G+q8aL4mVY1VqLJvmRpWmqNx0YL/0ZOR2j KIiuAt0jZVAFXHwbel0nTQ/Z5FjuSecJGewQ7crwGr9CXsscV5HfI9Q3zVX9G5GsEz7o mvGA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=didIiQ2b; 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:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=68Fw0VstvOJ5KRce9Fl2UJr5HAM04X4dIRBClvxSJGU=; b=cPhpkWaqAycnzRiNQWsnbQSuOw6M/HwJfAfLlLIKdabLh6AUxfcmv8s5M4LJ8TpvZ6 AHuOR5qJ1C+gqv5cr4iiNJ0P2V7WnoOGOXaGzJQnZaGkoXKdP2YmHctMMCKBX0Uvfwcj SuYFGDyMlMiFGefKPCGCRxBow/m2AJNk42bIg= 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: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=68Fw0VstvOJ5KRce9Fl2UJr5HAM04X4dIRBClvxSJGU=; b=X+lQzeivD8KfMJggfrm/TlsIBrBK79Wt82aj65g2BumSp5tbcgtIsy82k6fvjFbbll jC0Yt0w6LRJ0o4Ls1JDXBCfAKTQYznR8oUqVXqDUeGBpQqMGPVqY1GOkleQ6lM5a4in9 a01VD3sYokiAO3twClSMDCaMesqtb+dHGeyQHBe1YDU6NZ/QV34q9+A+m+63E/RTTf1A cHtsNDcsvpJbpmuYYWEFA3do2FE7Dtc/52gesa1X7czagfoQjw5cy2ENHejPAbpneYZM sRdP/TW5k51TjgcAQWNfNZkz06AByjFno3ifJYDeyLn1bFv0uhz48sf/V2mIiJYCG4OQ JlSg== X-Gm-Message-State: AJIora9WODskaaWD445vFBceJw/wmNsmuK/us4Cae+XbL+uEfzSUf0/W p+5MshtAcHOO+kB5gRBBpM4W1daA X-Google-Smtp-Source: AGRyM1ud22Ox85u1QnQ1xJd4sIOiISh6pAQuyPGVp/QuvJYsBV210GZrJ5OWS0/ZrxQhZ+gc4f7sEw== X-Received: by 2002:a17:907:a056:b0:72b:1964:fbcc with SMTP id gz22-20020a170907a05600b0072b1964fbccmr7663655ejc.489.1657785097381; Thu, 14 Jul 2022 00:51:37 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:34cc:b0:43a:d872:b6aa with SMTP id w12-20020a05640234cc00b0043ad872b6aals143160edc.0.gmail; Thu, 14 Jul 2022 00:51:36 -0700 (PDT) X-Received: by 2002:a05:6402:5c9:b0:420:aac6:257b with SMTP id n9-20020a05640205c900b00420aac6257bmr10542726edx.128.1657785096014; Thu, 14 Jul 2022 00:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657785096; cv=none; d=google.com; s=arc-20160816; b=zj561S0T60DCujs3T3ENfPYcCZhUCTZaklLpsdQdWDOrQMUchAfKlD2zH2d+sdHyE5 89tc1l30Gr91D3YtyYDZhw71qBBYzVrMUU9hfpsUsgyAJkn7wen5eu+YTzU+wpb0vC2V 0mxVQmnWbUvPhObUVg9eSZz1QoOd5ZgFVPqb63UU9Dlvcr/SG5mqAd5qEyXTnDZUVr1S k+0ck374e8raYkDvgd4r+BOLyuJlLfcticHqeeSXoHJwGwaSP+/sxDKiKE3eIHaRFPYe 9HeRJd9CCfDy9al9aXjDpthVBX2G+6FKnGkCNwafjbOzJs0IIHpeZBKXerqT8BcOtvwg w90w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:dkim-signature; bh=N7/sSWXem3bN7xJUzqI7RvbQX3kYUU7XoPk2vsJB6V0=; b=oGjg//Ms413OGKCmZgdRPOwcqA0AfS3xJe3BDzXPhf/LNEHMHIjik94FN9bIKb5roW JedFPukLMQvBDr9YKhTPvGsSmBdjheSSd4pvcU0STfOQp0DU0VLj/4ZxKt69SQkPlqLM wXJb2X+OrdbbU15AqFSU35Kh8dXWuU11SeS8o43CncbHpog3kiG1zUVFiRhDmR5K/5BI Y1ng6KgF91aG8Rk5bz1L2oO4hR8dXWcinzkXMqJyC9YEnMWQ7CEBEAC4U3VJ5MRUTQhM pmxnJFPYdvMSFIt5Bmq/CKKZqoveqEu7kCSdAMDc8lxawiSNT4DOt4tEDOgIbmTrxICL dyZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=didIiQ2b; 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 sc17-20020a1709078a1100b0072b67a5f3e1sor287227ejc.70.2022.07.14.00.51.35 for (Google Transport Security); Thu, 14 Jul 2022 00:51:36 -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:906:9b0a:b0:72b:4fc2:4b07 with SMTP id eo10-20020a1709069b0a00b0072b4fc24b07mr7639277ejc.700.1657785095299; Thu, 14 Jul 2022 00:51:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 00:51:34 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 01/11] mtd: nand: Get rid of busw parameter Date: Thu, 14 Jul 2022 09:51:21 +0200 Message-Id: <20220714075131.411548-1-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 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=didIiQ2b; 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 29a198a1592d83f2bc1be3b2631b3bcf3d5b380f Auto-detection functions are passed a busw parameter to retrieve the actual NAND bus width and eventually set the correct value in chip->options. Rework the nand_get_flash_type() function to get rid of this extra parameter and let detection code directly set the NAND_BUSWIDTH_16 flag in chip->options if needed. 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 | 59 +++++++++++++++++--------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6f81257cf1..9244287b10 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3890,8 +3890,7 @@ static void nand_onfi_detect_micron(struct nand_chip *chip, /* * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise. */ -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) { struct nand_onfi_params *p = &chip->onfi_params; char id[4]; @@ -3963,9 +3962,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, chip->bits_per_cell = p->bits_per_cell; if (onfi_feature(chip) & ONFI_FEATURE_16_BIT_BUS) - *busw = NAND_BUSWIDTH_16; - else - *busw = 0; + chip->options |= NAND_BUSWIDTH_16; if (p->ecc_bits != 0xff) { chip->ecc_strength_ds = p->ecc_bits; @@ -3995,8 +3992,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, return 1; } #else -static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip) { return 0; } @@ -4005,8 +4001,7 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, /* * Check if the NAND chip is JEDEC compliant, returns 1 if it is, 0 otherwise. */ -static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, - int *busw) +static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip) { struct nand_jedec_params *p = &chip->jedec_params; struct jedec_ecc_info *ecc; @@ -4068,9 +4063,7 @@ static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, chip->bits_per_cell = p->bits_per_cell; if (jedec_feature(chip) & JEDEC_FEATURE_16_BIT_BUS) - *busw = NAND_BUSWIDTH_16; - else - *busw = 0; + chip->options |= NAND_BUSWIDTH_16; /* ECC info */ ecc = &p->ecc_info[0]; @@ -4160,7 +4153,7 @@ static int nand_get_bits_per_cell(u8 cellinfo) * manufacturer-specific "extended ID" decoding patterns. */ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, - u8 id_data[8], int *busw) + u8 id_data[8]) { int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ @@ -4213,7 +4206,6 @@ 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)); - *busw = 0; } else if (id_len == 6 && id_data[0] == NAND_MFR_HYNIX && !nand_is_slc(chip)) { unsigned int tmp; @@ -4254,7 +4246,6 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = 768 * 1024; else mtd->erasesize = (64 * 1024) << tmp; - *busw = 0; } else { /* Calc pagesize */ mtd->writesize = 1024 << (extid & 0x03); @@ -4267,7 +4258,9 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, mtd->erasesize = (64 * 1024) << (extid & 0x03); extid >>= 2; /* Get buswidth information */ - *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; + /* Get buswidth information */ + if (extid & 0x1) + chip->options |= NAND_BUSWIDTH_16; /* * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per @@ -4293,15 +4286,13 @@ 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], - int *busw) + struct nand_flash_dev *type, u8 id_data[8]) { int maf_id = id_data[0]; mtd->erasesize = type->erasesize; mtd->writesize = type->pagesize; mtd->oobsize = mtd->writesize / 32; - *busw = type->options & NAND_BUSWIDTH_16; /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; @@ -4363,7 +4354,7 @@ 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, int *busw) + struct nand_flash_dev *type, u8 *id_data) { if (!strncmp((char *)type->id, (char *)id_data, type->id_len)) { mtd->writesize = type->pagesize; @@ -4378,8 +4369,6 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, chip->onfi_timing_mode_default = type->onfi_timing_mode_default; - *busw = type->options & NAND_BUSWIDTH_16; - if (!mtd->name) mtd->name = type->name; @@ -4441,9 +4430,24 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, if (!type) type = nand_flash_ids; + /* + * Save the NAND_BUSWIDTH_16 flag before letting auto-detection logic + * override it. + * This is required to make sure initial NAND bus width set by the + * NAND controller driver is coherent with the real NAND bus width + * (extracted by auto-detection code). + */ + busw = chip->options & NAND_BUSWIDTH_16; + + /* + * The flag is only set (never cleared), reset it to its default value + * before starting auto-detection. + */ + chip->options &= ~NAND_BUSWIDTH_16; + for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { - if (find_full_id_nand(mtd, chip, type, id_data, &busw)) + if (find_full_id_nand(mtd, chip, type, id_data)) goto ident_done; } else if (*dev_id == type->dev_id) { break; @@ -4453,11 +4457,11 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->onfi_version = 0; if (!type->name || !type->pagesize) { /* Check if the chip is ONFI compliant */ - if (nand_flash_detect_onfi(mtd, chip, &busw)) + if (nand_flash_detect_onfi(mtd, chip)) goto ident_done; /* Check if the chip is JEDEC compliant */ - if (nand_flash_detect_jedec(mtd, chip, &busw)) + if (nand_flash_detect_jedec(mtd, chip)) goto ident_done; } @@ -4471,10 +4475,11 @@ 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, &busw); + nand_decode_ext_id(mtd, chip, id_data); } else { - nand_decode_id(mtd, chip, type, id_data, &busw); + nand_decode_id(mtd, chip, type, id_data); } + /* Get chip options */ chip->options |= type->options;