27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #define MODULE_NAME "ov534_9"
33 #define OV534_REG_ADDRESS 0xf1
34 #define OV534_REG_SUBADDR 0xf2
35 #define OV534_REG_WRITE 0xf3
36 #define OV534_REG_READ 0xf4
37 #define OV534_REG_OPERATION 0xf5
38 #define OV534_REG_STATUS 0xf6
40 #define OV534_OP_WRITE_3 0x37
41 #define OV534_OP_WRITE_2 0x33
42 #define OV534_OP_READ_2 0xf9
44 #define CTRL_TIMEOUT 500
69 .sizeimage = 320 * 240 * 3 / 8 + 590,
74 .sizeimage = 640 * 480 * 3 / 8 + 590,
79 .sizeimage = 800 * 600 * 3 / 8 + 590,
84 .sizeimage = 1024 * 768 * 3 / 8 + 590,
89 .sizeimage = 1280 * 1024 * 3 / 8 + 590,
96 .sizeimage = 640 * 480,
103 .bytesperline = 2592,
104 .sizeimage = 2592 * 1680,
109 static const u8 bridge_init[][2] = {
143 static const u8 ov965x_init[][2] = {
325 static const u8 bridge_init_2[][2] = {
353 static const u8 ov965x_init_2[][2] = {
395 static const u8 ov971x_init[][2] = {
453 static const u8 ov965x_start_1_vga[][2] = {
476 static const u8 ov965x_start_1_svga[][2] = {
498 static const u8 ov965x_start_1_xga[][2] = {
521 static const u8 ov965x_start_1_sxga[][2] = {
544 static const u8 bridge_start_qvga[][2] = {
572 static const u8 bridge_start_vga[][2] = {
599 static const u8 bridge_start_svga[][2] = {
626 static const u8 bridge_start_xga[][2] = {
653 static const u8 bridge_start_sxga[][2] = {
670 static const u8 ov965x_start_2_qvga[][2] = {
688 static const u8 ov965x_start_2_vga[][2] = {
704 static const u8 ov965x_start_2_svga[][2] = {
718 static const u8 ov965x_start_2_sxga[][2] = {
732 static const u8 ov562x_init[][2] = {
748 static const u8 ov562x_init_2[][2] = {
852 struct usb_device *
udev = gspca_dev->
dev;
859 usb_sndctrlpipe(udev, 0),
864 pr_err(
"reg_w failed %d\n", ret);
869 static void reg_w(
struct gspca_dev *gspca_dev,
u16 reg,
u8 val)
871 PDEBUG(D_USBO,
"reg_w [%04x] = %02x", reg, val);
872 reg_w_i(gspca_dev, reg, val);
875 static u8 reg_r(
struct gspca_dev *gspca_dev,
u16 reg)
877 struct usb_device *udev = gspca_dev->
dev;
883 usb_rcvctrlpipe(udev, 0),
887 PDEBUG(D_USBI,
"reg_r [%04x] -> %02x", reg, gspca_dev->
usb_buf[0]);
889 pr_err(
"reg_r err %d\n", ret);
895 static int sccb_check_status(
struct gspca_dev *gspca_dev)
900 for (i = 0; i < 5; i++) {
913 "sccb status 0x%02x, attempt %d/5",
920 static void sccb_write(
struct gspca_dev *gspca_dev,
u8 reg,
u8 val)
922 PDEBUG(D_USBO,
"sccb_write [%02x] = %02x", reg, val);
927 if (!sccb_check_status(gspca_dev))
928 pr_err(
"sccb_write failed\n");
931 static u8 sccb_read(
struct gspca_dev *gspca_dev,
u16 reg)
935 if (!sccb_check_status(gspca_dev))
936 pr_err(
"sccb_read failed 1\n");
939 if (!sccb_check_status(gspca_dev))
940 pr_err(
"sccb_read failed 2\n");
946 static void reg_w_array(
struct gspca_dev *gspca_dev,
947 const u8 (*data)[2],
int len)
950 reg_w(gspca_dev, (*data)[0], (*data)[1]);
956 static void sccb_w_array(
struct gspca_dev *gspca_dev,
957 const u8 (*data)[2],
int len)
960 if ((*data)[0] != 0xff) {
961 sccb_write(gspca_dev, (*data)[0], (*data)[1]);
963 sccb_read(gspca_dev, (*data)[1]);
964 sccb_write(gspca_dev, 0xff, 0x00);
976 PDEBUG(D_CONF,
"led status: %d", status);
978 data = reg_r(gspca_dev, 0x21);
980 reg_w(gspca_dev, 0x21, data);
982 data = reg_r(gspca_dev, 0x23);
988 reg_w(gspca_dev, 0x23, data);
991 data = reg_r(gspca_dev, 0x21);
993 reg_w(gspca_dev, 0x21, data);
997 static void setbrightness(
struct gspca_dev *gspca_dev,
s32 brightness)
999 struct sd *
sd = (
struct sd *) gspca_dev;
1007 sccb_write(gspca_dev, 0x24, val);
1010 sccb_write(gspca_dev, 0x25, val);
1017 sccb_write(gspca_dev, 0x26, val);
1024 sccb_write(gspca_dev, 0x55,
1029 static void setcontrast(
struct gspca_dev *gspca_dev,
s32 val)
1031 sccb_write(gspca_dev, 0x56,
1035 static void setautogain(
struct gspca_dev *gspca_dev,
s32 autogain)
1040 val = sccb_read(gspca_dev, 0x13);
1041 sccb_write(gspca_dev, 0xff, 0x00);
1046 sccb_write(gspca_dev, 0x13, val);
1049 static void setexposure(
struct gspca_dev *gspca_dev,
s32 exposure)
1051 static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
1054 sccb_write(gspca_dev, 0x10, expo[exposure]);
1056 val = sccb_read(gspca_dev, 0x13);
1057 sccb_write(gspca_dev, 0xff, 0x00);
1058 sccb_write(gspca_dev, 0x13, val);
1060 val = sccb_read(gspca_dev, 0xa1);
1061 sccb_write(gspca_dev, 0xff, 0x00);
1062 sccb_write(gspca_dev, 0xa1, val & 0xe0);
1065 static void setsharpness(
struct gspca_dev *gspca_dev,
s32 val)
1068 val = sccb_read(gspca_dev, 0x42);
1069 sccb_write(gspca_dev, 0xff, 0x00);
1070 sccb_write(gspca_dev, 0x42, val | 0x40);
1075 val = 1 << (val - 1);
1076 sccb_write(gspca_dev, 0x3f,
1078 val = sccb_read(gspca_dev, 0x42);
1079 sccb_write(gspca_dev, 0xff, 0x00);
1080 sccb_write(gspca_dev, 0x42, val & 0xbf);
1083 static void setsatur(
struct gspca_dev *gspca_dev,
s32 val)
1085 u8 val1, val2, val3;
1086 static const u8 matrix[5][2] = {
1094 val1 = matrix[
val][0];
1095 val2 = matrix[
val][1];
1097 sccb_write(gspca_dev, 0x4f, val3);
1098 sccb_write(gspca_dev, 0x50, val3);
1099 sccb_write(gspca_dev, 0x51, 0x00);
1100 sccb_write(gspca_dev, 0x52, val1);
1101 sccb_write(gspca_dev, 0x53, val2);
1102 sccb_write(gspca_dev, 0x54, val3);
1103 sccb_write(gspca_dev, 0x58, 0x1a);
1105 val1 = sccb_read(gspca_dev, 0x41);
1106 sccb_write(gspca_dev, 0xff, 0x00);
1107 sccb_write(gspca_dev, 0x41, val1);
1110 static void setlightfreq(
struct gspca_dev *gspca_dev,
s32 freq)
1114 val = sccb_read(gspca_dev, 0x13);
1115 sccb_write(gspca_dev, 0xff, 0x00);
1117 sccb_write(gspca_dev, 0x13, val & 0xdf);
1120 sccb_write(gspca_dev, 0x13, val | 0x20);
1122 val = sccb_read(gspca_dev, 0x42);
1123 sccb_write(gspca_dev, 0xff, 0x00);
1128 sccb_write(gspca_dev, 0x42, val);
1132 static int sd_config(
struct gspca_dev *gspca_dev,
1139 static int sd_init(
struct gspca_dev *gspca_dev)
1141 struct sd *sd = (
struct sd *) gspca_dev;
1145 reg_w(gspca_dev, 0xe7, 0x3a);
1146 reg_w(gspca_dev, 0xe0, 0x08);
1153 sccb_write(gspca_dev, 0x12, 0x80);
1157 sccb_read(gspca_dev, 0x0a);
1158 sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
1159 sccb_read(gspca_dev, 0x0b);
1160 sensor_id |= sccb_read(gspca_dev, 0x0b);
1161 PDEBUG(D_PROBE,
"Sensor ID: %04x", sensor_id);
1164 if ((sensor_id & 0xfff0) == 0x9650) {
1167 gspca_dev->
cam.cam_mode = ov965x_mode;
1170 reg_w_array(gspca_dev, bridge_init,
1172 sccb_w_array(gspca_dev, ov965x_init,
1174 reg_w_array(gspca_dev, bridge_init_2,
1176 sccb_w_array(gspca_dev, ov965x_init_2,
1178 reg_w(gspca_dev, 0xe0, 0x00);
1179 reg_w(gspca_dev, 0xe0, 0x01);
1181 reg_w(gspca_dev, 0xe0, 0x00);
1182 }
else if ((sensor_id & 0xfff0) == 0x9710) {
1188 gspca_dev->
cam.cam_mode = ov971x_mode;
1191 gspca_dev->
cam.bulk = 1;
1192 gspca_dev->
cam.bulk_size = 16384;
1193 gspca_dev->
cam.bulk_nurbs = 2;
1195 sccb_w_array(gspca_dev, ov971x_init,
1200 reg_w(gspca_dev, 0x1c, 0x00);
1202 reg_w(gspca_dev, 0x1d, 0x00);
1208 p = video_device_node_name(&gspca_dev->
vdev);
1211 reg_w(gspca_dev, 0x56, 0x1f);
1213 reg_w(gspca_dev, 0x56, 0x17);
1214 }
else if ((sensor_id & 0xfff0) == 0x5620) {
1216 gspca_dev->
cam.cam_mode = ov562x_mode;
1219 reg_w_array(gspca_dev, ov562x_init,
1221 sccb_w_array(gspca_dev, ov562x_init_2,
1223 reg_w(gspca_dev, 0xe0, 0x00);
1225 pr_err(
"Unknown sensor %04x", sensor_id);
1232 static int sd_start(
struct gspca_dev *gspca_dev)
1234 struct sd *sd = (
struct sd *) gspca_dev;
1243 sccb_w_array(gspca_dev, ov965x_start_1_vga,
1245 reg_w_array(gspca_dev, bridge_start_qvga,
1247 sccb_w_array(gspca_dev, ov965x_start_2_qvga,
1251 sccb_w_array(gspca_dev, ov965x_start_1_vga,
1253 reg_w_array(gspca_dev, bridge_start_vga,
1255 sccb_w_array(gspca_dev, ov965x_start_2_vga,
1259 sccb_w_array(gspca_dev, ov965x_start_1_svga,
1261 reg_w_array(gspca_dev, bridge_start_svga,
1263 sccb_w_array(gspca_dev, ov965x_start_2_svga,
1267 sccb_w_array(gspca_dev, ov965x_start_1_xga,
1269 reg_w_array(gspca_dev, bridge_start_xga,
1271 sccb_w_array(gspca_dev, ov965x_start_2_svga,
1276 sccb_w_array(gspca_dev, ov965x_start_1_sxga,
1278 reg_w_array(gspca_dev, bridge_start_sxga,
1280 sccb_w_array(gspca_dev, ov965x_start_2_sxga,
1285 reg_w(gspca_dev, 0xe0, 0x00);
1286 reg_w(gspca_dev, 0xe0, 0x00);
1291 static void sd_stopN(
struct gspca_dev *gspca_dev)
1293 reg_w(gspca_dev, 0xe0, 0x01);
1295 reg_w(gspca_dev, 0xe0, 0x00);
1299 #define UVC_STREAM_EOH (1 << 7)
1300 #define UVC_STREAM_ERR (1 << 6)
1301 #define UVC_STREAM_STI (1 << 5)
1302 #define UVC_STREAM_RES (1 << 4)
1303 #define UVC_STREAM_SCR (1 << 3)
1304 #define UVC_STREAM_PTS (1 << 2)
1305 #define UVC_STREAM_EOF (1 << 1)
1306 #define UVC_STREAM_FID (1 << 0)
1308 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
1311 struct sd *sd = (
struct sd *) gspca_dev;
1314 int remaining_len = len;
1317 payload_len = gspca_dev->
cam.bulk ? 2048 : 2040;
1319 len =
min(remaining_len, payload_len);
1327 if (data[0] != 12 || len < 12) {
1328 PDEBUG(D_PACK,
"bad header");
1334 PDEBUG(D_PACK,
"payload error");
1340 PDEBUG(D_PACK,
"PTS not present");
1343 this_pts = (data[5] << 24) | (data[4] << 16)
1344 | (data[3] << 8) | data[2];
1355 data + 12, len - 12);
1360 data + 12, len - 12);
1365 data + 12, len - 12);
1376 remaining_len -= len;
1378 }
while (remaining_len > 0);
1383 struct gspca_dev *gspca_dev =
1393 setbrightness(gspca_dev, ctrl->
val);
1396 setcontrast(gspca_dev, ctrl->
val);
1399 setsatur(gspca_dev, ctrl->
val);
1402 setlightfreq(gspca_dev, ctrl->
val);
1405 setsharpness(gspca_dev, ctrl->
val);
1409 setautogain(gspca_dev, ctrl->
val);
1411 setexposure(gspca_dev, gspca_dev->
exposure->val);
1418 .s_ctrl = sd_s_ctrl,
1421 static int sd_init_controls(
struct gspca_dev *gspca_dev)
1423 struct sd *sd = (
struct sd *)gspca_dev;
1428 gspca_dev->
vdev.ctrl_handler = hdl;
1454 pr_err(
"Could not initialize controls\n");
1463 .config = sd_config,
1465 .init_controls = sd_init_controls,
1468 .pkt_scan = sd_pkt_scan,
1473 {USB_DEVICE(0x05a9, 0x8065)},
1474 {USB_DEVICE(0x06f8, 0x3003)},
1475 {USB_DEVICE(0x05a9, 0x1550)},
1488 static struct usb_driver sd_driver = {
1490 .id_table = device_table,
1494 .suspend = gspca_suspend,
1495 .resume = gspca_resume,
1496 .reset_resume = gspca_resume,