Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2953791imm; Thu, 24 May 2018 19:48:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpf0d0azhEoe9ScwMU8BooODvimO3x+uhJwLQ/KAdSEDwG/viEtT1vc4p6c3Cb57y2zqwdE X-Received: by 2002:a65:438a:: with SMTP id m10-v6mr469445pgp.315.1527216515226; Thu, 24 May 2018 19:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216515; cv=none; d=google.com; s=arc-20160816; b=05foIKCMk8HcZghoyMLZEYu5GK9niPsjnHWmhSXMLNiQCXOFJkFtQzqshDVuLczU7i IrIlsakuJHFrC2xw9FP9BtS4wpMkAVMlNIwe1mD3EQSTVgQ/5xmwt5UceuxWmq2zJlko N0ZaVcxWch5dR0KAAeNVAW5Ug35u+7Gq/yBtnzh97inMjixhnUF9Tfx0G3o0gC86iV7G 9/U4e8m64JkTcbQ8y3HxE4Z0+wLeXojZnvYJ3AIZ3JkCPTzYPg2Bloy7YfXyg5I7/El9 brEZaaPCCRTTujFjVGT3LXxB//khIlknX79SRQxJhwFXqZm7BSGiXbR/WV3r2gq2TJfD DrcQ== 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:arc-authentication-results; bh=xz4QCXBGhvBDFAxwt94K1Jx8mVI4fv2L/3oVxMABr+A=; b=mpPoiK67Ef6Ha9MLVnN0Ikwv7tc0KlwvhPcyvgeShFp061/SV5NYcjruKkSSudh/gf aQ7KRhdiFAt4PP9JnZSQLEidX99BxiOCb63qMSgp35Mqe12LmZm2WTMCmzTrsXe+KhLw 1WLDPX70r+OTd2hz/hv5ENiK5Tg/UFA8bHfwItmeR9+zH6etB/S3qMGo2KY0SSF4EBtt YA2DX2KdsPfxEwYym1Iie8Aj+Ik/epDXsRIsEw7R49B94mICVHrPe2BAXlytgIwa0tME 9hjuUw9CFT10fPQ0bPxy0GcjSaEvJ/BGxaCA3GAQxRB0qO8v4NerZfv53iZikZSMWBCo VjOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZNvKsyh/; 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 38-v6si23006675pln.390.2018.05.24.19.48.20; Thu, 24 May 2018 19:48:35 -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=ZNvKsyh/; 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 S968791AbeEXXmU (ORCPT + 99 others); Thu, 24 May 2018 19:42:20 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37317 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964936AbeEXXmS (ORCPT ); Thu, 24 May 2018 19:42:18 -0400 Received: by mail-pg0-f67.google.com with SMTP id a13-v6so1457603pgu.4; Thu, 24 May 2018 16:42:17 -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=xz4QCXBGhvBDFAxwt94K1Jx8mVI4fv2L/3oVxMABr+A=; b=ZNvKsyh/4yG0I4Blv4NiYB6wYi7XaScBKG91/ZZOG8eQaeu2nfNFhFy7546KFUpMXM pR3ldeQzqDujv3M+UzWC4hLRgcnw6i0kuZEqb8PraID6+Q54tgO3p7fAc4smq61+LMut wsWDO12dUameAuodWPuws/W3VKR6fhOBE4zgmYh3qQFUDO0abgaNU7GhNK84rXcJSbnT adawfJRSAyp2TFwjI69ulP4M7ikS0uR4B17MOHYfHYEyzYcjbZVaLQynevNm27+XH4rs itLJt03nbpOpF9RcIdsJW5DrZqWm3PNrmO3i6ueOlAQpmfOaiYssVrmjLPA426iX49V4 +PCw== 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=xz4QCXBGhvBDFAxwt94K1Jx8mVI4fv2L/3oVxMABr+A=; b=LYKtn0vJA6ZzqCd/JUTO4WzhGaVmA2LrF+98XeE1ljylV8mnz6XmNvYLnbc5V8iVf3 tNn8kzOmGt0QdYgFHvX6vILnEF9JtwFauFeKPiobuea1ZSE9y5rG8CLqg/k2eUQWfdcr 4KD6Tf1U0BqfgQRvr+YRuQOuQrtNttcEy8eI5OfVMKyMO69dGieODUGAn+vYac7ycoEV 3QgZWlTfu7hMqrPon6gM+ICTe6MojEHFZmID9piNxNIFTU8btEU2xHfmBPW3AqmgFpL2 k7RownJQc1GHsJ/f1SfFzY5tuJdbhjos1EOujuAq4B/o3W258X+sCuKaQ33wy72xp2AB dECQ== X-Gm-Message-State: ALKqPwf3oY1cefbZDXFtaoutJgKaTywte+00X0dY+IlNT9EjzwYajfdd GHksb4Vu225KWt7/pgX2FS0= X-Received: by 2002:a65:56cb:: with SMTP id w11-v6mr44724pgs.175.1527205337269; Thu, 24 May 2018 16:42:17 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1511:8de6:27a8:ed13:2ef5]) by smtp.gmail.com with ESMTPSA id c83-v6sm44347682pfc.111.2018.05.24.16.42.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 May 2018 16:42:15 -0700 (PDT) Date: Thu, 24 May 2018 16:42:13 -0700 From: Dmitry Torokhov To: Ravi Chandra Sadineni Cc: lee.jones@linaro.org, ravisadineni@google.com, dtor@google.com, tbroch@google.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, rajatja@google.com, bleung@google.com Subject: Re: [PATCH] cros_ec_keyb: Increment the wakeup count to the specific mfd device. Message-ID: <20180524234213.GE177107@dtor-ws> References: <20180523182958.25195-1-ravisadineni@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180523182958.25195-1-ravisadineni@chromium.org> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ravi, On Wed, May 23, 2018 at 11:29:58AM -0700, Ravi Chandra Sadineni wrote: > If the IRQ is processed during resume, increment the wakeup count to the > specific mfd device based on the event, if the mfd device is wake enabled. > This helps in identifying the specific device that caused the wake. > > Signed-off-by: Ravi Chandra Sadineni > --- > drivers/input/keyboard/cros_ec_keyb.c | 20 +++++++++++++++----- > drivers/mfd/cros_ec.c | 25 +++++++++++-------------- > 2 files changed, 26 insertions(+), 19 deletions(-) > > diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c > index 79eb29550c348..9b39289774405 100644 > --- a/drivers/input/keyboard/cros_ec_keyb.c > +++ b/drivers/input/keyboard/cros_ec_keyb.c > @@ -245,12 +245,16 @@ static int cros_ec_keyb_work(struct notifier_block *nb, > switch (ckdev->ec->event_data.event_type) { > case EC_MKBP_EVENT_KEY_MATRIX: > /* > - * If EC is not the wake source, discard key state changes > - * during suspend. > + * If keyb input device is not wake enabled, discard key > + * state changes during suspend. > */ > - if (queued_during_suspend) > + if (queued_during_suspend && ckdev->idev > + && !device_may_wakeup(&ckdev->idev->dev)) > return NOTIFY_OK; > > + else if (queued_during_suspend && ckdev->idev) > + pm_wakeup_event(&ckdev->idev->dev, 0); Are we reporting wakeup event on the right device? Normally we only report wakeups on hardware device whereas here we using input devices which are logical abstractions... In any case this can be collapsed a bit: if (queued_during_suspend && ckdev->idev) { if (!device_may_wakeup(&ckdev->idev->dev) return NOTIFY_OK; pm_wakeup_event(&ckdev->idev->dev, 0); } But I think you should actually look at ckdev->dev device here. Also, why do we ignore EC_MKBP_EVENT_SYSRQ event? > + > if (ckdev->ec->event_size != ckdev->cols) { > dev_err(ckdev->dev, > "Discarded incomplete key matrix event.\n"); > @@ -270,13 +274,17 @@ static int cros_ec_keyb_work(struct notifier_block *nb, > case EC_MKBP_EVENT_BUTTON: > case EC_MKBP_EVENT_SWITCH: > /* > - * If EC is not the wake source, discard key state > + * If bs is not wake enabled, discard key state > * changes during suspend. Switches will be re-checked in > * cros_ec_keyb_resume() to be sure nothing is lost. > */ > - if (queued_during_suspend) > + if (queued_during_suspend && ckdev->bs_idev > + && !device_may_wakeup(&ckdev->bs_idev->dev)) > return NOTIFY_OK; > > + else if (queued_during_suspend && ckdev->bs_idev) > + pm_wakeup_event(&ckdev->bs_idev->dev, 0); > + > if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) { > val = get_unaligned_le32( > &ckdev->ec->event_data.data.buttons); > @@ -522,6 +530,7 @@ static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev) > return ret; > } > > + device_init_wakeup(&idev->dev, true); > return 0; > } > > @@ -598,6 +607,7 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev) > return err; > } > > + device_init_wakeup(&idev->dev, true); > return 0; > } > > diff --git a/drivers/mfd/cros_ec.c b/drivers/mfd/cros_ec.c > index d61024141e2b6..df9520365e54b 100644 > --- a/drivers/mfd/cros_ec.c > +++ b/drivers/mfd/cros_ec.c > @@ -64,12 +64,14 @@ static irqreturn_t ec_irq_thread(int irq, void *data) > * cros_ec_get_next_event() returned an error (default value for > * wake_event is true) > */ > - if (wake_event && device_may_wakeup(ec_dev->dev)) > + if (device_may_wakeup(ec_dev->dev) && wake_event > + && ec_dev->wake_enabled) > pm_wakeup_event(ec_dev->dev, 0); > > if (ret > 0) > blocking_notifier_call_chain(&ec_dev->event_notifier, > - 0, ec_dev); > + wake_event && ec_dev->wake_enabled, > + ec_dev); > return IRQ_HANDLED; > } > > @@ -229,7 +231,7 @@ int cros_ec_suspend(struct cros_ec_device *ec_dev) > } > EXPORT_SYMBOL(cros_ec_suspend); > > -static void cros_ec_drain_events(struct cros_ec_device *ec_dev) > +static void cros_ec_report_events_during_suspend(struct cros_ec_device *ec_dev) > { > while (cros_ec_get_next_event(ec_dev, NULL) > 0) > blocking_notifier_call_chain(&ec_dev->event_notifier, > @@ -253,21 +255,16 @@ int cros_ec_resume(struct cros_ec_device *ec_dev) > dev_dbg(ec_dev->dev, "Error %d sending resume event to ec", > ret); > > - /* > - * In some cases, we need to distinguish between events that occur > - * during suspend if the EC is not a wake source. For example, > - * keypresses during suspend should be discarded if it does not wake > - * the system. > - * > - * If the EC is not a wake source, drain the event queue and mark them > - * as "queued during suspend". > - */ > if (ec_dev->wake_enabled) { > disable_irq_wake(ec_dev->irq); > ec_dev->wake_enabled = 0; > - } else { > - cros_ec_drain_events(ec_dev); > } > + /* > + * Let the mfd devices know about events that occur during > + * suspend. This way the clients know what to do with them. > + */ > + cros_ec_report_events_during_suspend(ec_dev); > + > > return 0; > } > -- > 2.17.0.441.gb46fe60e1d-goog > -- Dmitry