Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5578773img; Wed, 27 Mar 2019 11:03:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKDdVUjT5A3AkHBVZARtYXfUFJU2VxZL/GYrUHnt9DNhGIL6f8i+dqJoJcHKU5Y/nmKQrh X-Received: by 2002:a65:63cd:: with SMTP id n13mr36073022pgv.193.1553709822616; Wed, 27 Mar 2019 11:03:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553709822; cv=none; d=google.com; s=arc-20160816; b=p1CjFTfc+hIG9qcn6TaUjItJxJTTehi3konaM4SoMqYBzZ6CoAUPwxEbGSfEpOMrbO Tmh7gx2P9mZXi1hrL7Rd1afixpF2QfCa3zWEwFUrkxVgO6HRSGPlw6i5ofYDc0jJj9Nb 24qSUVOhZ1OT73spclKDArKxC+Ys2bbWLfHLPeSOMaMl5ZANyaugNfJ5FynPa3CaoqvP WNAfA5zOGvUHTecflPBfoaXPfB3WoTmKPUwvhhq4HbRmm3nsKgshs+ZzW9lNuR0JCmT0 lQvMmGxfPN63RJ0+xrihxxhEZg0OJPAoEUni1D2IcySn2EITwDgbrD+YmSu2RgpHZKGQ LvSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QH+X0f9ZH9LL+4n1jziBdvV+21gws0fhBuJezi+Z9vk=; b=JpJCE05F1b9YQc9xXy0r+M51Xb/JHt/LmdxJ92my2mGyV4AF11KgN2VBHhA7/sWGXh 4TsVa0hBC9eqI5IbyHU0yz1fHHWuIqsjgXq+NWoz87KfcJkrzmqWwmJZ1rYtRBWyy9pB nMZzNs79Ah0C5tgh0q8rM8yOgGJaNZb8aKNLT2CQ0wrMSYtC9t6hxQF7BvqBSkfoMqBB DfwMAdakmyLFiElXjkWrKRuelzqYAD/ZhDXLCI1EV80TQNOwARZ7RMag6vPAhASIpuew mF/vn1GEYNKP6X8gj01czloE09mnsn9DVF0Gfygm0yWAyffXXlPV9cl7MSAosv+OPH+a t3gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SmaSFmf0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k131si8968512pga.267.2019.03.27.11.03.27; Wed, 27 Mar 2019 11:03:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SmaSFmf0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730876AbfC0SCd (ORCPT + 99 others); Wed, 27 Mar 2019 14:02:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730712AbfC0SCa (ORCPT ); Wed, 27 Mar 2019 14:02:30 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A1FE217F5; Wed, 27 Mar 2019 18:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709749; bh=gKrx5b9kXf4CGaPaiL11Cp/4MC/nYXPjMqoRixiE+j4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SmaSFmf0AzG02MxVjLBzLlxWmZnit/mQBXPMJC7/yLXd5GOBFl2IIQsKsxw3wSVEG Nkb0kTbIhllV3Cw3JIZ3JqhwMrgtqFGk49NDn65ktMT/6iVF8S9iXSLEKr0wOQeLEw WIJwdbpWIRDzDLUtxpS5wNbyDxY3KPh0SmuoBIoE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Russell King , Aaro Koskinen , Keerthy , Peter Ujfalusi , Tony Lindgren , Linus Walleij , Sasha Levin , linux-omap@vger.kernel.org, linux-gpio@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 018/262] gpio: gpio-omap: fix level interrupt idling Date: Wed, 27 Mar 2019 13:57:53 -0400 Message-Id: <20190327180158.10245-18-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King [ Upstream commit d01849f7deba81f4959fd9e51bf20dbf46987d1c ] Tony notes that the GPIO module does not idle when level interrupts are in use, as the wakeup appears to get stuck. After extensive investigation, it appears that the wakeup will only be cleared if the interrupt status register is cleared while the interrupt is enabled. However, we are currently clearing it with the interrupt disabled for level-based interrupts. It is acknowledged that this observed behaviour conflicts with a statement in the TRM: CAUTION After servicing the interrupt, the status bit in the interrupt status register (GPIOi.GPIO_IRQSTATUS_0 or GPIOi.GPIO_IRQSTATUS_1) must be reset and the interrupt line released (by setting the corresponding bit of the interrupt status register to 1) before enabling an interrupt for the GPIO channel in the interrupt-enable register (GPIOi.GPIO_IRQSTATUS_SET_0 or GPIOi.GPIO_IRQSTATUS_SET_1) to prevent the occurrence of unexpected interrupts when enabling an interrupt for the GPIO channel. However, this does not appear to be a practical problem. Further, as reported by Grygorii Strashko , the TI Android kernel tree has an earlier similar patch as "GPIO: OMAP: Fix the sequence to clear the IRQ status" saying: if the status is cleared after disabling the IRQ then sWAKEUP will not be cleared and gates the module transition When we unmask the level interrupt after the interrupt has been handled, enable the interrupt and only then clear the interrupt. If the interrupt is still pending, the hardware will re-assert the interrupt status. Should the caution note in the TRM prove to be a problem, we could use a clear-enable-clear sequence instead. Cc: Aaro Koskinen Cc: Keerthy Cc: Peter Ujfalusi Signed-off-by: Russell King [tony@atomide.com: updated comments based on an earlier TI patch] Signed-off-by: Tony Lindgren Acked-by: Grygorii Strashko Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/gpio/gpio-omap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c index f4e9921fa966..7f33024b6d83 100644 --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -883,14 +883,16 @@ static void omap_gpio_unmask_irq(struct irq_data *d) if (trigger) omap_set_gpio_triggering(bank, offset, trigger); - /* For level-triggered GPIOs, the clearing must be done after - * the HW source is cleared, thus after the handler has run */ - if (bank->level_mask & BIT(offset)) { - omap_set_gpio_irqenable(bank, offset, 0); + omap_set_gpio_irqenable(bank, offset, 1); + + /* + * For level-triggered GPIOs, clearing must be done after the source + * is cleared, thus after the handler has run. OMAP4 needs this done + * after enabing the interrupt to clear the wakeup status. + */ + if (bank->level_mask & BIT(offset)) omap_clear_gpio_irqstatus(bank, offset); - } - omap_set_gpio_irqenable(bank, offset, 1); raw_spin_unlock_irqrestore(&bank->lock, flags); } -- 2.19.1