From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752780AbdC0MQw (ORCPT ); Mon, 27 Mar 2017 08:16:52 -0400 Received: from mail-eopbgr30137.outbound.protection.outlook.com ([40.107.3.137]:61246 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751751AbdC0MQm (ORCPT ); Mon, 27 Mar 2017 08:16:42 -0400 Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none;linuxfoundation.org; dmarc=none action=none header.from=axentia.se; From: Peter Rosin To: Greg Kroah-Hartman CC: Peter Rosin , Wolfram Sang , Rob Herring , Mark Rutland , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Jonathan Corbet , , , , , , Andrew Morton , Colin Ian King , Paul Gortmaker Subject: [PATCH v11 00/12] mux controller abstraction and iio/i2c muxes Date: Mon, 27 Mar 2017 14:17:37 +0200 Message-ID: <1490617069-13119-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: [81.224.171.159] X-ClientProxiedBy: HE1PR0402CA0008.eurprd04.prod.outlook.com (10.175.27.18) To DB6PR0202MB2550.eurprd02.prod.outlook.com (10.169.211.8) X-MS-Office365-Filtering-Correlation-Id: 4667d699-de32-4d4d-f257-08d4750b12d7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB6PR0202MB2550; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;3:kjYFDHEk6UTgnocF1YYucO19vTKwzdSZX4l8zdQl5SAEXS1b6kMJMkt0S16rB8iw/b90cR+ePkkfcp9aKUYYFhgyzFfi6DP2WRlLp4Sym3wP2TOIEuKaGkbgIJTs0kf1HUBwwn0qo6Q88GIWM/UbMG7MmDL8r5kwKNccNilpt/BZu9PP9+a9WZLsEP1IvMCZwrHJ1dx/uPCucgOipPTBsVXffA0Ylzdfa19hGUNK6Kt/HysyKBFodBiye0yPRzJT8uszsR4eZpV98lWV1+7vsw==;25:e/oY0LPnXm2Vr2ImAakE0B170atl4Um4Q82aFpOtBRWK1LFpejK3hJy5Zvv9pFIqxHB2XSS5juEl1zFi2cYcC3k/XCeYn7W6wsQ/cnqEzQf1UJuWTD3ncclu9HGTaeX/aCFiptexMAiiGaj51WIQD7sro1J5p1DKrOyNj30Ut+4XcCIZWQarIxpShAjyJjWUs1Y4waByGBW/esKzAk5E/tEYHwYqvlBGbq0DqCfIBhtDUtyYSMMTeToO5cIUi5auFk7OR69PmgBSYTNjbRUCsBVJoAo/zg38tZKDraxFqz1S5XBoZLgqx7d011yUnU7/VECw4bSP50ThjvALrmAB6EZJ6r5MIy8FtnXzSxJ92f4nfY8CNWtKo12WUnfQ4TD33Pht6Ifh2ASeGG4KuS4fd3QoEBhsfS0G67PmU8ItjGAuPwPWHvBiyIkQ8Y6pa8h5rWveTvU+VE2U1FxGE8nZpQ== X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;31:N/gd39tBc+MJdxMM36gq2+3fCRjV5bFee6FKzK5GMsbY1reR0A7KpY4n9/ustTLn2/q2uHjgDDgrEzrpdY2P0s/8D38GoSY9x3y8XXq6B6PlaVPF67sOsSePi6T0V3FOuqYR/Hy7ckGPgtgmdT/1nMpZqJpK+nLl0es7cspPXkCl3sS08AaU+92O82Hp2E2wiM77gWIfUewGZGkpB7vuWqSM+arhLfSPvzRzeJI14HY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(788757137089)(211171220733660); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123555025)(20161123558025)(20161123564025)(2016111802025)(20161123562025)(20161123560025)(6072148)(6043046);SRVR:DB6PR0202MB2550;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0202MB2550; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;4:hlhup18IFczRDtzfYXBVETEFYAqooCVPf3E11K77cz8PJ6PV2Pp5bEOAya8LPuz/j0z5C5b0PiKPR87bMgXW+McgCwalA10Q0RzPjpcT4OyG39Jsqb/fJFFHtuJDeRNP0/486mHO+CbxhcBU3ZT5MTMIG+bS08MvrvrV/iinZcytH6SjDu4nxGzAgPOIC1PJqMmolxh1I6meh/UwwLTQBfvLt1glem8IsB8X0/o1fhS0bod35E+N3Pmb5+KM2jKnFarPzqfkrkm+xe25W5DXHaS6tOge/MZIabuqm2up9OK/5Zimz9xbBUy3MyibTQiNFuWKIm+LFdQ2vm18+N6ZqkLjAtf75l920KrGmrgScwSpuNlHJPLwHC3xf1hsFlrX1oTlfKMIC9G8MXsfE2Ns2y7Qv1Rf784kpv7acOnLZezOlS/cw7z3kJrX1M3lAvrUjBdiurMumfIBtlWMMPAzSTtPJiWGrgvXoXHANNNee0B0Nu0BCw6hYCMKj91c5FaLe8x6SXwbGxweEoX8XvZ33VM3wUEnClS9aMLJM9o1tW+D2z22OOrhQobpwzaMzVnWrqsBavRrLjHCer3bcD/rOxOl5IkhxXJYUmEB5DuCg6cEcNwbqNcgVGrCE2f5blYAEnFhUJT94DXOWuww75c3VQH1AA56+2p3Op0GTz54WM7MqvH5NptIdWiq/cGLboAah54N56V5CVVQ4bkq+Bh4Zsph90seiYHYwv6Ct1a6aQU= X-Forefront-PRVS: 02596AB7DA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(39410400002)(39450400003)(39830400002)(52314003)(36756003)(4326008)(50466002)(5003940100001)(33646002)(53936002)(66066001)(6506006)(47776003)(6486002)(7736002)(8666007)(50986999)(54906002)(38730400002)(50226002)(86362001)(48376002)(6512007)(3846002)(6116002)(110136004)(8676002)(2906002)(189998001)(81166006)(42186005)(7416002)(6916009)(305945005)(6666003)(74482002)(25786009)(5660300001)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0202MB2550;H:localhost.localdomain;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB6PR0202MB2550;23:JPyDwzf+Dj38SDID9a1/E/wmjXjuFmebqmK1sVC?= =?us-ascii?Q?NHOeo0wtA1w3vmy2ul879QE0c2GBf3UDZo89KaaD3lXe2goAnWHdkdXSwedA?= =?us-ascii?Q?ONNg+T2kufwSRr/9XNLND2SWpFc7Q18iR+0q99S0ccb3hKvTBdbuwyb8z6n7?= =?us-ascii?Q?dZWCQYJwzMlC+SfDUvism+sp1Gjaq3wbEKAHRsRhzz1JMzxOtw7hCfnMYYNm?= =?us-ascii?Q?jtmg/KGeXDCibWpfL0fRgexF+rzNJVXKBvWQlL6xMqWs0xuKjY7ExarSAjkc?= =?us-ascii?Q?sJRBnJLl5WDQI5+1zrHTDjc2xpflPm5Uj6gvDxGxcfeGuq7Clid2Sc8NV0UD?= =?us-ascii?Q?oRIM7MZUJHO5rBFXLPrSPFo8AYI7kD9VLiXaIRLgpsnqTx5yeAgkcCroGVFv?= =?us-ascii?Q?0qje/G3lc5DDAve67wkjqnXXPttxTVVlsy9Z4qPQOpB6cLCXJ+73NhbMRN3H?= =?us-ascii?Q?QeaA6T4HZ2cG/0IdOLGU8o0+hPWwn4rb36qCEByUsj/w1dTqAHLAdZXu23l4?= =?us-ascii?Q?ki+3B9E6LbyJtdsG4Z6tRgiN/IIMfT+uGz6IUeeHEqkCUzqICxC9YaYchdMa?= =?us-ascii?Q?OfIsHukcR+aVxmBFU732xQ1AqRgqVIFr0prscqHEhhf/ZzjcxPVcUdotknOJ?= =?us-ascii?Q?LuAJD6N7Cb80vQDDxYx0o+uKVTHbzj59FzlvwMBKZnr5PInhTKaxSwherJb9?= =?us-ascii?Q?DPdVVXrzsM4YMYM/M25bVrY2yLVUDiu6Ao7YEbc63nsWej/JwnQjSGaagScn?= =?us-ascii?Q?lxdXGTzTCF0XC6UO9ZHaFSaMw7n9m5qrUXayQpZlMRLiT4O3ZuuaNb45izIs?= =?us-ascii?Q?5tT26dPI7KZGpz5w14/RQEtQnBwxv2+Ee7zPDfNo7nCeStomijsKxafCmtYG?= =?us-ascii?Q?q/1oz6TwDEkArSyIcOcZQhJllwQ2hmQSkkOJYWBqzJGR6FgZ6yVnwct2MQY9?= =?us-ascii?Q?bYzAFoHkrZKCz/pkBpDS40gYlHMilr9s/+PgMNxLW+21XE+YhC6tUsOyTS38?= =?us-ascii?Q?6p9Cuig4gBQwwnFVz5LyZE92Cx8C7iyHHadq3GBGyQagPFlOTWEeHI5Jjmde?= =?us-ascii?Q?wAVadFwQ=3D?= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;6:uby1rqbrt/HVadGP02LPFw+G/jG+U4bTi640uqqXoIaN/L2NJ6VDzSjak67YioWTV/3MPtROiTZ/W+J9Q9syG3TgY+aJRqdJNN4xcsc/1s0xu31qhtayUeAtyHzZaEyI+Ei9jM1pfXF3puu86bRnO21PGPS3mMcjFKbaPFLtbVqPGUj8nN6qQlGHn4WOH8UANSVFYmbK6iD7+BNMj3uC/PPx7rqnvMoeNH0al17gS0MuzfIIhYWMAC63yFc51nSpImQOg8AMaBNAJfNM/5STDu+zPFOsHGcjQB+Vkg8SEN2IsZJOHCGjnJaEPxH243ywJrbIsrE+aPkZ8r3jR0i+xaytCaAxRGU6AVqq5zZ7ZVldy/jwZ9q1wGl1EP8ff8TjE5lx3FOS1J3pbw9Gg3iGvQ==;5:8K/VFUHC5Sa7yFNE9ox1QNnRy4LHRV69avxvP4rm+KDc8Jzqwv4piQ572b6uCPrrITQHH+tHfwHg/9G2nhemwuVCbLUA0Jp8EOBhpZ+xWeKL0LPKrL+i8fi1TxKNfDs/hLLqT/Z70RjwsXBcz4Aabg==;24:CY3y0fA6Cl4swsFkuNoSmJ7oNlM6K3biGnOLB8R/57EAyNL/YIPXXYNaFRZOKjOa+sVeewqi1HMWrLSCtXiEzn63nBDsc8U7d3nhYC3E5Ek= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0202MB2550;7:K59+H6lMY4O2XnkjsMW2AWuUE9dK/QWWZAIGmtWN+a+awZ0oZEcKQUktiRsCk8Tksae0AFlT06NBmsacQfjjvQhSdtgmSWwIYeqCQ/iqjt4B4C/wm1zine4YppdErmIIgQ5qgTKTlKIOOh7CVQ+neg3GAI38IfFZXjodCvJ9ac9dnc1z8tOgD/SSZNMfHCYoFxwzW0AwJ9gvDxjomKR+tQoJCIO6kSXbHhpupBO4OOXkBB/1RxrQNzC5nBMPzmQU/rP99kWk8lEVkB5GU5eBuYEOLz7M1Uzyz/h0HguWQ+281Jlx0z8J4jJ4SPb3ZysiUaKG2x6BZVjh3yR8GCtdGQ== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2017 12:16:16.2654 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0202MB2550 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg! Since you didn't want to pull this, please consider applying the raw patches instead. The patches have been in linux-next for a couple of weeks like this already, but whatever works for you... Please just use the text from the pull request I sent earlier if you still need something for a possible merge commit, but why would you need a merge for raw patches? v10 -> v11 changes - added a fixes-tag and an ack from Jonathan on patch 11 - added a new patch (12) with a fix for messed up error path reported by Paul Gortmaker. - fixed some editorial nitpicks in the documentation comments in patch 3. v9 -> v10 changes - rebased onto v4.11-rc1 - added reviewed-by tags from Rob on patches 7 and 9 - added a new patch (11) with a fix for an unsigned compare with less than zero detected by CoverityScan and reported by Colin Ian King - allowed the mux core to be built as a module, after discussion with Paul Gortmaker - added explicit includes of linux/export.h and linux/init.h from the mux core, also noted by Paul - fixed trivial whitespace issue in drivers/mux/Makefile - added trailing '>' after my mail address in MODULE_AUTHOR, which was missing in all new modules in drivers/mux v8 -> v9 changes - dropped the suffix from the compatible string of the i2c-mux-simple binding (was ,mux-locked or ,parent-locked) and add an optional mux-locked property instead to change the desired locking behavior from the default parent-locked - add description of the difference between mux-locked and parent-locked - renamed i2c-mux-simple to i2c-mux (bindings for this general purpose i2c mux are in i2c-mux-gpmux.txt since i2c-mux.txt is already occupied by the common i2c-mux bindings) - changed compatible from mux-gpio to gpio-mux - changed bindings for idle-state back to a single array, but add defines for as-is and hi-Z thus avoiding magic numbers - make use of the above defines in the code as well - make idle-state a common mux property described in mux-controller.txt instead of repeating the info in individual mux controller bindings - drop the adi,parallel property from the adg792 bindings and piggy-back on the #mux-control-cells property - refrain from using the compatible string as node name - dropped the simplified bindings for single-user gpio mux - added acks on patches 2/10 and 5/10 from Rob v7 -> v8 changes - cleanup the implementation of the simplified gpio bindings, but still... - ...reorder patches so that they appear last in the series (patches 11 and 12 were patches 4 and 5 in v7) since Jonathan convinced me that they were perhaps not such a good idea after all. But I still wanted to show the last version I had and I'm still a bit undecided... - added some words to the remaining otherwise empty commit messages - added various acks/reviews from Jonathan and Wolfram. - move mux last in drivers/Kconfig and drivers/Makefile - bump copyright years - centralize error reporting of common operatinons to the mux core - add WARN_ON for faulty usage of mux_chip_register - simplify code for other WARN_ON call sites v6 -> v7 changes - move from drivers/misc/mux-* to drivers/mux/ [I will remove Cc:s to Arnd and Greg for v8, when/if that happens] - add managed versions of mux_chip_alloc and mux_chip_register - use the above in mux-gpio.c and mux-adg792a.c - also use them to support a simplified binding of a gpio mux for the common case where there is a single consumer (and no specific idle requirements) - new binding for describing idle behaviour of mux-adg792a - add bindings for the gpo-pins on the mux-adg792g - use device_property_read_u32 instead of of_property_read_u32 in mux-gpio.c - rename iio mux compatible to io-channel-mux (was iio-mux) - remove linuxism in the bindings (it was mentioning a function name) - add missing quote in the example in the io-channel-mux binding - factor out preparatory cleanup of devres docs to its own patch - add blank line in mux_chip_free - use SIMPLE_{PARENT,MUX}_LOCKED instead of magic numbers {0,1} in i2c-mux-simple.c - add some acks and a reviewed-by from Jonathan v5 -> v6 changes - fix stupidity in mux_chip_priv, mux_gpio_remove and adg792a_remove. - change the devicetree bindings for the iio-mux to use a list of strings (channels property) instead of a list children. v4 -> v5 changes - remove support for fancier dt layouts and go back to the phandle approach from v2 and before, killing the horrible non-working refcounting crap from v4 and avoiding a bunch of life-time issues in v3. - introduce the concept of a mux-chip, that can hold one or more mux-controllers (inspired by the pwm subsystem). - add dt #mux-control-cells property needed to get to the desired mux controller if a mux chip provides more than one. - take away the option to build the mux-core as a module. - if the mux controller has an idle state, make sure the mux controller is set up in the idle state initially (when it should be idle). - do not use a variable length array on the stack in mux_gpio_set to temporarily store the gpio state, preallocate space instead. - fix resource leak on one failure path in mux_gpio_probe. - driver for Analog Devices ADG792A/G, literally the first mux chip I found on the Internet with an i2c interface (that was not a dedicated i2c multiplexer like PCA9547) which I used to verify that the abstractions in the mux core are up to the task. Untested, just proof of concept that at least looks pretty and compiles... - various touch-ups. v3 -> v4 changes - rebased onto next-20161122 (depends on recent _available iio changes). - added support for having the mux-controller in a child node of a mux-consumer if it is a sole consumer, to hopefully even further satisfy the complaint from Rob (and later Lars-Peter) about dt complexity. - the above came at the cost of some rather horrible refcounting code, please review and suggest how it should be done... - changed to register a device class instead of a bus. - pass in the parent device into mux_control_alloc and require less work from mux-control drivers. - changed device names from mux:control%d to mux%d - move kernel-doc from mux-core.c to mux.h (and add some bits). - give the gpio driver a chance to update all mux pins at once. - factor out iio ext_info lookup into new helper function. /Lars-Peter - use an unsigned type for the iio ext_info count. /Lars-Peter - unified "brag strings" in the file headers. v2 -> v3 changes - have the mux-controller in the parent node of any mux-controller consumer, to hopefully satisfy complaint from Rob about dt complexity. - improve commit message of the mux subsystem commit, making it more general, as requested by Jonathan. - remove priv member from struct mux_control and calculate it on the fly. /Jonathan - make the function comments in mux-core.c kernel doc. /Jonathan - add devm_mux_control_* to Documentation/driver.model/devres.txt. /Jonathan - add common dt bindings for mux-controllers, refer to them from the mux-gpio bindings. /Rob - clarify how the gpio pins map to the mux state. /Rob - separate CONFIG_ variables for the mux core and the mux gpio driver. - improve Kconfig help texts. - make CONFIG_MUX_GPIO depend on CONFIG_GPIOLIB. - keep track of the number of mux states in the mux core. - since the iio channel number is used as mux state, it was possible to drop the state member from the mux_child struct. - cleanup dt bindings for i2c-mux-simple, it had some of copy-paste problems from ots origin (i2c-mux-gpio). - select the mux control subsystem in config for the i2c-mux-simple driver. - add entries to MAINTAINERS and my sign-off, I'm now satisfied and know nothing in this to be ashamed of. 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 (and subsystem) that is shared between all instances, and combine that with an iio mux driver and a new general purpose i2c mux driver that is only hooking the i2c muxing and the new mux controller. 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). 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... Cheers, peda Peter Rosin (12): devres: trivial whitespace fix dt-bindings: document devicetree bindings for mux-controllers and gpio-mux mux: minimal mux subsystem and gpio-based mux controller iio: inkern: api for manipulating ext_info of iio channels dt-bindings: iio: io-channel-mux: document io-channel-mux bindings iio: multiplexer: new iio category and iio-mux driver dt-bindings: i2c: i2c-mux: document general purpose i2c-mux bindings i2c: i2c-mux-gpmux: new driver dt-bindings: mux-adg792a: document devicetree bindings for ADG792A/G mux mux: adg792a: add mux controller driver for ADG792A/G iio: multiplexer: fix unsigned check with less than zero mux: core: fix error handling in devm_mux_chip_alloc .../devicetree/bindings/i2c/i2c-mux-gpmux.txt | 99 +++++ .../bindings/iio/multiplexer/io-channel-mux.txt | 39 ++ .../devicetree/bindings/mux/adi,adg792a.txt | 75 ++++ Documentation/devicetree/bindings/mux/gpio-mux.txt | 69 ++++ .../devicetree/bindings/mux/mux-controller.txt | 157 +++++++ Documentation/driver-model/devres.txt | 10 +- MAINTAINERS | 15 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/i2c/muxes/Kconfig | 13 + drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-gpmux.c | 173 ++++++++ drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/inkern.c | 60 +++ drivers/iio/multiplexer/Kconfig | 18 + drivers/iio/multiplexer/Makefile | 6 + drivers/iio/multiplexer/iio-mux.c | 459 +++++++++++++++++++++ drivers/mux/Kconfig | 46 +++ drivers/mux/Makefile | 7 + drivers/mux/mux-adg792a.c | 140 +++++++ drivers/mux/mux-core.c | 422 +++++++++++++++++++ drivers/mux/mux-gpio.c | 114 +++++ include/dt-bindings/mux/mux.h | 16 + include/linux/iio/consumer.h | 37 ++ include/linux/mux.h | 252 +++++++++++ 26 files changed, 2232 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-gpmux.txt create mode 100644 Documentation/devicetree/bindings/iio/multiplexer/io-channel-mux.txt create mode 100644 Documentation/devicetree/bindings/mux/adi,adg792a.txt create mode 100644 Documentation/devicetree/bindings/mux/gpio-mux.txt create mode 100644 Documentation/devicetree/bindings/mux/mux-controller.txt create mode 100644 drivers/i2c/muxes/i2c-mux-gpmux.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/mux/Kconfig create mode 100644 drivers/mux/Makefile create mode 100644 drivers/mux/mux-adg792a.c create mode 100644 drivers/mux/mux-core.c create mode 100644 drivers/mux/mux-gpio.c create mode 100644 include/dt-bindings/mux/mux.h create mode 100644 include/linux/mux.h -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Rosin Subject: [PATCH v11 00/12] mux controller abstraction and iio/i2c muxes Date: Mon, 27 Mar 2017 14:17:37 +0200 Message-ID: <1490617069-13119-1-git-send-email-peda@axentia.se> Mime-Version: 1.0 Content-Type: text/plain Return-path: Sender: linux-kernel-owner@vger.kernel.org To: Greg Kroah-Hartman Cc: Peter Rosin , Wolfram Sang , Rob Herring , Mark Rutland , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Jonathan Corbet , linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-doc@vger.kernel.org, Andrew Morton , Colin Ian King , Paul Gortmaker List-Id: devicetree@vger.kernel.org Hi Greg! Since you didn't want to pull this, please consider applying the raw patches instead. The patches have been in linux-next for a couple of weeks like this already, but whatever works for you... Please just use the text from the pull request I sent earlier if you still need something for a possible merge commit, but why would you need a merge for raw patches? v10 -> v11 changes - added a fixes-tag and an ack from Jonathan on patch 11 - added a new patch (12) with a fix for messed up error path reported by Paul Gortmaker. - fixed some editorial nitpicks in the documentation comments in patch 3. v9 -> v10 changes - rebased onto v4.11-rc1 - added reviewed-by tags from Rob on patches 7 and 9 - added a new patch (11) with a fix for an unsigned compare with less than zero detected by CoverityScan and reported by Colin Ian King - allowed the mux core to be built as a module, after discussion with Paul Gortmaker - added explicit includes of linux/export.h and linux/init.h from the mux core, also noted by Paul - fixed trivial whitespace issue in drivers/mux/Makefile - added trailing '>' after my mail address in MODULE_AUTHOR, which was missing in all new modules in drivers/mux v8 -> v9 changes - dropped the suffix from the compatible string of the i2c-mux-simple binding (was ,mux-locked or ,parent-locked) and add an optional mux-locked property instead to change the desired locking behavior from the default parent-locked - add description of the difference between mux-locked and parent-locked - renamed i2c-mux-simple to i2c-mux (bindings for this general purpose i2c mux are in i2c-mux-gpmux.txt since i2c-mux.txt is already occupied by the common i2c-mux bindings) - changed compatible from mux-gpio to gpio-mux - changed bindings for idle-state back to a single array, but add defines for as-is and hi-Z thus avoiding magic numbers - make use of the above defines in the code as well - make idle-state a common mux property described in mux-controller.txt instead of repeating the info in individual mux controller bindings - drop the adi,parallel property from the adg792 bindings and piggy-back on the #mux-control-cells property - refrain from using the compatible string as node name - dropped the simplified bindings for single-user gpio mux - added acks on patches 2/10 and 5/10 from Rob v7 -> v8 changes - cleanup the implementation of the simplified gpio bindings, but still... - ...reorder patches so that they appear last in the series (patches 11 and 12 were patches 4 and 5 in v7) since Jonathan convinced me that they were perhaps not such a good idea after all. But I still wanted to show the last version I had and I'm still a bit undecided... - added some words to the remaining otherwise empty commit messages - added various acks/reviews from Jonathan and Wolfram. - move mux last in drivers/Kconfig and drivers/Makefile - bump copyright years - centralize error reporting of common operatinons to the mux core - add WARN_ON for faulty usage of mux_chip_register - simplify code for other WARN_ON call sites v6 -> v7 changes - move from drivers/misc/mux-* to drivers/mux/ [I will remove Cc:s to Arnd and Greg for v8, when/if that happens] - add managed versions of mux_chip_alloc and mux_chip_register - use the above in mux-gpio.c and mux-adg792a.c - also use them to support a simplified binding of a gpio mux for the common case where there is a single consumer (and no specific idle requirements) - new binding for describing idle behaviour of mux-adg792a - add bindings for the gpo-pins on the mux-adg792g - use device_property_read_u32 instead of of_property_read_u32 in mux-gpio.c - rename iio mux compatible to io-channel-mux (was iio-mux) - remove linuxism in the bindings (it was mentioning a function name) - add missing quote in the example in the io-channel-mux binding - factor out preparatory cleanup of devres docs to its own patch - add blank line in mux_chip_free - use SIMPLE_{PARENT,MUX}_LOCKED instead of magic numbers {0,1} in i2c-mux-simple.c - add some acks and a reviewed-by from Jonathan v5 -> v6 changes - fix stupidity in mux_chip_priv, mux_gpio_remove and adg792a_remove. - change the devicetree bindings for the iio-mux to use a list of strings (channels property) instead of a list children. v4 -> v5 changes - remove support for fancier dt layouts and go back to the phandle approach from v2 and before, killing the horrible non-working refcounting crap from v4 and avoiding a bunch of life-time issues in v3. - introduce the concept of a mux-chip, that can hold one or more mux-controllers (inspired by the pwm subsystem). - add dt #mux-control-cells property needed to get to the desired mux controller if a mux chip provides more than one. - take away the option to build the mux-core as a module. - if the mux controller has an idle state, make sure the mux controller is set up in the idle state initially (when it should be idle). - do not use a variable length array on the stack in mux_gpio_set to temporarily store the gpio state, preallocate space instead. - fix resource leak on one failure path in mux_gpio_probe. - driver for Analog Devices ADG792A/G, literally the first mux chip I found on the Internet with an i2c interface (that was not a dedicated i2c multiplexer like PCA9547) which I used to verify that the abstractions in the mux core are up to the task. Untested, just proof of concept that at least looks pretty and compiles... - various touch-ups. v3 -> v4 changes - rebased onto next-20161122 (depends on recent _available iio changes). - added support for having the mux-controller in a child node of a mux-consumer if it is a sole consumer, to hopefully even further satisfy the complaint from Rob (and later Lars-Peter) about dt complexity. - the above came at the cost of some rather horrible refcounting code, please review and suggest how it should be done... - changed to register a device class instead of a bus. - pass in the parent device into mux_control_alloc and require less work from mux-control drivers. - changed device names from mux:control%d to mux%d - move kernel-doc from mux-core.c to mux.h (and add some bits). - give the gpio driver a chance to update all mux pins at once. - factor out iio ext_info lookup into new helper function. /Lars-Peter - use an unsigned type for the iio ext_info count. /Lars-Peter - unified "brag strings" in the file headers. v2 -> v3 changes - have the mux-controller in the parent node of any mux-controller consumer, to hopefully satisfy complaint from Rob about dt complexity. - improve commit message of the mux subsystem commit, making it more general, as requested by Jonathan. - remove priv member from struct mux_control and calculate it on the fly. /Jonathan - make the function comments in mux-core.c kernel doc. /Jonathan - add devm_mux_control_* to Documentation/driver.model/devres.txt. /Jonathan - add common dt bindings for mux-controllers, refer to them from the mux-gpio bindings. /Rob - clarify how the gpio pins map to the mux state. /Rob - separate CONFIG_ variables for the mux core and the mux gpio driver. - improve Kconfig help texts. - make CONFIG_MUX_GPIO depend on CONFIG_GPIOLIB. - keep track of the number of mux states in the mux core. - since the iio channel number is used as mux state, it was possible to drop the state member from the mux_child struct. - cleanup dt bindings for i2c-mux-simple, it had some of copy-paste problems from ots origin (i2c-mux-gpio). - select the mux control subsystem in config for the i2c-mux-simple driver. - add entries to MAINTAINERS and my sign-off, I'm now satisfied and know nothing in this to be ashamed of. 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 (and subsystem) that is shared between all instances, and combine that with an iio mux driver and a new general purpose i2c mux driver that is only hooking the i2c muxing and the new mux controller. 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). 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... Cheers, peda Peter Rosin (12): devres: trivial whitespace fix dt-bindings: document devicetree bindings for mux-controllers and gpio-mux mux: minimal mux subsystem and gpio-based mux controller iio: inkern: api for manipulating ext_info of iio channels dt-bindings: iio: io-channel-mux: document io-channel-mux bindings iio: multiplexer: new iio category and iio-mux driver dt-bindings: i2c: i2c-mux: document general purpose i2c-mux bindings i2c: i2c-mux-gpmux: new driver dt-bindings: mux-adg792a: document devicetree bindings for ADG792A/G mux mux: adg792a: add mux controller driver for ADG792A/G iio: multiplexer: fix unsigned check with less than zero mux: core: fix error handling in devm_mux_chip_alloc .../devicetree/bindings/i2c/i2c-mux-gpmux.txt | 99 +++++ .../bindings/iio/multiplexer/io-channel-mux.txt | 39 ++ .../devicetree/bindings/mux/adi,adg792a.txt | 75 ++++ Documentation/devicetree/bindings/mux/gpio-mux.txt | 69 ++++ .../devicetree/bindings/mux/mux-controller.txt | 157 +++++++ Documentation/driver-model/devres.txt | 10 +- MAINTAINERS | 15 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/i2c/muxes/Kconfig | 13 + drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-gpmux.c | 173 ++++++++ drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/inkern.c | 60 +++ drivers/iio/multiplexer/Kconfig | 18 + drivers/iio/multiplexer/Makefile | 6 + drivers/iio/multiplexer/iio-mux.c | 459 +++++++++++++++++++++ drivers/mux/Kconfig | 46 +++ drivers/mux/Makefile | 7 + drivers/mux/mux-adg792a.c | 140 +++++++ drivers/mux/mux-core.c | 422 +++++++++++++++++++ drivers/mux/mux-gpio.c | 114 +++++ include/dt-bindings/mux/mux.h | 16 + include/linux/iio/consumer.h | 37 ++ include/linux/mux.h | 252 +++++++++++ 26 files changed, 2232 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-gpmux.txt create mode 100644 Documentation/devicetree/bindings/iio/multiplexer/io-channel-mux.txt create mode 100644 Documentation/devicetree/bindings/mux/adi,adg792a.txt create mode 100644 Documentation/devicetree/bindings/mux/gpio-mux.txt create mode 100644 Documentation/devicetree/bindings/mux/mux-controller.txt create mode 100644 drivers/i2c/muxes/i2c-mux-gpmux.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/mux/Kconfig create mode 100644 drivers/mux/Makefile create mode 100644 drivers/mux/mux-adg792a.c create mode 100644 drivers/mux/mux-core.c create mode 100644 drivers/mux/mux-gpio.c create mode 100644 include/dt-bindings/mux/mux.h create mode 100644 include/linux/mux.h -- 2.1.4