From patchwork Mon Feb 4 09:03:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuvaraj CD X-Patchwork-Id: 2089821 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 4CA393FD56 for ; Mon, 4 Feb 2013 09:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754061Ab3BDJDp (ORCPT ); Mon, 4 Feb 2013 04:03:45 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:62738 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754004Ab3BDJDn (ORCPT ); Mon, 4 Feb 2013 04:03:43 -0500 Received: by mail-pa0-f49.google.com with SMTP id kp6so1150260pab.22 for ; Mon, 04 Feb 2013 01:03:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=PcYyWrKfDGhz3syPsf1k4+jxJLfyfbfhhiD6kqchsc4=; b=xldkpNg6MInydf8Vj/Sr1T4/lnu4QCTtJbA7LpEnBdRR6mdf/jODanO9tICxybE8nQ pWOBYp0UdaCE25BQNMWd6cp3GhPBF2fY37sqeMLWB0b7fet4tbCItpQhxFe8v7IEbsGt FBMAQrKfJWpEpFXPByOilRCyRg1nzAoi8AEL7XgUq/WKuXpNHcy1Or2yoJE5je0uPsnO z8hyV8dEtUXLancmJGteO3FHLo3U7ZdosAs3ErN9gCBK71brPKKFzJmi+wv8aw9psYRd NfK9N70iqcNxHAZ8HPi253cZ40TXtMRcfYWslE+WKQNRVlox8nv7egbZQw48EiuOoH03 NXmg== X-Received: by 10.66.72.198 with SMTP id f6mr50697765pav.42.1359968622587; Mon, 04 Feb 2013 01:03:42 -0800 (PST) Received: from yuvaraj-ubuntu.sisodomain.com ([115.113.119.130]) by mx.google.com with ESMTPS id a1sm19767382pav.2.2013.02.04.01.03.37 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Feb 2013 01:03:41 -0800 (PST) From: Yuvaraj Kumar C D To: linux-i2c@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, w.sang@pengutronix.de Cc: broonie@opensource.wolfsonmicro.com, ch.naveen@samsung.com, sjg@chromium.org, grundler@chromium.org, Yuvaraj Kumar C D Subject: [RFC] i2c: Providing hooks for i2c multimaster bus arbitration. Date: Mon, 4 Feb 2013 14:33:15 +0530 Message-Id: <1359968595-21291-1-git-send-email-yuvaraj.cd@samsung.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org This RFC patch is w.r.t multimaster bus arbitration which is already being discussing in the mainline. This patch provides hooks for the i2c multimaster bus arbitration and to have the arbitration parameters. Signed-off-by: Yuvaraj Kumar C D --- drivers/i2c/i2c-core.c | 13 ++++++++++++- include/linux/i2c.h | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index e388590..ed89fc8 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1408,18 +1408,29 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) (msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : ""); } #endif + if (adap->mm_arbit_algo) { + ret = adap->mm_arbit_algo->i2c_mm_bus_get(adap); + if (ret) + /* I2C bus under control of another master. */ + return -EAGAIN; + } if (in_atomic() || irqs_disabled()) { ret = i2c_trylock_adapter(adap); - if (!ret) + if (!ret && adap->mm_arbit_algo) { + adap->mm_arbit_algo->i2c_mm_bus_release(adap); + /* I2C activity is ongoing. */ return -EAGAIN; + } } else { i2c_lock_adapter(adap); } ret = __i2c_transfer(adap, msgs, num); i2c_unlock_adapter(adap); + if (adap->mm_arbit_algo) + adap->mm_arbit_algo->i2c_mm_bus_release(adap); return ret; } else { diff --git a/include/linux/i2c.h b/include/linux/i2c.h index d0c4db7..61fbfe3 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -371,6 +371,17 @@ struct i2c_algorithm { }; /* + *This struct provides hooks for i2c multi-master arbitration needs. + */ +struct i2c_mm_arbitration { + void *arbitration_data; + + /* Should return 0 if mastership could be successfully established */ + int (*i2c_mm_bus_get)(struct i2c_adapter *adap); + void (*i2c_mm_bus_release)(struct i2c_adapter *adap); +}; + +/* * i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. */ @@ -393,6 +404,7 @@ struct i2c_adapter { struct mutex userspace_clients_lock; struct list_head userspace_clients; + struct i2c_mm_arbitration *mm_arbit_algo; }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)