0d4d3da1053c147bb0fbac713dfcefeb9a6fb817
[openwrt/staging/linusw.git] /
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
5 reflect FS/FE timing
6
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
10
11 Replicate this in the kernel Unicam driver.
12
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 ---
15 drivers/media/platform/bcm2835/bcm2835-unicam.c | 12 ++++++++++++
16 1 file changed, 12 insertions(+)
17
18 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
19 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
20 @@ -49,6 +49,7 @@
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>
27 #include <linux/io.h>
28 @@ -543,6 +544,8 @@ struct unicam_device {
29 struct v4l2_device v4l2_dev;
30 struct media_device mdev;
31
32 + struct gpio_desc *sync_gpio;
33 +
34 /* parent device */
35 struct platform_device *pdev;
36 /* subdevice async Notifier */
37 @@ -943,6 +946,8 @@ static irqreturn_t unicam_isr(int irq, v
38 if (fe) {
39 bool inc_seq = unicam->frame_started;
40
41 + if (unicam->sync_gpio)
42 + gpiod_set_value(unicam->sync_gpio, 0);
43 /*
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
47 * aka frame start.
48 */
49 ts = ktime_get_ns();
50 +
51 + if (unicam->sync_gpio)
52 + gpiod_set_value(unicam->sync_gpio, 1);
53 +
54 for (i = 0; i < ARRAY_SIZE(unicam->node); i++) {
55 if (!unicam->node[i].streaming)
56 continue;
57 @@ -3407,6 +3416,9 @@ static int unicam_probe(struct platform_
58 goto err_unicam_put;
59 }
60
61 + unicam->sync_gpio = devm_gpiod_get_optional(&pdev->dev, "sync",
62 + GPIOD_OUT_LOW);
63 +
64 ret = platform_get_irq(pdev, 0);
65 if (ret <= 0) {
66 dev_err(&pdev->dev, "No IRQ resource\n");