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: 49114 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1F0F9202A3 for ; Thu, 28 May 2015 13:35:22 +0000 (UTC) Received: by lani11 with SMTP id i11sf11211952lan.3 for ; Thu, 28 May 2015 06:35:20 -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=iMdZ03iPtRpBsB9yY8iLjZghcIXHRUBlcZpBfdzRgIB+l2ecqu/s4qh01c49kpaeaR 19lSAQheHurYay+yZT+kEl7sJEMFDJyws2L+//RVr+0EAb5vbOkZphJGEvetQwlyIMCp 8+SYn2oyfnRjoXzUlt5TQbBx9x2J8Drw/r7TFc5n3m3eqI221Tri6GPhfFoBmDqgTIYB ESt+5o9/35BHOKSFXpCmfIMgKny10IIxsumxazICsEgEw7aJbenKqkZI2Sn4Oo9MTckA E6ZYC2BTwnG9e8nDSobY54Tw6t0qM7zOJAzac0vDiV1Ygega21U3kaGGHMok1Hm82T2f fr9A== X-Gm-Message-State: ALoCoQn0SyiBUKnhGhzgSdAXqDG5dVQs+wdcuSGuDA8R0nKsxou/OokZOrhYP49lp4ZFeeCfhdP2 X-Received: by 10.112.14.101 with SMTP id o5mr2681022lbc.3.1432820120773; Thu, 28 May 2015 06:35:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.7 with SMTP id w7ls184338law.84.gmail; Thu, 28 May 2015 06:35:20 -0700 (PDT) X-Received: by 10.152.87.204 with SMTP id ba12mr2902089lab.35.1432820120564; Thu, 28 May 2015 06:35:20 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id jq16si1993162lab.7.2015.05.28.06.35.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2015 06:35:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by laat2 with SMTP id t2so31937592laa.1 for ; Thu, 28 May 2015 06:35:20 -0700 (PDT) X-Received: by 10.112.222.133 with SMTP id qm5mr2883970lbc.86.1432820120138; Thu, 28 May 2015 06:35:20 -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 hn6csp1165241lbb; Thu, 28 May 2015 06:35:18 -0700 (PDT) X-Received: by 10.67.7.199 with SMTP id de7mr5479076pad.107.1432820115299; Thu, 28 May 2015 06:35:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fw3si3637418pbb.133.2015.05.28.06.35.14; Thu, 28 May 2015 06:35:15 -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 S1753968AbbE1NfM (ORCPT + 1 other); Thu, 28 May 2015 09:35:12 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:35731 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753220AbbE1NfJ (ORCPT ); Thu, 28 May 2015 09:35:09 -0400 Received: by pdea3 with SMTP id a3so41889644pde.2 for ; Thu, 28 May 2015 06:35:09 -0700 (PDT) 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 Cc: Wolfram Sang , linux-arm-kernel@lists.infradead.org, Vaibhav Hiremath , Haojian Zhuang 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> 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.49 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 */