From patchwork Wed Sep 11 15:32:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 2873331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7B332BF43F for ; Wed, 11 Sep 2013 15:43:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3CFA2202FE for ; Wed, 11 Sep 2013 15:43:49 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5E692025D for ; Wed, 11 Sep 2013 15:43:47 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VJmZl-0008CA-FP; Wed, 11 Sep 2013 15:43:29 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VJmR0-0000mY-FR; Wed, 11 Sep 2013 15:34:26 +0000 Received: from mga11.intel.com ([192.55.52.93]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VJmQG-0000dv-3W for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2013 15:33:41 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 11 Sep 2013 08:33:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.90,885,1371106800"; d="scan'208";a="399998727" Received: from blue.fi.intel.com ([10.237.72.156]) by fmsmga002.fm.intel.com with ESMTP; 11 Sep 2013 08:32:46 -0700 Received: by blue.fi.intel.com (Postfix, from userid 1004) id 23B59E0098; Wed, 11 Sep 2013 18:32:41 +0300 (EEST) From: Mika Westerberg To: linux-i2c@vger.kernel.org Subject: [PATCH v2 8/9] spi: prepare runtime PM support for SPI devices Date: Wed, 11 Sep 2013 18:32:39 +0300 Message-Id: <1378913560-2752-9-git-send-email-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1378913560-2752-1-git-send-email-mika.westerberg@linux.intel.com> References: <1378913560-2752-1-git-send-email-mika.westerberg@linux.intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130911_113340_384439_EF50A612 X-CRM114-Status: GOOD ( 21.19 ) X-Spam-Score: -7.7 (-------) Cc: Aaron Lu , Dmitry Torokhov , Mika Westerberg , Samuel Ortiz , Arnd Bergmann , Wolfram Sang , Greg Kroah-Hartman , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Liam Girdwood , linux-acpi@vger.kernel.org, Kyungmin Park , Mark Brown , Lv Zheng , Lee Jones , linux-arm-kernel@lists.infradead.org, Mauro Carvalho Chehab X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds runtime PM support for the SPI bus analogous to what has been done for the I2C bus. This means that the SPI core prepares runtime PM for a client device just before a driver is about to be bound to it. Devices that are not bound to any driver are not prepared for runtime PM. In order to participate the runtime PM of the SPI bus a device driver needs to drop the device runtime PM reference count by calling pm_runtime_put() in its ->probe() callback and possibly implement rest of the runtime PM callbacks. If the driver doesn't support runtime PM, the device in question is regarded as being runtime PM active and powered on. This patch adds also runtime PM support for the SPI master device because it is needed to be able to runtime power manage the SPI controller device. The SPI master device is handled along with the SPI controller device. Signed-off-by: Mika Westerberg Acked-by: Mark Brown --- drivers/spi/spi.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 978dda2..94ebab9 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -240,22 +240,61 @@ EXPORT_SYMBOL_GPL(spi_bus_type); static int spi_drv_probe(struct device *dev) { const struct spi_driver *sdrv = to_spi_driver(dev->driver); + struct spi_device *spi = to_spi_device(dev); + int ret; - return sdrv->probe(to_spi_device(dev)); + /* Make sure that the master is powered on */ + pm_runtime_get_sync(&spi->master->dev); + + /* + * Enable runtime PM for the SPI device. The SPI device driver can + * participate in runtime PM by calling pm_runtime_put() in its + * probe() callback. + */ + pm_runtime_get_noresume(&spi->dev); + pm_runtime_set_active(&spi->dev); + pm_runtime_enable(&spi->dev); + + ret = sdrv->probe(spi); + if (ret) { + pm_runtime_disable(&spi->dev); + pm_runtime_set_suspended(&spi->dev); + pm_runtime_put_noidle(&spi->dev); + } + + pm_runtime_put(&spi->master->dev); + + return ret; } static int spi_drv_remove(struct device *dev) { const struct spi_driver *sdrv = to_spi_driver(dev->driver); + struct spi_device *spi = to_spi_device(dev); + int ret; + + pm_runtime_get_sync(&spi->master->dev); + + ret = sdrv->remove(spi); + + /* Undo the runtime PM done in spi_drv_probe() */ + pm_runtime_disable(&spi->dev); + pm_runtime_set_suspended(&spi->dev); + pm_runtime_put_noidle(&spi->dev); - return sdrv->remove(to_spi_device(dev)); + pm_runtime_put(&spi->master->dev); + + return ret; } static void spi_drv_shutdown(struct device *dev) { const struct spi_driver *sdrv = to_spi_driver(dev->driver); + struct spi_device *spi = to_spi_device(dev); + pm_runtime_get_sync(&spi->master->dev); sdrv->shutdown(to_spi_device(dev)); + pm_runtime_put(&spi->master->dev); } /** @@ -1174,6 +1213,10 @@ int spi_register_master(struct spi_master *master) } } + pm_runtime_set_active(&master->dev); + pm_runtime_no_callbacks(&master->dev); + pm_runtime_enable(&master->dev); + mutex_lock(&board_lock); list_add_tail(&master->list, &spi_master_list); list_for_each_entry(bi, &board_list, list) @@ -1217,6 +1260,8 @@ void spi_unregister_master(struct spi_master *master) list_del(&master->list); mutex_unlock(&board_lock); + pm_runtime_disable(&master->dev); + dummy = device_for_each_child(&master->dev, NULL, __unregister); device_unregister(&master->dev); }