From patchwork Thu Apr 4 01:40:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 10884723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E452117EE for ; Thu, 4 Apr 2019 01:40:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB69028A30 for ; Thu, 4 Apr 2019 01:40:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BECA328A2E; Thu, 4 Apr 2019 01:40:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5EDC128A30 for ; Thu, 4 Apr 2019 01:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=OC7OJE3sQI4BP7Q0ddnUaITNMrd8uD0dvnjufawJbNI=; b=WdBZTJk3fko/TT lDqfM9ZCpsaPgIK2V8evJqLChB7lZ+8P35LextheeA+VSIfGhxzvMxEVJQMd1GT57XXMBJIUMlOdj OUTEWI+XYrKPCMAHf1nidtl6d1dYJmZht0kxk3cbRNh9mgOcZoZFaSVvR7OBmEaQqO6nIR16TzRDN z8R3kDCAo8nAZJzPBNDSES04JG5kBK3sGY4AZRV3vW9NJ0cC0IW2+p+Xon53LYE2cQFDESQEGFU3c 5SzBLsq/vak8yY8AshfXBpgi8AqEgXo9L8wJv+uiMmKSyrBlJl2FPk/m55kt6CvjElLIuSfeEm1Lt jH42i63oqAm/PbtLpRXQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBrMt-000632-Bq; Thu, 04 Apr 2019 01:40:39 +0000 Received: from mail-eopbgr50049.outbound.protection.outlook.com ([40.107.5.49] helo=EUR03-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBrMb-0005lm-Qy for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 01:40:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f9AZco5422ZehIdKir2N0iZaqcbW2n+bBnxo/k40hlQ=; b=w/rA/pWZ2f3l/FufAkuwmDZMXl1ETtSoxgPuMyuwHVHYJRtxy3pv5PpVCPOBzKIfBAvwXzEm0CFuVkV6ke4ravlprpfubxUu806w+jEbgjimH7DGigpJ+hDigJpjHCekyGiEsl01EVSoL1PD3j/sjaGe0+6g5Fv75MndJ60wyJY= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3770.eurprd04.prod.outlook.com (52.134.73.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.22; Thu, 4 Apr 2019 01:40:17 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::e8ca:4f6b:e43:c170]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::e8ca:4f6b:e43:c170%3]) with mapi id 15.20.1771.016; Thu, 4 Apr 2019 01:40:17 +0000 From: Anson Huang To: "dmitry.torokhov@gmail.com" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "linux-input@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: [RESEND] input: keyboard: imx: make sure keyboard can always wake up system Thread-Topic: [RESEND] input: keyboard: imx: make sure keyboard can always wake up system Thread-Index: AQHU6odaZd/8EWsin0yXXO1zjKS4qw== Date: Thu, 4 Apr 2019 01:40:16 +0000 Message-ID: <1554341727-16084-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR03CA0038.apcprd03.prod.outlook.com (2603:1096:203:2f::26) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d6b49fd1-5ea8-434e-1d9c-08d6b89e7d10 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600139)(711020)(4605104)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020); SRVR:DB3PR0402MB3770; x-ms-traffictypediagnostic: DB3PR0402MB3770: x-microsoft-antispam-prvs: x-forefront-prvs: 0997523C40 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(376002)(346002)(366004)(396003)(189003)(199004)(52116002)(99286004)(71190400001)(71200400001)(25786009)(50226002)(256004)(66066001)(2201001)(36756003)(4326008)(68736007)(105586002)(2616005)(81166006)(476003)(478600001)(2906002)(8936002)(14454004)(14444005)(186003)(6436002)(2501003)(386003)(110136005)(81156014)(97736004)(53936002)(86362001)(486006)(6486002)(5660300002)(106356001)(8676002)(6506007)(3846002)(6116002)(102836004)(6512007)(316002)(26005)(7736002)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0402MB3770; H:DB3PR0402MB3916.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: mtlpFNmKPurjY1hvUDy97xv0jltP2fDWKBO8o6g/WB3xMKRo73XjZ/2CTRkHoX4yd7ofWT7pJzieVdwhm/ycIzZlBZi9Wm0h0NF6oGS1Y+kAX+DY2DgijoARg2seBqv8spJBwEzxqlJqum0WNgmwTV8CmRIJttwKMvRglYqy76fNwj0I1iYNNLQNxtsRysW6r71GPrgcoISVpAyMSqtjnWcHVXh88f2WeMFptgnDyg4Fpt+2jwfbROuPg/TycH8bgCrOVCxBk71L3rv/Z2AIWDqMHhy0I1eBrCE5hW0N1O0vSyUbR32Cb7nedleXOreFr0GI1ZyVE3kJm46/JVTKWzL4olsd2d1emcv7uCa9QraXmGvBAV58ZBNE7f2Ox/UZFQ/q4DzQvfoiwehDsgWir8zB4d+7ZMwVtPyM6d+epbk= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6b49fd1-5ea8-434e-1d9c-08d6b89e7d10 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Apr 2019 01:40:16.8720 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3770 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_184022_045307_BEF70177 X-CRM114-Status: GOOD ( 13.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dl-linux-imx Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 cf08f4a..97500a2 100644 --- a/drivers/input/keyboard/imx_keypad.c +++ b/drivers/input/keyboard/imx_keypad.c @@ -524,11 +524,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); @@ -538,13 +539,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); @@ -568,7 +576,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 = {