Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966617AbcKXVxw (ORCPT ); Thu, 24 Nov 2016 16:53:52 -0500 Received: from mail-db5eur01on0115.outbound.protection.outlook.com ([104.47.2.115]:45389 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966233AbcKXVxU (ORCPT ); Thu, 24 Nov 2016 16:53:20 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=peda@axentia.se; From: Peter Rosin To: CC: Peter Rosin , Peter Korsgaard , Wolfram Sang , Subject: [PATCH v3] i2c: i2c-mux-gpio: update mux with gpiod_set_array_value_cansleep Date: Thu, 24 Nov 2016 19:19:28 +0100 Message-ID: <1480011568-13254-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: DB5PR08CA0047.eurprd08.prod.outlook.com (10.166.166.143) To AM5PR0201MB2308.eurprd02.prod.outlook.com (10.169.243.7) X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2308;2:J6qmpiniOEW8D0W9N8l4+IzHierPHJIErRucfXMnDDsPF6pqSuTXs5PLqMQe3uA8cA1W0XynxPpyW/ZevD9RFIpwalJ8BTuJle9o6I6rW+Hxij+tcHnQ44BK0dvrRGBOgx3jT2+9qEWGwwQOLB07r1UC9VFBfLb0E+tfxpevcA4=;3:BxQYpuhcL0LISg5VgFef2MBc6KjzsXr01lVEI3DHoBihW7AFhEzvPl058BXP22qVlitSG5YvYF2rgJWezDzlwSZn4E9qmSrNns3o31o3Iqlkd5QwWXmphjMM0TORJRWlBK7/yIAiW6OjtXSl8dBfYomcRxF1cC0Ia5UOEZNn8+k=;25:oqz8z8/FqdJavaz8Hys7HjUPIJu8itIw3NSTQIu6RIXDgRAWkPVvzsnfIdxPKMhtGFxh3nOZ7ERzHS2ihKKjVAf1fCXYUypnl/yVLeCIH1XyqqpoqexqEG1btrQe7tX4odZAPwnZMveSiHnDepTyY/m/zSHDPcg9QcIDDMNvvLXgFYTO/65WmsXMkVSo/TCW1eI/YM4wLKv1/YsWluQ2pdZwPwsmMssRkOykXwqVNKSGKSe2fwEXdA08JwflIpvuzJcQXWyey9ZfqHpLkGYrHxuX+al/JZkc1yzj9zMN8hbpiFQcnF1GQF3GnztITKA8TxpdwzA2H613vRKihLcc2Yd0dXla1YnyYDf5lCnksjJckGNdb7LJA2zShgoO9wGrQLtl4aABaCfl85Lo6ekubb/zTUK9ZPYv5gZaQGY8jbB1efJr3KvhtSaCI37H0rN2e2bzQyDfNC1pXHXQZIx+qg== X-MS-Office365-Filtering-Correlation-Id: 98641ffe-f7eb-457d-f8fe-08d4149672d4 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:AM5PR0201MB2308; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2308;31:8NFl6DEefr4c8jTj2gKxQq5Kufx1uwlgs2ywpYtf+/fODpu8l+JDrAixqHcE8Tl2JcSTUdNn2gm+pFtnwJYVXqhtXEBz2CiYDDCx2yRBJFgFq2QB/ainRccgxtCV+faXukoSfwTuSaB9BL1WZtnMbgbRoM4/kwb68j8BVQbmmlhu6gRKvFHzzW2bGmCRs7/97Gbb/I1MFGVBxSPp/jEvDZ8DQfV1F/dl7wRXJN5TQJBCnv/LuOuLGPEmAryTYJrs7Pz1EyGngdLflRefaDqZLuhkBrAf6aDib8ymW4neYoY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6045199)(6060326)(6040361)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041248)(6061324)(2016111802025)(20161123555025)(20161123564025)(20161123560025)(20161123562025)(6043046);SRVR:AM5PR0201MB2308;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0201MB2308; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2308;4:6S41psQ2VJtN0IQX2EzN4AQURHMMOUb6XdXBDIZQcA7cO0S/cNNJhur3lfNLM+iClIpaZremjrY7esT9k5cJJ/cIEt/MX4zwbCbt+8aRo3QlV/e62ul8dwhBnnuq/TPq7hHAcji9ibUBFRkrYFs8+V48OqCs+5/SGKHJNAWe6vnMcCyBLVrUYmkCbUY5KON7YozONx61PYJSx3LutABSQsgQpR0NXMVPGJ46LwytRFU3q6KstCk8lR5p3tqaDNTaxYNAwuGVw/iuLtITVx5XKOoIrJeh6b5GphSUdXK0aS0CxIQLS6DyZgRdRzjaEB36+J/gTxZsRyyCRAk/fuu3LjIwEXrcGFSMwWmyeJSBK/JA8V9DuZSuJjRvLmv45aeaKs2k4ueJD0xN0502Do/1YOf7iJbl+/r9ESjFptgrj6EDxqSuiaxH2CUYiigITBm1GuWSmd6vRN7C5ty+kjoeF/FodZyVxHNoG7AsmSrocaor1S/l9KASCDLEdp3T9UffS4DitABm04Y5JozvmC44rMcEaT/MwAgNYoCNvBikyJDWGd6BlH+Wy9hswTLjBE28TKW0MmSNsNb54FyxWZvubKGdAji3H4KGN2fj7QHJOtl72tMRdA2/DgAvdOX6Oi7oJp5CkycjVemJoOCl4nDD4mtMqxIyKKBA3IzGiTyl0ws= X-Forefront-PRVS: 0136C1DDA4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(7736002)(39380400001)(39410400001)(86362001)(74482002)(42186005)(6666003)(36756003)(5003940100001)(47776003)(6916009)(6116002)(105586002)(38730400001)(66066001)(2351001)(305945005)(230783001)(110136003)(101416001)(106356001)(7846002)(50986999)(97736004)(50466002)(50226002)(92566002)(3846002)(48376002)(189998001)(81156014)(15650500001)(8676002)(4326007)(68736007)(77096005)(2906002)(33646002)(39400400001)(5660300001)(81166006)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0201MB2308;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;AM5PR0201MB2308;23:OJj2SBrTWkaRN4aH5y7bwEv109jzhYMWpW+OrwT?= =?us-ascii?Q?5fY3GzkaWu9DZfyge0LfAELSu6fDmoOux+XAR5UrhG6vL4tAqS1Xo5kMxwVD?= =?us-ascii?Q?Na//5rdgJTp3L+IBrTWhJ5DR7ErWuCJrpC8l4fwaWHOs5bQA74mOs3LQy//H?= =?us-ascii?Q?//mgkl09B1Srqgu1Fr3ElUASzQku6yz+etfRKZaA3D+hsm52Oj8Qp/edfGfT?= =?us-ascii?Q?UIpj/F4vrCkjXGW8moh90K2RWdZoyJ2lTY1tSuvpgzCdV7eJ2cjjNyEaATfG?= =?us-ascii?Q?BoBNvcPCf0Hi5FzW0tLx1R52jbTDDqmLTQ4q1CdMTGqQXlKvctOvJp+fwC4/?= =?us-ascii?Q?67dklO62Srg1gPj3Ci7pCNQnbyY2wZ39P6pgRkQ8xp0unQUOwsP8whz3R2DQ?= =?us-ascii?Q?WJ5taC5GmnWzGT5HDxdvBp/9sYUrjxEN6yHq0IbhKbACYFGlQzSth5lIW2vP?= =?us-ascii?Q?ldOCNUjNNC9ji+xL9QrD+4sZcLEg6V1Gs4hI8nr8gSNbLt8uBayafgG7zIWg?= =?us-ascii?Q?Mm8WM3EDyAWxz47EJJZYCHKlMt62JqUTF3SWKGcy826+gxwKXhmSMyM5qGNo?= =?us-ascii?Q?bt8oYz2NL9MvCpQReoxCWRu1CynL10Ip00X65GdwhC81HPUwEHs86MjEQI9n?= =?us-ascii?Q?ECUGGTHZc+RtAOe72JJWMTelpUK3moOcUwD/xKQfkjl8Wu8No90+zPoQOpYe?= =?us-ascii?Q?FPYMENMiX7VYrBrmsuKwoeR1JWws6rxFQyApHcua0NEKYxKiHlY3VEpOXAPd?= =?us-ascii?Q?KJa4l2cVdGa4gezSyQ8uFc3LQYCNh2jqQnp2Xk/u+049BTk/8Xb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85B7IWV57sgFyJdY6dDcm9EKqCEDfvUzxykfWkurn/r/sJDEI0I3UX59jck4cOQxR0/5DLlmoWMBLdt5PIKcZZnE/hoCUwywpBI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM5PR0201MB2308;7:+TS1ERjbCQaMj9vEHlkj1RshMHAirwCe7C9neK6/O6Ubcmhgswr+ByiMfrkyXbb6pUCtenYZeqONENXlpbf8kMS57JFiJrRIsXxr11QnBQbOQpmfOqwxrKigIE1/EgQZdI/w1YQfdnnhPi0SGoCLavJpdVdYMhrufO5KyqDA5704vYKxl7MBerUsU+MB4k6s/HB/971Dqe1o4xZu1/IIT0BqGg5iMdoDs2gqONe3NZK0G2Dn8yGwioLFg6ZvnOVwp3Rf45sUCUCPE7ESHWT7ZNy80gjqXh1MYf68nk/Z9WiVTKueNz+3r0K0Z8J0sXcTr8WYU/WPNORNipih33ZhT+Dq4CQ+Qis6MF7DsjSwL2Q= X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2016 18:19:36.1915 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0201MB2308 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2560 Lines: 83 If the gpio controller supports it and the gpio lines are concentrated to one gpio chip, the mux controller pins will get updated simultaneously. Signed-off-by: Peter Rosin --- drivers/i2c/muxes/i2c-mux-gpio.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) Hi! v2 -> v3 changes - preallocate temporary storage for the values array needed by the gpiod_set_array_value_cansleep call, killing a warning about variable length arrays reported by Wolfram. - allocate a correctly sized array for gpios (number of pins, not number of channels). v1 -> v2 changes - rebase onto something without interference from other patches Cheers, Peter diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index e5cf26eefa97..655684d621a4 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -21,6 +21,8 @@ struct gpiomux { struct i2c_mux_gpio_platform_data data; unsigned gpio_base; + struct gpio_desc **gpios; + int *values; }; static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) @@ -28,8 +30,10 @@ static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) int i; for (i = 0; i < mux->data.n_gpios; i++) - gpio_set_value_cansleep(mux->gpio_base + mux->data.gpios[i], - val & (1 << i)); + mux->values[i] = (val >> i) & 1; + + gpiod_set_array_value_cansleep(mux->data.n_gpios, + mux->gpios, mux->values); } static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan) @@ -176,12 +180,16 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) if (!parent) return -EPROBE_DEFER; - muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, 0, 0, + muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, + mux->data.n_gpios * sizeof(*mux->gpios) + + mux->data.n_gpios * sizeof(*mux->values), 0, i2c_mux_gpio_select, NULL); if (!muxc) { ret = -ENOMEM; goto alloc_failed; } + mux->gpios = muxc->priv; + mux->values = (int *)(mux->gpios + mux->data.n_gpios); muxc->priv = mux; platform_set_drvdata(pdev, muxc); @@ -219,10 +227,12 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) goto err_request_gpio; } + gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]); + mux->gpios[i] = gpio_desc; + if (!muxc->mux_locked) continue; - gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]); gpio_dev = &gpio_desc->gdev->dev; muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; } -- 2.1.4