From patchwork Mon Mar 25 22:43:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 1064887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=atomide.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44Sq6t3SgWz9sSR for ; Tue, 26 Mar 2019 09:43:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730063AbfCYWne (ORCPT ); Mon, 25 Mar 2019 18:43:34 -0400 Received: from muru.com ([72.249.23.125]:42718 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfCYWnd (ORCPT ); Mon, 25 Mar 2019 18:43:33 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id BB86D8120; Mon, 25 Mar 2019 22:43:46 +0000 (UTC) From: Tony Lindgren To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aaro Koskinen , Grygorii Strashko , Keerthy , Peter Ujfalusi , Russell King , Tero Kristo Subject: [PATCH 1/3] gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only Date: Mon, 25 Mar 2019 15:43:16 -0700 Message-Id: <20190325224318.15076-2-tony@atomide.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325224318.15076-1-tony@atomide.com> References: <20190325224318.15076-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We need to only apply errata 1.101 handling to clear non-wakeup edge gpios for idle to the gpio bank(s) in the wkup domain to prevent spurious wake-up events. And we must restore what we did after idle manually as the gpio bank in wkup domain is not restored otherwise. Let's keep bank->saved_datain register reading separate, that's not related to the 1.101 errata and is used separately on restore. Cc: Aaro Koskinen Cc: Grygorii Strashko Cc: Keerthy Cc: Peter Ujfalusi Cc: Russell King Cc: Tero Kristo Reported-by: Grygorii Strashko Signed-off-by: Tony Lindgren --- drivers/gpio/gpio-omap.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -1444,7 +1444,10 @@ static void omap_gpio_restore_context(struct gpio_bank *bank); static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) { struct device *dev = bank->chip.parent; - u32 l1 = 0, l2 = 0; + void __iomem *base = bank->base; + u32 nowake; + + bank->saved_datain = readl_relaxed(base + bank->regs->datain); if (bank->funcs.idle_enable_level_quirk) bank->funcs.idle_enable_level_quirk(bank); @@ -1456,20 +1459,15 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) goto update_gpio_context_count; /* - * If going to OFF, remove triggering for all + * If going to OFF, remove triggering for all wkup domain * non-wakeup GPIOs. Otherwise spurious IRQs will be * generated. See OMAP2420 Errata item 1.101. */ - bank->saved_datain = readl_relaxed(bank->base + - bank->regs->datain); - l1 = bank->context.fallingdetect; - l2 = bank->context.risingdetect; - - l1 &= ~bank->enabled_non_wakeup_gpios; - l2 &= ~bank->enabled_non_wakeup_gpios; - - writel_relaxed(l1, bank->base + bank->regs->fallingdetect); - writel_relaxed(l2, bank->base + bank->regs->risingdetect); + if (!bank->loses_context && bank->enabled_non_wakeup_gpios) { + nowake = bank->enabled_non_wakeup_gpios; + omap_gpio_rmw(base, bank->regs->fallingdetect, nowake, ~nowake); + omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake); + } bank->workaround_enabled = true; @@ -1518,6 +1516,12 @@ static void omap_gpio_unidle(struct gpio_bank *bank) return; } } + } else { + /* Restore changes done for OMAP2420 errata 1.101 */ + writel_relaxed(bank->context.fallingdetect, + bank->base + bank->regs->fallingdetect); + writel_relaxed(bank->context.risingdetect, + bank->base + bank->regs->risingdetect); } if (!bank->workaround_enabled) From patchwork Mon Mar 25 22:43:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 1064888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=atomide.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44Sq6w1pwSz9sSR for ; Tue, 26 Mar 2019 09:43:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730459AbfCYWnf (ORCPT ); Mon, 25 Mar 2019 18:43:35 -0400 Received: from muru.com ([72.249.23.125]:42732 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfCYWnf (ORCPT ); Mon, 25 Mar 2019 18:43:35 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 74995819C; Mon, 25 Mar 2019 22:43:48 +0000 (UTC) From: Tony Lindgren To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aaro Koskinen , Grygorii Strashko , Keerthy , Peter Ujfalusi , Russell King , Tero Kristo Subject: [PATCH 2/3] gpio: gpio-omap: always scan for triggered non-wakeup capable interrupts Date: Mon, 25 Mar 2019 15:43:17 -0700 Message-Id: <20190325224318.15076-3-tony@atomide.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325224318.15076-1-tony@atomide.com> References: <20190325224318.15076-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org The bank->workaround_enabled should be for omap24xx erratum 1.101 but is not needed any longer as erratum 1.101 handling only needs to happen based on !bank->loses_context with patch "gpio: omap: Limit errata 1.101 handling to wkup domain gpios only". Further Grygorii Strashko points out that we are now tagging all edge GPIOs as non-wakeup GPIOs and rely on original erratum 1.101 handling for scacnning for edge interrupts that have triggered during idle. Also the TI Android kernel tree has an earlier commit "GPIO: OMAP: Always scan gpios during runtime resume" by Tero Kristo saying: "This allows the driver to generate interrupts for GPIOs that can't wakeup but have changed state during runtime suspend. We cannot depend on the decision based on no need to restore, as the system state might change and pending events could gather up." So let's remove bank->workaround_enabled and always scan for triggered edge interrupts on resume. We do that based on bank->enabled_non_wakeup_gpios. Cc: Aaro Koskinen Cc: Grygorii Strashko Cc: Keerthy Cc: Peter Ujfalusi Cc: Russell King Cc: Tero Kristo Reported-by: Grygorii Strashko Signed-off-by: Tony Lindgren --- drivers/gpio/gpio-omap.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -83,7 +83,6 @@ struct gpio_bank { int stride; u32 width; int context_loss_count; - bool workaround_enabled; u32 quirks; void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable); @@ -1469,8 +1468,6 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake); } - bank->workaround_enabled = true; - update_gpio_context_count: if (bank->get_context_loss_count) bank->context_loss_count = @@ -1524,9 +1521,6 @@ static void omap_gpio_unidle(struct gpio_bank *bank) bank->base + bank->regs->risingdetect); } - if (!bank->workaround_enabled) - return; - l = readl_relaxed(bank->base + bank->regs->datain); /* @@ -1576,8 +1570,6 @@ static void omap_gpio_unidle(struct gpio_bank *bank) writel_relaxed(old0, bank->base + bank->regs->leveldetect0); writel_relaxed(old1, bank->base + bank->regs->leveldetect1); } - - bank->workaround_enabled = false; } static void omap_gpio_init_context(struct gpio_bank *p) From patchwork Mon Mar 25 22:43:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 1064889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=atomide.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44Sq6y1rpWz9sSR for ; Tue, 26 Mar 2019 09:43:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730492AbfCYWnh (ORCPT ); Mon, 25 Mar 2019 18:43:37 -0400 Received: from muru.com ([72.249.23.125]:42740 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726010AbfCYWnh (ORCPT ); Mon, 25 Mar 2019 18:43:37 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 588D681AE; Mon, 25 Mar 2019 22:43:50 +0000 (UTC) From: Tony Lindgren To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aaro Koskinen , Grygorii Strashko , Keerthy , Peter Ujfalusi , Russell King , Tero Kristo Subject: [PATCH 3/3] gpio: gpio-omap: add check for off wake capable gpios Date: Mon, 25 Mar 2019 15:43:18 -0700 Message-Id: <20190325224318.15076-4-tony@atomide.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190325224318.15076-1-tony@atomide.com> References: <20190325224318.15076-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We are currently assuming all GPIOs are non-wakeup capable GPIOs as we not configuring the bank->non_wakeup_gpios like we used to earlier with platform_data. Let's add omap_gpio_is_off_wakeup_capable() to make the handling clearer while considering that later patches may want to configure SoC specific bank->non_wakeup_gpios for the GPIOs in wakeup domain. Cc: Aaro Koskinen Cc: Grygorii Strashko Cc: Keerthy Cc: Peter Ujfalusi Cc: Russell King Cc: Tero Kristo Reported-by: Grygorii Strashko Signed-off-by: Tony Lindgren --- drivers/gpio/gpio-omap.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c --- a/drivers/gpio/gpio-omap.c +++ b/drivers/gpio/gpio-omap.c @@ -352,6 +352,22 @@ static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset) } } +/* + * Off mode wake-up capable GPIOs in bank(s) that are in the wakeup domain. + * See TRM section for GPIO for "Wake-Up Generation" for the list of GPIOs + * in wakeup domain. If bank->non_wakeup_gpios is not configured, assume none + * are capable waking up the system from off mode. + */ +static bool omap_gpio_is_off_wakeup_capable(struct gpio_bank *bank, u32 gpio_mask) +{ + u32 no_wake = bank->non_wakeup_gpios; + + if (no_wake) + return !!(~no_wake & gpio_mask); + + return false; +} + static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, unsigned trigger) { @@ -383,13 +399,7 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, } /* This part needs to be executed always for OMAP{34xx, 44xx} */ - if (!bank->regs->irqctrl) { - /* On omap24xx proceed only when valid GPIO bit is set */ - if (bank->non_wakeup_gpios) { - if (!(bank->non_wakeup_gpios & gpio_bit)) - goto exit; - } - + if (!bank->regs->irqctrl && !omap_gpio_is_off_wakeup_capable(bank, gpio)) { /* * Log the edge gpio and manually trigger the IRQ * after resume if the input level changes @@ -402,7 +412,6 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio, bank->enabled_non_wakeup_gpios &= ~gpio_bit; } -exit: bank->level_mask = readl_relaxed(bank->base + bank->regs->leveldetect0) | readl_relaxed(bank->base + bank->regs->leveldetect1);