Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp105980pxv; Fri, 30 Jul 2021 20:26:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHvEsRY/rMBCXIOtZ3ZK4GgVjf0JQBP+GVryZXLIHdkRsssHtz6/oHvO7xL8aRQPwZvCvI X-Received: by 2002:a17:906:7b49:: with SMTP id n9mr3726013ejo.299.1627701973543; Fri, 30 Jul 2021 20:26:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627701973; cv=none; d=google.com; s=arc-20160816; b=LWcqwZdRzdgGNyhTFB4dctT4rVmT5G48UqKBxL3IF9RJRIvUGbBTHIgcQG4d8NKVR3 G6/cNwZlwdS4QiJGZv9uQvJcyclf2khF7YdmN7M3+9I8v4sDtBvAPvSKX0X0Erx2uIqL kWzkW40bud4fV4VF7bm1ZMWVQn5n46xmKdIO1iRpYK1EdrgFzaOYSBKV0fgC7uaVIfUm EqFTO3mZ8JCekbmq4eVn1gzehR2amu5czGu4Im5v8WY/NPKijlNOguHUsdWKXelvtcMy mxv+dGKISRzgD+XaakUKJH0hX8iM3/Kzdjb4jCzrVaRdRXJ0slgVwafkJwuTf/A1vNLt clTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=l4MGW4wS50KoAtX30Vv2oYIVRxx6mi89jKPkafQfQiE=; b=tN/ikNUFM9UYhI3l36J9jl7E5Z4FCBurb8CnwB2DcfE4J3gg8Ky8007R8S2ltRdthP s0R1CsCHzeKX9CNmv7cgrJlOTneuSg50UtI8ltvAHNN+XFNiAXAw3Z89Ra/wnhSadQ9W NzjPzmmQ15+tFoj82ESkhjLgwPZZEJPEwsiWBk0gzJ+ZVCs5Rfqb44EKx75A7mPbs49Y mgBw0CUusCgwyDR1+JxF9b0nCkddrxIsyoCOdzNuCS9xKfwdWuf4+Skkyz9Voc86rnHG M+Tm6F+ljzYcdaxr9uGhBTQXUPy65coV+NPAybwBYCB7bfewdVVXFboG2/CKq6MwqO5+ XJwg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n10si4406429ejk.210.2021.07.30.20.25.28; Fri, 30 Jul 2021 20:26:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbhGaDWh (ORCPT + 99 others); Fri, 30 Jul 2021 23:22:37 -0400 Received: from mga18.intel.com ([134.134.136.126]:37975 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbhGaDWf (ORCPT ); Fri, 30 Jul 2021 23:22:35 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10061"; a="200408406" X-IronPort-AV: E=Sophos;i="5.84,283,1620716400"; d="scan'208";a="200408406" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2021 20:22:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,283,1620716400"; d="scan'208";a="439414699" Received: from host.sh.intel.com ([10.239.154.115]) by fmsmga007.fm.intel.com with ESMTP; 30 Jul 2021 20:22:27 -0700 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] iio: hid-sensor-press: Add timestamp channel Date: Sat, 31 Jul 2021 11:25:56 +0800 Message-Id: <20210731032556.26813-1-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each sample has a timestamp field with this change. This timestamp may be from the sensor hub when present or local kernel timestamp. The unit of timestamp is nanosecond. Signed-off-by: Ye Xiang --- drivers/iio/pressure/hid-sensor-press.c | 40 +++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/iio/pressure/hid-sensor-press.c b/drivers/iio/pressure/hid-sensor-press.c index c416d261e3e3..b365483bd09e 100644 --- a/drivers/iio/pressure/hid-sensor-press.c +++ b/drivers/iio/pressure/hid-sensor-press.c @@ -16,17 +16,24 @@ #include #include "../common/hid-sensors/hid-sensor-trigger.h" -#define CHANNEL_SCAN_INDEX_PRESSURE 0 +enum { + CHANNEL_SCAN_INDEX_PRESSURE, + CHANNEL_SCAN_INDEX_TIMESTAMP, +}; struct press_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info press_attr; - u32 press_data; + struct { + u32 press_data; + u64 timestamp __aligned(8); + } scan; int scale_pre_decml; int scale_post_decml; int scale_precision; int value_offset; + s64 timestamp; }; static const u32 press_sensitivity_addresses[] = { @@ -44,7 +51,9 @@ static const struct iio_chan_spec press_channels[] = { BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), .scan_index = CHANNEL_SCAN_INDEX_PRESSURE, - } + }, + IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP) + }; /* Adjust channel real bits based on report descriptor */ @@ -157,14 +166,6 @@ static const struct iio_info press_info = { .write_raw = &press_write_raw, }; -/* Function to push data to buffer */ -static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, - int len) -{ - dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); - iio_push_to_buffers(indio_dev, data); -} - /* Callback handler to send event after all samples are received and captured */ static int press_proc_event(struct hid_sensor_hub_device *hsdev, unsigned usage_id, @@ -174,10 +175,13 @@ static int press_proc_event(struct hid_sensor_hub_device *hsdev, struct press_state *press_state = iio_priv(indio_dev); dev_dbg(&indio_dev->dev, "press_proc_event\n"); - if (atomic_read(&press_state->common_attributes.data_ready)) - hid_sensor_push_data(indio_dev, - &press_state->press_data, - sizeof(press_state->press_data)); + if (atomic_read(&press_state->common_attributes.data_ready)) { + if (!press_state->timestamp) + press_state->timestamp = iio_get_time_ns(indio_dev); + + iio_push_to_buffers_with_timestamp( + indio_dev, &press_state->scan, press_state->timestamp); + } return 0; } @@ -194,9 +198,13 @@ static int press_capture_sample(struct hid_sensor_hub_device *hsdev, switch (usage_id) { case HID_USAGE_SENSOR_ATMOSPHERIC_PRESSURE: - press_state->press_data = *(u32 *)raw_data; + press_state->scan.press_data = *(u32 *)raw_data; ret = 0; break; + case HID_USAGE_SENSOR_TIME_TIMESTAMP: + press_state->timestamp = hid_sensor_convert_timestamp( + &press_state->common_attributes, *(s64 *)raw_data); + break; default: break; } -- 2.17.1