Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp490180rwb; Sat, 13 Aug 2022 02:29:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DOYrAAezfTJPxPxKzcJgZGmu369i7rUKKl3EqY66aWCqGaILG+wQLFc3zC2l8zzvLiO0H X-Received: by 2002:a17:90b:1241:b0:1f3:1d9f:a933 with SMTP id gx1-20020a17090b124100b001f31d9fa933mr8049786pjb.221.1660382960146; Sat, 13 Aug 2022 02:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660382960; cv=none; d=google.com; s=arc-20160816; b=ohfrU4XC9dafL4Dmw6T1fb2b3EXumiGnU6AvDIwS74JVnD56RyU2fbREijWiMpiXBF 3uXo0SputihX5k4FVl8L/4MJIXkVvWWnWy0EqEUiN6bY+tk3P/2zXL7HmR1xptfN100k evMVaOGlaF5spWbuVzvAr8iYKNJU2FbXTYXIshAdkIuHDTf97zfw98zMzCfkIXBIGXIZ oWxKcd65cAAg9xe+zdOou+CNxCRhhOwBFHOeXs+Qri36DleWZux8yM+bxm4juZffec3Y SPK07awcj3fjUhqrs5mxg7Z0kHBez1eH92OdepTzDmKtQI4A0RcTHJC20iifwQYzX8If Zd9g== 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 :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=h5K4EsOSrhyEgm18Wb3+Rh+Lb0Fv4BWADs+AkbfAd+g=; b=se1JY87YwBLAO2fq8cA5YG2u7Kt401VcCWYW/AyMV9vWdUbv9ZKk5s7eOL0GnzzRb0 gnXKjdpujyr5rCJoYVoIHB4kTherf/WUqtQs7IxDmR21XTE/AMX3FP9nNLMxQqPuD3wo dYOLRUQx54mILBhpyLmjrBfjznPW8wwPvXyCn6JwPDnKbLfhkISwexCSQjFSM8f0nTyY 4e2ryg9fZDrFsMxfBeJONUT2COCyJHWP+pJkhuvDIhtLPKaFYyGi9RCMurnK8jsKnm5L LSqRGR/zgSkaQdKHkhIa3wIOXwBBuPbYL+c6VMCKdkaw5u5v6q3qMcDb2Mba86BQfFpF OS9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ljones.dev header.s=fm2 header.b=ar2UrWeE; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=5AOxtlXs; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d22-20020a63fd16000000b0040dbc216491si5351578pgh.823.2022.08.13.02.29.09; Sat, 13 Aug 2022 02:29:20 -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=@ljones.dev header.s=fm2 header.b=ar2UrWeE; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=5AOxtlXs; 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 S238792AbiHMJ2M (ORCPT + 99 others); Sat, 13 Aug 2022 05:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiHMJ2K (ORCPT ); Sat, 13 Aug 2022 05:28:10 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9CA32A437; Sat, 13 Aug 2022 02:28:08 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id F2FC032008FF; Sat, 13 Aug 2022 05:28:07 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 13 Aug 2022 05:28:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm2; t=1660382887; x=1660469287; bh=h5K4EsOSrhyEgm18Wb3+Rh+Lb 0Fv4BWADs+AkbfAd+g=; b=ar2UrWeErRcBptso98LxB/4MniI6bA9p7mORSGC7I KZQLBOic4UevEyQ7IQyQddFP5Vw3Q3PtMQtjyUCo7I0vHtAHOdgsOPM6txVC8kzj 0Vt2Lnj5Nir+xYfIyb6SM7DOrKWFzer7gRl/plUl/UCwXFhDVObZILyXGJvo1zbV 1BKWGsuyKweaDEWoDBcRvSY9zXfRSBfFZIivl4ERybgJPQ8WC0wya+c9WN4lXRWI If0iuKf0GhbW2ywaWfQ4zTOKHGS47q5bWAnfZUQ8YPuKCo8Ej0mWH9r6xEpPCqLg Q8xln2o3KA7QOM0CFL3fy9csZlGx8gvsgl3fy+cV4NXpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1660382887; x=1660469287; bh=h5K4EsOSrhyEgm18Wb3+Rh+Lb0Fv4BWADs+ AkbfAd+g=; b=5AOxtlXs6VFCyBMpfdmxfpk5AeO1oQJpNJMOPu4hd8rIO6jA4nj sDxcsNX+RmfCDlM9dnSV+eJN3u7fhq7Jv3Kh0m1sV93l+D+AfZRVctiEkPyUzzN7 4UTInBqrVmI+4Ty0gzD2rH3Og6MMT2kowtqGsehbzzDqZAin7LDnu7bqnMmeD2TL Ayigoy8vn6CLeIvT7H8sGL124iG5fnLH94V7jRsgiH5D/DALM8+fbtvPP5JD1w94 y1hU95hY6h6LE+DzFcW8ksIsD459UD5B1yUADXaM5WPTyNmXCPXoQURkms3rpYaP gvbULsdxpbY1V2w6RxBE8ecSbh3kk/LHhoQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegkedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehljhho nhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfdujedthfduudekffefkeeiffdttd dvhfegudduueffuefhfefggeefteevvdegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 13 Aug 2022 05:28:03 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: markgross@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 1/2] asus-wmi: Adjust tablet/lidflip handling to use enum Date: Sat, 13 Aug 2022 21:27:52 +1200 Message-Id: <20220813092753.6635-1-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_NONE,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 Due to multiple types of tablet/lidflip, the existing code for handling these events is refactored to use an enum for each type. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-nb-wmi.c | 13 +++--- drivers/platform/x86/asus-wmi.c | 67 ++++++++++++++++++++---------- drivers/platform/x86/asus-wmi.h | 9 +++- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c index a81dc4b191b7..3a93e056c4e1 100644 --- a/drivers/platform/x86/asus-nb-wmi.c +++ b/drivers/platform/x86/asus-nb-wmi.c @@ -115,12 +115,12 @@ static struct quirk_entry quirk_asus_forceals = { }; static struct quirk_entry quirk_asus_use_kbd_dock_devid = { - .use_kbd_dock_devid = true, + .tablet_switch_mode = asus_wmi_kbd_dock_devid, }; static struct quirk_entry quirk_asus_use_lid_flip_devid = { .wmi_backlight_set_devstate = true, - .use_lid_flip_devid = true, + .tablet_switch_mode = asus_wmi_lid_flip_devid, }; static int dmi_matched(const struct dmi_system_id *dmi) @@ -492,16 +492,13 @@ static void asus_nb_wmi_quirks(struct asus_wmi_driver *driver) switch (tablet_mode_sw) { case 0: - quirks->use_kbd_dock_devid = false; - quirks->use_lid_flip_devid = false; + quirks->tablet_switch_mode = asus_wmi_no_tablet_switch; break; case 1: - quirks->use_kbd_dock_devid = true; - quirks->use_lid_flip_devid = false; + quirks->tablet_switch_mode = asus_wmi_kbd_dock_devid; break; case 2: - quirks->use_kbd_dock_devid = false; - quirks->use_lid_flip_devid = true; + quirks->tablet_switch_mode = asus_wmi_lid_flip_devid; break; } diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 0421ffb81927..b4690ac39147 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -485,8 +485,11 @@ static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id) static int asus_wmi_input_init(struct asus_wmi *asus) { + struct device *dev; int err, result; + dev = &asus->platform_device->dev; + asus->inputdev = input_allocate_device(); if (!asus->inputdev) return -ENOMEM; @@ -494,35 +497,38 @@ static int asus_wmi_input_init(struct asus_wmi *asus) asus->inputdev->name = asus->driver->input_name; asus->inputdev->phys = asus->driver->input_phys; asus->inputdev->id.bustype = BUS_HOST; - asus->inputdev->dev.parent = &asus->platform_device->dev; + asus->inputdev->dev.parent = dev; set_bit(EV_REP, asus->inputdev->evbit); err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL); if (err) goto err_free_dev; - if (asus->driver->quirks->use_kbd_dock_devid) { + switch (asus->driver->quirks->tablet_switch_mode) { + case asus_wmi_no_tablet_switch: + break; + case asus_wmi_kbd_dock_devid: result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_DOCK); if (result >= 0) { input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE); input_report_switch(asus->inputdev, SW_TABLET_MODE, !result); } else if (result != -ENODEV) { - pr_err("Error checking for keyboard-dock: %d\n", result); + dev_err(dev, "Error checking for keyboard-dock: %d\n", result); } - } - - if (asus->driver->quirks->use_lid_flip_devid) { + break; + case asus_wmi_lid_flip_devid: result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_LID_FLIP); if (result < 0) - asus->driver->quirks->use_lid_flip_devid = 0; + asus->driver->quirks->tablet_switch_mode = asus_wmi_no_tablet_switch; if (result >= 0) { input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE); input_report_switch(asus->inputdev, SW_TABLET_MODE, result); } else if (result == -ENODEV) { - pr_err("This device has lid_flip quirk but got ENODEV checking it. This is a bug."); + dev_err(dev, "This device has lid_flip quirk but got ENODEV checking it. This is a bug."); } else { - pr_err("Error checking for lid-flip: %d\n", result); + dev_err(dev, "Error checking for lid-flip: %d\n", result); } + break; } err = input_register_device(asus->inputdev); @@ -548,8 +554,9 @@ static void asus_wmi_input_exit(struct asus_wmi *asus) static void lid_flip_tablet_mode_get_state(struct asus_wmi *asus) { - int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_LID_FLIP); + int result; + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_LID_FLIP); if (result >= 0) { input_report_switch(asus->inputdev, SW_TABLET_MODE, result); input_sync(asus->inputdev); @@ -3044,20 +3051,26 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) return; } - if (asus->driver->quirks->use_kbd_dock_devid && code == NOTIFY_KBD_DOCK_CHANGE) { - result = asus_wmi_get_devstate_simple(asus, - ASUS_WMI_DEVID_KBD_DOCK); + switch (asus->driver->quirks->tablet_switch_mode) { + case asus_wmi_no_tablet_switch: + break; + case asus_wmi_kbd_dock_devid: + if (code == NOTIFY_KBD_DOCK_CHANGE) { + result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_KBD_DOCK); if (result >= 0) { input_report_switch(asus->inputdev, SW_TABLET_MODE, - !result); + !result); input_sync(asus->inputdev); } return; - } - - if (asus->driver->quirks->use_lid_flip_devid && code == NOTIFY_LID_FLIP) { - lid_flip_tablet_mode_get_state(asus); - return; + } + break; + case asus_wmi_lid_flip_devid: + if (code == NOTIFY_LID_FLIP) { + lid_flip_tablet_mode_get_state(asus); + return; + } + break; } if (asus->fan_boost_mode_available && code == NOTIFY_KBD_FBM) { @@ -3700,8 +3713,14 @@ static int asus_hotk_resume(struct device *device) if (asus_wmi_has_fnlock_key(asus)) asus_wmi_fnlock_update(asus); - if (asus->driver->quirks->use_lid_flip_devid) + switch (asus->driver->quirks->tablet_switch_mode) { + case asus_wmi_no_tablet_switch: + case asus_wmi_kbd_dock_devid: + break; + case asus_wmi_lid_flip_devid: lid_flip_tablet_mode_get_state(asus); + break; + } return 0; } @@ -3742,8 +3761,14 @@ static int asus_hotk_restore(struct device *device) if (asus_wmi_has_fnlock_key(asus)) asus_wmi_fnlock_update(asus); - if (asus->driver->quirks->use_lid_flip_devid) + switch (asus->driver->quirks->tablet_switch_mode) { + case asus_wmi_no_tablet_switch: + case asus_wmi_kbd_dock_devid: + break; + case asus_wmi_lid_flip_devid: lid_flip_tablet_mode_get_state(asus); + break; + } return 0; } diff --git a/drivers/platform/x86/asus-wmi.h b/drivers/platform/x86/asus-wmi.h index b302415bf1d9..413920bad0c6 100644 --- a/drivers/platform/x86/asus-wmi.h +++ b/drivers/platform/x86/asus-wmi.h @@ -25,6 +25,12 @@ struct module; struct key_entry; struct asus_wmi; +enum asus_wmi_tablet_switch_mode { + asus_wmi_no_tablet_switch, + asus_wmi_kbd_dock_devid, + asus_wmi_lid_flip_devid, +}; + struct quirk_entry { bool hotplug_wireless; bool scalar_panel_brightness; @@ -33,8 +39,7 @@ struct quirk_entry { bool wmi_backlight_native; bool wmi_backlight_set_devstate; bool wmi_force_als_set; - bool use_kbd_dock_devid; - bool use_lid_flip_devid; + enum asus_wmi_tablet_switch_mode tablet_switch_mode; int wapf; /* * For machines with AMD graphic chips, it will send out WMI event -- 2.37.1