From patchwork Wed Jul 13 07:16:36 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: 2126 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 12E633F066 for ; Wed, 13 Jul 2022 09:16:55 +0200 (CEST) Received: by mail-ej1-f71.google.com with SMTP id ne36-20020a1709077ba400b0072b64ce28aasf2583450ejc.3 for ; Wed, 13 Jul 2022 00:16:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1657696614; cv=pass; d=google.com; s=arc-20160816; b=EFnpimORr37BcQHSjkLiCVRurXw/XzKB/swE+MNrZtQBjM8/MXazNbi9SEwbtJ5zhb Gvsm/7m8XFEaVS+43UtUFq/McVnZwfDwlssQW6/3YD0qpd2PDa4nIrPFPcOaFuM59I5C Wp0mJOaSC/gDt/zsXcBn9ZWw/FDj6pJUgskPpda5wbpxkJfI0yo5uYzgEevWGbcvbn8+ D+ENw3XukDjyxv4TcInmm6CmieIm3o6AtWhPWFXBhJvxwEmfkATgHRSrwN4daemm0hf5 I+sHHxEzjZkh1qExk2II1iRSPFBlBiUSIF0UOqu8mT5Zdxpvawdf/JQAqtmHwKuBnyaU qLlg== 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=wilx1cJ3Q91m/NlChT8WG1/k99hqsAYd4TVg/efHXsk=; b=yRZRgGROda5h5GarG4dLoEJTGNYy0xUya6aJ81RhFG3nxBlSMaFEdloayCyxZydVt7 cQK9TbDUBqa2omMHn6vMre2kJ2+4nTQkkyU0EAUxFomSMXV5cIolZtKdAKSsV+U+gS3b uncWKstf/qLoFzjo3J72n+v2tGe2OY7goqcY55hGrb0On4jsugpnvqYXJt/h3fVXBH1l opK0oeqZvcxxHYVDnybTO/ecZ68mt3uM+a9a6+rOLfSNj5qzu0UhDoGlA2rwbQOPUAsi lKl0toEG9YLOs8wSt3uCvAfXCe/RkOhDjf6Uxt3sfbqGPSqgvmpXMiIJHb99jSUtw76J bTug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NrBUgsrm; 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=wilx1cJ3Q91m/NlChT8WG1/k99hqsAYd4TVg/efHXsk=; b=mf9gYATXp4ZXLOGbFFyI030UwzRqazv77vvobssxFtyFliCPfucuS9NekvcpR+w+Cz Yip65i3hu5DdMuNWRKllof2XkGTaWfrXWMcIf+OSCAxKtD5m/DFq2TVudE7rRUvFA+Fq gnUpv8/y9uEaap3spwNzKI5YobaPQzIcaDIY0= 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=wilx1cJ3Q91m/NlChT8WG1/k99hqsAYd4TVg/efHXsk=; b=xg+S/zRGdnWCuLEG4qaEGUW83fSjvl5R4BnOIaB+rGsMCCD9HT9wRIsMBGzRLgD8A6 nomBAtGwcBCnDewFHmwD/fC+RTDze85TVSul90qTfF9jPfShYHrvPWg1kGy5gJhdv2QM QFP08XIknt+stYtpDwdNYjw2oMt5TlN/9VZRSqLt1sx4tlHPIYRYQtdF3RhIYesMRiEs tOBMoxcxlnBCtaZXg4KXYpAlfiLiTwQeHJlIMFEFh6ZU06wE6Pdw9GPY0vTT/Xvv0OwR nh2izRnzREi8hIVMAA/CeHpl1uQhJZ40KBHMJNUqloJAIms7LGqVgurzETE86ne/W96u JtQw== X-Gm-Message-State: AJIora8ynVr2ukyJ8pZUT+H7KMwEKMw9sE07gQWOT7lwQZ3aRnppDUtk G/w76yEKvmJjtXsjNzDWeeTcUYZS X-Google-Smtp-Source: AGRyM1tAXFoXGZtgnAKBJn/CYFcxHFJOiNimYmCTql3kHItoFHPBLjtQoEhYCqOLmCiDxG8YnpwR9w== X-Received: by 2002:a05:6402:5202:b0:43a:a238:61c with SMTP id s2-20020a056402520200b0043aa238061cmr2889452edd.186.1657696614814; Wed, 13 Jul 2022 00:16:54 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:35d5:b0:43a:7724:247e with SMTP id z21-20020a05640235d500b0043a7724247els218345edc.2.gmail; Wed, 13 Jul 2022 00:16:53 -0700 (PDT) X-Received: by 2002:a05:6402:ea7:b0:43a:ecea:76e with SMTP id h39-20020a0564020ea700b0043aecea076emr2874259eda.77.1657696613342; Wed, 13 Jul 2022 00:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657696613; cv=none; d=google.com; s=arc-20160816; b=n5BawQbSbnvkecURWG5FTecDBB3Tl9H+h4oG60n9xZGYnM8dQx57z3RQ+C4OKygaxT OX6r5PicV7MG11ZgPZEqBRlxjof9vdTzPpZhOTKiDBAJM71UIHba1JBWiLaQ33Gi6Sud /0aBlTrj3z2ldAW/UFB1hZbyb3OWpfNPTf5MFzAg90f+Me8A95AWsMUAfPksA74YAiyy iGYGPKAOE/Oyhs1ZOIaKdBOEW9Q6apWgOJLtgLvGkw/mvw/XPPdEQOTEQzPZu2didxvq /paKjH4O/Qv4C5In9GhEjxmTaIh/FPEWHAS7fdpOiEMF3fqo7jDpY8VBqd4VcvVFSw0Z VcmA== 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=gJVGkB2EpFxqz1nkyX65cKT4A6W6dwwPZ79Io4s/HMI=; b=Z49cxtpZEsBvXpA52goJusGKdeZvFBsZzalWfdLTxOrIkXvzWIpI4rfZQrwZWcRmRQ 8jh3iOQiAN0xQ/PeECxBUmXc26XAxufhq7BbhFC/AmnkVZZKoAGSS8gV4xdi/t2R/BLv 5CbRg3iwmnC3NUiOXVLXJAUe83E8+MYG4wEIzN5zICKOjV5oyYTO/Jw/GaNFJd0VYfuh UlUD1nj96Pb03QkzXyM0dzUenPB9NSVFcVlR0MI5UA/m9GOckj2q0qKsSM6fVcFKysVW uz2o3pLpuc9b+wTP6mXwdoTdarD/7CpbchxWbtlBNtGc2eR2d4N+HYKAMKS9b6BuNspW Orrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=NrBUgsrm; 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 fg22-20020a1709069c5600b006efdb7394eesor3577153ejc.99.2022.07.13.00.16.53 for (Google Transport Security); Wed, 13 Jul 2022 00:16:53 -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:907:720a:b0:72b:549e:305a with SMTP id dr10-20020a170907720a00b0072b549e305amr1879704ejc.691.1657696612936; Wed, 13 Jul 2022 00:16:52 -0700 (PDT) Received: from panicking.amarulasolutions.com ([2.198.242.86]) by smtp.gmail.com with ESMTPSA id z41-20020a509e2c000000b0043a95981050sm7414523ede.79.2022.07.13.00.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 00:16:52 -0700 (PDT) From: Michael Trimarchi To: Dario Binacchi , linux-amarula@amarulasolutions.com, Tommaso Merciai Subject: [PATCH 3/4] mtd: nand: Add manufacturer specific initialization/detection steps Date: Wed, 13 Jul 2022 09:16:36 +0200 Message-Id: <20220713071637.275456-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220713071637.275456-1-michael@amarulasolutions.com> References: <20220713071637.275456-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=NrBUgsrm; 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 6d8b892288..02789789e9 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4276,6 +4276,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 @@ -4376,6 +4409,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. */ @@ -4384,8 +4437,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; /* @@ -4446,6 +4499,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)) @@ -4475,8 +4532,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); } @@ -4492,12 +4548,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; @@ -4509,7 +4559,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); @@ -4542,28 +4592,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[];