From patchwork Wed Apr 20 15:17:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 8892031 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A823DBF29F for ; Wed, 20 Apr 2016 15:35:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABE7020263 for ; Wed, 20 Apr 2016 15:35:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 902AA201F2 for ; Wed, 20 Apr 2016 15:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752170AbcDTPfP (ORCPT ); Wed, 20 Apr 2016 11:35:15 -0400 Received: from mail-db3on0141.outbound.protection.outlook.com ([157.55.234.141]:28992 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752082AbcDTPfL (ORCPT ); Wed, 20 Apr 2016 11:35:11 -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=ktIN0LS4nGwUjGqrIDWuN+KmWwKNe3qjBgeM0wIs1bY=; b=TxqJoWgQc9Cf8yWVpgi2uzq/xClMABa1wmcn2+ywajab9DVJAwwpok2Wd90izh5yYV6BMyBE0odzBw0ov2JVb1w8SLjKAyFd6TG4h9jrdx0AtJiqPXzLfW5gKoVwJsXuWiWh/39rDPsnBsszzpJ/2O5STjt47cXiH9Rr2Z0vxqU= 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:12 +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 04/24] i2c: i2c-arb-gpio-challenge: convert to use an explicit i2c mux core Date: Wed, 20 Apr 2016 17:17:44 +0200 Message-ID: <1461165484-2314-5-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: 66e33629-8205-4d29-0a84-08d3692f240a X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:G3WEp0BcVje66xpi0A5lAC0Qo0oKSnJmY/+mJDbgeGWZPvuWrFVXQ3+kqNpgQT+UU/7D07eUFX3qKPalgf58hRzdu1zdx7Rrm/jBub+3sdxSb6fjBiclJlGnlJPo8NurXNk/iTICjZ/1+8q/YJrwY/hZfLuAAaSlWXP4nRLZIP3jRFFU9u7A7kWKPyg52GFd; 3:CsvYshsmJgU2Ycz17bNtnlCHJYHRr55Xz1lJnNlNDhBFQccE0lv1VC/Sb/wuXHfvpqquVmBm7eOMwVFxsGVROITru+27lny9XpNaAwbuP+x3o79A+UOOa50/Yt8RXAiK; 25:0iwokO9CnhUaQMOSXM3frsbyENF2pUhygWW34xF1/nHww8DdPzjvMMSvOcsVBzmdZsbLthVVHbxLdTXd1l2cbBzweOq2B3aOO7dpbk0uY66KC4gmbSGAZdfpUL+qQgQI8uOsfgpTHJfXru3qcKjRiPN6TZb7yuAfSgk0vsYaeZC0mH9NKv8ywyV+YmQpYE4e0a4bBrkumoK5jYFG8NOshKvZiBAS7vxgclBiqYO2zg2EWX0ZtssTyar/6aAaSKVo4yEEDlCzWX6a8icLMbosNdUfC0ROxlsRvl+U/0UL31Ia/QDmJJEYkZTpfBSmzdXDqi9M8WLHONV+l0Aoho7oPQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1312; 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:69rtKP0b2Js6jvxuJKnjjTHCVFxCGlANaxYT4rWveWeEF+6P24/OC+5dBSkyej9YVJZJPBPeSqAjXXpHQvDgSy8xO7jQsnXHV1p/kaEWUnP7NEkiACDfT2bciWG2TEXQyUinJ26h7fOa4HEO4UhUQVKKNQ/d10XM/o3xhkV06cIxbYYeoVGx/LGUAV0hPWKyTfysBqZGgDZgs6z2b0MGigpzboDJ+9Pn4CmXkcVmpfl5zO1EbpEplM0dsmmAHD58cFAplipsbV6tKQszlqO/T9rsVpDw0q7P2Djrh1Np2P657TYH2/G8OO5ZybCudpkZwVly3+9saVtGa7w87IK2pDvjlpSip7DFqJ9+5W+EdPggbAF6da4hz6RvdrGnYQTJ0PljETrXPjj3xIW03cS7lZel2L+P7Fe758AEC1Ho0qZvrA9eXyl+gC4Z/d+ylRK1sltYMMDQ3Su6lVjjPslEIQ== 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)(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:Ui5Dr2rG+Areo6TrpeaA7oonhCehqI6jbDy4W894m?= =?us-ascii?Q?tQwhAcLz6XHU3DXRbXpzJQcDqxkIsoY894JM94okGPHa0K0qLHbR7WyP90d0?= =?us-ascii?Q?TBameucbUDlZGDlClAsTP/iQfkdI0CJwMzWbFZMa9NJCdzmV9N5nRGgqf4VR?= =?us-ascii?Q?+4H4brMLNB4tTO+/2zmQxn3ECRLH6TScbPAH6wlUt1uHWi5HMT7UGcHVKKG9?= =?us-ascii?Q?uWqvv03cK8JmHQ1TJBcRQ3opPk6aR+yz0BzjERd3F524I0QZCjJNUz//pesV?= =?us-ascii?Q?YprXAFh6C5S5HWK9yzuBWpfeTJvb3gb4wiE/5Lnny5HNlFocj9vSY4y9XsTo?= =?us-ascii?Q?ifx1skTe9qd4T3+3lnmmwJtbvWxELu2NLI/kzjIzym5YDNl651XVdXuTToRG?= =?us-ascii?Q?qqLme9eQwQAir5WdkR7PrWKZL3+lUbVL/LXBG+qJkmO1slu/jzJyyNokKX1j?= =?us-ascii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ecB4XK69Sez9M2VKNIfuulIH8xlroUZ//Bm35DHZt1IneirN6BCQugNcKyJA41Y20PZjUa93qR8XctVpYFna7Sg/yEyOLEotnjsunUbnpNU6gpLl3SbU+ZVdaA4mIAgfhPYxZJttFdPiN920KdRYuybCZflUhwu8YpkoLvocru9BhQfUd8BBPdE= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 15:19:12.4168 (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-arb-gpio-challenge.c | 47 +++++++++++++----------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c index 402e3a6c671a..a90bbc4037dd 100644 --- a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c +++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c @@ -28,8 +28,6 @@ /** * struct i2c_arbitrator_data - Driver data for I2C arbitrator * - * @parent: Parent adapter - * @child: Child bus * @our_gpio: GPIO we'll use to claim. * @our_gpio_release: 0 if active high; 1 if active low; AKA if the GPIO == * this then consider it released. @@ -42,8 +40,6 @@ */ struct i2c_arbitrator_data { - struct i2c_adapter *parent; - struct i2c_adapter *child; int our_gpio; int our_gpio_release; int their_gpio; @@ -59,9 +55,9 @@ struct i2c_arbitrator_data { * * Use the GPIO-based signalling protocol; return -EBUSY if we fail. */ -static int i2c_arbitrator_select(struct i2c_adapter *adap, void *data, u32 chan) +static int i2c_arbitrator_select(struct i2c_mux_core *muxc, u32 chan) { - const struct i2c_arbitrator_data *arb = data; + const struct i2c_arbitrator_data *arb = i2c_mux_priv(muxc); unsigned long stop_retry, stop_time; /* Start a round of trying to claim the bus */ @@ -93,7 +89,7 @@ static int i2c_arbitrator_select(struct i2c_adapter *adap, void *data, u32 chan) /* Give up, release our claim */ gpio_set_value(arb->our_gpio, arb->our_gpio_release); udelay(arb->slew_delay_us); - dev_err(&adap->dev, "Could not claim bus, timeout\n"); + dev_err(muxc->dev, "Could not claim bus, timeout\n"); return -EBUSY; } @@ -102,10 +98,9 @@ static int i2c_arbitrator_select(struct i2c_adapter *adap, void *data, u32 chan) * * Release the I2C bus using the GPIO-based signalling protocol. */ -static int i2c_arbitrator_deselect(struct i2c_adapter *adap, void *data, - u32 chan) +static int i2c_arbitrator_deselect(struct i2c_mux_core *muxc, u32 chan) { - const struct i2c_arbitrator_data *arb = data; + const struct i2c_arbitrator_data *arb = i2c_mux_priv(muxc); /* Release the bus and wait for the other master to notice */ gpio_set_value(arb->our_gpio, arb->our_gpio_release); @@ -119,6 +114,7 @@ static int i2c_arbitrator_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; struct device_node *parent_np; + struct i2c_mux_core *muxc; struct i2c_arbitrator_data *arb; enum of_gpio_flags gpio_flags; unsigned long out_init; @@ -134,12 +130,13 @@ static int i2c_arbitrator_probe(struct platform_device *pdev) return -EINVAL; } - arb = devm_kzalloc(dev, sizeof(*arb), GFP_KERNEL); - if (!arb) { - dev_err(dev, "Cannot allocate i2c_arbitrator_data\n"); + muxc = i2c_mux_alloc(NULL, dev, 1, sizeof(*arb), 0, + i2c_arbitrator_select, i2c_arbitrator_deselect); + if (!muxc) return -ENOMEM; - } - platform_set_drvdata(pdev, arb); + arb = i2c_mux_priv(muxc); + + platform_set_drvdata(pdev, muxc); /* Request GPIOs */ ret = of_get_named_gpio_flags(np, "our-claim-gpio", 0, &gpio_flags); @@ -196,21 +193,18 @@ static int i2c_arbitrator_probe(struct platform_device *pdev) dev_err(dev, "Cannot parse i2c-parent\n"); return -EINVAL; } - arb->parent = of_get_i2c_adapter_by_node(parent_np); + muxc->parent = of_get_i2c_adapter_by_node(parent_np); of_node_put(parent_np); - if (!arb->parent) { + if (!muxc->parent) { dev_err(dev, "Cannot find parent bus\n"); return -EPROBE_DEFER; } /* Actually add the mux adapter */ - arb->child = i2c_add_mux_adapter(arb->parent, dev, arb, 0, 0, 0, - i2c_arbitrator_select, - i2c_arbitrator_deselect); - if (!arb->child) { + ret = i2c_mux_add_adapter(muxc, 0, 0, 0); + if (ret) { dev_err(dev, "Failed to add adapter\n"); - ret = -ENODEV; - i2c_put_adapter(arb->parent); + i2c_put_adapter(muxc->parent); } return ret; @@ -218,11 +212,10 @@ static int i2c_arbitrator_probe(struct platform_device *pdev) static int i2c_arbitrator_remove(struct platform_device *pdev) { - struct i2c_arbitrator_data *arb = platform_get_drvdata(pdev); - - i2c_del_mux_adapter(arb->child); - i2c_put_adapter(arb->parent); + struct i2c_mux_core *muxc = platform_get_drvdata(pdev); + i2c_mux_del_adapters(muxc); + i2c_put_adapter(muxc->parent); return 0; }