From patchwork Fri Jul 22 16:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2232 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 4F0363F047 for ; Fri, 22 Jul 2022 18:11:12 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id y8-20020a056402358800b0043bcb538b85sf1876694edc.10 for ; Fri, 22 Jul 2022 09:11:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1658506272; cv=pass; d=google.com; s=arc-20160816; b=LdYc0ZqtvyFAG71c4DlSQgz/IvlMxEkIXed2oxWeEqpHn7lA/xdh/Hy6n6omcPNBIJ kRdCW4ynzvUhKPYGRqlLxpzZIx/weLbsi1rimNnsRm/pnhjkydtpYc+u/ZPTUJeWAWHs RJf67ToF3zcJ439Wi/vaSXYJV+Z4C8Loa0Hp1hG+zAKZ0kesm5lZ3SLhjlgX5n0AoJTU 1/8bXVT4k6FadmnIyMcXvZbio7CwO3d3DDVGco7RQOhVSIrrsnQHVedQea3B/0xtF2+i /gI4H1UcRl8WT1AtYCUp41nq9CBTncIzmpPbQgJycrIcG8Xdnnqhbbd78eTiRlOa0/X6 h+mg== 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=m6D7wlV86Y4Eq1a1C1wH1C9fxPM+Xo3qaLWyerbMuX0=; b=HtV7hMSOcG8NXkSzCMdyKS0l4GLtdOzLYr2UY97pWUAPwhl/ZREmnbRpK8RzB2schz //0S3fcQFGHaBfTO11WHiAx/nWif0IhmsoortqQSC7YDD0Kt55wbE5DZ31vrteAf604k IFEJ8jOhPca3gIBxZaX3oTx83l9Thui9Mqu2RPRbMyi38x1drBjO7bv+eoS2nY2Gzn+U wn586t9Sh4Qj/FO1vZLQAlkX7xsrLbXQVsyCw+dbHilPUTA8Y7vDZ03UINwP3uYyokLX H+7hJbfqBU1y5RZrqH1M9lG1hiO/lzSjJnBLRSfKDNjR+kpu9vFW+ZFayyZEHDdacKtN QNqQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hFljHZBD; 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=m6D7wlV86Y4Eq1a1C1wH1C9fxPM+Xo3qaLWyerbMuX0=; b=qU8M/hz6mA4aaJRzsGv7jD6RTgnmPMYC7qCnPv+I0yItdt03yjEfNvxHuli5ZQ2xup ZPs9BpaCB/45qsvjS5JkPeTGgrD6Vtjtvqp+M88IqBIAGtZivlHUmGnenjHVZ6+V8KUu qaBqxOl+s6yatiYFZxm1L2+5nDP2pLnyjaT4E= 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=m6D7wlV86Y4Eq1a1C1wH1C9fxPM+Xo3qaLWyerbMuX0=; b=1MplmoJ7/f0Bf3AvDMNBwI20QGTDWLFWa0HKpwv9hBPAApxyEf+edAgNej5XL3qf+h mSuyiu8StJ2pUGGjzsB554iIKjkfs0HxE1RzfG0OPRlSR5cCaRvyo1Ezq/d3fBUr0Kpl +HzEUE/FJNqw9b6sGLnm7liF1uEt0rfnuuU46JUTWbAPU9QU0vmRnGv0fuVkvC/Yl5n0 nC/QXht/gP1jyOI3etVbOa34VEITisTHxbygW4oEmAE+RmgKfzyCf5pMX7RctNp2BzO2 ysODCKfMK3PzwzYFP0bG8Y83Ni0WM32i6RctcKqwuN44hhAOWqgbXL3chLfihsq5MRSc RGIA== X-Gm-Message-State: AJIora9uUB10pX4VAxdDUHsCajQFf7zzt9rtVZN+YB/c7n5gEcOeOfXh G60n/OI5/SWs7jMYFcXT6/5R9XX5 X-Google-Smtp-Source: AGRyM1s4Yrn8BbU5ARk4O2mF60+P1hL//T6tQHg9EhaV6z/S3jof9vdD5QyMAETTFw6xmvoe5XUKLQ== X-Received: by 2002:a17:906:ef90:b0:72b:9ce5:f016 with SMTP id ze16-20020a170906ef9000b0072b9ce5f016mr452287ejb.697.1658506271986; Fri, 22 Jul 2022 09:11:11 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:11cb:b0:43a:7c1c:8981 with SMTP id j11-20020a05640211cb00b0043a7c1c8981ls2106758edw.0.-pod-prod-gmail; Fri, 22 Jul 2022 09:11:11 -0700 (PDT) X-Received: by 2002:a50:cdc2:0:b0:43b:bb93:3a5f with SMTP id h2-20020a50cdc2000000b0043bbb933a5fmr632046edj.122.1658506270856; Fri, 22 Jul 2022 09:11:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658506270; cv=none; d=google.com; s=arc-20160816; b=QbW1cZZaFO83douq5S17zXFCiWi0sQTHsfrxR+/MCWeU4sQPDsvj+7kpj7yTGFOgLx JtSDYydYK46vUSDS8bPXGtFPrYHsBGJlLwi3+FrL6qPM2RFaGDTgGBSIcBqQLx/RIITb 2wftCUIVbaLV+dNyZKUGMphSSLxDgqVyKlenkpauG4Qm8ZJ388Z9squXIeg2yUtzddXC nKgLM9eXCfaQD0llDg0H2rb+1A/8e4wTAkRLTV//E/+uJ6fnjN1UbFewDZjxRxWd5bod PkQ8A0ebUh+3e2o4r7w5+syUMUj6Jqk56mjiy3xWHisgx36mgAdqY7ETjOJAdse16zIK 6j6g== 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=aNS64cmA9ulz6/dS+EH0hp8jY3RUzbjM0jzsDFdJ4xs=; b=WPyW9/H7W/vHVvEFMLjHak4hlr31EAw73Cvj1Iw72DW5f+qg/TdwPswdURy8FIH7yr iE46aYk1Gc8gk7bMsPuLpuIGpeeWBmVfgjmGkrsIyC5fGwpCR3C3m4UWmZi0dZKnHMpt P7qiye0uc3Y1NQA1m3F6Oxzr7aAbXQG4pP7AHRiCsmovG3x1eoXEfYE54Ck3pqam4nWQ kwwbUvk0GknAfzos+bkpSpYITe/ScZeH1cYtmZA9sTvK9JeslaYjBYM4Seonqj+dWhRt QHdLavy46YFx9/ujzR+TSQ99VcNt5IE8+ea5hiInm4nXv85oMcEKr+RluvNaXNexIG9c 4UEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hFljHZBD; 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 os20-20020a170906af7400b006fe8bef9830sor2095776ejb.108.2022.07.22.09.11.10 for (Google Transport Security); Fri, 22 Jul 2022 09:11:10 -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:907:94d0:b0:72f:269c:3aa3 with SMTP id dn16-20020a17090794d000b0072f269c3aa3mr443029ejc.695.1658506270456; Fri, 22 Jul 2022 09:11:10 -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 d19-20020a170906305300b006fe8ac6bc69sm2174025ejd.140.2022.07.22.09.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:11:09 -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 v4 03/14] mtd: nand: Add manufacturer specific initialization/detection steps Date: Fri, 22 Jul 2022 18:09:57 +0200 Message-Id: <20220722161009.2686504-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220722161009.2686504-1-dario.binacchi@amarulasolutions.com> References: <20220722161009.2686504-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=hFljHZBD; 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 --- (no changes since v3) 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[];