From patchwork Wed Sep 26 15:08:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11736 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 6F74023E57 for ; Wed, 26 Sep 2012 15:09:27 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id E8ECBA180B0 for ; Wed, 26 Sep 2012 15:09:26 +0000 (UTC) Received: by ieje10 with SMTP id e10so1603999iej.11 for ; Wed, 26 Sep 2012 08:09:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:mime-version:content-type :x-gm-message-state; bh=Sl9ymORFVNs7/nWklCg4zhlGyXFnbv1o750PWslVv8g=; b=hM7y/DZaOSFsgrfu16GVCT6yhcG5rkYgqubAPARt5yNffyBA2nP04DlTWskY42KUsz WpHG9aEfEzErkW1MzPirtQE1n1HuG8pVHnlB4NXzsfW2U1uIL3mDarNQAPFB1ulJvPRt FZ61IpPqFygSzemftrQy8gO/yVBp8PVwqODezHWd0JrPfB2zsUXjuB2SC7oDcg8MJirQ o/xvvPGixARjcZwtH3RkyvGnbRABljPRvXTAD2UncQyW/JxIiAAZzYz7VC4A3QYEuFZi EQry/KER9S2VnimdkNs5c9kB69k/eni84DAK9mYFE1dKwz+rE2zkXcktirjoqWAtCHiU cMoQ== Received: by 10.50.7.212 with SMTP id l20mr740965iga.43.1348672166219; Wed, 26 Sep 2012 08:09:26 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp361244igc; Wed, 26 Sep 2012 08:09:25 -0700 (PDT) Received: by 10.14.211.3 with SMTP id v3mr1692696eeo.43.1348672164609; Wed, 26 Sep 2012 08:09:24 -0700 (PDT) Received: from eu1sys200aog107.obsmtp.com (eu1sys200aog107.obsmtp.com [207.126.144.123]) by mx.google.com with SMTP id o42si2985698eep.59.2012.09.26.08.09.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Sep 2012 08:09:24 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.123 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.123; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.123 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob107.postini.com ([207.126.147.11]) with SMTP ID DSNKUGMamhX4y3jfsrLZYMwxwCFGt84F9o02@postini.com; Wed, 26 Sep 2012 15:09:24 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5B38C16C; Wed, 26 Sep 2012 15:08:59 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D15591DDC; Wed, 26 Sep 2012 15:08:58 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 5A18FA8065; Wed, 26 Sep 2012 17:08:52 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 26 Sep 2012 17:08:57 +0200 From: Linus Walleij To: Grant Likely , Mark Brown , Cc: Anmar Oueja , Linus Walleij , Ulf Hansson , Vipul Kumar Samar , Viresh Kumar Subject: [PATCH] spi/pl022: get/put resources on suspend/resume Date: Wed, 26 Sep 2012 17:08:53 +0200 Message-ID: <1348672133-5837-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQk5/p8RmhTSM+bDwHQyC52K2fI5OharUAJmv3wgXr1QHJchxu8h8HLbmEY0EzBiMkSUKI/o This factors out the resource handling in runtime suspend/resume and also calls it from the ordinary suspend and resume hooks. The semantics require that ordinary PM op suspend is called with runtime PM in resumed mode, so that ordinary suspend can assume that it will e.g. decrease the clock reference counter to 0, runtime resume having previously increased it to 1. Cc: Ulf Hansson Cc: Vipul Kumar Samar Cc: Viresh Kumar Signed-off-by: Linus Walleij --- Vipin: can you confirm that this approach works for your case with only suspend/resume but no runtime PM? Question: can I be sure that the above semantics is taken care of by runtime PM, or will I have to add kludges to the ordinary suspend/resume hooks to make sure that the device is out of runtime suspend before suspending? --- drivers/spi/spi-pl022.c | 64 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 15737bc..63cd7c6 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -2300,6 +2300,43 @@ pl022_remove(struct amba_device *adev) return 0; } +/* + * These two functions are used from both suspend/resume and + * the runtime counterparts to handle external resources like + * clocks, pins and regulators when going to sleep. + */ +static void pl022_suspend_resources(struct pl022 *pl022) +{ + int ret; + + clk_disable(pl022->clk); + + /* Optionally let pins go into sleep states */ + if (!IS_ERR(pl022->pins_sleep)) { + ret = pinctrl_select_state(pl022->pinctrl, + pl022->pins_sleep); + if (ret) + dev_err(&pl022->adev->dev, + "could not set pins to sleep state\n"); + } +} + +static void pl022_resume_resources(struct pl022 *pl022) +{ + int ret; + + /* Optionaly enable pins to be muxed in and configured */ + if (!IS_ERR(pl022->pins_default)) { + ret = pinctrl_select_state(pl022->pinctrl, + pl022->pins_default); + if (ret) + dev_err(&pl022->adev->dev, + "could not set default pins\n"); + } + + clk_enable(pl022->clk); +} + #ifdef CONFIG_SUSPEND static int pl022_suspend(struct device *dev) { @@ -2311,6 +2348,7 @@ static int pl022_suspend(struct device *dev) dev_warn(dev, "cannot suspend master\n"); return ret; } + pl022_suspend_resources(pl022); dev_dbg(dev, "suspended\n"); return 0; @@ -2321,6 +2359,8 @@ static int pl022_resume(struct device *dev) struct pl022 *pl022 = dev_get_drvdata(dev); int ret; + pl022_resume_resources(pl022); + /* Start the queue running */ ret = spi_master_resume(pl022->master); if (ret) @@ -2336,36 +2376,16 @@ static int pl022_resume(struct device *dev) static int pl022_runtime_suspend(struct device *dev) { struct pl022 *pl022 = dev_get_drvdata(dev); - int status = 0; - - clk_disable(pl022->clk); - - /* Optionally let pins go into sleep states */ - if (!IS_ERR(pl022->pins_sleep)) { - status = pinctrl_select_state(pl022->pinctrl, - pl022->pins_sleep); - if (status) - dev_err(dev, "could not set pins to sleep state\n"); - } + pl022_suspend_resources(pl022); return 0; } static int pl022_runtime_resume(struct device *dev) { struct pl022 *pl022 = dev_get_drvdata(dev); - int status = 0; - - /* Optionaly enable pins to be muxed in and configured */ - if (!IS_ERR(pl022->pins_default)) { - status = pinctrl_select_state(pl022->pinctrl, - pl022->pins_default); - if (status) - dev_err(dev, "could not set default pins\n"); - } - - clk_enable(pl022->clk); + pl022_resume_resources(pl022); return 0; } #endif