Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp14447714pxu; Tue, 5 Jan 2021 01:37:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5hT1XIEGPH8LTlTFZiZCvZR9Te7Mix61X89yf3ahw2FKdnYAiSqDhadyuJ68hmkvhr1hX X-Received: by 2002:a50:9f4a:: with SMTP id b68mr74120100edf.296.1609839426058; Tue, 05 Jan 2021 01:37:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609839426; cv=none; d=google.com; s=arc-20160816; b=lOcLXpewvlQ/IB4BRm+4S3Kps4O7i9doFuwsXEZR1otyoKaYsh/VlMHIEekJak7Xmw f1ofQfFrZ3G0pUw3tl7mafmIWhR5mB2xE9u5gIZJIpiF2YWsJngGKV6Q3IXanvazCgQO ZgZWilLfqkmW0P3ZzRE+NQnGfc6uswaZYt49zXCkN8U4eQl7pmCGVlTv8JEDK1sWMpE0 oZSgXbH/zIit2ATO8Mz/xGfzNxWgwt/4ee5HvbwLXwhBwY9GJc4u5kMmJ/7xzMSeFpcE yIvt1G7HjFiD3ruBErhOHw2IWPsw1F6lWpWKonEHYeHa64GNW0CqmxG26Pml3Iwa/8bk FTaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=m+BYd4x5eMh+4NQrahbRTKSOThz21dtxkl4Z/JZ22Y0=; b=N+IEGj96DL3mkTBLtuAY667mmQSR33aJElYR+QwW8qNfXh41ncdboD8Djr2DrL8eo3 p/4z4wRS5XcqL0KJC9lwBIgmYCrf7IWEOT2iMjTTiqvozwEQEoMk5sSy6kHj/ooCSfEj lU8mZcy/UWM6pi6zKRLZP7C7+PjXUFFDsyfr0kzo51XT2AGvMQLXil5vDTrzK9sOi7ai ryXyJtbdI6ig3SQhKxSpqnM4F9IXZt8sdhnL+3EdMmOr7JMz8rRgFxz1aj33jb8g2n5z v2tZRvpO4rlgRL0UIDUcK3jBwQpiA0CovCZVLHaRY1qvrx87+bLjegZX16vHtdzq+IJ/ Dhhw== 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 n25si30974043edw.77.2021.01.05.01.36.42; Tue, 05 Jan 2021 01:37:06 -0800 (PST) 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 S1728402AbhAEJfE (ORCPT + 99 others); Tue, 5 Jan 2021 04:35:04 -0500 Received: from mga17.intel.com ([192.55.52.151]:51525 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbhAEJfB (ORCPT ); Tue, 5 Jan 2021 04:35:01 -0500 IronPort-SDR: pqsdM/7mqejmQpnLd/6GhATl/29sUsrh9ip6PzZLSCj08Lv+Zs7eogcxAgOw5ScH9shmDc3bLm w+HrgCKzTKOw== X-IronPort-AV: E=McAfee;i="6000,8403,9854"; a="156864097" X-IronPort-AV: E=Sophos;i="5.78,476,1599548400"; d="scan'208";a="156864097" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2021 01:34:12 -0800 IronPort-SDR: Nvc985u7Lh5kDG9XupQ5MtKpcstNMQFRpf6MjGH/Eo2AV2AQv00ADNKxMxM81EJGXtRezmItle L5IrIhHeQd7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,476,1599548400"; d="scan'208";a="569665174" Received: from host.sh.intel.com ([10.239.154.115]) by fmsmga005.fm.intel.com with ESMTP; 05 Jan 2021 01:34:11 -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 5/6] iio: hid-sensor-incl-3d: Add timestamp channel Date: Tue, 5 Jan 2021 17:35:14 +0800 Message-Id: <20210105093515.19135-6-xiang.ye@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210105093515.19135-1-xiang.ye@intel.com> References: <20210105093515.19135-1-xiang.ye@intel.com> 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. And the unit of timestamp is nanosecond. Signed-off-by: Ye Xiang --- drivers/iio/orientation/hid-sensor-incl-3d.c | 43 ++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c index df2fe91e8117..3baa52fbb426 100644 --- a/drivers/iio/orientation/hid-sensor-incl-3d.c +++ b/drivers/iio/orientation/hid-sensor-incl-3d.c @@ -24,15 +24,21 @@ enum incl_3d_channel { INCLI_3D_CHANNEL_MAX, }; +#define CHANNEL_SCAN_INDEX_TIMESTAMP INCLI_3D_CHANNEL_MAX + struct incl_3d_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX]; - u32 incl_val[INCLI_3D_CHANNEL_MAX]; + struct { + u32 incl_val[INCLI_3D_CHANNEL_MAX]; + u64 timestamp __aligned(8); + } scan; int scale_pre_decml; int scale_post_decml; int scale_precision; int value_offset; + s64 timestamp; }; static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = { @@ -81,7 +87,8 @@ static const struct iio_chan_spec incl_3d_channels[] = { BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_HYSTERESIS), .scan_index = CHANNEL_SCAN_INDEX_Z, - } + }, + IIO_CHAN_SOFT_TIMESTAMP(CHANNEL_SCAN_INDEX_TIMESTAMP), }; /* Adjust channel real bits based on report descriptor */ @@ -186,13 +193,6 @@ static const struct iio_info incl_3d_info = { .write_raw = &incl_3d_write_raw, }; -/* Function to push data to buffer */ -static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len) -{ - dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); - iio_push_to_buffers(indio_dev, (u8 *)data); -} - /* Callback handler to send event after all samples are received and captured */ static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev, unsigned usage_id, @@ -202,10 +202,16 @@ static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev, struct incl_3d_state *incl_state = iio_priv(indio_dev); dev_dbg(&indio_dev->dev, "incl_3d_proc_event\n"); - if (atomic_read(&incl_state->common_attributes.data_ready)) - hid_sensor_push_data(indio_dev, - (u8 *)incl_state->incl_val, - sizeof(incl_state->incl_val)); + if (atomic_read(&incl_state->common_attributes.data_ready)) { + if (!incl_state->timestamp) + incl_state->timestamp = iio_get_time_ns(indio_dev); + + iio_push_to_buffers_with_timestamp(indio_dev, + &incl_state->scan, + incl_state->timestamp); + + incl_state->timestamp = 0; + } return 0; } @@ -222,13 +228,18 @@ static int incl_3d_capture_sample(struct hid_sensor_hub_device *hsdev, switch (usage_id) { case HID_USAGE_SENSOR_ORIENT_TILT_X: - incl_state->incl_val[CHANNEL_SCAN_INDEX_X] = *(u32 *)raw_data; + incl_state->scan.incl_val[CHANNEL_SCAN_INDEX_X] = *(u32 *)raw_data; break; case HID_USAGE_SENSOR_ORIENT_TILT_Y: - incl_state->incl_val[CHANNEL_SCAN_INDEX_Y] = *(u32 *)raw_data; + incl_state->scan.incl_val[CHANNEL_SCAN_INDEX_Y] = *(u32 *)raw_data; break; case HID_USAGE_SENSOR_ORIENT_TILT_Z: - incl_state->incl_val[CHANNEL_SCAN_INDEX_Z] = *(u32 *)raw_data; + incl_state->scan.incl_val[CHANNEL_SCAN_INDEX_Z] = *(u32 *)raw_data; + break; + case HID_USAGE_SENSOR_TIME_TIMESTAMP: + incl_state->timestamp = + hid_sensor_convert_timestamp(&incl_state->common_attributes, + *(s64 *)raw_data); break; default: ret = -EINVAL; -- 2.17.1