Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752246AbdHNOdW (ORCPT ); Mon, 14 Aug 2017 10:33:22 -0400 Received: from mail-bl2nam02on0074.outbound.protection.outlook.com ([104.47.38.74]:36465 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750859AbdHNOdU (ORCPT ); Mon, 14 Aug 2017 10:33:20 -0400 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=bestguesspass action=none header.from=xilinx.com; Subject: Re: [PATCH 2/8] gpio: zynq: Wakeup gpio controller when it is used as IRQ controller To: Linus Walleij , Michal Simek , Nava kishore Manne CC: "linux-kernel@vger.kernel.org" , "monstr@monstr.eu" , Borsodi Petr , =?UTF-8?Q?S=c3=b6ren_Brinkmann?= , Steffen Trumtrar , Peter Crosthwaite , "linux-gpio@vger.kernel.org" , Rob Herring , Josh Cartwright , "linux-arm-kernel@lists.infradead.org" References: <72d3cd83bed792a23ab60cf9b6d51b618f5aa084.1502103715.git.michal.simek@xilinx.com> From: Michal Simek Message-ID: <6da5fd79-fbc8-b613-954f-dcbe2ef8d6c5@xilinx.com> Date: Mon, 14 Aug 2017 16:33:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.1.0.1062-23256.005 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(2980300002)(438002)(199003)(377454003)(189002)(24454002)(106466001)(33646002)(83506001)(189998001)(77096006)(31696002)(229853002)(65806001)(8676002)(81156014)(6246003)(81166006)(53546010)(65956001)(54906002)(6636002)(6666003)(63266004)(2950100002)(8936002)(31686004)(47776003)(9786002)(5660300001)(23676002)(76176999)(54356999)(50986999)(478600001)(626005)(39060400002)(4326008)(305945005)(356003)(50466002)(36386004)(230700001)(64126003)(2906002)(86362001)(4001350100001)(36756003)(65826007)(107986001)(5001870100001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR02MB2466;H:xsj-pvapsmtpgw02;FPR:;SPF:Pass;PTR:xapps1.xilinx.com,unknown-60-100.xilinx.com;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2NAM02FT021;1:RTKko4BRExfBFR7qDCAxPKN41YnIrIe5WYySWGnEssyuKuubGGP+6kN4KyCvL78tqC9seG+26ks1DB0QEOq6T6ZzKjCxGapNflz3SEsyGoH+2BRdqNKm0N1+9Enq6MJL95jimXhulgKR7Ej5NtR6nKi3zZaND0yiSZQE3B23nnjcYMbBB5XmtddZB0zTktKoSyZoG2ABTDI1sC9L7geA8sBg6Myik1LK+TzUae3bDF/b8mc5Ub7/BlYcCpATTWA9bV5+ZJZfMC0ll79a/sjN8PtwUAeS9x1DvR8c2/hi1gkh+kV1uJyJucZ4MyMUQ1vwbta+Y97IyxdG11bZENIuVxmrA5E/A8U1VuLZLiCk84Y+fA5NhCs+OsAQeFijM1owGTy3I/ohOfhbpqYIL+CuIew/2Ks1jMxgZfnJ566COPWqfJFrtaHtmaNny3CZ+SdKLPs2m6bEFK5bswd4QNQK36ASCwDXJq0WP1StQ66jRDNOlWzMzJ5cliMeCFooV5tY5apXSUCOKNpk+0lcv/LuyxSYdEuZ+HSaF6aBAeQctYQwPU6DxRGVrRqZZtpdVLILVHTAeusVDwb2zN4WA92Hj5C/2GJwOpv2JuWRV26l8jloH08FOG0rMHVFOSbmd5oOm6us98xmcdUJTddTPAGq7kymdZhOx6jz473TAOamy0kqj6ksHdL/9vnQPug7F51q3wYb5WVmfvxKPSQWQc6m0qK1iXk6xKNiIH9wsayWDU3G5awDNav1KNTacN2ryfhNT47YRTL4YzHTHnCA2BqgiHhJeNPjRTYl0rbOx3XztKCwgRqfvwUxXMIIUHOSsN2D/Qizwn15q+93E6DImDXPlw== X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 045ae337-b59b-4c66-e624-08d4e32166bd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(8251501002)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BN6PR02MB2466; X-Microsoft-Exchange-Diagnostics: 1;BN6PR02MB2466;3:x8X20Gj6ggSGYA+eYeJtSZCeCcpcW0IEsTF8zm/nMVuF2VQ0kgeFJ8dzfPT6yj15r1Rqle2J2vbRH/uWgO+S/RPN1B/ftQq4K2yaSuXRgHSDVegC9YFMGubykywvyANTgYIkbixee3KAfKP9Eufm/EtUJh6p3ZWTks1jL2p+PxrVkSVZ7clgewbob6exE/I1V2mh1k1WGtJ4zinLB2R+SXZiWu7jwyq0mteSrqs19SqO4rfm2+daCgSdDVlyyn6+qo2dLxOkRfJf0bldXP6mLQ1p6Vtb5Fe2eDlMJE402ucryVXcv/Fn41ZwFUCW4roGnf2HvmGIQybWSSv3lAaRLGA5sLPLZzT/OeRLFuleS+c=;25:GAh49FxviVmJoKO7y+cUs7S2B9M14YWQGnWqD4ntGkXA4aQg4SVd5NHqFxSdykmLj+4zUWthQsXCKNyEk8HtImwUYDY7pVG5ChjaINP5EPImLtxzFQ4+lYrvFdRo7/eA2Q+SRJJ7RCC9NOkFD78GdxlmBMvwfUUofq3L+y0mwJ90lIMJvbKG1gsc7jujlGRpSFN0UEudXhVneSakQKLYGBtkE6nQTAwCnZTR+bvnVfKngeVxI2x/yBV9pwsK3hfQZZEn2jDGLPSey4A3+RPc/u9XHmRFX9d8Jz068CawF+Hx4RXypWi3Z8HHANBCP1HELZ5RwL3LqOusIuWA2AhEcA== X-MS-TrafficTypeDiagnostic: BN6PR02MB2466: X-LD-Processed: 657af505-d5df-48d0-8300-c31994686c5c,ExtAddr X-Microsoft-Exchange-Diagnostics: 1;BN6PR02MB2466;31:QY+AW2lsbhqPtZu0rjSHSxk0gXCSXacNwXKRjlNr7Kt3jnFTUYjiUim+oQc8PXw5Pq4mrD7O5+RdULpwsOTawjLOdXawK3VOWnUWvXdc2NvEfX7ok6tgXCAs/1a0e9d4ebvleSd5Hhes1d7t/4p8ZTQZXyGtl+BKzdl0ETZxoMvEnmyy+jIQioiDtAONqmEikT869ZuPwDDGiWrFglHU4UzzK53H2gG/OSf6v8D5EqA=;20:txBE8OKClj3XjQH+v8g4qZgFmhDQ2GEmT/FpJJoW5uS7UezD+3obznTjxKVOQp0BUaGjylkbxn6axaUNvNYYuFQQvinFGVsVZi4P4pclzwmBmSd+7QbNXmE8quzMZp/gTxigdYn9ahVi51f6QIiGA257P/JuOzmGjWrjbjbL6/PiAUwMdYEYx5p3OX49QQfcmPWDGrbuRFODeRuE4Rhx7XQOd9hRVv2V58P5V3JGvpamkrjepwUXpLqeQ+db0ubMT+4R1fKgwW6ShAUYn4eJezTkUlPrYZlWrHrsdNIELwOyQEXZrkPpiugxUUdCqi6gZG5de5k4acK5X65mxkM0lxhWGdc+erKv7AXZmpDi8Y0b7STB7mJXBc6GDs4Ka7mBCgKhYjalp+cVFr0E6w3guJW4v2QHJx3R13a349VaW3L9+VTqkczkTWum4gi5UekSH6hixB84rVP2BCWelb//lWKLwLx23vT+jVyJj2N8BxiHDuMc3IkvUwOvjrahSzlb X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(13016025)(8121501046)(13018025)(3002001)(10201501046)(93006095)(93004095)(100000703101)(100105400095)(6055026)(6041248)(20161123564025)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BN6PR02MB2466;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BN6PR02MB2466; X-Microsoft-Exchange-Diagnostics: 1;BN6PR02MB2466;4:ge+TlO9rKYQD99ZWQXkIYdENsOyMFlQDt+wdcW+nxW18m/w6K/+Y+ihRR6ZC+4fr8tkQcrEDxai+tByONgxYkdlz0cH9gB7NrlVvC0+j+A4zcpNoeDNdb5cGupJ8IEfVOkrzyw6wES4d1EySHikT6fVB5zMoTExtAsTgw3e0WgJ9TDEDXTJ9eKlkJ4ZoWoLHIS20s34SDQN0fH6Bhm83t8eGWtWzwonV/11b8gJ4ZJnxSBMTpBCusrMI/+yoXBi/IyNyGzHPxn2OtnEgqXFeyTkyLXrFFLBm5FN5fu9Y8n4= X-Forefront-PRVS: 039975700A X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCTjZQUjAyTUIyNDY2OzIzOlBNZ3NPUGJTc2hDSUEzR2F0emwxemordlRL?= =?utf-8?B?UHJsSytCaDI3Yk5SL0crUVdzazBPajFJdnFYMUtVWnZySkJ1SXkxdFpha0hj?= =?utf-8?B?U1NiMUczZHg4OFJBOUVuVDlrWW02eWR3SGtQOWcvb2ZCRU42K1F4Q05nbmp6?= =?utf-8?B?REd4WTFpcmRwOGUrR0JyejZsU0hEKzVTZElwakY5V2k4WlQwZitPUjlpT2lN?= =?utf-8?B?TTYxQThiT2tXd3ZpTEdUbHErYmdoZE44eWVNeTF4OWxoS0dFLzg0clVYSXhJ?= =?utf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alp+gEcuyFoRO4jROOXsXrSM8zIlT9qfWzC7LW4c+k85VhXZJQ7qZZJc5IVZCgVTassYVcIs1x1Brtb+vYLDlj0lmSsOETt75vjxLYgaCFv9Ae6nBrK8MzYI1WwZ0ZKtRQ==;24:kd5FkyHmhSRzQ7ZJhCCaYJF5X9CDQeu4egLaMSapM2HjtNrM4cJsHzTvuvaMAEkxoZ4Ks5DG716dTpFsbkMN9lYqcMCgNg1m2BGxKeWN8fo=;7:/r6CWIBkFwCYxM+IE1GcLEQdVcwBn5KYNG1WW8pnLh5RK7z59lC8qEt7u5/vCLSE0J5BB6NEcyaAn/g+A+2GIFxfwN5OpVyF4n+NEvK4jTaBVUzebpCBH+j3tph+OgZ4ZFGxP+6r0n153r3NhDgawMdRsYiVI/Q1apif65QzcFRYemYissc73T15MM7PI3Di0Ca/YIXdUJMA+WaTlWwGDjBIUFpOooY4+7DbvC/sOCk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2017 14:33:16.0573 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c;Ip=[149.199.60.100];Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB2466 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4927 Lines: 142 On 14.8.2017 15:53, Linus Walleij wrote: > On Mon, Aug 7, 2017 at 1:01 PM, Michal Simek wrote: > >> From: Borsodi Petr >> >> There is a problem with GPIO driver when used as IRQ controller. >> It is not working because the module is sleeping (clock is disabled). >> The patch enables clocks when IP is used as IRQ controller. >> >> Signed-off-by: Borsodi Petr >> Signed-off-by: Michal Simek > > I'm a bit worried about this patch. > >> +static int zynq_gpio_irq_request_resources(struct irq_data *d) >> +{ >> + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); >> + int ret; >> + >> + if (!try_module_get(chip->gpiodev->owner)) >> + return -ENODEV; > > You are poking around in gpiolib internals, I don't really like that. > I prefer that you use accessors and try to make the core deal with > this instead of fixing it up with a local hack in the driver. > >> + ret = pm_runtime_get_sync(chip->parent); >> + if (ret < 0) { >> + module_put(chip->gpiodev->owner); >> + return ret; >> + } > > What you essentially do is disable runtime PM while IRQs are in > use, the patch commit log should say this. > >> + if (gpiochip_lock_as_irq(chip, d->hwirq)) { >> + chip_err(chip, "unable to lock HW IRQ %lu for IRQ\n", d->hwirq); >> + pm_runtime_put(chip->parent); >> + module_put(chip->gpiodev->owner); >> + return -EINVAL; >> + } > > This is essentially a separate patch that should be done orthogonally. > (I don't care super-much about that though.) > >> +static void zynq_gpio_irq_release_resources(struct irq_data *d) >> +{ >> + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); >> + >> + gpiochip_unlock_as_irq(chip, d->hwirq); >> + pm_runtime_put(chip->parent); >> + module_put(chip->gpiodev->owner); >> +} > (...) >> + .irq_request_resources = zynq_gpio_irq_request_resources, >> + .irq_release_resources = zynq_gpio_irq_release_resources, > > Look at this from gpiolib.c: > > static int gpiochip_irq_reqres(struct irq_data *d) > { > struct gpio_chip *chip = irq_data_get_irq_chip_data(d); > > if (!try_module_get(chip->gpiodev->owner)) > return -ENODEV; > > if (gpiochip_lock_as_irq(chip, d->hwirq)) { > chip_err(chip, > "unable to lock HW IRQ %lu for IRQ\n", > d->hwirq); > module_put(chip->gpiodev->owner); > return -EINVAL; > } > return 0; > } > > static void gpiochip_irq_relres(struct irq_data *d) > { > struct gpio_chip *chip = irq_data_get_irq_chip_data(d); > > gpiochip_unlock_as_irq(chip, d->hwirq); > module_put(chip->gpiodev->owner); > } > > If you add pm_runtime_get_sync()/put to this and export > the functions you have the same thing and you can just reuse this > code instead of copying it. > > Arguably the above should indeed have that runtime PM code > (unless we know a better way to deal with IRQs). > > So can we fix this in the core and reuse it from there? I have checked 4.13-rc1 and none is doing anything with clock in these irq routines. It means it is a question if they have the same issue when device is sleeping or we do something wrong. It is not a problem to move these calls to core (patch is quite simple) but validate that if this is correct on others SoC. Do you know if we can validate this on different SoC? Nava: Can you please validate this again on ZynqMP? Thanks, Michal diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9568708a550b..a08a044fa4aa 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1647,14 +1647,22 @@ static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq) static int gpiochip_irq_reqres(struct irq_data *d) { struct gpio_chip *chip = irq_data_get_irq_chip_data(d); + int ret; if (!try_module_get(chip->gpiodev->owner)) return -ENODEV; + ret = pm_runtime_get_sync(chip->parent); + if (ret < 0) { + module_put(chip->gpiodev->owner); + return ret; + } + if (gpiochip_lock_as_irq(chip, d->hwirq)) { chip_err(chip, "unable to lock HW IRQ %lu for IRQ\n", d->hwirq); + pm_runtime_put(chip->parent); module_put(chip->gpiodev->owner); return -EINVAL; } @@ -1666,6 +1674,7 @@ static void gpiochip_irq_relres(struct irq_data *d) struct gpio_chip *chip = irq_data_get_irq_chip_data(d); gpiochip_unlock_as_irq(chip, d->hwirq); + pm_runtime_put(chip->parent); module_put(chip->gpiodev->owner); }