From patchwork Fri Sep 20 16:02:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayman Bagabas X-Patchwork-Id: 11154639 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 7205416B1 for ; Fri, 20 Sep 2019 16:04:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 437B5206B6 for ; Fri, 20 Sep 2019 16:04:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qmCFDsvO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388810AbfITQE1 (ORCPT ); Fri, 20 Sep 2019 12:04:27 -0400 Received: from mail-yb1-f194.google.com ([209.85.219.194]:35716 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387662AbfITQE1 (ORCPT ); Fri, 20 Sep 2019 12:04:27 -0400 Received: by mail-yb1-f194.google.com with SMTP id b128so2828313ybh.2; Fri, 20 Sep 2019 09:04:26 -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=medjA5JOhuw+KXtE21Z9wSEAHcoK7CM97EXuoE1ZTMk=; b=qmCFDsvOe/YgB+NGjcoewLJKldrjcEn2rXJ75aqtzkNrNfTkfVKuTLzdAQxunKHyXG 1Lx/1ohULnzmjrtoVF/AmLNCECLJSXFTVfahFr7+AQSvid3JcsXgDVCNHnpilZIJvR79 EEqalIiXSJif2RCgkpr7jn5gejTkqgIzZSIjbCujmI6ZjN2zTCJkUy2j/QZWI20/Rn2P JlCsHSytzlePCQc+tk/leX4MS/qbh/zKjHT62kbxBlz6dc+0m56XGpsWDBuAjRRMmGI7 2qjKDJszIY+HrSfoC5UcO/jLss7Z/0JwH0GnrqJH4VF1bOV70KbrbG+C5JqNM7LF5uDR jbPQ== 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=medjA5JOhuw+KXtE21Z9wSEAHcoK7CM97EXuoE1ZTMk=; b=DoiR7sY+py6T6EayXjf+tES9+y8XFszjmGIWcsVS4sm65QZsufqgl2C0ZSq61z8oRC VS/uLIMz/in9UjzgeX1Khcc3AMVVh9ONs/MT9VEs786XvEi8FA4dG//LPcln+SlykME5 xUZqklv9ldgIcXiuMjtM09WLnB2FN0aKml6icZPDLNBKLEdMbjs/CHftqpNpDYEdmZTv JSBL7bIyhvDa47H7krDkx4rCp50rEH+5gcmpw3V7BPZJFf3Mrex1wFL4rvLG3S1/9L6E 0tpYhxJlKM1J5+ng8lfoCYCXQeqNSnUDzLmxVq2SSRgNnIEjs+2h4ecwSYPup7/XnekI A2qw== X-Gm-Message-State: APjAAAXtdHZdo99a2JSeJiCn932BHe3DZw+NqM9UIKnaqSduzDtVMHoV NdQivcYRXE9xGPoiVB6rbQ== X-Google-Smtp-Source: APXvYqxlS66AQHJOgZy8g1lRD1J9PxCvfi3Ck8LLWIhdVAWblCpttWFegVV0sYSwTJJEAH2mE9HPeg== X-Received: by 2002:a25:42cf:: with SMTP id p198mr1761945yba.147.1568995466140; Fri, 20 Sep 2019 09:04:26 -0700 (PDT) Received: from localhost.localdomain ([12.156.111.130]) by smtp.gmail.com with ESMTPSA id 207sm518086ywu.106.2019.09.20.09.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 09:04:25 -0700 (PDT) From: Ayman Bagabas To: Darren Hart , Andy Shevchenko , Mauro Carvalho Chehab , Sinan Kaya , "Rafael J. Wysocki" , Takashi Iwai , Ayman Bagabas , Stuart Hayes , Matan Ziv-Av , "Enrico Weigelt, metux IT consult" , 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 v4 6/6] platform/x86: huawei-wmi: Add debugfs support Date: Fri, 20 Sep 2019 12:02:39 -0400 Message-Id: <20190920160250.12510-7-ayman.bagabas@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190920160250.12510-1-ayman.bagabas@gmail.com> References: <20190920160250.12510-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 Add a debugfs interface that can be used to call the WMI management interface function if available. Signed-off-by: Ayman Bagabas --- drivers/platform/x86/huawei-wmi.c | 97 +++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 56697d49377d..5efb8d1bbda7 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -52,10 +53,16 @@ struct quirk_entry { static struct quirk_entry *quirks; +struct huawei_wmi_debug { + struct dentry *root; + u64 arg; +}; + struct huawei_wmi { bool battery_available; bool fn_lock_available; + struct huawei_wmi_debug debug; struct input_dev *idev[2]; struct led_classdev cdev; struct platform_device *pdev; @@ -592,6 +599,94 @@ static void huawei_wmi_fn_lock_exit(struct device *dev) device_remove_file(dev, &dev_attr_fn_lock_state); } +/* debugfs */ + +static void huawei_wmi_debugfs_call_dump(struct seq_file *m, void *data, + union acpi_object *obj) +{ + struct huawei_wmi *huawei = m->private; + int i; + + switch (obj->type) { + case ACPI_TYPE_INTEGER: + seq_printf(m, "0x%llx", obj->integer.value); + break; + case ACPI_TYPE_STRING: + seq_printf(m, "\"%*s\"", obj->string.length, obj->string.pointer); + break; + case ACPI_TYPE_BUFFER: + seq_puts(m, "{"); + for (i = 0; i < obj->buffer.length; i++) { + seq_printf(m, "0x%02x", obj->buffer.pointer[i]); + if (i < obj->buffer.length - 1) + seq_puts(m, ","); + } + seq_puts(m, "}"); + break; + case ACPI_TYPE_PACKAGE: + seq_puts(m, "["); + for (i = 0; i < obj->package.count; i++) { + huawei_wmi_debugfs_call_dump(m, huawei, &obj->package.elements[i]); + if (i < obj->package.count - 1) + seq_puts(m, ","); + } + seq_puts(m, "]"); + break; + default: + dev_err(&huawei->pdev->dev, "Unexpected obj type, got %d\n", obj->type); + return; + } +} + +static int huawei_wmi_debugfs_call_show(struct seq_file *m, void *data) +{ + struct huawei_wmi *huawei = m->private; + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer in; + union acpi_object *obj; + int err; + + in.length = sizeof(u64); + in.pointer = &huawei->debug.arg; + + err = huawei_wmi_call(&in, &out); + if (err) + return err; + + obj = out.pointer; + if (!obj) { + err = -EIO; + goto fail_debugfs_call; + } + + huawei_wmi_debugfs_call_dump(m, huawei, obj); + +fail_debugfs_call: + kfree(out.pointer); + return err; +} + +DEFINE_SHOW_ATTRIBUTE(huawei_wmi_debugfs_call); + +static void huawei_wmi_debugfs_setup(struct device *dev) +{ + struct huawei_wmi *huawei = dev_get_drvdata(dev); + + huawei->debug.root = debugfs_create_dir("huawei-wmi", NULL); + + debugfs_create_x64("arg", 0644, huawei->debug.root, + &huawei->debug.arg); + debugfs_create_file("call", 0400, + huawei->debug.root, huawei, &huawei_wmi_debugfs_call_fops); +} + +static void huawei_wmi_debugfs_exit(struct device *dev) +{ + struct huawei_wmi *huawei = dev_get_drvdata(dev); + + debugfs_remove_recursive(huawei->debug.root); +} + /* Input */ static void huawei_wmi_process_key(struct input_dev *idev, int code) @@ -717,6 +812,7 @@ static int huawei_wmi_probe(struct platform_device *pdev) huawei_wmi_leds_setup(&pdev->dev); huawei_wmi_fn_lock_setup(&pdev->dev); huawei_wmi_battery_setup(&pdev->dev); + huawei_wmi_debugfs_setup(&pdev->dev); } return 0; @@ -734,6 +830,7 @@ static int huawei_wmi_remove(struct platform_device *pdev) } if (wmi_has_guid(HWMI_METHOD_GUID)) { + huawei_wmi_debugfs_exit(&pdev->dev); huawei_wmi_battery_exit(&pdev->dev); huawei_wmi_fn_lock_exit(&pdev->dev); }