From patchwork Mon Jan 18 15:21:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youngmin Nam X-Patchwork-Id: 8055381 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 309189F440 for ; Mon, 18 Jan 2016 15:21:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4212C2039C for ; Mon, 18 Jan 2016 15:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA26C20386 for ; Mon, 18 Jan 2016 15:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753401AbcARPV0 (ORCPT ); Mon, 18 Jan 2016 10:21:26 -0500 Received: from mail-pf0-f178.google.com ([209.85.192.178]:36787 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753285AbcARPVZ (ORCPT ); Mon, 18 Jan 2016 10:21:25 -0500 Received: by mail-pf0-f178.google.com with SMTP id n128so159229500pfn.3 for ; Mon, 18 Jan 2016 07:21: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=pZSO9ri6TodUZT/7IYIkCcbK2KUkC99jm5slXTHKB60=; b=vq74CFz1PdRkNdCmZiX2vWA75qn3cqNR07OHdg0FMZY8nIYJL9bNcBov6vjv//UTW7 r1VbFWEtcxW8xFAK1lNVVT+tjt1bDJjUJyZmh9a2w/ufkfyXX9/wqga7wvFiwHA404ib 40E6/B9bha2gB3UGM8wX6XbYSzc8VuvvUDDiQJV/f/+IEN/uWFNET+gLJkvP/jHmwTBu U7ijEypmFq2KD/A4aweNNnXM2WTuGSJQu2EpMfAG7OrNNrMKSybxWaMT6ftSiZFTVosC YjNHLCITAZ6vj9N6iY/dbH9vLB+NGQkYS9E/KpgqelJLtg8iIDnYTVCpgSMTiK1lwUXF 9iAA== 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=pZSO9ri6TodUZT/7IYIkCcbK2KUkC99jm5slXTHKB60=; b=NCKl3xylWKOd27SnmkxajzxuHBSdkq0tp9DQ+jMQIO766GXrBw/GRHWO0dN6cVKfNl X2dbMGPCSXQN113kLxmwVfexN+OYelpSXcp1QX8Wc7JXV3aLjjhIMFvSp5E/P0k3VsqZ KJTapbF5i7etNbPWIGdZXQREGczN6G4szmgS+Nr9y+pj7qiMmUYN34aqk+kInkg/YStH 15B46fwAbQGUCZdDHPgVV28FU7Qk7JKJXzhIVyVlf1QkgewUFr3i0P0mbLdFhyr8enkD RTkfRkRjbgZ07a81JYB4PDQJtFHcIU9nwnRpAV0LqH7rg1mcKbV+/T2qJvHnWETc5Ddr oKrg== X-Gm-Message-State: ALoCoQnNqq1E2Cxkc1shIdOfXmIInm2peFCwdsRf5GrwVC6fvQELEsSUN20MNUym9IzdVONA7EIiqCHSXlI72iUBC0rw3KbcUA== X-Received: by 10.98.75.4 with SMTP id y4mr37075299pfa.32.1453130484878; Mon, 18 Jan 2016 07:21:24 -0800 (PST) Received: from youngmin ([49.175.82.80]) by smtp.gmail.com with ESMTPSA id 7sm34739152pfn.89.2016.01.18.07.21.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jan 2016 07:21:24 -0800 (PST) Received: by youngmin (Postfix, from userid 1000) id 52476166B89; Tue, 19 Jan 2016 00:21:21 +0900 (KST) From: Youngmin Nam To: tomasz.figa@gmail.com, k.kozlowski@samsung.com, linus.walleij@linaro.org, kgene@kernel.org, thomas.ab@samsung.com Cc: linux-samsung-soc@vger.kernel.org, Youngmin Nam Subject: [PATCH] pinctrl: samsung: Fixes samsung_gpio_direction_in/output releated with spinlock Date: Tue, 19 Jan 2016 00:21:02 +0900 Message-Id: <1453130462-3621-1-git-send-email-ym0914@gmail.com> X-Mailer: git-send-email 2.7.0.25.gfc10eb5 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=-6.8 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, gpio set callback was changed with samsung_gpio_set_value to implement gpio set callback with spinlock using samsung_gpio_set. Signed-off-by: Youngmin Nam --- drivers/pinctrl/samsung/pinctrl-samsung.c | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index 48294e7..a25f6f6 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -524,20 +524,26 @@ static void samsung_gpio_set(struct gpio_chip *gc, unsigned offset, int value) { struct samsung_pin_bank *bank = gc_to_pin_bank(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]); +} + +static void samsung_gpio_set_value(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(gc, offset, value); spin_unlock_irqrestore(&bank->slock, flags); } @@ -569,7 +575,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 = gc_to_pin_bank(gc); type = bank->type; @@ -586,31 +591,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) { + struct samsung_pin_bank *bank = gc_to_pin_bank(gc); + unsigned long flags; + int ret; + + spin_lock_irqsave(&bank->slock, flags); samsung_gpio_set(gc, offset, value); - return samsung_gpio_set_direction(gc, offset, false); + ret = samsung_gpio_set_direction(gc, offset, false); + spin_unlock_irqrestore(&bank->slock, flags); + + return ret; } /* @@ -891,7 +907,7 @@ static int samsung_pinctrl_register(struct platform_device *pdev, static const struct gpio_chip samsung_gpiolib_chip = { .request = gpiochip_generic_request, .free = gpiochip_generic_free, - .set = samsung_gpio_set, + .set = samsung_gpio_set_value, .get = samsung_gpio_get, .direction_input = samsung_gpio_direction_input, .direction_output = samsung_gpio_direction_output,