From patchwork Wed Jul 13 07:16:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2124 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 2B4923F066 for ; Wed, 13 Jul 2022 09:16:45 +0200 (CEST) Received: by mail-ed1-f71.google.com with SMTP id s17-20020a056402521100b0043ade613038sf4522451edd.17 for ; Wed, 13 Jul 2022 00:16:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657696605; cv=pass; d=google.com; s=arc-20160816; b=eeO5mebJXEs6sPYM8pkKgoPCG1p59Uzn2CDCvY1W4SO/caTLpWLRYPIGXjDUiFkhUu 1wOdVBSUqZcxvEPUPgyc7EPnXZB252jIyvtWuD/7klqJrFV5axHHKSL66VlmcRLLCI7U W0Zdzn4zWn3VBYPmX6BWWu6iZa+1Q9wiDar+Xx2P2ee/nQOCMt2zgR2yOXduu6u6v9w4 dNiH02eThcpkXppaeXuTaYkKlszmTzICkZVrY6lgXEzCy0pJFtcwi0Iq37Ll2kkiLBdp hm6Y4NvPbpvP9qYBB/Ia+6e0JoLrzbpa4eipCNZF36kPhiqVYg6wR63QIculUuwxZQap YFwQ== 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=w6jeEffYbyh5yW4irRptvwg51uM2EHfMcnY/JdAF/24=; b=Ih/QIXCD8vuRqngVWNGn0xzaLZIW2i9kPBU7rYf7oXLHKbbrPSq1AbvMgLJrBYQDet c33qO5HP/mw+VJbua1ooKPLYVofAhUjEAe4esw651Lpip3Ju3Q3IxsoqCTOCT0ndGUlN gWUVTQBQpMbYuFxWGbOaIWTOL/0aSygS3Zh8exhvZ4DO1nGbOBejkT5bi55SCQfvjk5v nWY9dyZJOuuI6Pv5vSBQJM6zrE4KzEH3GmUNruFz8TNiqFBRCh3iJAYsigii9o28FFGk XdVDgbhgMC72rivef7xKDMH6j9kliKKKSbc0QdzbvFvbjlJOSv6j26nyyrKUMfPuCIPx LXrw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=B3PYyACO; 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=w6jeEffYbyh5yW4irRptvwg51uM2EHfMcnY/JdAF/24=; b=EwVb6Fn03lYEMl6aRHZ5k8eLy9gXvbb3IkuSOfyUnn0+oQa31isQNFjtGZ24algyvn faGnwZk2ZSqwZ+7eGeWXmoAcY+rHkU18JcRLEh/Fk7+iEMXHUbvj8oxs1LRALnFtRujk TKi3zBQ2kXgSknfJtGtpg3zmhvww2yM1UzVNg= 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=w6jeEffYbyh5yW4irRptvwg51uM2EHfMcnY/JdAF/24=; b=XPwinDRXup/NO93iwcpr1v1jwhH+LBZALuCNCiNcTNYTBHx3ltEO+jLdlkHM/V1dam 4tVkZFQvk6/u4yjmgXrQvI/PKY47G6vQObmSOkRU6C68NeKXw+N1IIQkoTXq2vEGAg84 JoZwqhsnZ/00QyagMJy/8GOsybl+AuQA+lm5ikeLgVAujO2YdAekbJY3lr1vpWj3XXm2 gsFmhYitZHrBVvHqAHXzJoJdNhJLTt6UwH186Ar14Y6r4vuk9MkQf6CNsA/pMRZSUP/g vk66FVOqZzI8DMhmkCqwB1UBigO/am/8SP5A6tBZKpsyifzs+Rjvs9bRdze4yY4XLFU4 b17Q== X-Gm-Message-State: AJIora/BcL5MklgUtqj8MPfe0Gmb6tFiv3xJO4t7j91FzWNRauK1mM9v kYEHmBLh+NodjaKaBKwow/duhKw0 X-Google-Smtp-Source: AGRyM1u6kU7KXAS7jGJHifbKNCaXGfc3mlASjaAdAc7B8Lu88c0K3HbVt+vL1pAvOcfTB1gGtADvAA== X-Received: by 2002:a17:907:b17:b0:72a:edb8:7529 with SMTP id h23-20020a1709070b1700b0072aedb87529mr1902678ejl.749.1657696604940; Wed, 13 Jul 2022 00:16:44 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:1c89:b0:72b:5b68:a7e with SMTP id nb9-20020a1709071c8900b0072b5b680a7els100069ejc.1.gmail; Wed, 13 Jul 2022 00:16:43 -0700 (PDT) X-Received: by 2002:a17:906:5a6f:b0:72b:10c8:8513 with SMTP id my47-20020a1709065a6f00b0072b10c88513mr2020220ejc.312.1657696603514; Wed, 13 Jul 2022 00:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696603; cv=none; d=google.com; s=arc-20160816; b=SOpCndKfUKpmI8PAIFp94Tj7C7G/uo7leIxPT9n3EQqwKB9Bx9OmqY88i2JxwEpPhG fl/+wBaQ3y0/xN5a4w2zMfbAJgEfcBF/oAJzCT999YQ55sV6aF/M8aL4IXiXOOT1w3Ck UWkk6pPiUAT7oU76pTNC5WQLzTavS0qJdR5pW9dDIUkdsyZe1XJwgla0ohf0EcI23zHi vMNY9Zw3vFMdfulkpbxWjsBDYnGQ4UAnkUXOGXJOg/irnDfcTxeq7tNEmXXyp+5LIAej XM05oqZftRmImCwReOfn7v4dkl6exmDaF4fcWd+mdfxPY2Gl6JZ/CX3G3S4z2kuRtmb6 mKQQ== 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=lIuIWLqqz2ogXeLR2OiG+YgBNXzZxQ2P6FCSJQWqai8=; b=HahvC5SJvpjmY1CEcEHihKX/dSwnhnM76SCPPkslENnjF4Jkuuc9/dKEM/yZ/MjK+6 jQRrMpBXQIv5hSe8gU7zy5v9esq350sl99Pj1t9j3BRAiLHG6m7NTpe7aSKxpOtj+BS3 R4KsVPhj41hWqa+GzVPCVludCTgC80d2pzymUo9Yj0KvGxOEjmOF6Ty4hY+WB3NVgaq8 B1FCbb8sxrlCpy+HwpWGLv4t0Po+AZXoi5KAwJz+ELLUqurIz4C80/dW1iluWeAdT6x5 Bd8g6TzkkLVtZvINEGXj1en+GXV8b4/kCTO9nUXumv1leA3k66r/WNVu5+Bjo6MPVwJU t9SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=B3PYyACO; 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 gr21-20020a170906e2d500b00726946aa176sor3601965ejb.48.2022.07.13.00.16.43 for (Google Transport Security); Wed, 13 Jul 2022 00:16:43 -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:c150:b0:726:b4e7:772 with SMTP id dp16-20020a170906c15000b00726b4e70772mr1907613ejc.499.1657696603142; Wed, 13 Jul 2022 00:16:43 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id z41-20020a509e2c000000b0043a95981050sm7414523ede.79.2022.07.13.00.16.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 00:16:41 -0700 (PDT) From: Michael Trimarchi To: Dario Binacchi , linux-amarula@amarulasolutions.com, Tommaso Merciai Subject: [PATCH 1/4] mtd: nand: Drop busw variable and use chip->options field Date: Wed, 13 Jul 2022 09:16:34 +0200 Message-Id: <20220713071637.275456-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=B3PYyACO; 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: , No functional change. Reduce the function parameters in preparation of support specific nand manufacture Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 58 ++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6f81257cf1..cb22e0ec13 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,7 @@ 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; + chip->options |= (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; /* * Toshiba 24nm raw SLC (i.e., not BENAND) have 32B OOB per @@ -4293,15 +4284,14 @@ 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; + chip->options |= (type->options & NAND_BUSWIDTH_16) ? NAND_BUSWIDTH_16 : 0; /* All legacy ID NAND are small-page, SLC */ chip->bits_per_cell = 1; @@ -4363,7 +4353,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,7 +4368,7 @@ 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; + chip->options |= (type->options & NAND_BUSWIDTH_16) ? NAND_BUSWIDTH_16 : 0; if (!mtd->name) mtd->name = type->name; @@ -4441,9 +4431,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 +4458,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 +4476,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; From patchwork Wed Jul 13 07:16:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2125 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id B19763F066 for ; Wed, 13 Jul 2022 09:16:51 +0200 (CEST) Received: by mail-ej1-f72.google.com with SMTP id qa41-20020a17090786a900b00722f313a60esf3010710ejc.13 for ; Wed, 13 Jul 2022 00:16:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657696611; cv=pass; d=google.com; s=arc-20160816; b=TZg/IyhcenbIv624zeG2uCUjpS1vPXsPE2Vm5PZs5vqKyTff9eWY8jfs6/76eDDsGe FLN2+VQtZHljpPzzAOmhFu+0fuCpBHC/a9c2Mm947mQX+RgSb5xaIQJbkIEeQTwTIVGI xVwnHw6VSJsRvDHvvWgcjEakc02uYmtN1D80TWF43MGsnpWmu8c/6/DGdqWqWIb4m7R1 PQBjtCj+MYXhFtM68/mLk8XRLPOvwPddLsUCJZfonzul3HIX1dcrn5edfFEXeTzX+BfO 7xmMTNgg2r8QNoH3k//bdnXJTq14qBkGnCKmUzXUc/P/VsLlwuPoCeFd6vmGxlRKGG97 2XMw== 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=E3ASCE/hK2G0yMY3KcbL5URDU2plegvB3zTMNoF3qaSYEurHlZObc4a43LcG+2pJlW BZaRq1dAI8uJ6YuVAcIbGoE6yQh1WT3bMyvckIQM7tPtRiZVk/4G3yf3oq24SDmH8MXO 32Zwky0OmCWtrZEoE0F9UIkzd/Wwn1yINgdGxIOPSIMzxogmdIQT9DI3cadVgSPH5YVG ADQ7dMqj91mZBpPTdJXmyezifJvRA7Opv1t34TasjPaf+hhyfEpnembhmWh+IL7XV7M7 2WT9Bn+r8CZVYaIpVuUYnjlmN5cWF4xL5XGCL+aifEAqdxtPk0QA2FYJe7GZUc4O+osh xBYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VFj6Lo8l; 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=O0lEvNva28UrVpLYBt4cPNwg6wKXY+jZL1rN13EDJp3Lx/nYzPF1vltq7h+PhyEd8s mEaLtSKSQgpl0QOIptBfmAldwCvsuZGT5rQCJ2DnFMUtKgesLNt4AI4uslob4ho4loGY NIU8qsKiLlZPlm3Yh8RNihd93GrEvA+NPUVFU= 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=cb8rmgLQmMWQJEU5QmF8CivzGonpgckUQgFDTMDCG/y6e+13dWUODYDiB/IoQkxBeU 7HFuGeWb0PakepG+mEgQtw2eEyWLeCrDSufGXfr0stbH0pCsrb1kC4p4SfMaoIMRfDig mwVFcMYYmbIW2lq6wHkTqTlzxFFNMWZdR8MYpu99FoWTnThMu9MgiCLVReA4pml4aSiK 78IoE6oLHLzfAT6oP+8H4AOihLRmymHeJ+Wfsr3LGP1pcx3nibfag0c/Vhj3tPCMdHAo X4T4T+FQHYaD2PXi1pXAjabXH244FRwvVldbbp1ywd7oF/JBtzugQkEd2Ts/VtceW1S0 O+gA== X-Gm-Message-State: AJIora+Errlo0Mxg2wmptZgJYFROJwZBNRSAkZZkb8L6Lcx1jgJkK/YF mjJyLGzQ5EW0pt/GvdbH8UniJHC4 X-Google-Smtp-Source: AGRyM1t2DpDgnQqvSSeoDhlSMySj/EGyff41Niera4HLf/MLqD6D70fSBYU+xW69krkuCGk4DS25Sw== X-Received: by 2002:a05:6402:3301:b0:43a:9ad4:633 with SMTP id e1-20020a056402330100b0043a9ad40633mr2895064eda.261.1657696611528; Wed, 13 Jul 2022 00:16:51 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:16a7:b0:718:c04a:5161 with SMTP id hc39-20020a17090716a700b00718c04a5161ls1931067ejc.11.gmail; Wed, 13 Jul 2022 00:16:50 -0700 (PDT) X-Received: by 2002:a17:907:3d94:b0:72b:54bc:aa38 with SMTP id he20-20020a1709073d9400b0072b54bcaa38mr1955565ejc.679.1657696610119; Wed, 13 Jul 2022 00:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696610; cv=none; d=google.com; s=arc-20160816; b=qwM8Csx0McYPmbHW8hoGSkHSNdgD1fM61gjVzcL2HoRxu5S123E/+62zQ7qHEDp8OF bAJd0Wt89Q4nT0nc2utHhTa7jQPGPLGD6HDeuZvZ9hip490N+iQcGgu6I5hPFE5qCw1U 3GaoQ72vScaxvul/iaisfa0esoGhbEHNFhIAe89O9etLV+s2czDqMm3ySzOtwdffcVbh D7Ni1sIu+8ejAv+i2McuokvGsS8nIyX0U/MFkN/VjY1WiQP2Q+KNbtscHOtQgnZMO8f+ jfQALE1qnJrRnqyTS3NvEHO6V3t7ylGmTtE5M3McL42VkIA0UOkdHVYkyFA6hdavPYeS qUaQ== 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=U5bZaPXeo93mXen6txe72EU3sfqLDNYjDDMLInc1jU6ac6CL2FQUsAM+7O5IOnfEQh ZY+95UhImrRGxz5fk+BQnvCZc3j8ZuKy8UWe9VCnEzs5gYj7NyrepIUAPAYMSMuez+dk +2b6/z+wjZvzTGaUz64MXY1OHTExNc6MzkdMACj2ZXDwntDx6hGqsS/MYprGdQIPXlEO TL523eBcsiFIk+3jE/kc6o/mgqdMKjxvjRc7y6gazViX9ht07gWD+JX9ktVsWeIIoGEY vnvN6x6WYwPCGqrdM8TR0IQ1A13jHBTajVwkIBIOsx+syCNRW8naeQ+E+WwZfmpLcMlX L8SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=VFj6Lo8l; 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 y88-20020a50bb61000000b0043a5410aa13sor4692542ede.1.2022.07.13.00.16.50 for (Google Transport Security); Wed, 13 Jul 2022 00:16:50 -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:6402:270b:b0:43a:d89e:8c2d with SMTP id y11-20020a056402270b00b0043ad89e8c2dmr2809596edd.413.1657696609755; Wed, 13 Jul 2022 00:16:49 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id z41-20020a509e2c000000b0043a95981050sm7414523ede.79.2022.07.13.00.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 00:16:49 -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 09:16:35 +0200 Message-Id: <20220713071637.275456-2-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713071637.275456-1-michael@amarulasolutions.com> References: <20220713071637.275456-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=VFj6Lo8l; 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; From patchwork Wed Jul 13 07:16:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2126 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 12E633F066 for ; Wed, 13 Jul 2022 09:16:55 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id ne36-20020a1709077ba400b0072b64ce28aasf2583450ejc.3 for ; Wed, 13 Jul 2022 00:16:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657696614; cv=pass; d=google.com; s=arc-20160816; b=EFnpimORr37BcQHSjkLiCVRurXw/XzKB/swE+MNrZtQBjM8/MXazNbi9SEwbtJ5zhb Gvsm/7m8XFEaVS+43UtUFq/McVnZwfDwlssQW6/3YD0qpd2PDa4nIrPFPcOaFuM59I5C Wp0mJOaSC/gDt/zsXcBn9ZWw/FDj6pJUgskPpda5wbpxkJfI0yo5uYzgEevWGbcvbn8+ D+ENw3XukDjyxv4TcInmm6CmieIm3o6AtWhPWFXBhJvxwEmfkATgHRSrwN4daemm0hf5 I+sHHxEzjZkh1qExk2II1iRSPFBlBiUSIF0UOqu8mT5Zdxpvawdf/JQAqtmHwKuBnyaU qLlg== 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=wilx1cJ3Q91m/NlChT8WG1/k99hqsAYd4TVg/efHXsk=; b=yRZRgGROda5h5GarG4dLoEJTGNYy0xUya6aJ81RhFG3nxBlSMaFEdloayCyxZydVt7 cQK9TbDUBqa2omMHn6vMre2kJ2+4nTQkkyU0EAUxFomSMXV5cIolZtKdAKSsV+U+gS3b uncWKstf/qLoFzjo3J72n+v2tGe2OY7goqcY55hGrb0On4jsugpnvqYXJt/h3fVXBH1l opK0oeqZvcxxHYVDnybTO/ecZ68mt3uM+a9a6+rOLfSNj5qzu0UhDoGlA2rwbQOPUAsi lKl0toEG9YLOs8wSt3uCvAfXCe/RkOhDjf6Uxt3sfbqGPSqgvmpXMiIJHb99jSUtw76J bTug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NrBUgsrm; 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=wilx1cJ3Q91m/NlChT8WG1/k99hqsAYd4TVg/efHXsk=; b=mf9gYATXp4ZXLOGbFFyI030UwzRqazv77vvobssxFtyFliCPfucuS9NekvcpR+w+Cz Yip65i3hu5DdMuNWRKllof2XkGTaWfrXWMcIf+OSCAxKtD5m/DFq2TVudE7rRUvFA+Fq gnUpv8/y9uEaap3spwNzKI5YobaPQzIcaDIY0= 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=wilx1cJ3Q91m/NlChT8WG1/k99hqsAYd4TVg/efHXsk=; b=xg+S/zRGdnWCuLEG4qaEGUW83fSjvl5R4BnOIaB+rGsMCCD9HT9wRIsMBGzRLgD8A6 nomBAtGwcBCnDewFHmwD/fC+RTDze85TVSul90qTfF9jPfShYHrvPWg1kGy5gJhdv2QM QFP08XIknt+stYtpDwdNYjw2oMt5TlN/9VZRSqLt1sx4tlHPIYRYQtdF3RhIYesMRiEs tOBMoxcxlnBCtaZXg4KXYpAlfiLiTwQeHJlIMFEFh6ZU06wE6Pdw9GPY0vTT/Xvv0OwR nh2izRnzREi8hIVMAA/CeHpl1uQhJZ40KBHMJNUqloJAIms7LGqVgurzETE86ne/W96u JtQw== X-Gm-Message-State: AJIora8ynVr2ukyJ8pZUT+H7KMwEKMw9sE07gQWOT7lwQZ3aRnppDUtk G/w76yEKvmJjtXsjNzDWeeTcUYZS X-Google-Smtp-Source: AGRyM1tAXFoXGZtgnAKBJn/CYFcxHFJOiNimYmCTql3kHItoFHPBLjtQoEhYCqOLmCiDxG8YnpwR9w== X-Received: by 2002:a05:6402:5202:b0:43a:a238:61c with SMTP id s2-20020a056402520200b0043aa238061cmr2889452edd.186.1657696614814; Wed, 13 Jul 2022 00:16:54 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:35d5:b0:43a:7724:247e with SMTP id z21-20020a05640235d500b0043a7724247els218345edc.2.gmail; Wed, 13 Jul 2022 00:16:53 -0700 (PDT) X-Received: by 2002:a05:6402:ea7:b0:43a:ecea:76e with SMTP id h39-20020a0564020ea700b0043aecea076emr2874259eda.77.1657696613342; Wed, 13 Jul 2022 00:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696613; cv=none; d=google.com; s=arc-20160816; b=n5BawQbSbnvkecURWG5FTecDBB3Tl9H+h4oG60n9xZGYnM8dQx57z3RQ+C4OKygaxT OX6r5PicV7MG11ZgPZEqBRlxjof9vdTzPpZhOTKiDBAJM71UIHba1JBWiLaQ33Gi6Sud /0aBlTrj3z2ldAW/UFB1hZbyb3OWpfNPTf5MFzAg90f+Me8A95AWsMUAfPksA74YAiyy iGYGPKAOE/Oyhs1ZOIaKdBOEW9Q6apWgOJLtgLvGkw/mvw/XPPdEQOTEQzPZu2didxvq /paKjH4O/Qv4C5In9GhEjxmTaIh/FPEWHAS7fdpOiEMF3fqo7jDpY8VBqd4VcvVFSw0Z VcmA== 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=gJVGkB2EpFxqz1nkyX65cKT4A6W6dwwPZ79Io4s/HMI=; b=Z49cxtpZEsBvXpA52goJusGKdeZvFBsZzalWfdLTxOrIkXvzWIpI4rfZQrwZWcRmRQ 8jh3iOQiAN0xQ/PeECxBUmXc26XAxufhq7BbhFC/AmnkVZZKoAGSS8gV4xdi/t2R/BLv 5CbRg3iwmnC3NUiOXVLXJAUe83E8+MYG4wEIzN5zICKOjV5oyYTO/Jw/GaNFJd0VYfuh UlUD1nj96Pb03QkzXyM0dzUenPB9NSVFcVlR0MI5UA/m9GOckj2q0qKsSM6fVcFKysVW uz2o3pLpuc9b+wTP6mXwdoTdarD/7CpbchxWbtlBNtGc2eR2d4N+HYKAMKS9b6BuNspW Orrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NrBUgsrm; 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 fg22-20020a1709069c5600b006efdb7394eesor3577153ejc.99.2022.07.13.00.16.53 for (Google Transport Security); Wed, 13 Jul 2022 00:16:53 -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:720a:b0:72b:549e:305a with SMTP id dr10-20020a170907720a00b0072b549e305amr1879704ejc.691.1657696612936; Wed, 13 Jul 2022 00:16:52 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id z41-20020a509e2c000000b0043a95981050sm7414523ede.79.2022.07.13.00.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 00:16:52 -0700 (PDT) From: Michael Trimarchi To: Dario Binacchi , linux-amarula@amarulasolutions.com, Tommaso Merciai Subject: [PATCH 3/4] mtd: nand: Add manufacturer specific initialization/detection steps Date: Wed, 13 Jul 2022 09:16:36 +0200 Message-Id: <20220713071637.275456-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713071637.275456-1-michael@amarulasolutions.com> References: <20220713071637.275456-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=NrBUgsrm; 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 abbe26d144ec22bb067fa414d717b9f7ca2e12bd A lot of NANDs are implementing generic features in a non-generic way, or are providing advanced auto-detection logic where the NAND ID bytes meaning changes with the NAND generation. Providing this vendor specific initialization step will allow us to get rid of full-id entries in the nand_ids table or all the vendor specific cases added over the time in the generic NAND ID decoding logic. Signed-off-by: Boris Brezillon Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/nand_base.c | 86 ++++++++++++++++++++++++++------ include/linux/mtd/rawnand.h | 30 +++++++++++ 2 files changed, 100 insertions(+), 16 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 6d8b892288..02789789e9 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4276,6 +4276,39 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) } } +/* + * Manufacturer detection. Only used when the NAND is not ONFI or JEDEC + * compliant and does not have a full-id or legacy-id entry in the nand_ids + * table. + */ +static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip *chip) +{ + /* + * Try manufacturer detection if available and use + * nand_decode_ext_id() otherwise. + */ + if (chip->manufacturer.desc && chip->manufacturer.desc->ops && + chip->manufacturer.desc->ops->detect) + chip->manufacturer.desc->ops->detect(chip); + else + nand_decode_ext_id(mtd, chip); +} + +/* + * Manufacturer initialization. This function is called for all NANDs including + * ONFI and JEDEC compliant ones. + * Manufacturer drivers should put all their specific initialization code in + * their ->init() hook. + */ +static int nand_manufacturer_init(struct nand_chip *chip) +{ + if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops || + !chip->manufacturer.desc->ops->init) + return 0; + + return chip->manufacturer.desc->ops->init(chip); +} + /* * Old devices have chip data hardcoded in the device ID table. nand_decode_id * decodes a matching ID table entry and assigns the MTD size parameters for @@ -4376,6 +4409,26 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, return false; } +/** + * nand_get_manufacturer_desc - Get manufacturer information from the + * manufacturer ID + * @id: manufacturer ID + * + * Returns a nand_manufacturer_desc object if the manufacturer is defined + * in the NAND manufacturers database, NULL otherwise. + */ +static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id) +{ + int i; + + for (i = 0; nand_manuf_ids[i].id != 0x0; i++) { + if (nand_manuf_ids[i].id == id) + return &nand_manuf_ids[i]; + } + + return NULL; +} + /* * Get the flash and manufacturer id and lookup if the type is supported. */ @@ -4384,8 +4437,8 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, int *maf_id, int *dev_id, struct nand_flash_dev *type) { + const struct nand_manufacturers *manufacturer_desc; int busw, ret; - int maf_idx; u8 *id_data = chip->id.data; /* @@ -4446,6 +4499,10 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); + /* Try to identify manufacturer */ + manufacturer_desc = nand_get_manufacturer_desc(*maf_id); + chip->manufacturer.desc = manufacturer_desc; + for (; type->name != NULL; type++) { if (is_full_id_nand(type)) { if (find_full_id_nand(mtd, chip, type)) @@ -4475,8 +4532,7 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chipsize = (uint64_t)type->chipsize << 20; if (!type->pagesize) { - /* Decode parameters from extended ID */ - nand_decode_ext_id(mtd, chip); + nand_manufacturer_detect(mtd, chip); } else { nand_decode_id(mtd, chip, type); } @@ -4492,12 +4548,6 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->options &= ~NAND_SAMSUNG_LP_OPTIONS; ident_done: - /* Try to identify manufacturer */ - for (maf_idx = 0; nand_manuf_ids[maf_idx].id != 0x0; maf_idx++) { - if (nand_manuf_ids[maf_idx].id == *maf_id) - break; - } - if (chip->options & NAND_BUSWIDTH_AUTO) { WARN_ON(chip->options & NAND_BUSWIDTH_16); chip->options |= busw; @@ -4509,7 +4559,7 @@ ident_done: */ pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", *maf_id, *dev_id); - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, mtd->name); + pr_info("%s %s\n", manufacturer_desc->name, mtd->name); pr_warn("bus width %d instead %d bit\n", (chip->options & NAND_BUSWIDTH_16) ? 16 : 8, busw ? 16 : 8); @@ -4542,28 +4592,32 @@ ident_done: if (mtd->writesize > 512 && chip->cmdfunc == nand_command) chip->cmdfunc = nand_command_lp; + ret = nand_manufacturer_init(chip); + if (ret) + return ERR_PTR(ret); + pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", *maf_id, *dev_id); #ifdef CONFIG_SYS_NAND_ONFI_DETECTION if (chip->onfi_version) - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, chip->onfi_params.model); else if (chip->jedec_version) - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, chip->jedec_params.model); else - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, type->name); #else if (chip->jedec_version) - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, chip->jedec_params.model); else - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, type->name); - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, + pr_info("%s %s\n", manufacturer_desc->name, type->name); #endif diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index f2c6a978cb..57fe7fb47b 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -796,6 +796,17 @@ nand_get_sdr_timings(const struct nand_data_interface *conf) return &conf->timings.sdr; } +/** + * struct nand_manufacturer_ops - NAND Manufacturer operations + * @detect: detect the NAND memory organization and capabilities + * @init: initialize all vendor specific fields (like the ->read_retry() + * implementation) if any. + */ +struct nand_manufacturer_ops { + void (*detect)(struct nand_chip *chip); + int (*init)(struct nand_chip *chip); +}; + /** * struct nand_chip - NAND Private Flash Chip Data * @mtd: MTD device registered to the MTD framework @@ -897,6 +908,7 @@ nand_get_sdr_timings(const struct nand_data_interface *conf) * devices. * @priv: [OPTIONAL] pointer to private chip data * @write_page: [REPLACEABLE] High-level page write function + * @manufacturer: [INTERN] Contains manufacturer information */ struct nand_chip { @@ -983,6 +995,11 @@ struct nand_chip { struct nand_bbt_descr *badblock_pattern; void *priv; + + struct { + const struct nand_manufacturers *desc; + void *priv; + } manufacturer; }; static inline void nand_set_flash_node(struct nand_chip *chip, @@ -1016,6 +1033,17 @@ static inline void nand_set_controller_data(struct nand_chip *chip, void *priv) chip->priv = priv; } +static inline void nand_set_manufacturer_data(struct nand_chip *chip, + void *priv) +{ + chip->manufacturer.priv = priv; +} + +static inline void *nand_get_manufacturer_data(struct nand_chip *chip) +{ + return chip->manufacturer.priv; +} + /* * NAND Flash Manufacturer ID Codes */ @@ -1120,10 +1148,12 @@ struct nand_flash_dev { * struct nand_manufacturers - NAND Flash Manufacturer ID Structure * @name: Manufacturer name * @id: manufacturer ID code of device. + * @ops: manufacturer operations */ struct nand_manufacturers { int id; char *name; + const struct nand_manufacturer_ops *ops; }; extern struct nand_flash_dev nand_flash_ids[]; From patchwork Wed Jul 13 07:16:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2127 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 6845A3F066 for ; Wed, 13 Jul 2022 09:16:57 +0200 (CEST) Received: by mail-ej1-f70.google.com with SMTP id nc23-20020a1709071c1700b0072b94109144sf517528ejc.2 for ; Wed, 13 Jul 2022 00:16:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657696617; cv=pass; d=google.com; s=arc-20160816; b=dNoxUa4pQOSDdZsKMlSG+8eZrzX7L29ottCseS6NEagUbDal484LsNvE3yZQEArwTi EIQW3MbG9bk6G5Ogz5Ajbt76GVlChrhFvwARiDwkXM1LSNCN2PhYRWLdCarqjWWDLRpN avXM5mIq52wrYJh6XkuGaXfERLyI/Xc73iNfGv5mej0mfPDS1CFxM1pBkZz/ODNOsDFP 1Ytz0WtM5lvwVAvkNPKmCsUrFTNQpMKIkpr3BvXvoTbS1qA35Nk0OEtXntIHTWYNarpj cesusH4OQvSsoHASvMMJ0CnOXSZoNy5ChSsGk19szNrGgvc7OcCN6RrzJBgGeUObMqGl IHKA== 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=IDg9TVVrpq+dfJeFyjw/2BnAHX3YoQO88cP55qPELH4=; b=Ky+0npze7Gv8zSoUOU9T/a8VHWV5WjclHrpkARaCMU8EMia3E3gewI3gQ5C7YjY7oY kXqGI25JWFKEHPHo4Ded0VPCd9nQteuwHHQ9qKgRgeR7QldK0I2nVqR03doaI+4fH8cT Y4N4pM7Ykxx0NHDGXxMd6+5VUvaDWSO6WXTdilTnzHVKNHd6euo/+1UpP/nZyXlXXw5N Oup02nGaX1oh+t6FhKccTsjEp/jX9oku5vXLQawku0s9kmw3/x8bT9YLL2vhUDu3bgcG yUFLAjbulfBhdcZKS0C27Zs2qQUJse5ZHNStZhr1GSvZzuzTghZkBIc3iB54KThOQyJP oXhw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fizIRujx; 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=IDg9TVVrpq+dfJeFyjw/2BnAHX3YoQO88cP55qPELH4=; b=HFaQiMXdv3Gl4ugvhyd7ni4yBNBqYFmi82ZzCuf3BjVsKMj9/Bx5fVeVUsEtybg7Jz aTU+XGdWmbD/491+VRIQIdiuQMC1F/TYzAwGItzzHuKr2TMt34rZ3Qw8VRUhLTyv0XVJ F6kMzJNVYl3zXv2poI2n9iY1HPo03j5zPNP4A= 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=IDg9TVVrpq+dfJeFyjw/2BnAHX3YoQO88cP55qPELH4=; b=fLhEUtDut7ZdSNiL2+BUpuNHqSe4Jd7VPGa90lbEiEgvwwE0kxTQJiaZcltKtzI32c ZS4oeZisja0Um77WovMnj3rB23Q55LcosLeR2wrTSWTsfrN2J729AOblozluiEIzqdTa TOgm2fe1hVw26zdre+67V750PA/F9yKjnZ8QlfEN4NZw1kVrBYRH6+fUODerHTVUI6tP mehJLVV3SfVCua0Y2ItqUXwEn09lTbZeSiAm38mChPQZXyBt5wOfogaZeMqoqQrDPS+e VTWbX+CW5WZbWZbauMYfm3DwyE6oeEtcp9SIjY4bZDQcG+XdZJzZflaZ2LTDs/fiVbQy zRtQ== X-Gm-Message-State: AJIora//RfAiQTBQDrsSMsiUQSbuXEzh4jgsEmwn59bm7jsDIdTIV/uF qvPGIAhEr3sVr+n96w1LBdvzK0yx X-Google-Smtp-Source: AGRyM1tUzdJh19g4rsGrF0/Nuc+OQZoI0Xo+GfzSl4gYS93OS9JLEweDFZErKRiQIGUnatJHAnONJA== X-Received: by 2002:a17:906:844f:b0:72b:549e:a654 with SMTP id e15-20020a170906844f00b0072b549ea654mr1891888ejy.535.1657696617189; Wed, 13 Jul 2022 00:16:57 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:42c7:b0:43a:82dc:c2a2 with SMTP id i7-20020a05640242c700b0043a82dcc2a2ls218568edc.3.gmail; Wed, 13 Jul 2022 00:16:56 -0700 (PDT) X-Received: by 2002:a50:e613:0:b0:439:fd34:32db with SMTP id y19-20020a50e613000000b00439fd3432dbmr2871049edm.291.1657696615849; Wed, 13 Jul 2022 00:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696615; cv=none; d=google.com; s=arc-20160816; b=CvagBQ7yFnHPopnVUWwUt+i06dNglG1pNXFrBSttAp2PJVeIfbq+as7GVzAmy+9na5 osUvDTNmF8YlnKRe968RUaqBdUnvs/nddKtXsp02guYHAGWYhqnPKwyfGhwVtuOrQn51 CtQmBKgvufK9vNJulOZbv2ELiq4mcqLc8oP8U8+wUPH8IJYyDolBPGEUgaCkeAkGklfo vG4iIH3cAaftQQ1FyIk052YyFDcvBgALijH8yHB6rCyyrKp3V/Sf/8awgyqYIVugo6c7 eQts5G5uE/ZkZnZXPF4AZQgU/S3K4iRm5mJcbOMMT5s0U3GWz2+r2zdoTCLKGoRIaWTj iEVQ== 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=IMfmcXJgLF3QxDo3zzC10MOLmmWWh43Nj1jajYbOo2c=; b=c8cGLW6j+dPzBUXglUxWiMOu4rXUO6EzB/n7DBJpuC33ynmBGyDn6V0wHsXIqazgTO VyIEymD2bk21PFNvNbBDljYzcBsDvuPfeAEzqv1CVj9NN+Rpy9Xe7AHIUfPp4Zjh+Mg2 P6Da05MK0OzZZ+Efpb482KSa2H5v36ld07iDcY0HLFvnIHgFjG8xxFuB+DdnQftku2as /pjcQU6wW9eTeId1w0m5wjKk4J5KSRXmiAhbGwyin2RZfvlY4Pu86FsaNG4BfWY0F8x8 ZcVRgL7bnoxi4MaGyU5aycCsJp/vNVf23qE9BrdzxbFFONu/xZHvXUGl0PmcvpCq0AF4 Ht/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=fizIRujx; 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 g19-20020a50d0d3000000b004396590144fsor4651712edf.43.2022.07.13.00.16.55 for (Google Transport Security); Wed, 13 Jul 2022 00:16:55 -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:6402:438f:b0:43a:cee2:a081 with SMTP id o15-20020a056402438f00b0043acee2a081mr2815913edc.298.1657696615550; Wed, 13 Jul 2022 00:16:55 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id z41-20020a509e2c000000b0043a95981050sm7414523ede.79.2022.07.13.00.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 00:16:54 -0700 (PDT) From: Michael Trimarchi To: Dario Binacchi , linux-amarula@amarulasolutions.com, Tommaso Merciai Subject: [PATCH 4/4] mtd: nand: Get rid of mtd variable in function calls Date: Wed, 13 Jul 2022 09:16:37 +0200 Message-Id: <20220713071637.275456-4-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713071637.275456-1-michael@amarulasolutions.com> References: <20220713071637.275456-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=fizIRujx; 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: , chip points to mtd. Passing chip is enough to have a reference to mtd when is necessary Signed-off-by: Michael Trimarchi --- drivers/mtd/nand/raw/mxs_nand_spl.c | 2 +- drivers/mtd/nand/raw/nand_base.c | 26 ++++++++++++++------------ include/linux/mtd/rawnand.h | 3 +-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/nand/raw/mxs_nand_spl.c b/drivers/mtd/nand/raw/mxs_nand_spl.c index 05886fa025..29c25f774e 100644 --- a/drivers/mtd/nand/raw/mxs_nand_spl.c +++ b/drivers/mtd/nand/raw/mxs_nand_spl.c @@ -83,7 +83,7 @@ static int mxs_flash_full_ident(struct mtd_info *mtd) struct nand_chip *chip = mtd_to_nand(mtd); struct nand_flash_dev *type; - type = nand_get_flash_type(mtd, chip, &nand_maf_id, &nand_dev_id, NULL); + type = nand_get_flash_type(chip, &nand_maf_id, &nand_dev_id, NULL); if (IS_ERR(type)) { chip->select_chip(mtd, -1); diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 02789789e9..06f066c5d6 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4152,8 +4152,9 @@ 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) +static void nand_decode_ext_id(struct nand_chip *chip) { + struct mtd_info *mtd = &chip->mtd; int extid, id_len; /* The 3rd id byte holds MLC / multichip data */ chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); @@ -4281,7 +4282,7 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip) * compliant and does not have a full-id or legacy-id entry in the nand_ids * table. */ -static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip *chip) +static void nand_manufacturer_detect(struct nand_chip *chip) { /* * Try manufacturer detection if available and use @@ -4291,7 +4292,7 @@ static void nand_manufacturer_detect(struct mtd_info *mtd, struct nand_chip *chi chip->manufacturer.desc->ops->detect) chip->manufacturer.desc->ops->detect(chip); else - nand_decode_ext_id(mtd, chip); + nand_decode_ext_id(chip); } /* @@ -4314,9 +4315,10 @@ static int nand_manufacturer_init(struct nand_chip *chip) * decodes a matching ID table entry and assigns the MTD size parameters for * the chip. */ -static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, +static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) { + struct mtd_info *mtd = &chip->mtd; int maf_id = chip->id.data[0]; mtd->erasesize = type->erasesize; @@ -4399,7 +4401,7 @@ static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, chip->onfi_timing_mode_default = type->onfi_timing_mode_default; - chip->options |= (type->options & NAND_BUSWIDTH_16) ? NAND_BUSWIDTH_16 : 0; + chip->options |= type->options; if (!mtd->name) mtd->name = type->name; @@ -4432,11 +4434,11 @@ static const struct nand_manufacturers *nand_get_manufacturer_desc(u8 id) /* * Get the flash and manufacturer id and lookup if the type is supported. */ -struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, - struct nand_chip *chip, - int *maf_id, int *dev_id, - struct nand_flash_dev *type) +struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, + int *maf_id, int *dev_id, + struct nand_flash_dev *type) { + struct mtd_info *mtd = &chip->mtd; const struct nand_manufacturers *manufacturer_desc; int busw, ret; u8 *id_data = chip->id.data; @@ -4532,9 +4534,9 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, chip->chipsize = (uint64_t)type->chipsize << 20; if (!type->pagesize) { - nand_manufacturer_detect(mtd, chip); + nand_manufacturer_detect(chip); } else { - nand_decode_id(mtd, chip, type); + nand_decode_id(chip, type); } /* Get chip options */ @@ -4724,7 +4726,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips, nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); /* Read the flash type */ - type = nand_get_flash_type(mtd, chip, &nand_maf_id, + type = nand_get_flash_type(chip, &nand_maf_id, &nand_dev_id, table); if (IS_ERR(type)) { diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 57fe7fb47b..d8141cb4d1 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -29,8 +29,7 @@ struct nand_flash_dev; struct device_node; /* Get the flash and manufacturer id and lookup if the type is supported. */ -struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, - struct nand_chip *chip, +struct nand_flash_dev *nand_get_flash_type(struct nand_chip *chip, int *maf_id, int *dev_id, struct nand_flash_dev *type);