From patchwork Sun Jun 4 15:19:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 103030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2203043vqr; Sun, 4 Jun 2023 08:50:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7W6udaHTRFZ40IGnJ2ZXT821YdddyQTcKE3EpbKvWN/mbn1jYT37Rrapza7RoZ+P7UyjRO X-Received: by 2002:aca:2814:0:b0:39a:6203:a754 with SMTP id 20-20020aca2814000000b0039a6203a754mr5586431oix.31.1685893829216; Sun, 04 Jun 2023 08:50:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685893829; cv=none; d=google.com; s=arc-20160816; b=LlG2pmwbATPEXibnCJKASZ3vuHJOPf+gPcWN/Y9rdcRMGLxE5KFbSLo7J0t71nYFZJ gr88r2woHmOsSDn+dGwNzy2W1iPFSwN9obrjke8L/lOxnBcuX7x/KmShlBr2QY4znrQd AG/GJi8Dwhyo9U+i/aUXhVzltSCeiBSM5ZJTMGWrUB5dMe+7VZFiMUlQlKd5SPkdp/AX 9uAuW/l4a+sh4Pp364wSbRFBSKZZMe0TkBF6vWW5WwcKlPayw4oFBgaor4WQJ/w5MefC q6/Ygwi2AD2KFG3EVAKNK38gqcZKKJNhcsnF+tvPERQziXiubifVAbIyFe9QnnkhXnCE cjYg== 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; bh=SkBCbzC5Q7H3q9402Khr5Bmslhuw0GegI8f6ZmI6UM0=; b=SnW2SSWWne+kiCNzHa2PpLjRGDs8FBrShNiAEkO0rn1+rLRlvidhcDHA7JiJEvGOYo MO9V8qo/SsVbiHjM4Dwc2O3mN7A0bWlgFBOWpWoXlMUgCFAvN0Wv0uRNQVZHnFh5ZXEB vv/XWBjPnLH50w4xFn9eeUKk3GKgEppSPB49a1fUuTw+m8cEIo4PNQUqDWNWNcOAkzSs LaEDfy7Fv317o76xnOYpKLRiPwnfLFrRKKzGymTVqp231DZlAsKJuTkB3JRjvtyBGY5F WaGc3vvxlErH1ORCwGkPg+7+GNzpN2foJqw2O345yY2JTjh+7woPvbIj5UE90SLIW3T4 QL5A== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o12-20020a170902d4cc00b001b061af0599si4265292plg.340.2023.06.04.08.50.08; Sun, 04 Jun 2023 08:50:29 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231752AbjFDPYv (ORCPT + 99 others); Sun, 4 Jun 2023 11:24:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230354AbjFDPYh (ORCPT ); Sun, 4 Jun 2023 11:24:37 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6822D3; Sun, 4 Jun 2023 08:24:35 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id d5d90b075636b89b; Sun, 4 Jun 2023 17:24:34 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id EC066961C82; Sun, 4 Jun 2023 17:24:33 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Michal Wilczynski Subject: [RFT][PATCH v1 1/4] ACPI: button: Eliminate the driver notify callback Date: Sun, 04 Jun 2023 17:19:06 +0200 Message-ID: <2176493.Icojqenx9y@kreacher> In-Reply-To: <1847933.atdPhlSkOF@kreacher> References: <1847933.atdPhlSkOF@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeljedgkeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepfedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihgthhgrlhdrfihilhgtiiihnhhskhhisehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=3 Fuz1=3 Fuz2=3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767787807915536424?= X-GMAIL-MSGID: =?utf-8?q?1767787807915536424?= From: Rafael J. Wysocki Rework the ACPI button driver to install notify handlers or fixed event handlers for the devices it binds to by itself, reduce the indentation level in its notify handler routine and drop its notify callback. This will allow acpi_device_install_notify_handler() and acpi_device_remove_notify_handler() to be simplified going forward and it will allow the driver to use different notify handlers for the lid and for the power and sleep buttons. Signed-off-by: Rafael J. Wysocki Reviewed-by: Michal Wilczynski --- drivers/acpi/button.c | 140 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 96 insertions(+), 44 deletions(-) Index: linux-pm/drivers/acpi/button.c =================================================================== --- linux-pm.orig/drivers/acpi/button.c +++ linux-pm/drivers/acpi/button.c @@ -135,7 +135,6 @@ static const struct dmi_system_id dmi_li static int acpi_button_add(struct acpi_device *device); static void acpi_button_remove(struct acpi_device *device); -static void acpi_button_notify(struct acpi_device *device, u32 event); #ifdef CONFIG_PM_SLEEP static int acpi_button_suspend(struct device *dev); @@ -153,7 +152,6 @@ static struct acpi_driver acpi_button_dr .ops = { .add = acpi_button_add, .remove = acpi_button_remove, - .notify = acpi_button_notify, }, .drv.pm = &acpi_button_pm, }; @@ -409,45 +407,55 @@ static void acpi_lid_initialize_state(st button->lid_state_initialized = true; } -static void acpi_button_notify(struct acpi_device *device, u32 event) +static void acpi_button_notify(acpi_handle handle, u32 event, void *data) { - struct acpi_button *button = acpi_driver_data(device); + struct acpi_device *device = data; + struct acpi_button *button; struct input_dev *input; + int keycode; - switch (event) { - case ACPI_FIXED_HARDWARE_EVENT: - event = ACPI_BUTTON_NOTIFY_STATUS; - fallthrough; - case ACPI_BUTTON_NOTIFY_STATUS: - input = button->input; - if (button->type == ACPI_BUTTON_TYPE_LID) { - if (button->lid_state_initialized) - acpi_lid_update_state(device, true); - } else { - int keycode; - - acpi_pm_wakeup_event(&device->dev); - if (button->suspended) - break; - - keycode = test_bit(KEY_SLEEP, input->keybit) ? - KEY_SLEEP : KEY_POWER; - input_report_key(input, keycode, 1); - input_sync(input); - input_report_key(input, keycode, 0); - input_sync(input); - - acpi_bus_generate_netlink_event( - device->pnp.device_class, - dev_name(&device->dev), - event, ++button->pushed); - } - break; - default: + if (event != ACPI_BUTTON_NOTIFY_STATUS) { acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", event); - break; + return; + } + + button = acpi_driver_data(device); + + if (button->type == ACPI_BUTTON_TYPE_LID) { + if (button->lid_state_initialized) + acpi_lid_update_state(device, true); + + return; } + + acpi_pm_wakeup_event(&device->dev); + + if (button->suspended) + return; + + input = button->input; + keycode = test_bit(KEY_SLEEP, input->keybit) ? KEY_SLEEP : KEY_POWER; + + input_report_key(input, keycode, 1); + input_sync(input); + input_report_key(input, keycode, 0); + input_sync(input); + + acpi_bus_generate_netlink_event(device->pnp.device_class, + dev_name(&device->dev), + event, ++button->pushed); +} + +static void acpi_button_notify_run(void *data) +{ + acpi_button_notify(NULL, ACPI_BUTTON_NOTIFY_STATUS, data); +} + +static u32 acpi_button_event(void *data) +{ + acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_button_notify_run, data); + return ACPI_INTERRUPT_HANDLED; } #ifdef CONFIG_PM_SLEEP @@ -492,8 +500,9 @@ static int acpi_button_add(struct acpi_d struct acpi_button *button; struct input_dev *input; const char *hid = acpi_device_hid(device); + acpi_status status; char *name, *class; - int error; + int error = 0; if (!strcmp(hid, ACPI_BUTTON_HID_LID) && lid_init_state == ACPI_BUTTON_LID_INIT_DISABLED) @@ -535,12 +544,15 @@ static int acpi_button_add(struct acpi_d } else { pr_info("Unsupported hid [%s]\n", hid); error = -ENODEV; - goto err_free_input; } - error = acpi_button_add_fs(device); - if (error) - goto err_free_input; + if (!error) + error = acpi_button_add_fs(device); + + if (error) { + input_free_device(input); + goto err_free_button; + } snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid); @@ -568,6 +580,30 @@ static int acpi_button_add(struct acpi_d error = input_register_device(input); if (error) goto err_remove_fs; + + switch (device->device_type) { + case ACPI_BUS_TYPE_POWER_BUTTON: + status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, + acpi_button_event, + device); + break; + case ACPI_BUS_TYPE_SLEEP_BUTTON: + status = acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, + acpi_button_event, + device); + break; + default: + status = acpi_install_notify_handler(device->handle, + ACPI_DEVICE_NOTIFY, + acpi_button_notify, + device); + break; + } + if (ACPI_FAILURE(status)) { + error = -ENODEV; + goto err_input_unregister; + } + if (button->type == ACPI_BUTTON_TYPE_LID) { /* * This assumes there's only one lid device, or if there are @@ -580,11 +616,11 @@ static int acpi_button_add(struct acpi_d pr_info("%s [%s]\n", name, acpi_device_bid(device)); return 0; - err_remove_fs: +err_input_unregister: + input_unregister_device(input); +err_remove_fs: acpi_button_remove_fs(device); - err_free_input: - input_free_device(input); - err_free_button: +err_free_button: kfree(button); return error; } @@ -593,6 +629,22 @@ static void acpi_button_remove(struct ac { struct acpi_button *button = acpi_driver_data(device); + switch (device->device_type) { + case ACPI_BUS_TYPE_POWER_BUTTON: + acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, + acpi_button_event); + break; + case ACPI_BUS_TYPE_SLEEP_BUTTON: + acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, + acpi_button_event); + break; + default: + acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + acpi_button_notify); + break; + } + acpi_os_wait_events_complete(); + acpi_button_remove_fs(device); input_unregister_device(button->input); kfree(button); From patchwork Sun Jun 4 15:20:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 103032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2203674vqr; Sun, 4 Jun 2023 08:52:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5xGLLNGSIfP0BqJts8zkyiMnsGrIbMt2DbKKiVyEDH/R435GgSg4AtVKH3Hk3qVhUOKYq6 X-Received: by 2002:a05:6a00:3923:b0:64d:42f6:4c7b with SMTP id fh35-20020a056a00392300b0064d42f64c7bmr19888868pfb.27.1685893934644; Sun, 04 Jun 2023 08:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685893934; cv=none; d=google.com; s=arc-20160816; b=qWghV4YMnEMrXsaZwiIjP1UxVHKYogj0Ly6XdDF1pRN58h3cgcXgSSZwsJm7MfTUh7 73kSwwl9top+RrlEdDyNs3naljBF3EO1T9B4j+W0nPjM1gL1YZG14l0ClihTkectbwK1 W0sTckPTsc+LD8dc6dJO/MLzXiaryd7F3+mF0HxB01T8glVeXzpkeQKLWqriz6bZ2jz9 ymqJZFLF0YGD0q1jO2tgjZwCm4Ffm+aJs7Cyg7D4SgKj4hcgAS03TMSlLTrkS+pV2D82 k/01rsCtWilDOXst03EUoZVB0BTVi6PtLN2bHuBEMx+9ZpP+ssjD9EPu7KTvP2pr8SEj w0+Q== 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; bh=NyoA0AFM08aJvqotbodIilTobuZGxvdnJGGXGYA0BeA=; b=f3lHBtFP8nCm/gIoJtIiHe4kBo6eP5jL9mZdMraltR6CDEnwO7Q3ImqKyvCk7UoAyh s7vBal3r/Q2lnH6Y3B3K2ZBTM1Hw8t9BagqKd7kBki1yX2bOQIoA/5raaTUBkeD/gWGW yrosqs8Na9/mqHArUg6JXdwSpR0bvRIUjauAjhSkBGneLqj8Vpv7fV4nJmp0wCxyiWHd ks5ZAyKqH8Xz7Q7GTF2Yn4ylgeObz5CbeqHZDNVB0lqcXDqP3Yo8OygZ43MxPBEdiqu8 VlyGd18+I8kmKF8CW/PWsNdZSSLWEo4GwR4k/0csHQ40Dq4NgO56eA2JQIWRuvqZ4oSu 8Z0g== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y24-20020aa79438000000b0064f6a531c88si1858975pfo.323.2023.06.04.08.51.59; Sun, 04 Jun 2023 08:52:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231620AbjFDPYn (ORCPT + 99 others); Sun, 4 Jun 2023 11:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230005AbjFDPYg (ORCPT ); Sun, 4 Jun 2023 11:24:36 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 118FBD2; Sun, 4 Jun 2023 08:24:34 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id 80b17cd337c071f1; Sun, 4 Jun 2023 17:24:33 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 1D1C1961C82; Sun, 4 Jun 2023 17:24:33 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Michal Wilczynski Subject: [RFT][PATCH v1 2/4] ACPI: button: Use different notify handlers for lid and buttons Date: Sun, 04 Jun 2023 17:20:27 +0200 Message-ID: <2438693.jE0xQCEvom@kreacher> In-Reply-To: <1847933.atdPhlSkOF@kreacher> References: <1847933.atdPhlSkOF@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeljedgkeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepfedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihgthhgrlhdrfihilhgtiiihnhhskhhisehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=3 Fuz1=3 Fuz2=3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767787918486109928?= X-GMAIL-MSGID: =?utf-8?q?1767787918486109928?= From: Rafael J. Wysocki Since the lid handling in acpi_button_notify() is special, introduce acpi_lid_notify() specifically for handling lid notifications. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/button.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) Index: linux-pm/drivers/acpi/button.c =================================================================== --- linux-pm.orig/drivers/acpi/button.c +++ linux-pm/drivers/acpi/button.c @@ -407,12 +407,10 @@ static void acpi_lid_initialize_state(st button->lid_state_initialized = true; } -static void acpi_button_notify(acpi_handle handle, u32 event, void *data) +static void acpi_lid_notify(acpi_handle handle, u32 event, void *data) { struct acpi_device *device = data; struct acpi_button *button; - struct input_dev *input; - int keycode; if (event != ACPI_BUTTON_NOTIFY_STATUS) { acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", @@ -421,16 +419,28 @@ static void acpi_button_notify(acpi_hand } button = acpi_driver_data(device); + if (!button->lid_state_initialized) + return; - if (button->type == ACPI_BUTTON_TYPE_LID) { - if (button->lid_state_initialized) - acpi_lid_update_state(device, true); + acpi_lid_update_state(device, true); +} +static void acpi_button_notify(acpi_handle handle, u32 event, void *data) +{ + struct acpi_device *device = data; + struct acpi_button *button; + struct input_dev *input; + int keycode; + + if (event != ACPI_BUTTON_NOTIFY_STATUS) { + acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n", + event); return; } acpi_pm_wakeup_event(&device->dev); + button = acpi_driver_data(device); if (button->suspended) return; @@ -497,6 +507,7 @@ static int acpi_lid_input_open(struct in static int acpi_button_add(struct acpi_device *device) { + acpi_notify_handler handler; struct acpi_button *button; struct input_dev *input; const char *hid = acpi_device_hid(device); @@ -526,17 +537,20 @@ static int acpi_button_add(struct acpi_d if (!strcmp(hid, ACPI_BUTTON_HID_POWER) || !strcmp(hid, ACPI_BUTTON_HID_POWERF)) { button->type = ACPI_BUTTON_TYPE_POWER; + handler = acpi_button_notify; strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER); sprintf(class, "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); } else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) || !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) { button->type = ACPI_BUTTON_TYPE_SLEEP; + handler = acpi_button_notify; strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP); sprintf(class, "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); } else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) { button->type = ACPI_BUTTON_TYPE_LID; + handler = acpi_lid_notify; strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID); sprintf(class, "%s/%s", ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); @@ -594,8 +608,7 @@ static int acpi_button_add(struct acpi_d break; default: status = acpi_install_notify_handler(device->handle, - ACPI_DEVICE_NOTIFY, - acpi_button_notify, + ACPI_DEVICE_NOTIFY, handler, device); break; } @@ -640,7 +653,9 @@ static void acpi_button_remove(struct ac break; default: acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, - acpi_button_notify); + button->type == ACPI_BUTTON_TYPE_LID ? + acpi_lid_notify : + acpi_button_notify); break; } acpi_os_wait_events_complete(); From patchwork Sun Jun 4 15:22:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 103034 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2206482vqr; Sun, 4 Jun 2023 09:00:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ56Ivhwb1DIoS0rUE7rlMlB+CRM42r2WSLQS/a1FJtxGIlFS0ZOSRIcCmTxi/ir+1dLDWCc X-Received: by 2002:a17:903:18e:b0:1b0:6a99:cfe0 with SMTP id z14-20020a170903018e00b001b06a99cfe0mr5689333plg.17.1685894402061; Sun, 04 Jun 2023 09:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685894402; cv=none; d=google.com; s=arc-20160816; b=zYAO+AZOuQPITIDJlcmNaJe/w6TDJwPPS08H5WGquJ0ykEK2sRhJfOyC4a0l0OskVI bOvIQhJinMj6FfH43ee3rMJi8F9uEw6rjWbntD/cyRipdKAKZo9nxbH26Wy9oGx1w0iX SLzcoEp5Hv1prNEWwZvAzNvvHE74xMIcuPK6OHAIGkQuv2ot567HBY2VleJxuHBDiSnG 40mcph5i1YVbrEY8Y6VpWpGuOed3rjLjWquLL3xyPcIvuD+Au3gqel6yjlqrnoK1kaFL TtXSG50QenhrnkaWh+/7Oz1tCjqC7Kcef0RmdKM7aquI1juT0lLvW4nS640+RMq4RRKz Yuzw== 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; bh=2MGFo3nsIfI5B5K9GXzIUc6O8gs4zd/38b21mcn12MM=; b=nyxSmb/foew5xf1xc5tyPNUMObprzJ5owsBREgTJaMftRO/851xJoIa3m9zMejq8QQ D6OtHfDJsuxzFqp2GRqY+bVyvUmzFd3JTfdChlLMJwp8LfEo3ZsLu9Ao/5qbicfXNsFf CC9W37GVIxkvXLQAWig5sxV9App09vGvrFDRUZJZYc0N3p5dKL0b522MmpZ0+BG9nm5u 7lah7tL4jdtzBBgZDm3IOa2UR5sCIs/5gc4eY33M/tq+S97z4JnIZqgSqtDtEUGTu2Zk 9L7QmkwISt93NAwCqxgA3vCPoJpHB7MecIqY76kl65HvP2538a5Yag/twxfd5id7anGw tHjw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e12-20020a170902ed8c00b001ae5b59462asi4084975plj.309.2023.06.04.08.59.48; Sun, 04 Jun 2023 09:00:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230392AbjFDPYh (ORCPT + 99 others); Sun, 4 Jun 2023 11:24:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjFDPYf (ORCPT ); Sun, 4 Jun 2023 11:24:35 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63349CE; Sun, 4 Jun 2023 08:24:34 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id 4b94dd63f174b4c0; Sun, 4 Jun 2023 17:24:32 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 69A92961C82; Sun, 4 Jun 2023 17:24:32 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Michal Wilczynski , Josh Triplett , Hanjun Guo Subject: [RFT][PATCH v1 3/4] ACPI: tiny-power-button: Eliminate the driver notify callback Date: Sun, 04 Jun 2023 17:22:48 +0200 Message-ID: <5392458.Sb9uPGUboI@kreacher> In-Reply-To: <1847933.atdPhlSkOF@kreacher> References: <1847933.atdPhlSkOF@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeljedgkeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihgthhgrlhdrfihilhgtiiihnhhskhhisehinhhtvghlrdgtohhmpdhrtghpthhtohepjhhoshhhsehjohhshhhtrhhiphhlvghtthdrohhrghdprhgtphht thhopehguhhohhgrnhhjuhhnsehhuhgrfigvihdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767788408200162637?= X-GMAIL-MSGID: =?utf-8?q?1767788408200162637?= From: Rafael J. Wysocki Rework the ACPI tiny-power-button driver to install a notify handler or a fixed event handler for the device it binds to by itself and drop its notify callback. This will allow acpi_device_install_notify_handler() and acpi_device_remove_notify_handler() to be simplified going forward. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/tiny-power-button.c | 49 ++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) Index: linux-pm/drivers/acpi/tiny-power-button.c =================================================================== --- linux-pm.orig/drivers/acpi/tiny-power-button.c +++ linux-pm/drivers/acpi/tiny-power-button.c @@ -19,18 +19,52 @@ static const struct acpi_device_id tiny_ }; MODULE_DEVICE_TABLE(acpi, tiny_power_button_device_ids); -static int acpi_noop_add(struct acpi_device *device) +static void acpi_tiny_power_button_notify(acpi_handle handle, u32 event, void *data) { - return 0; + kill_cad_pid(power_signal, 1); } -static void acpi_noop_remove(struct acpi_device *device) +static void acpi_tiny_power_button_notify_run(void *not_used) { + acpi_tiny_power_button_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, NULL); } -static void acpi_tiny_power_button_notify(struct acpi_device *device, u32 event) +static u32 acpi_tiny_power_button_event(void *not_used) { - kill_cad_pid(power_signal, 1); + acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_tiny_power_button_notify_run, NULL); + return ACPI_INTERRUPT_HANDLED; +} + +static int acpi_tiny_power_button_add(struct acpi_device *device) +{ + acpi_status status; + + if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) { + status = acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, + acpi_tiny_power_button_event, + NULL); + } else { + status = acpi_install_notify_handler(device->handle, + ACPI_DEVICE_NOTIFY, + acpi_tiny_power_button_notify, + NULL); + } + if (ACPI_FAILURE(status)) + return -ENODEV; + + return 0; +} + +static void acpi_tiny_power_button_remove(struct acpi_device *device) +{ + if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) { + acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, + acpi_tiny_power_button_event); + } else { + acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY, + acpi_tiny_power_button_notify); + } + acpi_os_wait_events_complete(); } static struct acpi_driver acpi_tiny_power_button_driver = { @@ -38,9 +72,8 @@ static struct acpi_driver acpi_tiny_powe .class = "tiny-power-button", .ids = tiny_power_button_device_ids, .ops = { - .add = acpi_noop_add, - .remove = acpi_noop_remove, - .notify = acpi_tiny_power_button_notify, + .add = acpi_tiny_power_button_add, + .remove = acpi_tiny_power_button_remove, }, }; From patchwork Sun Jun 4 15:23:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 103031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2203462vqr; Sun, 4 Jun 2023 08:51:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Lu/A3gJo8GUTpIjs62rlfToyHK0LHeJOtfIlIdYtBoMQxr2CE2SXHS4Esqq5bTL7YZyeS X-Received: by 2002:a92:ddc4:0:b0:33d:504a:3058 with SMTP id d4-20020a92ddc4000000b0033d504a3058mr8674051ilr.18.1685893900865; Sun, 04 Jun 2023 08:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685893900; cv=none; d=google.com; s=arc-20160816; b=oPFXcV3zo37YAI0fxcwZ4sZ4LH4I+iv8+mAbShCLMLfbSIM3nkg6GfCG8rVJLKOfFT unZTkxXiSGtI0UZhKRjljGai7K2Wr4+oajqz76CrjBl1IxarlV0fhOGdGAx+m6uoooEB uQlcm3aEkzukoeVmhVDojMAPmMUZFhX2R3eTgcKpb25T5I9eKD+VTDsu0NubCAIjEmmB 0FgOyPfNUg2E9503fo1rZBfaBfI7BF56vJXx0bSGcchn6X51bk+03sCDbEkJAGJsCnsb LH9AKvtsN5QE7m2f+4x6WNjfbH8B6uKwch4ur6GljY4FgssuS/17yRIZsK17Uq6RZJ09 ytsQ== 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; bh=KXEC/MRgLGysulU0c0B21u2V4Dbdn3U3EXgsq7CwFRM=; b=CqIDbqOkiLSob9IZjsRlzJUpeIsZaso4e1V1ZTwu5qmeW2+M7x7gaTuFQsDUdOd18x JMcAJxDDz3SULeHq61aBqNCz9H3kP+dvj3XFTSp2bZ5G57i2hjf3t2gZXf2u+iayREm9 +wG5xsyzeggHVuQVR3VmZhlMdXJYpJ06FKi36gwJb7XCqvOCaTATKkLkLUTrj9IZf9xf 5YFiRB1FCYoSMfatOUFubMtRoGgn9yecbsMOp9buYdIEywfdUQOy4VOY7e1MaQQmVF8c 3kRlmSysuVQNooAaM//UMaO39y9szKcBl8gWwu8259Vn9pvsOn/reQECWCHesiOBZVYB xplQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a63eb45000000b005289dd0ef00si2435562pgk.568.2023.06.04.08.51.26; Sun, 04 Jun 2023 08:51:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231316AbjFDPYl (ORCPT + 99 others); Sun, 4 Jun 2023 11:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229569AbjFDPYf (ORCPT ); Sun, 4 Jun 2023 11:24:35 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 632CBCD; Sun, 4 Jun 2023 08:24:34 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id 08b175b11797ce0d; Sun, 4 Jun 2023 17:24:32 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id B326F961C82; Sun, 4 Jun 2023 17:24:31 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Michal Wilczynski Subject: [RFT][PATCH v1 4/4] ACPI: bus: Simplify installation and removal of notify callback Date: Sun, 04 Jun 2023 17:23:40 +0200 Message-ID: <2130740.OBFZWjSADL@kreacher> In-Reply-To: <1847933.atdPhlSkOF@kreacher> References: <1847933.atdPhlSkOF@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeljedgkeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepfedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihgthhgrlhdrfihilhgtiiihnhhskhhisehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=3 Fuz1=3 Fuz2=3 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767787883216980873?= X-GMAIL-MSGID: =?utf-8?q?1767787883216980873?= From: Rafael J. Wysocki Because the only drivers that cared about button fixed events take care of those events by themselves now, eliminate the code related to them from acpi_device_install_notify_handler() and acpi_device_remove_notify_handler(). Signed-off-by: Rafael J. Wysocki --- drivers/acpi/bus.c | 53 +++++++++-------------------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) Index: linux-pm/drivers/acpi/bus.c =================================================================== --- linux-pm.orig/drivers/acpi/bus.c +++ linux-pm/drivers/acpi/bus.c @@ -530,65 +530,30 @@ static void acpi_notify_device(acpi_hand acpi_drv->ops.notify(device, event); } -static void acpi_notify_device_fixed(void *data) -{ - struct acpi_device *device = data; - - /* Fixed hardware devices have no handles */ - acpi_notify_device(NULL, ACPI_FIXED_HARDWARE_EVENT, device); -} - -static u32 acpi_device_fixed_event(void *data) -{ - acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_notify_device_fixed, data); - return ACPI_INTERRUPT_HANDLED; -} - static int acpi_device_install_notify_handler(struct acpi_device *device, struct acpi_driver *acpi_drv) { - acpi_status status; - - if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) { - status = - acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, - acpi_device_fixed_event, - device); - } else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) { - status = - acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, - acpi_device_fixed_event, - device); - } else { - u32 type = acpi_drv->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS ? + u32 type = acpi_drv->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS ? ACPI_ALL_NOTIFY : ACPI_DEVICE_NOTIFY; + acpi_status status; - status = acpi_install_notify_handler(device->handle, type, - acpi_notify_device, - device); - } - + status = acpi_install_notify_handler(device->handle, type, + acpi_notify_device, device); if (ACPI_FAILURE(status)) return -EINVAL; + return 0; } static void acpi_device_remove_notify_handler(struct acpi_device *device, struct acpi_driver *acpi_drv) { - if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON) { - acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, - acpi_device_fixed_event); - } else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON) { - acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, - acpi_device_fixed_event); - } else { - u32 type = acpi_drv->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS ? + u32 type = acpi_drv->flags & ACPI_DRIVER_ALL_NOTIFY_EVENTS ? ACPI_ALL_NOTIFY : ACPI_DEVICE_NOTIFY; - acpi_remove_notify_handler(device->handle, type, - acpi_notify_device); - } + acpi_remove_notify_handler(device->handle, type, + acpi_notify_device); + acpi_os_wait_events_complete(); }