From patchwork Thu Jul 21 06:44:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2218 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 5480944190 for ; Thu, 21 Jul 2022 08:44:55 +0200 (CEST) Received: by mail-wm1-f70.google.com with SMTP id v67-20020a1cac46000000b003a2be9fa09csf584812wme.3 for ; Wed, 20 Jul 2022 23:44:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658385895; cv=pass; d=google.com; s=arc-20160816; b=hHHqO++m8YUPufRg4yxhbyxIRA2I7cwMbspG7JItFn9sPdlTJ8aQjoxq0Ejz8A4Deb PxZ6ZEG435K3utNEVzhkSqXd7tE35USuwR4KZutinAgA+eI+FtVacKDZoDMevalRaNrG WogUb+JSfOCnaxN1G+4scwN+FNCpNcY2XoAMyyNIyfsluJvairZoFuXlQGS0coKI7EGo pbSjcFia5X9VQ865L51m7hue3YumUObXI6penTCx16CRX2bk+wxDAJX8Duq5v1RXrKFu x39+7abymSbP4LKlqMZCVME7VsSoY18k1xiwkO6XqmAQbCBQ7exS4NjIxh0rJYPJJ20z w2mw== 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=Jv9wUhY1Kkob0FB46vciQJoNhMvFlLjjltOW3o3oFEwbKmHWSX48WTnmMWAGckISh0 NkI5PuImXqbSfZRD61F6JRG9UNT6oUwQ6/jbW+nYtTYRfqmK5LLCWpEP/XRkxr476z6r rTf3WM3o4tfzdQ0R9n0jtZIqSa++xEo6qn0F+PSkNUodKpiygCQBEOh8ydWrjplkXwa7 6BuveqRtyinUOVuJec6bsNfNRkdM51WuoUpZdgNzY6K0bu5I5/rRnaY83PhRYDI30L7k HQ9W/S6MmAQUJjffsn1IJgttZfvmNFm1Px2cLVV9DWpdlLoUErf+QlsU5FmrQEg68ru8 PSaw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cuwYcSY+; 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=jv+OBUtkNshgDZY6H9zHumng5Qsmg8AtU8pXrx8Z+evk8Ou0ZmdPEO0UxOVuqm2lIa ywa2GGxX40tH0HD3u3z2umYv2T+lg4igWkR1vceIApW07UFwxCP0hfvPqterqCsKlnR2 QgGVqNirbKaFaC0I5tJDkk/IAfF6e0v8i8Z4Q= 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=7qbOBBcCt2lLH3XLpT2RDOxdPy5WkdFkJwmqngFYDI86N5s1dynb9t6HjVPKfGnrwa O5M/Wh+OGnaygDKFN1A/XA35ait/K+ccfta7Oe3Z2p9HF9QsEYltnq5cnX82vtEqlA7q HjWnEe0yAQpsUkj4Hy1Gd8QPZ2MT8rmPIkxmQhgpMzCwrI6RGyXurqt7m3uFPAlsA2sI tC4096WMDXsc1MwCnsY6oY4e0YVvzyIvT/qNi9N6FeLkdvjBw5PLl7MxeA/Qgl4Uruih 9cCr9I4jiHLDnyzbDimVHRDhA7C1yjq5pCPc0W6mLhxCr611H8hjvz9X6NyXyxRM+ltf 5VZA== X-Gm-Message-State: AJIora/2SGz1EXPv/VNYHXV8LOUggZI3vrq3ydB6GxB11uSuULlLxfs+ a+bU21inpayXj1FPDatGEIzvI2IG X-Google-Smtp-Source: AGRyM1vDXdZtrCrg0uRZac9Izs0clYHAiEUVRUl7TVPtY+j5TM7gC5XFekc5tY5WbLEyEEGEbvAnSQ== X-Received: by 2002:adf:ecc8:0:b0:21d:e148:64a9 with SMTP id s8-20020adfecc8000000b0021de14864a9mr22374955wro.518.1658385895095; Wed, 20 Jul 2022 23:44:55 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:adf:d209:0:b0:21e:53a1:af5d with SMTP id j9-20020adfd209000000b0021e53a1af5dls243643wrh.3.-pod-prod-gmail; Wed, 20 Jul 2022 23:44:54 -0700 (PDT) X-Received: by 2002:adf:d1c6:0:b0:21e:4f40:9029 with SMTP id b6-20020adfd1c6000000b0021e4f409029mr3621619wrd.719.1658385894061; Wed, 20 Jul 2022 23:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658385894; cv=none; d=google.com; s=arc-20160816; b=F9QF/n6UAwCycIeo2F1zq+D/gFRshkgPL+9X4hSitqspg39elW9DW3N2wEPxXra6GK p20l0/i0wlSF8bGddKO/bPlqmCguF4INtHVYbXId/3DydUwg8aQDKiihx4YcdVKAWUo3 BYVSnFyslznFNQNDdz/IZKU/ZAuSyQqeWlUhNwp/E9TRJ2UVnFNsKWAMZWinKHGE2PCq H4riU2qN+RoeGD87yDyzbH8mg6yVPcwa+qO6QSXq5/WrVESeD/h2WyM8SLRdsirk0tuH 2XZWAAfK4WkMrAmTOkeq6pY9Y48Mbr5GUpNrHp8KgnuePdsXV9rn+2jmYGs6W5DVP4b1 3kbw== 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=YxhGgs/4h82FIBhyghQcxpywVgoIWIqiQHnV0YlXoZPjuEdSr+033uTxItZry/ntIu 4qtowXX6CS3JRUtbVWIift5qCPra+4qvfZ8liAkFxzW0cvR7SXN+vxbdrJ5VNK4OSTY6 q85O1wSm6SLMlto9Lk5XieJZLiwLPVTM0XvRQI9M59uem/tkTe/XI5aNRmsOYbumSwOi xoYDGYXPR5lvdSYVKZwtjMFUgtkpLtawo46zjjobXOZy9gmimsc24RM+1IJXXU5AsbMR +cdjCwMrYX1++a7N8YTkffffIh25HDDXpkdP976s1Qhc9p2wTjaQuzEAJfKErENT8BDH x2oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cuwYcSY+; 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 l11-20020adfc78b000000b0021dc1558c51sor454016wrg.17.2022.07.20.23.44.54 for (Google Transport Security); Wed, 20 Jul 2022 23:44:54 -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:a5d:64a3:0:b0:21d:adaa:ce4c with SMTP id m3-20020a5d64a3000000b0021dadaace4cmr33211898wrp.161.1658385893703; Wed, 20 Jul 2022 23:44:53 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.pdxnet.pdxeng.ch (mob-5-90-140-42.net.vodafone.it. [5.90.140.42]) by smtp.gmail.com with ESMTPSA id c18-20020a056000105200b0021e4f446d43sm903711wrx.58.2022.07.20.23.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:44:53 -0700 (PDT) From: Dario Binacchi To: u-boot@lists.denx.de Cc: Amarula patchwork , michael@amarulasolutions.com, Dario Binacchi , Patrice Chotard , Simon Glass , Wolfgang Denk Subject: [PATCH v3 03/13] mtd: nand: Add manufacturer specific initialization/detection steps Date: Thu, 21 Jul 2022 08:44:25 +0200 Message-Id: <20220721064435.2456601-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220721064435.2456601-1-dario.binacchi@amarulasolutions.com> References: <20220721064435.2456601-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=cuwYcSY+; 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[];