Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752369AbcDUN41 (ORCPT ); Thu, 21 Apr 2016 09:56:27 -0400 Received: from mail-db3on0125.outbound.protection.outlook.com ([157.55.234.125]:38944 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752307AbcDUN4Z convert rfc822-to-8bit (ORCPT ); Thu, 21 Apr 2016 09:56:25 -0400 From: Peter Rosin To: Crestez Dan Leonard , Peter Rosin , Jonathan Cameron , "linux-iio@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , "Hartmut Knaack" , Lars-Peter Clausen , "Peter Meerwald-Stadler" , Daniel Baluta , "linux-i2c@vger.kernel.org" , Wolfram Sang , "devicetree@vger.kernel.org" , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , "Kumar Gala" Subject: Re: [PATCH] iio: inv_mpu6050: Add support for auxiliary I2C master Thread-Topic: [PATCH] iio: inv_mpu6050: Add support for auxiliary I2C master Thread-Index: AdGb05TwBzi52Y0WRxGAXzl8IgBtxQ== Date: Thu, 21 Apr 2016 13:56:18 +0000 Message-ID: Accept-Language: en-US, sv-SE Content-Language: sv-SE X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=axentia.se; x-originating-ip: [217.210.101.82] x-ms-office365-filtering-correlation-id: 16f696c7-371a-4c17-52eb-08d369ecb696 x-microsoft-exchange-diagnostics: 1;AM4PR02MB1297;5:QNMd0Rm05dxYLH5a4/VuC2aMCmNsrYEtGMp4dz/wJpdf2VsTqQHofioUC8j+wOSx7hSJrjKEdxt4ezAQIEcd+nYWk/dkNgJGuRZHM8j3R3bQ9fS4YFT7QzWVdA/0lN5r/b+RZJwYU9rPXSqcou/d/1TttDqdZ1cxtKvu2vlvHDAChpUqVaA9cW+4+GxkY2Ej;24:kQ8FRZ4T5LFwXrUHTyqihapeCaK/M57nZUP6iQeF5AswrCE0q+sWZF4ao/9yIJURYc/3jXg+rIpFK2f9R5gaogOBY4RJc5Vx8NNpVndL2gw=;7:Re3t9DnXgW9kVD2O04Ch/AN7adzZwMnG1F1OIsOdcnrUsALMMntjvCmWgjGfTX3/bEfEJpslzqGooD6Sd5ajDtnJAH7hHwYU8UMjiIRpgj3OtxV8ZmoTaSqpW6PQsoNYnhyObh+QbTJsmgRKGs9/pOGJXHMU7XT14tNEyP1UqDMatGXPLidzIqfpl/qQb7CFgLYNqFKQjTjzO1KF1AxZZPSVldRSmRFm0d5cyEYprdM= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM4PR02MB1297; 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)(8121501046)(5005006)(10201501046)(3002001)(6041072)(6043046);SRVR:AM4PR02MB1297;BCL:0;PCL:0;RULEID:;SRVR:AM4PR02MB1297; x-forefront-prvs: 091949432C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(377454003)(24454002)(3280700002)(10400500002)(122556002)(74482002)(9686002)(87936001)(2900100001)(189998001)(5002640100001)(5003600100002)(81166005)(5008740100001)(76576001)(3660700001)(2906002)(2501003)(15975445007)(4326007)(33656002)(77096005)(50986999)(92566002)(102836003)(3846002)(6116002)(1220700001)(1096002)(74316001)(11100500001)(19580395003)(586003)(19580405001)(86362001)(54356999)(5001770100001)(5004730100002)(66066001)(7059030)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM4PR02MB1297;H:AM4PR02MB1299.eurprd02.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Apr 2016 13:56:18.0406 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4ee68585-03e1-4785-942a-df9c1871a234 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR02MB1297 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4238 Lines: 111 Crestez Dan Leonard wrote: > On 04/20/2016 11:31 PM, Peter Rosin wrote: > > Crestez Dan Leonard wrote: > >> Changes since that version: > >> * Nest the adapter in inv_mpu6050_state instead of making it static > >> * Explicitly forward of_node "i2c-aux-master" to allow describing aux devices > >> via devicetree. > >> > >> For bypass/mux mode devicetree works automatically. The forwarding is based on > >> the "chan_id" parameter to i2c_add_mux_adapter and is implemented here: > >> > >> http://lxr.free-electrons.com/source/drivers/i2c/i2c-mux.c?v=4.5#L158 > >> > >> Perhaps it might be better for devices handled via master mode to be described > >> via i2c@1? This would work by scanning the mpu node's children for something > >> with reg == 1. > > > > The 0 in i2c@0 (which is used by the mux mode) is the index of the mux slave > > meaning that i2c@1 would be a second mux slave on the same mux, but this is > > not a real mux as such, it is a gate which is piggybacking on the i2c mux infra. > > So, this "mux" can't have a second slave which is why only 0 is valid. > > This behavior is automatic in i2c mux code and seems to assume that all > the children of mux_dev are i2c muxes. This might be obviously correct > and useful for dedicated i2c mux devices but in my case mux_dev is just > the i2c_client for a sensor. > > From Documentation/devicetree/bindings/i2c/i2c-mux.txt: > > > An i2c bus multiplexer/switch will have several child busses that are > > numbered uniquely in a device dependent manner. The nodes for an i2c > > bus multiplexer/switch will have one child node for each child bus. > > This seems to be written in a way that would allow me to define the > "auxiliary i2c master" as bus "1". After all, the numbering is device > dependent and it's not clear that all the child busses need to be > accessible through muxing rather than indirect access through device > registers. You are correct that if you have devicetree children where reg does not match the chan_id given to i2c_add_mux_adapter() those children will be ignored by the i2c-mux code. So, the code would be happy with a devicetree such as: mpu6050@68 { compatible = "..."; reg = <0x68>; ... i2c-aux-mux@0 { #address-cells = <1>; #size-cells = <0>; reg = <0>; foo@44 { compatible = "bar"; reg = <0x44>; ... } } i2c-aux-master@1 { #address-cells = <1>; #size-cells = <0>; reg = <1>; gazonk@44 { compatible = "baz"; reg = <0x44>; ... } } } as long as you do only call i2c_add_mux_adapter() with chan_id = 0. And that is what you are doing. But I think it is a bit subtle... > >> Or maybe the two busses should be called i2c-aux-master and i2c-aux-mux? Not > >> sure how to deal with that on the mux side. > > > > Changing i2c to i2c-aux-mux would break existing device trees, that seems > > like a bad thing, no? > > That support was not documented in mpu6050's bindings and might not be > actually used. > > >> It is not clear how to properly handle this and suggestions are welcome. The > >> way it currently works with this patch is documented immediately below. > > > > I think the naming could be i2c-master0, i2c-master1 etc if it, with > > future work, would be possible to add more than one master (you talked about > > 5 i2c slaves..). > > The device has 5 sets of registers for controlling i2c slaves but only > one physical auxiliary i2c bus. As far as I can tell slaves 0-3 are > intended to be used for gathering readings for slaved sensors > periodically without external intervention. Slave 4 can generate an > interrupt on completion and is more suitable for general-purpose > communication with any number of devices. Ah, ok, so all 5 sets of slave registers are about the same physical i2c bus. So, you basically cannot sanely use this physical aux i2c bus as an i2c-mux and an extra i2c adapter in the same hw design. Correct? In that case, couldn't you look at the names of any devicetree children and use that to decide if you should even attempt to call i2c_add_mux_adapter or i2c_add_adapter? (But please don't clobber stuff for my i2c-mux rework, or you will have to wait even longer for that deadlock to be resolved) Cheers, Peter