From patchwork Fri Feb 24 20:16:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 9591131 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 585E46020A for ; Fri, 24 Feb 2017 20:18:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4169328947 for ; Fri, 24 Feb 2017 20:18:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 320BB2894E; Fri, 24 Feb 2017 20:18:30 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF13128947 for ; Fri, 24 Feb 2017 20:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751296AbdBXUS3 (ORCPT ); Fri, 24 Feb 2017 15:18:29 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36517 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751163AbdBXUS2 (ORCPT ); Fri, 24 Feb 2017 15:18:28 -0500 Received: by mail-qk0-f196.google.com with SMTP id r90so4219712qki.3 for ; Fri, 24 Feb 2017 12:17:18 -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=djfu+x+snFojmGQ0OAon4wHt6+6Oh18S13VmrU+Lhcs=; b=rLDdPdLs4SXOFxtza2Pci4mWhWovjJcm1sDzUPqamJRfeBNvIBDXpjnpUmimFGiwZT sAA96TGzMsURbJxkc+/pcpTAXfpOTcOIbOY9q71MltWtLxCFTtguiks8EgrbMRz7PkWV K+J0nO7BF6quqWRM5Wu/w47l3YKb5/p0NboL2F+kT5P9NcmDW4xdgBjRAHRsN25/v5ot bvOolVOebOKN5frvhO6E1eTovznbdRNMBTThO1VJPY4z3auIOCJOy/jEg3M1RNaVJMC5 9ESnZldwBbEm5VDuSdcknXZLIieI1kDZH9PjzLC683Kd2/8V+t1DaTn2C/7iI0qe93nb 1ONw== 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=djfu+x+snFojmGQ0OAon4wHt6+6Oh18S13VmrU+Lhcs=; b=q4HuXkstgVJF3R2FJOGUdGHQ6502PsrEg24BUukpll8Vg2S7HEadsj/VkFfynC6Odo /gz2vypjiG8ZITpNQh/Ws97NtEOxww0rXMZ+oL2wo9WLZXuRI+Mib6kGhBRp4tGmpcaa t6FXuEzv48nlzGYwgWSMUKQvZgjwn1wWLsFazNcU0yM/mUThMzdtHgR1NYEqAK6J8mUR Gmz8CkMMCOzMuY8G+B2TgxZO6jB2wRlVtRwM8PjE/BojgKOYyxATG0ArKxDpDrNsqIe0 5vSvsMXdabvu1lXUe7iVF3Qns8A+qM4DxCea+isXXZJrBGeco2dppBJ+VIYrXehh1Wve AdFg== X-Gm-Message-State: AMke39kKWpEx79c3G0CVQ23wCM5ngD4r/8DkAiV4ESICJhoSGlJ6KMjd7MAPSovveou18g== X-Received: by 10.55.156.129 with SMTP id f123mr5067819qke.8.1487967437919; Fri, 24 Feb 2017 12:17:17 -0800 (PST) Received: from mail.broadcom.com ([192.19.218.250]) by smtp.gmail.com with ESMTPSA id o190sm5418808qkc.65.2017.02.24.12.17.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Feb 2017 12:17:17 -0800 (PST) From: Kamal Dasu To: linux-spi@vger.kernel.org, cyrille.pitchen@atmel.com, marex@denx.de, broonie@kernel.org Cc: linux-mtd@lists.infradead.org, f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.com, Kamal Dasu Subject: [PATCH v6 3/3] mtd: spi-nor: Add spi-nor mtd suspend and resume handlers Date: Fri, 24 Feb 2017 15:16:39 -0500 Message-Id: <1487967399-28967-4-git-send-email-kdasu.kdev@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1487967399-28967-1-git-send-email-kdasu.kdev@gmail.com> References: <1487967399-28967-1-git-send-email-kdasu.kdev@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Implemented and populated spi-nor mtd PM handlers for suspend and resume ops. spi-nor suspend op set's the flash state to FL_PM_SUSPENDED state and resume op re-initializes spi-nor flash and set's flash state to FL_READY. The handlers ensures synchronization between the spi-nor and the mtd layer by calling spi_nor_get/release_device() and setting respective flash states. Signed-off-by: Kamal Dasu --- drivers/mtd/spi-nor/spi-nor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 5363807..8e38895 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1629,6 +1629,28 @@ int spi_nor_init(struct spi_nor *nor) } EXPORT_SYMBOL_GPL(spi_nor_init); +/* mtd suspend handler */ +static int spi_nor_suspend(struct mtd_info *mtd) +{ + return spi_nor_get_device(mtd, FL_PM_SUSPENDED); +} + +/* mtd resume handler */ +static void spi_nor_resume(struct mtd_info *mtd) +{ + struct spi_nor *nor = mtd_to_spi_nor(mtd); + struct device *dev = nor->dev; + + if (nor->state == FL_PM_SUSPENDED) { + /* re-initialize the nor chip */ + spi_nor_init(nor); + /* mtd can resume transfers */ + spi_nor_release_device(mtd); + } else { + dev_err(dev, "resume() called, chip not in suspended state\n"); + } +} + int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) { const struct flash_info *info = NULL; @@ -1695,6 +1717,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, enum read_mode mode) mtd->size = info->sector_size * info->n_sectors; mtd->_erase = spi_nor_erase; mtd->_read = spi_nor_read; + mtd->_suspend = spi_nor_suspend; + mtd->_resume = spi_nor_resume; /* NOR protection support for STmicro/Micron chips and similar */ if (JEDEC_MFR(info) == SNOR_MFR_MICRON ||