From patchwork Wed Apr 20 15:17:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 8891971 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 06DD29F39A for ; Wed, 20 Apr 2016 15:35:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F25AF2024F for ; Wed, 20 Apr 2016 15:35:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4B5B2027D for ; Wed, 20 Apr 2016 15:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752099AbcDTPex (ORCPT ); Wed, 20 Apr 2016 11:34:53 -0400 Received: from mail-db3on0134.outbound.protection.outlook.com ([157.55.234.134]:44038 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751899AbcDTPeu (ORCPT ); Wed, 20 Apr 2016 11:34:50 -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=VaTI6fOL1cRSn336bmm276qW/vFn6arUPKROk1MsS/s=; b=aJ46V6SXxtTM4pfu//N7q8vEpyndI6Yaz3VKlORLzX5KE0gFI2aK8xgqZls3LfD8JYHr9sBmtSuPsQTn0ZUNZuLBw+A1jSZlBJhXjhSQ2mkzKutXLs03fzkV6iMNEIBY8+QryhTRK2WzxLclgMa0Aq7+6UEEzUbEO3Hf7M9XGNI= 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:19:19 +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 05/24] i2c: i2c-mux-pca9541: convert to use an explicit i2c mux core Date: Wed, 20 Apr 2016 17:17:45 +0200 Message-ID: <1461165484-2314-6-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: 27b65ca4-594d-4f71-f6bb-08d3692f27fc X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:hdKcxpijgxXXH37TkKyP9F7w8EZnXpRMf2vfyEy3FRxZyS43B6kWS8HLFF/f4Ggug9QLp4C6rARUHI96+JZ9LKd970o/wv3JIY6CRto0t6c2THGjpUcnxvXjdCnPk4tnVoZ4KJzSgwr/Q3ub9sNulSoYgrda+TgHLceWpnKmjicqY58yrZWJny20wMG7whZj; 3:pHCYc1gFPwV9y+5+UNX1nvcb1h+tz3TjfrN19j01SRZy6M9iFNT0Vr+Nk3GLkodSVw+mAmcQ/ynps6yCpFHalCSmbBmN83TY6yfZOnNNdOilWKZ4qcYsV3jAMFyOV6WQ X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 25:jQrSoY6G23VWVb0B1bV+vqDwkYjnKCkY/gDKM3K9MkvO3nVPYRpiD+9c15Gpld+R5VOhS8uIYxbopCRCIK/2nSMwaWOCh8yU+05N5gqt6INY+bEwQgerVslzdJLcr05/8Hzrb5Oaz4v2I7QdWnNt9wxkyWWkNAObAZq3P1rVtLtWhripGEzyFLLqs6v2O30fBlp0bZ+nF+Y04mIN9mHMpU7TzVe7o4y7LhMApWpBwB9Aeef5XDE4A9BbkXP2pYY1pa2mNMfwyf3eqCgKs1Xnrc0fWrnzs3HWU8MxDqX0nBmL6V4vjDw6v4VxCgOSbNULYUSJrfk1SHps84I5M0MrtD5ncxyp/4eMpDGNd7H3PcVLlMD/+AkxTx9x4tH8zNa6pFyv7YC2uy/YzNmrXTajTihomECayPR+Kq8QSzEGXjqOsKhaN1vFTii/uEFAZiFYc7Xahn1lCl1gE2hdtIM3ZcLkTOI84ASzxdn8wbkFFqOQqD4WX/uAwsNZTBB3vCyWZlt2az67PBJzge3VqnTcAuKKfJU+cd7mzOQaS0iM5C7TFuZHOUiXlRDUuFi2vO5iYD+dOUBswznIjIIpHeFSdbawUc0PVAPjNMOvKZvvh2UFl4Aq7e+2NMmjXc6bBPtiKOoKyIyr5891mGih6IE67IRAQ/XjFJynURuZtnC3NCg= 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:dKvjmu0UZLrL8urlIViSIS9ZEC6bXxM/hmCy/qvqk+WefFn8JraWCB10lwz+Q1w19Nv+ujeyXJLajLXyki1GFxid3iALGJehjL1T5ZEeGoT/NdkSBXqRnL51Ui2gwIikWmtCQ5f5+sQVJZIM3gBFFz6omTrU3u9uvIYELomq3AW7KO1Ef3absOL/xSC4OKJTjE95eFXjqjzo6qGAKpJWktMh6JrNVteu1NqvrIf/b1o/UliHwGfnDtI9xmiTOCBPbQPbJTcN3Prrc9ciySbXirldbZRsTCij1W3g3XQzZdgjGENKX0IVVg6LarnyPM5THrE0RCy0i4Bq1lfbebFRUEOx43pGLdeulj2EUJKuckF9YbFgvkUdbAk+e6mdNW+y8NXDRvspfSQWoP0O2BVb7fVuziuSEs/zEEDNU7La75KDLb37QpHzykvbn/2rfWn7/PiIZkkoLSB+ZUWGsqlW0w== X-Forefront-PRVS: 0918748D70 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(66066001)(2906002)(19580395003)(19580405001)(110136002)(92566002)(189998001)(230783001)(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:m1spNXpW0J6zmEeKAwUPxYIWdYmQvqvAXZUfM6Dqm?= =?us-ascii?Q?EaChDF+DPv6/Zc4sOAu/8FeX3BFh+XaiBqDSjhcNjl4qFK1imCEcq1OsD06O?= =?us-ascii?Q?gb9bhhXfdDFB3EE0RUKp5hqZUDz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q?0FPCY4m48MpjxXz3fKDyszL?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 5:xsDFOutkbmg1MJhfF8wl8QtTVeZk+jBeUbboonJz9lBKTBI/Rnp0qbMIj3AUXZR2qXEvN1xE4R4SZ0HRCoGH2LzbWl621MSVU9AAlJBVzU61R5Tsg+SRAhdiaZbDB+4VYPj7vS0HO2AiwpkDSli7VETf7uhx+HfNt8symtVs1lkqDMTHHLK+R0eY2EPjMFLR; 24:qX1WF3Z9FKlfxgsBz2aD0Xpi8UZo2bxeE98/QtUmCp0p5T2HjlPFiewjRhMg7Qj8aFoBGs3WTUFQdS/Zn8RAWHs/LnxUtc8wHigNSjuMD4k=; 7:es55+uQcg309z+tR3arQly02DrUlb0zWnkkHZhbFVsXcoMMTIbVAnAtPw30keo+GLv3Z1gcLl8sIGCXkiGl94TooSRV1jwbnZjwCJa8bZ9Zy51c74qWjvY1Zf54ORoZHN/4hxGNawVEO2O0TxwtKhP31SpbuddWU9BX4dWTejOaGhl0t40iyv5nhY/4t9HWF+F+dSkZNUL/HnRev8usOXmr0SWQav61x6LYWNIhL4SQ= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 15:19:19.7920 (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 Allocate an explicit i2c mux core to handle parent and child adapters etc. Update the select/deselect ops to be in terms of the i2c mux core instead of the child adapter. Signed-off-by: Peter Rosin --- drivers/i2c/muxes/i2c-mux-pca9541.c | 58 +++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c index d0ba424adebc..3cb8af635db5 100644 --- a/drivers/i2c/muxes/i2c-mux-pca9541.c +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c @@ -73,7 +73,7 @@ #define SELECT_DELAY_LONG 1000 struct pca9541 { - struct i2c_adapter *mux_adap; + struct i2c_client *client; unsigned long select_timeout; unsigned long arb_timeout; }; @@ -217,7 +217,8 @@ static const u8 pca9541_control[16] = { */ static int pca9541_arbitrate(struct i2c_client *client) { - struct pca9541 *data = i2c_get_clientdata(client); + struct i2c_mux_core *muxc = i2c_get_clientdata(client); + struct pca9541 *data = i2c_mux_priv(muxc); int reg; reg = pca9541_reg_read(client, PCA9541_CONTROL); @@ -285,9 +286,10 @@ static int pca9541_arbitrate(struct i2c_client *client) return 0; } -static int pca9541_select_chan(struct i2c_adapter *adap, void *client, u32 chan) +static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan) { - struct pca9541 *data = i2c_get_clientdata(client); + struct pca9541 *data = i2c_mux_priv(muxc); + struct i2c_client *client = data->client; int ret; unsigned long timeout = jiffies + ARB2_TIMEOUT; /* give up after this time */ @@ -309,9 +311,11 @@ static int pca9541_select_chan(struct i2c_adapter *adap, void *client, u32 chan) return -ETIMEDOUT; } -static int pca9541_release_chan(struct i2c_adapter *adap, - void *client, u32 chan) +static int pca9541_release_chan(struct i2c_mux_core *muxc, u32 chan) { + struct pca9541 *data = i2c_mux_priv(muxc); + struct i2c_client *client = data->client; + pca9541_release_bus(client); return 0; } @@ -324,20 +328,13 @@ static int pca9541_probe(struct i2c_client *client, { struct i2c_adapter *adap = client->adapter; struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev); + struct i2c_mux_core *muxc; struct pca9541 *data; int force; - int ret = -ENODEV; + int ret; if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA)) - goto err; - - data = kzalloc(sizeof(struct pca9541), GFP_KERNEL); - if (!data) { - ret = -ENOMEM; - goto err; - } - - i2c_set_clientdata(client, data); + return -ENODEV; /* * I2C accesses are unprotected here. @@ -352,34 +349,33 @@ static int pca9541_probe(struct i2c_client *client, force = 0; if (pdata) force = pdata->modes[0].adap_id; - data->mux_adap = i2c_add_mux_adapter(adap, &client->dev, client, - force, 0, 0, - pca9541_select_chan, - pca9541_release_chan); + muxc = i2c_mux_alloc(adap, &client->dev, 1, sizeof(*data), 0, + pca9541_select_chan, pca9541_release_chan); + if (!muxc) + return -ENOMEM; - if (data->mux_adap == NULL) { + data = i2c_mux_priv(muxc); + data->client = client; + + i2c_set_clientdata(client, muxc); + + ret = i2c_mux_add_adapter(muxc, force, 0, 0); + if (ret) { dev_err(&client->dev, "failed to register master selector\n"); - goto exit_free; + return ret; } dev_info(&client->dev, "registered master selector for I2C %s\n", client->name); return 0; - -exit_free: - kfree(data); -err: - return ret; } static int pca9541_remove(struct i2c_client *client) { - struct pca9541 *data = i2c_get_clientdata(client); - - i2c_del_mux_adapter(data->mux_adap); + struct i2c_mux_core *muxc = i2c_get_clientdata(client); - kfree(data); + i2c_mux_del_adapters(muxc); return 0; }