Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mipi-csis: Emit V4L2_EVENT_FRAME_SYNC events

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.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Link: https://lore.kernel.org/r/20240314093652.56923-1-stefan.klug@ideasonboard.com
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

authored by

Stefan Klug and committed by
Laurent Pinchart
58a5650f 836e2548

+33 -1
+33 -1
drivers/media/platform/nxp/imx-mipi-csis.c
··· 30 30 31 31 #include <media/v4l2-common.h> 32 32 #include <media/v4l2-device.h> 33 + #include <media/v4l2-event.h> 33 34 #include <media/v4l2-fwnode.h> 34 35 #include <media/v4l2-mc.h> 35 36 #include <media/v4l2-subdev.h> ··· 743 742 mipi_csis_system_enable(csis, false); 744 743 } 745 744 745 + static void mipi_csis_queue_event_sof(struct mipi_csis_device *csis) 746 + { 747 + struct v4l2_event event = { 748 + .type = V4L2_EVENT_FRAME_SYNC, 749 + }; 750 + u32 frame; 751 + 752 + frame = mipi_csis_read(csis, MIPI_CSIS_FRAME_COUNTER_CH(0)); 753 + event.u.frame_sync.frame_sequence = frame; 754 + v4l2_event_queue(csis->sd.devnode, &event); 755 + } 756 + 746 757 static irqreturn_t mipi_csis_irq_handler(int irq, void *dev_id) 747 758 { 748 759 struct mipi_csis_device *csis = dev_id; ··· 778 765 event->counter++; 779 766 } 780 767 } 768 + 769 + if (status & MIPI_CSIS_INT_SRC_FRAME_START) 770 + mipi_csis_queue_event_sof(csis); 771 + 781 772 spin_unlock_irqrestore(&csis->slock, flags); 782 773 783 774 mipi_csis_write(csis, MIPI_CSIS_INT_SRC, status); ··· 1171 1154 return 0; 1172 1155 } 1173 1156 1157 + static int mipi_csis_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh, 1158 + struct v4l2_event_subscription *sub) 1159 + { 1160 + if (sub->type != V4L2_EVENT_FRAME_SYNC) 1161 + return -EINVAL; 1162 + 1163 + /* V4L2_EVENT_FRAME_SYNC doesn't require an id, so zero should be set */ 1164 + if (sub->id != 0) 1165 + return -EINVAL; 1166 + 1167 + return v4l2_event_subscribe(fh, sub, 0, NULL); 1168 + } 1169 + 1174 1170 static const struct v4l2_subdev_core_ops mipi_csis_core_ops = { 1175 1171 .log_status = mipi_csis_log_status, 1172 + .subscribe_event = mipi_csis_subscribe_event, 1173 + .unsubscribe_event = v4l2_event_subdev_unsubscribe, 1176 1174 }; 1177 1175 1178 1176 static const struct v4l2_subdev_video_ops mipi_csis_video_ops = { ··· 1390 1358 snprintf(sd->name, sizeof(sd->name), "csis-%s", 1391 1359 dev_name(csis->dev)); 1392 1360 1393 - sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 1361 + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; 1394 1362 sd->ctrl_handler = NULL; 1395 1363 1396 1364 sd->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;