Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753278AbdDDJ2e (ORCPT ); Tue, 4 Apr 2017 05:28:34 -0400 Received: from mail-ve1eur01on0107.outbound.protection.outlook.com ([104.47.1.107]:59435 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752785AbdDDJ2b (ORCPT ); Tue, 4 Apr 2017 05:28:31 -0400 Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=axentia.se; Subject: Re: [PATCH v2] i2c/muxes/i2c-mux-ltc4306: LTC4306 and LTC4305 I2C multiplexer/switch To: , , , , References: <1490782541-7832-1-git-send-email-michael.hennerich@analog.com> <0d4c068f-d909-64be-421d-4500da7ebd4c@axentia.se> CC: , , , From: Peter Rosin Organization: Axentia Technologies AB Message-ID: Date: Tue, 4 Apr 2017 11:28:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [81.224.171.159] X-ClientProxiedBy: DB6PR0601CA0035.eurprd06.prod.outlook.com (10.169.209.21) To AM5PR0202MB2548.eurprd02.prod.outlook.com (10.173.89.9) X-MS-Office365-Filtering-Correlation-Id: 55656de1-b182-4be7-de82-08d47b3cf302 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075);SRVR:AM5PR0202MB2548; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2548;3:uDMKYivOO7k2EapNosKTNIID7cDPgtSZBv0MksSdXb14cqc8Obo+5Sf4KMibSs65nZqUSL2V1OLm8oETsWoCOUNx0yWcz7/HHI9RY7r6kyyiTEZVytuXcmMr9Pmir7iF4C18WPv35I+NnW3Ihkc/TDMCg+WnzEu1v0s0GNh3YGgAbM2pXD4GPyJR1x//ZGDvnV2PX0A8YLC7SZ2r4dFSKsCJxJuWLp+kPcPKWCOkeL2H6/6i0b2+9aoQqBUsks78Yd6daIWdEdkh71xywpx123l0pB8UaVjyK9s1iPYaWV0=;25:nTgBVKuU3ZVNwOPMiWxr+lmguAkH8qAMvvDBEuoQQcjZa3E5RsotAe2dSgKJY8kciis5M0/TR18pyKrJH6NplG2A3Y1e9e7WWZuXTmicrWHxqli3H1fy7T3qC860AncEnwE18TlbDXt/lFYc3WoGijocgqLhJ05vf/JJ2PSN/SVY/s78amjBIAnZruDhIiOs60tqLdARmOn9RGH4y4HWSwRlV+NLAZ4jx93Nm9RSxTG3ZC+3mZQmMw67kqVBsTFj+YvDmIbHUTfb8Xk1c7cACNfrBq2C2V8KilBRn0E+HYdV4OVxO9JRoO/SJuu7Pr0pAtT6V8sdcT4FRe6ycDtz6iRpzXLBp4b7S4Xfiu/+OnuHWg2q6upXdctpmK2HIfjp9Vrf3unMchOv1Wen6PajT49XVhjeWcDvN8uqbCCre3d05yiI13dn4FlCnsO8YbjM1Sl+sbc/MQueKqsXdlAwUg== X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2548;31:WiNEw2iPYeRA5qEofPS9PExmbTM5/YS9/E5iHpDek/aGz1wjLhhKCMENY5VLWtKffn4KHhyCcX1T5D8yZWC7bCt0H2rulUcf58MC9Ybs3jgLVl5XE6XVKqvUdqSbK0m45rl3Re6hUikVMnqsmmtxQ/vdnw1KTMXgg0QaIQ7Ruv7DDYru5O+sI2nW1pgy3fV8zXD4k7IZKgLQsCbEpIcfxeSHm5RzuB8Zk2ey3nxA3o0cOc3M7cBYFTPxLW4MAU6cfH5zGWTZFoX1zH9YBKWtTdjp8ogyeGmiqSw6zzlUrS0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(6041248)(201703131423075)(201702281528075)(201703061421075)(2016111802025)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(6072148)(6043046);SRVR:AM5PR0202MB2548;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0202MB2548; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2548;4:JOMmx1kochNtkD4fWcMqHoqVztS9SAjZe4O0w5ZjG+e9ldELGcRmJIWwvlO9XGy/3TkfxT9naDvax/KkXNE2djf/onAedeMUHuqhmzoJkx9DYby+6MXzRtyvpXr+wjtGn1ZAR4qlDV6mFXeCPz8B5nAut7CrzEJupioAMjZaH48PMcPiBa6rySUy6s/ddmok8I+6dTDyDf1H0RHirN+GCQphKFfTG18O0B4ip8iwOuFtqbhPahULYdRX2nV6AmxqKbc30fnWOrQ0zMLAHRBCh6/OIYAH/ZSt0UmYabOpzBLfRPIhypYHr29CnY2aoR3cj8Q2hRgZDliZ8q3obXqU4MAdSG9qh9pEdt+lFkJe/hKM1HYchnRiClyLvPgBYp4KTmwJQirXRHcKAWwhE7Cba1WHtiAbCnnh1Mk+hNaMw8XUFuouDE0NviHEg7IraniHp5AZRlyiG+uH4ROEruPd11hwJldm+ghpunGYvi54XHKzmNYEnBxblWNw6cOKCpZXl17xOsJWUD9pgZQYs+ruUBUebcPIIpbpbzvkL+FJfh8VZNOMcwhRMlfx0xwVVxQGnBKxkbqdhnVAqYhJRQwbRNoVEg0SjuEeHgZoKk31lIrKlSOH5rIdbYW6UR5XX5StRPQArWTvXUxPFzzKNIrmNBv9citrjUD7pjDvwudjlQ96vuaDRx1RZJQomjjTTs8lbt/CLuWjVkCW0MBGRTCULaRoLzqI5GH/3Zu1uWBFhz4EIL92ff1iDWs1l5BRvkWOFdfhG/Xh5RF+5Ummv42CUA== X-Forefront-PRVS: 0267E514F9 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(39400400002)(39410400002)(39450400003)(39830400002)(117156002)(25786009)(305945005)(83506001)(230783001)(8676002)(189998001)(7736002)(4326008)(229853002)(23746002)(33646002)(2950100002)(31696002)(86362001)(42186005)(6246003)(6486002)(77096006)(38730400002)(2906002)(31686004)(90366009)(65826007)(74482002)(230700001)(76176999)(50986999)(47776003)(54356999)(81166006)(8666007)(36756003)(53936002)(54906002)(5660300001)(65806001)(65956001)(66066001)(4001350100001)(3846002)(6116002)(50466002)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0202MB2548;H:[192.168.0.125];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;AM5PR0202MB2548;23:JuYpLKYN7GevK00GFsu6r0Dd4GzpLDD3sNA?= =?Windows-1252?Q?YtRTbgUdNCTUcYCHgV+/9KNHTErsoZr6SQDJho3fFLkX/5QYsV2JTkYA?= =?Windows-1252?Q?N1MeCYr4cgRAvifKQiQ3N5xzQOHmzPMRcMw45OfepxU9UafQJWiyvOFs?= =?Windows-1252?Q?lozvAutu4hvJeAuEGzj2ciPgcuZDkyIELds2pMPQl8iFmKLn8pLpql4e?= =?Windows-1252?Q?7dLThiUz3Zvdwwt4GIVmYdvMHyAFwKgHv0y+m1SGkMt57+djcTHfIiBT?= =?Windows-1252?Q?a8eHvtLPZSYS2n3fOa04blxmSzqOF3DqPTIeJ47L9+NS5z7FD1Ics6Sk?= =?Windows-1252?Q?Xqfj/EZjjce5c8aTeNOB3gRnDptLgd0S/PlI3bYIiPepvvIPuiVjaElY?= =?Windows-1252?Q?JuNY16u0J/K5b6sM2/cwi7E57hJ7e17qijh5p9tZOUsl+CNOSKPWr2wW?= =?Windows-1252?Q?vkrpmYGKHCoO4t6mIhOtSdvRycv6b7owk+JamWTDgI4MS+nre2KR/Jzk?= =?Windows-1252?Q?5x4+jZ2AdWx00EOY6miBtz755DjPaYl27L/F04Fm9AYUg1AWDFr3WauZ?= =?Windows-1252?Q?7Ua3vhzTsUPnxKbY4CoWL6GL4Bhb1iyggrl+bIl85MXuIcJitydRAicS?= =?Windows-1252?Q?emJH5KO3xEIA2VPzP4vn3VY2k+zwLoWEnKF0fYBS36ha29j5uruXziCw?= =?Windows-1252?Q?LyVnsSWut7L6lhYerg/An69tkV3NMXyZ7a9TW4xFq4keK4wDTuWk0aeA?= =?Windows-1252?Q?GGp6thO4G2zWzVKFCW/SEO7EsUFl9m+a3Nm2FSntD2o/NC28be9e9YxU?= =?Windows-1252?Q?s4VHbeKcTg5yyRf4HT9T99WDDjKNiGA1pHtHDfCELpHXwpT0XPuk4JFY?= =?Windows-1252?Q?wyjM5NhFEzrbAz0acbOOV56vmaNe2OHisdcPNrr8qHBueQmHbYYRoRmD?= =?Windows-1252?Q?dNqi/FGR2Y6xSinid4kvUyxKT0rKtvjJTS+hnWQeSAjJtaBQWMY4bxnw?= =?Windows-1252?Q?CRYOYKy/wzsKmne/4PpMJngUntAVwxvDtI30lkmMuL1l6CzVGELOMvNT?= =?Windows-1252?Q?6t4hETCF/BKsVF0penLGZPa0zOqzeYGREN+mfEBbySZ2FzScfpIqEAd1?= =?Windows-1252?Q?jxNboTOi8l6A+vERPFy2w7NYdB/suHJghn9QS4UHrcsI8L3vwTmqZFHl?= =?Windows-1252?Q?kuJVzC9uGW8NhRlcYyDFTuoItjOl9vpcMah9HJJ3hICwDrRJgxvuRvWz?= =?Windows-1252?Q?IbLehFxwid1WY7LMJpPkBYPqCvArJvuCqJhTuXdhbhuU447CkVZp7coO?= =?Windows-1252?Q?1Pu4OXCwdV145r9ioJq1EQFNxs3D2on4ZKKLbzqajKuOMI00=3D?= X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2548;6:11HpW9kxvvmgmPUGcPNiW9c8LBMrG0OCEyOHsq3kThfzzKvwHCXRjso81vLnNKD5nYu2wcROcy8FCFfTnpiMc+XvotRLZbnPgcDLYaibPNwas8hjaZywkkttDRZKbMdYXbDIXTy3PJCNzTAdCUazSymRLktkioOGLkQKDnew9rcYU/kigtoRYFV3MnBKBqjHZqFNXdYbScHwYUWuS6XedU+Crq2MykrAFOg4KWHA47ct18q7ISK53V6I9LXWxjRFI7ZsT4vNS5mt1wsvstM6yOZI6lHQ4itu0TTB87S9tdvGzpaLKfMeFJUvpwg0z1z9SeoHYZhEg5Zeaj0ASByBYGbRC712l6xOtkadwzbweqDumuARC2FVtTfRT4oVY/OfzDt0ikgJbevsF87vNTj+Mw==;5:Vi8iUKiGm/LvDGrkzbY7hsyesPKyJAhAKji8/T8IMYlPyB7aRZdflKZoHnm1tn+jxLn8TxSiH2HkfbibjAI8H4TlL048o4svIgtLkOTMuuQ+aczakoIxyJBNL3ShV0eeeBgYdmef+ufnsHEfii6snw==;24:bRV8m+Q0whixJfs5v1j8E8mPkxHb5Setn+ByNkOt4ZMY+2UwZHKH+SYWAeomGo3yRVtxkb4s3esrFisddOwaDGnd6zEDAPfvckIodRJxgp0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM5PR0202MB2548;7:+w+TPoyv/38Mv9RZYeLVdk677+Gdbze96Ps/J74hMnWAFMVwUCUG6RqJVjDOh07bFXg08NtBhbSiSPoEWZoN+BWhpYQOkimzk2+7+DbgyJvwyryZaS0ECWp8O73S5rBMWj6wLyWqYcRzuMJ/IQ8988jQ3xvMkbMk0mMKggSkDI/PBntBoj4lpMkwq+HORLDYSqQUYlTuGQl+rLV36Y4qNJAvV+MkCfG79OOhZAoLUMA14Tc6Cp2/gk1L+VrskHTy6O1ZcyquyiZngT1eSFPff/nE6vwKV/miuFPPMnmxDZ3VzHtptpxRO7Q8yJOF8H5Qo3Er8Ncw19yDiERbP20pQg== X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2017 09:28:25.9968 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0202MB2548 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3625 Lines: 86 *snip* *snip* >>> +static int ltc4306_gpio_get(struct gpio_chip *chip, unsigned int offset) >>> +{ >>> + struct ltc4306 *data = gpiochip_get_data(chip); >>> + int ret = 0; >>> + >>> + if (gpiochip_line_is_open_drain(chip, offset) || >>> + (data->regs[LTC_REG_MODE] & BIT(7 - offset))) { >> >> I wonder about this open-coded register cache. So, gpio people, is there >> a guarantee from gpiolib that only one gpio_chip operation is in flight >> concurrently? Because I don't see any evidence of that. With that in >> mind, I think some locking is needed? > > I thought there is a per chip mutex in the gpiolib. But I can't find > anything like this either. Since these two gpios can be used from > different internal or external users. The locking seem to be needed. > > This gets us back to the regmap option. I did a quick grep, and 9 out of > 205 drivers using regmap i2c, also use i2c_smbus... concurrently. > > grep -Rl regmap_init_i2c ./drivers | xargs grep -l i2c_smbus_ | grep "\.c" > > Mostly to work around non uniform transfer layouts. I see three options. 1. Go with regmap and convert to mux-locked. Then the unlocked i2c-xfer becomes an ordinary i2c-xfer (or smbus, whatever). This will result in the cleanest code. 2. Go with regmap and stay parent-locked. Then hook into the regmap locking as is done in one of the drivers that have worked around similar problems with regmap and parent-locked i2c-mux interactions: drivers/media/dvb-frontends/rtl2830.c drivers/media/dvb-frontends/m88ds3103.c This will probably work, but you'd need to add a number of extra helper functions. 3. Exclude register 3 from regmap and only use regmap for the other registers. This will be a bit ugly and ad-hoc, will need clear comments on what is going on and why it is safe etc. And I want to see it before I accept it. And it might not be my call to begin with, because TBH, it sounds a bit disgusting... > I'll check with Mark Brown on this topic. Ok, might be a good idea... >>> + >>> +add_adapter_failed: >>> + i2c_mux_del_adapters(muxc); >>> +gpio_default: >>> + gpiod_direction_input(data->en_gpio); >> >> This was actually not what I had in mind when I asked about it in v1, and >> this looks a bit strange. You have no way of knowing if the pin was >> configured as input when probe was called, and I don't see code like this >> all over the place. Maybe it's is ok to not disable the chip over >> suspend/resume, I was just asking because it looked a bit strange to grab >> a pin and then forget about it. Now that I think about it some more, it's >> probably ok to do just that since it is perhaps not possible to make the >> chip draw less power by deasserting enable, but what do I know? > > GPIOs are assumed by default inputs. So if you want to undo the actions > in probe. The logical consequence is to move them back to inputs, and > let the external PULL-UP or PULL-DOWN on the ENABLE decide what happens. > I would also prefer to leave it enabled, so that the GPIOs can retain My point is that I do not see any probe functions undoing gpio configs. Why bother in this case? Or are other probe functions really doing this? I actually didn't check, but I haven't stumbled over it previously and at least think I would have noticed... > it's last state. Well I think the device draws a bit less power when > disabled. But we don't support runtime PM anyways. It might not be safe to reset the gpio pins over a suspend/resume depending on what they are used for, so it is probably a bad idea to go there. Sorry for bringing the whole issue up and muddying the waters... Cheers, peda