From patchwork Thu May 28 13:32:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Hiremath X-Patchwork-Id: 6498761 Return-Path: X-Original-To: patchwork-linux-arm@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 E7F3CC0020 for ; Thu, 28 May 2015 13:39:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8233F20627 for ; Thu, 28 May 2015 13:38:57 +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 05CD420626 for ; Thu, 28 May 2015 13:38:54 +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 1Yxxyq-0004zR-Dj; Thu, 28 May 2015 13:36:16 +0000 Received: from mail-pd0-f182.google.com ([209.85.192.182]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yxxy6-0004MJ-4G for linux-arm-kernel@lists.infradead.org; Thu, 28 May 2015 13:35:32 +0000 Received: by pdbki1 with SMTP id ki1so42067468pdb.1 for ; Thu, 28 May 2015 06:35:09 -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=ERT06W88nC+RFKEWmy5NhAmQXmMmA3S1Cpod6XPOx8nRndkVFctOHh0VcmIDYBP1IH NetHdliG9qMVQcYqiEcTXNwfz4VbgRlcQ3o7u+mmc6RJd1a0Ms2+q3siAk96WuA8dght 0gGliuNFTF7E4dxGSny+O4PB4pk2+tozXOrC922gRrGpSNFv+FMx9LTma8aYZTOSyk19 SYfCH4v5djT8ZR4a5eTeFUq3JgfbT/3mV123njq9WLSQDKnMLQI5l8HEZjAGTH49jJMJ CDh3bUDuKhBkYhGeIVRmArLLvvoHxZAfj6LB4zMiPfikx+Xy1j1bLjKLKhlmXkdqpU4l 3D6Q== X-Gm-Message-State: ALoCoQlzzTun5J0t9Hh01Gau7yh51m8K78NX5N55oYj8iaHzlqKz156cFsSGUV7Z9GnbeNkA9EzC X-Received: by 10.69.31.106 with SMTP id kl10mr5428997pbd.155.1432820109190; Thu, 28 May 2015 06:35:09 -0700 (PDT) Received: from localhost.localdomain ([202.62.77.106]) by mx.google.com with ESMTPSA id f1sm2473461pds.62.2015.05.28.06.35.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 May 2015 06:35:08 -0700 (PDT) From: Vaibhav Hiremath To: linux-i2c@vger.kernel.org Subject: [PATCH 1/3] i2c: core: append hardware lock with bus lock Date: Thu, 28 May 2015 19:02:46 +0530 Message-Id: <1432819968-17515-2-git-send-email-vaibhav.hiremath@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432819968-17515-1-git-send-email-vaibhav.hiremath@linaro.org> References: <1432819968-17515-1-git-send-email-vaibhav.hiremath@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150528_063530_286572_6B50133C X-CRM114-Status: GOOD ( 14.70 ) X-Spam-Score: -1.8 (-) Cc: Haojian Zhuang , Vaibhav Hiremath , linux-arm-kernel@lists.infradead.org, Wolfram Sang 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 */