From patchwork Thu Jul 14 07:51:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2145 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 C6DDD3F013 for ; Thu, 14 Jul 2022 09:51:41 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id z14-20020a056402274e00b0043ae5c003c1sf985081edd.9 for ; Thu, 14 Jul 2022 00:51:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657785101; cv=pass; d=google.com; s=arc-20160816; b=Ai41rQnStM+ic01W6Sg+spfOGYf10OMTC2S4/c3DCe0kHkYWrMt5aI41zQS++9Zjrz Py6Q9pP6MhzZm9scPL5s/XCgVxuR9jt4Rne46b1w7lNpkrJIgqMACC8Ha31HKP3XCHvL 9+OjtvTxo4+jqrjvvfSeiydlcyU77fXIzHywREYw6H867bkuk/BD9mA3N1LSdXSEQE9f KHQaPgLkZA5kkufk10xHxFpyN+uwfMcarIBfrz8tk5cmBfohwRWCWUFznvm2wl2x1pMi ZSjvvOvAQxx9NEIcbuHCIs7Q9ujPhXoa00M5SmSRTqCMPbvrDGjhP0+gr3pvPyxaNnBl xyuw== 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=JpXqIHIv235h6o++wG12BeZEvn5KaWZoPpEUGWFr7cE=; b=qqSh4vd4hYdh8xwYNMFizC1/XsuBmWy+ve2TgzHX6e6DhqmXL2lJZ7douQXS69NuIp i7PtdnxS70eQBjR93wkrdIA0NaE/6IX4o4s++wrxvwPwXVNA1kwRmO60dlf5xBdY924g pwzuh094s8izAXLQ5Q0evEeorSa9lpPdPwllxs3wxclWum/Cmn4UDC7QfasbXr2tOPQl yoA2E4YngdJiX6OHfg+bDKifIx6YtGNu/7Hg4wMjebZzuBRWptFazmKhGAI9WPEVi0gq KPGk6PxRvSXrw53GAqbepQnmEHWA+elR8ZxcCJC+k8XWNndA2VIeAGRLDhhib0t6Czeb x/2g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pnztSpIq; 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=JpXqIHIv235h6o++wG12BeZEvn5KaWZoPpEUGWFr7cE=; b=JnJO5K0khAjOHHHdGPCt6/BQOUZ9rwivd3/7xH6XZkvWVJoq+Q9Rh07yCV/x38URDC HKcQUiet3FZrTpR/DVP4Xtj54i8w7276bG+xwIuMXwJoxp5E7IXMxmkVi2jgP5OHfDWU 8ABA9vxRMq7mxnoQ20PHXfHqKF23jPOULXr8E= 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=JpXqIHIv235h6o++wG12BeZEvn5KaWZoPpEUGWFr7cE=; b=nOcmQYzcub1pRlq1IQRn9q/ykaB77hVFoJfojadEHmYiiEsrDkJoXBd98NRW5hPBEm 3RrgyXh6gqrn0/rhJA1YyyhZMe1Qe1JQIlRt5IePxLisPZWhsxZdJhippZNEyd7WjwbJ FzDoAPjqhCDwRmqw4/SOIRH7cXTpUvbDgKQKS7GBcskdJTmb2OOOC5RNw0QAbKpjqji4 M/0ojW1A7JppkpVCNKgKaBuzldUnPWIVse/vztQh8jG9oU/f0GmXSuu+u8Rpzr8tfR+J uHOlEMGBtvkwL2zW6ZAFH0xvQGQiHjDHmRfwd1WthjBSmFkneFGDgrzKHewu0QSfMfhL 7UHQ== X-Gm-Message-State: AJIora8jK8fW80RYUN5f5YThD4Xh5GbZ1yOhWvxzneluCxAC/6aHkE3W nfsc2WamdZetaq+zMtrC9zc3YFGr X-Google-Smtp-Source: AGRyM1s3pOg8AwpLOZEXglUgAIgZJmIc3FQirpM74YOKTmntY0LpCVMf+J2W0y8tQpFR/hNGIWri+A== X-Received: by 2002:a17:907:6e02:b0:72b:9f16:1bc5 with SMTP id sd2-20020a1709076e0200b0072b9f161bc5mr6609690ejc.676.1657785101486; Thu, 14 Jul 2022 00:51:41 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:7f27:b0:72b:6e70:8c8c with SMTP id qf39-20020a1709077f2700b0072b6e708c8cls2307209ejc.10.gmail; Thu, 14 Jul 2022 00:51:40 -0700 (PDT) X-Received: by 2002:a17:907:3e07:b0:72e:e1e2:1415 with SMTP id hp7-20020a1709073e0700b0072ee1e21415mr952080ejc.596.1657785100097; Thu, 14 Jul 2022 00:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657785100; cv=none; d=google.com; s=arc-20160816; b=k5mBz7pPn3QxjU+YZWUvLVWr1WR80M0SlEicCO3z02AsBbywFm7NTjBNYGeipGgZso oqZsdQiAYxvXYycFR4l8OX+7o35kdMsPsoqS5VBae2jAj9Beh2C3WveJQ7gqbitqMXnt ej01nJ96snCUZsmBJxLhKKy+/SrFcT9v6PAsweEXbpJ5rPCpZLSwE639P97ViaPfdJzI enYRiJn//kjREjpPr7zh6I1qls7IxX1UJ9+pJN6+wXVWzPwPE31QGc7SlsrBxB12+2eW ZNM25EZ+x9Q3g773Y/AaV7665Kc89SPNjkA2IlYmkPiRLk42jwdSC+pfCBNbZCMh9nNY ck2Q== 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=ygNrYdotaJQDkfnb9m1VDTVvYwwV3uPyyciPN0sEPOM=; b=ZyJtK377KfM8zOP7KDY3/o9QrftjJH+EfoWxzktMIdl/U1hRNbzORa+fwGOeDyrhL5 4CNQg9wz29mOkwpfng5KZyaGwCqUSp0AzWsrw4dsOj87LDbh1u9ZjODQeVHrFklj6XPt lKga2lAuuxnjpesvK7N7rXhwIDkK8CrqgfqrOOMfSbd5lAX/2jycsF7jQcOdqcMTvqfz Qxtwmlx0l4fReA3N9SI4wuariHVVbAxeSrTYE0Qrkv6UJ8UzumC96TM21fnnLIgz/609 8mPyHK262G6u/VY5UYVCVi1RtKZy0Iww69CzwIg0ivlYwDg3gmeRdzvLHSiUWKJCHZlF UeMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=pnztSpIq; 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 hq26-20020a1709073f1a00b006f3a0bc0cf1sor313287ejc.128.2022.07.14.00.51.40 for (Google Transport Security); Thu, 14 Jul 2022 00:51:40 -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:28d4:b0:72b:49c0:d04a with SMTP id en20-20020a17090728d400b0072b49c0d04amr7613123ejc.141.1657785099346; Thu, 14 Jul 2022 00:51:39 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 00:51:38 -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 09:51:23 +0200 Message-Id: <20220714075131.411548-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220714075131.411548-1-michael@amarulasolutions.com> References: <20220714075131.411548-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=pnztSpIq; 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 6e964275e5..d9024432b7 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4278,6 +4278,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 @@ -4375,6 +4408,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. */ @@ -4383,8 +4436,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; /* @@ -4425,6 +4478,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; @@ -4443,8 +4502,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)) @@ -4474,8 +4531,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); } @@ -4491,12 +4547,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; @@ -4508,7 +4558,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); @@ -4541,28 +4591,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[];