Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1802492lql; Wed, 13 Mar 2024 08:32:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUqbXBSTDs+A57u9o2F2ySTtpSi217LFQX1Gwp0r4fsfQZUNjyx43VGgkoOfbmOPuGrTzuoBN3m4fO+H9OTJme7LMBHtCH4P6hi2nc8A== X-Google-Smtp-Source: AGHT+IFDEMQLnEF12i3q+CXSV9uZwMGWWtnrP4XVjoua36QEPle4EtkPztuoOqvSLWWKNGWQvynj X-Received: by 2002:a17:903:2443:b0:1dd:97db:21a6 with SMTP id l3-20020a170903244300b001dd97db21a6mr4200522pls.3.1710343955806; Wed, 13 Mar 2024 08:32:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710343955; cv=pass; d=google.com; s=arc-20160816; b=Plb4LYjd/TgtLymK6xVUOxUSKt0xeJPoHvheYMnC1Hetbhf30EqJBQnKIAbBCYF+wO O0Zo3X62qTR4cq4yt4ePUfkMUB30b4hD5XNVl+KPihh8JViUFykx3wUfaXqG+lY2WqvD PKKEVzN5Ao4/f1OEYrtCeqRVFs16RKZj5vCJR/BQDMtb5OtiP5kHpPOAe5kjdf+u9MP8 kxYybEjc4tLHkCKWkD/fNOaJOYqesd/WeMqqq2KM344aUx8FR0xJcF4ws5UfG3WGPpeZ M+2u++FgR0CdR+yQYhKrdMC8Y0jbWEZStSRYmAcM2AetZDnnP2b4ndoYV5DEdvPKFJjT y1QA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=18AJVTPHhE43GH7fRz6QcQWy5t7Wa+dpmL7P1bZGLZM=; fh=HX8zrDCW8MyReaRv3wRUjhfAkf7ejKqPQiGHP+ikDZ8=; b=Ke99TUlMYow9+wNld0ifcBDIv4m1WlLevHNZPFzQrUKGh9GmKwEDytir9XtvnL57Gs DzYGjREi6hsvnmiiYVR9GNEs7pzKkVoskXZjbld+NNm97oSevmYZq+2q/z15RVYHzGzU Ap1SDA4IlKGKEhFdb9UIzZlqqKkfJyiAUNSKAG2PEl8wx+mDpSQ1E9OmA7KFDBQSOUW3 dBW0MFk+MGzp63/LktHVDqgGnnLfu5yVPYK+PXrcqxSUc/moSoCb4SaTLxJmoTOXYv+7 hrlXbq29U5eeN4czUx4t4Ag3o1JAZH0ILEUX327txUL9MGtkqq8Vw7QA/jijP3054goI Evog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=vKEYO3rz; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-101682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101682-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q15-20020a170902a3cf00b001dd6e316144si8897378plb.600.2024.03.13.08.32.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 08:32:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=vKEYO3rz; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-101682-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101682-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 16969282436 for ; Wed, 13 Mar 2024 15:32:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0C3947A6A; Wed, 13 Mar 2024 15:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vKEYO3rz" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D77B04502C; Wed, 13 Mar 2024 15:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710343943; cv=none; b=d6md1cLSE0ovuQ0uuxJLcqOm3IeZunQ07WQ1lNF6n0Trc7lNVHvwvaIEsLBDvkgd9+aHjWO3nbrB7+UhpqWOqU/HSTfU4Mi88z+DIBUBE310Jje96tI81kUqIv1gr+vkTR3fO3DRhgNkvN18cPwkNSQW0CMr/ubp8KoTA84GFxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710343943; c=relaxed/simple; bh=RYj/hTGFeOICAffBo+IOFSfUokMceJPXN3Xwefp5Ee4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=BvdNqa07PRo2CfUtOas0fvRiL7q4QShf7HRbOZvWVJAiU1Yfu/YxyEM0MUVjEoSDrjHDkamq2rENGHbhelQpb+G4udgke16zKyijbnmypo0zPVQj2GMdEPPnYYSeULzXjJszjtw+ZpZFX2j0Hrc4ZSZJRlSB6VcVGctrxsqaBL4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=vKEYO3rz; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from jasper.fritz.box (unknown [IPv6:2a00:6020:448c:6c00:9b07:31b5:38e1:e957]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BBF51A8F; Wed, 13 Mar 2024 16:31:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1710343917; bh=RYj/hTGFeOICAffBo+IOFSfUokMceJPXN3Xwefp5Ee4=; h=From:To:Cc:Subject:Date:From; b=vKEYO3rzSe33FG42cJPkl0ClUEYxkAfR9ZnW4wrdK56dAsnXCEpeOmIf5k6JImSk3 TK06yhx3ScUjKFrsHZJbiFV6CVzHVTbE4018kKNoISnJ48nxMgojTL2BIqVuLZTQsn QTxPOhHeCmU29xv7PCtcW3CjuD7uSYnaol0JUHXg= From: Stefan Klug To: libcamera-devel@lists.libcamera.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Stefan Klug , Rui Miguel Silva , Laurent Pinchart , Martin Kepplinger , Purism Kernel Team , Mauro Carvalho Chehab , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Subject: [PATCH] mipi-csis: Emit V4L2_EVENT_FRAME_SYNC events Date: Wed, 13 Mar 2024 16:30:58 +0100 Message-Id: <20240313153058.189684-1-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.40.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 Samsung CSIS Mipi receiver provides a start-of-frame interrupt and a framecount register. As the CSI receiver is the hardware unit that lies closest to the sensor, the frame counter is the best we can get on these devices. In case of the ISI available on the i.MX8 M Plus it is also the only native start-of-frame signal available. This patch exposes the sof interrupt and the framecount as V4L2_EVENT_FRAME_SYNC event on the subdevice. It was tested on a Debix-Som-A with a 6.8-rc4 kernel. Signed-off-by: Stefan Klug --- drivers/media/platform/nxp/imx-mipi-csis.c | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/nxp/imx-mipi-csis.c b/drivers/media/platform/nxp/imx-mipi-csis.c index db8ff5f5c4d3..caeb1622f741 100644 --- a/drivers/media/platform/nxp/imx-mipi-csis.c +++ b/drivers/media/platform/nxp/imx-mipi-csis.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -742,6 +743,18 @@ static void mipi_csis_stop_stream(struct mipi_csis_device *csis) mipi_csis_system_enable(csis, false); } +static void mipi_csis_queue_event_sof(struct mipi_csis_device *csis) +{ + struct v4l2_event event = { + .type = V4L2_EVENT_FRAME_SYNC, + }; + + u32 frame = mipi_csis_read(csis, MIPI_CSIS_FRAME_COUNTER_CH(0)); + + event.u.frame_sync.frame_sequence = frame; + v4l2_event_queue(csis->sd.devnode, &event); +} + static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id) { struct mipi_csis_device *csis = dev_id; @@ -765,6 +778,10 @@ static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id) event->counter++; } } + + if (status & MIPI_CSIS_INT_SRC_FRAME_START) + mipi_csis_queue_event_sof(csis); + spin_unlock_irqrestore(&csis->slock, flags); mipi_csis_write(csis, MIPI_CSIS_INT_SRC, status); @@ -1154,8 +1171,23 @@ static int mipi_csis_log_status(struct v4l2_subdev *sd) return 0; } +static int mipi_csis_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, + struct v4l2_event_subscription *sub) +{ + if (sub->type != V4L2_EVENT_FRAME_SYNC) + return -EINVAL; + + /* V4L2_EVENT_FRAME_SYNC doesn't require an id, so zero should be set */ + if (sub->id != 0) + return -EINVAL; + + return v4l2_event_subscribe(fh, sub, 0, NULL); +} + static const struct v4l2_subdev_core_ops mipi_csis_core_ops = { .log_status = mipi_csis_log_status, + .subscribe_event = mipi_csis_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, }; static const struct v4l2_subdev_video_ops mipi_csis_video_ops = { @@ -1358,7 +1390,7 @@ static int mipi_csis_subdev_init(struct mipi_csis_device *csis) snprintf(sd->name, sizeof(sd->name), "csis-%s", dev_name(csis->dev)); - sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; sd->ctrl_handler = NULL; sd->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE; -- 2.40.1