From patchwork Wed Jul 13 11:06:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 2130 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 9934D3F066 for ; Wed, 13 Jul 2022 13:06:25 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id f13-20020a0564021e8d00b00437a2acb543sf8073074edf.7 for ; Wed, 13 Jul 2022 04:06:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657710385; cv=pass; d=google.com; s=arc-20160816; b=0c/t806NQLDJw5pHaBI+1y8z7ms1Fcy9Db3YnVzaFigWgjwTX3KxPkRQ0AzsAH37x5 3zPqfYJUgpr9QiKzGlDi4xod/qkYwU5sOIwhQoIB5cSj7OEWxvK8DBdkDKxTR3vFH8xD j3eCiKLwoB/DYzyGFYGioLmINHR1e33cNukC2VSG2R8ovMHpI9hmUGzbDCUXODN9ARqN 396vlDHzGFuy62qxEE7/hvHvM0pbMurOjYKnLxOM6PsSiCmwh/wGR0VW6a3Pj/grwTbx Z4neAbAJ8d/K4rUVt0MT74fmqNooRZ4vt6XBypidIm6C+CAajkusetuRCfZ86UXT1d5k r/hQ== 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=b1IHRYnDEyvn3k/n6sa6jiCIYOI8teZsswOQj2t8xNI=; b=RgYF9Qj66beU2voVDHDqU/1M3J0MXJ25mdfuKxXVkGtd0MW0vxRz3KA5nOgUApAD1w F9s78X9H3+e2dFg5CKYuNsxPRt2txAnmnhmDmfpBPPlqQJjeb/Wsh+9UHwlJWz47yumq 9l/6Y+SbAtspOqbZ4IOF/BLxmwgOcdRrhmm80kWxGzMiHGIsBrlfMv0NjcjOnsnlq5x9 4kseb8srhXu8u+ydlb/lH67VmwIfdlEb6ox65ozb5t0vQKzqKe/9otqm000nEPWbACan zgq32VYxqkVgPsjnyBuWJ4rUOBgpXmV+O5Mbqt+OxIklq2wy9L3eH5A8QEHPEcU5jxPy yhVw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=FS5wJehs; 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=b1IHRYnDEyvn3k/n6sa6jiCIYOI8teZsswOQj2t8xNI=; b=XAS1ZRiBqApwv7GHnHpRb66418QjKMFJyGKRBUJDcllJD0gxUqeU2TvubgAd7Df0Sd 5sBhxGsMxpr5ig6gQaIDu6OlmqjabZD/fqGci4I6LnkNF1gKNM4I9Mt0/HrLOTL2MUDF bFErigaAE82/cPj9OOi3eQCc/qI9IkTzolw9w= 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=b1IHRYnDEyvn3k/n6sa6jiCIYOI8teZsswOQj2t8xNI=; b=7j38u52EyJCB0YVOazrBrw4J7gGW6d2PQnxSS/uTUdvnsATdSDlR814srZyNAD34al R2po7SxSjKSsH5RGLnYyYg+qn3qKPRYQK+f+Qkn4zljXYZs3SwDHLg8iaUeogaWwWg2P 6BSXIq3vcn+yv/HBEeSDl2svtwpOIsFAvI6w0LH6VM2YBfasXANvSSaFmirL5EwwYxoi /4F/bUpZFEbnRmuGDDvOKmpR1B+qUVuhcLrgSUBA+sz45mpiUEZgfC+6dSygY4m6KaMd OFFV7kgVP/GVXWiJiWbMUgHP/GnfbT68uW+To5Ynt7HO0Zwo0q9z2VGaXxMtZZ953ya7 tg0g== X-Gm-Message-State: AJIora/+4kCMB5S52R2G3d2fOOOfguoOrb6+WOAtLLoK+440TDWCBrsr HDAcXEVhKBQm8dfuGPlS0VV5mV6K X-Google-Smtp-Source: AGRyM1sav66f3dsuY7tfBlnnPYMPS4MrM4QAnErq3DbKvW7PToyUxWYkVskA4LUQMQqwF8l5p0VvsA== X-Received: by 2002:a17:907:2c68:b0:72b:3a2c:e5b5 with SMTP id ib8-20020a1709072c6800b0072b3a2ce5b5mr2806520ejc.619.1657710385408; Wed, 13 Jul 2022 04:06:25 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:1c0d:b0:72b:7c6f:2e73 with SMTP id nc13-20020a1709071c0d00b0072b7c6f2e73ls2593851ejc.9.gmail; Wed, 13 Jul 2022 04:06:24 -0700 (PDT) X-Received: by 2002:a17:907:6287:b0:6e1:6ac:c769 with SMTP id nd7-20020a170907628700b006e106acc769mr2944835ejc.388.1657710383978; Wed, 13 Jul 2022 04:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657710383; cv=none; d=google.com; s=arc-20160816; b=GlnFXvitngf4IL9Q2auFYHAgxkZAtJw4bkAhJRh6MupzYciA01xjgumjDb0zVdr6Pf aP3mwEhH8WT4AqaOPTco+RBrI31wZpMUQ4fBf+JBor+XdinbTwiz2RIVP6vAOcm53rO8 vFYa3hSmy7rtny+7l0Npl5Vpan9jbg0ln956uuMMNv7kVVx08td00b2TpDHkwtKJ//6d ZkiMh2kzDWj7/9Lv+qn1wDvOPSjZIwwGZnD9bdN7OvMj4VAKv60H6p0i3LEiP1JQJqf9 y+ZeUS9GPeXkoe/4JKqgZupyybVDaoabHDkG/0iEs7lInwVuUZaUq698Uww+o4uu33y7 kkCA== 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=3zfc72Q9ZPrMWX2d8HLpfnVU/ABDFmB8Hclz+8wfWmc=; b=N3vpOCMjBRnECma0ZzacPO8NHECHX6cVLu8Sr52S65UA46DJmRlBA006uONRS8BD8S IDxJ/W48ptPSv2RcdV5QCtP5ElwWP0l+D1XOMQoCjVuqfrpu6nHFGAWAW7UEHHTmKIeC 8BtDf1YC1Y8z7JaBiU8mplmkrHp+hUXoQqvdX5xvfx64x8PDF73OI0nw8+I0RvluBXM/ Rpx6Eg9nyl9NKVFGnaLzu65WtwZwUiBGrJdBn9YDBdwYeOqCAJIDI5iwbdWgwf4L6Ti8 2d9//WTBOFY88+F4B180KpFfa0DEj1OlAWGs0Rxdv6lHOftUFDDQQLDO/pL3DYAurHSc nYOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=FS5wJehs; 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 h4-20020a50c384000000b0043573b35f10sor5123171edf.64.2022.07.13.04.06.23 for (Google Transport Security); Wed, 13 Jul 2022 04:06:23 -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:2cd:b0:43a:70f7:1af2 with SMTP id b13-20020a05640202cd00b0043a70f71af2mr3982587edx.357.1657710383211; Wed, 13 Jul 2022 04:06:23 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id fg16-20020a1709069c5000b006fec27575f1sm4830767ejc.123.2022.07.13.04.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 04:06:22 -0700 (PDT) From: Michael Trimarchi To: linux-amarula@amarulasolutions.com, Dario Binacchi , Tommaso Merciai Subject: [PATCH V2 3/4] mtd: nand: Add manufacturer specific initialization/detection steps Date: Wed, 13 Jul 2022 13:06:15 +0200 Message-Id: <20220713110616.305444-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713110616.305444-1-michael@amarulasolutions.com> References: <20220713110616.305444-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=FS5wJehs; 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 0c0e4fbb6d..d58451196c 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4282,6 +4282,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 @@ -4380,6 +4413,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. */ @@ -4388,8 +4441,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; /* @@ -4450,6 +4503,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)) @@ -4479,8 +4536,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); } @@ -4496,12 +4552,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; @@ -4513,7 +4563,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); @@ -4546,28 +4596,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[];