From patchwork Tue Jun 2 18:45:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 6530741 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 16A2E9F443 for ; Tue, 2 Jun 2015 18:48:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AAC520544 for ; Tue, 2 Jun 2015 18:48:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42A1720531 for ; Tue, 2 Jun 2015 18:48:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YzrD1-0005OT-A7; Tue, 02 Jun 2015 18:46:43 +0000 Received: from mail-pa0-f50.google.com ([209.85.220.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YzrCn-00059S-0x for linux-arm-kernel@lists.infradead.org; Tue, 02 Jun 2015 18:46:29 +0000 Received: by padjw17 with SMTP id jw17so66671644pad.2 for ; Tue, 02 Jun 2015 11:46:06 -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:in-reply-to :references; bh=SmaSIuXrDU/48pp6y1mKwf7yrCCQp6msNh3bMKd30uo=; b=e+jG4GOnzLA317uh16Pj2LrAmkqyW7aeniFDJ8F+LYKByytLh12VzjxzKtdTLppuhr OKGyYPJOaPfeBLfzh7asfNCQRrwYULrNqbIu01p5Q8WocXXwsTkHvRS/LVN6GpMs1B2Q 2Kgi5Vyn0mKgcQ1YqoJiw9jylPHfLdX2jFbR6/L4ThWtqDVP3hWI0WJvZ+uuG3tl0OFM SUqqsBAPegFPJ6BJlxyVrYgekqcTifLXrEmz/O94ibE/6OZ68zxjexiZCdTZ1Ztan8U7 6uWdL7pnI0FNgJ9f2THBQ0IBTDBOeSqayopkDuo3Umd+ehC39vT5LA44aT3wEq1x/IS7 gigw== X-Gm-Message-State: ALoCoQk/iaj+je2s1lb8js9qEcLI9nnhlzLMMiLgytCx3hSlyYdVa5+Il1bMAiJCdVAZcglozkao X-Received: by 10.66.199.8 with SMTP id jg8mr15256216pac.15.1433270766792; Tue, 02 Jun 2015 11:46:06 -0700 (PDT) Received: from localhost.localdomain ([223.190.86.187]) by mx.google.com with ESMTPSA id jx5sm18222527pbc.85.2015.06.02.11.45.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jun 2015 11:46:05 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Subject: [PATCH-RESEND 1/3] i2c: core: append hardware lock with bus lock Date: Wed, 3 Jun 2015 00:15:29 +0530 Message-Id: <1433270731-23790-2-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1433270731-23790-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1433270731-23790-1-git-send-email-vaibhav.hiremath@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150602_114629_093291_1756214F X-CRM114-Status: GOOD ( 14.26 ) X-Spam-Score: -0.7 (/) Cc: Haojian Zhuang , Vaibhav Hiremath , linux-arm-kernel@lists.infradead.org, wsa@the-dreams.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, 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 To justify the need for hardware lock, lets take a real usecase scenario - In case of Marvell SoC, PXA910 silicon, both AP and CP are present and these two ARM cores are sharing one pair of I2C pins. In order to keep I2C transaction operated with atomic, hardware lock (RIPC) is required. This patch extends support for atomic operation by adding hardware lock. History: The attempt has been made to push this patch-sets upstream sometime back in 2011, but not sure what happened later. I am making another attempt, hopefully will conclude it now. Link to previous patch: http://marc.info/?l=linux-i2c&m=130432846300735&w=2 Signed-off-by: Haojian Zhuang Signed-off-by: Vaibhav Hiremath --- drivers/i2c/i2c-core.c | 22 ++++++++++++++++++---- include/linux/i2c.h | 5 +++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 987c124..daea523 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -868,8 +868,11 @@ void i2c_lock_adapter(struct i2c_adapter *adapter) if (parent) i2c_lock_adapter(parent); - else + else { rt_mutex_lock(&adapter->bus_lock); + if (adapter->hardware_lock) + adapter->hardware_lock(adapter); + } } EXPORT_SYMBOL_GPL(i2c_lock_adapter); @@ -880,11 +883,19 @@ EXPORT_SYMBOL_GPL(i2c_lock_adapter); static int i2c_trylock_adapter(struct i2c_adapter *adapter) { struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); + int ret = 0; if (parent) return i2c_trylock_adapter(parent); - else - return rt_mutex_trylock(&adapter->bus_lock); + else { + ret = rt_mutex_trylock(&adapter->bus_lock); + if (ret && adapter->hardware_trylock) { + ret = adapter->hardware_trylock(adapter); + if (!ret) + i2c_unlock_adapter(adapter); + } + return ret; + } } /** @@ -897,8 +908,11 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter) if (parent) i2c_unlock_adapter(parent); - else + else { + if (adapter->hardware_unlock) + adapter->hardware_unlock(adapter); rt_mutex_unlock(&adapter->bus_lock); + } } EXPORT_SYMBOL_GPL(i2c_unlock_adapter); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index e83a738..0758fb3 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -504,6 +504,11 @@ struct i2c_adapter { /* data fields that are valid for all devices */ struct rt_mutex bus_lock; + /* if hardware lock feature provided */ + void (*hardware_lock)(struct i2c_adapter *); + void (*hardware_unlock)(struct i2c_adapter *); + int (*hardware_trylock)(struct i2c_adapter *); + int timeout; /* in jiffies */ int retries; struct device dev; /* the adapter device */