From patchwork Wed Jul 13 17:11:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 2141 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 725FE3F066 for ; Wed, 13 Jul 2022 19:11:24 +0200 (CEST) Received: by mail-ej1-f70.google.com with SMTP id nb10-20020a1709071c8a00b006e8f89863cesf3666631ejc.18 for ; Wed, 13 Jul 2022 10:11:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657732284; cv=pass; d=google.com; s=arc-20160816; b=gtlW6RMIyY63N9ngbs0kMTMJwyRY9dMCS7Rd+MRv4ffp8KNcFc373PfuY/wjbXfHDO a3qbW822ymjOqOG3vJVTWq48aO2tCKKlaTsPyxcAX1v4KtLnkZtAQN+XFOl4Uxs9lIR0 2U6uZ3qH3hqRFQt5VTZhlsOrchuFnTR2x7CHBkHBjnh1dOHqiFUBVOEs65XLD98Li1cb XkHJ0wo/suCr26KWMrf6FTfydmBYB6gGTzyK1oxX0y+IswOEeGLA74ACKsHUMBymUfyG 5I3+z3qCKgNv7cBFPQfivtyCBKGZv9cPOt78iItWcQ1aRQSdmwWg2KcOwRiek75/vOxu IdCg== 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=DU2TuxvTenvLWiGypuF8wkXdXV23FrkD0mAB5f7YPMmpX7R8R4d+5pSdHTc8wkclY0 XqRk+87zVjNXpUCIyOfdQ/uK3N/KiJpyr0ntYDJ4A6HOPqUoEUMXHGem2GeOC6x6ABzO tiXc3HZUsufLdcHFRzf527pZaX3PabYFP/s9Co67ttxq3wMXDatAR7nonRbOG5Bp0B0N /fJjL/kH7qg5q1JSZ1xl8F/qVLKV0mvdyY/F6aAz88LJrqCURpJ/gZFQlIqxHOk1HbVH 3zSwac1Oz7sOj9TCsknkFdhbOotezK1ZqlSTWZURno7od/QV85NGJn1wr1jUVkmYgnGB zc/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ue9I7d2O; 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=LMPxHgapvw2rhXCtgjTjhiTwZD20bJcTEJfS7+VWdFo/eeRAMBTEWbHQvxsP1pII2n m/kgA31yIIu8pFUn2wR8vTukfTDfL/unRGUhNMsxXnAONu/F4Rm5vmF3MwK/OEFk3Qp3 enGISr3SA+aByiGJgojEpgo3RKQ/9PNp8Qsvc= 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=ZCAVbRgioHDlQCjmwPnvTtvbnqTyHVMGNadT9q+6f6MK5QhJ5V/e1M/L7h+K8/k3qR pflyrAiyFhupYilXoYW/j3HIXZNGDL+V4YG/mxY+7Cm6IbfTRYKrxmBCnLOPenad/yTd BCo1CCiNveexu9DGZgWj4i2BX+wDkL03lPgPBANDAw9D68sCenGWdLSZfWwNwZ0Nk0n6 R8tPe41lDtmlHBlUj/p1onQ3QWF4rurtt60qPDO4PyJzHDrEsX0svd5WYesLBd246Qhr 0ULwQQSANK7I2P4r1Y0r1E4QkMcalI2+lRbbAbNMEhx+0DkALfiTD2A7mPq/YLqU4TNp +R4A== X-Gm-Message-State: AJIora/tjW9iyn152c/o5PI60sCCkUM0mHyQNWj4chMR4rxrkaBmdUoo 5o0TkctjyfmIL8zVQbopu2VgB/9x X-Google-Smtp-Source: AGRyM1t+lOfkjdIcgqSH9OL11xFZwOrSD8lylaT3BNtLPJd/B8EMHszwpikPa0kL4cSn83AU79K4JQ== X-Received: by 2002:a17:907:2c4a:b0:72b:5b9b:9c50 with SMTP id hf10-20020a1709072c4a00b0072b5b9b9c50mr4601976ejc.636.1657732284250; Wed, 13 Jul 2022 10:11:24 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:7f27:b0:72b:6e70:8c8c with SMTP id qf39-20020a1709077f2700b0072b6e708c8cls1500463ejc.10.gmail; Wed, 13 Jul 2022 10:11:23 -0700 (PDT) X-Received: by 2002:a17:906:8a4a:b0:72b:5b23:3065 with SMTP id gx10-20020a1709068a4a00b0072b5b233065mr4462387ejc.557.1657732282836; Wed, 13 Jul 2022 10:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657732282; cv=none; d=google.com; s=arc-20160816; b=pJ070bXz534ZPSF1eLynsMaZdtiRfwDwMUBtB3t/oKFGprDK9pDz4JxILdel54L5B0 H7FLpvPE4AAWN+a1VbeDKdmJgm+0RZp5iuvj7nb9XG/Vf2eY/bQ1X16+04f3IJR8UZF4 BwpYzifmDhWqjorcFP2AC9X3n5WUBQfFpDPnnFWuCoxLHGlQ5dHUBGre6E1GV61nWYFN A2M7RIakJWyj7jofYy6z3rtD7Trhpv2wWUHbiPkxWD+Zj1hYP3GY3ixNZbN1RVkp79/j djG4sVpa8RmC/SwSS6OFU8dWfsWqxjfX/dtuF1RERiBTQSOvk/QgBRD7771UWmn+5oUp GPXw== 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=KuOTbzXpKl6XjIhGh8urrVHjE6Y/Of9FGNLl46Pn+S41ncs272lH2Rxliq/1zCJS7r 0ycWExl1zdLWVa4hsvsDkRMSx8UUdeIyqZqb8UZoWWFj3tDy8N0XXuh3gjB/0Ej7gIl1 6J36DeTP/pTaGAJzA1FeJEBRguMHWNPMduxUWRb0fxI77n91AeHi/m6pAFvxW+FXOOxB tsJzYE8FvCLiJRajFpPDGZ9oegAXvNoWRcTCP0Oj4fi92kaWcRsePfITQW9k4wjzXXIX m+OUc/HpT6fBKMMpP9zf0daXggSPH2+/nO0AxxfntTyjUYWjDN4XTEFYQW4L13YmnDw1 tzoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ue9I7d2O; 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 e24-20020a170906375800b00722e565b857sor4159805ejc.87.2022.07.13.10.11.22 for (Google Transport Security); Wed, 13 Jul 2022 10:11:22 -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:106:b0:715:7cdf:400f with SMTP id 6-20020a170906010600b007157cdf400fmr4562708eje.1.1657732282109; Wed, 13 Jul 2022 10:11:22 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 10:11:21 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH V3 3/4] mtd: nand: Add manufacturer specific initialization/detection steps Date: Wed, 13 Jul 2022 19:11:10 +0200 Message-Id: <20220713171111.337338-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713171111.337338-1-michael@amarulasolutions.com> References: <20220713171111.337338-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=Ue9I7d2O; 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[];