From patchwork Tue Feb 4 15:58:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 24121 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B8A5E202FA for ; Tue, 4 Feb 2014 15:59:58 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id pa12sf24442132veb.5 for ; Tue, 04 Feb 2014 07:59:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=HrUJJJhOPHL6d4klScVIc9g7A0ylVJAmSCLTJkLGqgY=; b=HsqIodR2WMmZWP7lWkbwe61traeaXFWqDUvkMjjBMvmp3HCjeqxzn1Ntr4da1Qtyei uBr5p2a26C4jY9QN9fUf9Osn7913NsSkCPB5zknob0mrxqAKUD4uOxVOnNoEYhd04Crp P9cPq755x5joi0OheXHHDokSqab+nKhPXLK+QLmBaS9zjPLsCgKaovpF5di/hEMmOXnw 0WNTMGOS5IumwZP0fEc+0Fx5qCDbxf/EHucKmQaUJV6emIe6/ZQKfautChMspR4v0eoz 1j05NqDYjgB7TwsDMcdVQr80oVV5YxdstzJTZCFQpuL8AZnxqjSFtOk03+HNAX5ZJa7T kNcg== X-Gm-Message-State: ALoCoQmxhghTtpKO/hNqJURdBCd3I+nMvxubhqZ2NSWz6r5bqDdABTHPvGOfxrkP/DMm67xzxN7J X-Received: by 10.59.7.2 with SMTP id cy2mr11374201ved.9.1391529597876; Tue, 04 Feb 2014 07:59:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.161 with SMTP id o30ls2429353qge.98.gmail; Tue, 04 Feb 2014 07:59:57 -0800 (PST) X-Received: by 10.52.109.193 with SMTP id hu1mr28408199vdb.11.1391529597802; Tue, 04 Feb 2014 07:59:57 -0800 (PST) Received: from mail-vb0-f42.google.com (mail-vb0-f42.google.com [209.85.212.42]) by mx.google.com with ESMTPS id tj7si8321986vdc.111.2014.02.04.07.59.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 07:59:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.42; Received: by mail-vb0-f42.google.com with SMTP id i3so5884004vbh.15 for ; Tue, 04 Feb 2014 07:59:57 -0800 (PST) X-Received: by 10.220.88.204 with SMTP id b12mr32945843vcm.3.1391529597705; Tue, 04 Feb 2014 07:59:57 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp245393vcz; Tue, 4 Feb 2014 07:59:57 -0800 (PST) X-Received: by 10.112.168.104 with SMTP id zv8mr14277090lbb.5.1391529596501; Tue, 04 Feb 2014 07:59:56 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id n3si12973239lae.4.2014.02.04.07.59.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 07:59:56 -0800 (PST) Received-SPF: neutral (google.com: 209.85.217.181 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id z5so6488520lbh.40 for ; Tue, 04 Feb 2014 07:59:55 -0800 (PST) X-Received: by 10.152.120.201 with SMTP id le9mr639188lab.68.1391529595676; Tue, 04 Feb 2014 07:59:55 -0800 (PST) Received: from localhost.localdomain (host-95-199-220-119.mobileonline.telia.com. [95.199.220.119]) by mx.google.com with ESMTPSA id dm8sm35906603lad.7.2014.02.04.07.59.53 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 07:59:54 -0800 (PST) From: Ulf Hansson To: Russell King , linux-arm-kernel@lists.infradead.org Cc: Alessandro Rubini , Linus Walleij , Wolfram Sang , Chris Ball , Mark Brown , linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, linux-mmc@vger.kernel.org, Ulf Hansson Subject: [PATCH 14/17] i2c: nomadik: Fixup deployment of runtime PM Date: Tue, 4 Feb 2014 16:58:55 +0100 Message-Id: <1391529538-21685-15-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1391529538-21685-1-git-send-email-ulf.hansson@linaro.org> References: <1391529538-21685-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Since the device is active while a successful probe has been completed, the reference counting for the clock will be screwed up and never reach zero. The issue is resolved by implementing runtime PM callbacks and let them handle the resources accordingly, including the clock. Cc: Alessandro Rubini Cc: Linus Walleij Cc: Wolfram Sang Signed-off-by: Ulf Hansson --- drivers/i2c/busses/i2c-nomadik.c | 47 ++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 0caa8ea..2d7dbc9 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -674,7 +674,7 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags) static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num_msgs) { - int status; + int status = 0; int i; struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); int j; @@ -683,19 +683,6 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, pm_runtime_get_sync(&dev->adev->dev); - status = clk_prepare_enable(dev->clk); - if (status) { - dev_err(&dev->adev->dev, "can't prepare_enable clock\n"); - goto out_clk; - } - - /* Optionaly enable pins to be muxed in and configured */ - pinctrl_pm_select_default_state(&dev->adev->dev); - - status = init_hw(dev); - if (status) - goto out; - /* Attempt three times to send the message queue */ for (j = 0; j < 3; j++) { /* setup the i2c controller */ @@ -716,12 +703,6 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, break; } -out: - clk_disable_unprepare(dev->clk); -out_clk: - /* Optionally let pins go into idle state */ - pinctrl_pm_select_idle_state(&dev->adev->dev); - pm_runtime_put_sync(&dev->adev->dev); dev->busy = false; @@ -938,6 +919,29 @@ static int nmk_i2c_resume(struct device *dev) #define nmk_i2c_resume NULL #endif +#if CONFIG_PM +static int nmk_i2c_runtime_suspend(struct device *dev) +{ + struct amba_device *adev = to_amba_device(dev); + struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); + + clk_disable_unprepare(nmk_i2c->clk); + pinctrl_pm_select_idle_state(dev); + return 0; +} + +static int nmk_i2c_runtime_resume(struct device *dev) +{ + struct amba_device *adev = to_amba_device(dev); + struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); + + clk_prepare_enable(nmk_i2c->clk); + pinctrl_pm_select_default_state(dev); + init_hw(nmk_i2c); + return 0; +} +#endif + /* * We use noirq so that we suspend late and resume before the wakeup interrupt * to ensure that we do the !pm_runtime_suspended() check in resume before @@ -946,6 +950,9 @@ static int nmk_i2c_resume(struct device *dev) static const struct dev_pm_ops nmk_i2c_pm = { .suspend_noirq = nmk_i2c_suspend, .resume_noirq = nmk_i2c_resume, + SET_PM_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend, + nmk_i2c_runtime_resume, + NULL) }; static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)