From patchwork Tue Sep 24 02:48:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11157879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F34ED13B1 for ; Tue, 24 Sep 2019 02:48:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C766D20882 for ; Tue, 24 Sep 2019 02:48:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N0VkslEZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389572AbfIXCs6 (ORCPT ); Mon, 23 Sep 2019 22:48:58 -0400 Received: from mail-vk1-f195.google.com ([209.85.221.195]:44654 "EHLO mail-vk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729357AbfIXCs6 (ORCPT ); Mon, 23 Sep 2019 22:48:58 -0400 Received: by mail-vk1-f195.google.com with SMTP id j21so89899vki.11; Mon, 23 Sep 2019 19:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=mDRWgzAX5BzQRDnjOLDKf4M+7Qn9M6zsk32ycuv6xH4=; b=N0VkslEZkvlZ7XKxe5H5llyUaQGvL8nIS8guUP+jULM5VMdrj7GYcoQPHfLY4xkQgM J/c3iEGNEVgiw+ox0H9n+Lr+gELUuNZD8PpwCcZNrS/liP3Aod0QGCRcfd7Wq5lNhjod QZ3Et/qtO0mThdak+gx4WKyX6FhSj15vPF23EmzSfJDvYXZs/glzFlGBsz4NPulyY07m theDI6Yk8nS8Bzp58AnJeSdQ7i2Iic7RryUV9pYvPk1Yc+d9ABzG1WyiyVMbWm0bhsxD L4eMQ9RIpNwlnqkZTuFijES/dCADbrftP+OkWUYUZ/h6HiQF6KsvJk0H1oa8oZEZrLrL NjVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mDRWgzAX5BzQRDnjOLDKf4M+7Qn9M6zsk32ycuv6xH4=; b=fV9qstJFoXQKGJxU1C6TUToDQgbWH1yd+tolzYa9LjOkCRQ9X7FdOoBdu7UKMYW81r kyZKb1u4enH4AOMgaBKeRIqZe1GXKBxHhVok4c9+3CEN35hOc7g+eaqj/5ghiIfgjfm4 cRCBRP6obuxwGmHrOP+ewjlHT7QetqTtdGUfWY28mRMn3v1THEg+3jyP87yghCqPZghS 56tkKWQRyxKezWMdXhC4qgyP4HF79Unw0+Kle9emP/Qb6UkQpiLQBnoGSeAQJCo6NrRO 2FZVVvSXJ/SvA+ECpW1mkjs2uHFCJLUazMcalGT1zDubzYUKI2a+c90cT3//yyKInA4d cd/Q== X-Gm-Message-State: APjAAAWc96c6ZNwgbgUVPXcvS/UFzqaAI2ITr7swIxl4rwzyNF28xIf0 EARoQ42JlbdBLKeTIXWg7Q== X-Google-Smtp-Source: APXvYqyKpLBVRgvTXjDX9Gj1rdYlV6N0LT11EdMkMnZdKhZ8jC2DXsW/kKharKP8PkjHlXPD5yT7Jg== X-Received: by 2002:a1f:b987:: with SMTP id j129mr393905vkf.27.1569293336411; Mon, 23 Sep 2019 19:48:56 -0700 (PDT) Received: from localhost.localdomain ([2601:901:202:18cc:820:670:dd1:f572]) by smtp.gmail.com with ESMTPSA id o16sm46547uar.2.2019.09.23.19.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2019 19:48:55 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , Mauro Carvalho Chehab , "Rafael J. Wysocki" , Sinan Kaya , Takashi Iwai , Ayman Bagabas , Stuart Hayes , Matan Ziv-Av , Hans de Goede , Peng Hao , Krzysztof Kozlowski , Mattias Jacobsson <2pi@mok.nu>, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/6] platform/x86: huawei-wmi: Add quirks and module parameters Date: Mon, 23 Sep 2019 22:48:07 -0400 Message-Id: <20190924024821.497-3-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190924024821.497-1-ayman.bagabas@gmail.com> References: <20190924024821.497-1-ayman.bagabas@gmail.com> MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Introduce quirks and module parameters. 3 quirks are added: 1. Fixes reporting brightness keys twice since it's already handled by acpi-video. 2. Some models need a short delay when setting battery thresholds to prevent a race condition when two processes read/write. (will be used later) 3. Matebook X (2017) handles micmute led through the "legacy" interface which is not currently implemented. Use ACPI EC method to control this led. (will be used later) 2 module parameters are added to enable this short delay and/or report brightness keys through this driver. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 9496ea3c78b5..0e919bf56ad1 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -22,6 +23,14 @@ #define WMI0_EXPENSIVE_GUID "39142400-C6A3-40fa-BADB-8A2652834100" #define WMI0_EVENT_GUID "59142400-C6A3-40fa-BADB-8A2652834100" +struct quirk_entry { + bool battery_reset; + bool ec_micmute; + bool report_brightness; +}; + +static struct quirk_entry *quirks; + struct huawei_wmi { struct input_dev *idev[2]; struct led_classdev cdev; @@ -49,6 +58,58 @@ static const struct key_entry huawei_wmi_keymap[] = { { KE_END, 0 } }; +static int battery_reset = -1; +static int report_brightness = -1; + +module_param(battery_reset, bint, 0444); +MODULE_PARM_DESC(battery_reset, + "Reset battery charge values to (0-0) before disabling it using (0-100)"); +module_param(report_brightness, bint, 0444); +MODULE_PARM_DESC(report_brightness, + "Report brightness keys."); + +/* Quirks */ + +static int __init dmi_matched(const struct dmi_system_id *dmi) +{ + quirks = dmi->driver_data; + return 1; +} + +static struct quirk_entry quirk_unknown = { +}; + +static struct quirk_entry quirk_battery_reset = { + .battery_reset = true, +}; + +static struct quirk_entry quirk_matebook_x = { + .ec_micmute = true, + .report_brightness = true, +}; + +static const struct dmi_system_id huawei_quirks[] = { + { + .callback = dmi_matched, + .ident = "Huawei MACH-WX9", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HUAWEI"), + DMI_MATCH(DMI_PRODUCT_NAME, "MACH-WX9"), + }, + .driver_data = &quirk_battery_reset + }, + { + .callback = dmi_matched, + .ident = "Huawei MateBook X", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HUAWEI"), + DMI_MATCH(DMI_PRODUCT_NAME, "HUAWEI MateBook X") + }, + .driver_data = &quirk_matebook_x + }, + { } +}; + static int huawei_wmi_micmute_led_set(struct led_classdev *led_cdev, enum led_brightness brightness) { @@ -139,6 +200,11 @@ static void huawei_wmi_process_key(struct input_dev *idev, int code) return; } + if (quirks && !quirks->report_brightness && + (key->sw.code == KEY_BRIGHTNESSDOWN || + key->sw.code == KEY_BRIGHTNESSUP)) + return; + sparse_keymap_report_entry(idev, key, 1, true); } @@ -253,6 +319,13 @@ static __init int huawei_wmi_init(void) if (!huawei_wmi) return -ENOMEM; + quirks = &quirk_unknown; + dmi_check_system(huawei_quirks); + if (battery_reset != -1) + quirks->battery_reset = battery_reset; + if (report_brightness != -1) + quirks->report_brightness = report_brightness; + err = platform_driver_register(&huawei_wmi_driver); if (err) goto pdrv_err;