From patchwork Wed Mar 3 06:36:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Xiang X-Patchwork-Id: 12114923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9059AC433E9 for ; Thu, 4 Mar 2021 00:30:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A6816023B for ; Thu, 4 Mar 2021 00:30:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442158AbhCDA3w (ORCPT ); Wed, 3 Mar 2021 19:29:52 -0500 Received: from mga17.intel.com ([192.55.52.151]:50156 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841810AbhCCGiH (ORCPT ); Wed, 3 Mar 2021 01:38:07 -0500 IronPort-SDR: c83ZcA82RkRczXgl5i59GxccgYZGylr0JMG86BuoM2IeMQgH4yycrfzhpmRSdbE5lcgugAAzsp +swzsKSf2pTQ== X-IronPort-AV: E=McAfee;i="6000,8403,9911"; a="167012874" X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="167012874" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2021 22:35:57 -0800 IronPort-SDR: Gy3mAPxL2/2WviYYVKUVJHi6hQ4UjNDKPADQJzNEPFb7llQZquOPv8f7Z4bWgwEnfCYCeU79xt GKmB5DG5WRWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="383870896" Received: from host.sh.intel.com ([10.239.154.115]) by orsmga002.jf.intel.com with ESMTP; 02 Mar 2021 22:35:55 -0800 From: Ye Xiang To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ye Xiang Subject: [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel Date: Wed, 3 Mar 2021 14:36:12 +0800 Message-Id: <20210303063615.12130-2-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210303063615.12130-1-xiang.ye@intel.com> References: <20210303063615.12130-1-xiang.ye@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This patch ensures that, there is sufficient space and correct alignment for the timestamp. Fixes: d7ed89d5aadf ("iio: hid: Add humidity sensor support") Signed-off-by: Ye Xiang --- drivers/iio/humidity/hid-sensor-humidity.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c index ec88ae3f233d..74383abc0d44 100644 --- a/drivers/iio/humidity/hid-sensor-humidity.c +++ b/drivers/iio/humidity/hid-sensor-humidity.c @@ -15,7 +15,10 @@ struct hid_humidity_state { struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info humidity_attr; - s32 humidity_data; + struct { + s32 humidity_data; + u64 timestamp __aligned(8); + } scan; int scale_pre_decml; int scale_post_decml; int scale_precision; @@ -129,9 +132,8 @@ static int humidity_proc_event(struct hid_sensor_hub_device *hsdev, struct hid_humidity_state *humid_st = iio_priv(indio_dev); if (atomic_read(&humid_st->common_attributes.data_ready)) - iio_push_to_buffers_with_timestamp(indio_dev, - &humid_st->humidity_data, - iio_get_time_ns(indio_dev)); + iio_push_to_buffers_with_timestamp(indio_dev, &humid_st->scan, + iio_get_time_ns(indio_dev)); return 0; } @@ -146,7 +148,7 @@ static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev, switch (usage_id) { case HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY: - humid_st->humidity_data = *(s32 *)raw_data; + humid_st->scan.humidity_data = *(s32 *)raw_data; return 0; default: From patchwork Wed Mar 3 06:36:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Xiang X-Patchwork-Id: 12114921 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B2F4C4361B for ; Thu, 4 Mar 2021 00:30:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3C8264EE3 for ; Thu, 4 Mar 2021 00:30:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242461AbhCDA3z (ORCPT ); Wed, 3 Mar 2021 19:29:55 -0500 Received: from mga17.intel.com ([192.55.52.151]:50151 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841820AbhCCGiR (ORCPT ); Wed, 3 Mar 2021 01:38:17 -0500 IronPort-SDR: m+zdDewE6wxrFoFKHb2ZbRXnhjeKrgQgg4pv7kEW6BAy4tfDqgd9rn1re0UjwtpQCig4sNPF3C Qval5Zc9Zb5w== X-IronPort-AV: E=McAfee;i="6000,8403,9911"; a="167012884" X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="167012884" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2021 22:36:00 -0800 IronPort-SDR: n841CAA7egzCmxnVOXp/mTQQeI446hcezOqZau0UCHroGA5Lvwp4e4q2IFlvtHhEdBBZe8zaUX qabmyh2hOinA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="383870907" Received: from host.sh.intel.com ([10.239.154.115]) by orsmga002.jf.intel.com with ESMTP; 02 Mar 2021 22:35:58 -0800 From: Ye Xiang To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ye Xiang Subject: [PATCH 2/4] iio: hid-sensor-humidity: Get sample timestamp from sensor hub Date: Wed, 3 Mar 2021 14:36:13 +0800 Message-Id: <20210303063615.12130-3-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210303063615.12130-1-xiang.ye@intel.com> References: <20210303063615.12130-1-xiang.ye@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Try to get sample timestamp from sensor hub first, if failed then use system timestamp. Signed-off-by: Ye Xiang --- drivers/iio/humidity/hid-sensor-humidity.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c index 74383abc0d44..f7b4c76ed94f 100644 --- a/drivers/iio/humidity/hid-sensor-humidity.c +++ b/drivers/iio/humidity/hid-sensor-humidity.c @@ -23,6 +23,7 @@ struct hid_humidity_state { int scale_post_decml; int scale_precision; int value_offset; + s64 timestamp; }; static const u32 humidity_sensitivity_addresses[] = { @@ -131,9 +132,14 @@ static int humidity_proc_event(struct hid_sensor_hub_device *hsdev, struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct hid_humidity_state *humid_st = iio_priv(indio_dev); - if (atomic_read(&humid_st->common_attributes.data_ready)) + if (atomic_read(&humid_st->common_attributes.data_ready)) { + if (!humid_st->timestamp) + humid_st->timestamp = iio_get_time_ns(indio_dev); + iio_push_to_buffers_with_timestamp(indio_dev, &humid_st->scan, - iio_get_time_ns(indio_dev)); + humid_st->timestamp); + humid_st->timestamp = 0; + } return 0; } @@ -151,6 +157,10 @@ static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev, humid_st->scan.humidity_data = *(s32 *)raw_data; return 0; + case HID_USAGE_SENSOR_TIME_TIMESTAMP: + humid_st->timestamp = hid_sensor_convert_timestamp(&humid_st->common_attributes, + *(s64 *)raw_data); + return 0; default: return -EINVAL; } From patchwork Wed Mar 3 06:36:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Xiang X-Patchwork-Id: 12114919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DE4FC43619 for ; Thu, 4 Mar 2021 00:30:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB1A764EC0 for ; Thu, 4 Mar 2021 00:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236672AbhCDA35 (ORCPT ); Wed, 3 Mar 2021 19:29:57 -0500 Received: from mga17.intel.com ([192.55.52.151]:50147 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841823AbhCCGi3 (ORCPT ); Wed, 3 Mar 2021 01:38:29 -0500 IronPort-SDR: QupRfpN9oBzzs6zVIuboLXDxDoZMdk2mqvHukpoBsDxq6zthxHviWdMYu5UUnLmncnlofHcucd aPcxtno4UaWg== X-IronPort-AV: E=McAfee;i="6000,8403,9911"; a="167012902" X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="167012902" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2021 22:36:02 -0800 IronPort-SDR: 1NxdKoDzUvWwhEtx/0uVwLiNyEaT+4EYDyHqLUGY+iyA3yPB99tpZj9MxZPd8Wxtw9MltYeL8D Uh+pPZQ5bibA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="383870919" Received: from host.sh.intel.com ([10.239.154.115]) by orsmga002.jf.intel.com with ESMTP; 02 Mar 2021 22:36:00 -0800 From: Ye Xiang To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ye Xiang Subject: [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel Date: Wed, 3 Mar 2021 14:36:14 +0800 Message-Id: <20210303063615.12130-4-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210303063615.12130-1-xiang.ye@intel.com> References: <20210303063615.12130-1-xiang.ye@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org This patch fixes 2 issues of timestamp channel: 1. This patch ensures that there is sufficient space and correct alignment for the timestamp. 2. Correct the timestamp channel scan index. Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support") Signed-off-by: Ye Xiang --- drivers/iio/temperature/hid-sensor-temperature.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c index e3d38cbcf354..dc534ed784c3 100644 --- a/drivers/iio/temperature/hid-sensor-temperature.c +++ b/drivers/iio/temperature/hid-sensor-temperature.c @@ -15,7 +15,10 @@ struct temperature_state { struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info temperature_attr; - s32 temperature_data; + struct { + s32 temperature_data; + u64 timestamp __aligned(8); + } scan; int scale_pre_decml; int scale_post_decml; int scale_precision; @@ -36,7 +39,7 @@ static const struct iio_chan_spec temperature_channels[] = { BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), }, - IIO_CHAN_SOFT_TIMESTAMP(3), + IIO_CHAN_SOFT_TIMESTAMP(1), }; /* Adjust channel real bits based on report descriptor */ @@ -127,9 +130,8 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev, struct temperature_state *temp_st = iio_priv(indio_dev); if (atomic_read(&temp_st->common_attributes.data_ready)) - iio_push_to_buffers_with_timestamp(indio_dev, - &temp_st->temperature_data, - iio_get_time_ns(indio_dev)); + iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan, + iio_get_time_ns(indio_dev)); return 0; } @@ -144,7 +146,7 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev, switch (usage_id) { case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE: - temp_st->temperature_data = *(s32 *)raw_data; + temp_st->scan.temperature_data = *(s32 *)raw_data; return 0; default: return -EINVAL; From patchwork Wed Mar 3 06:36:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Xiang X-Patchwork-Id: 12114917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2C3AC15506 for ; Thu, 4 Mar 2021 00:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E97364EDF for ; Thu, 4 Mar 2021 00:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240111AbhCDA34 (ORCPT ); Wed, 3 Mar 2021 19:29:56 -0500 Received: from mga17.intel.com ([192.55.52.151]:50156 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841824AbhCCGi3 (ORCPT ); Wed, 3 Mar 2021 01:38:29 -0500 IronPort-SDR: yIfh+60QftoxJaewV0G3QGyUTSm630FeEBeLr0HV2b1l6nGenlxyt0VWgytiq1ptusUbL12lX6 /OwU0CQgnZ6Q== X-IronPort-AV: E=McAfee;i="6000,8403,9911"; a="167012921" X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="167012921" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Mar 2021 22:36:05 -0800 IronPort-SDR: p8PRixu5iICIt0F7j6aYBCTvO75n1qvcpJjSZ7PgSSavIFjUJZbG53rGiC5ERXthdLGpPpxWhb PLQ1PRooPStg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,219,1610438400"; d="scan'208";a="383870931" Received: from host.sh.intel.com ([10.239.154.115]) by orsmga002.jf.intel.com with ESMTP; 02 Mar 2021 22:36:03 -0800 From: Ye Xiang To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ye Xiang Subject: [PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub Date: Wed, 3 Mar 2021 14:36:15 +0800 Message-Id: <20210303063615.12130-5-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210303063615.12130-1-xiang.ye@intel.com> References: <20210303063615.12130-1-xiang.ye@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Try to get sample timestamp from sensor hub first, if failed then use system timestamp. Signed-off-by: Ye Xiang --- drivers/iio/temperature/hid-sensor-temperature.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c index dc534ed784c3..0d8110735779 100644 --- a/drivers/iio/temperature/hid-sensor-temperature.c +++ b/drivers/iio/temperature/hid-sensor-temperature.c @@ -23,6 +23,7 @@ struct temperature_state { int scale_post_decml; int scale_precision; int value_offset; + s64 timestamp; }; static const u32 temperature_sensitivity_addresses[] = { @@ -129,9 +130,14 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev, struct iio_dev *indio_dev = platform_get_drvdata(pdev); struct temperature_state *temp_st = iio_priv(indio_dev); - if (atomic_read(&temp_st->common_attributes.data_ready)) + if (atomic_read(&temp_st->common_attributes.data_ready)) { + if (!temp_st->timestamp) + temp_st->timestamp = iio_get_time_ns(indio_dev); + iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan, - iio_get_time_ns(indio_dev)); + temp_st->timestamp); + temp_st->timestamp = 0; + } return 0; } @@ -148,6 +154,10 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev, case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE: temp_st->scan.temperature_data = *(s32 *)raw_data; return 0; + case HID_USAGE_SENSOR_TIME_TIMESTAMP: + temp_st->timestamp = hid_sensor_convert_timestamp(&temp_st->common_attributes, + *(s64 *)raw_data); + return 0; default: return -EINVAL; }