From patchwork Wed Apr 20 15:17:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 8892111 Return-Path: X-Original-To: patchwork-linux-media@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 5EE669F39A for ; Wed, 20 Apr 2016 15:35:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7190D2024F for ; Wed, 20 Apr 2016 15:35:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF6572024D for ; Wed, 20 Apr 2016 15:35:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752053AbcDTPfo (ORCPT ); Wed, 20 Apr 2016 11:35:44 -0400 Received: from mail-db3on0119.outbound.protection.outlook.com ([157.55.234.119]:59776 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751811AbcDTPfk (ORCPT ); Wed, 20 Apr 2016 11:35:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentiatech.onmicrosoft.com; s=selector1-axentia-se; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rLWXVKDFEI2s6T4DG1Jy6x6OhC2Zy62z9Ht8wZ4YLCA=; b=R646aPw1aTHJ7S2INW6sTYULqAIhFeOwiZU8VWo7GwyGtS5riHpIrubgw8w5A1Us1iO0DWSAKM+zpKsaU4VeHzI7/dMXcmERJdvknU/4QjwIes9c2Qefahr25FD5TUKpNTIDxI3wgrXXyY7L5mh9Oy3p5iFJcBy6OyOhPRJvtcE= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=axentia.se; Received: from localhost.localdomain (217.210.101.82) by VI1PR02MB1312.eurprd02.prod.outlook.com (10.165.231.154) with Microsoft SMTP Server (TLS) id 15.1.466.19; Wed, 20 Apr 2016 15:20:23 +0000 From: Peter Rosin To: CC: Peter Rosin , Wolfram Sang , Jonathan Corbet , Peter Korsgaard , Guenter Roeck , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Antti Palosaari , Mauro Carvalho Chehab , Rob Herring , Frank Rowand , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Kalle Valo , Jiri Slaby , Daniel Baluta , Lucas De Marchi , Adriana Reus , Matt Ranostay , Krzysztof Kozlowski , Hans Verkuil , Terry Heo , Arnd Bergmann , Tommi Rantala , Crestez Dan Leonard , , , , , , Peter Rosin Subject: [PATCH v7 17/24] i2c: muxes always lock the parent adapter Date: Wed, 20 Apr 2016 17:17:57 +0200 Message-ID: <1461165484-2314-18-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461165484-2314-1-git-send-email-peda@axentia.se> References: <1461165484-2314-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DB3PR01CA0069.eurprd01.prod.exchangelabs.com (10.242.133.172) To VI1PR02MB1312.eurprd02.prod.outlook.com (10.165.231.154) X-MS-Office365-Filtering-Correlation-Id: 0ccc1d37-2819-409c-1841-08d3692f4dff X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:aGEy7pQ8pQPpzPSZXSzacVWvLdJShqmAR7TbIcbchquSA8R+1aSei4o+Y3GFm/jCNLDCGs76H48G1yhxFRmqYqjIE57pvQvAJ1ucJHOe4YO8fXDsrEHb0uCA18y2FaTcbdfjdH/c9fGc3xjlmMZuo+kPnJym4HX9fbEM2OtR1SRLn3JMEwM6cYPuG6Hy3T+w; 3:hXdb5pGSACKLnX4ciL4VqjrkdRNOl7Z+pMgbY3FcAA4ZVIwY4sKbG56zrSIaUPwz6ZMDr55A3BqTO+lDB+g7H535NhtCLsD/FHu9n312ityKeaaJ1RRD9jUY3WifgjvG X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 25:jqw/+q04NhoifaIyfRZKHiCKw8LwU5EGca7Z4TPLUrYoSrLKn5lK/3tioDYMeyq0T1K3mZwRE7L8kGBHUa0sstV4Y3O0UuSQ5D2b+Vhr4ef3hNJrSkCr3sClvp7+yf20ZHbeVC9YtM3KfgWWqCbMCdvjw0jZP7futNydhlF8P3DVW8Sm0HKdoR7VpS5fP+10DNbTioISMSsy9ybYaJTEZ24E/7Ywt+Qsc5GxIRkwqnQyKZj9wQ4okwraej/6CeT3Qerwn03STd5VA7KPniiLA35GZCTlaL9PnqO15er6ACgvOZ6Yy+0Q0Jyt4MQiyCrUQZwa3lHh7/91BqeYEhilb5jIEIVB64Q7ePbdgrtIQzy7T6mYMSGJWzgQmxf957xxyIwlAOzqsmC/OuIau8skS5ZJnqXxGaVAJbk6f+qMjV4K6jH9Jz/pN8IAoKoU/8Knc8+jR5eiZvmfwJ/bo5vMvGkN616M4wzYe+n0r5809Ka+YFiwn0vvGhEc8Ip1GqQ3pULR1qUo/hVYe4PTN9G6YbQQUz2m02bLc48O4oCW+Rhaq43tlcLjvu3h5WDI4RJJbXJSrxm+y2I1SDZTRn6a8FeBe9g4g6sTcLymxOxoTuTO9qOt8Yo3MgMGMHq9InjWlrd+HKsBODZgXMujM35XOw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(9101521026)(6040130)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041046)(6043046); SRVR:VI1PR02MB1312; BCL:0; PCL:0; RULEID:; SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 4:c1sxR3118pM4r/G76hsSW2uLifxWSEp+/JYzMc+7GbxnQHdNQcdQyAyoGfq4AZs5jFgXXhPnhU+ruWAGXDJlYUsZ3o6vm30Jkq/ILmtBGnRWN3zN1zCyR+vVxLaRVgQXzxrarGtaTyPku2qlJcv+PotU9nXs0kIgPi0/MXm2mB452QMTUTTAUmsOEmvpqEbm+KrhGJ6HjE3H6l4syAoeScaQARYQf6UqVMB+UShW8RzTyTeK5zgqsH9MebTw6IpJDMLIBuRlxrAhpjLKXlc3xRHJjsyP8p0uLe7V2Rh5c+0Uvj3Gb0PYUP4aFx1juFbdFDD6Pfkd1y/bEsWSMbXIBjPn72Q6cT3Q2MZqT9IFIPIKeVLYwHi3vmDHF5tCZne9KeKU+Zy7yjqymyTz93+VZn7qXUc/2pRQESjp9Zvq3cId12POWIe57dMwjKjyWBSU+8in/4Ohmn5+LCsSxG3hPQ== X-Forefront-PRVS: 0918748D70 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(66066001)(2906002)(19580395003)(19580405001)(110136002)(92566002)(189998001)(5008740100001)(47776003)(42186005)(33646002)(6116002)(3846002)(5003940100001)(586003)(81166005)(48376002)(2950100001)(4326007)(50466002)(76176999)(1096002)(50226001)(77096005)(50986999)(36756003)(575784001)(86362001)(2351001)(229853001)(74482002)(5004730100002)(7059030)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR02MB1312; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR02MB1312; 23:dHloplfnud5iwBKfXdtgk8jhtMrTg23nkxpXq7eQi?= =?us-ascii?Q?3nd4vsSHsAZ2lt41bN6omuUsOelXNg20edme4OMa3mxC6qlQ3cvr+CPEWwbu?= =?us-ascii?Q?xFEdk/XV40dfdoImGrZEvUgYShPHY0rEe6YyB6WjUWpjrvZ6XNIzd09CenY1?= =?us-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ostics: 1; VI1PR02MB1312; 5:4Z6SalZfRIYJBXygMiNhOZfykTt8oAgikJ68RJHZyaTn3ip5SDsHrQYl9Tm8dvneJLyqABp7fQSUum75af7aakaQhP5ljw5F4UBAE0ds8mTZb1iAOvlc5NKRfGcuFER5ZoTGtAjWgufCqnx3Q3ytgUSFSDj7XuLRFToc0KnWG1tesBVs1xcpIWjotxKBx8kH; 24:/VT8BOlgWslQhgBO5vCYMNWk6oIgHCIgSDSFw7v1MjE/+jw04tEtAabFMKYp1Ab/3IcVPUFRqd+L/UEll8tsBpp/KzJ9717WIzn2aEcLZ6A=; 7:M9/r4/lB6V2wUUHodEATcTEKcSH7gFIzThDnJdcYeYE0sg6CIvBiwfxXDKk63Bta6HYnBk6FyCH4piJtI9ZTkiAx64oZl1Kw9lf4oYuXjwBcR5Ue7kj5GH88xncDBKbquIurOAq91iKf4wSK94R2nSDBogvLed4nIUrVcdwGpV7r3YwpFJEG+GDUSu1wPQW6RkGCeQvf1xNKxPbNMDYeEzyjYHFhJRNzvuaLloYQMHk= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 15:20:23.5438 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB1312 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Instead of checking for i2c parent adapters for every lock/unlock, simply override the locking for muxes to always lock/unlock the parent adapter directly. Signed-off-by: Peter Rosin --- drivers/i2c/i2c-core.c | 21 +++------------------ drivers/i2c/i2c-mux.c | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 21f46d011c33..5314434c2b5d 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -967,12 +967,7 @@ static int i2c_check_addr_busy(struct i2c_adapter *adapter, int addr) */ static void i2c_adapter_lock_bus(struct i2c_adapter *adapter, int flags) { - struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); - - if (parent) - i2c_lock_adapter(parent); - else - rt_mutex_lock(&adapter->bus_lock); + rt_mutex_lock(&adapter->bus_lock); } /** @@ -983,12 +978,7 @@ static void i2c_adapter_lock_bus(struct i2c_adapter *adapter, int flags) */ static int i2c_adapter_trylock_bus(struct i2c_adapter *adapter, int flags) { - struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); - - if (parent) - return parent->trylock_bus(parent, flags); - else - return rt_mutex_trylock(&adapter->bus_lock); + return rt_mutex_trylock(&adapter->bus_lock); } /** @@ -999,12 +989,7 @@ static int i2c_adapter_trylock_bus(struct i2c_adapter *adapter, int flags) */ static void i2c_adapter_unlock_bus(struct i2c_adapter *adapter, int flags) { - struct i2c_adapter *parent = i2c_parent_is_i2c_adapter(adapter); - - if (parent) - i2c_unlock_adapter(parent); - else - rt_mutex_unlock(&adapter->bus_lock); + rt_mutex_unlock(&adapter->bus_lock); } static void i2c_dev_set_name(struct i2c_adapter *adap, diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c index 25e9336b0e6e..dc958eebdbb4 100644 --- a/drivers/i2c/i2c-mux.c +++ b/drivers/i2c/i2c-mux.c @@ -98,6 +98,30 @@ static unsigned int i2c_mux_parent_classes(struct i2c_adapter *parent) return class; } +static void i2c_parent_lock_bus(struct i2c_adapter *adapter, int flags) +{ + struct i2c_mux_priv *priv = adapter->algo_data; + struct i2c_adapter *parent = priv->muxc->parent; + + parent->lock_bus(parent, flags); +} + +static int i2c_parent_trylock_bus(struct i2c_adapter *adapter, int flags) +{ + struct i2c_mux_priv *priv = adapter->algo_data; + struct i2c_adapter *parent = priv->muxc->parent; + + return parent->trylock_bus(parent, flags); +} + +static void i2c_parent_unlock_bus(struct i2c_adapter *adapter, int flags) +{ + struct i2c_mux_priv *priv = adapter->algo_data; + struct i2c_adapter *parent = priv->muxc->parent; + + parent->unlock_bus(parent, flags); +} + struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent, struct device *dev, int max_adapters, int sizeof_priv, u32 flags, @@ -165,6 +189,9 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc, priv->adap.retries = parent->retries; priv->adap.timeout = parent->timeout; priv->adap.quirks = parent->quirks; + priv->adap.lock_bus = i2c_parent_lock_bus; + priv->adap.trylock_bus = i2c_parent_trylock_bus; + priv->adap.unlock_bus = i2c_parent_unlock_bus; /* Sanity check on class */ if (i2c_mux_parent_classes(parent) & class)