Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751947AbcJJSCd (ORCPT ); Mon, 10 Oct 2016 14:02:33 -0400 Received: from mail-ve1eur01on0094.outbound.protection.outlook.com ([104.47.1.94]:58912 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751110AbcJJSCa (ORCPT ); Mon, 10 Oct 2016 14:02:30 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; Subject: Re: [PATCH 03/10] i2c/muxes: Juniper I2CS RE mux To: Pantelis Antoniou , Lee Jones References: <1475853669-22480-1-git-send-email-pantelis.antoniou@konsulko.com> <1475853669-22480-4-git-send-email-pantelis.antoniou@konsulko.com> CC: Linus Walleij , Alexandre Courbot , Rob Herring , Mark Rutland , Frank Rowand , Wolfram Sang , Richard Purdie , Jacek Anaszewski , Jean Delvare , Avirup Banerjee , Georgi Vlaev , Guenter Roeck , JawaharBalaji Thirumalaisamy , , , , , , From: Peter Rosin Organization: Axentia Technologies AB Message-ID: Date: Mon, 10 Oct 2016 17:29:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1475853669-22480-4-git-send-email-pantelis.antoniou@konsulko.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: AM4PR0101CA0003.eurprd01.prod.exchangelabs.com (10.167.254.13) To AM5PR0201MB2307.eurprd02.prod.outlook.com (10.169.242.151) X-MS-Office365-Filtering-Correlation-Id: d77f66d1-f5b1-4a53-47c5-08d3f1223b72 X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2307;2:rZIDB8T67Ca+VONVDg8uPkzZ+5c3ffuNEJIUeuF9rkY2Vtvszet5MS1HdWySYstiWINL70sn+6G/Rw5mGxqT9QPMEGKrMj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3heM2HwmAnpmIaPEWGRYlgfYIVYHxZjEg+ZNPgo= X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2307;31:BP0wmXZikB2HvDQo6hCHxcna0W81dltM2ydRz9sH6OZEekUl284iC3KxxtCCT/lfO6IfEcJ7wVy9IwHEScYEGJoH4RbT/m5ni00cdX25GQ3pfdMr+Z5uXVusSjehOpsEW8hBbNhI8N6GBVbHi4bkYN+dFJZL21bVf9WcLsGYc3aqTucGqNvN/OlSbugGwh2w1FL6hbYFW8zBlWnxTMsJCWbLdErz+P1QTeIePCFbHrVcEzt7T/hwlUnH24lJQ/5+BSyQMN5VsWErj5YndENfmg==;4:cvoaVI/yFCwblNmAyShP7zUkJBS6dVX66RGdKKEWIF49cRmO1SrtmNwFJRisRK6y6e35TYtNBavcU5xiF1B4hpc/TKxKjmvhywe2nYOfQv5eqXCYG2ej22JsU6xYjjilZGpN+PsYiJ0IHxb9b/ZxiabiBWCMkZ3Y3NTdMrgR88vmlqDJi816VXy14oPyLIhO+ltTVqr+yDs8FTnqF2hFnMXPr+fIW0K/elYNqcF55TyCdjVfgJ09JFYORX5h5tAOqRtU0AzURS6GltzobJ2sD+bw+gigiE5Xd/3XMr8BzcoDnfvXCe0ppjYUSi/3V3V4j+X8AeGOQ58oGMIy023soH7uWPjpw37k0kwBKrEkrIKh3PfdxKN+szRp6DcbwNl0tcoaV8y2oNVgGe8WGDgtWj2ysw4gTsGHiLNfU+ADVN0d+j7FxbCrvE0L+PxKvaHY5nZBBS+2c4NCqOUW6JCckzWklRFTrlULfBnAfxR7xShg5v0p2Xj0VrzdW6nUQ+IszvTGYRPy/uNpiFfWVIf5yQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(35073007944872)(138986009662008); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6042046)(6043046);SRVR:AM5PR0201MB2307;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0201MB2307; X-Forefront-PRVS: 0091C8F1EB X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(7916002)(199003)(24454002)(189002)(377424004)(83506001)(65826007)(31696002)(97736004)(92566002)(305945005)(6666003)(65956001)(65806001)(3846002)(6116002)(586003)(47776003)(66066001)(64126003)(5001770100001)(2950100002)(7846002)(19580395003)(19580405001)(4326007)(2906002)(76176999)(7736002)(7416002)(5660300001)(50466002)(4001350100001)(86362001)(54356999)(50986999)(101416001)(77096005)(8666005)(23746002)(31686004)(189998001)(117156001)(106356001)(42186005)(8676002)(105586002)(230700001)(81166006)(81156014)(36756003)(74482002)(68736007)(33646002)(7059030)(2004002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0201MB2307;H:[192.168.0.125];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;AM5PR0201MB2307;23:a10YtGKeaZE1dkrNgEqA4tBNtNvT04wfNq0?= =?Windows-1252?Q?Aw+vJVNNRODEP1fMqnhdiCw4D3nngqG07JxEIUVjf7ovRESPOeOFeKpU?= =?Windows-1252?Q?5y/DNo1GY7git1g/B5oAbj5Ymb2ea4ejAnRB6piO76HHPQyFiLdYKKrG?= =?Windows-1252?Q?YsCyLoky+NLiAlb+E4zjy+qdVua5QvzUE2z3wMM820jAieEYBJIfkQ+a?= =?Windows-1252?Q?Zzxw5NVFDJ7LnDAGaY10GGrsJXhhCrVObRv0SLFyaGnNzvztDQtonBd4?= =?Windows-1252?Q?glE/x0FwIyNZZEi0ZrHWrSQ5cheXAbtl87kruHmpB9hmX6m8Qi/ZPDrJ?= =?Windows-1252?Q?srzlkwywXeiMyRY27n2wSMl6aw+e8WgF+2r4HLPOXaqzLc+mgy0WToR7?= =?Windows-1252?Q?92cGWuXWRj51pCD5iOlQgb4Lh44mfxWTkGULb1on7JQ3fBYMPuZIEdfQ?= =?Windows-1252?Q?hSSh1QHtsOtgpdqQsgOPjAsiHtafnM7T/EBPOpvx3f4SZNsUSGb7a1ww?= =?Windows-1252?Q?lCxE/Au65Aw0XBwObTnIQTXESbW8AE+JLBs6lKV6GTJ5/zjliOcNNQOx?= =?Windows-1252?Q?/R9FvpJnYOpIoPOsMPS2z0AeF3rw6+k7zpYktQFVIc8sxczGb85c2NET?= =?Windows-1252?Q?+1ZPu3L6DKMU0NriTAhPYVRyQl7NQlZId7Gq2ihkOPa/3/Dfc1PT0xoQ?= =?Windows-1252?Q?NKdbZPr52ZDZjPjSAitT2OIf8eRgKFihMIJSw2xDD2Vtblhvr+DyBlvz?= =?Windows-1252?Q?0qA4uf0GWX0Y8XMvPGY+RO8VLOhKQ94oXMxVdH4FcL7bbT1YWMzi3l9A?= =?Windows-1252?Q?QhH/hpZhawAG261P7vNDj3apWKxLIwsj9sPEjz7B/80j4VLyzpsftvWc?= =?Windows-1252?Q?Wz3LrD8QofpTGXosfSEABkyLwGqcNRdLYoxeFBHzGF4Xraaon+DBOGTb?= =?Windows-1252?Q?pPF/vAEwXmAugMHUv5rY/a2gHDo9nsYEBcFYqzGWk6jVxPKc2nTf1n4Q?= =?Windows-1252?Q?j9O41Dc6gqw9etVhya4Kk8IbsD3I5RS/vYPggqc7FR0KIiDutdvb9iqr?= =?Windows-1252?Q?ICdnCfcTnlVFo4J3348tO/HyvLQSCHGJMAFLZaM7KuGvp6UXUmF7VWuN?= =?Windows-1252?Q?Z609pegAA1tP7G1W3K+fKF1IazTM4gZg6QH0GvoGQpq0dgFpjI5T7Ax8?= =?Windows-1252?Q?GJ1TCxEXFELsENXonMN5Lxa1px7hToqpQXMy96C3b+j3UlK9lxop5arL?= =?Windows-1252?Q?THvX1EcgZlKHWehAqd6SEexk5OzM3sAe7ZvDqJZX6OpQzQYM9Jhv4Lhc?= =?Windows-1252?Q?pR5Y83AQDLf3ggxwT2g1HPKAlSJ0ulgnTyh8PLo+AJzbtObGEUi9yKAu?= =?Windows-1252?Q?qvfymJUJUpybjUZ7RFw+jpi8mIn8/cdYsNW9ZBsF6EZp9QQuqgwXkm4b?= =?Windows-1252?Q?2ovQ54943uLCApuW513LdgTKhryilHDEr5t5xrdTBVKIwnZDqr6rLCOi?= =?Windows-1252?Q?L5nuoYfYGUutDVXlN/nxXD7AMBfCcvip9gn9wa9u4P/qI/kU/jw=3D?= =?Windows-1252?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2307;6:QpbSbzwlpeMV+HJmwYqgLA6Tco6uZhYa5iiNWwT39ms5K14fCKNh8MtmD3eQ4GqAUglkuL7aMEAApCjkKxZ7FSGbVELd5c5Ljzw4cIY7vftb3WCqtIbgp4DrUU+DDDKjsblilVLpBAaq/ZzdhtBCM1VbSP1o+WCAZ9VZFhGrehJIdW8wAhGIKSyf6HKdQ5ylSalLcmJpS7kQS+Lg8s8rBP0rperbMCTlvaLhmof82VeVWdFogOM4gyUKZJdd2fosqeOfAShuFcgSV7sK80aw5eBR8jYRbB4fOXTIqgnyDKSkzPzYcyXCAqtrs4u6IY7Qff7xV8cFyQj2KjLsWqTGFw==;5:nf62hPcwHhSR8QHmwUevT1o5yyO0NBtX1TQCmrAN0/ZMaxa0a+9Z30QJ7adS+MrHYU03TBFX8k2Ef5tDd3BieFMIYpPk5PRzJ+5VIkX8iqxllfN8zcfMk6w5WEWUwb/95ZreY334IBmPlaM1gLwfff1hNW8gTcqDCUcC+r9v+1g=;24:3U2usjDVpbXLcxRoLraLGHRh4MAS8Yhylg9olx5gIuApAUkS1nTmD87aSBt0u9KknDNWNiFGJ3unI2OQEAc+zAZMFZFR+iHpMw243wGdJeE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2307;7:IAqweAkZcTIczZoKr9m+y4cWGn7J9Dko7AlQFoYt73fqeZbOnvZazTJQlcCNpS8Dw2oLpTACjsECBbAHx7cG0rfL59nWS2Np96PKaPALWv8DB99XnXsNauwTZTRUtLGu6J9kPAv3fcrNS3tHXnE7WN/opG51hBYdzqduWDdYr+KY3jFwF2gHiRPyoD6h//7W+q0JOMOqXtuxbYyuwEY9t1GAFkQtipTM/55VCalvjeaJjqUh/bHz7gsOvVJ1yLvtlfJ5xcnC2U/qW6fkrtzfr5j9nDXE2mZFsa7lF52PStjRk0RnqZsbt6FiUvqCJuq+3JoPkKjV+Q3qSRMsZus60BNlC5kaHT9ZCvBJcId0htw= X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2016 15:29:30.2486 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0201MB2307 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7354 Lines: 254 On 2016-10-07 17:21, Pantelis Antoniou wrote: > From: Georgi Vlaev > > Add support for Juniper I2C Slave RE multiplexer driver. > > This I2C multiplexer driver allows the RE to access some of > the FPC I2C buses. It's compatible only with the FPC variant of the > I2CS. > > Signed-off-by: Georgi Vlaev > Signed-off-by: Guenter Roeck > [Ported from Juniper kernel] > Signed-off-by: Pantelis Antoniou > --- > drivers/i2c/muxes/Kconfig | 10 +++ > drivers/i2c/muxes/Makefile | 1 + > drivers/i2c/muxes/i2c-mux-i2cs.c | 155 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 166 insertions(+) > create mode 100644 drivers/i2c/muxes/i2c-mux-i2cs.c > > diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig > index f45a9cb..c95380d 100644 > --- a/drivers/i2c/muxes/Kconfig > +++ b/drivers/i2c/muxes/Kconfig > @@ -30,6 +30,16 @@ config I2C_MUX_GPIO > This driver can also be built as a module. If so, the module > will be called i2c-mux-gpio. > > +config I2C_MUX_I2CS > + tristate "Juniper I2C Slave MFD client RE multiplexer" > + depends on MFD_JUNIPER_I2CS > + help > + Select this to enable the Juniper I2C Slave RE multiplexer driver > + on the relevant Juniper platforms. > + > + This driver can also be built as a module. If so, the module > + will be called i2c-mux-i2cs. > + > config I2C_MUX_PCA9541 > tristate "NXP PCA9541 I2C Master Selector" > help > diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile > index 78d8cba..45b4287 100644 > --- a/drivers/i2c/muxes/Makefile > +++ b/drivers/i2c/muxes/Makefile > @@ -6,6 +6,7 @@ obj-$(CONFIG_I2C_ARB_GPIO_CHALLENGE) += i2c-arb-gpio-challenge.o > obj-$(CONFIG_I2C_DEMUX_PINCTRL) += i2c-demux-pinctrl.o > > obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o > +obj-$(CONFIG_I2C_MUX_I2CS) += i2c-mux-i2cs.o > obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o > obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o > obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o > diff --git a/drivers/i2c/muxes/i2c-mux-i2cs.c b/drivers/i2c/muxes/i2c-mux-i2cs.c Please name the file i2c-mux-jnx-i2cs.c. Or something else a bit more specific. > new file mode 100644 > index 0000000..c498a44 > --- /dev/null > +++ b/drivers/i2c/muxes/i2c-mux-i2cs.c > @@ -0,0 +1,155 @@ > +/* > + * Juniper Networks I2CS RE mux driver > + * > + * Copyright (C) 2012, 2013, 2014 Juniper Networks. All rights reserved. > + * > + * This program is free software; you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation; either version 2 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include init? > +#include > +#include > +#include > +#include > +#include > +#include regmap? > +#include > +#include > + > +#define MISC_IO_RE_EN 0x01 > + > +/* > + * Read/write to mux register. > + * Don't use i2c_transfer()/i2c_smbus_xfer() > + * for this as they will try to lock adapter a second time > + */ If this is the only concern, you should consider making this gate mux-locked instead of parent-locked. Then you can avoid all these unlocked games. But there are caveats, so you better read Documentation/i2c/i2c-topology for the details before you change. > +static int i2cs_mux_read_byte(struct i2c_client *client, > + u8 offset, u8 *val) > +{ > + struct i2c_msg msg[2]; > + > + msg[0].addr = client->addr; > + msg[0].flags = 0; > + msg[0].len = 1; > + msg[0].buf = &offset; > + > + msg[1].addr = client->addr; > + msg[1].flags = I2C_M_RD; > + msg[1].len = 1; > + msg[1].buf = val; > + > + return client->adapter->algo->master_xfer(client->adapter, msg, 2); If you still want to be parent-locked, use __i2c_transfer. In either case, consider adding code that handles the case of no algo->master_xfer (some i2c adapters only support algo->smbus_xfer). > +} > + > +static int i2cs_mux_write_byte(struct i2c_client *client, u8 offset, u8 val) > +{ > + struct i2c_msg msg; > + char buf[2]; > + > + msg.addr = client->addr; > + msg.flags = 0; > + msg.len = 2; > + buf[0] = offset; > + buf[1] = val; > + msg.buf = buf; > + > + return client->adapter->algo->master_xfer(client->adapter, &msg, 1); > +} > + > +static int i2cs_mux_select(struct i2c_mux_core *muxc, u32 chan) > +{ > + int ret; > + u8 val = 0; > + struct i2c_client *client = i2c_mux_priv(muxc); > + > + ret = i2cs_mux_read_byte(client, I2CS_MISC_IO, &val); > + if (ret < 0) > + return ret; > + > + val |= MISC_IO_RE_EN; > + ret = i2cs_mux_write_byte(client, I2CS_MISC_IO, val); > + To me, it sounds as if I2CS_MISC_IO is a register with more than one bit and that you are open to nasty races here. You probably need to interact with the mfd parent and arrange some locking. > + return ret; > +} > + > +static int i2cs_mux_deselect(struct i2c_mux_core *muxc, u32 chan) > +{ > + int ret; > + u8 val = 0; > + struct i2c_client *client = i2c_mux_priv(muxc); > + > + ret = i2cs_mux_read_byte(client, I2CS_MISC_IO, &val); > + if (ret < 0) > + return ret; > + > + val &= ~MISC_IO_RE_EN; > + ret = i2cs_mux_write_byte(client, I2CS_MISC_IO, val); > + > + return 0; > +} > + > +static int i2cs_mux_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct i2c_client *client; > + struct i2c_mux_core *muxc; > + int ret; > + > + if (!dev->parent) > + return -ENODEV; > + > + client = i2c_verify_client(dev->parent); > + if (!client) > + return -ENODEV; > + > + muxc = i2c_mux_alloc(client->adapter, &client->dev, 1, 0, 0, > + i2cs_mux_select, i2cs_mux_deselect); You only have one child adapter, making this a gate. Please use the I2C_MUX_GATE flag which should be available in 4.9. This also affects the preferred devicetree, see comment on that patch. > + if (!muxc) > + return -ENOMEM; > + muxc->priv = client; > + > + ret = i2c_mux_add_adapter(muxc, 0, 0, 0); > + if (ret) > + return ret; > + > + platform_set_drvdata(pdev, muxc); > + > + return 0; > +} > + > +static int i2cs_mux_remove(struct platform_device *pdev) > +{ > + i2c_mux_del_adapters(platform_get_drvdata(pdev)); > + > + return 0; > +} > + > +static const struct of_device_id i2cs_mux_of_match[] = { > + { .compatible = "jnx,i2c-mux-i2cs", }, > + {}, > +}; > +MODULE_DEVICE_TABLE(of, i2cs_mux_of_match); > + > +static struct platform_driver i2cs_mux_driver = { > + .driver = { > + .name = "i2c-mux-i2cs", > + .owner = THIS_MODULE, Drop this line. Cheers, Peter > + .of_match_table = of_match_ptr(i2cs_mux_of_match), > + }, > + .probe = i2cs_mux_probe, > + .remove = i2cs_mux_remove, > +}; > +module_platform_driver(i2cs_mux_driver); > + > +MODULE_DESCRIPTION("Juniper Networks I2CS RE Mux driver"); > +MODULE_AUTHOR("Georgi Vlaev "); > +MODULE_LICENSE("GPL"); > +MODULE_ALIAS("platform:i2c-mux-i2cs"); >