From patchwork Mon Sep 12 20:01:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Dasu X-Patchwork-Id: 9327963 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 076C160231 for ; Mon, 12 Sep 2016 20:07:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB49428EA5 for ; Mon, 12 Sep 2016 20:07:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC0F728EA9; Mon, 12 Sep 2016 20:07:40 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 74DDE28EA5 for ; Mon, 12 Sep 2016 20:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751244AbcILUHk (ORCPT ); Mon, 12 Sep 2016 16:07:40 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34247 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750998AbcILUHj (ORCPT ); Mon, 12 Sep 2016 16:07:39 -0400 Received: by mail-pf0-f195.google.com with SMTP id g202so8542476pfb.1 for ; Mon, 12 Sep 2016 13:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=O+ylmjXAios+pqd4N36Xpl5I+4sVj+5pw4sycowFVVs=; b=RDMGrQMqLcboL1etQTj4OExmHXqZwVzYwSKMvjdhDrgEspi//OYVI2MzCtfATFgRgE GiuoCdWuXmc+9PP6tal+T5xbKwS7ynrIEt/XblH4CTK//jhOL5dNhrcDHLT8K2pKeLa1 9Ocg4oi+rfnIfGowy6M+LyhI7bbROTfZqMuCm0/ckq8DsEdUya1w+h8nhiNOWUWSFtI1 IZXJ2RcJ4JYASIZqpDPB4Y7fYzs5toUxZufMWv2A1zratonu/+bVBiti6WP3xJ25AtNp B7ojhhNpl+Tm8qm8kuEYZg6ud+ISVwEln4TcJ6xGbTKu8IUCeKYYTAfnS1ligm6CJbjw 8hKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=O+ylmjXAios+pqd4N36Xpl5I+4sVj+5pw4sycowFVVs=; b=Ffnp59c1ypVhj5Wf3y2RFJlrcF3T3r9poR3J9b94Zju5ZIl+WnMmfZCAJdTY07sD96 MZan031KbsW6CPYwNLhW2lfkeH772SK8XOoS214mH/zTt7WbEi5aWiWfziR+fCFPynRy 0YM/erv7NkuA17vPnwkhj7I2UD0uT7Ku7clgU5nRxPBjM1JfAgzi+NUIJa/MyDaGoNq7 52AgkjN/EKM7D3ES8QuANzkpd5/hAtVl1JTeqPe4DruXUjIGHwJusJvM63k1fX8IZt1G 5Ez9AJdK97iVf3KQh36hpxO1hiFr1Tpva9MiFbRyiuKbQKsbOTeLhBTy9+8E/9u7+sDa 6X1w== X-Gm-Message-State: AE9vXwOK7GYIouq6zkQUcx3rICyECDDEyhWs7kb2zvLEIpIusTP2WeyRpOHdH6SZfBGSug== X-Received: by 10.98.220.145 with SMTP id c17mr19472834pfl.159.1473710858452; Mon, 12 Sep 2016 13:07:38 -0700 (PDT) Received: from mail.broadcom.com ([216.31.219.19]) by smtp.gmail.com with ESMTPSA id bm8sm26465699pac.16.2016.09.12.13.07.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Sep 2016 13:07:37 -0700 (PDT) From: Kamal Dasu To: linux-spi@vger.kernel.org, f.fainelli@gmail.com, linux-mtd@lists.infradead.org, computersforpeace@gmail.com Cc: bcm-kernel-feedback-list@broadcom.com, Kamal Dasu Subject: [PATCH v2, 1/1] mtd: devices: m25p80: Add PM suspend resume support Date: Mon, 12 Sep 2016 16:01:34 -0400 Message-Id: <1473710494-4084-1-git-send-email-kdasu.kdev@gmail.com> X-Mailer: git-send-email 1.9.1 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 Adding PM support so as to be able to probe spi-nor flash on resume. There are vendor specific commands to setup the transfer mode and enable read/write as part of spi_nor_scan(), done on initial probe and needed on resume(). The spi-nor structure is private to the m25p driver and hence is the only place this can be done without having to duplicate code in controller driver. Signed-off-by: Kamal Dasu --- drivers/mtd/devices/m25p80.c | 68 +++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 9cf7fcd..48c3f64 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -186,6 +186,39 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, } /* + * scan for spi nor flash vendor parts and setup + * read/write mode + */ +static int m25p_nor_flash_scan(struct device *dev) +{ + struct m25p *flash = dev_get_drvdata(dev); + struct flash_platform_data *data; + char *flash_name = NULL; + enum read_mode mode = SPI_NOR_NORMAL; + + data = dev_get_platdata(dev); + + /* For some (historical?) reason many platforms provide two different + * names in flash_platform_data: "name" and "type". Quite often name is + * set to "m25p80" and then "type" provides a real chip name. + * If that's the case, respect "type" and ignore a "name". + */ + if (data && data->type) + flash_name = data->type; + else if (!strcmp(flash->spi->modalias, "spi-nor")) + flash_name = NULL; /* auto-detect */ + else + flash_name = flash->spi->modalias; + + if (flash->spi->mode & SPI_RX_QUAD) + mode = SPI_NOR_QUAD; + else if (flash->spi->mode & SPI_RX_DUAL) + mode = SPI_NOR_DUAL; + + return spi_nor_scan(&flash->spi_nor, flash_name, mode); +} + +/* * board specific setup should have ensured the SPI clock used here * matches what the READ command supports, at least until this driver * understands FAST_READ (for clocks over 25 MHz). @@ -195,8 +228,6 @@ static int m25p_probe(struct spi_device *spi) struct flash_platform_data *data; struct m25p *flash; struct spi_nor *nor; - enum read_mode mode = SPI_NOR_NORMAL; - char *flash_name; int ret; data = dev_get_platdata(&spi->dev); @@ -220,27 +251,11 @@ static int m25p_probe(struct spi_device *spi) spi_set_drvdata(spi, flash); flash->spi = spi; - if (spi->mode & SPI_RX_QUAD) - mode = SPI_NOR_QUAD; - else if (spi->mode & SPI_RX_DUAL) - mode = SPI_NOR_DUAL; - if (data && data->name) nor->mtd.name = data->name; - /* For some (historical?) reason many platforms provide two different - * names in flash_platform_data: "name" and "type". Quite often name is - * set to "m25p80" and then "type" provides a real chip name. - * If that's the case, respect "type" and ignore a "name". - */ - if (data && data->type) - flash_name = data->type; - else if (!strcmp(spi->modalias, "spi-nor")) - flash_name = NULL; /* auto-detect */ - else - flash_name = spi->modalias; + ret = m25p_nor_flash_scan(nor->dev); - ret = spi_nor_scan(nor, flash_name, mode); if (ret) return ret; @@ -248,7 +263,6 @@ static int m25p_probe(struct spi_device *spi) data ? data->nr_parts : 0); } - static int m25p_remove(struct spi_device *spi) { struct m25p *flash = spi_get_drvdata(spi); @@ -319,10 +333,24 @@ static const struct of_device_id m25p_of_table[] = { }; MODULE_DEVICE_TABLE(of, m25p_of_table); +#ifdef CONFIG_PM_SLEEP +static int m25p_suspend(struct device *dev) +{ + return 0; +} + +static int m25p_resume(struct device *dev) +{ + return m25p_nor_flash_scan(dev); +} +#endif +static SIMPLE_DEV_PM_OPS(m25p_pm_ops, m25p_suspend, m25p_resume); + static struct spi_driver m25p80_driver = { .driver = { .name = "m25p80", .of_match_table = m25p_of_table, + .pm = &m25p_pm_ops, }, .id_table = m25p_ids, .probe = m25p_probe,