From patchwork Thu Nov 17 23:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13047493 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 8F3BBC43217 for ; Thu, 17 Nov 2022 23:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234932AbiKQXtL (ORCPT ); Thu, 17 Nov 2022 18:49:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234724AbiKQXtJ (ORCPT ); Thu, 17 Nov 2022 18:49:09 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3C22DEEA for ; Thu, 17 Nov 2022 15:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668728938; bh=UzfN/nVAKX/EZyeVXEzUh4NnnpwMKQ3fygNjZ2yLwEU=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=N8GIF5Dpll2LdmqVkUvgEqOweGVpSN0yYm6b4zCEYgfwyj9yHRiitFeDHpnOW4YQX afystvtLH5eY1ULIGg+wY4IQdimiChQkdxmPSu3baBwQycdwHLeKUhTwvb9BxGkyUK 2EfAcFuHqWj2d3IMMBT0xblG7Fe2mgrOfboyKdSmNKvn1T6a28dlwCFUfJYHXVfInb zSQ4WDONtMEaWb+oaDqADKlfmTVMSDAiJ2S97sQnGY1egriVD7CvHTQC8UJgom+CVg 3YkJtM5eX2BInJW6lCr1aL4Sf+I92x/HKAbDWj3NEcDlN09eiwzhdZSXSCVRLutBFr 1olkyjqN37eEg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.45.31]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MEFvj-1omEN246sP-00ABvA; Fri, 18 Nov 2022 00:48:58 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH v3 1/4] HID: hid-sensor-custom: Allow more custom iio sensors Date: Fri, 18 Nov 2022 00:48:21 +0100 Message-Id: <20221117234824.6227-1-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117150508.00002704@Huawei.com> References: <20221117150508.00002704@Huawei.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:MkV0adkBqD82yx49c3Ts4LXGqBXULZKDpxDqBnLpp4IEVmCTh3e BJvLg0RiGRrTVZJ8VEqAUf9bOm/K2ex8ABBtOjTqkyhXeaX/7RnWnEHKETTuNDOQlItNYwh xzq4F7hbp4zXI5axCO8Gsvrx6+TFpXrKCVqkCl+3F/91SO6MBCHchRIdPljUpaQmkZLcg6h biqVERzhTWUexz7q8dejg== UI-OutboundReport: notjunk:1;M01:P0:OU8vI4Ca/RY=;zBzr99mNjjIdNwVXiFAkDewvRLG /96x6IyG8oxw+qzw2N9rwuJF2FqeKT82KSdwJOqLkpb2dI9sFHd1Lg5j0At00crOWIKqyCTqo 5B5ASwRk4LPX6OuK7XM5hjGgufKB5Jg655+Sa8WlkYiKi0Ne6CYdFEYSizCgWRQT3w4xLhd+u XRveiQwBZ8JP1x6bgbGTL5Ebm4CN+ExAA4kXcvxxLlgNloreBN8CbCCH3mQNxk5VSKg03nwQv 82r7NkGjZ6KqQekKmmbAmGzKZYsmPLYtss6O0meupSEbxQxr/ji8ewEIpn5gabPXDVxqbRKKx BKCNTKN8PL1i0vJSKtPH/BcHoBD6F+B5lHXTmC8fUFRlPooHPYdahP1nBtR2NEvXOpCO1j5Xt G1Ka/CqJ+EpwSslH2HM4Bcgb4cYhdcvX6HaYB4ywCZfOdSrcL2iIhfyjprKM9bi5WRfBznmRK T22Ejg19Zbepk5BfX6Rd8UL3gdN9xZ6x99LeWjFTL7YrB9J7D9tOv2ap5X9tjkAHH2A0O9e55 kQps2KJbiTSvHbQg3M81+uWKSxlWSYdMvp1MI2pfWg437xZW2ZkrrNMW8BFPhIlQ2EljCkuWF Hu2zkDUdH83sFfT7VSdj308mz2Mt7PffsFqWdL08j9joazMfCcFYA4hg0sZ0V1C0jNK26LPHu G+F4HRZxETLKPoPoMKdJdVJyyT8AGCA6l9hrZc2F8MbMwyaFfvWHkxiTaA7WXyDRrFosvO1te /RmDBEuQUGLnu/GNcrwfdmYtqhhGfyVXPlt6puhz/nouvDEnlp8XNhiKC4rycE9knTF/e0HTQ d3yDNdO57YA183f//VmEgerGsBzM2JzVIiNkCJSv7lDNqZBPB1HIXOHBHqu/U6DpFeIepYDVe Z6FyiT+/ZM0cf1/5VOTpkBEW4IwiNCIB+3EVcNR/KWrR6rzHYdgw3djO7kuyKwIbYw1I6V/mI aOS8X4Iu3p2exjS0tpGRaVgakI8= Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The known LUID table for established/known custom HID sensors was limited to sensors with "INTEL" as manufacturer. But some vendors such as Lenovo also include fairly standard iio sensors (e.g. ambient light) in their custom sensors. Expand the known custom sensors table by a tag used for the platform device name and match sensors based on the LUID as well as optionally on model and manufacturer properties. Introduce sensors from Lenovo's "Intelligent Sensing Solution" on the Lenovo Yoga 9 14IAP7 as an example. Signed-off-by: Philipp Jungkamp --- Hello, here's a short summary of changes compared to v1: Added an additional commit which adds the LISS entries to the known custom sensors. Removed all unnecessary linebreaks from modified function calls and stayed below the 80 columns. Revisited the matching logic and removed the explicit error codes in favor of bools and forwarding the inner error. I noticed that the strange ENODATA return code was already redundant with the **known out parameter. So I removed it. Changes compared to v2: I forgot to sign off on the new commit I introduced. I'm not really too comfortable with signoffs and mailing lists yet. Regards, Philipp Jungkamp drivers/hid/hid-sensor-custom.c | 211 +++++++++++++++++++++----------- include/linux/hid-sensor-ids.h | 1 + 2 files changed, 142 insertions(+), 70 deletions(-) -- 2.38.1 diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 32c2306e240d..89e56913c92e 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -750,114 +751,184 @@ static void hid_sensor_custom_dev_if_remove(struct hid_sensor_custom } -/* luid defined in FW (e.g. ISH). Maybe used to identify sensor. */ -static const char *const known_sensor_luid[] = { "020B000000000000" }; +/* + * Match a known custom sensor. + * tag and luid is mandatory. + */ +struct hid_sensor_custom_match { + const char *tag; + const char *luid; + const char *model; + const char *manufacturer; + bool check_dmi; + struct dmi_system_id dmi; +}; -static int get_luid_table_index(unsigned char *usage_str) -{ - int i; +/* + * Custom sensor properties used for matching. + */ +struct hid_sensor_custom_properties { + u16 serial_num[HID_CUSTOM_MAX_FEATURE_BYTES]; + u16 model[HID_CUSTOM_MAX_FEATURE_BYTES]; + u16 manufacturer[HID_CUSTOM_MAX_FEATURE_BYTES]; +}; + +static const struct hid_sensor_custom_match hid_sensor_custom_known_table[] = { + /* + * Intel Integrated Sensor Hub (ISH) + */ + { /* Intel ISH hinge */ + .tag = "INT", + .luid = "020B000000000000", + .manufacturer = "INTEL", + }, + {} +}; - for (i = 0; i < ARRAY_SIZE(known_sensor_luid); i++) { - if (!strncmp(usage_str, known_sensor_luid[i], - strlen(known_sensor_luid[i]))) - return i; +static bool hid_sensor_custom_prop_match_str(const u16 *prop, const char *match, + size_t count) +{ + while (count-- && *prop && *match) { + if (*prop & 0xFF00 || + *match != (char) *prop) + return false; + prop++; + match++; } - return -ENODEV; + return (count == -1) || *prop == (u16)*match; } -static int get_known_custom_sensor_index(struct hid_sensor_hub_device *hsdev) +static bool hid_sensor_custom_get_prop(struct hid_sensor_hub_device *hsdev, + u32 prop_usage_id, size_t prop_size, + u16 *prop) { - struct hid_sensor_hub_attribute_info sensor_manufacturer = { 0 }; - struct hid_sensor_hub_attribute_info sensor_luid_info = { 0 }; + struct hid_sensor_hub_attribute_info prop_attr = { 0 }; int report_size; int ret; - static u16 w_buf[HID_CUSTOM_MAX_FEATURE_BYTES]; - static char buf[HID_CUSTOM_MAX_FEATURE_BYTES]; - int i; - memset(w_buf, 0, sizeof(w_buf)); - memset(buf, 0, sizeof(buf)); + memset(prop, 0, prop_size); - /* get manufacturer info */ - ret = sensor_hub_input_get_attribute_info(hsdev, - HID_FEATURE_REPORT, hsdev->usage, - HID_USAGE_SENSOR_PROP_MANUFACTURER, &sensor_manufacturer); + ret = sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, + hsdev->usage, prop_usage_id, + &prop_attr); if (ret < 0) - return ret; + return 0; - report_size = - sensor_hub_get_feature(hsdev, sensor_manufacturer.report_id, - sensor_manufacturer.index, sizeof(w_buf), - w_buf); + report_size = sensor_hub_get_feature(hsdev, prop_attr.report_id, + prop_attr.index, prop_size, prop); if (report_size <= 0) { hid_err(hsdev->hdev, - "Failed to get sensor manufacturer info %d\n", + "Failed to get sensor property %08x %d\n", + prop_usage_id, report_size); - return -ENODEV; + return report_size; } - /* convert from wide char to char */ - for (i = 0; i < ARRAY_SIZE(buf) - 1 && w_buf[i]; i++) - buf[i] = (char)w_buf[i]; + return 0; +} + +static bool +hid_sensor_custom_do_match(struct hid_sensor_hub_device *hsdev, + const struct hid_sensor_custom_match *match, + const struct hid_sensor_custom_properties *prop) +{ + struct dmi_system_id dmi[] = { match->dmi, { 0 } }; + + if (!hid_sensor_custom_prop_match_str(prop->serial_num, "LUID:", 5) || + !hid_sensor_custom_prop_match_str(prop->serial_num + 5, match->luid, + HID_CUSTOM_MAX_FEATURE_BYTES - 5)) + return false; + + if (match->model && + !hid_sensor_custom_prop_match_str(prop->model, match->model, + HID_CUSTOM_MAX_FEATURE_BYTES)) + return false; - /* ensure it's ISH sensor */ - if (strncmp(buf, "INTEL", strlen("INTEL"))) - return -ENODEV; + if (match->manufacturer && + !hid_sensor_custom_prop_match_str(prop->manufacturer, match->manufacturer, + HID_CUSTOM_MAX_FEATURE_BYTES)) + return false; - memset(w_buf, 0, sizeof(w_buf)); - memset(buf, 0, sizeof(buf)); + if (match->check_dmi && !dmi_check_system(dmi)) + return false; - /* get real usage id */ - ret = sensor_hub_input_get_attribute_info(hsdev, - HID_FEATURE_REPORT, hsdev->usage, - HID_USAGE_SENSOR_PROP_SERIAL_NUM, &sensor_luid_info); + return true; +} + +static int +hid_sensor_custom_properties_get(struct hid_sensor_hub_device *hsdev, + struct hid_sensor_custom_properties *prop) +{ + int ret; + + ret = hid_sensor_custom_get_prop(hsdev, + HID_USAGE_SENSOR_PROP_SERIAL_NUM, + HID_CUSTOM_MAX_FEATURE_BYTES, + prop->serial_num); if (ret < 0) return ret; - report_size = sensor_hub_get_feature(hsdev, sensor_luid_info.report_id, - sensor_luid_info.index, sizeof(w_buf), - w_buf); - if (report_size <= 0) { - hid_err(hsdev->hdev, "Failed to get real usage info %d\n", - report_size); - return -ENODEV; - } + ret = hid_sensor_custom_get_prop(hsdev, + HID_USAGE_SENSOR_PROP_MODEL, + HID_CUSTOM_MAX_FEATURE_BYTES, + prop->model); + if (ret < 0) + return ret; - /* convert from wide char to char */ - for (i = 0; i < ARRAY_SIZE(buf) - 1 && w_buf[i]; i++) - buf[i] = (char)w_buf[i]; + ret = hid_sensor_custom_get_prop(hsdev, + HID_USAGE_SENSOR_PROP_MANUFACTURER, + HID_CUSTOM_MAX_FEATURE_BYTES, + prop->manufacturer); + if (ret < 0) + return ret; - if (strlen(buf) != strlen(known_sensor_luid[0]) + 5) { - hid_err(hsdev->hdev, - "%s luid length not match %zu != (%zu + 5)\n", __func__, - strlen(buf), strlen(known_sensor_luid[0])); - return -ENODEV; + return 0; +} + +static int +hid_sensor_custom_get_known(struct hid_sensor_hub_device *hsdev, + const struct hid_sensor_custom_match **known) +{ + int ret; + const struct hid_sensor_custom_match *match = + hid_sensor_custom_known_table; + struct hid_sensor_custom_properties prop; + + ret = hid_sensor_custom_properties_get(hsdev, &prop); + if (ret < 0) + return ret; + + while (match->tag) { + if (hid_sensor_custom_do_match(hsdev, match, &prop)) { + *known = match; + return 0; + } + match++; } - /* get table index with luid (not matching 'LUID: ' in luid) */ - return get_luid_table_index(&buf[5]); + *known = NULL; + return 0; } static struct platform_device * hid_sensor_register_platform_device(struct platform_device *pdev, struct hid_sensor_hub_device *hsdev, - int index) + const struct hid_sensor_custom_match *match) { - char real_usage[HID_SENSOR_USAGE_LENGTH] = { 0 }; + char real_usage[HID_SENSOR_USAGE_LENGTH]; struct platform_device *custom_pdev; const char *dev_name; char *c; - /* copy real usage id */ - memcpy(real_usage, known_sensor_luid[index], 4); + memcpy(real_usage, match->luid, 4); + real_usage[4] = '\0'; - /* usage id are all lowcase */ for (c = real_usage; *c != '\0'; c++) *c = tolower(*c); - /* HID-SENSOR-INT-REAL_USAGE_ID */ - dev_name = kasprintf(GFP_KERNEL, "HID-SENSOR-INT-%s", real_usage); + dev_name = kasprintf(GFP_KERNEL, "HID-SENSOR-%s-%s", + match->tag, real_usage); if (!dev_name) return ERR_PTR(-ENOMEM); @@ -873,7 +944,7 @@ static int hid_sensor_custom_probe(struct platform_device *pdev) struct hid_sensor_custom *sensor_inst; struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; int ret; - int index; + const struct hid_sensor_custom_match *match = NULL; sensor_inst = devm_kzalloc(&pdev->dev, sizeof(*sensor_inst), GFP_KERNEL); @@ -888,10 +959,10 @@ static int hid_sensor_custom_probe(struct platform_device *pdev) mutex_init(&sensor_inst->mutex); platform_set_drvdata(pdev, sensor_inst); - index = get_known_custom_sensor_index(hsdev); - if (index >= 0 && index < ARRAY_SIZE(known_sensor_luid)) { + ret = hid_sensor_custom_get_known(hsdev, &match); + if (!ret && match) { sensor_inst->custom_pdev = - hid_sensor_register_platform_device(pdev, hsdev, index); + hid_sensor_register_platform_device(pdev, hsdev, match); ret = PTR_ERR_OR_ZERO(sensor_inst->custom_pdev); if (ret) { diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h index ac631159403a..13b1e65fbdcc 100644 --- a/include/linux/hid-sensor-ids.h +++ b/include/linux/hid-sensor-ids.h @@ -132,6 +132,7 @@ #define HID_USAGE_SENSOR_PROP_FRIENDLY_NAME 0x200301 #define HID_USAGE_SENSOR_PROP_SERIAL_NUM 0x200307 #define HID_USAGE_SENSOR_PROP_MANUFACTURER 0x200305 +#define HID_USAGE_SENSOR_PROP_MODEL 0x200306 #define HID_USAGE_SENSOR_PROP_REPORT_INTERVAL 0x20030E #define HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS 0x20030F #define HID_USAGE_SENSOR_PROP_SENSITIVITY_RANGE_PCT 0x200310 From patchwork Thu Nov 17 23:48:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13047491 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 E5324C4332F for ; Thu, 17 Nov 2022 23:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235044AbiKQXtK (ORCPT ); Thu, 17 Nov 2022 18:49:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbiKQXtH (ORCPT ); Thu, 17 Nov 2022 18:49:07 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CEB6528BF for ; Thu, 17 Nov 2022 15:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668728938; bh=oNUFG+zVXBZTn6a9L42OesJqyqm7jfClcKQ1QvZfqLA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ENGdSRbtUD/LMic07aMe4ZMweiy0cOXMrOiV+qo9Uib8AZkdZaPxs7LfUvzAMmI0Q lCr1xk+P75hqcY8F36d3ZPLonzKM0vSRuCDjFOd9QfVB2y0xePsgBFhkTerA+rqmeg Zd9K+xPXsuwT459xMMWtP5bwPK2N07mOwLMlJ5MIrCQV3g0DwPgvkqDCiI2JuXT/Ln s+MsM/5QltUmofmV6qiK/EfSGHHJGf6qV7T2fXMU+i6/4LAQ+x4OIlXmlervNdtOEJ W2zGm6pe4f825FjvnuZ9rmKUs7FOgU/OLVSIB/4yh4fU9ZlRcpwwdxnd6fYBrv2PSH sUyC++2utzVng== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.45.31]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M1Hdw-1oxSW819vW-002oix; Fri, 18 Nov 2022 00:48:58 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH v3 2/4] HID: hid-sensor-custom: Add LISS custom sensors Date: Fri, 18 Nov 2022 00:48:22 +0100 Message-Id: <20221117234824.6227-2-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117234824.6227-1-p.jungkamp@gmx.net> References: <20221117150508.00002704@Huawei.com> <20221117234824.6227-1-p.jungkamp@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:Mk5soXo7846gxSR7IROUJyjnh9yxWZJKx1M7fMr2a13FrgmUSiR GAE1BwMAQ8KqfD+SB5tmrWcxq9KIJ/KgXr2iigJiirls0Tfo9dVYFjWcbrUZCRJljmEnLCc pFOan/hBqEXn5oc7R7e7M0l2hAbOXZXoXPTBJXKiYkFfAZUU8dyG0d8qMb4J8zg4Z6sWd7E yhG0mmUdXZH0ypuxqLDvg== UI-OutboundReport: notjunk:1;M01:P0:v0v1/2Kwl/w=;flv8MUygq/s58Ri3omixtG/gmFU AiKwWroCFuajuf36eO3O4WIaf+yRV1mJ7e8eaZVZxOBhXNyQkfdiAtucTpwQxnsQ3oKaU2iMW dCkrbS1W6eZ53dDYCTlfSkR1PGfa5jSKV4uYD2uUeX5hsoSMfLp52JVVJ49hhVt3PgVta6osE TlwD4w+S2p6YnagKtkdpRtdCh8wZ8DbEoTMlMfnfRfTB5rnTzvfkPifIrz9/zY5uoE/9xX42w +IPObMt7a58HQCH40hOE+9hnh8otDxNPO5bb8ISqRDnW9vET/tlMvphOtZiF+2mMbPLfRMlXz qSxupjzgin2tR3WvKuGnPX0+8q9uxDjjlsSzGxxc6yU1QWFzFOjg/7cGPJXvqVQrf4Cq0JtVC xapCLviqC8HNMBtWWIrezedOrgjhA+KKBdg+RntQAdC0yyHmTQe82gIeT4cQmorVY+c8dzCty IHTRipsHeK6xOseujgc7ooV6YACtLbW2RGcTDgx81uAjrXiqyzgjKrxepMYYhBIb0T46je0nX RyPL2E2mKJRIJM1Znx8MZBws6878Bu/p3y0E4hqGjczfmbwC3An4qiR+/8739ryp+pGEjctTL 53DldcJXcd+EliEZySa+DQIlRt2w21U3wNUPRLOP71vJwwIi0zk72Jvyf3T9ZG6t3kq5It86Y /XbP6pFwht5FJKmi5CyQvP4XcE0ma6FoSdSNMRjN6sg68etsgX3hszdGdmWPSCmld3BTOGbKh EO88V8o6xQZnf5oj7v6TDb52Q8WzNgBqxoOeFZZXrJFHpM9+Fyc9oKeAi+zkELxEx0cfzhmuu +D/o7vswv+ARec/LeV7XsRJULtCiROfr4zcU+z3T1CoNEJuqa3FK7Rru71WUUi5xCMuNH9SUi l8dA1QLy8KSuRfMQJJMIfxoI3DotCqFf/3KK7spTXqVCZkVwHut1kLqzsXpVvH5m8gKfZy4Cv ESLrUQ== Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add the Lenovo Intelligent Sensing Solution (LISS) custom sensors to the known custom sensors. Signed-off-by: Philipp Jungkamp --- Here is the requested noop commit that changes the device ids for the known LISS sensors. drivers/hid/hid-sensor-custom.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) -- 2.38.1 diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 89e56913c92e..85db14406b23 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -782,6 +782,29 @@ static const struct hid_sensor_custom_match hid_sensor_custom_known_table[] = { .luid = "020B000000000000", .manufacturer = "INTEL", }, + /* + * Lenovo Intelligent Sensing Solution (LISS) + */ + { /* ambient light */ + .tag = "LISS", + .luid = "0041010200000082", + .model = "STK3X3X Sensor", + .manufacturer = "Vendor 258", + .check_dmi = true, + .dmi.matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + } + }, + { /* human presence */ + .tag = "LISS", + .luid = "0226000171AC0081", + .model = "VL53L1_HOD Sensor", + .manufacturer = "ST_MICRO", + .check_dmi = true, + .dmi.matches = { + DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), + } + }, {} }; From patchwork Thu Nov 17 23:48:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13047494 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 566F3C4332F for ; Thu, 17 Nov 2022 23:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233679AbiKQXtL (ORCPT ); Thu, 17 Nov 2022 18:49:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235022AbiKQXtJ (ORCPT ); Thu, 17 Nov 2022 18:49:09 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E79532EE for ; Thu, 17 Nov 2022 15:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668728938; bh=zIOolA9952zV+6SNTVjguhB5zc/PxoGHuNoxiOEklMc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=CYaQrexCPWkvB4K7HCCUV70u0D3YqgBR9ePeefEWUt/a2lX3vobK2PxB18atbEDQx 9XnSlvoTQxI3BFMTpJMMzytIIicsLhpwg6AM/4HQqUf2pqxL6efeYmKswjQiu8ic3N 6+14lR8hOleqczgYTEgKUyjhPDCEG+5IMCU/rt7cS/SFje49BOjbbckNxCvG7MEVOt SMdzaOISqzHi5uiIXSTCTZ4R0oz75Cynnx9X95/Cj3GpbjLsaP1F79DQNUqmI6W2IN HpEmuE6gIZfPj5F6VYNHUTCGZdy4kCNX5/PomFj9Szrdo3XxQ7j1tNOz7CkqRCat1E xPchfsxStDi0g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.45.31]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MybGh-1pACJj2Eyj-00z1HI; Fri, 18 Nov 2022 00:48:58 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH v3 3/4] IIO: hid-sensor-als: Use generic usage Date: Fri, 18 Nov 2022 00:48:23 +0100 Message-Id: <20221117234824.6227-3-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117234824.6227-1-p.jungkamp@gmx.net> References: <20221117150508.00002704@Huawei.com> <20221117234824.6227-1-p.jungkamp@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:B+Lw3Kwaq4T7WZF5qjT0PDZusoXKQWzpeLqJv+wKjWrRyglIep+ v7sv9Jg+zuYrbV+EBIG1rgmmesi96KLIjsv2hVF/KkhKcFf9x1KDW9AN0EVCWloZydkRiQL 3ix8iOI2MivV6Y0v+fTFfDLdVylJV2Y5KrbsDICIfR/3nUnyA99ZvR0683dhseVgqLfmRsE OMMEwxBA+Zwhxp9CqbvVQ== UI-OutboundReport: notjunk:1;M01:P0:DYjvMxMyr5Q=;Wn0xAxIj0+QMZhFRsk8RHl73DzT dlWZcp+8DBmhIvJHTF7+ZyJxpU+t1JvWtsFYv7C9u9+SjSTmRu36CNZrfV1axwIRthB6ns07s YpeFFvY7UKE7eBMIBgSQIDCZI1JE8uk4oaXmCG3FpcdBodC0oezKx5NvujNXPektiD0cyQQjk 1Cj40ELLKf2ccnFUzYh7Csvl9PJwYpsW3uu2/H2mSe0D66gXtaCz382gswK1EzZHNjn6vOJ9O 5+9DYzr3ou52OIq2/RVbVmyfAjPOTOF09NBMRCxEVWHSna3PZqsdkJcLVMqsJt2tGqUDmNJ+G yoNcrO9dA0/hGCga8HWqiUHYDFGMRTcgahZ0YdRzMs8X73d874Hn2BaOcWH+LcdimDJEZ7122 vEuNkppsZZ38Dc8z2QtvBal+S/nDv8tTkJzSIVVivCNIiRo6hlkJxK49Tj48bxSqJ/nci5ISq Res09snEEUU4Iet2V7SrcJI5v0SzG+feTu078seLEhrlL0LzsJqKfQ6C8eMIKSywpl+EacFP5 hU0PRW0Jp9ecpzCs9zFzYqS/xenuop+hf1an0frOzWq497/3fy0WLmgDmiFBtdfEACuP4mUmE k2HrpfEkWQZWbacmUC/v1EeRuMWx/EPmJXY8nFzumpjzKbT8KyGx1H9+5Ay+XV3t5880E5S6E QMrOoR5QoVSSAxlGarMp3Vw1UnBt4BDodkd9Tx4evgNs9Ii0knpo7JZPH2VPNaDK4ZBTnH/Bm qRG9Ul7l60dIuVoHvHC6hGQDcrVvLcMfiy2zosRRHYQCh5df+UZf3r9X0kmpudqQQen3MeYzn 2O9IqrFN3sx9opGHwm9PtRqMg3wku7LDIGbCgdSP0BSpjHnY8244NUCev/ZsWBhkTtsNKtaeu LeHcBeQMB8IF1pSwy9dHRK1TIltBgNae4M97hMxdr/wJFXyly9RFrM3GUdj671u1NqBbfp3fi Dp5DfO/VysfrNVHJdETqHJD79Uo= Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use a generic 'hsdev->usage' instead of the HID_USAGE_SENSOR_ALS to allow this driver to drive the Lenovo custom ambient light sensor, which is registered under a 'custom' usage and not HID_USAGE_SENSOR_ALS. Add the Lenovo Intelligent Sensing Solution (LISS) ambient light sensor to the platform device ids. Signed-off-by: Philipp Jungkamp Acked-by: Srinivas Pandruvada Reviewed-by: Jonathan Cameron --- Less unnecessary line breaks in function calls. drivers/iio/light/hid-sensor-als.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) -- 2.38.1 diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 5a1a625d8d16..eb1aedad7edc 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -86,6 +86,7 @@ static int als_read_raw(struct iio_dev *indio_dev, long mask) { struct als_state *als_state = iio_priv(indio_dev); + struct hid_sensor_hub_device *hsdev = als_state->common_attributes.hsdev; int report_id = -1; u32 address; int ret_type; @@ -110,11 +111,8 @@ static int als_read_raw(struct iio_dev *indio_dev, hid_sensor_power_state(&als_state->common_attributes, true); *val = sensor_hub_input_attr_get_raw_value( - als_state->common_attributes.hsdev, - HID_USAGE_SENSOR_ALS, address, - report_id, - SENSOR_HUB_SYNC, - min < 0); + hsdev, hsdev->usage, address, report_id, + SENSOR_HUB_SYNC, min < 0); hid_sensor_power_state(&als_state->common_attributes, false); } else { @@ -259,9 +257,7 @@ static int als_parse_report(struct platform_device *pdev, dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index, st->als_illum.report_id); - st->scale_precision = hid_sensor_format_scale( - HID_USAGE_SENSOR_ALS, - &st->als_illum, + st->scale_precision = hid_sensor_format_scale(usage_id, &st->als_illum, &st->scale_pre_decml, &st->scale_post_decml); return ret; @@ -285,7 +281,8 @@ static int hid_als_probe(struct platform_device *pdev) als_state->common_attributes.hsdev = hsdev; als_state->common_attributes.pdev = pdev; - ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_ALS, + ret = hid_sensor_parse_common_attributes(hsdev, + hsdev->usage, &als_state->common_attributes, als_sensitivity_addresses, ARRAY_SIZE(als_sensitivity_addresses)); @@ -303,7 +300,8 @@ static int hid_als_probe(struct platform_device *pdev) ret = als_parse_report(pdev, hsdev, (struct iio_chan_spec *)indio_dev->channels, - HID_USAGE_SENSOR_ALS, als_state); + hsdev->usage, + als_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); return ret; @@ -333,8 +331,7 @@ static int hid_als_probe(struct platform_device *pdev) als_state->callbacks.send_event = als_proc_event; als_state->callbacks.capture_sample = als_capture_sample; als_state->callbacks.pdev = pdev; - ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_ALS, - &als_state->callbacks); + ret = sensor_hub_register_callback(hsdev, hsdev->usage, &als_state->callbacks); if (ret < 0) { dev_err(&pdev->dev, "callback reg failed\n"); goto error_iio_unreg; @@ -356,7 +353,7 @@ static int hid_als_remove(struct platform_device *pdev) struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct als_state *als_state = iio_priv(indio_dev); - sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS); + sensor_hub_remove_callback(hsdev, hsdev->usage); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &als_state->common_attributes); @@ -368,6 +365,10 @@ static const struct platform_device_id hid_als_ids[] = { /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ .name = "HID-SENSOR-200041", }, + { + /* Format: HID-SENSOR-custom_sensor_tag-usage_id_in_hex_lowercase */ + .name = "HID-SENSOR-LISS-0041", + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, hid_als_ids); From patchwork Thu Nov 17 23:48:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13047492 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 66751C433FE for ; Thu, 17 Nov 2022 23:49:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235062AbiKQXtK (ORCPT ); Thu, 17 Nov 2022 18:49:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234932AbiKQXtJ (ORCPT ); Thu, 17 Nov 2022 18:49:09 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45AC0532DB for ; Thu, 17 Nov 2022 15:49:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668728939; bh=SBPi6rC4HYka5zDnNBrOrmm3M7oLCjGw6JXOetO9axc=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=EJ/sKvwZYgjzwMoTYcxi6ZWDWLZjVg2p2F79yQ68vUxyVpuZqZJVMohf7barQ12Vh Hsq0yuo4piHO7t9OgCAe9naQKyuHq9kUNya5lE+jtEi+wXOiOWoR2bJ+GAaAbasfdH gj2D8lkaa4yfFpfPfkWl1SWb4smkJNDLbZWtqEg0jb0CAS3++h/5Mg7jJGYqMm08LA U1bTN8N69LhWvjTedXhIQ2ySqIOhk05wwOXUV4ChzfLG9omSAHGlWlGWG87jUrf9QU DtdJEKBrlUiuDeR0VzM+DW/gEw0KmM93d5yfGmxfajhHnGBvWLgi+FwQHw1QWmQxRR gK0t16YvYUx/Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.45.31]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MTzf6-1oUpoG3HHO-00R2eJ; Fri, 18 Nov 2022 00:48:58 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH v3 4/4] IIO: hid-sensor-prox: Use generic usage Date: Fri, 18 Nov 2022 00:48:24 +0100 Message-Id: <20221117234824.6227-4-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117234824.6227-1-p.jungkamp@gmx.net> References: <20221117150508.00002704@Huawei.com> <20221117234824.6227-1-p.jungkamp@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:FtF42SKxW4Y0NsJUoz0NWjfPmxlmknLRVKlwol05qznXaqv8SMd j9q/s/3sG02jBfnsJV7N6ITBiC4wJQrX2bhCh1uR6EEmhEbyk7mPlcg4H+2aC4dfA1G6aCX a5cYF9QDFCUjUW0UiE6lAzFZ76i3E9ndfpjVFye0ERo+4v4KVGz0yDF4xltv9Tuunkws1kl 3aAn44QaV0kGGcdIAFHSA== UI-OutboundReport: notjunk:1;M01:P0:15xA/mjBlMA=;km3rN0PTQgP6oI5Ma1nD3MWDqot qoGCwESng+PBa8+ACOGtR9I9ZmrpPiUP3kg8CAcB0bp1jdYmwdDZAb5fAkSUhzUMmD7Q1hXS6 0QkPDby7AqXKoQS9kRrVl46XxwQE+Th7uS/9Z793bv3kZM6AxRIRGTA1jczqv7UNqpgR2cefd 3NAaNvxnCAR/LjzhXGVulCf8RO7TMCHurXXtxUYv5qnat8DWWn7HhsdEHXy34x+V7Nc+l9/sT p8v8M3k2z2e7P2xgV0h+inePPHbkPw9kyqSCO6+K+yoYgVhM5y49MzeGbANBLMiFBH+w9SSRD Uf3QLfpmqS142gUVfYgrf3i0kzw4AGhROqzTWGviGRYiQtuK9fcuBJ5kvosyOeImXmOL0LQAA wgur+IKIzCeOoaPUGmETlZRKg2ydCLiB994jVtOqph9rMF4+2DCD1t8RUzNzWGN+Msrvn8i/z 1hdkSPHguTuxd+pcA/y5g/7Qh1hzGiPI/nEOK7KlwmUv3GtTLHC9VSFoYLY55La1weRza7GtI QKUhJTCdO9RPq2p55gpB07OfvqD4jzUk+e4pFuXcrG0pPeFd/VlOOi4IfDYza/RE4zZsii5vU /iV1nFWIAu+XstBrW7JSTNNycA/dlEJehun80VpHJ+zZfOiP/hmlMFvEaTXZsZiVkmUCwW85M iapzjWamxNGjLE1gUoHUfMvHC9bT+GDazA13e5cGcgLMGQrPHknxuF16sEzk15xwJgunpwDZx wPdyhwJp1DOlLXfWZ9zJq0Dyn7h+aMyECleaMY44TdaJwAbL/syCyFj06SR0IBx+J3hjIS0yH W5EPUs47Ad6uqLjS8Ye0n+wOqHHf+SHLC2rh5fB+mCzmE8PUHM2y5Jo6SHb4ATN4CuF7vD3Vb GzzkHYXU01CQSNmeKxPAnjCu6isgkCWpLihH5/b1i68dqD3KDAGZjPS3WkaBPqFu+yNG2Ce3F Gd5cFw== Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use a generic 'hsdev->usage' instead of the HID_USAGE_SENSOR_PROX to allow this driver to drive the Lenvo custom proximity sensor, which is registered under a 'custom' usage and not HID_USAGE_SENSOR_PROX. Add the Lenovo Intelligent Sensing Solution (LISS) human presence sensor to the platform device ids. Signed-off-by: Philipp Jungkamp Reviewed-by: Jonathan Cameron --- Lines are shorter and the switch statement for raw_len is cleaner. drivers/iio/light/hid-sensor-prox.c | 37 ++++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) -- 2.38.1 diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index f10fa2abfe72..a47591e1bad9 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -61,6 +61,7 @@ static int prox_read_raw(struct iio_dev *indio_dev, long mask) { struct prox_state *prox_state = iio_priv(indio_dev); + struct hid_sensor_hub_device *hsdev; int report_id = -1; u32 address; int ret_type; @@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev, report_id = prox_state->prox_attr.report_id; min = prox_state->prox_attr.logical_minimum; address = HID_USAGE_SENSOR_HUMAN_PRESENCE; + hsdev = prox_state->common_attributes.hsdev; break; default: report_id = -1; @@ -84,11 +86,8 @@ static int prox_read_raw(struct iio_dev *indio_dev, hid_sensor_power_state(&prox_state->common_attributes, true); *val = sensor_hub_input_attr_get_raw_value( - prox_state->common_attributes.hsdev, - HID_USAGE_SENSOR_PROX, address, - report_id, - SENSOR_HUB_SYNC, - min < 0); + hsdev, hsdev->usage, address, report_id, + SENSOR_HUB_SYNC, min < 0); hid_sensor_power_state(&prox_state->common_attributes, false); } else { @@ -191,10 +190,16 @@ static int prox_capture_sample(struct hid_sensor_hub_device *hsdev, switch (usage_id) { case HID_USAGE_SENSOR_HUMAN_PRESENCE: - prox_state->human_presence = *(u32 *)raw_data; - ret = 0; - break; - default: + switch (raw_len) { + case 1: + prox_state->human_presence = *(u8 *)raw_data; + return 0; + case 4: + prox_state->human_presence = *(u32 *)raw_data; + return 0; + default: + break; + } break; } @@ -244,7 +249,7 @@ static int hid_prox_probe(struct platform_device *pdev) prox_state->common_attributes.hsdev = hsdev; prox_state->common_attributes.pdev = pdev; - ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_PROX, + ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage, &prox_state->common_attributes, prox_sensitivity_addresses, ARRAY_SIZE(prox_sensitivity_addresses)); @@ -262,7 +267,7 @@ static int hid_prox_probe(struct platform_device *pdev) ret = prox_parse_report(pdev, hsdev, (struct iio_chan_spec *)indio_dev->channels, - HID_USAGE_SENSOR_PROX, prox_state); + hsdev->usage, prox_state); if (ret) { dev_err(&pdev->dev, "failed to setup attributes\n"); return ret; @@ -291,8 +296,8 @@ static int hid_prox_probe(struct platform_device *pdev) prox_state->callbacks.send_event = prox_proc_event; prox_state->callbacks.capture_sample = prox_capture_sample; prox_state->callbacks.pdev = pdev; - ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_PROX, - &prox_state->callbacks); + ret = sensor_hub_register_callback(hsdev, hsdev->usage, + &prox_state->callbacks); if (ret < 0) { dev_err(&pdev->dev, "callback reg failed\n"); goto error_iio_unreg; @@ -314,7 +319,7 @@ static int hid_prox_remove(struct platform_device *pdev) struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct prox_state *prox_state = iio_priv(indio_dev); - sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_PROX); + sensor_hub_remove_callback(hsdev, hsdev->usage); iio_device_unregister(indio_dev); hid_sensor_remove_trigger(indio_dev, &prox_state->common_attributes); @@ -326,6 +331,10 @@ static const struct platform_device_id hid_prox_ids[] = { /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ .name = "HID-SENSOR-200011", }, + { + /* Format: HID-SENSOR-tag-usage_id_in_hex_lowercase */ + .name = "HID-SENSOR-LISS-0226", + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, hid_prox_ids);