From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DE2938E5C8 for ; Thu, 14 May 2026 20:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778788996; cv=none; b=YcxxiGb8AMqGab9RUOta3nABmoXx0geB+kaVvBg/MekiwGr65IB8f1z0VkStgQxxi44PSqwA8uNJtVpzleWZ8H6yBpvu2i8YqTPMLO3Mz+APEwRLXnbJPoR/ynOVDfQKC9QbGM67h7o0pxQxzlM2CXhlFtvFYgS54Xmv7Tr29vs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778788996; c=relaxed/simple; bh=JyaFkUWgtfBo+oIhi7/QYewpDXo+BM1/a5j4udwAjiI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=qCz4d2GuT92X79kBF8syb01DDU1WkSowtOW0u20cBeKLwAaJtEwSW4E38FZabY1gB2+vJVR1naadZUF17EX6kVq9m1e0G2DcOgsEom0PxQ1JkcyolEPpMBX06ZOQgm8f+RL51NNRcrBrD2LMOQ/LPB8q0bwN6cDYSa0xEqiOF/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MbYcA7/9; arc=none smtp.client-ip=209.85.208.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MbYcA7/9" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-38e7d983f91so81486831fa.2 for ; Thu, 14 May 2026 13:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778788993; x=1779393793; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uqdLGbe9sGAYV6Jg54APm3n/EVTOhUOxE0f13Hm3Zss=; b=MbYcA7/9+LdtAu5vOqfqScpNiyb07CMiPQwP8E3r95Ly5hFJXixVtn1m10qN1doydJ 2HDym+RlX6X9h0VVk10nOSc2PpTwjNx945oscql6p7tIcnD9Gn82kB9wmKm2CAVR4QFA lTsEA//5EV04HlaWGhX+Pyw00+QEyAtDVE7M22/sSoFeaphqLMCha3x/px0OX3SFt6NP 8EmBOpmXYR5JtSnsBaP5V1oie1eZXve7BIqeietu27ih5fRTB4UPNxIHtGT1pZZiehHi OTszPVOHb4GpJweBLyx0bpJMSq45Zwh54Hu4k4q+zCC2RJ5vKqAQ56xywUHf1RfUbGzi gFXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778788993; x=1779393793; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=uqdLGbe9sGAYV6Jg54APm3n/EVTOhUOxE0f13Hm3Zss=; b=McgWoJmBgBplqbrLgMXlAYtwm98rLRBkKQRE3Ki9VghnvYfBSPXKJlkXPljsPJgX8L cDEEuA+affFMxCeizvXZtAi/Lr2OR1KniQrISdDkdbsgLTI6vUNKCwULRjl1Wm8+pi5J NAG/1U8yaPN31WumFL/fNGv1t04ZGZLE1HvTLgNbhuqsVre25dlvySkpRLiWrCyE50Z5 19HRDQ/NCt5KRcwF+WMSZVlXPWeA/cR+x3FQqEQ07Pvh8LmeR+1g77o3iE3GWlBZXfgQ Jl8GO8k/bSBXes/KNxOADv3MCkz2rMnc7V5XuHvHqwpZK25iW5KLgw0d5eNWTzeNVRL3 8Vrg== X-Forwarded-Encrypted: i=1; AFNElJ+S1ERGlzsPGqm5273DpoSvkG2hj5CphpzGWIVk+fp1ySF14RRhof84BD3V2a5G480E4UOo6bI4E19EhdE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1F7uHTjXEkZvUWyOg4GbnN6kpqtoyYsityNs9rRIJjmybit7E D+U+0yfYtn2gKRXtUr7LjRIKd1iYmxqGFckMuPhOxMc/g7ZMG3AbCXzr X-Gm-Gg: Acq92OH94OLJ0sjeR/6mPHryw6OkJsICp8Eu9G1Ery1oQY2P7GXmmcYqwYcC731lDP3 3eqscW2ElOKW9OhOJ8BmwSecmf8J4ymVKQ79DkkEkNkJCk6OxzD4M0sZjAnPzwiNq3HoGiXMtPq +ouh+R2f1AgTgIhiDmbctCfHlfhk4KyRIcAFaNZQPe8mN4l59wdGUioI49mJ+8tLZsFLq21CvEG LQhu16Lcd/3guC01ao/mYFHh4VwbAPmwqAe45/kRLFFUwto6X2us88/MBZjTZKDQia+oLt9Kkhe 5/uA7Z+In1marO3BPT8MBmElyxwfWFrXTnxPa7oCC4f++2+PHw9cWYC/Jwd5UHJt57GawZInWk/ kBV3w0ae+SwFHt+xR5XvK4KnVw8ynemHIJVkYKueWXi1XNHcnIpNIJEiIgBk8ioBmeyhXQcLeeT wEn/tI2U8UADREZh5P9X/WV927cglCSM4HgTPW8esSsr91hhHIuprkUGq23ofCkgxr X-Received: by 2002:a05:6512:4016:b0:5a8:e5a0:e0f4 with SMTP id 2adb3069b0e04-5aa0e6133femr155683e87.12.1778788992644; Thu, 14 May 2026 13:03:12 -0700 (PDT) Received: from Shofiq (87-92-218-151.rev.dnainternet.fi. [87.92.218.151]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a9164bc166sm682710e87.46.2026.05.14.13.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 13:03:12 -0700 (PDT) From: Md Shofiqul Islam To: linux-iio@vger.kernel.org Cc: jic23@kernel.org, lars@metafoo.de, linux-kernel@vger.kernel.org Subject: [PATCH] iio: health: max30102: Add timestamp to FIFO data Date: Thu, 14 May 2026 23:03:09 +0300 Message-ID: <20260514200309.1597-1-shofiqtest@gmail.com> X-Mailer: git-send-email 2.54.0.windows.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The I2C DMA read buffer was not aligned to IIO_DMA_MINALIGN, which can cause issues on platforms with strict DMA alignment requirements. Fix this by annotating the buffer field with __aligned(IIO_DMA_MINALIGN). Replace the plain processed_buffer[] array with a packed scan struct containing the channel data and an aligned_s64 timestamp field. This satisfies the alignment requirement for iio_push_to_buffers_with_timestamp() and ensures correct layout when the IIO core appends the timestamp. Add IIO_CHAN_SOFT_TIMESTAMP entries to both max30102_channels[] and max30105_channels[] so the IIO core knows to expect a timestamp slot in the scan buffer. Capture iio_get_time_ns() per FIFO sample read and pass it to iio_push_to_buffers_with_timestamp() so userspace consumers receive timing information alongside the intensity data. Signed-off-by: Md Shofiqul Islam --- drivers/iio/health/max30102.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/iio/health/max30102.c b/drivers/iio/health/max30102.c index 47da44efd68b..447c4de8ff4b 100644 --- a/drivers/iio/health/max30102.c +++ b/drivers/iio/health/max30102.c @@ -24,6 +24,7 @@ #include #include #include +#include #define MAX30102_DRV_NAME "max30102" #define MAX30102_PART_NUMBER 0x15 @@ -106,8 +107,11 @@ struct max30102_data { struct regmap *regmap; enum max30102_chip_id chip_id; - u8 buffer[12]; - __be32 processed_buffer[3]; /* 3 x 18-bit (padded to 32-bits) */ + u8 buffer[12] __aligned(IIO_DMA_MINALIGN); + struct { + __be32 channels[3]; /* 3 x 18-bit (padded to 32-bits) */ + aligned_s64 ts; + } scan; }; static const struct regmap_config max30102_regmap_config = { @@ -152,6 +156,7 @@ static const struct iio_chan_spec max30102_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), .scan_index = -1, }, + IIO_CHAN_SOFT_TIMESTAMP(2), }; static const struct iio_chan_spec max30105_channels[] = { @@ -164,6 +169,7 @@ static const struct iio_chan_spec max30105_channels[] = { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), .scan_index = -1, }, + IIO_CHAN_SOFT_TIMESTAMP(3), }; static int max30102_set_power(struct max30102_data *data, bool en) @@ -253,7 +259,7 @@ static inline int max30102_fifo_count(struct max30102_data *data) } #define MAX30102_COPY_DATA(i) \ - memcpy(&data->processed_buffer[(i)], \ + memcpy(&data->scan.channels[(i)], \ &buffer[(i) * MAX30102_REG_FIFO_DATA_BYTES], \ MAX30102_REG_FIFO_DATA_BYTES) @@ -298,11 +304,13 @@ static irqreturn_t max30102_interrupt_handler(int irq, void *private) mutex_lock(&data->lock); while (cnt || (cnt = max30102_fifo_count(data)) > 0) { + s64 ts = iio_get_time_ns(indio_dev); + ret = max30102_read_measurement(data, measurements); if (ret) break; - iio_push_to_buffers(data->indio_dev, data->processed_buffer); + iio_push_to_buffers_with_timestamp(indio_dev, &data->scan, ts); cnt--; } -- 2.54.0.windows.1