From patchwork Fri Feb 3 23:31:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 723966 X-Patchwork-Delegate: cyrille.pitchen@atmel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vFY875mw1z9s4s for ; Sat, 4 Feb 2017 10:33:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DgJ6xzcf"; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cZnLo-00050N-Rp; Fri, 03 Feb 2017 23:33:08 +0000 Received: from mail-qt0-f196.google.com ([209.85.216.196]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cZnLZ-0004p1-Kp for linux-mtd@lists.infradead.org; Fri, 03 Feb 2017 23:32:55 +0000 Received: by mail-qt0-f196.google.com with SMTP id n13so7744631qtc.0 for ; Fri, 03 Feb 2017 15:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oLStp/cF1Mpe/4MFWON+MdaH9dvLH96LHhaif+W5X9w=; b=DgJ6xzcfsMx6j11+GF62wp43RjHHrStaKhM+h62NBizJ7FsFtRetiRgw9Wk2XksWKb omLN9bJj/VnOvbwm8ZBDUDh0NV/He2HnGqSmT9ti0CpdIIjQR+30ixCdb9UFvBGBsttt NcRzIrLmQ07g1ikpcqfyaSbTJlCcjg5n53to51E3QhfHyPf+InKbyHjTAmt4WF/tuFAx qfW72e+r12R7SdRWYpv0ijQZ+e4QODCRtjZwH4Qkhmf21NYDNoCAusEcxUCX5XwryfVX W814Ze1a/qCo5Fv8UsBqyKVwDJhvDjSk4WnQKJ3BGv8PaF3cy0jmgciwclWhlIsq2Mck OUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oLStp/cF1Mpe/4MFWON+MdaH9dvLH96LHhaif+W5X9w=; b=XZCLjeRS8tUKRoNAoqEwYCGqWVSyl+SocCaJW99a1GXD1TOhVj+EJEc48f0APZfBh2 ufVUibUN17z0jtPOIqBVXJvILfWbWGrfkMqW7jNr8+ii378SL29tzu3AOOiGvZmGCxZR cEMjQvVcJJDPelcPhL37rGMi8QYeBCYDNq6xG1zAywwTYL+BnocvlFR7ismwK7rIjyIc eMttqyleH8BkQg/BvCj2XSQxAW74V0DGBPq/dtG0kna/FTrKgHoinrrrEa8a25U9Q+Vf G1Vlm+c49ZhCydX7cw4GTcmJht0mTVTL37sXxXQn4KvzhFmZj8SAoOO7F6fWZECufpNh sGXg== X-Gm-Message-State: AIkVDXKKN8yN181MqwBSeJn/OH4n84+Kc8QuVlceGf4nGVJYZpnGIce5WEt0ReGrgtW48g== X-Received: by 10.55.49.7 with SMTP id x7mr16423070qkx.141.1486164694809; Fri, 03 Feb 2017 15:31:34 -0800 (PST) Received: from mail.broadcom.com ([192.19.218.250]) by smtp.gmail.com with ESMTPSA id 140sm25747914qkj.19.2017.02.03.15.31.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 15:31:34 -0800 (PST) From: Kamal Dasu To: linux-spi@vger.kernel.org, cyrille.pitchen@atmel.com, marex@denx.de, broonie@kernel.org Subject: [PATCH v1 1/5] mtd: spi-nor: Added way to rescan spi-nor device Date: Fri, 3 Feb 2017 18:31:12 -0500 Message-Id: <1486164676-12912-2-git-send-email-kdasu.kdev@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486164676-12912-1-git-send-email-kdasu.kdev@gmail.com> References: <1486164676-12912-1-git-send-email-kdasu.kdev@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170203_153253_762207_6F4C444E X-CRM114-Status: GOOD ( 17.14 ) X-Spam-Score: -2.2 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [209.85.216.196 listed in dnsbl.sorbs.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.196 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.216.196 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (kdasu.kdev[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bcm-kernel-feedback-list@broadcom.com, f.fainelli@gmail.com, linux-mtd@lists.infradead.org, Kamal Dasu MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org On pm resume op spi-nor flash may need to be reconfigured on a power reset, however there is no need to go through a full spi_nor_scan(). The driver might need to disable protection, program the address width and transfer mode where applicable. The spi-nor framework has all the generic code to do this. Refactored a few pieces and added a spi_nor_pm_rescan() to be called by the mtd device driver's pm resume() op. Signed-off-by: Kamal Dasu --- drivers/mtd/spi-nor/spi-nor.c | 93 +++++++++++++++++++++++++++++++++++++------ include/linux/mtd/spi-nor.h | 17 ++++++++ 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index da7cd69..e72233b 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1312,26 +1312,28 @@ static int spi_nor_check(struct spi_nor *nor) return 0; } -int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) +static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, + const char *name, + int *retval) + { const struct flash_info *info = NULL; struct device *dev = nor->dev; - struct mtd_info *mtd = &nor->mtd; - struct device_node *np = spi_nor_get_flash_node(nor); - int ret; - int i; + int ret = 0; ret = spi_nor_check(nor); if (ret) - return ret; + goto info_out; if (name) info = spi_nor_match_id(name); /* Try to auto-detect if chip name wasn't specified or not found */ if (!info) info = spi_nor_read_id(nor); - if (IS_ERR_OR_NULL(info)) - return -ENOENT; + if (IS_ERR_OR_NULL(info)) { + ret = -ENOENT; + goto info_out; + } /* * If caller has specified name of flash model that can normally be @@ -1342,7 +1344,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) jinfo = spi_nor_read_id(nor); if (IS_ERR(jinfo)) { - return PTR_ERR(jinfo); + ret = PTR_ERR(jinfo); + goto info_out; } else if (jinfo != info) { /* * JEDEC knows better, so overwrite platform ID. We @@ -1357,8 +1360,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) } } - mutex_init(&nor->lock); +info_out: + + *retval = ret; + return info; +} +static void spi_nor_unprotect(struct spi_nor *nor, + const struct flash_info *info) +{ /* * Atmel, SST, Intel/Numonyx, and others serial NOR tend to power up * with the software protection bits set @@ -1372,6 +1382,35 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) write_sr(nor, 0); spi_nor_wait_till_ready(nor); } +} + +static inline void spi_nor_print_flash_info(struct spi_nor *nor, + const struct flash_info *info) +{ + struct mtd_info *mtd = &nor->mtd; + struct device *dev = nor->dev; + + dev_info(dev, "%s (%lld Kbytes)\n", info->name, + (long long)mtd->size >> 10); + +} + +int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) +{ + const struct flash_info *info; + struct device *dev = nor->dev; + struct mtd_info *mtd = &nor->mtd; + struct device_node *np = spi_nor_get_flash_node(nor); + int ret; + int i; + + info = spi_nor_get_flash_info(nor, name, &ret); + if (ret) + return ret; + + mutex_init(&nor->lock); + + spi_nor_unprotect(nor, info); if (!mtd->name) mtd->name = dev_name(dev); @@ -1517,8 +1556,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) nor->read_dummy = spi_nor_read_dummy_cycles(nor); - dev_info(dev, "%s (%lld Kbytes)\n", info->name, - (long long)mtd->size >> 10); + spi_nor_print_flash_info(nor, info); dev_dbg(dev, "mtd .name = %s, .size = 0x%llx (%lldMiB), " @@ -1540,6 +1578,37 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) } EXPORT_SYMBOL_GPL(spi_nor_scan); +int spi_nor_pm_rescan(struct spi_nor *nor, const char *name) +{ + int ret = 0; + const struct flash_info *info; + struct device *dev = nor->dev; + + info = spi_nor_get_flash_info(nor, name, &ret); + if (ret) + return ret; + + spi_nor_unprotect(nor, info); + + if (nor->flash_read == SPI_NOR_QUAD) { + ret = set_quad_mode(nor, info); + if (ret) { + dev_err(dev, "quad mode not supported\n"); + return ret; + } + } + + if (nor->addr_width == 4 && JEDEC_MFR(info) != CFI_MFR_AMD) + set_4byte(nor, info, 1); + + spi_nor_print_flash_info(nor, info); + dev_dbg(dev, "addr width %d read mode %d", + nor->addr_width, nor->flash_read); + + return ret; +} +EXPORT_SYMBOL_GPL(spi_nor_pm_rescan); + static const struct flash_info *spi_nor_match_id(const char *name) { const struct flash_info *id = spi_nor_ids; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index c425c7b..487b473 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -213,4 +213,21 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor) */ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode); +/** + * spi_nor_pm_rescan() - rescan the SPI NOR + * @nor: the spi_nor structure + * @name: the chip type name + * + * The drivers can use this function to set the SPI NOR flash device to + * its initial scanned state, it shall use all nor information set on poweron + * for the read mode, address width and enabling write mode for certain + * manufacturers. This would be needed to be called for flash devices that are + * reset during power management. + * + * The chip type name can be provided through the @name parameter. + * + * Return: 0 for success, others for failure. + */ +int spi_nor_pm_rescan(struct spi_nor *nor, const char *name); + #endif