From patchwork Fri Mar 2 17:04:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10255277 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E0D6A6037F for ; Fri, 2 Mar 2018 17:33:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE16C26E74 for ; Fri, 2 Mar 2018 17:33:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C289E26E96; Fri, 2 Mar 2018 17:33:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B99526E74 for ; Fri, 2 Mar 2018 17:33:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ctBTnAZkan0W83CSmBKc7t7eJl4sxcbXgMaJVkqkm6M=; b=JyroS7P6iI6STwn8RC6r7jEB3s 4qmOGVW/LyUb7DwuHjDVDZotnCzYDCH7ZafDQM7jGQn9WkF4JYA2vFGdqfvYnjASJAZLMzD0eQxa8 JsR/uCYJNmWP93isCCXK/whXoVXmcD8u/Zw3npl3IPA7+NvH620dxck1jXbrbym4aNS55504vaC6O 97jE4aFm6qkro/MNDffgrmMWlF5Y7rDtbvN1C/+vA5lRynGyq4sAGmRWYsgEnIjTWUdrnlwy9SqB9 Cdav4bz03+933dGMAHN8vmugIbh6JL0i6Ux1kxYIX2geFgbpxL7fcJfaitb5+FbFCAH3GUUI7PBA/ 7jr3UgUg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eroY8-0002xf-UN; Fri, 02 Mar 2018 17:32:53 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1ero7E-0002ak-RH; Fri, 02 Mar 2018 17:05:38 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 274EF207EF; Fri, 2 Mar 2018 18:04:48 +0100 (CET) Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id 3DE3A2091C; Fri, 2 Mar 2018 18:04:47 +0100 (CET) From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Cyrille Pitchen , Josh Wu , Kamal Dasu , Harvey Hunt , Stefan Agner Subject: [PATCH 52/52] mtd: rawnand: allocate dynamically ONFI parameters during detection Date: Fri, 2 Mar 2018 18:04:00 +0100 Message-Id: <20180302170400.6712-53-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180302170400.6712-1-miquel.raynal@bootlin.com> References: <20180302170400.6712-1-miquel.raynal@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180302_090505_921758_3B785D07 X-CRM114-Status: GOOD ( 17.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Miquel Raynal MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Now that it is possible to do dynamic allocations during the identification phase, convert the onfi_params structure (which is only needed with ONFI compliant chips) into a pointer that will be allocated only if needed. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 37 +++++++++++++++++++++++++------------ drivers/mtd/nand/raw/nand_micron.c | 4 ++-- drivers/mtd/nand/raw/nand_timings.c | 12 ++++++------ include/linux/mtd/rawnand.h | 6 +++--- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 82d52112907f..1b9fdf51ed8e 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -5100,6 +5100,7 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) { struct mtd_info *mtd = nand_to_mtd(chip); struct nand_onfi_params *p; + struct onfi_params *op; char *model; char id[4]; int i, ret, val; @@ -5154,8 +5155,6 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) if (!chip->onfi_version) { pr_info("unsupported ONFI version: %d\n", val); goto free_onfi_param_page; - } else { - ret = 1; } sanitize_string(p->manufacturer, sizeof(p->manufacturer)); @@ -5224,19 +5223,31 @@ static int nand_flash_detect_onfi(struct nand_chip *chip) bitmap_set(chip->parameters.set_feature_list, ONFI_FEATURE_ADDR_TIMING_MODE, 1); } - chip->parameters.onfi_params.t_prog = le16_to_cpu(p->t_prog); - chip->parameters.onfi_params.t_bers = le16_to_cpu(p->t_bers); - chip->parameters.onfi_params.t_r = le16_to_cpu(p->t_r); - chip->parameters.onfi_params.t_ccs = le16_to_cpu(p->t_ccs); - chip->parameters.onfi_params.async_timing_mode = - le16_to_cpu(p->async_timing_mode); - chip->parameters.onfi_params.vendor_revision = - le16_to_cpu(p->vendor_revision); - memcpy(chip->parameters.onfi_params.vendor, p->vendor, - sizeof(p->vendor)); + op = kzalloc(sizeof(*op), GFP_KERNEL); + if (!op) { + ret = -ENOMEM; + goto free_model; + } + op->t_prog = le16_to_cpu(p->t_prog); + op->t_bers = le16_to_cpu(p->t_bers); + op->t_r = le16_to_cpu(p->t_r); + op->t_ccs = le16_to_cpu(p->t_ccs); + op->async_timing_mode = le16_to_cpu(p->async_timing_mode); + op->vendor_revision = le16_to_cpu(p->vendor_revision); + memcpy(op->vendor, p->vendor, sizeof(p->vendor)); + chip->parameters.onfi_params = op; + + /* Identification done, free the full ONFI parameter page and exit */ + kfree(p); + + return 1; + +free_model: + kfree(model); free_onfi_param_page: kfree(p); + return ret; } @@ -5966,6 +5977,8 @@ static int nand_scan_ident(struct mtd_info *mtd, int maxchips, static void nand_scan_ident_cleanup(struct nand_chip *chip) { kfree(chip->parameters.model); + kfree(chip->parameters.onfi_params); + } static int nand_set_ecc_soft_ops(struct mtd_info *mtd) diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c index 651129023257..0674721acad8 100644 --- a/drivers/mtd/nand/raw/nand_micron.c +++ b/drivers/mtd/nand/raw/nand_micron.c @@ -57,9 +57,9 @@ static int micron_nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) static int micron_nand_onfi_init(struct nand_chip *chip) { struct nand_parameters *p = &chip->parameters; - struct nand_onfi_vendor_micron *micron = (void *)p->onfi_params.vendor; + struct nand_onfi_vendor_micron *micron = (void *)p->onfi_params->vendor; - if (chip->onfi_version && p->onfi_params.vendor_revision) { + if (p->onfi_params && p->onfi_params->vendor_revision) { chip->read_retries = micron->read_retry_options; chip->setup_read_retry = micron_nand_setup_read_retry; } diff --git a/drivers/mtd/nand/raw/nand_timings.c b/drivers/mtd/nand/raw/nand_timings.c index b97bcf29f75a..58dc524471fa 100644 --- a/drivers/mtd/nand/raw/nand_timings.c +++ b/drivers/mtd/nand/raw/nand_timings.c @@ -292,6 +292,7 @@ int onfi_fill_data_interface(struct nand_chip *chip, int timing_mode) { struct nand_data_interface *iface = &chip->data_interface; + struct onfi_params *onfi_params = chip->parameters.onfi_params; if (type != NAND_SDR_IFACE) return -EINVAL; @@ -306,17 +307,16 @@ int onfi_fill_data_interface(struct nand_chip *chip, * tR, tPROG, tCCS, ... * These information are part of the ONFI parameter page. */ - if (chip->onfi_version) { - struct nand_parameters *params = &chip->parameters; + if (onfi_params) { struct nand_sdr_timings *timings = &iface->timings.sdr; /* microseconds -> picoseconds */ - timings->tPROG_max = 1000000ULL * params->onfi_params.t_prog; - timings->tBERS_max = 1000000ULL * params->onfi_params.t_bers; - timings->tR_max = 1000000ULL * params->onfi_params.t_r; + timings->tPROG_max = 1000000ULL * onfi_params->t_prog; + timings->tBERS_max = 1000000ULL * onfi_params->t_bers; + timings->tR_max = 1000000ULL * onfi_params->t_r; /* nanoseconds -> picoseconds */ - timings->tCCS_min = 1000UL * params->onfi_params.t_ccs; + timings->tCCS_min = 1000UL * onfi_params->t_ccs; } return 0; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 9e15256bef2b..7d43fc05d009 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -445,7 +445,7 @@ struct nand_parameters { DECLARE_BITMAP(get_feature_list, ONFI_FEATURE_NUMBER); /* ONFI parameters */ - struct onfi_params onfi_params; + struct onfi_params *onfi_params; }; /* The maximum expected count of bytes in the NAND ID sequence */ @@ -1559,10 +1559,10 @@ struct platform_nand_data { /* return the supported asynchronous timing mode. */ static inline int onfi_get_async_timing_mode(struct nand_chip *chip) { - if (!chip->onfi_version) + if (!chip->parameters.onfi_params) return ONFI_TIMING_MODE_UNKNOWN; - return chip->parameters.onfi_params.async_timing_mode; + return chip->parameters.onfi_params->async_timing_mode; } int onfi_fill_data_interface(struct nand_chip *chip,