Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp836890ybi; Fri, 12 Jul 2019 05:28:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyI1g6Mw9pH8IN0Arcrof5LpT5Z4wUV8m6K6f13Kmgu9ePPx63vErufAQmvHMEcWAF9xPJQ X-Received: by 2002:a63:ce01:: with SMTP id y1mr7721022pgf.389.1562934506917; Fri, 12 Jul 2019 05:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934506; cv=none; d=google.com; s=arc-20160816; b=z56TSQQxuau1u0dQTyAuAKybAM4XwVO+0RKQdyeR/wWL2U3SYIir769FO+2M7ftNv8 1lWzOJV9fiV9iSYvqSiLvTYgcQIZmE4Z0y2xqG+UklZACyiPuJwU583bJrhwGARDQNZF XYLMhDZd7z4K9IRlt/5HiUuY+gfWiR7UVvEjnIKsXZ2QbTxSX/amR3YjHIqFbIfx/gPC cpugT6QhDMO26TXVuwp5wMQeABAzWS9XJpyixufk2dLQ6JnIPYJJFuoiwrXrwlHeyHeK 8bXNOEKRTERNlo0Bwf9sN0JnbgfbbFhWMkdRyLtqObbxdfUnSAE0HlqbAStIfZk1+yPE +AIA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E8JtekGpGSeAg7NUMQs7ISZBZ5uu3CVUCuJynVkpJQ4=; b=YJ4A80SjdV19/KcKQ8IFW5UkH63NWRuLJZ/ViRJ33AfejhUr8wLqjCEPVFxZTlUNPT ERsa5kSDiiDImdm16h3s8pdh/mbGsLj5j2UIoJM/5ph5Z/SEK1Oh5Pwgupw/dW+tX13r 9/92sclGy+zSC97h9eX0D8Y6uYmFPQdKDk1qPi65C89aYv/6gbK69IHHAUFtc2iVF5ql EzBNhlvBGX7moZeM8dX+THc+3xMVG8bpXBAo1/y0ZBLT07IeDURCQZAakKaTdKMHj+Ni ewcx89Jg8E8fGZzts73dVR9WiRFnIxGqraeU7+HdnG7oiH80JlQLO2P9oWB5N0ckHkjL DRCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WHOKmxoq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y15si8074123pfe.133.2019.07.12.05.28.11; Fri, 12 Jul 2019 05:28:26 -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=WHOKmxoq; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728237AbfGLM1E (ORCPT + 99 others); Fri, 12 Jul 2019 08:27:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728531AbfGLM1A (ORCPT ); Fri, 12 Jul 2019 08:27:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C19621019; Fri, 12 Jul 2019 12:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934419; bh=Rq1qE4Q+NB15mQzhFLDDE6hKkM47OvHr+VRz5Ui1n4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHOKmxoqntiKzBWzqQJrp642TfS/pKrHtdFK+oatXRsXXpkoFHSX0NaW6JOio993f CkDweI0fryafF/m/WhuwY/HJxabf2iVGWnnjDE7sDgz1orTXLXpHE5M5ELF+L0E99V zih9jZyvAFaLBVcKuUm+yzR1OJ/F9IpqvkSuNNis= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anson Huang , Dmitry Torokhov , Sasha Levin Subject: [PATCH 5.1 049/138] Input: imx_keypad - make sure keyboard can always wake up system Date: Fri, 12 Jul 2019 14:18:33 +0200 Message-Id: <20190712121630.544937655@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit ce9a53eb3dbca89e7ad86673d94ab886e9bea704 ] There are several scenarios that keyboard can NOT wake up system from suspend, e.g., if a keyboard is depressed between system device suspend phase and device noirq suspend phase, the keyboard ISR will be called and both keyboard depress and release interrupts will be disabled, then keyboard will no longer be able to wake up system. Another scenario would be, if a keyboard is kept depressed, and then system goes into suspend, the expected behavior would be when keyboard is released, system will be waked up, but current implementation can NOT achieve that, because both depress and release interrupts are disabled in ISR, and the event check is still in progress. To fix these issues, need to make sure keyboard's depress or release interrupt is enabled after noirq device suspend phase, this patch moves the suspend/resume callback to noirq suspend/resume phase, and enable the corresponding interrupt according to current keyboard status. Signed-off-by: Anson Huang Signed-off-by: Dmitry Torokhov Signed-off-by: Sasha Levin --- drivers/input/keyboard/imx_keypad.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c index 539cb670de41..ae9c51cc85f9 100644 --- a/drivers/input/keyboard/imx_keypad.c +++ b/drivers/input/keyboard/imx_keypad.c @@ -526,11 +526,12 @@ static int imx_keypad_probe(struct platform_device *pdev) return 0; } -static int __maybe_unused imx_kbd_suspend(struct device *dev) +static int __maybe_unused imx_kbd_noirq_suspend(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct imx_keypad *kbd = platform_get_drvdata(pdev); struct input_dev *input_dev = kbd->input_dev; + unsigned short reg_val = readw(kbd->mmio_base + KPSR); /* imx kbd can wake up system even clock is disabled */ mutex_lock(&input_dev->mutex); @@ -540,13 +541,20 @@ static int __maybe_unused imx_kbd_suspend(struct device *dev) mutex_unlock(&input_dev->mutex); - if (device_may_wakeup(&pdev->dev)) + if (device_may_wakeup(&pdev->dev)) { + if (reg_val & KBD_STAT_KPKD) + reg_val |= KBD_STAT_KRIE; + if (reg_val & KBD_STAT_KPKR) + reg_val |= KBD_STAT_KDIE; + writew(reg_val, kbd->mmio_base + KPSR); + enable_irq_wake(kbd->irq); + } return 0; } -static int __maybe_unused imx_kbd_resume(struct device *dev) +static int __maybe_unused imx_kbd_noirq_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct imx_keypad *kbd = platform_get_drvdata(pdev); @@ -570,7 +578,9 @@ static int __maybe_unused imx_kbd_resume(struct device *dev) return ret; } -static SIMPLE_DEV_PM_OPS(imx_kbd_pm_ops, imx_kbd_suspend, imx_kbd_resume); +static const struct dev_pm_ops imx_kbd_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx_kbd_noirq_suspend, imx_kbd_noirq_resume) +}; static struct platform_driver imx_keypad_driver = { .driver = { -- 2.20.1