Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5328969ybi; Wed, 12 Jun 2019 00:18:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqx8bvvrKEByv9SpJzu2Jh1XKRuLRM91x21gTZkQRU2xUhZHskr+uKCuu4aLMBrAJMC3t0c0 X-Received: by 2002:a17:902:23:: with SMTP id 32mr18667853pla.34.1560323938321; Wed, 12 Jun 2019 00:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560323938; cv=none; d=google.com; s=arc-20160816; b=NEWnzk/vpLw7IAHYlL0Y9ypgNHHyiIPFVyAeLdozD6IQuFSyKe4p96DoSNRGEOVQms HijAtd9DXQiluVHC9ilyKlFWUSYho2VbZV1jSDONnQ+24zml30fnW8Cs92hUrZZQkm6I c3ewXvuo8s1tRExxxkF2bSmICM82hBhKRUDUXvPpJLGskIPVyWGCM5Crop+Eseg5jBzX VjfFFLcj7dSv4tvjV0GI8oDjdqiGdLuJT7bCFPFR84ATRl6ekfKuoTNgn3Tp/PZzffu5 R66IYlEsibOtiauxyuldJyb+ED8368UCFO3lgPyGr9oTnd2l4ssldin3JcXGgXHTBuEs oq/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=cO1aoOgamWKzIBPutERy4+vShJ7ff0SjV7iwgqOmOxU=; b=hMIrDYfFXw00DJo8DBfIEY72sdzCbXg8EesdnE9UKQbeJiCLIhcgwL9oo2AX84XTV3 mkVwddzHW0FZy98Qx4m5MlvdlQFQMijLd1GMeZijZO7QCBecf5VsLh5XpMbTslJfdc39 JNZ8ZxG2chcY6Iwnvg4Q+dWn1KEDQw99kL5tMx1l+TFP2oXZfjk5BsotLcqOwtd1WgJ9 HhydQXb7aZ+fQmSKt6s0PSkBTTXiNbLFQyHcnavbfaoesJVYcgPS/siOHJyqKOBmM1rG 1spmWAKx1Bxj7g+/u402n9lbXz5VVS69cemoZWonszbRn/gykrLXxQqIVzL8APwV8M7i wYSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bjVRjE0A; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r14si4525993pjp.95.2019.06.12.00.18.39; Wed, 12 Jun 2019 00:18:58 -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=@gmail.com header.s=20161025 header.b=bjVRjE0A; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405967AbfFLAvY (ORCPT + 99 others); Tue, 11 Jun 2019 20:51:24 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41839 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405015AbfFLAvX (ORCPT ); Tue, 11 Jun 2019 20:51:23 -0400 Received: by mail-pl1-f194.google.com with SMTP id s24so5840650plr.8; Tue, 11 Jun 2019 17:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=cO1aoOgamWKzIBPutERy4+vShJ7ff0SjV7iwgqOmOxU=; b=bjVRjE0AIuXeVIkRPq5d1Q0m6f/ChSKt7gvzCfbsz28S9ZzhVQDoKcXtAbRw1ACu7m 7kp5ZXFytWCzXikbqIWU3/EvpxFMQfB2WIIUqTOSaJMIVSVV+Dhm+q2vF1nsxPL0ZQZN Xr4PWhZzFjjKM8olQlI+MNryiceHMLT2yhZwrxNEe+PPQiJHcsAN3gqc/Mj1eyT37wpG c97pPNrG3ML1GaEN+kj4zNEVcoHq9wcOmaqbjGvpzCgZTLuyoJtUrBdZ/iSO7t17EGrG 4euwRIk+oYorOyunXr8AfmtpioQuylyPP3xvwk0CbS+/E00uzYIB370WOdBdaH6J7lDA PWDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cO1aoOgamWKzIBPutERy4+vShJ7ff0SjV7iwgqOmOxU=; b=DWHzqi77Honw22GNNGKJzjDVztRrpEDpOJN5MPQ81TQJOo7LHKh/cc+G84ZMw8DkKp Re1wzNCtbLHlqgtrUaDvpXVGCxuf14elkTVvDBgwGzzbko145AbCYrEPDAxf/IIqDPib Jt9ReXI60Bks+QfCXw6cj9toj2bYAqiGFYqWV4QBsZoOK8uTk6vcn+3v8hS2YXyBbUHw gPI5JWgjDAU9qV/G164RE2uvsoI/0N/0RX4KFnw0GCyNiiupYpe134uKfnSAr+Qs/MCz mpv448I3LadB4Ux9q+zQmGzC/KzS8sEa44i1XiRiBFImnl6AVm3nwohIJ2r97XShFHG/ 5PxQ== X-Gm-Message-State: APjAAAUfealE+WXDh4NNevwFORAZjwLc+3Rzw+5DTot2W3xOJiM5y5JD Vdw9MiZKG0I7wtIyntw+Yan0o03iM2Q= X-Received: by 2002:a17:902:28:: with SMTP id 37mr15273311pla.188.1560300682592; Tue, 11 Jun 2019 17:51:22 -0700 (PDT) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id y5sm14480199pgv.12.2019.06.11.17.51.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 11 Jun 2019 17:51:21 -0700 (PDT) Date: Tue, 11 Jun 2019 17:51:20 -0700 From: "dmitry.torokhov@gmail.com" To: Anson Huang Cc: "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" , dl-linux-imx Subject: Re: [RESEND] input: keyboard: imx: make sure keyboard can always wake up system Message-ID: <20190612005120.GI143729@dtor-ws> References: <1554341727-16084-1-git-send-email-Anson.Huang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1554341727-16084-1-git-send-email-Anson.Huang@nxp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 04, 2019 at 01:40:16AM +0000, Anson Huang wrote: > 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 Applied, thank you. > --- > 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 = { > -- > 2.7.4 > -- Dmitry