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: 668965 X-Patchwork-Delegate: boris.brezillon@free-electrons.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 [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sXzRW6T3Jz9sdn for ; Tue, 13 Sep 2016 06:09:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=RDMGrQMq; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bjXWM-0002Yw-Eh; Mon, 12 Sep 2016 20:08:02 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bjXWJ-0002MY-DS for linux-mtd@lists.infradead.org; Mon, 12 Sep 2016 20:08:00 +0000 Received: by mail-pf0-x241.google.com with SMTP id 128so8529847pfb.0 for ; Mon, 12 Sep 2016 13:07:38 -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=LaX1hWjjwo8rffrUM4yhtaCgIR8FsQdEZmcKGK8nQHtK9q35vko1KDHePSZ5BoIzpO vSXaIVkb3Cztp4SbRdGH/E/nsgKlfwAzJHpC26NefWLQu1PSjw4oytXrhF1Hlxt0e/7F ROxOn6Seje/M1cUVX7DmbX6ZCiCYGIl62DtitWoQOiJBWJfv60ahNvcv9e9DJgiWRm8E sSDbPESMT8JkfDQA3h4wMa+uIM3MzWd/DKOKKm/Dbwpouhb187spckWxW+wF0VLlCRIf xJFOvActuZVQc5oV3KHzlSER48ArcJSw8eLwYcFitbbPfLcDsn46eT7Hw3Zv8KnW2CJ1 8cRA== X-Gm-Message-State: AE9vXwMTRB32JwJcAMyo6aTk8wSPi/V0LIpK4oFGj8ncKkzSOhQ/1c3vVJWrn5JpwmYfNw== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160912_130759_505285_424CA026 X-CRM114-Status: GOOD ( 15.56 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c00:0:0:0:241 listed in] [list.dnswl.org] -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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 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, Kamal Dasu MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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,