From patchwork Wed Apr 20 15:17:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 8892001 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 F0460BF29F for ; Wed, 20 Apr 2016 15:35:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DF56220268 for ; Wed, 20 Apr 2016 15:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B09D720263 for ; Wed, 20 Apr 2016 15:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752120AbcDTPfA (ORCPT ); Wed, 20 Apr 2016 11:35:00 -0400 Received: from mail-db3on0125.outbound.protection.outlook.com ([157.55.234.125]:54592 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751899AbcDTPe4 (ORCPT ); Wed, 20 Apr 2016 11:34:56 -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=bTTfhZ9ESPDFy4Ap+vHzYtvQ55c8BbvJSYUFn9M+btY=; b=mXzouZUn/uqO1LXj+7gCe6ibjyLNY/8tbELCNNnweN1VKJ7XTOx4b9mkhu4bzWDFPtYMOFAvNLXUolPzO7ymLWALxBRBGsJH5wZ15MYQZ+Rf5Pb2owuSSHezyrYaE0vyaccB7MugLW6F+9WcjPyyY+ejcSaKwpkaMMBnh2Ps2X0= 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:03 +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 03/24] i2c: i2c-mux-pinctrl: convert to use an explicit i2c mux core Date: Wed, 20 Apr 2016 17:17:43 +0200 Message-ID: <1461165484-2314-4-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: 104369c1-6339-43b2-7d71-08d3692f1e73 X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:YNUelhp4szPGRtJp8UZsawhrSckao9s86nw/QPwSvpxGd5iA+mcgD1aIJyKUGkVCBJKBW5BaNisatfc2VoshtKg6NcVEVt2bUtRBrMGkTodlkSXQ0xflJ20SFCepQENXRKR73d/ueqgXJuhL61HMDrV6TZ6qK6J7hXKabQGfhYbV4gVpfsmqJ/6My/Jsb4c7; 3:l3rC9nvEa4F+bPo7/ITCanmcR7RlpXxui6WlRpULg1Sa/GFWGszSqp1W/3MLkExEkzggoK7MwYMa+V5PHCFbwzqgF+yk4tv3Vbtb+I0SyOm1P1yZ6x9Rq/NNTYvqqV5h X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 25:kvOaowjkfUqbBPHlSJiFlQAVprFnMAY7LaPqB/Z3nrebWNJiND0AR66fUZyySTY+WffopnCS18Anz8esil6P2CcZ10pkIyT43P0I/s5Vwuw4YXHnJgX9MnCvWMfVqyO9EeSoMN7QXlXeE9bG/pbyK6vpUXQIhkSxhi6aC1o7Tj3p4iY4LzWik7/XzNBXFabaXnux68RAw68+1sv4NHnbwUj2MCId7jRkPvR/bPbletdVwg7PoDD/RJ6u6LyQ3FfHMoh419IgOdnoSMvmQCzXvW81EJFeKVCM2diGG2IORt7PydNroqP0vX/00epi9QqFX7tRMwkiwUMKTtu3HrCnw6rrZsGdSWd97Zb/soqCa8w1sFAv6EVSLLhjb0j+ziB8iAZB+Y5Xf57sswmiSEtENPfDh3LGprWq0vjHdCoN5nrDjYDTFaVOx5KF0DA2oa6bZT5KqrNl4FIOGwIpHh4ZhMr9UsVOADEqe+dvjXweN+kFlGamQL7g13noXKNYoiDI/MoG6umByMZjy1N80vPC91egJNZTTDeAIePCYDV2yqxaxd2zl22/wTwgoyj6P3b4zC9CZVF9Yvk2bWnMWmqkR7xqVrbgoYjWjTNIw7V1agPcsd7dH3/6oA51W+77kVgOSWql40vQS9aYLhWnN20u13B03W27SeUEMYiGbkVLbuc= 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:NkLFQtPryZ1XxioOXAWmZOpzt3Y9PKOgwH1MZIkLb5DdwHlRnWF7uQxS2az+2leT/hW9WrFAcXUxisNXEktDpDsU3PZfHpg3sJyDv4c2SbkIhX5Zvy4l5Z2KPxrjc4OUpRPyK3lreB5hqIypfoPVtVU7p3VpzogProhDPOpTuZGhtgiPS9SGLrjG4absAW4um5RGDKIxMtOd9Hb8TD9cMaypN+QvhVxP2WE7HDuyEgLDiWB1cuOxBks1TfRU7070butmJa0kNu3mAWZM7H4jEF7X3BFwz9y3YRATjp0zuWGAh+GNhb46wVUlrPf8/dwitE/yrIEqYyVBC0oCfOdTmpx9YXnB+B+e9gikjDz45GjZFB8V5d76yLbKGr5g1xN6xGhjVuPpbfVmpjD+7Peur4stpW2plhIJVt36K+CNrFLuNDHfkjccZdKpOfZO9pndskhDNVBbt1FSoc6CU5Ye6A== 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:VJorUZCOwuoG/OdMRRSt4cXzU6vWzjTQr4Ib8dTjq?= =?us-ascii?Q?NOvEXZSVd0DXXNoB0lw7GtPlEF7FEqlj8TchsYU7zXNBBWLRKQ2Q7VWTCfY4?= =?us-ascii?Q?lHNdSogT9CGU7Chy3JA02Zpa1vGF/IUUHQPsWrVk5TCv3RBsIyXLQNuBBztI?= =?us-ascii?Q?LvzWc7u5DFVTcBS8o41ZiJ4admuLQX9S/UREfefEcN9X1Ba8nb8kC/C0zZyP?= =?us-ascii?Q?OCFGUDsPug7G/eC38GIEAwAN/t1FW509Pcgl59yKJZDJ5tJiDHb/Q4Az0zXl?= =?us-ascii?Q?WlFg0LZickKsTxdt/fUp74pl+EC0zwCEA/827W97PbTGtqI5imGMGUXVlNoA?= =?us-ascii?Q?fVBUE6WLWXMmGxJs1YwhjYjBzv8i9bqUelCzQzrxGHg4vvjmeGnGiSDntoVN?= =?us-ascii?Q?k8DsVS00+kaiGMM2v8fHtH+r5pWGDuxGzgJHHy9binP3+Owo0TiHj9ZBAwSo?= =?us-ascii?Q?jNA+MEhBUrAuCcddCQcjFopcdpb/dU7KvuIpeleiJABjopmkGX6eJa22QMlS?= =?us-ascii?Q?J2Gqr9UJ3L5M9r7JUSDa0CUXOoVX+VAS4kZtC3OQBvyZVDrsVFYZvwYB/J07?= =?us-ascii?Q?RFZxvtL8046lb6tfCPAM7z4qxCTk4ntzrW2mmOkM51djpUlRdSnbpGbkzGBg?= =?us-ascii?Q?4es5BCAU4hGp6KcYHN4wuH/drfe4JJzla4s3hM/8uL2u7Uo4ISKj31AyL9uh?= =?us-ascii?Q?lBe1TKSISiy9jiLarK/R2Bam8qqBHudjpv3RUij7ZNJ0y1Rqtby2TxQN472U?= =?us-ascii?Q?WFDog+xz1JiGqH7hk8oiTBrgwl0/HpO6aTla4/VEPLS7vLeAO/wsy10vMDKl?= =?us-ascii?Q?MTgBYKH/+yM9EkCbPDSYMybcelMGrzFC27Ri52FNy655Iu5FM3Ao1XUHj8EF?= =?us-ascii?Q?703eKNkj/DwmXfj6TJkCKSMnbxA7o4O7I7lJ8zVuhr6s889TQjaZOxVqkLYu?= =?us-ascii?Q?wcseLpQk290F3xboONQfp10tKNcE/+jCjes8Dau9ED9r9AArmqRm4IT25aKY?= =?us-ascii?Q?D8=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 5:RlAMrHsadSgkVSDZN1RflY+Rq/ok2BmZPeI0MvkVen/c2VyfSjDVn36qU4yFNmnDl9VdY6mEa8H3BP1pT9P3bkMTDVhHOScWMzRR8bLxda8GB+g+C7C4yb7aK1+sd6s5kchoE40ZUyCBjeOzihcCSCqOPNkis6M7+uJS+lVWoErhREdQedkrBdbOiODtMg2Y; 24:1xZQw5NKYUjzcdehNVxsMKhZN5JNgwNW2OJhmQTKlH70EHZbFLjyP/erko21WWQA+qJE2r7ZiaHkphgbzy6FsYTbak+Pifa0DVIqWbHO49s=; 7:EJWeomSeDE5BSSqszZ7AcunDoeqsSRygDNzVO/8rnMoMGTm0Avj9XfyHh10WQm0EGFWnHOsEsKBkA+Kzka92EGd1cFWDIPDyYzPxaRjbLmrszoZQHgduStxKa/5UfgRY7BDulagNx2XjLQ0JlJFHp7BTJI0ZydWAXBYSyiTaazkOCf1NzMSxOo01jnneYs+2muR+6eEqpeJU5HsreJ1gDj3DrQWGVco4wc4JRVldxJY= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 15:19:03.6822 (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-pinctrl.c | 83 ++++++++++++++----------------------- 1 file changed, 30 insertions(+), 53 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c index b5a982ba8898..1b8dc711815e 100644 --- a/drivers/i2c/muxes/i2c-mux-pinctrl.c +++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c @@ -26,34 +26,29 @@ #include struct i2c_mux_pinctrl { - struct device *dev; struct i2c_mux_pinctrl_platform_data *pdata; struct pinctrl *pinctrl; struct pinctrl_state **states; struct pinctrl_state *state_idle; - struct i2c_adapter *parent; - struct i2c_adapter **busses; }; -static int i2c_mux_pinctrl_select(struct i2c_adapter *adap, void *data, - u32 chan) +static int i2c_mux_pinctrl_select(struct i2c_mux_core *muxc, u32 chan) { - struct i2c_mux_pinctrl *mux = data; + struct i2c_mux_pinctrl *mux = i2c_mux_priv(muxc); return pinctrl_select_state(mux->pinctrl, mux->states[chan]); } -static int i2c_mux_pinctrl_deselect(struct i2c_adapter *adap, void *data, - u32 chan) +static int i2c_mux_pinctrl_deselect(struct i2c_mux_core *muxc, u32 chan) { - struct i2c_mux_pinctrl *mux = data; + struct i2c_mux_pinctrl *mux = i2c_mux_priv(muxc); return pinctrl_select_state(mux->pinctrl, mux->state_idle); } #ifdef CONFIG_OF static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, - struct platform_device *pdev) + struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; int num_names, i, ret; @@ -64,15 +59,12 @@ static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, return 0; mux->pdata = devm_kzalloc(&pdev->dev, sizeof(*mux->pdata), GFP_KERNEL); - if (!mux->pdata) { - dev_err(mux->dev, - "Cannot allocate i2c_mux_pinctrl_platform_data\n"); + if (!mux->pdata) return -ENOMEM; - } num_names = of_property_count_strings(np, "pinctrl-names"); if (num_names < 0) { - dev_err(mux->dev, "Cannot parse pinctrl-names: %d\n", + dev_err(&pdev->dev, "Cannot parse pinctrl-names: %d\n", num_names); return num_names; } @@ -80,23 +72,22 @@ static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, mux->pdata->pinctrl_states = devm_kzalloc(&pdev->dev, sizeof(*mux->pdata->pinctrl_states) * num_names, GFP_KERNEL); - if (!mux->pdata->pinctrl_states) { - dev_err(mux->dev, "Cannot allocate pinctrl_states\n"); + if (!mux->pdata->pinctrl_states) return -ENOMEM; - } for (i = 0; i < num_names; i++) { ret = of_property_read_string_index(np, "pinctrl-names", i, &mux->pdata->pinctrl_states[mux->pdata->bus_count]); if (ret < 0) { - dev_err(mux->dev, "Cannot parse pinctrl-names: %d\n", + dev_err(&pdev->dev, "Cannot parse pinctrl-names: %d\n", ret); return ret; } if (!strcmp(mux->pdata->pinctrl_states[mux->pdata->bus_count], "idle")) { if (i != num_names - 1) { - dev_err(mux->dev, "idle state must be last\n"); + dev_err(&pdev->dev, + "idle state must be last\n"); return -EINVAL; } mux->pdata->pinctrl_state_idle = "idle"; @@ -107,13 +98,13 @@ static int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, adapter_np = of_parse_phandle(np, "i2c-parent", 0); if (!adapter_np) { - dev_err(mux->dev, "Cannot parse i2c-parent\n"); + dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); return -ENODEV; } adapter = of_find_i2c_adapter_by_node(adapter_np); of_node_put(adapter_np); if (!adapter) { - dev_err(mux->dev, "Cannot find parent bus\n"); + dev_err(&pdev->dev, "Cannot find parent bus\n"); return -EPROBE_DEFER; } mux->pdata->parent_bus_num = i2c_adapter_id(adapter); @@ -131,19 +122,15 @@ static inline int i2c_mux_pinctrl_parse_dt(struct i2c_mux_pinctrl *mux, static int i2c_mux_pinctrl_probe(struct platform_device *pdev) { + struct i2c_mux_core *muxc; struct i2c_mux_pinctrl *mux; - int (*deselect)(struct i2c_adapter *, void *, u32); int i, ret; mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); if (!mux) { - dev_err(&pdev->dev, "Cannot allocate i2c_mux_pinctrl\n"); ret = -ENOMEM; goto err; } - platform_set_drvdata(pdev, mux); - - mux->dev = &pdev->dev; mux->pdata = dev_get_platdata(&pdev->dev); if (!mux->pdata) { @@ -166,14 +153,15 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev) goto err; } - mux->busses = devm_kzalloc(&pdev->dev, - sizeof(*mux->busses) * mux->pdata->bus_count, - GFP_KERNEL); - if (!mux->busses) { - dev_err(&pdev->dev, "Cannot allocate busses\n"); + muxc = i2c_mux_alloc(NULL, &pdev->dev, mux->pdata->bus_count, 0, 0, + i2c_mux_pinctrl_select, NULL); + if (!muxc) { ret = -ENOMEM; goto err; } + muxc->priv = mux; + + platform_set_drvdata(pdev, muxc); mux->pinctrl = devm_pinctrl_get(&pdev->dev); if (IS_ERR(mux->pinctrl)) { @@ -203,13 +191,11 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev) goto err; } - deselect = i2c_mux_pinctrl_deselect; - } else { - deselect = NULL; + muxc->deselect = i2c_mux_pinctrl_deselect; } - mux->parent = i2c_get_adapter(mux->pdata->parent_bus_num); - if (!mux->parent) { + muxc->parent = i2c_get_adapter(mux->pdata->parent_bus_num); + if (!muxc->parent) { dev_err(&pdev->dev, "Parent adapter (%d) not found\n", mux->pdata->parent_bus_num); ret = -EPROBE_DEFER; @@ -220,12 +206,8 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev) u32 bus = mux->pdata->base_bus_num ? (mux->pdata->base_bus_num + i) : 0; - mux->busses[i] = i2c_add_mux_adapter(mux->parent, &pdev->dev, - mux, bus, i, 0, - i2c_mux_pinctrl_select, - deselect); - if (!mux->busses[i]) { - ret = -ENODEV; + ret = i2c_mux_add_adapter(muxc, bus, i, 0); + if (ret) { dev_err(&pdev->dev, "Failed to add adapter %d\n", i); goto err_del_adapter; } @@ -234,23 +216,18 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev) return 0; err_del_adapter: - for (; i > 0; i--) - i2c_del_mux_adapter(mux->busses[i - 1]); - i2c_put_adapter(mux->parent); + i2c_mux_del_adapters(muxc); + i2c_put_adapter(muxc->parent); err: return ret; } static int i2c_mux_pinctrl_remove(struct platform_device *pdev) { - struct i2c_mux_pinctrl *mux = platform_get_drvdata(pdev); - int i; - - for (i = 0; i < mux->pdata->bus_count; i++) - i2c_del_mux_adapter(mux->busses[i]); - - i2c_put_adapter(mux->parent); + struct i2c_mux_core *muxc = platform_get_drvdata(pdev); + i2c_mux_del_adapters(muxc); + i2c_put_adapter(muxc->parent); return 0; }