Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2387219rwb; Thu, 29 Sep 2022 09:32:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SOM9A+Fvu3mg2zXuNMN8SF0Xg9cBUzoTEKBqsCAIy0lAhzLtKXVlzD0IhG+GV7AVDVoBR X-Received: by 2002:a17:907:dac:b0:782:95fa:545c with SMTP id go44-20020a1709070dac00b0078295fa545cmr3433556ejc.277.1664469142182; Thu, 29 Sep 2022 09:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664469142; cv=none; d=google.com; s=arc-20160816; b=W2oPGP33p+tDFqnj9TE8b0sLcQjdvuhkooG21D+7USJyzosyP0ikoLAOG/+pSGdJW+ mupN1XEVEWsm/3xJUrVTHuWgXoBznOQ6HjgmeRuDgsvKB2IELoTHxNJ8kXK6hOGr/I7K OIBA6XIJdP/X/1mwxAuJr7iKYZPVBZdzEn+JkKUE155aFOGVcLnLCM64G/IpKI+RdEdO 2JmWfePmeIT+Ms8uc0XTAu08JXR+oWFtObjRIfp2UYF8xAU7opxZ/Nmlzt68oXNgrcX+ L3qWcsU+Ga0sZA/NarVepUIVcZwW/aK+1DOPz1yUw3vIq7vrJTuO1QQ7eyBGrZj1hcgM dAlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B0r229No2ndloGNnSKqyWtju+ZyoGiLRkamOZbtAkwk=; b=0KHib69hveRT0zvfZ08Xmm+egp8+Ey/blaBn/efCzWQJQ9YEtQMkGej1zt+M+Gqc4F q116PfUfdwC7G8cafXZGxMKyIFNO6reMGVY7YWeurNpVW0PptHSVl+cKzIS1KzZYL7cx qfqNEHxeoB6cZMNWIqNCSMJRyrk6UoPU9tYVyDkSIliM2LGXG7h0XGwRUB5Kd7KlM24P 1xcJ9cAp1CFd3DVapazDQjNiMR0YQWnQxnStUdXj2BkIieeg57q4uKYIqaCivsfRG6Y/ wcKHhhcG0KWiXIz5STmFNgtJthAYDkVsJ8/5xVqL7COUIRQ8KV5oEhGpCvvd3ux80VJ2 Lazw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QAZJzlDg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020a1709064a5000b007269ef1872esi7071326ejv.897.2022.09.29.09.31.56; Thu, 29 Sep 2022 09:32:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QAZJzlDg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236209AbiI2QTr (ORCPT + 99 others); Thu, 29 Sep 2022 12:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236172AbiI2QT1 (ORCPT ); Thu, 29 Sep 2022 12:19:27 -0400 Received: from mail-il1-x136.google.com (mail-il1-x136.google.com [IPv6:2607:f8b0:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 548551E2749 for ; Thu, 29 Sep 2022 09:19:23 -0700 (PDT) Received: by mail-il1-x136.google.com with SMTP id d14so952714ilf.2 for ; Thu, 29 Sep 2022 09:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=B0r229No2ndloGNnSKqyWtju+ZyoGiLRkamOZbtAkwk=; b=QAZJzlDguy3mKE+zsGgcSFuSfTFJIGz9MKe+jjzBYYHKoqnsbf1JYHAA77B/hA5Y55 HUvOVMQVCf3wZb/K1/E3JTgZdP4DvVPS941/i9eitPOUey8Z9Gc59Juuati4DdUf1HuR eIr87rq4WFT95YPhIMLm/oIQskAsT6JSumqeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=B0r229No2ndloGNnSKqyWtju+ZyoGiLRkamOZbtAkwk=; b=7qvB7rbXr4u7hKUP6yr1OmpJXv3AXUB3j1YpQ4TmDbBsSh/j/iWsU6HZmVRGjhPHDb 4sjP/RKhxciDVuP1aCXLIWHYZ54bQTpzS59zi7oyc6aCCT9bgshTRPJHwCkV/008f6CF BkjYDV7JTdcGtRRMEqKPz9OhNGNZ38D2RnytvjgNtqnQ+cAUkIPrpQg8/r3v5LJp5bIu Dkjcay5wpzkAV8wglCcHKnWeLBPpzlajizB290/MAmR1FJ67WOhPEO6RHQhQm/2qrMzU XyFdGlbTH186xDBca9CEcMM1YwBXJyqE6Kq3sD9l1er8eWxv5DW8AFakhJRXrCM5H8pz cLCA== X-Gm-Message-State: ACrzQf2KyAkGlDm3aPJpzScJPHSvd+y7oZaYctyhPJQJiCKr2NEFYAu/ BwW+47HzvAPSKpzCor+6Q7VZ/A== X-Received: by 2002:a05:6e02:2186:b0:2f5:cc0b:fb14 with SMTP id j6-20020a056e02218600b002f5cc0bfb14mr2002088ila.315.1664468362253; Thu, 29 Sep 2022 09:19:22 -0700 (PDT) Received: from rrangel920.bld.corp.google.com (h24-56-189-219.arvdco.broadband.dynamic.tds.net. [24.56.189.219]) by smtp.gmail.com with ESMTPSA id f12-20020a02848c000000b0035aab2f1ab1sm2965451jai.134.2022.09.29.09.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 09:19:21 -0700 (PDT) From: Raul E Rangel To: linux-acpi@vger.kernel.org, linux-input@vger.kernel.org Cc: andriy.shevchenko@linux.intel.com, dmitry.torokhov@gmail.com, hdegoede@redhat.com, rafael@kernel.org, mika.westerberg@linux.intel.com, mario.limonciello@amd.com, timvp@google.com, linus.walleij@linaro.org, jingle.wu@emc.com.tw, Raul E Rangel , Benjamin Tissoires , Greg Kroah-Hartman , Jiri Kosina , Matthias Kaehlcke , Yang Li , linux-kernel@vger.kernel.org Subject: [PATCH v6 01/13] HID: i2c-hid: Use PM subsystem to manage wake irq Date: Thu, 29 Sep 2022 10:19:05 -0600 Message-Id: <20220929093200.v6.1.Id4b4bdfe06e2caf2d5a3c9dd4a9b1080c38b539c@changeid> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220929161917.2348231-1-rrangel@chromium.org> References: <20220929161917.2348231-1-rrangel@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The I2C hid driver is currently manually managing the wake IRQ. This change removes the explicit enable_irq_wake/disable_irq_wake and instead relies on the PM subsystem. This is done by calling dev_pm_set_wake_irq. i2c_device_probe already calls dev_pm_set_wake_irq when using device tree, and i2c_device_remove also already calls dev_pm_clear_wake_irq. There could be some device tree systems that have incorrectly declared `wake` capabilities, so this change will set the wake irq if one is missing. This matches the previous behavior. I tested this on an ACPI system that has a HID touchscreen and verified the IRQ was armed for wake on suspend. Signed-off-by: Raul E Rangel Acked-by: Benjamin Tissoires --- (no changes since v5) Changes in v5: - Added Acked-by: Benjamin Tissoires Changes in v3: - Fixed typo in if condition Changes in v2: - Set the wake_irq when not configured by the i2c-core. This is different than v1, where the wake_irq was only set for non DT systems. drivers/hid/i2c-hid/i2c-hid-core.c | 33 +++++++++++------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c index baa169fadd66321..a2fa40dec04ea59 100644 --- a/drivers/hid/i2c-hid/i2c-hid-core.c +++ b/drivers/hid/i2c-hid/i2c-hid-core.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -116,7 +117,6 @@ struct i2c_hid { wait_queue_head_t wait; /* For waiting the interrupt */ - bool irq_wake_enabled; struct mutex reset_lock; struct i2chid_ops *ops; @@ -1036,6 +1036,15 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops, if (ret < 0) goto err_powered; + /* + * The wake IRQ should be declared via device tree instead of assuming + * the IRQ can wake the system. This is here for legacy reasons and + * will be removed once the i2c-core supports querying ACPI for wake + * capabilities. + */ + if (!client->dev.power.wakeirq) + dev_pm_set_wake_irq(&client->dev, client->irq); + hid = hid_allocate_device(); if (IS_ERR(hid)) { ret = PTR_ERR(hid); @@ -1119,7 +1128,6 @@ static int i2c_hid_core_suspend(struct device *dev) struct i2c_hid *ihid = i2c_get_clientdata(client); struct hid_device *hid = ihid->hid; int ret; - int wake_status; ret = hid_driver_suspend(hid, PMSG_SUSPEND); if (ret < 0) @@ -1130,16 +1138,8 @@ static int i2c_hid_core_suspend(struct device *dev) disable_irq(client->irq); - if (device_may_wakeup(&client->dev)) { - wake_status = enable_irq_wake(client->irq); - if (!wake_status) - ihid->irq_wake_enabled = true; - else - hid_warn(hid, "Failed to enable irq wake: %d\n", - wake_status); - } else { + if (!device_may_wakeup(&client->dev)) i2c_hid_core_power_down(ihid); - } return 0; } @@ -1150,18 +1150,9 @@ static int i2c_hid_core_resume(struct device *dev) struct i2c_client *client = to_i2c_client(dev); struct i2c_hid *ihid = i2c_get_clientdata(client); struct hid_device *hid = ihid->hid; - int wake_status; - if (!device_may_wakeup(&client->dev)) { + if (!device_may_wakeup(&client->dev)) i2c_hid_core_power_up(ihid); - } else if (ihid->irq_wake_enabled) { - wake_status = disable_irq_wake(client->irq); - if (!wake_status) - ihid->irq_wake_enabled = false; - else - hid_warn(hid, "Failed to disable irq wake: %d\n", - wake_status); - } enable_irq(client->irq); -- 2.37.3.998.g577e59143f-goog