bcm27xx: add support for linux v5.15
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0554-media-i2c-imx477-Add-vsync-trigger_mode-parameter.patch
1 From 9ed9132402b92d1957927c8719f37d8b95bb00ff Mon Sep 17 00:00:00 2001
2 From: neocortex-vision <oss@neocortexvision.com>
3 Date: Thu, 28 Oct 2021 17:37:36 +0100
4 Subject: [PATCH] media: i2c: imx477: Add vsync trigger_mode parameter
5
6 trigger_mode == 0 (default) => no effect / no registers written
7 trigger_mode == 1 => source
8 trigger_mode == 2 => sink
9
10 This can be set e.g. in /boot/cmdline.txt as imx477.trigger_mode=N
11
12 Signed-off-by: Jonas Jacob <jonas.jacob@neocortexvision.com>
13 ---
14 drivers/media/i2c/imx477.c | 25 +++++++++++++++++++++++++
15 1 file changed, 25 insertions(+)
16
17 --- a/drivers/media/i2c/imx477.c
18 +++ b/drivers/media/i2c/imx477.c
19 @@ -25,6 +25,10 @@ static int dpc_enable = 1;
20 module_param(dpc_enable, int, 0644);
21 MODULE_PARM_DESC(dpc_enable, "Enable on-sensor DPC");
22
23 +static int trigger_mode;
24 +module_param(trigger_mode, int, 0644);
25 +MODULE_PARM_DESC(trigger_mode, "Set vsync trigger mode: 1=source, 2=sink");
26 +
27 #define IMX477_REG_VALUE_08BIT 1
28 #define IMX477_REG_VALUE_16BIT 2
29
30 @@ -98,6 +102,12 @@ MODULE_PARM_DESC(dpc_enable, "Enable on-
31 #define IMX477_TEST_PATTERN_B_DEFAULT 0
32 #define IMX477_TEST_PATTERN_GB_DEFAULT 0
33
34 +/* Trigger mode */
35 +#define IMX477_REG_MC_MODE 0x3f0b
36 +#define IMX477_REG_MS_SEL 0x3041
37 +#define IMX477_REG_XVS_IO_CTRL 0x3040
38 +#define IMX477_REG_EXTOUT_EN 0x4b81
39 +
40 /* Embedded metadata stream structure */
41 #define IMX477_EMBEDDED_LINE_WIDTH 16384
42 #define IMX477_NUM_EMBEDDED_LINES 1
43 @@ -1721,6 +1731,21 @@ static int imx477_start_streaming(struct
44 imx477_write_reg(imx477, 0x0b05, IMX477_REG_VALUE_08BIT, !!dpc_enable);
45 imx477_write_reg(imx477, 0x0b06, IMX477_REG_VALUE_08BIT, !!dpc_enable);
46
47 + /* Set vsync trigger mode */
48 + if (trigger_mode != 0) {
49 + /* trigger_mode == 1 for source, 2 for sink */
50 + const u32 val = (trigger_mode == 1) ? 1 : 0;
51 +
52 + imx477_write_reg(imx477, IMX477_REG_MC_MODE,
53 + IMX477_REG_VALUE_08BIT, 1);
54 + imx477_write_reg(imx477, IMX477_REG_MS_SEL,
55 + IMX477_REG_VALUE_08BIT, val);
56 + imx477_write_reg(imx477, IMX477_REG_XVS_IO_CTRL,
57 + IMX477_REG_VALUE_08BIT, val);
58 + imx477_write_reg(imx477, IMX477_REG_EXTOUT_EN,
59 + IMX477_REG_VALUE_08BIT, val);
60 + }
61 +
62 /* Apply customized values from user */
63 ret = __v4l2_ctrl_handler_setup(imx477->sd.ctrl_handler);
64 if (ret)