bcm27xx: 6.1: add kernel patches
[openwrt/staging/nbd.git] / target / linux / bcm27xx / patches-6.1 / 950-0470-media-i2c-ov7251-Add-module-param-to-select-ext-trig.patch
1 From 9524eae5a46285e574b869879fb0228fb4424a5f Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 1 Dec 2022 13:54:49 +0000
4 Subject: [PATCH] media: i2c: ov7251: Add module param to select ext
5 trig mode
6
7 As there isn't currently a defined mechanism for selecting an
8 external trigger mode on image sensors, copy the imx477
9 approach of using a module parameter to enable ext trig.
10
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 ---
13 drivers/media/i2c/ov7251.c | 35 ++++++++++++++++++++++++++++++++---
14 1 file changed, 32 insertions(+), 3 deletions(-)
15
16 --- a/drivers/media/i2c/ov7251.c
17 +++ b/drivers/media/i2c/ov7251.c
18 @@ -23,6 +23,10 @@
19 #include <media/v4l2-fwnode.h>
20 #include <media/v4l2-subdev.h>
21
22 +static int trigger_mode;
23 +module_param(trigger_mode, int, 0644);
24 +MODULE_PARM_DESC(trigger_mode, "Set vsync trigger mode: 0=standalone, (1=source - not implemented), 2=sink");
25 +
26 #define OV7251_SC_MODE_SELECT 0x0100
27 #define OV7251_SC_MODE_SELECT_SW_STANDBY 0x0
28 #define OV7251_SC_MODE_SELECT_STREAMING 0x1
29 @@ -525,7 +529,6 @@ static const struct reg_value ov7251_set
30 { 0x3662, 0x01 },
31 { 0x3663, 0x70 },
32 { 0x3664, 0x50 },
33 - { 0x3666, 0x0a },
34 { 0x3669, 0x1a },
35 { 0x366a, 0x00 },
36 { 0x366b, 0x50 },
37 @@ -592,9 +595,8 @@ static const struct reg_value ov7251_set
38 { 0x3c00, 0x89 },
39 { 0x3c01, 0x63 },
40 { 0x3c02, 0x01 },
41 - { 0x3c03, 0x00 },
42 { 0x3c04, 0x00 },
43 - { 0x3c05, 0x03 },
44 + { 0x3c05, 0x01 },
45 { 0x3c06, 0x00 },
46 { 0x3c07, 0x06 },
47 { 0x3c0c, 0x01 },
48 @@ -624,6 +626,16 @@ static const struct reg_value ov7251_set
49 { 0x5001, 0x80 },
50 };
51
52 +static const struct reg_value ov7251_ext_trig_on[] = {
53 + { 0x3666, 0x00 },
54 + { 0x3c03, 0x17 },
55 +};
56 +
57 +static const struct reg_value ov7251_ext_trig_off[] = {
58 + { 0x3666, 0x0a },
59 + { 0x3c03, 0x00 },
60 +};
61 +
62 static const unsigned long supported_xclk_rates[] = {
63 [OV7251_19_2_MHZ] = 19200000,
64 [OV7251_24_MHZ] = 24000000,
65 @@ -1372,6 +1384,23 @@ static int ov7251_s_stream(struct v4l2_s
66 dev_err(ov7251->dev, "could not sync v4l2 controls\n");
67 goto err_power_down;
68 }
69 +
70 + /* Set vsync trigger mode */
71 + switch (trigger_mode) {
72 + case 2:
73 + ov7251_set_register_array(ov7251,
74 + ov7251_ext_trig_on,
75 + ARRAY_SIZE(ov7251_ext_trig_on));
76 + break;
77 + case 0:
78 + default:
79 + /* case 1 for ext trig source currently not implemented */
80 + ov7251_set_register_array(ov7251,
81 + ov7251_ext_trig_off,
82 + ARRAY_SIZE(ov7251_ext_trig_off));
83 + break;
84 + }
85 +
86 ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT,
87 OV7251_SC_MODE_SELECT_STREAMING);
88 if (ret)