From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752140AbcKRBVC (ORCPT ); Thu, 17 Nov 2016 20:21:02 -0500 Received: from mail-db5eur01on0121.outbound.protection.outlook.com ([104.47.2.121]:16669 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750794AbcKRBU6 (ORCPT ); Thu, 17 Nov 2016 20:20:58 -0500 X-Greylist: delayed 91898 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 Nov 2016 20:20:57 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; From: Peter Rosin To: CC: Peter Rosin , Wolfram Sang , "Rob Herring" , Mark Rutland , "Jonathan Cameron" , Hartmut Knaack , "Lars-Peter Clausen" , Peter Meerwald-Stadler , "Arnd Bergmann" , Greg Kroah-Hartman , , , Subject: [RFC PATCH v2 0/7] mux controller abstraction and iio/i2c muxes Date: Thu, 17 Nov 2016 22:48:02 +0100 Message-ID: <1479419289-17553-1-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DB5PR03CA0075.eurprd03.prod.outlook.com (10.164.34.43) To DB6PR0201MB2311.eurprd02.prod.outlook.com (10.169.222.150) X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;2:fDgCCEoDuC+R+9a0k9hs2pskk09rAH8MxtlRO0MjWsf3MRi5ADiKJe7YKCqb0Ua1G1Dc4xl6D7ChnHGJ1D3iTZ+jyzUoSBXhypMLmKVfxNWQ/fHkYhO5SKmks8u6hJd7q/LOQqu3xXmkOF9t49Vnsw7AJeWG8FrqhuVgrBvqqAc=;3:B8xyGGBwrpt2afYlLp7vUnD1c82u6dSA27CTRkMDH4JdrG2yPjHcQoJO96NtVUsMyUaS2+wjeFLN3tNEovZ8IO0fA2agDu3o6n2cSPJFhvtyNtAAUEi/vhFCBFqv3yrei/M3pTWiSktv+sxbfthgXdmpykCQaVNShddW3kzqacc=;25:phjawsHhkAHTMNFcHaUvc9rs+SUKyG9zX3/5AWOPhpxqEqiHehGsxF5dp3Xn2G2HLzBJqmJcAKifPKftpDHd85W+e31gosjmUnwDnKHSOjaJEnD5/O412rtsYgpcXseLUmnEEqXHvHKJ3ZV2HdIZjCyYZ6Lfl+lYtiY22A8njKcroZwab29+ddo5lmn4qs7JFlODk9duPhzQ6WfFDWVNnRLo5WGOaGrFHMUugN/qnc2CziTfiLw7LPpUZVYZQZpujxKE8A2fGbG+QnGCp0XD3/SqdRb8MVT1UqNLRDPuJ/d+Gq5+xHXDrv6qyC6gtzYAyGUjiqNT32EXPiNLxEZD6w1dUNEYGCPhnhH9kPWMJgkU1sRh9bXG1vaRv1yd/KgezooUvpr9Nx747NECh/8rXnEcBvwF0SCz7Um9IxkN4SS8Rqp4jh1BcNSSyU8Bq0DN+b06iNfE35WmuUUVyOAnTQ== X-MS-Office365-Filtering-Correlation-Id: dd83f520-1370-4c77-b09f-08d40f33791c X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB6PR0201MB2311; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;31:GlOgFPZ36qvScZbT7p23tf5swT2ayCH/iC8rnSAaSj/plXX9jtMbqdVS4WZqeJhbPOjVWn3c2QIPQ5YebKF1SF9wNNpc049VggRHKrsiRXgMcuVh8KAWqZMXPVS++xNnn+IODYWl9s3GSFQPJlAT88TOcLHMnJ8rrsGOxYHC7fm8jFQdCXPoUfY1GUtQozrIGMNOpAaP94Yrnuu6cX5IUDbaC34VDi4JxiIiNfFAIq5HZmFnTIM9fWEcLn9MqsaueSUcz3h8Tqhwy4maq7d/VA==;4:Tw4N3Vv4gLXMLfSV4Dg9C4xnCC2twdsO+FQOVkGIM82eoTAfiGc31q0a2K5fjsqw0WMKMm3zQpkl+CxjViXCe/z6rkbueagOt4V6eLXUVr27kUi3tKIfLhDf9+I9fQsoHy0kuGPlpCD/x/BvUCUvwRIUUWGbbBPKLeSYeJGsBNleeG6Pv8GNK9BXJkpPfTAG6NxRHYxsfnRIUMhYOHM+QDFkPRvXhFmL+6Y5HQMmhEdnQzGAUKyv1rZBcuOzBSTof3BpHM8eX468+3rwSbytqnIkyqbvdNyRyLmdl85TLvOsBH9ktWIWcgISm2LkmjqwuKEGG+AdNZTaOWJKpnBIS49BWhWkWziexz5Lo7CzGeDRy+2GXGlPrNX059DSP8mKf/+jPnIJ/E0Zz3/vIJuJ1JiaistW3Ipwxq3V0i+FkgTaCkCFcYgoHDnHobLpK/DoSQHvBl1twsV5R0ulFhW3N7QQVupeAqy5QH1avq6bK1bFdPRwmPXow+18v1Qd47EbHNI9x3XodxCSo1YgP6HJ2A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040281)(6060326)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6061324)(6041223)(6043046);SRVR:DB6PR0201MB2311;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0201MB2311; X-Forefront-PRVS: 01294F875B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(52314003)(199003)(189002)(6666003)(6916009)(5660300001)(47776003)(66066001)(50226002)(81156014)(81166006)(5003940100001)(110136003)(86362001)(77096005)(189998001)(97736004)(68736007)(48376002)(105586002)(106356001)(50986999)(92566002)(7416002)(8666005)(8676002)(305945005)(101416001)(50466002)(7846002)(7736002)(74482002)(4326007)(3846002)(6116002)(2906002)(42186005)(36756003)(33646002)(2351001)(7059030)(42262002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0201MB2311;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =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SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0201MB2311;7:gJ7SCS+nXUr3xh4xE8GeVe0Cds92EHQAs8wwGSG56dA+gJUS0y/jez2TikWHOwGJeyWAjOoE/PXQhe+UoqYlR8XVg2KRbs8hjSvC6yWYtUnJ/UnztCuQlfurY55ei7IujDpEsdiBuLkgnUsvxFoEtWU91Cq6VSR8rq4VG074WrAT41DIBKpDx1yfigkSAnkfQezkp2zJN24DXhyG+MdoXQCwQdh39La+YP4psa4ABIzGu7fez7mOo5vurMV3NornjRl4gkA86YJ0HDODwFK2orEOFnZGhaoWvzrNKG8JKGigNeSECCprstv43y4g+u8TLD7++ih10eL0XeiQyGxa4B9T0lRWvXxHtI7EqS29k24= X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2016 21:48:30.1822 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0201MB2311 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! This is work in progress, I'm asking for early feedback. The code depends on the _available work in iio which can be found in linux-next. v1 -> v2 changes - fixup export of mux_control_put reported by kbuild - drop devicetree iio-ext-info property as noted by Lars-Peter, and replace the functionality by exposing all ext_info attributes of the parent channel for each of the muxed channels. A cache on top of that and each muxed channel gets its own view of the ext_info of the parent channel. - implement idle-state for muxes - clear out the cache on failure in order to force a mux update on the following use - cleanup the probe of i2c-mux-simple driver - fix a bug in the i2c-mux-simple driver, where failure in the selection of the mux caused a deadlock when the mux was later unconditionally deselected. I have a piece of hardware that is using the same 3 GPIO pins to control four 8-way muxes. Three of them control ADC lines to an ADS1015 chip with an iio driver, and the last one controls the SDA line of an i2c bus. We have some deployed code to handle this, but you do not want to see it or ever hear about it. I'm not sure why I even mention it. Anyway, the situation has nagged me to no end for quite some time. So, after first getting more intimate with the i2c muxing code and later discovering the drivers/iio/inkern.c file and writing a couple of drivers making use of it, I came up with what I think is an acceptable solution; add a generic mux controller driver that is shared between all instances, and combine that with an iio mux driver and a new generic i2c mux driver. The new i2c mux I called "simple" since it is only hooking the i2c muxing and the new mux controller (much like the alsa simple card driver does for ASoC). My initial (private) version didn't add "mux" as a new bus, but I couldn't get decent type-checking and nice devicetree integration with that. It does however feel a bit rich to add a new bus for something as small as mux controllers? One thing that I would like to do, but don't see a solution for, is to move the mux control code that is present in various drivers in drivers/i2c/muxes to this new minimalistic muxing subsystem, thus converting all present i2c muxes (but perhaps not gates and arbitrators) to be i2c-mux-simple muxes. I'm using an rwsem to lock a mux, but that isn't really a perfect fit. Is there a better locking primitive that I don't know about that fits better? I had a mutex at one point, but that didn't allow any concurrent accesses at all. At least the rwsem allows concurrent access as long as all users agree on the mux state, but I suspect that the rwsem will degrade to the mutex situation pretty quickly if there is any contention. Also, the "mux" name feels a bit ambitious, there are many muxes in the world, and this tiny bit of code is probably not good enough to be a nice fit for all... This is all very fresh code and only lightly tested, but it feels very promising! Now, go ahead and rip this to pieces... Cheers, Peter Peter Rosin (7): dt-bindings: document devicetree bindings for mux-gpio misc: minimal mux subsystem and gpio-based mux controller iio: inkern: api for manipulating ext_info of iio channels dt-bindings: iio: iio-mux: document iio-mux bindings iio: multiplexer: new iio category and iio-mux driver dt-bindings: i2c: i2c-mux-simple: document i2c-mux-simple bindings i2c: i2c-mux-simple: new driver .../devicetree/bindings/i2c/i2c-mux-simple.txt | 91 +++++ .../bindings/iio/multiplexer/iio-mux.txt | 49 +++ .../devicetree/bindings/misc/mux-gpio.txt | 79 ++++ drivers/i2c/muxes/Kconfig | 12 + drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-simple.c | 168 ++++++++ drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/inkern.c | 55 +++ drivers/iio/multiplexer/Kconfig | 17 + drivers/iio/multiplexer/Makefile | 6 + drivers/iio/multiplexer/iio-mux.c | 444 +++++++++++++++++++++ drivers/misc/Kconfig | 6 + drivers/misc/Makefile | 2 + drivers/misc/mux-core.c | 299 ++++++++++++++ drivers/misc/mux-gpio.c | 115 ++++++ include/linux/iio/consumer.h | 6 + include/linux/mux.h | 53 +++ 18 files changed, 1405 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-simple.txt create mode 100644 Documentation/devicetree/bindings/iio/multiplexer/iio-mux.txt create mode 100644 Documentation/devicetree/bindings/misc/mux-gpio.txt create mode 100644 drivers/i2c/muxes/i2c-mux-simple.c create mode 100644 drivers/iio/multiplexer/Kconfig create mode 100644 drivers/iio/multiplexer/Makefile create mode 100644 drivers/iio/multiplexer/iio-mux.c create mode 100644 drivers/misc/mux-core.c create mode 100644 drivers/misc/mux-gpio.c create mode 100644 include/linux/mux.h -- 2.1.4