From patchwork Sat Aug 23 20:42:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 4769991 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5F9AF9F2E8 for ; Sat, 23 Aug 2014 20:43:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86397201BA for ; Sat, 23 Aug 2014 20:43:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 907162018E for ; Sat, 23 Aug 2014 20:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751143AbaHWUm5 (ORCPT ); Sat, 23 Aug 2014 16:42:57 -0400 Received: from mail-lb0-f172.google.com ([209.85.217.172]:64980 "EHLO mail-lb0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751170AbaHWUm4 (ORCPT ); Sat, 23 Aug 2014 16:42:56 -0400 Received: by mail-lb0-f172.google.com with SMTP id z11so10897746lbi.3 for ; Sat, 23 Aug 2014 13:42:54 -0700 (PDT) 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:organization :user-agent:mime-version:content-transfer-encoding:content-type; bh=c8goxMQqJ4kui0N6/DAD2i3krrZ8DywxUvyXhgCfwq4=; b=lRQM+8Mps12mRS5UJ1rzY0OncFKocQH4xfwLxg1nA2qiPC/XYn+j/UbUiy2c0Bs5hT o+2hg2SgiGaLDDaWYiSUiFW4vv3DldRe+WKYXqutoC1Jl3uhD6kF45BiXxXt915FvfHx aM/rFmEYqvCL12MumM7NzuWaW3TBStSneiqkCEAawS66aNcnQygnERSoVZGTgSXx0wNV E0DNQcTSUi0l8hsq9OhSN2lkfZkZnhLLxgG/hrRQYOqc1oYlqv1vnYPZYhxcOaycVOkG TOLHHM1WaS1f2eE6ChxNltnsGRPHC5HXCaIqlYqaf/WzkEfse+fmUxktr9joeKqgyljN 0eMA== X-Gm-Message-State: ALoCoQnGe6zECk8mDCBg2gFL/bfW1Bmul97UzI1SqyItFjxjTER466GKYVvzCRzDDTqm4/tyzih/ X-Received: by 10.152.8.82 with SMTP id p18mr3397546laa.83.1408826574697; Sat, 23 Aug 2014 13:42:54 -0700 (PDT) Received: from wasted.cogentembedded.com (ppp16-220.pppoe.mtu-net.ru. [81.195.16.220]) by mx.google.com with ESMTPSA id u6sm20735089laj.7.2014.08.23.13.42.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Aug 2014 13:42:53 -0700 (PDT) From: Sergei Shtylyov To: wsa@the-dreams.de, linux-i2c@vger.kernel.org Cc: linux-sh@vger.kernel.org Subject: [PATCH] Revert "i2c-rcar: remove spinlock" Date: Sun, 24 Aug 2014 00:42:52 +0400 Message-ID: <5687273.SAZk4lxXAk@wasted.cogentembedded.com> Organization: Cogent Embedded Inc. User-Agent: KMail/4.13.3 (Linux/3.15.10-200.fc20.x86_64; KDE/4.13.3; x86_64; ; ) MIME-Version: 1.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 reverts commit 150b8be3cda54412ad7b54f5392b513b25c0aaa7. The I2C core's per-adapter locks can't protect from IRQs, so the driver still needs a spinlock to protect the register accesses. Signed-off-by: Sergei Shtylyov Cc: stable@vger.kernel.org # 3.16+ --- The patch is against Wolfram Sang's 'linux.git' repo. drivers/i2c/busses/i2c-rcar.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux/drivers/i2c/busses/i2c-rcar.c =================================================================== --- linux.orig/drivers/i2c/busses/i2c-rcar.c +++ linux/drivers/i2c/busses/i2c-rcar.c @@ -34,6 +34,7 @@ #include #include #include +#include /* register offsets */ #define ICSCR 0x00 /* slave ctrl */ @@ -95,6 +96,7 @@ struct rcar_i2c_priv { struct i2c_msg *msg; struct clk *clk; + spinlock_t lock; wait_queue_head_t wait; int pos; @@ -365,6 +367,9 @@ static irqreturn_t rcar_i2c_irq(int irq, struct rcar_i2c_priv *priv = ptr; u32 msr; + /*-------------- spin lock -----------------*/ + spin_lock(&priv->lock); + msr = rcar_i2c_read(priv, ICMSR); /* Arbitration lost */ @@ -400,6 +405,9 @@ out: wake_up(&priv->wait); } + spin_unlock(&priv->lock); + /*-------------- spin unlock -----------------*/ + return IRQ_HANDLED; } @@ -409,14 +417,21 @@ static int rcar_i2c_master_xfer(struct i { struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); struct device *dev = rcar_i2c_priv_to_dev(priv); + unsigned long flags; int i, ret, timeout; pm_runtime_get_sync(dev); + /*-------------- spin lock -----------------*/ + spin_lock_irqsave(&priv->lock, flags); + rcar_i2c_init(priv); /* start clock */ rcar_i2c_write(priv, ICCCR, priv->icccr); + spin_unlock_irqrestore(&priv->lock, flags); + /*-------------- spin unlock -----------------*/ + ret = rcar_i2c_bus_barrier(priv); if (ret < 0) goto out; @@ -428,6 +443,9 @@ static int rcar_i2c_master_xfer(struct i break; } + /*-------------- spin lock -----------------*/ + spin_lock_irqsave(&priv->lock, flags); + /* init each data */ priv->msg = &msgs[i]; priv->pos = 0; @@ -437,6 +455,9 @@ static int rcar_i2c_master_xfer(struct i ret = rcar_i2c_prepare_msg(priv); + spin_unlock_irqrestore(&priv->lock, flags); + /*-------------- spin unlock -----------------*/ + if (ret < 0) break; @@ -540,6 +561,7 @@ static int rcar_i2c_probe(struct platfor irq = platform_get_irq(pdev, 0); init_waitqueue_head(&priv->wait); + spin_lock_init(&priv->lock); adap = &priv->adap; adap->nr = pdev->id;