From patchwork Thu Nov 15 12:13:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naveen Krishna Chatradhi X-Patchwork-Id: 1748731 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 6582FDF230 for ; Thu, 15 Nov 2012 11:55:09 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYy0P-0006kb-Ly; Thu, 15 Nov 2012 11:53:13 +0000 Received: from mailout2.samsung.com ([203.254.224.25]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYy0K-0006iV-Qy for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2012 11:53:09 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MDJ007H32CJ28O0@mailout2.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2012 20:53:07 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.124]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id ED.31.12699.3A7D4A05; Thu, 15 Nov 2012 20:53:07 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-bd-50a4d7a3724f Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 5D.31.12699.3A7D4A05; Thu, 15 Nov 2012 20:53:07 +0900 (KST) Received: from localhost.localdomain ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDJ0033F28S3800@mmp1.samsung.com> for linux-arm-kernel@lists.infradead.org; Thu, 15 Nov 2012 20:53:06 +0900 (KST) From: Naveen Krishna Chatradhi To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [PATCH 1/4] i2c-s3c2410: grab adapter lock while changing i2c clock Date: Thu, 15 Nov 2012 17:43:30 +0530 Message-id: <1352981613-2098-2-git-send-email-ch.naveen@samsung.com> X-Mailer: git-send-email 1.7.0.4 In-reply-to: <1352981613-2098-1-git-send-email-ch.naveen@samsung.com> References: <1352981613-2098-1-git-send-email-ch.naveen@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDLMWRmVeSWpSXmKPExsWyRsSkRnfx9SUBBq92CFtsenyN1YHRY/OS +gDGKC6blNSczLLUIn27BK6MVYufsxfslKr41HKdrYHxkGgXIweHhICJxJOuqi5GTiBTTOLC vfVsXYxcHEICSxklJv5oZoVImEicWfGOCSKxiFHiT8s9VghnA5PE1GNTmUCq2ATMJA4uWs0O YosIZEgsebSBEaSIWaCXUWLbvwdgCWEBH4lFJ+czg9gsAqoSrZs+gtm8Ai4SVz+8ZYZYpyDR uuwQWD2ngKvE9qVHGUFsIaCa3RdXskL0Ckh8m3yIBeIFWYlNB5hBdkkIXGeT+Lp8HzvEHEmJ gytusExgFF7AyLCKUTS1ILmgOCk910ivODG3uDQvXS85P3cTIzAIT/97Jr2DcVWDxSFGAQ5G JR5ei4+LA4RYE8uKK3MPMUpwMCuJ8BqcWxIgxJuSWFmVWpQfX1Sak1p8iNEH6JKJzFKiyfnA CMkriTc0NjE3NTa1NDIyMzXFIawkztvskRIgJJCeWJKanZpakFoEM46Jg1OqgdF19efH0wx1 5Dx/3A/9qpIkJT+n1fKxH2/p06+xKZd/cnpsj5x9f9lhydtLPrxfs7Xg3/TpwlkPv5+dqLuj b8Ehr+8bHeYKVq0r4dlnG3ipf2fgTK/MKxOdhbdN6bhw4NSzv0+C4hN9uV9/fCQZ+G9J4oam yXtfXVpe3nii23H6k02KC9UCL0fqKrEUZyQaajEXFScCAAWGvSdvAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeLIzCtJLcpLzFFi42I5/e+xgO7i60sCDDp3sFtsenyN1YHRY/OS +gDGqAZGm4zUxJTUIoXUvOT8lMy8dFsl7+B453hTMwNDXUNLC3MlhbzE3FRbJRefAF23zByg qUoKZYk5pUChgMTiYiV9O0wTQkPcdC1gGiN0fUOC4HqMDNBAwhrGjFWLn7MX7JSq+NRyna2B 8ZBoFyMnh4SAicSZFe+YIGwxiQv31rN1MXJxCAksYpT403KPFcLZwCQx9dhUsCo2ATOJg4tW s4PYIgIZEksebWAEKWIW6GWU2PbvAVhCWMBHYtHJ+cwgNouAqkTrpo9gNq+Ai8TVD2+ZIdYp SLQuOwRWzyngKrF96VFGEFsIqGb3xZWsExh5FzAyrGIUTS1ILihOSs810itOzC0uzUvXS87P 3cQIDvJn0jsYVzVYHGIU4GBU4uG1+Lg4QIg1say4MvcQowQHs5IIr8G5JQFCvCmJlVWpRfnx RaU5qcWHGH2ArprILCWanA+MwLySeENjE3NTY1NLEwsTM0scwkrivM0eKQFCAumJJanZqakF qUUw45g4OKUaGB16fv5jCHznJb9q/SoVA5FJFjIWOl6nvi1e0359csU0iYtub293PDk27V+W p4G044lIB1Who1mlekdXheqw3/gso2DwYO3bx4zu9cc/1ayPv2dw4xgvC/Oe/z923qx9pj1J wu747c5Hu6PCdyVvc47MnbbXX6Tj4/Mzz71cFu9vXr/qbnv4AmslluKMREMt5qLiRADxHy75 nwIAAA== X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121115_065309_304567_86F3BC58 X-CRM114-Status: GOOD ( 15.25 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [203.254.224.25 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: kgene.kim@samsung.com, w.sang@pengutronix.de, djkurtz@chromium.org, ben-linux@fluff.org, khali@linux-fr.org, naveenkrishna.ch@gmail.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Daniel Kurtz We probably don't want to change I2C frequency while a transfer is in progress. The current implementation grabs a spinlock, but that only protected the writes to IICCON when starting a message, it didn't protect against clock changes in the middle of a transaction. Note: The i2c-core already grabs the adapter lock before calling s3c24xx_i2c_doxfer(), which ensures that only one caller is issuing a xfer at a time. This means it is not necessary to disable interrupts (spin_lock_irqsave) when changing frequencies, since there won't be any i2c interrupts if there is no on-going xfer. Lastly, i2c_lock_adapter() may cause the cpufreq_transition to sleep if if a xfer is in progress, but this is ok since cpufreq notifiers are called in a kernel thread, and there are already cases where it could sleep, such as when using i2c to update the output of a voltage regulator. Note: the cpufreq part of this change has no functional affect on exynos, where the i2c clock is independent of the cpufreq. But, there is a slight perfomance boost since we no longer need to lock/unlock an additional spinlock. Signed-off-by: Daniel Kurtz Cc: Olof Johansson Cc: Doug Anderson Cc: Daniel Kurtz Signed-off-by: Naveen Krishna Chatradhi --- drivers/i2c/busses/i2c-s3c2410.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 3e0335f..155cb04 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -59,7 +59,6 @@ enum s3c24xx_i2c_state { }; struct s3c24xx_i2c { - spinlock_t lock; wait_queue_head_t wait; unsigned int quirks; unsigned int suspended:1; @@ -540,8 +539,6 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, goto out; } - spin_lock_irq(&i2c->lock); - i2c->msg = msgs; i2c->msg_num = num; i2c->msg_ptr = 0; @@ -550,7 +547,6 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, s3c24xx_i2c_enable_irq(i2c); s3c24xx_i2c_message_start(i2c, msgs); - spin_unlock_irq(&i2c->lock); timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); @@ -740,7 +736,6 @@ static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb, unsigned long val, void *data) { struct s3c24xx_i2c *i2c = freq_to_i2c(nb); - unsigned long flags; unsigned int got; int delta_f; int ret; @@ -754,9 +749,9 @@ static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb, if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) || (val == CPUFREQ_PRECHANGE && delta_f > 0)) { - spin_lock_irqsave(&i2c->lock, flags); + i2c_lock_adapter(&i2c->adap); ret = s3c24xx_i2c_clockrate(i2c, &got); - spin_unlock_irqrestore(&i2c->lock, flags); + i2c_unlock_adapter(&i2c->adap); if (ret < 0) dev_err(i2c->dev, "cannot find frequency\n"); @@ -962,7 +957,6 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; i2c->tx_setup = 50; - spin_lock_init(&i2c->lock); init_waitqueue_head(&i2c->wait); /* find the clock and enable it */