From patchwork Tue May 10 23:46:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1435 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:51:58 -0000 Delivered-To: patches@linaro.org Received: by 10.224.61.3 with SMTP id r3cs38922qah; Tue, 10 May 2011 16:46:55 -0700 (PDT) Received: by 10.231.13.193 with SMTP id d1mr5365805iba.44.1305071214672; Tue, 10 May 2011 16:46:54 -0700 (PDT) Received: from mail-iy0-f178.google.com (mail-iy0-f178.google.com [209.85.210.178]) by mx.google.com with ESMTPS id f4si21255036ibn.132.2011.05.10.16.46.54 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 May 2011 16:46:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linus.ml.walleij@gmail.com designates 209.85.210.178 as permitted sender) client-ip=209.85.210.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linus.ml.walleij@gmail.com designates 209.85.210.178 as permitted sender) smtp.mail=linus.ml.walleij@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by iyi12 with SMTP id 12so7230150iyi.37 for ; Tue, 10 May 2011 16:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=oT52WogjJdErOr9wO6HxcGF4c19yzvpDbrMxStoMuiQ=; b=f5PYR4NpvTAyKIvhtDLk/p70+7YsCVUtHpcOGOfflG16GJnqCap6j9uq0AXrHLBduP HEPOcT+3goZyGXhnAIP4R7v2QMC2G6EPvvxrHNDbJksWdmjhGVdDXcxYLj90HtcFBMje cak0nteikAV5CGoS2+zKf4bdaltk3IcRX1voI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=PMubjHLyw5gPp7n0PL+xi6bErjqj1uXID5gOmJJnscjvr1DGVGFuTDRzv0dnnMtP2t xodRnQmBkS2fPV3yiv/wsGHq3YbHs08bwm0uKI+gVgpx9bpIpQybyJam+1E0YDBuyb9I rdly6lZqO0J8X140WZvhEhmq7DPPJTzRFbQBs= MIME-Version: 1.0 Received: by 10.231.41.66 with SMTP id n2mr6157902ibe.76.1305071214179; Tue, 10 May 2011 16:46:54 -0700 (PDT) Received: by 10.231.20.3 with HTTP; Tue, 10 May 2011 16:46:54 -0700 (PDT) In-Reply-To: <1304977077-31661-1-git-send-email-linus.walleij@linaro.org> References: <1304977077-31661-1-git-send-email-linus.walleij@linaro.org> Date: Wed, 11 May 2011 01:46:54 +0200 Message-ID: Subject: Fwd: [PATCH 08/13] i2c/i2c-nomadik: use pm_runtime API From: Linus Walleij To: patches@linaro.org ---------- Forwarded message ---------- From: Linus Walleij Date: 2011/5/9 Subject: [PATCH 08/13] i2c/i2c-nomadik: use pm_runtime API To: Ben Dooks , linux-i2c@vger.kernel.org Kopia: Rabin Vincent , Linus Walleij From: Rabin Vincent Use the pm_runtime API for pins control. Signed-off-by: Rabin Vincent Reviewed-by: Srinidhi Kasagar Reviewed-by: Jonas Aberg Signed-off-by: Linus Walleij ---  drivers/i2c/busses/i2c-nomadik.c |   51 +++++++++++++++++++++++++++++++++----  1 files changed, 45 insertions(+), 6 deletions(-)                dev_err(&pdev->dev, "could not get i2c clock\n"); @@ -958,6 +995,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)  err_no_clk:        if (dev->regulator)                regulator_put(dev->regulator); +       pm_runtime_disable(&pdev->dev);        free_irq(dev->irq, dev);  err_irq:        iounmap(dev->virtbase); @@ -990,6 +1028,7 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev)        clk_put(dev->clk);        if (dev->regulator)                regulator_put(dev->regulator); +       pm_runtime_disable(&pdev->dev);        platform_set_drvdata(pdev, NULL);        kfree(dev); @@ -1000,10 +1039,10 @@ static struct platform_driver nmk_i2c_driver = {        .driver = {                .owner = THIS_MODULE,                .name = DRIVER_NAME, +               .pm = &nmk_i2c_pm,        },        .probe = nmk_i2c_probe,        .remove = __devexit_p(nmk_i2c_remove), -       .suspend = nmk_i2c_suspend,  };  static int __init nmk_i2c_init(void) -- 1.7.5.1 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at  http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index c8bf81a..f3a0af0 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -23,6 +23,7 @@  #include  #include  #include +#include  #include @@ -576,6 +577,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,        if (dev->regulator)                regulator_enable(dev->regulator); +       pm_runtime_get_sync(&dev->pdev->dev);        status = init_hw(dev);        if (status) @@ -634,6 +636,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,  out:        clk_disable(dev->clk);  out2: +       pm_runtime_put_sync(&dev->pdev->dev);        if (dev->regulator)                regulator_disable(dev->regulator); @@ -839,19 +842,50 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)  #ifdef CONFIG_PM -static int nmk_i2c_suspend(struct platform_device *pdev, pm_message_t mesg) +static int nmk_i2c_suspend(struct device *dev)  { -       struct nmk_i2c_dev *dev = platform_get_drvdata(pdev); +       struct platform_device *pdev = to_platform_device(dev); +       struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev); -       if (dev->busy) +       if (nmk_i2c->busy)                return -EBUSY; -       else -               return 0; + +       /* +        * During system suspend, runtime suspend transitions are disabled. +        * This check and direct call are here so that even if some driver +        * performs i2c transactions in its suspend rountine, we would properly +        * runtime suspend the i2c driver. +        */ +       if (!pm_runtime_suspended(dev)) +               if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend) +                       dev->bus->pm->runtime_suspend(dev); + +       return 0; +} + +static int nmk_i2c_resume(struct device *dev) +{ +       if (!pm_runtime_suspended(dev)) +               if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume) +                       dev->bus->pm->runtime_resume(dev); + +       return 0;  }  #else  #define nmk_i2c_suspend        NULL +#define nmk_i2c_resume NULL  #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 + * there has been a regular pm runtime resume (via pm_runtime_get_sync()). + */ +static const struct dev_pm_ops nmk_i2c_pm = { +       .suspend_noirq  = nmk_i2c_suspend, +       .resume_noirq   = nmk_i2c_resume, +}; +  static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)  {        return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; @@ -913,6 +947,9 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)                dev->regulator = NULL;        } +       pm_suspend_ignore_children(&pdev->dev, true); +       pm_runtime_enable(&pdev->dev); +        dev->clk = clk_get(&pdev->dev, NULL);        if (IS_ERR(dev->clk)) {