From patchwork Wed Mar 6 23:15:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 1052567 X-Patchwork-Delegate: patchwork@peda.user.lysator.liu.se Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axentia.se Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=axentia.se header.i=@axentia.se header.b="GHPFp6su"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44F8lv5wM2z9s7T for ; Thu, 7 Mar 2019 10:16:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726311AbfCFXQT (ORCPT ); Wed, 6 Mar 2019 18:16:19 -0500 Received: from mail-eopbgr80112.outbound.protection.outlook.com ([40.107.8.112]:32096 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726028AbfCFXQS (ORCPT ); Wed, 6 Mar 2019 18:16:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentia.se; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qEDsSkcy2Dl+pZMj925hy09I5tHTZNUpLAFoVOaWT7E=; b=GHPFp6su/WADVz5MJQaQEtJsnAEAFCiGqgz/Xd54+TjuDm3hzf0RiIYvgBEepZMtUCLSqJ+srYJbBuFegJweZ8WfqZvfex78wNOJOejiyAIWJ/C50p/Qn5KwfVspfiboFRkvd3Kxwpr5RjnxLTx+24aE9I/nvgwGwy9qQEaXEP8= Received: from VI1PR02MB4542.eurprd02.prod.outlook.com (20.178.12.74) by VI1PR02MB4592.eurprd02.prod.outlook.com (20.178.12.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1665.19; Wed, 6 Mar 2019 23:15:46 +0000 Received: from VI1PR02MB4542.eurprd02.prod.outlook.com ([fe80::38db:37eb:b43e:e4c1]) by VI1PR02MB4542.eurprd02.prod.outlook.com ([fe80::38db:37eb:b43e:e4c1%6]) with mapi id 15.20.1665.020; Wed, 6 Mar 2019 23:15:46 +0000 From: Peter Rosin To: "linux-kernel@vger.kernel.org" CC: Peter Rosin , Rob Herring , Mark Rutland , Guenter Roeck , "linux-i2c@vger.kernel.org" , "devicetree@vger.kernel.org" , Ken Chen , Pradeep Srinivasan Subject: [PATCH v2 3/5] i2c: mux: pca9541: prepare for PCA9641 support Thread-Topic: [PATCH v2 3/5] i2c: mux: pca9541: prepare for PCA9641 support Thread-Index: AQHU1HKH44/iJB6yF0CBwnJOj23PjQ== Date: Wed, 6 Mar 2019 23:15:45 +0000 Message-ID: <20190306231521.29367-4-peda@axentia.se> References: <20190306231521.29367-1-peda@axentia.se> In-Reply-To: <20190306231521.29367-1-peda@axentia.se> Accept-Language: en-US, sv-SE Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.11.0 x-originating-ip: [85.226.244.23] x-clientproxiedby: HE1PR1001CA0016.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:3:f7::26) To VI1PR02MB4542.eurprd02.prod.outlook.com (2603:10a6:803:b1::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 115f7e9d-4c7b-4635-9a82-08d6a289a98a x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:VI1PR02MB4592; x-ms-traffictypediagnostic: VI1PR02MB4592: x-microsoft-antispam-prvs: x-forefront-prvs: 0968D37274 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(39830400003)(396003)(366004)(346002)(136003)(189003)(199004)(5640700003)(53936002)(6486002)(71200400001)(6436002)(2501003)(71190400001)(99286004)(4326008)(6916009)(476003)(102836004)(76176011)(256004)(446003)(486006)(52116002)(3846002)(86362001)(386003)(74482002)(6506007)(6512007)(26005)(6116002)(97736004)(66066001)(305945005)(7736002)(2351001)(186003)(2616005)(14444005)(11346002)(25786009)(106356001)(36756003)(8936002)(8676002)(68736007)(81156014)(81166006)(5660300002)(508600001)(2906002)(54906003)(1076003)(50226002)(316002)(14454004)(105586002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR02MB4592; H:VI1PR02MB4542.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: axentia.se does not designate permitted sender hosts) x-microsoft-exchange-diagnostics: =?iso-8859-1?q?1=3BVI1PR02MB4592=3B23?= =?iso-8859-1?q?=3A6jdWfkUmVI0r0ow5QOOAXc0ve/ZbxajTwtYC8tI/7Bo+pSPV?= =?iso-8859-1?q?ehhZHvzwGKIBj7ElgMloC55LM1ZNpH02Z1cNo9GGdBiCnTaJA+r?= =?iso-8859-1?q?aFM2iNdSUgKiaZqLszTTBP5dEovZBXvyCh0WjzQq7dUvesNSh1o?= =?iso-8859-1?q?3hEHGB7u2W3Fr7YYGYD7UF4fTBsXgbRS1ycIGihD9bKUp5VHsFV?= =?iso-8859-1?q?m7P/ZfXetSzhIwlirXW3f86VsTIr12qVP/dMRVkODU5OtXrBPIc?= =?iso-8859-1?q?JurUxQZK6mKOfqfeoY8Syfe1+BXrS5gIa757YOLGvpD7Jno4s+x?= =?iso-8859-1?q?22EfHtI9EpvBfr+zsKD+bD9i07q187FQFkA29c6MD03BR6KzF9a?= =?iso-8859-1?q?3CuD7nIjErNzY1ec8vD8nfopB/dNG+w0TEBRhaS+gGp4XGm6pHj?= =?iso-8859-1?q?+gRPvYlnPbnlK30/sa57ESmyJJO6tG+AWVrURjFsArTwZUxBVE1?= =?iso-8859-1?q?sWnIHFeyBBLMkfy0Nav1A1OjUyMsLUP2689bMbNHBHB+Byvn/Qo?= =?iso-8859-1?q?j4+0txqmajmN9u+MkiyOltKv7T0jYGUZFGrSW0QOhNJ7F6TF7iI?= =?iso-8859-1?q?RiKnVVeNhcVlfMmmmCxHSRwmHwgF/n8fHJIyF1nlQufz178mVi5?= =?iso-8859-1?q?zF9fCIkTGOa+/aawSqgRDiSsFYi6LIRJY1sUXEWWF/GiWlPGeMy?= =?iso-8859-1?q?feAI9kXKneaZo7scz5/yikmyuveWttiV+8R1lCvbJjVMLSr3evW?= =?iso-8859-1?q?2k6fU3bciVojCwvLLd+53e0bcdl9hrJ0yoJHKouZzMR4eYekIFo?= =?iso-8859-1?q?Q86ApvkT8SEKzIuWjXUDoj6WLYQ5O+1gGbtgMOmWozpInYUx5Ax?= =?iso-8859-1?q?iT/QJMYNa9RttmOgp/NKjUhBvxtR+UoJhcAtwZIPBSL64XxzLxH?= =?iso-8859-1?q?rBLVgPgG0t7aX1bpUw9iDy/BOltzm2wSzuKPJ08Un7zL39fdweJ?= =?iso-8859-1?q?OXYJ+SFlsuslTVW+NSuOYHkqjhHS2zH7+MkJsjVsgJHoBH/5c6+?= =?iso-8859-1?q?CAaqoemoz4gN8gnin15Rr+HXFOGN6reH4pVizKqZHZLrDkxkxIc?= =?iso-8859-1?q?zGr57N6N1RY9HujB0wh5hmXQDzm6c4BDGgkFfltvVlwikZfBn5G?= =?iso-8859-1?q?dxRkA+pnvc8nGJDXWXGr59Stxb1JAiX/oIKuHJ8iCY7utD67eQa?= =?iso-8859-1?q?JOA3PmxuBJUTlPCqdjGhRIDzUUmVPvDGoynPJN0z3eI8B4Yl2Hm?= =?iso-8859-1?q?zNJeHYIh0KFF88IdtunaFJXyFQ+CXV+cHe0ua9arVgZP9Q+HDdr?= =?iso-8859-1?q?DOJLTDEAveuG3SqjB1RP4/NOdi3yf0Lte5zVJw400eS0oAsFS3K?= =?iso-8859-1?q?5DtzkyX8w7RAgYZD0mebAx4FmZGRgahwE8csS6upccob4ZyqOPQ?= =?iso-8859-1?q?=3D?= x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: KiN0cHHlCCcK/GIOOWWh1mOMJ+dFxzbsA4IpWQwfcizwxKAcL5Fo8mtcoBRHQoTTiszucWawI3VGQcawrbpt9vr2rAgBSSbrRLAr+M79hIMGlc2XP9I6vXr8neoZ77GqtQbl/36APQq+qJloA/dUXgA+e2Re2yy9fz+GvtpVpq77S9cBRXhrcxx7oS5hlyNThYWFXkjdS8CDAKuHxXVljVjUYxPlIIwUScMvPPL/b45ooGPaGFzT3iz8/gF4LX9dCGALGoRJQeShTQyaKtCurIuXNwJgbjH5RbxGh162qNMR5bqG7yyy2lh4KyL5AQwWjZWnss9CjQWX72h6AOQAiwRk1UA1bHBBVUg7l52zA6KEfE1vs/uLKDhRLQ573ZAn1qHHAJ+FGXliOCcxfTGqaXoIpV+SjOqtp6xg7h8g1TA= MIME-Version: 1.0 X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-Network-Message-Id: 115f7e9d-4c7b-4635-9a82-08d6a289a98a X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Mar 2019 23:15:45.9947 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB4592 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Make the arbitrate and release_bus implementation chip specific. Reviewed-by: Guenter Roeck Reviewed-by: Vladimir Zapolskiy Signed-off-by: Peter Rosin --- drivers/i2c/muxes/i2c-mux-pca9541.c | 62 +++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c index 28f46450f4b4..5eb36e3223d5 100644 --- a/drivers/i2c/muxes/i2c-mux-pca9541.c +++ b/drivers/i2c/muxes/i2c-mux-pca9541.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -70,26 +71,22 @@ #define SELECT_DELAY_SHORT 50 #define SELECT_DELAY_LONG 1000 -struct pca9541 { - struct i2c_client *client; - unsigned long select_timeout; - unsigned long arb_timeout; +enum chip_name { + pca9541, }; -static const struct i2c_device_id pca9541_id[] = { - {"pca9541", 0}, - {} +struct chip_desc { + int (*arbitrate)(struct i2c_client *client); + void (*release_bus)(struct i2c_client *client); }; -MODULE_DEVICE_TABLE(i2c, pca9541_id); +struct pca9541 { + const struct chip_desc *chip; -#ifdef CONFIG_OF -static const struct of_device_id pca9541_of_match[] = { - { .compatible = "nxp,pca9541" }, - {} + struct i2c_client *client; + unsigned long select_timeout; + unsigned long arb_timeout; }; -MODULE_DEVICE_TABLE(of, pca9541_of_match); -#endif static bool pca9541_mybus(int ctl) { @@ -271,7 +268,7 @@ static int pca9541_select_chan(struct i2c_mux_core *muxc, u32 chan) /* force bus ownership after this time */ do { - ret = pca9541_arbitrate(client); + ret = data->chip->arbitrate(client); if (ret) return ret < 0 ? ret : 0; @@ -289,10 +286,32 @@ 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); + data->chip->release_bus(client); return 0; } +static const struct chip_desc chips[] = { + [pca9541] = { + .arbitrate = pca9541_arbitrate, + .release_bus = pca9541_release_bus, + }, +}; + +static const struct i2c_device_id pca9541_id[] = { + { "pca9541", pca9541 }, + {} +}; + +MODULE_DEVICE_TABLE(i2c, pca9541_id); + +#ifdef CONFIG_OF +static const struct of_device_id pca9541_of_match[] = { + { .compatible = "nxp,pca9541", .data = &chips[pca9541] }, + {} +}; +MODULE_DEVICE_TABLE(of, pca9541_of_match); +#endif + /* * I2C init/probing/exit functions */ @@ -301,6 +320,8 @@ static int pca9541_probe(struct i2c_client *client, { struct i2c_adapter *adap = client->adapter; struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev); + const struct of_device_id *match; + const struct chip_desc *chip; struct i2c_mux_core *muxc; struct pca9541 *data; int force; @@ -309,12 +330,18 @@ static int pca9541_probe(struct i2c_client *client, if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; + match = of_match_device(of_match_ptr(pca9541_of_match), &client->dev); + if (match) + chip = of_device_get_match_data(&client->dev); + else + chip = &chips[id->driver_data]; + /* * I2C accesses are unprotected here. * We have to lock the I2C segment before releasing the bus. */ i2c_lock_bus(adap, I2C_LOCK_SEGMENT); - pca9541_release_bus(client); + chip->release_bus(client); i2c_unlock_bus(adap, I2C_LOCK_SEGMENT); /* Create mux adapter */ @@ -329,6 +356,7 @@ static int pca9541_probe(struct i2c_client *client, return -ENOMEM; data = i2c_mux_priv(muxc); + data->chip = chip; data->client = client; i2c_set_clientdata(client, muxc);