From patchwork Wed Sep 26 16:06:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11741 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 0E90C23E42 for ; Wed, 26 Sep 2012 16:06:51 +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 8C772A191F1 for ; Wed, 26 Sep 2012 16:06:50 +0000 (UTC) Received: by ieje10 with SMTP id e10so1782634iej.11 for ; Wed, 26 Sep 2012 09:06:50 -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=b9muc91himVLad9WFxzoUPs/e1q88TMXHRukPk+MMq0=; b=aX9v5JCIjwWNxfDx2anaFvmq5hy7H6YEFo7k4Kv/ntmOzW+e3oMC/NbxBebUXjERb1 RM+Jn4UUl9G4aDtChCzI9SnSfMtWpM808i6KoB6vMSbzupseZkPzcJZ1ZGzN6USc5wGh 2MOKkUoMnBx03vMFLVObJTKXNaTzGv+xeO3Dj3BKWnn67dPKXpTyZTqSqgcH7k94sagE f1zUlI8DMIU/8DZqXQf5kcxsiAWwj8LOlAP/4i0tjdYtN9A2Es/Rx16sBuAOAv8/+y7Q ps+OL0o1N11BvJXftsiQJ7BvDsGMfyEhWDNbAXceOKkGXqzmmoCBgqDoR93hriLsXgxd LxjA== Received: by 10.50.217.227 with SMTP id pb3mr11602040igc.28.1348675609782; Wed, 26 Sep 2012 09:06:49 -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 ex8csp364226igc; Wed, 26 Sep 2012 09:06:48 -0700 (PDT) Received: by 10.14.200.134 with SMTP id z6mr99962een.33.1348675605788; Wed, 26 Sep 2012 09:06:45 -0700 (PDT) Received: from eu1sys200aog102.obsmtp.com (eu1sys200aog102.obsmtp.com [207.126.144.113]) by mx.google.com with SMTP id 42si3235213eee.120.2012.09.26.09.06.33 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Sep 2012 09:06:45 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.113 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.113; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.113 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-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob102.postini.com ([207.126.147.11]) with SMTP ID DSNKUGMoCQazvVHvRxxWPVcexTKnr24uaHRw@postini.com; Wed, 26 Sep 2012 16:06:44 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id AF1BD9C; Wed, 26 Sep 2012 15:58:14 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 1D40CAC3; Wed, 26 Sep 2012 16:06:29 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id E453924C2C0; Wed, 26 Sep 2012 18:06:19 +0200 (CEST) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 26 Sep 2012 18:06:28 +0200 From: Linus Walleij To: Grant Likely , Mark Brown , Cc: Anmar Oueja , Linus Walleij , Vipul Kumar Samar , Viresh Kumar Subject: [PATCH v2] spi/pl022: get/put resources on suspend/resume Date: Wed, 26 Sep 2012 18:06:22 +0200 Message-ID: <1348675582-11538-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: ALoCoQmhWa3A/9e+9Phzkjk1PuWxUJUAWwcJvyl+P1PBRL0xjJdUAWmQ2Np5JTscTINfj9diwy8p 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: Vipul Kumar Samar Cc: Viresh Kumar Acked-by: Ulf Hansson Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Add more #ifdef for the case where we have neither normal PM nor runtime PM. --- drivers/spi/spi-pl022.c | 66 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 15737bc..9194641 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -2300,6 +2300,45 @@ pl022_remove(struct amba_device *adev) return 0; } +#if defined(CONFIG_SUSPEND) || defined(CONFIG_PM_RUNTIME) +/* + * 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); +} +#endif + #ifdef CONFIG_SUSPEND static int pl022_suspend(struct device *dev) { @@ -2311,6 +2350,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 +2361,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 +2378,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