From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796369521; b=srqcL7HpXTTr77GF3H9DsDQIHj6alTXTr164/TlAUO8xJd1N+SFM2Wvo4WpvKRzU3B8f gMfvko8X7/apwWNgvOikg1ANLWaY3VDjsnwZXrZEBX52gPMn36aS3oL5dLp/cKAJw1FWB orbHYLd+QJ4uiDxjHfCTZbXWpkoOLtkWtgi2+tIQKC0itEjD6Jplhlp8GLdqAKsMXFO90 gRW9DAuIoeY50UDfADAJqj0tUg8vL3S6OT42v5lXu42ePhWYPaXmfDRRtDEWc9EWU2pYj GsQigPZiUhGpqNsXQzpEXPuRlUw7x8AZC7+5stKLFz4VGTbH5O6FWHZt5GXO02uwawA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796369521; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Authority-Analysis:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=pZmsolm1VZJomQyG7Btxlb46BMu/HQp6oHU5i/0LbX0=; b=tPMENer8/unHFQSxqevO0HwP3mzmLwYtWFrcMOHWn7nHpSzlyGWhxL2iuikJLbkUdIPP IjNpVbTklCQoQZ9nzyRrxw9bu4uUcYFQDyeCNBTb1y6rtjCsUyXWIYQPDm67jio5kWNd+ rPpkuQfAovAGavnHLnybumtMrWrFHK9jwvvbnni/yM1dZCPLLIAO190YRpqr6E6wR91lk GA5VZCqtcU7Z9b1RTGq7CK3Qzu/2KzGRYt4NDAgqPJ4giVnHioaK9g3zdx3NGZypX7R0F jMIjwMfxeN4uLfQrTXksOGssEcnNb99hVQ5rI0E6sUG5tA9kbHBXyZxirJ+VIcelhGg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OvvXKMrY; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=FdebtPBI; arc=none smtp.remote-ip=205.220.180.131 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D802606A32C for ; Fri, 4 Dec 2026 07:32:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3D802606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OvvXKMrY; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=FdebtPBI Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B45LPpZ2087419 for ; Fri, 4 Dec 2026 07:31:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= pZmsolm1VZJomQyG7Btxlb46BMu/HQp6oHU5i/0LbX0=; b=OvvXKMrY5gWrvZki TQ7ix9fEIZeIOxnOPcnQcTlOrPgFaQOa5U4sPfoxOogcMuqaJYXiw/ofCcgTTwQY TvUdjuxuk31+G/1Ovg9gmzu4rqgdbprIr6WF/xIu2bRO1KzQZIMy60VaODQUTiP4 jmM5norR+CjQV+x9q21dEw/lXs7vQ7vI+SP/KhRhHLipTLZnMIuQcrU0QvpaRCR3 kBiGnPTyTc9Thpb+ES7IBbS29bC3JZL6iOOQG/w4wvFVLhIdc0f328/yT3jHMgOI h3mNfSm4BVunbtoK+FJKq0+jkDQO/e0D5/eRj9O/2kPw5JEQWcnHK7HCxVkGPz7b +ta3sw== Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4jbq7qgdb0-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 04 Dec 2026 07:31:53 +0000 (GMT) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-93f2c0e6653so103492285a.1 for ; Thu, 03 Dec 2026 23:31:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796369512; x=1796974312; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=pZmsolm1VZJomQyG7Btxlb46BMu/HQp6oHU5i/0LbX0=; b=FdebtPBIRMCkRHcwIkTJZbpXid8mHZQXmfmPa9FhTWhU+xSOD0CasyuNqwehsDweR1 wx3ArCIoIU5UAmnrFq91oYjvGXr0+q2YZPu1OvVnBxyc3ZshC/83pytXlzE63k+CB9Hy 789CR6bXAaiqtPUD8hp+tFdVSX4lmCKa/EqAw+TW74f3157R93qmAw+5OD9kqRjQkhgy 9NyCHQKeiilittML+w9lSSAJA23KQkeBZvV+Jv8/K/++YREd0T7WVYJV7H6dFPMO3ZGH Qy5bmBWLpEG1MEHdT2I+cXpB4rrhC621m9cstp9y/aKVDOCymawXUk5q0+nkf6VV206X YRcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796369512; x=1796974312; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pZmsolm1VZJomQyG7Btxlb46BMu/HQp6oHU5i/0LbX0=; b=ONkiKXZlJAIlW/VlY4MFfSRmzeI1AYTQKgoYechJDu6PzwytNCe9a9kmk2QGoL5xH5 /4wTl//tiaA+HeZyxF6Zi/wllQWKAT7Uw+WTAt5U/zbZVsy6fZ84wRhtC3fncLw0z9be +UBuaXikNJh8ZwvaF6osMsizl9i58y90NcHJmFP8jaeCGDyOcdDkkXXMp8/799ecZr7f wLlFdtxVrytGAo2jsqLHdGq7mk7o3v+E7buF/nF1TvcbcF31CwHSv+0/nErTckbFIMiF 6b8SUQazI6yH+13sFkjZ2nywleHgQJ/QrziQpVNQZTRkVEsRzRD2r1zw0dKm4w1xEewg s02g== X-Forwarded-Encrypted: i=1; AL+hErFHds3H4AOsmMYZndGJKZVwMN4/2977ZDD50eTkYMUQl58c2X4WC6nzoE38iOm7ns5S+qzhVB6bO2OZKEA=@vger.kernel.org X-Gm-Message-State: APuU4Z+axNgIG4i4krNL4xQMkg4FhlwxqxWOOOLZ0wpQLZZZFPL2c63l YyrKYNUoVDD+AVXqrArTFMtrEW6W7LLxQYiRjIXsv6x6rffNw8g6L2fdq0qhfQtkLxoUfIDlA7V pwT1zOm2+A1IQVyc0XuD71LYPfmcBs4m4TqBw2BPXBS9S0H10Zy81NOKMzzaTAJl4teE= X-Gm-Gg: AZFdTZfpoXlMLCQtqW8F4lUSNmjtYtMcdIv+g4+1Vqd7hRNqnvE/jhYb9zkIGzulMiD 8LdgAIKUntW0/INM3AJjlFrf5bzi3A1HgUDpqFUYsHGdNf2J/sYiHQ3AEcy4gcTcbTyOUre4Z6X IhJvn0XYPqifXd0fl0lkQTNNy0l4Xwm9M8zkOkwGBuBe+i2TAjab0zNyCvW/81f2H2hKCvhfNIQ JzkZyhbDrhBjFkcbfPwr5LGYUB9LkvaWgjTrTsymIMwa4BuORlK/K+Q22iSc/IwuYs94AMn1o96 9TbOsxe7Dpgwx/uQKF6ESF/tixLKSuuoUD10Byh2h0RDtWK8w0FpBgdXW6v4v3/SWQ73+b2icgx MUNWOIcgEnCO9SF07JytxRT+hDpIQK40Hfcfrz11sGPnGCPbUaWrX2ZRX7Jb2+Ck2lQCtNSrwo/ CZ70tzL4qrLbnZ X-Received: by 2002:a05:620a:4011:b0:93f:43a4:a47e with SMTP id af79cd13be357-94a827e7129mr203629885a.43.1796369512357; Thu, 03 Dec 2026 23:31:52 -0800 (PST) X-Received: by 2002:a05:620a:4011:b0:93f:43a4:a47e with SMTP id af79cd13be357-94a827e7129mr203625785a.43.1796369511722; Thu, 03 Dec 2026 23:31:51 -0800 (PST) Received: from [192.168.25.64] ([94.155.124.210]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00daf7fsm144515765e9.13.2026.12.03.23.31.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 23:31:50 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 09:31:50 +0200 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 02/14] media: qcom: camss: csid: Add an operation to read the SOF timestamp To: Loic Poulain , Mauro Carvalho Chehab , Bryan O'Donoghue , Vladimir Zapolskiy Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org References: <20261203-camss-hw-ts-v4-0-c271022b4b0d@oss.qualcomm.com> <20261203-camss-hw-ts-v4-2-c271022b4b0d@oss.qualcomm.com> Content-Language: en-US From: "Gjorgji Rosikopulos (Consultant)" In-Reply-To: <20261203-camss-hw-ts-v4-2-c271022b4b0d@oss.qualcomm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=Cpsq4X4D c=1 sm=1 tr=0 ts=6b126c69 cx=c_pps a=hnmNkyzTK/kJ09Xio7VxxA==:117 a=eGCDHFSXubCXFTSSGhjuOA==:17 a=n8IlR8rfZ27013JM:21 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=azFTyTkHoo-1bBfbsA4A:9 a=QEXdDO2ut3YA:10 a=PEH46H7Ffwr30OY-TuGO:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDAyOSBTYWx0ZWRfX/YZD/qg2S6Xx urevdIW/ET1ATAvwKH7IhKFYdLQhDdd49H+K5m0ezFwEkQ8g0J0fqvpCIX1xB2cEKUzQ1AAVQII R8CupAXzDM/s/IQedcQf0uaQCnzfa+8= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDAyOSBTYWx0ZWRfX5NEVgyNI5oCj sDNLpgLNRd5mgCAbGM+SozQ+5BijO3rS/HP/90q7XEu+inh6aXYFQ9s35BM4g27bWon7xRPiHuA SXEntvyhdTEFpS94fTqeiwaU3kq7AK/3reJqDbZCtmzrc8r7CWa1nlpCHSYxJSOk6QNMjtq83RH d0FxF9Nz1R2Ek2dwLM89CyiRA8Ye66OJStZaOl2CzTkTU9BcS5k2zuVRi5XFRcji5ekGPohC+8h xcJeAlkcUls7q4EoKPiENxF8UsZbrd0kzr9m9XfKbX/9yB6zbHLQ0m4QXg2QDw6gDpQycZvCMo5 iKb7VR8bdoh1d8eUZFV9pazANrzkZoABAJLFUMRU/2pN+xkYerszC3VdmaaJP+ayKATdUJ0LteM 01wROt3cQYNPd7wHG5msrkOukvPqmWzoCgSRFYPSrm9TdvxmCYsb2f3e6rv2QHsNSJwrHyMaX0r +6OZ1w+gDKSeId0KGCA== X-Proofpoint-GUID: 9KhpSThO5X0zotcE0zCZ3ToPL_XhHfw9 X-Proofpoint-ORIG-GUID: 9KhpSThO5X0zotcE0zCZ3ToPL_XhHfw9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-04_01,2026-12-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612040029 Hi Loic, On 12/3/2026 6:53 PM, Loic Poulain wrote: > Modern CSID revisions latch the global timestamp counter at SOF. That > counter is the ARM architected counter, so correlating it with > CLOCK_MONOTONIC through ktime_get_snapshot_id() turns the latched value > into the time the frame actually started, rather than the time the > interrupt handler ran. > > Add a hardware operation returning that counter value and do the > correlation in one place, leaving a CSID revision with nothing to do but > read its own registers. Keep the result for the frame being captured so > a consumer can pick it up the same way it already picks up the SOF > sequence number. Revisions not implementing the operation keep reporting > the time the SOF interrupt was handled. > > Suggested-by: Bryan O'Donoghue > Signed-off-by: Loic Poulain > --- > drivers/media/platform/qcom/camss/camss-csid.c | 119 ++++++++++++++++++++-- > drivers/media/platform/qcom/camss/camss-csid.h | 27 ++++- > drivers/media/platform/qcom/camss/camss-vfe-17x.c | 4 +- > drivers/media/platform/qcom/camss/camss-vfe.c | 6 +- > drivers/media/platform/qcom/camss/camss-vfe.h | 2 +- > 5 files changed, 142 insertions(+), 16 deletions(-) > > diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c > index 0f819c34e760e2df1aebf2215b8717521f11bb86..fd53e854454a6fc9d7cbe0c946a852a6f009cab3 100644 > --- a/drivers/media/platform/qcom/camss/camss-csid.c > +++ b/drivers/media/platform/qcom/camss/camss-csid.c > @@ -8,14 +8,17 @@ > * Copyright (C) 2015-2018 Linaro Ltd. > */ > #include > +#include > #include > #include > #include > #include > +#include > #include > #include > #include > #include > +#include > #include > #include > #include > @@ -37,6 +40,20 @@ > > #define LANE_CFG_BITWIDTH 4 > > +/* > + * The CSID latches the global timestamp counter on SOF. That counter is > + * the ARM architected counter, 56 bit wide and ticking at 19.2 MHz. > + * > + * Every CSID revision implementing this latches that same counter, so the > + * width and the rate are kept here. A revision latching something else > + * would have to describe it from its own implementation instead. > + */ > +#define CSID_TIMESTAMP_WIDTH 56 > +#define CSID_TIMESTAMP_MASK GENMASK_ULL(CSID_TIMESTAMP_WIDTH - 1, 0) > +#define CSID_TIMESTAMP_NS_MUL 10000 /* NSEC_PER_SEC / 19.2 MHz, reduced */ > +#define CSID_TIMESTAMP_NS_DIV 192 > +#define CSID_TIMESTAMP_MAX_AGE_NS (2 * NSEC_PER_MSEC) > + > #define MSM_CSID_NAME "msm_csid" > > const char * const csid_testgen_modes[] = { > @@ -779,9 +796,11 @@ static int csid_set_stream(struct v4l2_subdev *sd, int enable) > } > > if (csid->phy.need_vc_update) { > - /* Set to -1 as we want to do atomic_inc_return to read */ > - for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) > - atomic_set(&csid->sof_seq[i], -1); > + for (i = 0; i < MSM_CSID_MAX_SRC_STREAMS; i++) { > + /* Set to -1 as we want to do atomic_inc_return to read */ > + atomic_set(&csid->sof[i].seq, -1); > + atomic64_set(&csid->sof[i].ts, 0); > + } > > csid->res->hw_ops->configure_stream(csid, enable); > csid->phy.need_vc_update = false; > @@ -1367,7 +1386,7 @@ static inline unsigned int csid_pad_to_port(u32 pad) > return pad - MSM_CSID_PAD_FIRST_SRC; > } > > -atomic_t *csid_get_sof_seq(struct media_pad *pad) > +struct csid_sof *csid_get_sof(struct media_pad *pad) > { > struct csid_device *csid; > > @@ -1378,17 +1397,105 @@ atomic_t *csid_get_sof_seq(struct media_pad *pad) > if (!csid->res->frame_sync_en) > return NULL; > > - return &csid->sof_seq[csid_pad_to_port(pad->index)]; > + return &csid->sof[csid_pad_to_port(pad->index)]; > +} > + > +static u64 csid_timestamp_to_ns(u64 ticks) > +{ > + return mul_u64_u32_div(ticks, CSID_TIMESTAMP_NS_MUL, CSID_TIMESTAMP_NS_DIV); > +} > + > +/* > + * csid_timestamp_to_monotonic - Turn a latched counter value into a timestamp > + * @csid: CSID device > + * @ticks: Counter value the hardware latched > + * > + * Return @ticks expressed on CLOCK_MONOTONIC, or simply the CLOCK_MONOTONIC > + * time of this call if the architected counter isn't what drives timekeeping, > + * as there is then nothing to correlate the latched value against. > + */ > +static u64 csid_timestamp_to_monotonic(struct csid_device *csid, u64 ticks) > +{ > + struct system_time_snapshot snap; > + u64 delta, delta_ns, now; > + > + ktime_get_snapshot_id(CLOCK_MONOTONIC, &snap); > + > + if (!snap.valid) { > + dev_warn_once(csid->camss->dev, > + "CSID%u: Can't use hardware timestamp, no clock snapshot\n", > + csid->id); > + return ktime_get_ns(); > + } > + > + now = ktime_to_ns(snap.systime); > + > + /* > + * Translating requires reading the counter the CSID latched from. > + * If timekeeping is driven by something else there is nothing to > + * correlate against, so report the time this event was handled. > + * Below CSID means clock-source ID. > + */ > + if (snap.cs_id != CSID_ARM_ARCH_COUNTER) { > + dev_warn_once(csid->camss->dev, > + "CSID%u: Can't use hardware timestamp, invalid clock source (%d)\n", > + csid->id, snap.cs_id); > + return now; > + } > + > + /* How long ago, in counter ticks, the timestamp was latched */ > + delta = (snap.cycles - ticks) & CSID_TIMESTAMP_MASK; > + delta_ns = csid_timestamp_to_ns(delta); > + > + /* Fall back rather than reporting a nonsensical timestamp */ > + if (delta_ns > now) { > + dev_warn_once(csid->camss->dev, > + "CSID%u: SOF timestamp predates CLOCK_MONOTONIC, ignoring\n", > + csid->id); > + return now; > + } > + > + if (delta_ns > CSID_TIMESTAMP_MAX_AGE_NS) > + dev_warn_ratelimited(csid->camss->dev, > + "CSID%u: Too slow! SOF timestamp is %llu us old\n", > + csid->id, delta_ns / NSEC_PER_USEC); > + > + return now - delta_ns; > +} > + > +static u64 csid_hw_sof_ts(struct csid_device *csid, unsigned int id) > +{ > + const struct csid_hw_ops *hw_ops = csid->res->hw_ops; > + u64 ticks; > + > + if (!hw_ops->sof_ts) > + return ktime_get_ns(); > + > + ticks = hw_ops->sof_ts(csid, id); > + > + /* > + * For double-buffered CSID registers, the CSID configuration is > + * only latched on the first SOF, so no timestamp is captured for > + * that first SOF. > + */ > + if (!ticks && atomic_read(&csid->sof[id].seq) == -1) > + return ktime_get_ns(); > + > + return csid_timestamp_to_monotonic(csid, ticks); > } > > void csid_sof_event(struct csid_device *csid, unsigned int id) > { > + /* Read before the sequence number below, which arms the first SOF */ > + u64 ts = csid_hw_sof_ts(csid, id); > struct v4l2_event event = { > .type = V4L2_EVENT_FRAME_SYNC, > .u.frame_sync.frame_sequence = > - atomic_inc_return(&csid->sof_seq[id]), > + atomic_inc_return(&csid->sof[id].seq), > }; > > + atomic64_set(&csid->sof[id].ts, ts); > + > if (atomic_read(&csid->frame_sync_users)) > v4l2_event_queue(csid->subdev.devnode, &event); > } > diff --git a/drivers/media/platform/qcom/camss/camss-csid.h b/drivers/media/platform/qcom/camss/camss-csid.h > index ccafdbf3a9fe0c282da68ccdd04661b3fab81ff5..4925ea714aa74081a2b602f08696734b1087babb 100644 > --- a/drivers/media/platform/qcom/camss/camss-csid.h > +++ b/drivers/media/platform/qcom/camss/camss-csid.h > @@ -111,6 +111,15 @@ struct csid_hw_ops { > */ > int (*reset)(struct csid_device *csid); > > + /* > + * sof_ts - Read the counter value the hardware latched at SOF > + * @csid: CSID device > + * @id: CSID src-stream ID > + * > + * Return the raw counter value of the most recent SOF > + */ > + u64 (*sof_ts)(struct csid_device *csid, unsigned int id); > + > /* > * src_pad_code - Pick an output/src format based on the input/sink format > * @csid: CSID device > @@ -155,6 +164,16 @@ struct csid_subdev_resources { > const struct csid_formats *formats; > }; > > +/* > + * struct csid_sof - What the CSID tracks at start of frame, per src stream > + * @seq: Frame sequence number, -1 until the first SOF of the stream > + * @ts: CLOCK_MONOTONIC time of the frame start, 0 until the first SOF > + */ > +struct csid_sof { > + atomic_t seq; > + atomic64_t ts; > +}; > + > struct csid_device { > struct camss *camss; > u8 id; > @@ -178,7 +197,7 @@ struct csid_device { > struct v4l2_ctrl *testgen_mode; > const struct csid_subdev_resources *res; > atomic_t frame_sync_users; > - atomic_t sof_seq[MSM_CSID_MAX_SRC_STREAMS]; > + struct csid_sof sof[MSM_CSID_MAX_SRC_STREAMS]; > }; > > struct camss_subdev_resources; > @@ -271,12 +290,12 @@ u32 csid_src_pad_code(struct csid_device *csid, u32 sink_code, > void csid_sof_event(struct csid_device *csid, unsigned int id); > > /* > - * csid_get_sof_seq - Get a pointer to the SOF frame sequence variable. > + * csid_get_sof - Get a pointer to the SOF state of a CSID source stream > * @pad: Remote pad of a consumer's sink pad > * > - * Return the counter or NULL if @pad isn't a CSID or the CSID doesn't support > + * Return the state or NULL if @pad isn't a CSID or the CSID doesn't support > * SOF tracking. > */ > -atomic_t *csid_get_sof_seq(struct media_pad *pad); > +struct csid_sof *csid_get_sof(struct media_pad *pad); > > #endif /* QC_MSM_CAMSS_CSID_H */ > diff --git a/drivers/media/platform/qcom/camss/camss-vfe-17x.c b/drivers/media/platform/qcom/camss/camss-vfe-17x.c > index 4972d3ab65078387735ef2e853bf1c9c3d82baee..75f83601da8ef671d8a9f63e8df264729bf256f2 100644 > --- a/drivers/media/platform/qcom/camss/camss-vfe-17x.c > +++ b/drivers/media/platform/qcom/camss/camss-vfe-17x.c > @@ -491,8 +491,8 @@ static void vfe_isr_wm_done(struct vfe_device *vfe, u8 wm) > } > > ready_buf->vb.vb2_buf.timestamp = ts; > - if (line->sof_seq) > - ready_buf->vb.sequence = atomic_read(line->sof_seq); > + if (line->sof) > + ready_buf->vb.sequence = atomic_read(&line->sof->seq); > else > ready_buf->vb.sequence = output->sequence++; > > diff --git a/drivers/media/platform/qcom/camss/camss-vfe.c b/drivers/media/platform/qcom/camss/camss-vfe.c > index f9bd2367671f6e50c6948a6405f78b8c2b03e5f7..73320bffcd48936372a2b2c4f79b09d3575bdcec 100644 > --- a/drivers/media/platform/qcom/camss/camss-vfe.c > +++ b/drivers/media/platform/qcom/camss/camss-vfe.c > @@ -475,8 +475,8 @@ void vfe_buf_done(struct vfe_device *vfe, int wm) > } > > ready_buf->vb.vb2_buf.timestamp = ts; > - if (line->sof_seq) > - ready_buf->vb.sequence = atomic_read(line->sof_seq); > + if (line->sof) > + ready_buf->vb.sequence = atomic_read(&line->sof->seq); > else > ready_buf->vb.sequence = output->sequence++; > > @@ -531,7 +531,7 @@ int vfe_enable_output_v2(struct vfe_line *line) > } > > csid_pad = media_pad_remote_pad_first(&line->pads[MSM_VFE_PAD_SINK]); > - line->sof_seq = csid_get_sof_seq(csid_pad); > + line->sof = csid_get_sof(csid_pad); > > spin_lock_irqsave(&vfe->output_lock, flags); > > diff --git a/drivers/media/platform/qcom/camss/camss-vfe.h b/drivers/media/platform/qcom/camss/camss-vfe.h > index c37526caf9a6fc052c3f4ab4215e635167f6da95..b0921e348f2c73a5533c196400c70da187be2cee 100644 > --- a/drivers/media/platform/qcom/camss/camss-vfe.h > +++ b/drivers/media/platform/qcom/camss/camss-vfe.h > @@ -94,7 +94,7 @@ struct vfe_line { > struct vfe_output output; > const struct camss_format_info *formats; > unsigned int nformats; > - atomic_t *sof_seq; > + struct csid_sof *sof; > }; Looks good to me now. Reviewed-by: Gjorgji Rosikopulos > > struct vfe_device; >