From patchwork Wed Apr 20 15:17:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 8891961 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 0CC18BF29F for ; Wed, 20 Apr 2016 15:35:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E2FF62024D for ; Wed, 20 Apr 2016 15:35:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D45820268 for ; Wed, 20 Apr 2016 15:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752074AbcDTPes (ORCPT ); Wed, 20 Apr 2016 11:34:48 -0400 Received: from mail-db3on0111.outbound.protection.outlook.com ([157.55.234.111]:29312 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751899AbcDTPep (ORCPT ); Wed, 20 Apr 2016 11:34:45 -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=J8hyPlZ2A9xR+gX2CpW1xyV/HkGeiFzc4+NVhD1zpRI=; b=jaGA48tWB9ozx7qtAXi+Bpfr0HzMDIdcd5nvxqHWu578A+AJuIXTjkennqk33mdWpq/3yYs3YGUr2G+eSObxhS/jKaMq4gl/lN6Y0YKUCLrGT4PnR3mkA4URXmXZurespbsiZJyHOJaISQeic6PGnS5yyBUaWm2dX0/Wma422tc= 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:30 +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 07/24] i2c: i2c-mux-reg: convert to use an explicit i2c mux core Date: Wed, 20 Apr 2016 17:17:47 +0200 Message-ID: <1461165484-2314-8-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: 5ac4d97f-f3e5-4c87-a26f-08d3692f2e73 X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:7xPhWfcEDf2nc2Ba4vfr2AnbSlWJOhLZEkuU+1JGmuHR2mYmSr3Yrsayms3L56YIZQZaOkf2FuUmVaNK84146z4VVxzbgnUMqfvteX/1KmFkG21sQPPjXBQJygMT8R3CWEN1fW3f3zuM73u0OSqUIDdHrTSn9LYNpTYlYaZ1rIpWZj7CllBFQnojrHPPV1ew; 3:QmQYa/mMLTxX028IT3oUyYrPjHyHBYu1/z/bQ+SwtfAHLo7rA1SLaxXoqBganTfFOwpeGPGdqjQ5y70ivMZVa0XEGp5gv1qtYzXAqvVu0Ebk++Jt62LojcVPebDEAnNy X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 25:ozcgVQx1vRorLYj6Mk9qKn31WIVu7/PkwdWmwXGCtOEYHIlbvw/T7q4B3ZpcXD16TIO0sOhOoemnz2UZHl+Cud0XLBYvovhJquI9/SBIbF6gEt0arlo1XzCl9kLtfv8HbxlDR7C3wnlBy6HnazCWIFe312EHYAYAsiD1cTaA/BcPx8qSg9WIkEQCenSGrP+YIHmTY+3I/aMM8lH9qJYZwaW9v1MWc4qbSDDl8QN5vApXYebY9soTki7CaZKFH3+tiIzG7qegXkEcobfMJpP+mdjDPDIZ1+fop5LlZgTAjXVFRqRoVGVePrER/66YNLMsxuq+g+Sq6utWbP6JtUrmyplDY5F3FhMDx9J+4HyMMdLsEiKPnQceXEqE9vM2Jv77f1LRv4JtFBxtzk8PP7PiCVas3q6gXmXe4IbKakeggLYbTkzAJIaH2g5jk7lJofJ4n5j0G25yzminEaqUxfqIAQtBTxJyBvqqU4zjGFjvPyTImJmuEE3zqJ/MXSBr2PGb1+EdnS5PuW3s3zQtl8ldAETPMap+CBT0Js0x0cQyJWWFvJ0G4o6rWB28CcmDyHfCwwPg/mR1zt1+mSgWQdyeoT1N1wTlyBXDfhMbFaratmxK5zqueu5QUJeP6gNfxWwla9bTl90ViH7yCffWbzw25SL4LKE8two+SCYOLHGZIhY= 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:YXkrk7ajNzV/04sU86X44/c56Gg2rxHChetUgJP+z1yZQL498hhxS4yf9snQ9lVACJNIaIpDv6O38BvjoZwrKSRHiX1Ik1BC5L3wl3G1AuEax+2bFvxcxAWW2Zr6nAIWg7GR5g01SxlLg6vLNSdKPBy9oEIb4gNR+gx47xVEGASobBdqp+xUjyApbcyy4jm4GedqTjYLKtG/qeZZ7j1CCiVSpRYXLopyppzGJJWMXh2XZqQuujXBzSWUfOgiecIGIlCfuhO/7RKx3s0Q87ln2/p3heuuBL4jSlqqG0P+bGWINwGEc8F0UapZ2NGhF0QC0sG2ReXwh4/yY0jPigQHt4y6LYSUEUSs2mzKeAL2f8KrYEAvkROI8z0ns+LrsSguaaE6w7i6a+2zH+eE3uMDbJ/o/aEUXLcCVd4f9e9ZigI1ENg4IBr9NItv/R1MoDOpIuCL9nA4smwN9/7DazFAbQ== 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:vcJSI1ZbhuzdNjhTAvdMSHGlDy63v9jSRI6adiARY?= =?us-ascii?Q?5eLv0C+Ludtzo65nm5t5tZL2HvLdB+8cqAcC33AcTy12jS09wjEBr0Tu6S4u?= =?us-ascii?Q?ptD5wgWFR6GSAPsJwpfqs9IxlAvSV2OTdJzx2HgTbgHCPWD2kCIq7lFNW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microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 5:hbT8msQEdZEG86x8a55JYY4rh1rCj8AJF2VnvkwwnUAJNcaMG6KeWsrzvMXmwbDR50isfsd19QIqZ5DuVPBuoMM2I6te9BFrPzAcQ1JDY/lAAJbNhPbF1xCgMql24vNEln/XwlQwHaoJjZDaasyRA0e/K6R8gLnrKSqXeSyOOQyE4pqBYAnQQBQEPl51qPXE; 24:u2q8r4/bm61Cjb+59RBJIXjvunEiX1E16jhrLc+O6GLxAM3diBWCSNthZUYPULbaVlYNW/j7wY7OjLk3HzP3MsuQqi7u2fob0piDfW4cz9o=; 7:0n7aJW4CMRo9Q5je7vS5M+UjF9FYUUfuXf7RLSsRK8C4LnOL9DwjrrnbACMncKh4FrkC0EmFWmWFqn76RXa3nl3fC96VNVIiPtLKDHY3wgT93SaWgPsXQe7Wwk7nvHj0wTvRnO2g4P2kwks3wJ6++/vqiKBLqqlZnO7KCoumrDl2WxcpZucSOAgacn0jkeoZQJD02FM0vsgNrr4rjcamafljOna5Ei3aU+Iqut0gNOg= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 15:19:30.4486 (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-reg.c | 69 +++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c index 5fbd5bd0878f..6773cadf7c9f 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -21,8 +21,6 @@ #include struct regmux { - struct i2c_adapter *parent; - struct i2c_adapter **adap; /* child busses */ struct i2c_mux_reg_platform_data data; }; @@ -64,18 +62,16 @@ static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id) return 0; } -static int i2c_mux_reg_select(struct i2c_adapter *adap, void *data, - unsigned int chan) +static int i2c_mux_reg_select(struct i2c_mux_core *muxc, u32 chan) { - struct regmux *mux = data; + struct regmux *mux = i2c_mux_priv(muxc); return i2c_mux_reg_set(mux, chan); } -static int i2c_mux_reg_deselect(struct i2c_adapter *adap, void *data, - unsigned int chan) +static int i2c_mux_reg_deselect(struct i2c_mux_core *muxc, u32 chan) { - struct regmux *mux = data; + struct regmux *mux = i2c_mux_priv(muxc); if (mux->data.idle_in_use) return i2c_mux_reg_set(mux, mux->data.idle); @@ -85,7 +81,7 @@ static int i2c_mux_reg_deselect(struct i2c_adapter *adap, void *data, #ifdef CONFIG_OF static int i2c_mux_reg_probe_dt(struct regmux *mux, - struct platform_device *pdev) + struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct device_node *adapter_np, *child; @@ -107,7 +103,6 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux, if (!adapter) return -EPROBE_DEFER; - mux->parent = adapter; mux->data.parent = i2c_adapter_id(adapter); put_device(&adapter->dev); @@ -161,7 +156,7 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux, } #else static int i2c_mux_reg_probe_dt(struct regmux *mux, - struct platform_device *pdev) + struct platform_device *pdev) { return 0; } @@ -169,10 +164,10 @@ static int i2c_mux_reg_probe_dt(struct regmux *mux, static int i2c_mux_reg_probe(struct platform_device *pdev) { + struct i2c_mux_core *muxc; struct regmux *mux; struct i2c_adapter *parent; struct resource *res; - int (*deselect)(struct i2c_adapter *, void *, u32); unsigned int class; int i, ret, nr; @@ -180,17 +175,9 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) if (!mux) return -ENOMEM; - platform_set_drvdata(pdev, mux); - if (dev_get_platdata(&pdev->dev)) { memcpy(&mux->data, dev_get_platdata(&pdev->dev), sizeof(mux->data)); - - parent = i2c_get_adapter(mux->data.parent); - if (!parent) - return -EPROBE_DEFER; - - mux->parent = parent; } else { ret = i2c_mux_reg_probe_dt(mux, pdev); if (ret < 0) { @@ -199,6 +186,10 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) } } + parent = i2c_get_adapter(mux->data.parent); + if (!parent) + return -EPROBE_DEFER; + if (!mux->data.reg) { dev_info(&pdev->dev, "Register not set, using platform resource\n"); @@ -215,55 +206,45 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) return -EINVAL; } - mux->adap = devm_kzalloc(&pdev->dev, - sizeof(*mux->adap) * mux->data.n_values, - GFP_KERNEL); - if (!mux->adap) { - dev_err(&pdev->dev, "Cannot allocate i2c_adapter structure"); + muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, 0, 0, + i2c_mux_reg_select, NULL); + if (!muxc) return -ENOMEM; - } + muxc->priv = mux; + + platform_set_drvdata(pdev, muxc); if (mux->data.idle_in_use) - deselect = i2c_mux_reg_deselect; - else - deselect = NULL; + muxc->deselect = i2c_mux_reg_deselect; for (i = 0; i < mux->data.n_values; i++) { nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; class = mux->data.classes ? mux->data.classes[i] : 0; - mux->adap[i] = i2c_add_mux_adapter(mux->parent, &pdev->dev, mux, - nr, mux->data.values[i], - class, i2c_mux_reg_select, - deselect); - if (!mux->adap[i]) { - ret = -ENODEV; + ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class); + if (ret) { dev_err(&pdev->dev, "Failed to add adapter %d\n", i); goto add_adapter_failed; } } dev_dbg(&pdev->dev, "%d port mux on %s adapter\n", - mux->data.n_values, mux->parent->name); + mux->data.n_values, muxc->parent->name); return 0; add_adapter_failed: - for (; i > 0; i--) - i2c_del_mux_adapter(mux->adap[i - 1]); + i2c_mux_del_adapters(muxc); return ret; } static int i2c_mux_reg_remove(struct platform_device *pdev) { - struct regmux *mux = platform_get_drvdata(pdev); - int i; - - for (i = 0; i < mux->data.n_values; i++) - i2c_del_mux_adapter(mux->adap[i]); + struct i2c_mux_core *muxc = platform_get_drvdata(pdev); - i2c_put_adapter(mux->parent); + i2c_mux_del_adapters(muxc); + i2c_put_adapter(muxc->parent); return 0; }