From patchwork Tue Sep 25 11:22:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 11717 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 B646623EFB for ; Tue, 25 Sep 2012 11:23:19 +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 5556EA184FA for ; Tue, 25 Sep 2012 11:23:19 +0000 (UTC) Received: by ieje10 with SMTP id e10so12507417iej.11 for ; Tue, 25 Sep 2012 04:23:18 -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=YYLZVM6jVpsJWC/dJeAvy4fE07UGTtSMHaayxK7gOGM=; b=jWE9zF9o7b6FHtUckC6+IjZv8/lrtQcbZTBySVho6ZRbmaqVKLC2kOqE0rNceX8Bt9 vzHAWAaLLnV+//ySSFw5zgkDfO2pqsxGlAyMV0I28r0kVnPhtbU7D2jeatyPE3MA8Qhi xOF3Nlr6E9fTENRJdj7lanV67dkBJPxg/o3mqHAKag6tlMzQxYw9U7Yhnq/FzHZgJzER /+rFURCc6ml13kDzGyFoWxf0/7PzNyrTY0iNBYvqsn2bIQ07jqOijUOzEmUMTHbAiyel kTjc+SohmHbuE1kBkH5pO5KqAQC3+uQH0JV1T1t+92LLOUB/Rdrx+iQhTgbVdIB9vW3X hyQA== Received: by 10.42.109.194 with SMTP id m2mr11603076icp.48.1348572198700; Tue, 25 Sep 2012 04:23:18 -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 ex8csp288570igc; Tue, 25 Sep 2012 04:23:17 -0700 (PDT) Received: by 10.14.209.5 with SMTP id r5mr18935740eeo.28.1348572196983; Tue, 25 Sep 2012 04:23:16 -0700 (PDT) Received: from eu1sys200aog116.obsmtp.com (eu1sys200aog116.obsmtp.com [207.126.144.141]) by mx.google.com with SMTP id c41si27245eem.26.2012.09.25.04.23.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Sep 2012 04:23:16 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.141 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.141; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.141 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 eu1sys200aob116.postini.com ([207.126.147.11]) with SMTP ID DSNKUGGUINlSPpaVIosC+mmqb/Wbmwq2q1pJ@postini.com; Tue, 25 Sep 2012 11:23:16 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 62CA8134; Tue, 25 Sep 2012 11:22:57 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C37B82D79; Tue, 25 Sep 2012 11:22:56 +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 4171124C07C; Tue, 25 Sep 2012 13:22:50 +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; Tue, 25 Sep 2012 13:22:56 +0200 From: Linus Walleij To: Ben Dooks , Wolfram Sang , Cc: Anmar Oueja , Patrice Chotard , Linus Walleij Subject: [PATCH] i2c: nomadik: adopt pinctrl support Date: Tue, 25 Sep 2012 13:22:47 +0200 Message-ID: <1348572167-3770-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: ALoCoQmtHRjn6DLKnWhazvpcgzvmGQugE3z3tevJMJ6siLwHczgC2PeH+44ncrvuz3EeCC9Toyj+ From: Patrice Chotard Amend the I2C nomadik pin controller to optionally take a pin control handle and set the state of the pins to "default" on boot and before performing an i2c transfer, and to "sleep" after an i2c xfer. Signed-off-by: Patrice Chotard Signed-off-by: Linus Walleij --- drivers/i2c/busses/i2c-nomadik.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 1b898b6..8ed3962 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -24,6 +24,7 @@ #include #include #include +#include #define DRIVER_NAME "nmk-i2c" @@ -158,6 +159,10 @@ struct nmk_i2c_dev { int stop; struct completion xfer_complete; int result; + /* Two optional pin states - default & sleep */ + struct pinctrl *pinctrl; + struct pinctrl_state *pins_default; + struct pinctrl_state *pins_sleep; bool busy; }; @@ -642,6 +647,15 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, pm_runtime_get_sync(&dev->adev->dev); + /* Optionaly enable pins to be muxed in and configured */ + if (!IS_ERR(dev->pins_default)) { + status = pinctrl_select_state(dev->pinctrl, + dev->pins_default); + if (status) + dev_err(&dev->adev->dev, + "could not set default pins\n"); + } + clk_enable(dev->clk); status = init_hw(dev); @@ -670,6 +684,16 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap, out: clk_disable(dev->clk); + + /* Optionally let pins go into sleep states */ + if (!IS_ERR(dev->pins_sleep)) { + status = pinctrl_select_state(dev->pinctrl, + dev->pins_sleep); + if (status) + dev_err(&dev->adev->dev, + "could not set pins to sleep state\n"); + } + pm_runtime_put_sync(&dev->adev->dev); dev->busy = false; @@ -936,6 +960,22 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) dev->adev = adev; amba_set_drvdata(adev, dev); + dev->pinctrl = devm_pinctrl_get(&adev->dev); + if (IS_ERR(dev->pinctrl)) { + ret = PTR_ERR(dev->pinctrl); + goto err_pinctrl; + } + + dev->pins_default = pinctrl_lookup_state(dev->pinctrl, + PINCTRL_STATE_DEFAULT); + if (IS_ERR(dev->pins_default)) + dev_err(&adev->dev, "could not get default pinstate\n"); + + dev->pins_sleep = pinctrl_lookup_state(dev->pinctrl, + PINCTRL_STATE_SLEEP); + if (IS_ERR(dev->pins_sleep)) + dev_dbg(&adev->dev, "could not get sleep pinstate\n"); + dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); if (!dev->virtbase) { ret = -ENOMEM; @@ -1002,6 +1042,7 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) err_no_ioremap: amba_set_drvdata(adev, NULL); kfree(dev); + err_pinctrl: err_no_mem: return ret;