From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C768EC6FA91 for ; Mon, 19 Sep 2022 15:59:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbiISP7h (ORCPT ); Mon, 19 Sep 2022 11:59:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230347AbiISP7Y (ORCPT ); Mon, 19 Sep 2022 11:59:24 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0A5013E81 for ; Mon, 19 Sep 2022 08:59:20 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id b23so23102590iof.2 for ; Mon, 19 Sep 2022 08:59:20 -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; bh=hW0QoRs4aWz8hGceJu4a+SyoEP3lH5DdnWRzHluqBu0=; b=JaRo1ZTosTQe/0vWKQtXv0b1sMnT6M3VYtemc310W1+Gv5fsWMXd99UEw6C8wCFm6k qRysnmVAG/l7seml6DPM7LEqmrnIbSXD6Egre0UF4WVNVOGNoQ5A3TPwHK0yTtzVc+Ww 8JdXGOfwDxJjO2Vb9ZBnrlhGDD3o5UyyY7+aM= 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; bh=hW0QoRs4aWz8hGceJu4a+SyoEP3lH5DdnWRzHluqBu0=; b=IHGK6UVz9vPQL6fOtwyq0mnMvMG+DcJfco0Wx8sj80zHRJStfse6e7MRzrrV/ltrc6 BNBx4Tg0NSzHjc8z57RSdpAy/rkR4ROlVYl85aJgBKji0hmOCS9Xx/l7NGXOEVLQKK8O PU8/nDTk/sVvGY90ed0j9jooEcHWdKY/+CDDX6n/yIljQ7wjLvVL4eFjAfj7axAvo4Az +lhm3SOmA+WM6nOmIVwU+QSVg6Nux24+H8UxXsd4Ijto8wAekFN/FSuxDeb3MMAsE0bM EADU5s0FXay8v/sECNv1mYPDbOeU1dXLlP+LAgUhTZiGRS6RREPMOS+lhntO/vk5CPZj QFuA== X-Gm-Message-State: ACrzQf2MR758iW5oO6kPCO0kQynvj7jIG3IND8xJUjBr+B+wLLjPuXcL vt7CmZ1JgFAheOkPiIzOSedaAg== X-Google-Smtp-Source: AMsMyM5fGCKLLR+QD3OurBycWEJzSYo4BJhLo9F9vzj6fE4Q9/zHCZGYzeToxkoOFD+g2Q/rO1WIvA== X-Received: by 2002:a05:6638:24cc:b0:35a:5ee3:8f68 with SMTP id y12-20020a05663824cc00b0035a5ee38f68mr8828022jat.255.1663603160022; Mon, 19 Sep 2022 08:59:20 -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 t70-20020a025449000000b00349fb9b1abesm5634154jaa.106.2022.09.19.08.59.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Sep 2022 08:59:19 -0700 (PDT) From: Raul E Rangel To: linux-acpi@vger.kernel.org, linux-input@vger.kernel.org Cc: timvp@google.com, hdegoede@redhat.com, andriy.shevchenko@linux.intel.com, rafael@kernel.org, mario.limonciello@amd.com, jingle.wu@emc.com.tw, mika.westerberg@linux.intel.com, dmitry.torokhov@gmail.com, linus.walleij@linaro.org, Raul E Rangel , Alistair Francis , Angela Czubak , Bartosz Szczepanek , Benjamin Tissoires , Greg Kroah-Hartman , Jiri Kosina , linux-kernel@vger.kernel.org Subject: [PATCH v4 01/13] HID: i2c-hid: Use PM subsystem to manage wake irq Date: Mon, 19 Sep 2022 09:59:03 -0600 Message-Id: <20220919095504.v4.1.Id4b4bdfe06e2caf2d5a3c9dd4a9b1080c38b539c@changeid> X-Mailer: git-send-email 2.37.3.968.ga6b4b080e4-goog In-Reply-To: <20220919155916.1044219-1-rrangel@chromium.org> References: <20220919155916.1044219-1-rrangel@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- (no changes since v3) 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 baa169fadd6632..a2fa40dec04ea5 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.968.ga6b4b080e4-goog