Skip to content

Commit 11e053e

Browse files
committed
media: ov9282: Add external trigger mode support
Adds DT property `trigger-mode` to enable FSIN-triggered frame capture. Includes overlay and README update for ov9281_trig. Signed-off-by: Your Name <[email protected]>
1 parent 3829e1b commit 11e053e

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed

arch/arm/boot/dts/overlays/README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,6 +3718,10 @@ Params: rotation Mounting rotation of the camera sensor (0 or
37183718
clk-continuous Switch to continuous mode on the CSI clock lane,
37193719
which increases the maximum frame rate slightly.
37203720
Appears not to work on Pi3.
3721+
trigger-mode Enable external trigger mode (0 = normal,
3722+
1 = triggered). In this mode, the sensor outputs
3723+
a frame only when triggered by a rising edge
3724+
on the FSIN input pin.
37213725

37223726

37233727
Name: papirus

arch/arm/boot/dts/overlays/ov9281-overlay.dts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
// Definitions for OV9281 camera module on VC I2C bus
2+
// Definitions for OV9281_trig camera module on VC I2C bus
33
/dts-v1/;
44
/plugin/;
55

6-
#include <dt-bindings/gpio/gpio.h>
76

87
/{
98
compatible = "brcm,bcm2835";
@@ -96,6 +95,7 @@
9695
<&reg_frag>, "target:0=",<&cam0_reg>;
9796
arducam = <0>, "+6";
9897
clk-continuous = <0>, "-7-8";
98+
trigger-mode = <&cam_node>, "trigger-mode:0";
9999
};
100100
};
101101

arch/arm/boot/dts/overlays/ov9281.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ cam_node: ov9281@60 {
1414

1515
rotation = <0>;
1616
orientation = <2>;
17+
trigger-mode = <0>;
1718

1819
port {
1920
cam_endpoint: endpoint {

drivers/media/i2c/ov9282.c

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
#define OV9282_REG_MIPI_CTRL00 0x4800
6666
#define OV9282_GATED_CLOCK BIT(5)
6767

68+
/* Trigger mode registers */
69+
#define OV9282_REG_POWER_CTRL 0x4F00
70+
#define OV9282_REG_LOW_POWER_MODE_CTRL 0x3030
71+
#define OV9282_REG_NUM_FRAME_ON_TRIG 0x303F
72+
#define OV9282_REG_SLEEP_PERIOD_CTRL0 0x302C
73+
#define OV9282_REG_SLEEP_PERIOD_CTRL3 0x302F
74+
#define OV9282_REG_TIMING_23 0x3823
75+
6876
/* Input clock rate */
6977
#define OV9282_INCLK_RATE 24000000
7078

@@ -187,6 +195,7 @@ struct ov9282 {
187195
const struct ov9282_mode *cur_mode;
188196
u32 code;
189197
struct mutex mutex;
198+
int trigger_mode;
190199
};
191200

192201
static const s64 link_freq[] = {
@@ -947,6 +956,65 @@ static int ov9282_get_selection(struct v4l2_subdev *sd,
947956
return -EINVAL;
948957
}
949958

959+
/**
960+
* ov9282_apply_trigger_config() - Configure sensor for FSIN external trigger mode
961+
* @ov9282: pointer to ov9282 device
962+
*
963+
* Return: 0 on success, error code otherwise.
964+
*/
965+
static int ov9282_apply_trigger_config(struct ov9282 *ov9282)
966+
{
967+
int ret;
968+
969+
ret = ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT, 1, OV9282_MODE_STANDBY);
970+
if (ret) {
971+
return ret;
972+
}
973+
974+
/* Low power mode */
975+
ret = ov9282_write_reg(ov9282, OV9282_REG_POWER_CTRL, 1, 0x01);
976+
if (ret) {
977+
return ret;
978+
}
979+
980+
/* External trigger snapshot */
981+
ret = ov9282_write_reg(ov9282, OV9282_REG_LOW_POWER_MODE_CTRL, 1, 0x04);
982+
if (ret) {
983+
return ret;
984+
}
985+
986+
/* 1 frame per trigger */
987+
ov9282_write_reg(ov9282, OV9282_REG_NUM_FRAME_ON_TRIG, 1, 0x01);
988+
if (ret) {
989+
return ret;
990+
}
991+
992+
ov9282_write_reg(ov9282, OV9282_REG_SLEEP_PERIOD_CTRL0, 1, 0x00);
993+
if (ret) {
994+
return ret;
995+
}
996+
997+
ov9282_write_reg(ov9282, OV9282_REG_SLEEP_PERIOD_CTRL3, 1, 0x7F);
998+
if (ret) {
999+
return ret;
1000+
}
1001+
1002+
/* No auto wake */
1003+
ov9282_write_reg(ov9282, OV9282_REG_TIMING_23, 1, 0x00);
1004+
if (ret) {
1005+
return ret;
1006+
}
1007+
1008+
/* stay standby mode and wait for trigger signal */
1009+
ret = ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT,
1010+
1, OV9282_MODE_STANDBY);
1011+
if (ret) {
1012+
return ret;
1013+
}
1014+
1015+
return 0;
1016+
}
1017+
9501018
/**
9511019
* ov9282_start_streaming() - Start sensor stream
9521020
* @ov9282: pointer to ov9282 device
@@ -998,12 +1066,21 @@ static int ov9282_start_streaming(struct ov9282 *ov9282)
9981066
return ret;
9991067
}
10001068

1001-
/* Start streaming */
1002-
ret = ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT,
1003-
1, OV9282_MODE_STREAMING);
1004-
if (ret) {
1005-
dev_err(ov9282->dev, "fail to start streaming");
1006-
return ret;
1069+
if (ov9282->trigger_mode > 0) {
1070+
/* Configure FSIN external trigger mode */
1071+
ret = ov9282_apply_trigger_config(ov9282);
1072+
if (ret) {
1073+
dev_err(ov9282->dev, "failed to config external trigger mode");
1074+
}
1075+
}
1076+
else {
1077+
/* Start streaming */
1078+
ret = ov9282_write_reg(ov9282, OV9282_REG_MODE_SELECT,
1079+
1, OV9282_MODE_STREAMING);
1080+
if (ret) {
1081+
dev_err(ov9282->dev, "fail to start streaming");
1082+
return ret;
1083+
}
10071084
}
10081085

10091086
return 0;
@@ -1392,6 +1469,7 @@ static int ov9282_probe(struct i2c_client *client)
13921469
{
13931470
struct ov9282 *ov9282;
13941471
int ret;
1472+
u32 trig_mod;
13951473

13961474
ov9282 = devm_kzalloc(&client->dev, sizeof(*ov9282), GFP_KERNEL);
13971475
if (!ov9282)
@@ -1431,6 +1509,9 @@ static int ov9282_probe(struct i2c_client *client)
14311509
ov9282->code = MEDIA_BUS_FMT_Y10_1X10;
14321510
ov9282->vblank = ov9282->cur_mode->vblank;
14331511

1512+
ret = of_property_read_u32(client->dev.of_node, "trigger-mode", &trig_mod);
1513+
ov9282->trigger_mode = (ret == 0) ? trig_mod : -1;
1514+
14341515
ret = ov9282_init_controls(ov9282);
14351516
if (ret) {
14361517
dev_err(ov9282->dev, "failed to init controls: %d", ret);

0 commit comments

Comments
 (0)