Skip to content

Commit 96b5b11

Browse files
robertfossmchehab
authored andcommitted
media: ov8856: Implement sensor module revision identification
Query the sensor for its module revision, and compare it to known revisions. Currently 2A and 1B revision indentification is supported. [Sakari Ailus: Wrap a line over 80, alignment, use %u for printing u32] Signed-off-by: Robert Foss <[email protected]> Signed-off-by: Sakari Ailus <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 0c2c7a1 commit 96b5b11

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

drivers/media/i2c/ov8856.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@
3232
#define OV8856_MODE_STANDBY 0x00
3333
#define OV8856_MODE_STREAMING 0x01
3434

35+
/* module revisions */
36+
#define OV8856_2A_MODULE 0x01
37+
#define OV8856_1B_MODULE 0x02
38+
39+
/* the OTP read-out buffer is at 0x7000 and 0xf is the offset
40+
* of the byte in the OTP that means the module revision
41+
*/
42+
#define OV8856_MODULE_REVISION 0x700f
43+
#define OV8856_OTP_MODE_CTRL 0x3d84
44+
#define OV8856_OTP_LOAD_CTRL 0x3d81
45+
#define OV8856_OTP_MODE_AUTO 0x00
46+
#define OV8856_OTP_LOAD_CTRL_ENABLE BIT(0)
47+
3548
/* vertical-timings from sensor */
3649
#define OV8856_REG_VTS 0x380e
3750
#define OV8856_VTS_MAX 0x7fff
@@ -1156,6 +1169,46 @@ static int ov8856_identify_module(struct ov8856 *ov8856)
11561169
return -ENXIO;
11571170
}
11581171

1172+
ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
1173+
OV8856_REG_VALUE_08BIT, OV8856_MODE_STREAMING);
1174+
if (ret)
1175+
return ret;
1176+
1177+
ret = ov8856_write_reg(ov8856, OV8856_OTP_MODE_CTRL,
1178+
OV8856_REG_VALUE_08BIT, OV8856_OTP_MODE_AUTO);
1179+
if (ret) {
1180+
dev_err(&client->dev, "failed to set otp mode");
1181+
return ret;
1182+
}
1183+
1184+
ret = ov8856_write_reg(ov8856, OV8856_OTP_LOAD_CTRL,
1185+
OV8856_REG_VALUE_08BIT,
1186+
OV8856_OTP_LOAD_CTRL_ENABLE);
1187+
if (ret) {
1188+
dev_err(&client->dev, "failed to enable load control");
1189+
return ret;
1190+
}
1191+
1192+
ret = ov8856_read_reg(ov8856, OV8856_MODULE_REVISION,
1193+
OV8856_REG_VALUE_08BIT, &val);
1194+
if (ret) {
1195+
dev_err(&client->dev, "failed to read module revision");
1196+
return ret;
1197+
}
1198+
1199+
dev_info(&client->dev, "OV8856 revision %x (%s) at address 0x%02x\n",
1200+
val,
1201+
val == OV8856_2A_MODULE ? "2A" :
1202+
val == OV8856_1B_MODULE ? "1B" : "unknown revision",
1203+
client->addr);
1204+
1205+
ret = ov8856_write_reg(ov8856, OV8856_REG_MODE_SELECT,
1206+
OV8856_REG_VALUE_08BIT, OV8856_MODE_STANDBY);
1207+
if (ret) {
1208+
dev_err(&client->dev, "failed to exit streaming mode");
1209+
return ret;
1210+
}
1211+
11591212
return 0;
11601213
}
11611214

0 commit comments

Comments
 (0)