From patchwork Mon Dec 15 20:20:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 5497501 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6893F9F1CD for ; Mon, 15 Dec 2014 20:20:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4FDAB209F5 for ; Mon, 15 Dec 2014 20:20:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C1209209EB for ; Mon, 15 Dec 2014 20:20:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750932AbaLOUUr (ORCPT ); Mon, 15 Dec 2014 15:20:47 -0500 Received: from sauhun.de ([89.238.76.85]:52462 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750875AbaLOUUq (ORCPT ); Mon, 15 Dec 2014 15:20:46 -0500 Received: from p4fe25b75.dip0.t-ipconnect.de ([79.226.91.117]:34940 helo=localhost) by pokefinder.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Y0c8L-0000mh-2F; Mon, 15 Dec 2014 21:20:45 +0100 From: Wolfram Sang To: linux-sh@vger.kernel.org Cc: Wolfram Sang , Magnus Damm , Simon Horman , Laurent Pinchart , Geert Uytterhoeven Subject: [RFC 1/4] pinctrl: allow to unselect a state Date: Mon, 15 Dec 2014 21:20:14 +0100 Message-Id: <1418674817-12809-2-git-send-email-wsa@the-dreams.de> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418674817-12809-1-git-send-email-wsa@the-dreams.de> References: <1418674817-12809-1-git-send-email-wsa@the-dreams.de> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wolfram Sang Needed to implement an i2c n-to-1 bus demultiplexer where n different I2C IP cores should be able to serve the same bus (like i2c-rcar, i2c-sh_mobile, and i2c-gpio on Renesas RCar Gen2 SoCs). Alternative: We could also skip this patch and define two states instead of one to be used in the demuxer, like "active" and "passive". The drawback there is, that the passive state needs some dummy pins which are not actually used. They would only exist to free the active pins, so those could be used by another I2C core. Signed-off-by: Wolfram Sang --- drivers/pinctrl/core.c | 34 +++++++++++++++++++++++----------- include/linux/pinctrl/consumer.h | 5 +++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index e4f65510c87e..a7a6834e3f67 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -977,34 +977,46 @@ struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, EXPORT_SYMBOL_GPL(pinctrl_lookup_state); /** - * pinctrl_select_state() - select/activate/program a pinctrl state to HW - * @p: the pinctrl handle for the device that requests configuration - * @state: the state handle to select/activate/program + * pinctrl_deselect_state() - deselect a pinctrl state to HW + * @p: the pinctrl handle for the device that requests deconfiguration */ -int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) +void pinctrl_deselect_state(struct pinctrl *p) { - struct pinctrl_setting *setting, *setting2; - struct pinctrl_state *old_state = p->state; - int ret; - - if (p->state == state) - return 0; + struct pinctrl_setting *setting; if (p->state) { /* * For each pinmux setting in the old state, forget SW's record * of mux owner for that pingroup. Any pingroups which are * still owned by the new state will be re-acquired by the call * to pinmux_enable_setting() in the loop below. */ list_for_each_entry(setting, &p->state->settings, node) { if (setting->type != PIN_MAP_TYPE_MUX_GROUP) continue; pinmux_disable_setting(setting); } + + p->state = NULL; } +} +EXPORT_SYMBOL_GPL(pinctrl_deselect_state); + +/** + * pinctrl_select_state() - select/activate/program a pinctrl state to HW + * @p: the pinctrl handle for the device that requests configuration + * @state: the state handle to select/activate/program + */ +int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) +{ + struct pinctrl_setting *setting, *setting2; + struct pinctrl_state *old_state = p->state; + int ret; + + if (p->state == state) + return 0; - p->state = NULL; + pinctrl_deselect_state(p); /* Apply all the settings for the new state */ list_for_each_entry(setting, &state->settings, node) { diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h index 18eccefea06e..e96eea7a835c 100644 --- a/include/linux/pinctrl/consumer.h +++ b/include/linux/pinctrl/consumer.h @@ -36,6 +36,7 @@ extern struct pinctrl_state * __must_check pinctrl_lookup_state( struct pinctrl *p, const char *name); extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s); +extern void pinctrl_deselect_state(struct pinctrl *p); extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev); extern void devm_pinctrl_put(struct pinctrl *p); @@ -102,6 +103,10 @@ static inline int pinctrl_select_state(struct pinctrl *p, return 0; } +static inline void pinctrl_deselect_state(struct pinctrl *p) +{ +} + static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev) { return NULL;