From patchwork Fri Dec 14 20:00:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1880291 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id C9AF43FC64 for ; Fri, 14 Dec 2012 20:04:35 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TjbRd-0006wU-9Y; Fri, 14 Dec 2012 20:01:17 +0000 Received: from bombadil.infradead.org ([2001:4830:2446:ff00:4687:fcff:fea6:5117]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TjbRZ-0006wP-Gw for linux-arm-kernel@merlin.infradead.org; Fri, 14 Dec 2012 20:01:13 +0000 Received: from eu1sys200aog109.obsmtp.com ([207.126.144.127]) by bombadil.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1TjbRY-000683-95 for linux-arm-kernel@lists.infradead.org; Fri, 14 Dec 2012 20:01:12 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob109.postini.com ([207.126.147.11]) with SMTP ID DSNKUMuFdFpAVlJhX4QZiOhTrfMt2/o9//UQ@postini.com; Fri, 14 Dec 2012 20:01:12 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 6C65B223; Fri, 14 Dec 2012 20:00:38 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E3F2F5570; Fri, 14 Dec 2012 20:00:37 +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 10D0AA8074; Fri, 14 Dec 2012 21:00:30 +0100 (CET) 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; Fri, 14 Dec 2012 21:00:36 +0100 From: Linus Walleij To: , Subject: [PATCH v2] pinctrl: add sleep mode management Date: Fri, 14 Dec 2012 21:00:33 +0100 Message-ID: <1355515233-23663-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.11.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121214_150112_612260_30B85470 X-CRM114-Status: GOOD ( 14.33 ) X-Spam-Note: SpamAssassin invocation failed Cc: Anmar Oueja , Linus Walleij , Julien Delacou , Stephen Warren X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Julien Delacou This fix allows handling sleep mode for hogged pins in pinctrl. It provides functions to set pins to sleep/default configurations according to their current state. Signed-off-by: Julien Delacou Signed-off-by: Linus Walleij Reviewed-by: Stephen Warren --- ChangeLog v1->v2: - Move function prototypes to the local pinctrl/core.h header file - Added exports --- drivers/pinctrl/core.c | 37 ++++++++++++++++++++++++++++++++++--- drivers/pinctrl/core.h | 7 +++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 5b4885c..3611753 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -1076,6 +1076,30 @@ void pinctrl_unregister_map(struct pinctrl_map const *map) } } +/** + * pinctrl_force_sleep() - turn a given controller device into sleep state + * @pctldev: pin controller device + */ +int pinctrl_force_sleep(struct pinctrl_dev *pctldev) +{ + if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep)) + return pinctrl_select_state(pctldev->p, pctldev->hog_sleep); + return 0; +} +EXPORT_SYMBOL_GPL(pinctrl_force_sleep); + +/** + * pinctrl_force_default() - turn a given controller device into default state + * @pctldev: pin controller device + */ +int pinctrl_force_default(struct pinctrl_dev *pctldev) +{ + if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default)) + return pinctrl_select_state(pctldev->p, pctldev->hog_default); + return 0; +} +EXPORT_SYMBOL_GPL(pinctrl_force_default); + #ifdef CONFIG_DEBUG_FS static int pinctrl_pins_show(struct seq_file *s, void *what) @@ -1521,16 +1545,23 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, pctldev->p = pinctrl_get_locked(pctldev->dev); if (!IS_ERR(pctldev->p)) { - struct pinctrl_state *s = + pctldev->hog_default = pinctrl_lookup_state_locked(pctldev->p, PINCTRL_STATE_DEFAULT); - if (IS_ERR(s)) { + if (IS_ERR(pctldev->hog_default)) { dev_dbg(dev, "failed to lookup the default state\n"); } else { - if (pinctrl_select_state_locked(pctldev->p, s)) + if (pinctrl_select_state_locked(pctldev->p, + pctldev->hog_default)) dev_err(dev, "failed to select default state\n"); } + + pctldev->hog_sleep = + pinctrl_lookup_state_locked(pctldev->p, + PINCTRL_STATE_SLEEP); + if (IS_ERR(pctldev->hog_sleep)) + dev_dbg(dev, "failed to lookup the sleep state\n"); } mutex_unlock(&pinctrl_mutex); diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 12f5694..232a9f6 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -30,6 +30,8 @@ struct pinctrl_gpio_range; * @driver_data: driver data for drivers registering to the pin controller * subsystem * @p: result of pinctrl_get() for this device + * @hog_default: default state for pins hogged by this device + * @hog_sleep: sleep state for pins hogged by this device * @device_root: debugfs root for this device */ struct pinctrl_dev { @@ -41,6 +43,8 @@ struct pinctrl_dev { struct module *owner; void *driver_data; struct pinctrl *p; + struct pinctrl_state *hog_default; + struct pinctrl_state *hog_sleep; #ifdef CONFIG_DEBUG_FS struct dentry *device_root; #endif @@ -164,5 +168,8 @@ int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, bool dup, bool locked); void pinctrl_unregister_map(struct pinctrl_map const *map); +extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); +extern int pinctrl_force_default(struct pinctrl_dev *pctldev); + extern struct mutex pinctrl_mutex; extern struct list_head pinctrldev_list;