From patchwork Wed Jul 2 15:40:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 4466481 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5B223BEECB for ; Wed, 2 Jul 2014 15:44:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 822D3203E5 for ; Wed, 2 Jul 2014 15:44:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5865203AA for ; Wed, 2 Jul 2014 15:44:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2Mfn-0006uY-HP; Wed, 02 Jul 2014 15:42:15 +0000 Received: from mailout1.w1.samsung.com ([210.118.77.11]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X2Mfa-0006l3-4J for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 15:42:03 +0000 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N8300BAYCX8NA50@mailout1.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 02 Jul 2014 16:41:32 +0100 (BST) X-AuditID: cbfec7f5-b7f626d000004b39-97-53b428309d1f Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 97.B8.19257.03824B35; Wed, 02 Jul 2014 16:41:36 +0100 (BST) Received: from AMDC1227.digital.local ([106.116.147.199]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N8300DO3CX9L0B0@eusync1.samsung.com>; Wed, 02 Jul 2014 16:41:36 +0100 (BST) From: Tomasz Figa To: linux-samsung-soc@vger.kernel.org Subject: [PATCH 1/6] pinctrl: samsung: Decouple direction setting from pinctrl Date: Wed, 02 Jul 2014 17:40:59 +0200 Message-id: <1404315664-3174-2-git-send-email-t.figa@samsung.com> X-Mailer: git-send-email 1.9.3 In-reply-to: <1404315664-3174-1-git-send-email-t.figa@samsung.com> References: <1404315664-3174-1-git-send-email-t.figa@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAJMWRmVeSWpSXmKPExsVy+t/xy7oGGluCDXbNlbE4u+wgm0Xvgqts FlP+LGey2PT4GqvFjPP7mCzWz3jN4sDmMbvhIovHnWt72Dw2L6n36NuyitHj8ya5ANYoLpuU 1JzMstQifbsEroxNa1tZCjq0Kzrf3GVqYNyg3MXIySEhYCLxf/8XNghbTOLCvfVANheHkMBS RonWj9MZIZw+JokNyxvBqtgE1CQ+NzwCs0UEVCU+ty1gByliFjjMKHFo4QEWkISwgJ/EvVOT wIpYgIru3ekGi/MKOEo8W7uRGWKdnETvtjdANgcHp4CTxLMX3iBhIaCSh+8WMU1g5F3AyLCK UTS1NLmgOCk910ivODG3uDQvXS85P3cTIySUvu5gXHrM6hCjAAejEg/vC/1NwUKsiWXFlbmH GCU4mJVEeE8IbAkW4k1JrKxKLcqPLyrNSS0+xMjEwSnVwLiM3bAoy1E8eaeZZlmEFrdzR+Yq y1e5aerXhKcdcu/sDhRVCpNL5xeI2HilWn6H1AEDW5kdbtdP3P0q45ek8/tvd887e1a9JdHn tk3LFazwbdty6P4T+wD5w40JrwX32eUoXPj3rdlrx51Es6L8haufqys7uH/l/vFz9qGnrGre FsxcJzY3KLEUZyQaajEXFScCAM/jXdMDAgAA X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140702_084202_328434_41A79ED4 X-CRM114-Status: GOOD ( 16.96 ) X-Spam-Score: -5.0 (-----) Cc: Tomasz Figa , Linus Walleij , Kukjin Kim , Doug Anderson , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 This patch makes the pinctrl-samsung driver configure GPIO direction on its own, without using the pinctrl_gpio_direction_*() "helpers". The rationale behind this change is as follows: - pinctrl-samsung does not need translation from GPIO namespace to pinctrl namespace to handle GPIO operations - GPIO chip and offset therein are enough to calculate necessary offsets and bit masks in constant time, - the pinctrl_gpio_direction_*() functions do not do anything useful other than translating the pin into pinctrl namespace and calling the .gpio_set_direction() from pinmux_ops of the controller, - the undesirable side effect of using those helpers is losing the ability to change GPIO direction in atomic context, because they explicitly use a mutex for synchronization, Results of this patch are: - fixed warnings about scheduling while atomic in code that needs to set GPIO direction in atomic context (e.g. interrupt handler), - reduced overhead of bitbanging drivers that use gpio_direction_*(), e.g. i2c-gpio. Signed-off-by: Tomasz Figa --- drivers/pinctrl/pinctrl-samsung.c | 99 +++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/drivers/pinctrl/pinctrl-samsung.c b/drivers/pinctrl/pinctrl-samsung.c index 3e61d0f..779c8bc 100644 --- a/drivers/pinctrl/pinctrl-samsung.c +++ b/drivers/pinctrl/pinctrl-samsung.c @@ -340,50 +340,6 @@ static void samsung_pinmux_disable(struct pinctrl_dev *pctldev, samsung_pinmux_setup(pctldev, selector, group, false); } -/* - * The calls to gpio_direction_output() and gpio_direction_input() - * leads to this function call (via the pinctrl_gpio_direction_{input|output}() - * function called from the gpiolib interface). - */ -static int samsung_pinmux_gpio_set_direction(struct pinctrl_dev *pctldev, - struct pinctrl_gpio_range *range, unsigned offset, bool input) -{ - struct samsung_pin_bank_type *type; - struct samsung_pin_bank *bank; - struct samsung_pinctrl_drv_data *drvdata; - void __iomem *reg; - u32 data, pin_offset, mask, shift; - unsigned long flags; - - bank = gc_to_pin_bank(range->gc); - type = bank->type; - drvdata = pinctrl_dev_get_drvdata(pctldev); - - pin_offset = offset - bank->pin_base; - reg = drvdata->virt_base + bank->pctl_offset + - type->reg_offset[PINCFG_TYPE_FUNC]; - - mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1; - shift = pin_offset * type->fld_width[PINCFG_TYPE_FUNC]; - if (shift >= 32) { - /* Some banks have two config registers */ - shift -= 32; - reg += 4; - } - - spin_lock_irqsave(&bank->slock, flags); - - data = readl(reg); - data &= ~(mask << shift); - if (!input) - data |= FUNC_OUTPUT << shift; - writel(data, reg); - - spin_unlock_irqrestore(&bank->slock, flags); - - return 0; -} - /* list of pinmux callbacks for the pinmux vertical in pinctrl core */ static const struct pinmux_ops samsung_pinmux_ops = { .get_functions_count = samsung_get_functions_count, @@ -391,7 +347,6 @@ static const struct pinmux_ops samsung_pinmux_ops = { .get_function_groups = samsung_pinmux_get_groups, .enable = samsung_pinmux_enable, .disable = samsung_pinmux_disable, - .gpio_set_direction = samsung_pinmux_gpio_set_direction, }; /* set or get the pin config settings for a specified pin */ @@ -540,25 +495,59 @@ static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset) } /* - * gpiolib gpio_direction_input callback function. The setting of the pin - * mux function as 'gpio input' will be handled by the pinctrl susbsystem - * interface. + * The calls to gpio_direction_output() and gpio_direction_input() + * leads to this function call. */ +static int samsung_gpio_set_direction(struct gpio_chip *gc, + unsigned offset, bool input) +{ + struct samsung_pin_bank_type *type; + struct samsung_pin_bank *bank; + struct samsung_pinctrl_drv_data *drvdata; + void __iomem *reg; + u32 data, mask, shift; + unsigned long flags; + + bank = gc_to_pin_bank(gc); + type = bank->type; + drvdata = bank->drvdata; + + reg = drvdata->virt_base + bank->pctl_offset + + type->reg_offset[PINCFG_TYPE_FUNC]; + + mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1; + shift = offset * type->fld_width[PINCFG_TYPE_FUNC]; + if (shift >= 32) { + /* Some banks have two config registers */ + shift -= 32; + reg += 4; + } + + spin_lock_irqsave(&bank->slock, flags); + + data = readl(reg); + data &= ~(mask << shift); + if (!input) + data |= FUNC_OUTPUT << shift; + writel(data, reg); + + spin_unlock_irqrestore(&bank->slock, flags); + + return 0; +} + +/* gpiolib gpio_direction_input callback function. */ static int samsung_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { - return pinctrl_gpio_direction_input(gc->base + offset); + return samsung_gpio_set_direction(gc, offset, true); } -/* - * gpiolib gpio_direction_output callback function. The setting of the pin - * mux function as 'gpio output' will be handled by the pinctrl susbsystem - * interface. - */ +/* gpiolib gpio_direction_output callback function. */ static int samsung_gpio_direction_output(struct gpio_chip *gc, unsigned offset, int value) { samsung_gpio_set(gc, offset, value); - return pinctrl_gpio_direction_output(gc->base + offset); + return samsung_gpio_set_direction(gc, offset, false); } /*