Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2073914pxt; Sun, 8 Aug 2021 10:33:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmkcmghsyVMOUYKzVHqH723KzK3U4rsy7dEC5yBwFfAyiang55SoE26eDeOjkaWY1R98PC X-Received: by 2002:a5d:8b17:: with SMTP id k23mr140102ion.17.1628444030774; Sun, 08 Aug 2021 10:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628444030; cv=none; d=google.com; s=arc-20160816; b=IyS95pwlf/E4HmjA2f+A2OtoREO+pEf/VZGYPuL+bGxhlWJGOY0H/k39UcIcXkTx+v MA9MOM9P8LpOx2RK4fi+IXbGFeuMs1iu4fSzk/m/yGhT1WaiO2D0PXYGWjzOlK+sy9Af ch/V2zbfQkMIN/Jdp1i8uAEcTvWOZ4xyosdAJ+JsEfslaQzkNFLsr528sbiShzOq/v8K 0oh7aJ5IO5WIuT2X4YRtnYCx6AQzcS4V26OsfKbpiCJyrPZoqwfYaAqUo7NA8zH6W7np LNRvvN1PErtWjzAIG2nXYmJNtnJoK6T5CuwCBT4TtreXdgv7VDx6/TRO7yHFVz15Sew5 6/KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=7NcFj7ItRnJIwx7ut8K/dwyznxP7/4sgQZzGtXvVqBY=; b=IeBGO11PYacioQkTTZ29aXjcvQZddpXfOf/srX0aYYvSs1zRDacu+M49ayeXWaLsSI kcRxXinW9pHTBibSZu2k414PaCJQtbjmuHrIExdN/GIEOiLiN6dCBZozU3onZ4deI5Fp NOTTX9I4XEV83aveF25vql3FROsfU7WX4JYumSKauCmh8PARnu22zVsE8bKO0IJ6I5lO I3mPwM4KqUUOoEP3BKLucF3or+IhkvP5xFWNMrGVM35KpETILdMsR90IkqwQaqV1sv4Z PsPONNDtpdg0/1YXsPS0qh2wohp9lEonJf9q+egpL7hNhJ1hVauKB4wL+xgDSRwt+9CO 72Cg== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si14484871jar.87.2021.08.08.10.33.37; Sun, 08 Aug 2021 10:33:50 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232180AbhHHR2t (ORCPT + 99 others); Sun, 8 Aug 2021 13:28:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:56648 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231486AbhHHR2q (ORCPT ); Sun, 8 Aug 2021 13:28:46 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F016260F0F; Sun, 8 Aug 2021 17:28:25 +0000 (UTC) Date: Sun, 8 Aug 2021 18:31:15 +0100 From: Jonathan Cameron To: Ye Xiang Cc: jikos@kernel.org, srinivas.pandruvada@linux.intel.com, linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: hid-sensor-press: Add timestamp channel Message-ID: <20210808183115.31df0580@jic23-huawei> In-Reply-To: <20210731032556.26813-1-xiang.ye@intel.com> References: <20210731032556.26813-1-xiang.ye@intel.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 31 Jul 2021 11:25:56 +0800 Ye Xiang wrote: > 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 Applied to the togreg branch of iio.git and pushed out as testing to let 0-day see what it can find. Thanks, Jonathan > --- > 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; > }