1 From 6a0ae67b699bef301e835b814a416067567ecd39 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 3 Apr 2024 16:06:08 +0100
4 Subject: [PATCH 1039/1085] media: bcm2835-unicam: Add option for a GPIO to
7 The legacy stack had an option to have a GPIO track frame start and
8 end events to give basic synchronisation to the incoming image stream.
9 https://forums.raspberrypi.com/viewtopic.php?t=190314
11 Replicate this in the kernel Unicam driver.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 drivers/media/platform/bcm2835/bcm2835-unicam.c | 12 ++++++++++++
16 1 file changed, 12 insertions(+)
18 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
19 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
21 #include <linux/device.h>
22 #include <linux/dma-mapping.h>
23 #include <linux/err.h>
24 +#include <linux/gpio/consumer.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
28 @@ -543,6 +544,8 @@ struct unicam_device {
29 struct v4l2_device v4l2_dev;
30 struct media_device mdev;
32 + struct gpio_desc *sync_gpio;
35 struct platform_device *pdev;
36 /* subdevice async Notifier */
37 @@ -943,6 +946,8 @@ static irqreturn_t unicam_isr(int irq, v
39 bool inc_seq = unicam->frame_started;
41 + if (unicam->sync_gpio)
42 + gpiod_set_value(unicam->sync_gpio, 0);
44 * Ensure we have swapped buffers already as we can't
45 * stop the peripheral. If no buffer is available, use a
46 @@ -1003,6 +1008,10 @@ static irqreturn_t unicam_isr(int irq, v
51 + if (unicam->sync_gpio)
52 + gpiod_set_value(unicam->sync_gpio, 1);
54 for (i = 0; i < ARRAY_SIZE(unicam->node); i++) {
55 if (!unicam->node[i].streaming)
57 @@ -3407,6 +3416,9 @@ static int unicam_probe(struct platform_
61 + unicam->sync_gpio = devm_gpiod_get_optional(&pdev->dev, "sync",
64 ret = platform_get_irq(pdev, 0);
66 dev_err(&pdev->dev, "No IRQ resource\n");