From patchwork Wed Jul 20 16:22:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2204 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 E8BF03F046 for ; Wed, 20 Jul 2022 18:22:34 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id l16-20020a056402255000b0043bbb1e39c3sf958563edb.11 for ; Wed, 20 Jul 2022 09:22:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658334154; cv=pass; d=google.com; s=arc-20160816; b=l5BCDX+YQwbiTFz6rLIMrOq698/rYIU0FzXlU2DJ6nRTxJ5ueowPNMglTwaVwo3Nk9 WB569DgFcObc3f19DEdUlwKJan0LrVW0zTrC0DsD43MRfMVRebd1izTlwaYUWIJx0Wew uiApHTzlW5ejEZAfaJg1d2Y3dgj27aEN8m7y3MMo/0dCAEbHDPNd1iGqc5rbzGYIhBMK UKkfwrjPracf2BnKRK4Q15C7KmQ2ktmL3qW8XvOZ0wfbte8Zc7vTzpA6xiYIfwiH/AYg J1VvVv8d8ZB6ERT44+TXaQlpYnhAhl24tS0LObETsIb5ZI+qDqyoUajRtOhPEw9uDec9 623w== 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:cc:to:from:dkim-signature; bh=uXjrM6x3VLuZWW+6dwlmiwT/M5BegrrLiW4c1UeKEgc=; b=wSJx6N+PkbQZYydRuRznLHhTgM99CtKNj8K9+u3mnPWoQBLexMnJ5Q/LCKQYaOCRSj EUq4MCeTvjk3W9HLy5aIfWqQCKJ3y20OoaNczkrDCDm33eGZMyiqHsnqbDi3MayzqIYw jYw75PQzn64wStgfZzH4Rtaocjp4PntWdx9VM5FG70Odt5/LUMXjVBMc2weW2fk0uNkA ivgMUJmT/JrXxYgab6r2n3G4K+PdjMUaPogPgeAROvGfdy5894RlKO+OmJ+jpU3UC820 wH5u/oEakZYByJDESTKhjfNq+oViWlo6RgkxYZzKiw2FjCGPDUTviQtJbmAHk9W09Cdn XFig== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oqtht8r3; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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:cc: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=uXjrM6x3VLuZWW+6dwlmiwT/M5BegrrLiW4c1UeKEgc=; b=FpCq9ulA+N02e2ycTUn1B3UXLnebdknGWb3XBTApilwfD+N/I+e0Fn5jx6ztRwMqG7 g0nhvCVOGVOSnUIobK5ydNE8/rLTDUi4kYoSVQWBEMdjxrTQpzc3uXlKh1sHA6VCms0O Vn/3w8de0ZUYddGPWneVHKssqnPdikTHmy6rM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc: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=uXjrM6x3VLuZWW+6dwlmiwT/M5BegrrLiW4c1UeKEgc=; b=oPwAa1nWuO407l4xkRUkxbvdLaiSiIyfXsUnQqg8ELonKaZXvVmpgvawfSZkrxZiXV 0X622l63MGZVo7F0AgXfpDPkGeQlSIePSdyesw3Q7jXsJLkBGw74WaomsqW+NApoFXRX p9+Blm9ap3qzpvNM1w2KzIHKXeC2TwrRyT3h/Q1/hSlxlHy5RR6KJnkfeqNBWftnsS62 xr5Vw5Ie7psWrLXksSKJEGf7lfgbktgUP6GZjO2fXR08A3iJYpqryd0nNviI9YjFZFaE P+ZBSV0Nek+X/I+2YIsiddiShK2gK5pqFysj7Zq8r6FBMIP9/Twz4wx3Arj4xnej0d2d AyIw== X-Gm-Message-State: AJIora/8wj91oNs6IsvinpvvXQi+AWSE7bVNfFjrcQa+xQmev/nZUSD0 J7oR/uOURYPxFwl/ryg8JNmtwe7p X-Google-Smtp-Source: AGRyM1uXxMxuoKyZeTSYBOm9KDT5jMqoGoF82Hk2EO6SUT1H2CEZulXBISkJhnPAyQP3upZe4rpXjg== X-Received: by 2002:a17:907:1b1f:b0:72f:56db:cce9 with SMTP id mp31-20020a1709071b1f00b0072f56dbcce9mr8173326ejc.605.1658334154557; Wed, 20 Jul 2022 09:22:34 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:430c:b0:43a:6e16:5059 with SMTP id m12-20020a056402430c00b0043a6e165059ls257166edc.2.-pod-prod-gmail; Wed, 20 Jul 2022 09:22:33 -0700 (PDT) X-Received: by 2002:a05:6402:3047:b0:43a:9e43:95e5 with SMTP id bs7-20020a056402304700b0043a9e4395e5mr51951967edb.385.1658334153476; Wed, 20 Jul 2022 09:22:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658334153; cv=none; d=google.com; s=arc-20160816; b=FIcrgwxHGDteBGDZj7S7et4aJn5iBOFYGvdENeGa9pZNxYAShBZICssovHO2EQZovx /mRcATDFMQCiVLYmPaL2jGLsJ48lKDtm8XjKytzqVJ7F9YnXkzqJvgwhcoU92yEwkB7c QNZw/vxQn/lyC1gClZGWwiW/7Otup0H5sWXNnxwDRoZXZKbdXGStxUqLQlgTRHwj+sW6 gQDGfQyQqFb6IlnRYfKhdNMjBftsyhM2Lhn5nfYEgmQZDBQdFleUUAnKmLhbCq0TVqH7 IYNZFyJ4m+5KkzFl3KbWg/YEqjanTg0oWD5a3ki7mNAdjBeRSd8y1tf2VBuv0SJkM+tD jz2Q== 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:cc:to:from:dkim-signature; bh=qaBOrJiZDoLWMMI8Ww/DBu1HH0fVqO05oj5JUuFlTh8=; b=eMULaHaeROSkOkNQJ3naB9BDOQdRigddXrrFfcxnhwrw8IgXyUjSmmcU3uKGTFDRDi yFmGdB2Oe46US4QzFjGsvy2sZFU1MejS53cRH29bMPcufgB7U5kwlqAOIJcNntfKVwC3 zKugsz3bygc7bowNnA3T1mS9ZNV5+o50Z/5+tjn2FxyKH41aYcnhqU0kaMW6QIwXM+Qh 3pQNw4kRhf4vXBTVfFMyqyKjLLu7ZnfWuqNFopfRi5BBWcQ7jpr3Yes3kYli93Y+gnzN WTBOdE+IVjImq6/2eS9BKkD2vUwDjMtern3alwZ/yhzEtEQmc1r+pHsg/dHuk0EEUsMc qbRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oqtht8r3; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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 w20-20020a170906b19400b007116546988asor6017337ejy.11.2022.07.20.09.22.33 for (Google Transport Security); Wed, 20 Jul 2022 09:22:33 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:84f0:b0:72b:72b6:c7b2 with SMTP id zp16-20020a17090684f000b0072b72b6c7b2mr35799851ejb.642.1658334153122; Wed, 20 Jul 2022 09:22:33 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (host-87-14-98-67.retail.telecomitalia.it. [87.14.98.67]) by smtp.gmail.com with ESMTPSA id jl10-20020a17090775ca00b0072ed9efc9dfsm8057839ejc.48.2022.07.20.09.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 09:22:32 -0700 (PDT) From: Dario Binacchi To: michael@amarulasolutions.com Cc: Amarula patchwork , Dario Binacchi Subject: [PATCH v3 03/13] mtd: nand: Add manufacturer specific initialization/detection steps Date: Wed, 20 Jul 2022 18:22:06 +0200 Message-Id: <20220720162216.2397616-3-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220720162216.2397616-1-dario.binacchi@amarulasolutions.com> References: <20220720162216.2397616-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oqtht8r3; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@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: , From: Michael Trimarchi Upstream linux commit abbe26d144ec22. 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: Michael Trimarchi Signed-off-by: Dario Binacchi --- Changes in v3: - Use commit sha1 with 13 digits. - Fix code style warnings raised by patman. Changes in v2: - Use short-commit form. - Remove linux info. Uboot seems that backport without add this extra information. drivers/mtd/nand/raw/nand_base.c | 98 ++++++++++++++++++++++++-------- include/linux/mtd/rawnand.h | 30 ++++++++++ 2 files changed, 105 insertions(+), 23 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 220804c75c87..0900e6dbf9a6 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,30 @@ 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, - chip->onfi_params.model); + 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, - chip->jedec_params.model); + pr_info("%s %s\n", manufacturer_desc->name, + chip->jedec_params.model); else - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, - type->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, - chip->jedec_params.model); + pr_info("%s %s\n", manufacturer_desc->name, + chip->jedec_params.model); else - pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, - type->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 f2c6a978cbf8..57fe7fb47bd8 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[];