From patchwork Thu Jul 14 14:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2157 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 ED2383F013 for ; Thu, 14 Jul 2022 16:02:28 +0200 (CEST) Received: by mail-wm1-f69.google.com with SMTP id bg6-20020a05600c3c8600b003a03d5d19e4sf808505wmb.1 for ; Thu, 14 Jul 2022 07:02:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657807348; cv=pass; d=google.com; s=arc-20160816; b=mz6jcAVRrXghP6g3vnMITIaZ6xLCpp1lWoMnwN1VWiQ502wLC5tnacscJ932yPp9rp 6YfklzgoZDJmux3wCF5fgplhYOW8sV1b7qOjqx+cCpy/AOoKMiOp4rVnP1rEIcy8PkuE Ao0+gA/IZgK+zzrd0B7E6DpglShKHAbGXr3hFG/dSfxBQInWmDNqAi5dVyuVE4kgHIrw Dqr5UuimCQuwCjfjfFCbsc/+nqzB588kG4nDasRR349wkznjZk9WlZegsgxutvAReExf 6OvnkoXaYuCxaCZZBmt60gGUQEZir19EBSfdfXbdMbSdtMooAr5nSWi7mPMYF3GpXb5t 0IIQ== 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=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=lsR1+jUofuZ/yeoM6pP2MIMGu39ku7WSGeYqs1eGCiezln+2NnHifjiJ3bmWwWoCA0 /b69q5wSY8mkNkrW3mt8GVOqofX7I0Qa7uZl5GnHqIu2rPFpBLi4uJ9kg3r5ZaQ2L3vo p3vSW5mYexMFGY57axW0dPDCkKQnVa+bqfM0cfSZAZFTk5jr1g15QY+EUqKdRpqQjMCW hWauh4ghWLJcbWU+mfC10ouYwPoAwqWW3bdKpe0jTDEY72GIPnbxeXlOEny+jUFVWNIL 89OIumJHbJpBKEnbBPb7jSiiICphKGtgrj+NGpNhOe487sifqzOqDa1bqvZsPhdkjGWC UBig== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dniUdoR4; 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=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=BJL+wkH5zeUE1Viq3Vy676Kkj464O5nkI62iGXyHx6tVrIEZy/4+KWTibjRArXiJwE fxr+iifSr9dgfjiSrXTyTaqAUOA2nQktGBhAyVL1gWKSCREwxekfLwOWP547TL3nsrDV wCRJN1xhVuY0lwM5QPlXcxNamMFUimioaFffw= 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=Z+M1ItdFJHYx2BwAoYAsuhoRsY+QaBLWxfpo4/jPYQA=; b=JdCjRal3KCoDeiXFLUsnegGmgdGABtvYqaLSOcvHvDcyAIS3zEcaqES8DCiP9BnWcq P0DvE+oOTOdgVDTzMtSZBx3J9e3Y4teD19HV931fqLirx9tBcMsO9/EDNwSdSKXlYL44 NeJ2u6oa1NObrRJyUQPbRAK+QFR8Tv1n4I31Nkl62jAWdXrpmtOZyLu1pcfd9sB4/pGN 9twWhUGpwdup055AJCqD1aE0tKwYgzthIfbhqxxyMxvkdfa+o0pCPjdAM0XtkQf6+m5O frqX1/oT8UCnSylZjU8PFsmB8smlZtEGzSY7gkUC/S5noMrImImfNcM9TG3PJMBu6ULR Hzag== X-Gm-Message-State: AJIora8Pf9Km4woTJSAw+aZK80uMu5SxliP6AWpBFQPkcWbo67NzcLLD Ytq5f4EJMIfK59NkIRkgorcZgVh5 X-Google-Smtp-Source: AGRyM1tCS6oDReHBUgxZJZ/JsayCQBygunng3Ys5t1jJLroX9/OAbkm78nKF+mtFaDBvQY5+A53syQ== X-Received: by 2002:a05:6000:2a8:b0:21d:8c81:7eb0 with SMTP id l8-20020a05600002a800b0021d8c817eb0mr8222954wry.460.1657807348670; Thu, 14 Jul 2022 07:02:28 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6000:1849:b0:21d:9b2c:2273 with SMTP id c9-20020a056000184900b0021d9b2c2273ls109673wri.1.gmail; Thu, 14 Jul 2022 07:02:27 -0700 (PDT) X-Received: by 2002:a05:6000:1d86:b0:21d:6433:1455 with SMTP id bk6-20020a0560001d8600b0021d64331455mr8608262wrb.514.1657807347256; Thu, 14 Jul 2022 07:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657807347; cv=none; d=google.com; s=arc-20160816; b=xBYhxt2HozvwszBhpA9zeGKGWUY321EfqsJghGl8ofOgf9Hw+A3Z6gp+g7tQ8hbZfU N9dhM/6qu923VBQmFYR15uhXynjkHPUVuOVpJUIn+SsWeIsUnRfr9EYa9kQxmvuNrArT lBgM1H/EnYbx2X76fAjqdsovfZuIAhCyk1QKsfRiK8FsqNajF4MNBmzsBaFpgvkTbZSd ZMR3U/9Y3SGAUVpkduLmEZm3m4SX0recI94MKK+M3VVnQo+Uw9v0MeAEF3y/tTEh8bxa tx4EqZb7DTLFdDinCFOQIpeD4+5X3Q8TXaE+xN67/aSy2AEczg4884VH73u4ZSlnBXB0 W5Ag== 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=7/o+mGV8ywUVtQz4G7CKHG/IM0njUkMjI+CMpXHKhCc=; b=cFag3tq6XGY3Ao0f0gZagSmWdXG2BDVtMqTA7UMn7qnLfT7HizdGcWSFE4Zq5MB4qL ahJk/jdDLyE0t4H7fut6+NFvywj4eUfEm25NGTyuMpyrT7PUtkXOfHGMrEYBTzznrwP8 R1ntAxug2ioK2V7BX+XDYIHQtBhG0zNYKpkvQCG3tP4XKCHhEpGlVRglQm891SWtkltL y/Gvz99qdfAjWqPPv9fTlUayMLLPLO7Moje3Nf7g8uVK4+UktJ7aL02mLLwqfUbZbw7y OqkrUQ/1OiuznfaUoMQ92pLTws7BtzmBTCqquGuxnBQC3AH8D/eAOnUY3O7RDisWKxNA kb2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=dniUdoR4; 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 k13-20020a05600c0b4d00b003a2d3ee66c4sor1294739wmr.13.2022.07.14.07.02.27 for (Google Transport Security); Thu, 14 Jul 2022 07:02:27 -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:a1c:4487:0:b0:3a2:fb76:7981 with SMTP id r129-20020a1c4487000000b003a2fb767981mr8879995wma.98.1657807345961; Thu, 14 Jul 2022 07:02:25 -0700 (PDT) Received: from panicking.. ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id k11-20020a7bc40b000000b0039c5cecf206sm2029114wmi.4.2022.07.14.07.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 07:02:25 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH 03/11] mtd: nand: Add manufacturer specific initialization/detection steps Date: Thu, 14 Jul 2022 16:02:07 +0200 Message-Id: <20220714140215.444993-4-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714140215.444993-1-michael@amarulasolutions.com> References: <20220714140215.444993-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=dniUdoR4; 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 | 90 +++++++++++++++++++++++++------- include/linux/mtd/rawnand.h | 30 +++++++++++ 2 files changed, 102 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 4a78770a25..3b9c78cb24 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4286,6 +4286,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 @@ -4383,6 +4416,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. */ @@ -4391,8 +4444,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; /* @@ -4433,6 +4486,12 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, return ERR_PTR(-ENODEV); } + 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; + if (!type) type = nand_flash_ids; @@ -4451,8 +4510,6 @@ 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)) @@ -4482,8 +4539,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); } @@ -4499,12 +4555,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; @@ -4516,7 +4566,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); @@ -4549,28 +4599,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[];