From patchwork Mon Feb 8 15:49:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Youngmin Nam X-Patchwork-Id: 8251551 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 A1B52BEEE5 for ; Mon, 8 Feb 2016 15:49:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B2F8D203DA for ; Mon, 8 Feb 2016 15:49:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 98999202EC for ; Mon, 8 Feb 2016 15:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754589AbcBHPtv (ORCPT ); Mon, 8 Feb 2016 10:49:51 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36034 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754404AbcBHPtv (ORCPT ); Mon, 8 Feb 2016 10:49:51 -0500 Received: by mail-pf0-f193.google.com with SMTP id e127so1275432pfe.3 for ; Mon, 08 Feb 2016 07:49:50 -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=uKrPtQABIYml/vmNH2Hc+5wCdb7KXCjtdk6I2cml598=; b=AtxsRl3J7SrlVR5lW6wTxVAXkqS64wsmXVyOdow1qh6XwKXEofMH6IBXUWUlmlwXwu +DkSgQdP1yi0Ba/RxlitDp4NXl/rEQJ6tlgpkmrlSvOcXiIp23YNlJKDnJZHjj50QU80 ZXNWgw6JozWS7t9aAC7wYWJR9PBW5hu61/P0s381qWzh84st5BOG1KmGY1NECULoPMrT RkH6JCDaS7ZLwi5yYKJOZU8gUx5Kn4HMjpaTLxh22PyHHgjd+7nLPVdx5nDe6RDMNxJ7 ZuZIPNpl/vsm2Yz1ic0r6ttkmOvlDJKlEuyLmc9//BPV+XyHzdPOmkvYkTj1AYHqdewG Ig/A== 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=uKrPtQABIYml/vmNH2Hc+5wCdb7KXCjtdk6I2cml598=; b=eKIMf7+kp3YuABm6qN0r0PEFXRL51w8oZ2/+/+vDJ14iHirz/tolqMy8uRbjj9RUJc UiX9kWz2s0ZKH9v6rpUYd2bZnwKGZpPJd2ESCzm+2cLE5U0YJILOukdr5ablCSp8zAt/ CEghFX6Zv9ILyeFB/7E57fy8W7hNWUPU1eifxYdyhklt2gZcA+00DdiIVAhh2fD97Tfg aLEW4JWwEiV6ed+AfO6Ow8WTYU5q1mxUkdCIs85m5mX30ZYTgcNRF46eZ7IWy6r0qSoS MifnS54kXEyrqpAkIgwBzxDznk4pyn1JcO2bVJIekB9XxdndYfGlXRUikJEFWjLvXGe8 eeYg== X-Gm-Message-State: AG10YOR44zrrcsv8jrxfSI1AV3gw7pvRJF++/LV4xH5NpSS85908r0g977Cqp8aXw6KWSg== X-Received: by 10.98.13.154 with SMTP id 26mr28812214pfn.164.1454946590611; Mon, 08 Feb 2016 07:49:50 -0800 (PST) Received: from youngmin-870Z5G-880Z5F ([101.235.122.14]) by smtp.gmail.com with ESMTPSA id ud8sm37486012pac.11.2016.02.08.07.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 07:49:49 -0800 (PST) Received: by youngmin-870Z5G-880Z5F (Postfix, from userid 1000) id 428412E2541; Tue, 9 Feb 2016 00:49:47 +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 v4] pinctrl: samsung: Fixes samsung_gpio_direction_in/output releated with spinlock Date: Tue, 9 Feb 2016 00:49:28 +0900 Message-Id: <1454946568-23604-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..5cc97f8 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 = gpiochip_get_data(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 = gpiochip_get_data(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 = gpiochip_get_data(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; } /*