bcm27xx: update 6.1 patches from RPi foundation
[openwrt/staging/stintel.git] / target / linux / bcm27xx / patches-6.1 / 950-1294-imx477-make-trigger-mode-more-configurable.patch
1 From f4102d30e760482e9f2fc94dcf8ce223afef3230 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Erik=20Bot=C3=B6?= <erik.boto@gmail.com>
3 Date: Fri, 9 Feb 2024 18:37:46 +0100
4 Subject: [PATCH 1294/1295] imx477: make trigger-mode more configurable
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Allow trigger-mode to be overridden using device tree so that it can be
10 set per camera. Previously the mode could only be changed using a module
11 parameter, which would then affect all cameras.
12
13 Signed-off-by: Erik Botö <erik.boto@gmail.com>
14 ---
15 drivers/media/i2c/imx477.c | 19 ++++++++++++++-----
16 1 file changed, 14 insertions(+), 5 deletions(-)
17
18 --- a/drivers/media/i2c/imx477.c
19 +++ b/drivers/media/i2c/imx477.c
20 @@ -1124,6 +1124,9 @@ struct imx477 {
21 /* Current mode */
22 const struct imx477_mode *mode;
23
24 + /* Trigger mode */
25 + int trigger_mode_of;
26 +
27 /*
28 * Mutex for serialized access:
29 * Protect sensor module set pad format and start/stop streaming safely.
30 @@ -1711,7 +1714,7 @@ static int imx477_start_streaming(struct
31 struct i2c_client *client = v4l2_get_subdevdata(&imx477->sd);
32 const struct imx477_reg_list *reg_list;
33 const struct imx477_reg_list *extra_regs;
34 - int ret;
35 + int ret, tm;
36
37 if (!imx477->common_regs_written) {
38 ret = imx477_write_regs(imx477, mode_common_regs,
39 @@ -1748,14 +1751,15 @@ static int imx477_start_streaming(struct
40 return ret;
41
42 /* Set vsync trigger mode: 0=standalone, 1=source, 2=sink */
43 + tm = (imx477->trigger_mode_of >= 0) ? imx477->trigger_mode_of : trigger_mode;
44 imx477_write_reg(imx477, IMX477_REG_MC_MODE,
45 - IMX477_REG_VALUE_08BIT, (trigger_mode > 0) ? 1 : 0);
46 + IMX477_REG_VALUE_08BIT, (tm > 0) ? 1 : 0);
47 imx477_write_reg(imx477, IMX477_REG_MS_SEL,
48 - IMX477_REG_VALUE_08BIT, (trigger_mode <= 1) ? 1 : 0);
49 + IMX477_REG_VALUE_08BIT, (tm <= 1) ? 1 : 0);
50 imx477_write_reg(imx477, IMX477_REG_XVS_IO_CTRL,
51 - IMX477_REG_VALUE_08BIT, (trigger_mode == 1) ? 1 : 0);
52 + IMX477_REG_VALUE_08BIT, (tm == 1) ? 1 : 0);
53 imx477_write_reg(imx477, IMX477_REG_EXTOUT_EN,
54 - IMX477_REG_VALUE_08BIT, (trigger_mode == 1) ? 1 : 0);
55 + IMX477_REG_VALUE_08BIT, (tm == 1) ? 1 : 0);
56
57 /* set stream on register */
58 return imx477_write_reg(imx477, IMX477_REG_MODE_SELECT,
59 @@ -2187,6 +2191,7 @@ static int imx477_probe(struct i2c_clien
60 struct imx477 *imx477;
61 const struct of_device_id *match;
62 int ret;
63 + u32 tm_of;
64
65 imx477 = devm_kzalloc(&client->dev, sizeof(*imx477), GFP_KERNEL);
66 if (!imx477)
67 @@ -2204,6 +2209,10 @@ static int imx477_probe(struct i2c_clien
68 if (imx477_check_hwcfg(dev))
69 return -EINVAL;
70
71 + /* Default the trigger mode from OF to -1, which means invalid */
72 + ret = of_property_read_u32(dev->of_node, "trigger-mode", &tm_of);
73 + imx477->trigger_mode_of = (ret == 0) ? tm_of : -1;
74 +
75 /* Get system clock (xclk) */
76 imx477->xclk = devm_clk_get(dev, NULL);
77 if (IS_ERR(imx477->xclk)) {