From patchwork Wed Jul 13 17:11:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2139 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 721A13F066 for ; Wed, 13 Jul 2022 19:11:19 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id b15-20020a056402278f00b0043acaf76f8dsf7410972ede.21 for ; Wed, 13 Jul 2022 10:11:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657732279; cv=pass; d=google.com; s=arc-20160816; b=lSlqWhp5QE3gRhsvIOh8vgectxVvfnUWblTR6I+pQDgxVx1OQh59t5KRPVpyq+9PHZ wrFoD0CVtmZ3rQAorwuPUVZ5ja363AgJbgBsp4Q2I9DDIOjPzZatoR4m4bCd/affjtuR 1d2yciyWr1p3URs9vdg16ZfQ40YCxnxoaMwWa/tJJVf3ImXOuRU+0yo5YyvhpEiuhi3f zBUVcMVZm60cpIUeVnE5YBxrep9tc85jl6Kxlr659mWIp3In+wiSYpbTLVUhExO8wOba DcBm8vhfixGeeUfl4NFKyzr+QXf78Dx2B+6XUU7jZmtYQHPkNuh2lRNuqfBZqdG+DVHE hE5w== 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=EOpiqCLpkf6N34iEv2GdqhZBJu1AlHYF5+H8bPmhqyI=; b=VJWLkXjj73sVBABxKYPTJD9HKQG7OWYZ6rXCIw9MAgsdQm3NbwoHDKKwZ9iaKowVQL +cbJeKGtwGJuKiCHCkHvgEzCavNjaM9seBRw8p3SD3AKi6yGAxVNTO1TFLuXVDbIVvPt pAXmD5KZiXS3IoOO47DUON3eM3uRVlOF3lmFuXMSWXyuRfzReNC85lP/zDYBkBlusVeG iXLpH4IDGn6alZTDdE1QbJ4dpnSQedBBsQU6qkQytDZs1L4EwIumZ2M4EoZyflXFyuHM whNFfh/m+55KzayJthLtZc98KdAqwnSHsl62Aeh+aZPNKeWsLJ4cTCFqhj2EyiItEql4 X5Tw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BLQnlGx3; 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=EOpiqCLpkf6N34iEv2GdqhZBJu1AlHYF5+H8bPmhqyI=; b=hkFex/L2QpeiUL7as2Q9N3nlYbDuTtQAn9Ylm1FKOx7tMEM0xrDQkR/3fd3eNfBqv7 Vm3v41M2x9+m8kVTzDH4gbMvujhVJcihbh2zzOakj6tnJXZ10iYmDYB+GNQ0OWOlc2vi 6JMybMRT9eVtVmz6gBstAaH+8DsHXGLwQMsyw= 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=EOpiqCLpkf6N34iEv2GdqhZBJu1AlHYF5+H8bPmhqyI=; b=SA4U/kqnbb7OLy6shKYqCuG9HBTqsVmZ3dSoWqrVID94DpU4mqcDJVJLBjtzPotXwB tyQtIqv8v/WjyQ38+bl3yMwGyqMFP5Ifo82t2s7Nq8EJdBURyU5zYgUpjq2Jorp/plKD TdpPO2XZrJ0k0bOwUM19ebxFvk9dMXBBYtHpNHby9eZU9Aqf9oCmmBi8nce07bUSDu3c pFLap1i4QV0CHBcNhOKcaHRO8+SsIbmvQlmVB3ODKLCODBdfCgpVD9LUblZp476CnB8P uomLeX701O/sVfple5UHC3NYDSDugYSjIzNDCCI0NMsEjZ4uW9615LOck/Qykojz0BU0 1XrQ== X-Gm-Message-State: AJIora9kcVVbsy/CSXUlWB1kG4EVGboqWqgOZzZ4ld6CF4dKLvJFSQh0 Ef/OLU7khB6S3I5EVWnc13kRJbw5 X-Google-Smtp-Source: AGRyM1sIwlnUw8uvCL8ISyTaxFY+YGbhddIrw+Mtmm/ks06jJ103MYPVR6wH5yOXSNsVvh4B23BBPA== X-Received: by 2002:a05:6402:1518:b0:43a:103f:eaab with SMTP id f24-20020a056402151800b0043a103feaabmr6110393edw.280.1657732278963; Wed, 13 Jul 2022 10:11:18 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:906:95c1:b0:6ff:45d:c05d with SMTP id n1-20020a17090695c100b006ff045dc05dls3360699ejy.5.gmail; Wed, 13 Jul 2022 10:11:17 -0700 (PDT) X-Received: by 2002:a17:907:6e13:b0:72b:509e:bd6b with SMTP id sd19-20020a1709076e1300b0072b509ebd6bmr4544112ejc.202.1657732277605; Wed, 13 Jul 2022 10:11:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657732277; cv=none; d=google.com; s=arc-20160816; b=ng06R4L6XiMygwSBhQ/KJ836KvLK2F1/kFV9pbU1YARmpR6MvDiQrjdG3C1aM9YcTt cOdUZqkymdBvHaLcEPL93nIzkw30tzNR3kcay8Luaf/NIqjbF2AK/6I86QT1nuseGqIt aMWizruLcww8cf8dr4xD0vMCQmSnVmRQCtIrP3r7u3WZu+dbdGHqRp+x+bXbixEFUgY1 a3CYL8/2EZ8hkXBvZ5ftdyUEhOKoljrq76CVbeCVvDWE/CnvaMFiJKRCVUh5pk5BmN8I BtGWZa0yZX8OGwW9zShSFcWfN/vBSaEnh9r8fcBq5luwUsChbgb7SWb6blR6uzibZF9d 3tWQ== 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=QoykMmD6deblCNk3MyMVXZDZ/JuSl7VZD0u5e83RjB8=; b=vRawkFqe+8Wn8NbZ/P6DBvy3GVUtxex0jkzXOJs/hu3CQf33CHSKN+aD9GuX3CA80V qaJiZ7anlinw317M1l2IHlphkiU7sykNbfqFIcmoJoS+HekLFHpQ7AbY3zY+kAb0mw2n W2Eiu8Kz66TQgoXXx/Pal20NoTpVTBt+6NyZovtQLW5kY+p2Mav8reZ12yvK/D0JJp2d Iojx1kvVkdmpCZNpeh33sBzTUutVS/z25uyGxjANaY8rjO2qbwgXL5oGPSR2ZNXjKtqp QcMscjA7iKMMfwIbV6YAZUSvQH9C4nQV7eCSlc4meVc/n6h4ePd7VSUqnq3wOzjouA19 MH1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BLQnlGx3; 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 r20-20020a1709067fd400b0072b3119dfa4sor4356313ejs.65.2022.07.13.10.11.17 for (Google Transport Security); Wed, 13 Jul 2022 10:11:17 -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:2245:b0:715:7c81:e39d with SMTP id 5-20020a170906224500b007157c81e39dmr4576806ejr.262.1657732276819; Wed, 13 Jul 2022 10:11:16 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id lb16-20020a170907785000b0072b36cbcdaasm5218168ejc.92.2022.07.13.10.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 10:11:16 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH V3 1/4] mtd: nand: Get rid of busw parameter Date: Wed, 13 Jul 2022 19:11:08 +0200 Message-Id: <20220713171111.337338-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=BLQnlGx3; 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 --- V2->V3: - take commit message from upstream - take changes from upstream V1->V2: - reset the prefix as suggested by Dario - only drop busw assigment in find_full_id_nand --- 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;