From patchwork Wed Nov 16 23:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13045911 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 AD242C433FE for ; Wed, 16 Nov 2022 23:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233151AbiKPXUX (ORCPT ); Wed, 16 Nov 2022 18:20:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbiKPXUW (ORCPT ); Wed, 16 Nov 2022 18:20:22 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6637A623A4 for ; Wed, 16 Nov 2022 15:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668640804; bh=VZfj5fnV6z24fVIt9+oeclfarFXSxeQH3rhRQxKiCWk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=flxI9A+/xFaBfsIW8Trr7MSiLUK2Cry1Q9vTNxcq318tn8P8/PfNDuH/kagSWcOUo HjC/hAKHVJRuQra5flgBlfrL0rm5CCDKZuTeIHZG++XExcevSzi2lJ17OyQBj0Bw5j 4iwBoqhjjDuN8nkeEENpNUWO3zw9rUtnbwJTO3tMk+HZNx6nXHR8Py/rxCL2fofIfs /DuRs6RmpJQY4d8WKIrP3ao+K/De2xRPKsdm6KReOFRu6lbEs4ktinpQFccFjUNydB 5bQRIel+7vXWmN939ig77eRcgzwJFCfuOrERCI1LOyNfSNZbEz2BPSk4uQKczMnG0k 9GCLCMpxQH5qA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.44.107]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MUosN-1oUfdV1ZWT-00QlVl; Thu, 17 Nov 2022 00:20:04 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH 1/3] HID: hid-sensor-custom: More custom iio sensors Date: Thu, 17 Nov 2022 00:19:45 +0100 Message-Id: <20221116231947.18031-1-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:4R/iIz94O3mFHMRV+3ofHaYWvKebcSdr4iY+9ky7KOaS1a5O0lI flfBmMrGffYAAMYWmyhMZPKIQeHgZKVkujfZab/6LX2ppF8hLniQhMbRDrQ7OvlezGPo1iJ yx2JGIYMOZd10h3R/TiHBgqhe4m+xM+Z+bgLnQd0UmX0TixrDNjE14mU+3wxaii3aoSSJyX 0MTh9IoXCVOSWYGYxt5Gw== UI-OutboundReport: notjunk:1;M01:P0:eG8Z+1/02lA=;koYEnMh3G0CFdI4wolelkhQzJdw 8yJvrdWTxYsdOo+wMbKcI/ep62H5yAlxrggu4AGoBnbrIw+4bsflG6y9pEaNc440SPrrsRP55 50E2OTbhAJO7yS1+uy82reqj8Sknv0KuZK/iS3W0fNsozh9pPo55jxuRueW+dMMDRSaUnpvBP c4cmgEbQuQSN5SVag/W/EXW0QNfD5yfGPmkxtFQteQfRtExCKYTGCL69mwepGoLbrtKUqxfG7 bxMpJAcISPvZ+q1iRgs1Auh8hvF2RpydzPYJPC2vI1v9uuaAyK/0MK41mWSFbE9+hDspqoWtj w8JeiccT05Ow74MAJ1vd2ya4jXlNIqIDdA+sI7EGTPKKiaUZdeU3Y6MmzOTO8rdFb4lHRs2Jg jtTVw38eIp1UkccMFd1SdhuefxlmtZn4quAADbfTqPz5BDCths9TcQH2LhA99oC/V5YBnyWQP w0JGIcsp8JSYCve6bdtfMrb9MKrom69SFgCJejEx+B6h0VKBSOEVPJALt7ckP5MqzwIPx/OBN 2FRA5bTYwsHWDaL6bzKIHQRNZpjEjQ+oohp1o0w15TRDjzvYcjON59WMG9/T2+WENBUiJBMNM SxugiPPPlV8t0noq/eM52bfj6OFiXivE6qTueKaB8n6zO3FMur00ERTlK69IAbDMUft05UXKA 08j5m9SL0Bp81n2RNMC7MKojaIvK3L3ZC767rBFo06070WKTpLZMIfr+sCnp7mgksClaxUxi/ xaBknISQ95Iu1M+GCouWxRUrcj4CxsCEojjHBX9QDt2aFU9/lGqvzz4WmJu5yHG1xh7H6qvu/ sNoRupjatyXMIye+4sv9C4VlxCpjCONUMpXs+YCE6Gu3tnovgvqR2czxdR14315TPAvW0wjFu XQ+5K+SSyiJhS/Fot0RZyv6/5Wi1tJd+bnwqvWS9Olyspbc+uz7o73ToToFOaTHo5JOTtfE7C +ngK50ZIxrpkZb/f70/q8foAlFA= 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. Signed-off-by: Philipp Jungkamp --- drivers/hid/hid-sensor-custom.c | 225 +++++++++++++++++++++++--------- include/linux/hid-sensor-ids.h | 1 + 2 files changed, 161 insertions(+), 65 deletions(-) -- 2.38.1 diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 32c2306e240d..cb21f9178830 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,208 @@ 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]; +}; - 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 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", + }, + {} +}; + +static int hid_sensor_custom_prop_match_str(const u16 *prop, const char *match, + size_t max_count) +{ + while (max_count-- && *prop && *match) { + if (*prop & 0xFF00 || + *match != (char) *prop) + return 0; + prop++; + match++; } - return -ENODEV; + return 1; } -static int get_known_custom_sensor_index(struct hid_sensor_hub_device *hsdev) +static int 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 */ + /* get property info */ ret = sensor_hub_input_get_attribute_info(hsdev, - HID_FEATURE_REPORT, hsdev->usage, - HID_USAGE_SENSOR_PROP_MANUFACTURER, &sensor_manufacturer); + HID_FEATURE_REPORT, + hsdev->usage, + prop_usage_id, + &prop_attr); + /* property does not exist */ if (ret < 0) - return ret; + return -ENODATA; report_size = - sensor_hub_get_feature(hsdev, sensor_manufacturer.report_id, - sensor_manufacturer.index, sizeof(w_buf), - w_buf); + 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; } - /* 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; +} - /* ensure it's ISH sensor */ - if (strncmp(buf, "INTEL", strlen("INTEL"))) - return -ENODEV; +static int +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 } }; - memset(w_buf, 0, sizeof(w_buf)); - memset(buf, 0, sizeof(buf)); + /* + * Match the LUID property. + */ + 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 0; - /* 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); + /* + * Match the model property. (optional) + */ + if (match->model && + !hid_sensor_custom_prop_match_str(prop->model, + match->model, + HID_CUSTOM_MAX_FEATURE_BYTES)) + return 0; + + /* + * Match the manufacturer property. (optional) + */ + if (match->manufacturer && + !hid_sensor_custom_prop_match_str(prop->manufacturer, + match->manufacturer, + HID_CUSTOM_MAX_FEATURE_BYTES)) + return 0; + + /* + * Match DMI. (optional) + */ + if (match->check_dmi && !dmi_check_system(dmi)) + return 0; + + return 1; +} + +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 && ret != -ENODATA) + 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 && ret != -ENODATA) + 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 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 -ENODEV; + + 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]); + return -ENODEV; } 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 */ + /* usage ids 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); + /* HID-SENSOR-tag-real_usage */ + dev_name = kasprintf(GFP_KERNEL, "HID-SENSOR-%s-%s", + match->tag, real_usage); if (!dev_name) return ERR_PTR(-ENOMEM); @@ -873,7 +968,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 +983,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 Wed Nov 16 23:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13045912 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 366CAC433FE for ; Wed, 16 Nov 2022 23:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234236AbiKPXUt (ORCPT ); Wed, 16 Nov 2022 18:20:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234095AbiKPXUr (ORCPT ); Wed, 16 Nov 2022 18:20:47 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89AFF67F6D for ; Wed, 16 Nov 2022 15:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668640835; bh=1y+8rZE7q0ABSXY9muV0WeS/+08Tcvy1TbPfZoxaXkw=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=aveEc14nW8eGIdPS/C1NLvRpbOgAbTbJm7Me+qwJ6mgqDkpTL2M5yd5/ev5ac/4Ky 2ci4klyHXcj27n5H1n0QZjtjXQcjSVYi01/GyBAEReGLYN/+4BGV1BIhOhq3Ya2OKy LCmBuCAjkc92Q4OQfQnaRTiSiryv+HsmuDI16hRDZ0YdT+03b+lA+P163DMqlgNx06 EqgcE9Ht7UaQM0NCJuPPogHQZGwDeLZ0gCyo+bcwp4JONYgjfY7MbO7Ncl6zSKX44H 1tXg+yqlGTOOyLGgJRRdgjpKVJHKtLM9SkjFCq5mGnREes44OmNaFXsH55+ECVZ3ql xjx3di9DxuV2A== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.44.107]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M1Hdw-1oyCrY44ny-002ocA; Thu, 17 Nov 2022 00:20:35 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH 2/3] IIO: hid-sensor-als: Use generic usage Date: Thu, 17 Nov 2022 00:19:46 +0100 Message-Id: <20221116231947.18031-2-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116231947.18031-1-p.jungkamp@gmx.net> References: <20221116231947.18031-1-p.jungkamp@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:bfAPTdK3LER8BL5f7TXnwR55+T4GIbVySgScXmvsm8W7p+Oon07 VCmKRGZcCARJUQQGYvsP4wWWId1JoIwBDhx8PSUYxxg0Zr5rVBi24OUzAK/Doe1Cyo62NrF 01e2SQmLDi3yAClzHmiF0NybOVoJmMongWK9Xxm1iZgqdwaQWlF2f3+LVSw9/7zBA+TyYTL CFDLd9exx/gO0ErEuyzwQ== UI-OutboundReport: notjunk:1;M01:P0:hdURPqeR9O8=;s/hcK9P0p2qTplVtYJj0ut1sYpt DOZcSLvP0m0DAnfBTE/rUUkfeM6REj/ZBB9DO1ihtjiIOyGBtyDBPQ6z+ms2lFdvui6EyzHts ev0F6tT9UFE9PQtQfCKKsMbRAoHB9nceWNA+GuEqk44blC+gpnRWETYEssvkBKU91UtEsebmz omjgCalka+wsoc7YfWpeOoHNReEyfEvPconZsRxwe9jcuEcMc7Go/oRY6zDEEt7EcG10RxHnf GSe0Qpmc0rJblxsKCaGFYrd4ESdB8TjxLghrq0TLsf+QFC33qEXqoBhVCKD7WkJYuAaaSqIic pIIg1phGkbceoseYfLL8dmcjQUniNAa0yvgo9/OF3ZvMQInSNtw+rk4rr9Shpy7RDwPTp2NjG YfbzKOUDVj10QJMVrUDS1vwZXzOcOzWOVO7OkWH1YeuFF8HY+w2lJ5uhMkhpNtKWhQvirjdTc K4wg4Zas0703k1BOAybVfnvUWBz3QiQaYLw55tZcswElr2peUsAMbwWT0lCktKiI+I+WCm1Ic MJC50do24zWRvjsV4R4wbskh2jYJlz2zUNBjBqiRtszHOGjON6KC1NdAu0io/+7BuFsKr/yrz Ns3PHEfYuFE/ZXdf7jW3+rlpOryPgRE2ukfEvSARUIy3hkzk3vFHFIQzgWjeZfttD3KOqUAdl MCK4dyxo56510KM57BrPIwGFobqxIhBHDxLxqfIytH2oMx/GlrznL20w/AfXzL0PZnKHesqro IU5QgGAdSN6oAtyTBbDQjuqTHdgjRvTbPQRaAmFRIAmNujWqBjZwRcurUDd8OL8yAF9N+OUAp miIqD7lQeeqJp2iVYTHTO9xfGM3JqObhL2HApMazEmxJPGtEpJcNoq43DkDnxIHK/xujBwuuL w7qkrez1FefZ8Pv7zodfRNGM96MP58rYJiXAy/XQrxqh5JJKAt6a2vOJWdIlxIezlYjSLwLab DG3JkYGFfjBpFjsRiO+v7+0FXrQ= 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 Lenvo 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 --- drivers/hid/hid-sensor-custom.c | 13 +++++++++++++ drivers/iio/light/hid-sensor-als.c | 24 +++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) -- 2.38.1 diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index cb21f9178830..124493b8abaf 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -782,6 +782,19 @@ 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"), + } + }, {} }; diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index 5a1a625d8d16..0ada158582a9 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,8 +111,9 @@ 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, + hsdev, + hsdev->usage, + address, report_id, SENSOR_HUB_SYNC, min < 0); @@ -260,7 +262,7 @@ static int als_parse_report(struct platform_device *pdev, st->als_illum.report_id); st->scale_precision = hid_sensor_format_scale( - HID_USAGE_SENSOR_ALS, + usage_id, &st->als_illum, &st->scale_pre_decml, &st->scale_post_decml); @@ -285,7 +287,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 +306,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,7 +337,8 @@ 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, + ret = sensor_hub_register_callback(hsdev, + hsdev->usage, &als_state->callbacks); if (ret < 0) { dev_err(&pdev->dev, "callback reg failed\n"); @@ -356,7 +361,8 @@ 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 +374,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 Wed Nov 16 23:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Jungkamp X-Patchwork-Id: 13045913 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 A58F4C433FE for ; Wed, 16 Nov 2022 23:20:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbiKPXUw (ORCPT ); Wed, 16 Nov 2022 18:20:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234221AbiKPXUt (ORCPT ); Wed, 16 Nov 2022 18:20:49 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBC0967138 for ; Wed, 16 Nov 2022 15:20:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1668640837; bh=TcO94Z8nJH9mtnQDt0N40k7lEnO2Vze6eUJiZsgph7E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ILaYqu5ezMtYvGcJ9y05fk/TGIn81KXml/obiFQ35BMaxkS3wDeRpiQEp7ulwtZ1s QXM0WG5PZ7JXnUPHtvpyUb1XehHQpkrmSDeLR4LPXJklT3iL3MOYy/ynu5rVfaC2Q6 RXVfWlLe3GHqCysLTAdEtCy694RZo2wznGtc5ZUKvO88OWXqS+po1KSi+swrFK5OOw vUS7Oq4qFQ6r/ZyHQXq8Px4NdSLZ6VTQkTwvYOXIgeatKFPnXVBmTF/7FnONmz6wI2 6AHSxlwRuHKwxMvISkDb4QXrd355gODd+AqqxgEPSczpwPYgOu7/dh04LeYnAg0f4+ TRL1oh2f1/VZA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([95.223.44.107]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N1wlv-1p6DN619z7-012JBV; Thu, 17 Nov 2022 00:20:37 +0100 From: Philipp Jungkamp To: Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada Cc: linux-iio@vger.kernel.org, Philipp Jungkamp Subject: [PATCH 3/3] IIO: hid-sensor-prox: Use generic usage Date: Thu, 17 Nov 2022 00:19:47 +0100 Message-Id: <20221116231947.18031-3-p.jungkamp@gmx.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116231947.18031-1-p.jungkamp@gmx.net> References: <20221116231947.18031-1-p.jungkamp@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:9wBR7jrC/Lf3Jjt57h1uXycSpVR2VuTVgxZMAv4Lljxl614fODW hKlO+Zv7IoM981o+EXoqeEQ7SarA7EJ9jshNicJ+VW78+OOCxnrSjzduCrIbmEb+tawBjrW ZIXIqiekm2xVmhPzpMNHoBAw5ruRgaE9JxcWY/GcmYQX/y+WsWjt6HiWdD+IjxOf6srOZto Wzrssu1h1M+J7K7Fjfoig== UI-OutboundReport: notjunk:1;M01:P0:gHhA4aHBoM4=;KyHzld/pT3aApvLSA4T8vGFm8N3 1eXk4ShNwSKUd0MV6ze5BfNlkk8HFIjVHiwLHcX40PCOMTOEiuej34cKCca5QWG+Zv4L+s+eL sVv1GlYwxYmLuJ+X7G98M4htlhmbM/V8tInciiZAFoFQeIqaFwz4DihX73G/OzpJAFk8SjfqR jjT0Zv0CenHG8VbNo0RSb0UVy0Pm7TXIp+Hcmr/3YbhkVdtbtyD7LK0ij/x50t2sm84Z6Zkir y7X3z9YdFPm2FOlvbh3x7csiUbkjbzUZ2xZZ9dPAolUP2UGjOAnCQRnddQTdvrPyFl69I2s5e TBhb91PHIO1whf5Bo+hAfuGb7n4c9kDBJRVAMKqumcIcHR5X9ppm4+/ZvSYET6EEMWm0emPVy yXjZ2z7GZvmwpAxAkOYLMx0TxeBy5kLtC30QIHqRGK0TAIx/d7kpwbF8LLTggYzNIBc4s6S03 PtsCl6T6lDyeftmWeOdg0q7JpA/oYMRl9OPKnEHKZ0Cg6k7Su1IMWCrnmXJ3K8RQsbtq4uabS qPI1hhxlhq+lTAf4M+dGXs/g55lUs3esqYAEwd7xW0IBjiVq+6laqDWJ6i1NVfChWftdxccsr UA5se87CLD/po13iyTzKHqGPeyFc0hxkVZxgazk1ZPuS/nEUSsKIb348Jof3NwJxODVZe8dHP Cbj2AT/d2/5XtSygShNqPfHU9Xud0i+YTy5rDsxbOqxsaBXzAJV/8k54Mx0vhE4SfBfW6J/VZ 9eIhxlX8qlgc0pa1zohgp6heA/52KpsQo1UE6m0AUd0l0At+7sgcs/2yWKruaLn8wu5SY/GI0 WVTxCZh6WNyt4HLCF7HZ6mq3fKIPpTumGoU+wR+VGgi6AXfWQmpqMtJVJGBzbsT2Atd4EUhBQ iw4TK+ey0qPfykH1yOHqLd9V5HMz3yfrTvhMY0juIB8PNZ9nvY9Ox/qsOCZzZ8ga6rZqpRWlc ic/yjg== 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. Check for raw_len to accomodate the ReportSize(8) field used on the Lenovo Yoga 9 14IAP7. Add the Lenovo Intelligent Sensing Solution (LISS) human presence sensor to the platform device ids. Signed-off-by: Philipp Jungkamp --- drivers/hid/hid-sensor-custom.c | 10 ++++++++ drivers/iio/light/hid-sensor-prox.c | 39 +++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 11 deletions(-) -- 2.38.1 diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index 124493b8abaf..ec49dc80f074 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -795,6 +795,16 @@ static const struct hid_sensor_custom_match hid_sensor_custom_known_table[] = { 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"), + } + }, {} }; diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index f10fa2abfe72..cca6b75c44d5 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,8 +86,9 @@ 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, + hsdev, + hsdev->usage, + address, report_id, SENSOR_HUB_SYNC, min < 0); @@ -191,10 +194,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; + ret = 0; + break; + case 4: + prox_state->human_presence = *(u32 *)raw_data; + ret = 0; + break; + } break; } @@ -244,7 +253,8 @@ 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 +272,8 @@ 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 +302,9 @@ 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 +326,8 @@ 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 +339,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);