From patchwork Mon Feb 8 14:54:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youngmin Nam X-Patchwork-Id: 8250701 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D203FBEEE5 for ; Mon, 8 Feb 2016 14:54:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D729A203B7 for ; Mon, 8 Feb 2016 14:54:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CAFF22035B for ; Mon, 8 Feb 2016 14:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754031AbcBHOym (ORCPT ); Mon, 8 Feb 2016 09:54:42 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33122 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753603AbcBHOyZ (ORCPT ); Mon, 8 Feb 2016 09:54:25 -0500 Received: by mail-pf0-f195.google.com with SMTP id c10so8346380pfc.0 for ; Mon, 08 Feb 2016 06:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=/6Dvll6NvtzHp++lCedXYet9mRmJKi8mTPbQ0bLE5Rw=; b=X6BnPMZyUhJEtfMfw/iuz82IVcGfYs70Tpari3yrwXPFMa/3YOL3+jRiy9JNmt1/bX CyXq2fjO6xdDnobYDIWwJM8kdsiRL8WBp72UoVDz45m+iU2k8c9x3EMHp0xMcPvVAx+K DYkIaru1eXCoR9ArlYUv1Qo3inCHHpiU+wZjk4pgEaBPd79XesxdQ0WZ3T+S11773opl 95M9miS0d9rd40M/Afz6/m4mro6OOoVlplsmZBOr2KmqAAUkII+YM1VCZ/6D9+aXd4Fb hEEbz5vBnDXgO6aVN91YAR0GJCIeJUtIDLP79rA0m3rn9/YTsQbcgA65vQSbm482DCQZ QJtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/6Dvll6NvtzHp++lCedXYet9mRmJKi8mTPbQ0bLE5Rw=; b=kqo3rARequ8nhTq20UsCbZWwCyRqI59261qdU7O1tySHWWmSezNch8+0rH31fOqwBP eLeioSKZFkqTs7kzX1GakEReX/aFxzP1IMrco3Wx6VIpIhqn1f4QmfGPMG1Weeq2W2pZ 07RI70fAvsVV6TIPheY0mXUZ/Wa1T5jzGhc/Qr0sjj3JAYXFNk9buFbpT3WIg3BYu5J0 oh4LAal4REb9PzZnsZTtGsayf/ewuwO45A6h6tPgYzkUPn+Q2wCmIt6+v6zL3K31uFXV l/C3C1eRjRLED2rqzhyqB438PanHY9dsNkY1C0+2aH5NpZNWJszNUYidEJkx+g/rbtrt 2Nzg== X-Gm-Message-State: AG10YOR1t8ORz3CPG6j8VnYf1exLKEZoWAkvuUOm+s6QQ0D6UkqHn73sRMZqeYKCzARoIQ== X-Received: by 10.98.34.198 with SMTP id p67mr42709020pfj.93.1454943264932; Mon, 08 Feb 2016 06:54:24 -0800 (PST) Received: from youngmin-870Z5G-880Z5F ([101.235.122.14]) by smtp.gmail.com with ESMTPSA id ey2sm44227771pab.2.2016.02.08.06.54.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 06:54:23 -0800 (PST) Received: by youngmin-870Z5G-880Z5F (Postfix, from userid 1000) id 84C592E23E7; Mon, 8 Feb 2016 23:54:21 +0900 (KST) From: Youngmin Nam To: tomasz.figa@gmail.com, linus.walleij@linaro.org Cc: k.kozlowski@samsung.com, kgene@kernel.org, thomas.ab@samsung.com, linux-samsung-soc@vger.kernel.org, Youngmin Nam Subject: [PATCH v3] pinctrl: samsung: Fixes samsung_gpio_direction_in/output releated with spinlock Date: Mon, 8 Feb 2016 23:54:19 +0900 Message-Id: <1454943259-5486-1-git-send-email-ym0914@gmail.com> X-Mailer: git-send-email 2.7.1 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Previously, samsung_gpio_drection_in/output function were not covered with one spinlock. For example, samsung_gpio_direction_output function consists of two functions. 1. samsung_gpio_set 2. samsung_gpio_set_direction When 2 CPUs try to control the same gpio pin heavily, (situation like i2c control with gpio emulation) This situation can cause below problem. CPU 0 | CPU1 | samsung_gpio_direction_output | samsung_gpio_set(pin A as 1) | samsung_gpio_direction_output | samsung_gpio_set(pin A as 0) samsung_gpio_set_direction | | samsung_gpio_set_direction The initial value of pin A will be set as 0 while we wanted to set pin A as 1. This patch modifies samsung_gpio_direction_in/output function to be done in one spinlock to fix race condition. Additionally, the new samsung_gpio_set_value was added to implement gpio set callback(samsung_gpio_set) with spinlock using this function. Signed-off-by: Youngmin Nam Acked-by: Tomasz Figa --- drivers/pinctrl/samsung/pinctrl-samsung.c | 48 ++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index f67b1e9..38142c2 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -514,25 +514,35 @@ static const struct pinconf_ops samsung_pinconf_ops = { .pin_config_group_set = samsung_pinconf_group_set, }; -/* gpiolib gpio_set callback function */ -static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value) +/* + * The samsung_gpio_set_vlaue() should be called with "bank->slock" held + * to avoid race condition. + */ +static void samsung_gpio_set_value(struct gpio_chip *gc, + unsigned offset, int value) { struct samsung_pin_bank *bank = gpiochip_get_data(gc); const struct samsung_pin_bank_type *type = bank->type; - unsigned long flags; void __iomem *reg; u32 data; reg = bank->drvdata->virt_base + bank->pctl_offset; - spin_lock_irqsave(&bank->slock, flags); - data = readl(reg + type->reg_offset[PINCFG_TYPE_DAT]); data &= ~(1 << offset); if (value) data |= 1 << offset; writel(data, reg + type->reg_offset[PINCFG_TYPE_DAT]); +} +/* gpiolib gpio_set callback function */ +static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value) +{ + struct samsung_pin_bank *bank = gc_to_pin_bank(gc); + unsigned long flags; + + spin_lock_irqsave(&bank->slock, flags); + samsung_gpio_set_value(gc, offset, value); spin_unlock_irqrestore(&bank->slock, flags); } @@ -553,6 +563,8 @@ static int samsung_gpio_get(struct gpio_chip *gc, unsigned offset) } /* + * The samsung_gpio_set_direction() should be called with "bank->slock" held + * to avoid race condition. * The calls to gpio_direction_output() and gpio_direction_input() * leads to this function call. */ @@ -564,7 +576,6 @@ static int samsung_gpio_set_direction(struct gpio_chip *gc, struct samsung_pinctrl_drv_data *drvdata; void __iomem *reg; u32 data, mask, shift; - unsigned long flags; bank = gpiochip_get_data(gc); type = bank->type; @@ -581,31 +592,42 @@ static int samsung_gpio_set_direction(struct gpio_chip *gc, 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 samsung_gpio_set_direction(gc, offset, true); + struct samsung_pin_bank *bank = gc_to_pin_bank(gc); + unsigned long flags; + int ret; + + spin_lock_irqsave(&bank->slock, flags); + ret = samsung_gpio_set_direction(gc, offset, true); + spin_unlock_irqrestore(&bank->slock, flags); + return ret; } /* 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 samsung_gpio_set_direction(gc, offset, false); + struct samsung_pin_bank *bank = gc_to_pin_bank(gc); + unsigned long flags; + int ret; + + spin_lock_irqsave(&bank->slock, flags); + samsung_gpio_set_value(gc, offset, value); + ret = samsung_gpio_set_direction(gc, offset, false); + spin_unlock_irqrestore(&bank->slock, flags); + + return ret; } /*