From patchwork Sun Jun 9 00:00:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Stuebner X-Patchwork-Id: 2693201 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id 6C9493FC8C for ; Sun, 9 Jun 2013 00:01:56 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlT4H-0003OV-5D; Sun, 09 Jun 2013 00:01:09 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlT44-0006UM-Ke; Sun, 09 Jun 2013 00:00:56 +0000 Received: from gloria.sntech.de ([95.129.55.99]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlT41-0006Tc-KB for linux-arm-kernel@lists.infradead.org; Sun, 09 Jun 2013 00:00:54 +0000 Received: from 146-52-32-150-dynip.superkabel.de ([146.52.32.150] helo=marty.localnet) by gloria.sntech.de with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1UlT3g-0006YL-1l; Sun, 09 Jun 2013 02:00:32 +0200 From: Heiko =?utf-8?q?St=C3=BCbner?= To: Linus Walleij Subject: [PATCH 2/2] pinctrl: add function to separate combined pinconfig values Date: Sun, 9 Jun 2013 02:00:29 +0200 User-Agent: KMail/1.13.7 (Linux/3.2.0-3-686-pae; KDE/4.8.4; i686; ; ) References: <201306090159.05383.heiko@sntech.de> In-Reply-To: <201306090159.05383.heiko@sntech.de> MIME-Version: 1.0 Message-Id: <201306090200.30258.heiko@sntech.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130608_200053_779685_5B8C231E X-CRM114-Status: GOOD ( 17.22 ) X-Spam-Score: -2.4 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , Patrice Chotard X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The previous patch introduced constants to combine pinconfig settings into one value for easier devicetree handling. Therefore also add a function, that can separate these bitmaps into regular generic pinconfig options for handling inside pinctrl drivers. Signed-off-by: Heiko Stuebner --- .../bindings/pinctrl/pinctrl-bindings.txt | 3 + drivers/pinctrl/pinconf-generic.c | 61 ++++++++++++++++++++ drivers/pinctrl/pinconf.h | 6 ++ 3 files changed, 70 insertions(+), 0 deletions(-) diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt index d206da0..55141af 100644 --- a/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt +++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt @@ -132,3 +132,6 @@ controller device. dt-bindings/pinctrl/pinconfig.h defines a set of constants to combine basic generic pinconfig settings, like pulls, into one value, that can be used in pinctrl bindings like . + +This value can then be split into individual generic pinconfig values in the +driver using pinconf_generic_parse_dt_bitmap. diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c index 9a6812b..90896fe 100644 --- a/drivers/pinctrl/pinconf-generic.c +++ b/drivers/pinctrl/pinconf-generic.c @@ -139,3 +139,64 @@ void pinconf_generic_dump_config(struct pinctrl_dev *pctldev, } EXPORT_SYMBOL_GPL(pinconf_generic_dump_config); #endif + +/* + * Maps the devicetree config bits to actual pinconf values. + * The array indizes match the bits set in dt-bindings/pinctrl/pinconf.h + * and the array should contain an entry for each bit defined there + */ +static unsigned long conf_map[] = { + PIN_CONF_PACKED(PIN_CONFIG_BIAS_DISABLE, 0), + PIN_CONF_PACKED(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0), + PIN_CONF_PACKED(PIN_CONFIG_BIAS_BUS_HOLD, 0), + PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, 0), + PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_UP, 0), + PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_DOWN, 0), + PIN_CONF_PACKED(PIN_CONFIG_DRIVE_PUSH_PULL, 0), + PIN_CONF_PACKED(PIN_CONFIG_DRIVE_OPEN_DRAIN, 0), + PIN_CONF_PACKED(PIN_CONFIG_DRIVE_OPEN_SOURCE, 0), + PIN_CONF_PACKED(PIN_CONFIG_INPUT_SCHMITT_ENABLE, 1), + PIN_CONF_PACKED(PIN_CONFIG_INPUT_SCHMITT_ENABLE, 0), + PIN_CONF_PACKED(PIN_CONFIG_LOW_POWER_MODE, 0), + PIN_CONF_PACKED(PIN_CONFIG_OUTPUT, 0), + PIN_CONF_PACKED(PIN_CONFIG_OUTPUT, 1), +}; + +/* + * Parse a pinconf bitmap from a devicetree entry into individual pin configs. + * @pinconf: the bitmap containing config bits + * @configs: after the function returns contains a pointer to an array of + * pin configs + * @nconfigs: number of entries of configs + */ +int pinconf_generic_parse_dt_bitmap(unsigned long pinconf, + unsigned long **configs, + unsigned int *nconfigs) +{ + int bit; + int i; + unsigned long *cnf; + unsigned int ncnf; + + ncnf = hweight_long(pinconf); + cnf = kzalloc(ncnf * sizeof(unsigned long), GFP_KERNEL); + + i = 0; + while (pinconf && i < ncnf) { + bit = __ffs(pinconf); + pinconf &= ~BIT(i); + + if (bit > ARRAY_SIZE(conf_map)) { + pr_err("%s: unknown bit %d\n", __func__, bit); + kfree(cnf); + return -EINVAL; + } + + cnf[i] = conf_map[bit]; + i++; + } + + *configs = cnf; + *nconfigs = ncnf; + return 0; +} diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h index 92c7267..ae7480c 100644 --- a/drivers/pinctrl/pinconf.h +++ b/drivers/pinctrl/pinconf.h @@ -123,3 +123,9 @@ static inline void pinconf_generic_dump_config(struct pinctrl_dev *pctldev, return; } #endif + +#ifdef CONFIG_GENERIC_PINCONF +int pinconf_generic_parse_dt_bitmap(unsigned long pinconf, + unsigned long **configs, + unsigned int *nconfigs); +#endif