be1eb5611e56327bca752dabd215a13c23d27654
[openwrt/staging/blocktrron.git] /
1 From 083f39e40d980b47ab12b451d40b9f935bb22a5b Mon Sep 17 00:00:00 2001
2 From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
3 Date: Wed, 6 Dec 2023 14:27:57 +0000
4 Subject: [PATCH] drivers: media: i2c: imx296,imx477: Configure tigger_mode
5 every time
6
7 Don't assume the camera has been reset each time we start streaming,
8 but always write registers relating to trigger_mode, even in mode 0.
9
10 IMX477: Stop driving XVS on stop streaming, to avoid spurious pulses.
11
12 Signed-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>
13 ---
14 drivers/media/i2c/imx296.c | 9 +++++----
15 drivers/media/i2c/imx477.c | 29 ++++++++++++++---------------
16 2 files changed, 19 insertions(+), 19 deletions(-)
17
18 --- a/drivers/media/i2c/imx296.c
19 +++ b/drivers/media/i2c/imx296.c
20 @@ -650,10 +650,11 @@ static int imx296_stream_on(struct imx29
21 imx296_write(sensor, IMX296_CTRL00, 0, &ret);
22 usleep_range(2000, 5000);
23
24 - if (trigger_mode == 1) {
25 - imx296_write(sensor, IMX296_CTRL0B, IMX296_CTRL0B_TRIGEN, &ret);
26 - imx296_write(sensor, IMX296_LOWLAGTRG, IMX296_LOWLAGTRG_FAST, &ret);
27 - }
28 + /* external trigger mode: 0=normal, 1=triggered */
29 + imx296_write(sensor, IMX296_CTRL0B,
30 + (trigger_mode == 1) ? IMX296_CTRL0B_TRIGEN : 0, &ret);
31 + imx296_write(sensor, IMX296_LOWLAGTRG,
32 + (trigger_mode == 1) ? IMX296_LOWLAGTRG_FAST : 0, &ret);
33
34 imx296_write(sensor, IMX296_CTRL0A, 0, &ret);
35
36 --- a/drivers/media/i2c/imx477.c
37 +++ b/drivers/media/i2c/imx477.c
38 @@ -1742,26 +1742,21 @@ static int imx477_start_streaming(struct
39 imx477_write_reg(imx477, 0x0b05, IMX477_REG_VALUE_08BIT, !!dpc_enable);
40 imx477_write_reg(imx477, 0x0b06, IMX477_REG_VALUE_08BIT, !!dpc_enable);
41
42 - /* Set vsync trigger mode */
43 - if (trigger_mode != 0) {
44 - /* trigger_mode == 1 for source, 2 for sink */
45 - const u32 val = (trigger_mode == 1) ? 1 : 0;
46 -
47 - imx477_write_reg(imx477, IMX477_REG_MC_MODE,
48 - IMX477_REG_VALUE_08BIT, 1);
49 - imx477_write_reg(imx477, IMX477_REG_MS_SEL,
50 - IMX477_REG_VALUE_08BIT, val);
51 - imx477_write_reg(imx477, IMX477_REG_XVS_IO_CTRL,
52 - IMX477_REG_VALUE_08BIT, val);
53 - imx477_write_reg(imx477, IMX477_REG_EXTOUT_EN,
54 - IMX477_REG_VALUE_08BIT, val);
55 - }
56 -
57 /* Apply customized values from user */
58 ret = __v4l2_ctrl_handler_setup(imx477->sd.ctrl_handler);
59 if (ret)
60 return ret;
61
62 + /* Set vsync trigger mode: 0=standalone, 1=source, 2=sink */
63 + imx477_write_reg(imx477, IMX477_REG_MC_MODE,
64 + IMX477_REG_VALUE_08BIT, (trigger_mode > 0) ? 1 : 0);
65 + imx477_write_reg(imx477, IMX477_REG_MS_SEL,
66 + IMX477_REG_VALUE_08BIT, (trigger_mode <= 1) ? 1 : 0);
67 + imx477_write_reg(imx477, IMX477_REG_XVS_IO_CTRL,
68 + IMX477_REG_VALUE_08BIT, (trigger_mode == 1) ? 1 : 0);
69 + imx477_write_reg(imx477, IMX477_REG_EXTOUT_EN,
70 + IMX477_REG_VALUE_08BIT, (trigger_mode == 1) ? 1 : 0);
71 +
72 /* set stream on register */
73 return imx477_write_reg(imx477, IMX477_REG_MODE_SELECT,
74 IMX477_REG_VALUE_08BIT, IMX477_MODE_STREAMING);
75 @@ -1778,6 +1773,10 @@ static void imx477_stop_streaming(struct
76 IMX477_REG_VALUE_08BIT, IMX477_MODE_STANDBY);
77 if (ret)
78 dev_err(&client->dev, "%s failed to set stream\n", __func__);
79 +
80 + /* Stop driving XVS out (there is still a weak pull-up) */
81 + imx477_write_reg(imx477, IMX477_REG_EXTOUT_EN,
82 + IMX477_REG_VALUE_08BIT, 0);
83 }
84
85 static int imx477_set_stream(struct v4l2_subdev *sd, int enable)