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: 49433 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6F58820BD1 for ; Tue, 2 Jun 2015 18:46:12 +0000 (UTC) Received: by wifx6 with SMTP id x6sf33340192wif.1 for ; Tue, 02 Jun 2015 11:46: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:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=z15Cjdgl1rpVK5FsK0J/jK4hbMDccP/y6ihILF79a5A=; b=ZHZ4EZL7FxuNl//uWvdznHSZsvWpG60h3rxu7wgglcQLixZn2A/3McmZc1e37FYYZT syBaG+up36Vs8/saYJ452WWtIhNwsrx8jROHvoX4sVAgVtMiPvVuM0NnSPYLLR8R6ymd SItA/COIyvcFIlsME7dfNDzjPEkxp2PBkQsXjjJQewsIoG8HpucXgPBc8KUVCdyiEb+c kDrPUbxWtiAt1linVUrDDYsHeJMLsNQg8x9fLxBcqGyA0HfqsnKMJzSPnzPgNw+81qBp pmKM3+L/KDdKrrC1xynNXypLxWH1JhUt4fvmsQZyveDDxFInHCvBXJinrK0mTxyRsG30 m8UQ== X-Gm-Message-State: ALoCoQmdHv97ZzdQNNoAaxlEP6IZcvooLI8g63c29DApckqiYNVWblRcVDidIeTyny7t97aVj974 X-Received: by 10.180.83.72 with SMTP id o8mr17633319wiy.3.1433270771766; Tue, 02 Jun 2015 11:46:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.138 with SMTP id am10ls583924lac.67.gmail; Tue, 02 Jun 2015 11:46:11 -0700 (PDT) X-Received: by 10.152.45.98 with SMTP id l2mr28398443lam.77.1433270771593; Tue, 02 Jun 2015 11:46:11 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id et1si15823838lac.11.2015.06.02.11.46.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jun 2015 11:46:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by labpy14 with SMTP id py14so120879373lab.0 for ; Tue, 02 Jun 2015 11:46:11 -0700 (PDT) X-Received: by 10.112.182.4 with SMTP id ea4mr22794783lbc.35.1433270771436; Tue, 02 Jun 2015 11:46:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3276688lbb; Tue, 2 Jun 2015 11:46:10 -0700 (PDT) X-Received: by 10.68.204.36 with SMTP id kv4mr14652820pbc.37.1433270769562; Tue, 02 Jun 2015 11:46:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tc7si27234010pbc.137.2015.06.02.11.46.08; Tue, 02 Jun 2015 11:46:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754413AbbFBSqH (ORCPT + 1 other); Tue, 2 Jun 2015 14:46:07 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:32880 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754366AbbFBSqH (ORCPT ); Tue, 2 Jun 2015 14:46:07 -0400 Received: by padj3 with SMTP id j3so73110115pad.0 for ; Tue, 02 Jun 2015 11:46:06 -0700 (PDT) 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 Cc: linux-arm-kernel@lists.infradead.org, wsa@the-dreams.de, Vaibhav Hiremath , Haojian Zhuang 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> Sender: linux-i2c-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-i2c@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: vaibhav.hiremath@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 */