31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33 #define MODULE_NAME "ov534"
40 #define OV534_REG_ADDRESS 0xf1
41 #define OV534_REG_SUBADDR 0xf2
42 #define OV534_REG_WRITE 0xf3
43 #define OV534_REG_READ 0xf4
44 #define OV534_REG_OPERATION 0xf5
45 #define OV534_REG_STATUS 0xf6
47 #define OV534_OP_WRITE_3 0x37
48 #define OV534_OP_WRITE_2 0x33
49 #define OV534_OP_READ_2 0xf9
51 #define CTRL_TIMEOUT 500
98 .bytesperline = 320 * 2,
99 .sizeimage = 320 * 240 * 2,
103 .bytesperline = 640 * 2,
104 .sizeimage = 640 * 480 * 2,
111 .sizeimage = 320 * 240 * 3 / 8 + 590,
115 .sizeimage = 640 * 480 * 3 / 8 + 590,
119 static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
120 static const u8 vga_rates[] = {60, 50, 40, 30, 15};
122 static const struct framerates ov772x_framerates[] = {
138 static const u8 bridge_init_767x[][2] = {
183 static const u8 sensor_init_767x[][2] = {
338 static const u8 bridge_start_vga_767x[][2] = {
368 static const u8 sensor_start_vga_767x[][2] = {
374 static const u8 bridge_start_qvga_767x[][2] = {
407 static const u8 sensor_start_qvga_767x[][2] = {
414 static const u8 bridge_init_772x[][2] = {
472 static const u8 sensor_init_772x[][2] = {
565 static const u8 bridge_start_vga_772x[][2] = {
576 static const u8 sensor_start_vga_772x[][2] = {
586 static const u8 bridge_start_qvga_772x[][2] = {
597 static const u8 sensor_start_qvga_772x[][2] = {
610 struct usb_device *
udev = gspca_dev->
dev;
616 PDEBUG(D_USBO,
"SET 01 0000 %04x %02x", reg, val);
619 usb_sndctrlpipe(udev, 0),
624 pr_err(
"write failed %d\n", ret);
629 static u8 ov534_reg_read(
struct gspca_dev *gspca_dev,
u16 reg)
631 struct usb_device *udev = gspca_dev->
dev;
637 usb_rcvctrlpipe(udev, 0),
641 PDEBUG(D_USBI,
"GET 01 0000 %04x %02x", reg, gspca_dev->
usb_buf[0]);
643 pr_err(
"read failed %d\n", ret);
651 static void ov534_set_led(
struct gspca_dev *gspca_dev,
int status)
655 PDEBUG(D_CONF,
"led status: %d", status);
657 data = ov534_reg_read(gspca_dev, 0x21);
659 ov534_reg_write(gspca_dev, 0x21, data);
661 data = ov534_reg_read(gspca_dev, 0x23);
667 ov534_reg_write(gspca_dev, 0x23, data);
670 data = ov534_reg_read(gspca_dev, 0x21);
672 ov534_reg_write(gspca_dev, 0x21, data);
676 static int sccb_check_status(
struct gspca_dev *gspca_dev)
681 for (i = 0; i < 5; i++) {
700 static void sccb_reg_write(
struct gspca_dev *gspca_dev,
u8 reg,
u8 val)
702 PDEBUG(D_USBO,
"sccb write: %02x %02x", reg, val);
707 if (!sccb_check_status(gspca_dev)) {
708 pr_err(
"sccb_reg_write failed\n");
713 static u8 sccb_reg_read(
struct gspca_dev *gspca_dev,
u16 reg)
717 if (!sccb_check_status(gspca_dev))
718 pr_err(
"sccb_reg_read failed 1\n");
721 if (!sccb_check_status(gspca_dev))
722 pr_err(
"sccb_reg_read failed 2\n");
728 static void reg_w_array(
struct gspca_dev *gspca_dev,
729 const u8 (*data)[2],
int len)
732 ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
738 static void sccb_w_array(
struct gspca_dev *gspca_dev,
739 const u8 (*data)[2],
int len)
742 if ((*data)[0] != 0xff) {
743 sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
745 sccb_reg_read(gspca_dev, (*data)[1]);
746 sccb_reg_write(gspca_dev, 0xff, 0x00);
753 static void set_frame_rate(
struct gspca_dev *gspca_dev)
755 struct sd *
sd = (
struct sd *) gspca_dev;
763 const struct rate_s *
r;
764 static const struct rate_s rate_0[] = {
765 {60, 0x01, 0xc1, 0x04},
766 {50, 0x01, 0x41, 0x02},
767 {40, 0x02, 0xc1, 0x04},
768 {30, 0x04, 0x81, 0x02},
769 {15, 0x03, 0x41, 0x04},
771 static const struct rate_s rate_1[] = {
772 {125, 0x02, 0x81, 0x02},
773 {100, 0x02, 0xc1, 0x04},
774 {75, 0x03, 0xc1, 0x04},
775 {60, 0x04, 0xc1, 0x04},
776 {50, 0x02, 0x41, 0x04},
777 {40, 0x03, 0x41, 0x04},
778 {30, 0x04, 0x41, 0x04},
783 if (gspca_dev->
cam.cam_mode[gspca_dev->
curr_mode].priv == 0) {
796 sccb_reg_write(gspca_dev, 0x11, r->r11);
797 sccb_reg_write(gspca_dev, 0x0d, r->r0d);
798 ov534_reg_write(gspca_dev, 0xe5, r->re5);
800 PDEBUG(D_PROBE,
"frame_rate: %d", r->fps);
803 static void sethue(
struct gspca_dev *gspca_dev,
s32 val)
805 struct sd *sd = (
struct sd *) gspca_dev;
826 huesin = fixp_sin(val) * 0x80 / 0x100;
827 huecos = fixp_cos(val) * 0x80 / 0x100;
830 sccb_reg_write(gspca_dev, 0xab,
831 sccb_reg_read(gspca_dev, 0xab) | 0x2);
834 sccb_reg_write(gspca_dev, 0xab,
835 sccb_reg_read(gspca_dev, 0xab) & ~0x2);
838 sccb_reg_write(gspca_dev, 0xa9, (
u8)huecos);
839 sccb_reg_write(gspca_dev, 0xaa, (
u8)huesin);
843 static void setsaturation(
struct gspca_dev *gspca_dev,
s32 val)
845 struct sd *sd = (
struct sd *) gspca_dev;
849 static u8 color_tb[][6] = {
850 {0x42, 0x42, 0x00, 0x11, 0x30, 0x41},
851 {0x52, 0x52, 0x00, 0x16, 0x3c, 0x52},
852 {0x66, 0x66, 0x00, 0x1b, 0x4b, 0x66},
853 {0x80, 0x80, 0x00, 0x22, 0x5e, 0x80},
854 {0x9a, 0x9a, 0x00, 0x29, 0x71, 0x9a},
855 {0xb8, 0xb8, 0x00, 0x31, 0x87, 0xb8},
856 {0xdd, 0xdd, 0x00, 0x3b, 0xa2, 0xdd},
860 sccb_reg_write(gspca_dev, 0x4f + i, color_tb[val][i]);
862 sccb_reg_write(gspca_dev, 0xa7, val);
863 sccb_reg_write(gspca_dev, 0xa8, val);
867 static void setbrightness(
struct gspca_dev *gspca_dev,
s32 val)
869 struct sd *sd = (
struct sd *) gspca_dev;
874 sccb_reg_write(gspca_dev, 0x55, val);
876 sccb_reg_write(gspca_dev, 0x9b, val);
880 static void setcontrast(
struct gspca_dev *gspca_dev,
s32 val)
882 struct sd *sd = (
struct sd *) gspca_dev;
885 sccb_reg_write(gspca_dev, 0x56, val);
887 sccb_reg_write(gspca_dev, 0x9c, val);
890 static void setgain(
struct gspca_dev *gspca_dev,
s32 val)
892 switch (val & 0x30) {
910 sccb_reg_write(gspca_dev, 0x00, val);
913 static s32 getgain(
struct gspca_dev *gspca_dev)
915 return sccb_reg_read(gspca_dev, 0x00);
918 static void setexposure(
struct gspca_dev *gspca_dev,
s32 val)
920 struct sd *sd = (
struct sd *) gspca_dev;
925 sccb_reg_write(gspca_dev, 0x10, val);
934 sccb_reg_write(gspca_dev, 0x08, val >> 7);
935 sccb_reg_write(gspca_dev, 0x10, val << 1);
939 static s32 getexposure(
struct gspca_dev *gspca_dev)
941 struct sd *sd = (
struct sd *) gspca_dev;
945 return sccb_reg_read(gspca_dev, 0x10);
947 u8 hi = sccb_reg_read(gspca_dev, 0x08);
948 u8 lo = sccb_reg_read(gspca_dev, 0x10);
949 return (hi << 8 | lo) >> 1;
953 static void setagc(
struct gspca_dev *gspca_dev,
s32 val)
956 sccb_reg_write(gspca_dev, 0x13,
957 sccb_reg_read(gspca_dev, 0x13) | 0x04);
958 sccb_reg_write(gspca_dev, 0x64,
959 sccb_reg_read(gspca_dev, 0x64) | 0x03);
961 sccb_reg_write(gspca_dev, 0x13,
962 sccb_reg_read(gspca_dev, 0x13) & ~0x04);
963 sccb_reg_write(gspca_dev, 0x64,
964 sccb_reg_read(gspca_dev, 0x64) & ~0x03);
968 static void setawb(
struct gspca_dev *gspca_dev,
s32 val)
970 struct sd *sd = (
struct sd *) gspca_dev;
973 sccb_reg_write(gspca_dev, 0x13,
974 sccb_reg_read(gspca_dev, 0x13) | 0x02);
976 sccb_reg_write(gspca_dev, 0x63,
977 sccb_reg_read(gspca_dev, 0x63) | 0xc0);
979 sccb_reg_write(gspca_dev, 0x13,
980 sccb_reg_read(gspca_dev, 0x13) & ~0x02);
982 sccb_reg_write(gspca_dev, 0x63,
983 sccb_reg_read(gspca_dev, 0x63) & ~0xc0);
987 static void setaec(
struct gspca_dev *gspca_dev,
s32 val)
989 struct sd *sd = (
struct sd *) gspca_dev;
997 sccb_reg_write(gspca_dev, 0x13,
998 sccb_reg_read(gspca_dev, 0x13) | data);
1001 sccb_reg_write(gspca_dev, 0x13,
1002 sccb_reg_read(gspca_dev, 0x13) & ~data);
1007 static void setsharpness(
struct gspca_dev *gspca_dev,
s32 val)
1009 sccb_reg_write(gspca_dev, 0x91, val);
1010 sccb_reg_write(gspca_dev, 0x8e, val);
1015 struct sd *sd = (
struct sd *) gspca_dev;
1019 val = sccb_reg_read(gspca_dev, 0x1e);
1025 sccb_reg_write(gspca_dev, 0x1e, val);
1027 val = sccb_reg_read(gspca_dev, 0x0c);
1033 sccb_reg_write(gspca_dev, 0x0c, val);
1037 static void setlightfreq(
struct gspca_dev *gspca_dev,
s32 val)
1039 struct sd *sd = (
struct sd *) gspca_dev;
1041 val = val ? 0x9e : 0x00;
1043 sccb_reg_write(gspca_dev, 0x2a, 0x00);
1047 sccb_reg_write(gspca_dev, 0x2b, val);
1052 static int sd_config(
struct gspca_dev *gspca_dev,
1055 struct sd *sd = (
struct sd *) gspca_dev;
1058 cam = &gspca_dev->
cam;
1071 struct gspca_dev *gspca_dev = &sd->
gspca_dev;
1077 sd->
gain->val = getgain(gspca_dev);
1084 sd->
exposure->val = getexposure(gspca_dev);
1090 static int ov534_s_ctrl(
struct v4l2_ctrl *ctrl)
1093 struct gspca_dev *gspca_dev = &sd->
gspca_dev;
1101 sethue(gspca_dev, ctrl->
val);
1104 setsaturation(gspca_dev, ctrl->
val);
1107 setbrightness(gspca_dev, ctrl->
val);
1110 setcontrast(gspca_dev, ctrl->
val);
1114 setagc(gspca_dev, ctrl->
val);
1116 setgain(gspca_dev, sd->
gain->val);
1119 setawb(gspca_dev, ctrl->
val);
1123 setaec(gspca_dev, ctrl->
val);
1126 setexposure(gspca_dev, sd->
exposure->val);
1129 setsharpness(gspca_dev, ctrl->
val);
1132 sethvflip(gspca_dev, ctrl->
val, sd->
vflip->val);
1135 sethvflip(gspca_dev, sd->
hflip->val, ctrl->
val);
1138 setlightfreq(gspca_dev, ctrl->
val);
1145 .g_volatile_ctrl = ov534_g_volatile_ctrl,
1146 .s_ctrl = ov534_s_ctrl,
1149 static int sd_init_controls(
struct gspca_dev *gspca_dev)
1151 struct sd *sd = (
struct sd *) gspca_dev;
1171 brightness_min = -127;
1172 brightness_max = 127;
1174 contrast_max = 0x80;
1175 contrast_def = 0x40;
1176 exposure_min = 0x08;
1177 exposure_max = 0x60;
1178 exposure_def = 0x13;
1182 saturation_max = 255,
1183 saturation_def = 64,
1185 brightness_max = 255;
1195 gspca_dev->
vdev.ctrl_handler = hdl;
1244 pr_err(
"Could not initialize controls\n");
1258 static int sd_init(
struct gspca_dev *gspca_dev)
1260 struct sd *sd = (
struct sd *) gspca_dev;
1272 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
1273 ov534_reg_write(gspca_dev, 0xe0, 0x08);
1280 sccb_reg_write(gspca_dev, 0x12, 0x80);
1284 sccb_reg_read(gspca_dev, 0x0a);
1285 sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
1286 sccb_reg_read(gspca_dev, 0x0b);
1287 sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
1288 PDEBUG(D_PROBE,
"Sensor ID: %04x", sensor_id);
1290 if ((sensor_id & 0xfff0) == 0x7670) {
1292 gspca_dev->
cam.cam_mode = ov767x_mode;
1296 gspca_dev->
cam.bulk = 1;
1297 gspca_dev->
cam.bulk_size = 16384;
1298 gspca_dev->
cam.bulk_nurbs = 2;
1299 gspca_dev->
cam.mode_framerates = ov772x_framerates;
1303 reg_w_array(gspca_dev, bridge_init[sd->
sensor].
val,
1305 ov534_set_led(gspca_dev, 1);
1306 sccb_w_array(gspca_dev, sensor_init[sd->
sensor].
val,
1309 sd_start(gspca_dev);
1310 sd_stopN(gspca_dev);
1316 static int sd_start(
struct gspca_dev *gspca_dev)
1318 struct sd *sd = (
struct sd *) gspca_dev;
1323 {bridge_start_vga_767x,
1327 {bridge_start_vga_772x,
1333 {sensor_start_vga_767x,
1337 {sensor_start_vga_772x,
1343 sccb_reg_write(gspca_dev, 0x1e, 0x04);
1347 reg_w_array(gspca_dev, bridge_start[sd->
sensor][mode].
val,
1349 sccb_w_array(gspca_dev, sensor_start[sd->
sensor][mode].
val,
1352 set_frame_rate(gspca_dev);
1372 ov534_set_led(gspca_dev, 1);
1373 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1377 static void sd_stopN(
struct gspca_dev *gspca_dev)
1379 ov534_reg_write(gspca_dev, 0xe0, 0x09);
1380 ov534_set_led(gspca_dev, 0);
1384 #define UVC_STREAM_EOH (1 << 7)
1385 #define UVC_STREAM_ERR (1 << 6)
1386 #define UVC_STREAM_STI (1 << 5)
1387 #define UVC_STREAM_RES (1 << 4)
1388 #define UVC_STREAM_SCR (1 << 3)
1389 #define UVC_STREAM_PTS (1 << 2)
1390 #define UVC_STREAM_EOF (1 << 1)
1391 #define UVC_STREAM_FID (1 << 0)
1393 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
1396 struct sd *sd = (
struct sd *) gspca_dev;
1399 int remaining_len = len;
1402 payload_len = gspca_dev->
cam.bulk ? 2048 : 2040;
1404 len =
min(remaining_len, payload_len);
1412 if (data[0] != 12 || len < 12) {
1413 PDEBUG(D_PACK,
"bad header");
1419 PDEBUG(D_PACK,
"payload error");
1425 PDEBUG(D_PACK,
"PTS not present");
1428 this_pts = (data[5] << 24) | (data[4] << 16)
1429 | (data[3] << 8) | data[2];
1440 data + 12, len - 12);
1447 PDEBUG(D_PACK,
"wrong sized frame");
1451 data + 12, len - 12);
1456 data + 12, len - 12);
1467 remaining_len -= len;
1469 }
while (remaining_len > 0);
1473 static void sd_get_streamparm(
struct gspca_dev *gspca_dev,
1478 struct sd *sd = (
struct sd *) gspca_dev;
1486 static void sd_set_streamparm(
struct gspca_dev *gspca_dev,
1491 struct sd *sd = (
struct sd *) gspca_dev;
1496 set_frame_rate(gspca_dev);
1506 .config = sd_config,
1508 .init_controls = sd_init_controls,
1511 .pkt_scan = sd_pkt_scan,
1512 .get_streamparm = sd_get_streamparm,
1513 .set_streamparm = sd_set_streamparm,
1518 {USB_DEVICE(0x1415, 0x2000)},
1519 {USB_DEVICE(0x06f8, 0x3002)},
1532 static struct usb_driver sd_driver = {
1534 .id_table = device_table,
1538 .suspend = gspca_suspend,
1539 .resume = gspca_resume,
1540 .reset_resume = gspca_resume,