From patchwork Sat Aug 23 20:44:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 4770001 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5FCBEC0338 for ; Sat, 23 Aug 2014 20:44:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 823A9201BA for ; Sat, 23 Aug 2014 20:44:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A52102018E for ; Sat, 23 Aug 2014 20:44:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751260AbaHWUoO (ORCPT ); Sat, 23 Aug 2014 16:44:14 -0400 Received: from mail-lb0-f176.google.com ([209.85.217.176]:65166 "EHLO mail-lb0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751170AbaHWUoN (ORCPT ); Sat, 23 Aug 2014 16:44:13 -0400 Received: by mail-lb0-f176.google.com with SMTP id u10so10854707lbd.35 for ; Sat, 23 Aug 2014 13:44:11 -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=gx970WsD0vFLWT5ChiWhMGyCOczMeKSlweP81clSHRE=; b=h/WVOZfegM35qNGbEs7GP8rYs2xbQ1SBkWudQmSeHSD/2cJxCRryhqQG5ihacoNuQE GF7zAKrzXeAAFQ9ZpnwqOwGZKvWOn7PE9rkqsa86galg4eQwHe1woN30Q7M8rqoXVTSy UZVPXpIjptjs8Bbb6XWKsWSX2cG7TSRjh2ddlqQkzD5rM+44yJeKewoEfl4yVn/y1Zx8 Hz0yGPMwwTeByraWc13Tfs5ShM3LiRpFVenZHMkP/YN0zLF5wHAKAsECCsZZZOQXXXcO PmfAu/1nuBA7Z/AX4mLOlOkHoDFj7E+3TsRozOZvfI1CqnIrik39cwv6YhDiS4/YA2h8 g1jQ== X-Gm-Message-State: ALoCoQnGbFV8Lsbp5IOw2ls2RyXFGvf3CQyt7DYtdLudnnV6/ggkaiVdtFvX3w0By5+u4y181jj5 X-Received: by 10.152.21.195 with SMTP id x3mr11798075lae.63.1408826651729; Sat, 23 Aug 2014 13:44:11 -0700 (PDT) Received: from wasted.cogentembedded.com (ppp16-220.pppoe.mtu-net.ru. [81.195.16.220]) by mx.google.com with ESMTPSA id kv3sm53786825lbc.37.2014.08.23.13.44.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Aug 2014 13:44:11 -0700 (PDT) From: Sergei Shtylyov To: wsa@the-dreams.de, linux-i2c@vger.kernel.org Cc: linux-sh@vger.kernel.org Subject: [PATCH v2] Revert "i2c: rcar: remove spinlock" Date: Sun, 24 Aug 2014 00:44:09 +0400 Message-ID: <1642788.pEhrsPDp4u@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. Changes in version 2: - fixed summary. 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;