From patchwork Sun Jan 17 07:41:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youngmin Nam X-Patchwork-Id: 8050171 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 097A2BEEE5 for ; Sun, 17 Jan 2016 07:41:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 12286202C8 for ; Sun, 17 Jan 2016 07:41:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 806EF202FE for ; Sun, 17 Jan 2016 07:41:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753358AbcAQHl3 (ORCPT ); Sun, 17 Jan 2016 02:41:29 -0500 Received: from mail-pf0-f181.google.com ([209.85.192.181]:34256 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753356AbcAQHlS (ORCPT ); Sun, 17 Jan 2016 02:41:18 -0500 Received: by mail-pf0-f181.google.com with SMTP id q63so144758868pfb.1 for ; Sat, 16 Jan 2016 23:41:17 -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=eJhgL9qosujXtf+e6gyvkNyHZYX/jb3CFnFWogelNX1usxUHthgLXgLTf3P2BjLCQl J4UaKYeYBUBdgJwU/JTNM1t6B5EeVfHsSWWByXxlM906xy3XN/4SDUHosufpznW9pWxn fSbHmxO6rGrJU4mtYotKvv9gw9WEkkr00OjFPmvVQdWal9Syj9iukSzG/CBN7Tz72v36 tVQrlJbbVVF4kv7TcvAHQJVc46zm1hkWW52X9qLh33FP394hZOTMBWe+/CgSw3W1mTf/ NO+/tP5th6NwpQ71G5WDK8IDyiwCgx/uHIskmZNoutTwUp6o3iFx/1qIik780jXnmYQI NADg== 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=iPCDufsnmbWmaZjxBKWrLjZ+6VLYjprG687hClamwZqFi5LD89ra7b1U2wh8u7Ko6s /odBlnEr6CpcOklQNVakGgnPs3QsL8Ja+nsHw1fPyHbuji4maX+IgSMmzHzNc5rCJA16 OhYoZbg5H0KClyiP2WoGLnPtHnS8AOHPmGcVx4ETToL9f3zpUUXoJt+mpaDBdQFODK/V 3HlFm+kqVZUeD3kjyLLB5q2Ca4mDk13qOM2JpkdxYPN+FcbsdYiq9wRhUOI60sCtKl+B cV/ueHQQ5jp3HSfEpU9Q63w1ZHxgryJiFN15CF8unDAXZBoBjgqp8tZI7k7n4BCM62PN v38A== X-Gm-Message-State: ALoCoQlIf80rlPr7ds+uYZSSJKBMhyHI7KxsFHx3+bPwda2nRKftYefDTkSZ2XUQs5JCC9DkNNNSupdP8j9zIFdCR3FnBTErqA== X-Received: by 10.98.80.135 with SMTP id g7mr27679152pfj.132.1453016477754; Sat, 16 Jan 2016 23:41:17 -0800 (PST) Received: from youngmin ([101.235.112.47]) by smtp.gmail.com with ESMTPSA id w22sm25702504pfa.79.2016.01.16.23.41.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Jan 2016 23:41:17 -0800 (PST) Received: by youngmin (Postfix, from userid 1000) id 1C1F816066D; Sun, 17 Jan 2016 16:41:15 +0900 (KST) From: Youngmin Nam To: k.kozlowski@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: Sun, 17 Jan 2016 16:41:13 +0900 Message-Id: <1453016473-14203-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,