From patchwork Tue Dec 11 13:59:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13477 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 8AF4223FC0 for ; Tue, 11 Dec 2012 14:00:24 +0000 (UTC) Received: from mail-ie0-f177.google.com (mail-ie0-f177.google.com [209.85.223.177]) by fiordland.canonical.com (Postfix) with ESMTP id 21558A198EC for ; Tue, 11 Dec 2012 14:00:24 +0000 (UTC) Received: by mail-ie0-f177.google.com with SMTP id k13so12696437iea.36 for ; Tue, 11 Dec 2012 06:00:23 -0800 (PST) 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=P0tyWdgCej6HskGLqN/7DKdWw2xE9o4CzmEzVmRzslg=; b=bvrwZ+SowxV7JpqoCFLaoJiJkmo4wgC9xHeJvWe728F1HUxqoWJ3V2MNHPVNWwvxgo IJXX2T6qvwWyDO6cz5Jr4wa0DFh35ChfKenboFMuNSkKZbaqucRLn3vMx62Hm5XJk10u sLBDlEpO5dSCEmX/s8G57EreEPy3qF3L0RUSxgLczmLEMf+8/o+K6tKsiOSdVLW0ZQHv 3Ib6VLcoPlLy3c/0MPifTFToVHQ2xiO0YQIc8CfXjVTbbPmap8bJ0x/bczAe+RuPZhn2 o98mZpZ+/4ODTRC7PmmSH6Kghbz9qoWOVBqSYjxOf/qJ/rdqthsgACuSILa9c3X1+OI8 0ghw== Received: by 10.50.187.197 with SMTP id fu5mr9797095igc.70.1355234423528; Tue, 11 Dec 2012 06:00:23 -0800 (PST) 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.67.148 with SMTP id n20csp133202igt; Tue, 11 Dec 2012 06:00:23 -0800 (PST) Received: by 10.14.194.4 with SMTP id l4mr60724044een.42.1355234422651; Tue, 11 Dec 2012 06:00:22 -0800 (PST) Received: from eu1sys200aog102.obsmtp.com (eu1sys200aog102.obsmtp.com [207.126.144.113]) by mx.google.com with SMTP id k48si55091808een.74.2012.12.11.06.00.10 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 11 Dec 2012 06:00:22 -0800 (PST) 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 DSNKUMc8YmEne+RHvchrSb8XCAh9iIK/21kq@postini.com; Tue, 11 Dec 2012 14:00:19 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 B1466118; Tue, 11 Dec 2012 13:51:46 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 03D04D1F; Tue, 11 Dec 2012 13:59:58 +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 relay1.stm.gmessaging.net (Postfix) with ESMTPS id 103BF24C2F4; Tue, 11 Dec 2012 14:59:50 +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; Tue, 11 Dec 2012 14:59:56 +0100 From: Linus Walleij To: , Cc: Stephen Warren , Anmar Oueja , Julien Delacou , Linus Walleij Subject: [PATCH 1/2] pinctrl: add sleep mode management for hogs Date: Tue, 11 Dec 2012 14:59:53 +0100 Message-ID: <1355234393-17368-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: ALoCoQmiwbzzQPS04qAOrNzjrSjiDW6q780fA1pSCBjCQ4hI1rXSaYpVnYYKRwX5Ib8pT6BUpm80 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 from the individual pinctrl drivers. Signed-off-by: Julien Delacou Signed-off-by: Linus Walleij --- drivers/pinctrl/core.c | 35 ++++++++++++++++++++++++++++++++--- drivers/pinctrl/core.h | 4 ++++ include/linux/pinctrl/pinctrl.h | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 5cdee86..f9c50bb 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -1055,6 +1055,28 @@ 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; +} + +/** + * 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; +} + #ifdef CONFIG_DEBUG_FS static int pinctrl_pins_show(struct seq_file *s, void *what) @@ -1500,16 +1522,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..b5bbb09 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 diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h index 04d6700..814cb56 100644 --- a/include/linux/pinctrl/pinctrl.h +++ b/include/linux/pinctrl/pinctrl.h @@ -155,6 +155,8 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np) extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev); extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev); +extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); +extern int pinctrl_force_default(struct pinctrl_dev *pctldev); #else struct pinctrl_dev;