From patchwork Mon Feb 6 14:15:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 651508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96233C05027 for ; Mon, 6 Feb 2023 14:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbjBFORH (ORCPT ); Mon, 6 Feb 2023 09:17:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbjBFORG (ORCPT ); Mon, 6 Feb 2023 09:17:06 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80CEF227A6; Mon, 6 Feb 2023 06:16:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675693011; x=1707229011; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=rkMn+pXxQ+KKju55X4C3pa/suoqSDKrEPHgqwNgVWTQ=; b=K45G6x52p2EYve27n4pDIMWBT7ftGSQs11yEjSskVewIqB5mFxMJ08lU FGKLhMtu8WwQbzAxOuS1tEjV3XE8UbQVUympUWxn1rCGuYidIvgBrqX+B pDSESxErYZqLSEELsdw88Z1c3z67RvkEzCCQlsjLOGzJjhgryZRQnZx5z /sqyOhmQA3toGw51INWAL7O0fL3ODLEqjrEoJuQeV5amxTVkrCDm/PmjQ VlJPrYY9afXAJX/E6ZZXhfRTjhVsu9swbZhKzEnkh0y4X3ha4HWVPpjVj xI8gJuGRuL455PlHa66UzRswEJR5yMpHglCftiCHZtPwtfIM3OxbBl5Ao w==; X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="415431790" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="415431790" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 06:16:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10612"; a="666500603" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="666500603" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 06 Feb 2023 06:16:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 427F3241; Mon, 6 Feb 2023 16:17:03 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Mika Westerberg , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Linus Walleij , Jim Minter Subject: [PATCH v1 1/1] pinctrl: intel: Restore the pins that used to be in Direct IRQ mode Date: Mon, 6 Feb 2023 16:15:59 +0200 Message-Id: <20230206141558.20916-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org If the firmware mangled the register contents too much, check the saved value for the Direct IRQ mode. If it matches, we will restore the pin state. Reported-by: Jim Minter Fixes: 6989ea4881c8 ("pinctrl: intel: Save and restore pins in "direct IRQ" mode") Tested-by: Jim Minter Signed-off-by: Andy Shevchenko --- Jim, this is a bit simplified version than what you tested. But it shouldn't be a functional changes. Anyway, it would be nice if you have a chance to give this a try. Linus, I don't expect more to come for this cycle, feel free to apply directly. drivers/pinctrl/intel/pinctrl-intel.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c index cc3aaba24188..e49f271de936 100644 --- a/drivers/pinctrl/intel/pinctrl-intel.c +++ b/drivers/pinctrl/intel/pinctrl-intel.c @@ -1709,6 +1709,12 @@ const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_ EXPORT_SYMBOL_GPL(intel_pinctrl_get_soc_data); #ifdef CONFIG_PM_SLEEP +static bool __intel_gpio_is_direct_irq(u32 value) +{ + return (value & PADCFG0_GPIROUTIOXAPIC) && (value & PADCFG0_GPIOTXDIS) && + (__intel_gpio_get_gpio_mode(value) == PADCFG0_PMODE_GPIO); +} + static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int pin) { const struct pin_desc *pd = pin_desc_get(pctrl->pctldev, pin); @@ -1742,8 +1748,7 @@ static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int * See https://bugzilla.kernel.org/show_bug.cgi?id=214749. */ value = readl(intel_get_padcfg(pctrl, pin, PADCFG0)); - if ((value & PADCFG0_GPIROUTIOXAPIC) && (value & PADCFG0_GPIOTXDIS) && - (__intel_gpio_get_gpio_mode(value) == PADCFG0_PMODE_GPIO)) + if (__intel_gpio_is_direct_irq(value)) return true; return false; @@ -1873,7 +1878,12 @@ int intel_pinctrl_resume_noirq(struct device *dev) for (i = 0; i < pctrl->soc->npins; i++) { const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; - if (!intel_pinctrl_should_save(pctrl, desc->number)) + if (!(intel_pinctrl_should_save(pctrl, desc->number) || + /* + * If the firmware mangled the register contents too much, + * check the saved value for the Direct IRQ mode. + */ + __intel_gpio_is_direct_irq(pads[i].padcfg0))) continue; intel_restore_padcfg(pctrl, desc->number, PADCFG0, pads[i].padcfg0);