2 * SPCA505 chip based cameras initialization data
4 * V4L2 by Jean-Francis Moine <http://moinejf.free.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define MODULE_NAME "spca505"
26 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
27 MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
28 MODULE_LICENSE("GPL");
30 /* specific webcam descriptor */
32 struct gspca_dev gspca_dev
; /* !! must be the first item */
37 #define IntelPCCameraPro 0
41 /* V4L2 controls supported by the driver */
42 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
43 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
45 static const struct ctrl sd_ctrls
[] = {
48 .id
= V4L2_CID_BRIGHTNESS
,
49 .type
= V4L2_CTRL_TYPE_INTEGER
,
54 #define BRIGHTNESS_DEF 127
55 .default_value
= BRIGHTNESS_DEF
,
57 .set
= sd_setbrightness
,
58 .get
= sd_getbrightness
,
62 static const struct v4l2_pix_format vga_mode
[] = {
63 {160, 120, V4L2_PIX_FMT_SPCA505
, V4L2_FIELD_NONE
,
65 .sizeimage
= 160 * 120 * 3 / 2,
66 .colorspace
= V4L2_COLORSPACE_SRGB
,
68 {176, 144, V4L2_PIX_FMT_SPCA505
, V4L2_FIELD_NONE
,
70 .sizeimage
= 176 * 144 * 3 / 2,
71 .colorspace
= V4L2_COLORSPACE_SRGB
,
73 {320, 240, V4L2_PIX_FMT_SPCA505
, V4L2_FIELD_NONE
,
75 .sizeimage
= 320 * 240 * 3 / 2,
76 .colorspace
= V4L2_COLORSPACE_SRGB
,
78 {352, 288, V4L2_PIX_FMT_SPCA505
, V4L2_FIELD_NONE
,
80 .sizeimage
= 352 * 288 * 3 / 2,
81 .colorspace
= V4L2_COLORSPACE_SRGB
,
83 {640, 480, V4L2_PIX_FMT_SPCA505
, V4L2_FIELD_NONE
,
85 .sizeimage
= 640 * 480 * 3 / 2,
86 .colorspace
= V4L2_COLORSPACE_SRGB
,
90 #define SPCA50X_OFFSET_DATA 10
92 #define SPCA50X_REG_USB 0x02 /* spca505 501 */
94 #define SPCA50X_USB_CTRL 0x00 /* spca505 */
95 #define SPCA50X_CUSB_ENABLE 0x01 /* spca505 */
97 #define SPCA50X_REG_GLOBAL 0x03 /* spca505 */
98 #define SPCA50X_GMISC0_IDSEL 0x01 /* Global control device ID select spca505 */
99 #define SPCA50X_GLOBAL_MISC0 0x00 /* Global control miscellaneous 0 spca505 */
101 #define SPCA50X_GLOBAL_MISC1 0x01 /* 505 */
102 #define SPCA50X_GLOBAL_MISC3 0x03 /* 505 */
103 #define SPCA50X_GMISC3_SAA7113RST 0x20 /* Not sure about this one spca505 */
105 /* Image format and compression control */
106 #define SPCA50X_REG_COMPRESS 0x04
109 * Data to initialize a SPCA505. Common to the CCD and external modes
111 static const u8 spca505_init_data
[][3] = {
112 /* bmRequest,value,index */
113 {SPCA50X_REG_GLOBAL
, SPCA50X_GMISC3_SAA7113RST
, SPCA50X_GLOBAL_MISC3
},
115 {SPCA50X_REG_GLOBAL
, 0x00, SPCA50X_GLOBAL_MISC3
},
116 {SPCA50X_REG_GLOBAL
, 0x00, SPCA50X_GLOBAL_MISC1
},
117 /* Block USB reset */
118 {SPCA50X_REG_GLOBAL
, SPCA50X_GMISC0_IDSEL
, SPCA50X_GLOBAL_MISC0
},
121 /* Maybe power down some stuff */
124 /* Setup internal CCD ? */
146 * Data to initialize the camera using the internal CCD
148 static const u8 spca505_open_data_ccd
[][3] = {
149 /* bmRequest,value,index */
150 /* Internal CCD data set */
152 /* This could be a reset */
155 /* Setup compression and image registers. 0x6 and 0x7 seem to be
156 related to H&V hold, and are resolution mode specific */
158 /* DIFF(0x50), was (0x10) */
165 /* DIFF (0x4a), was (0xa) */
170 /* DIFF not written */
172 /* DIFF not written */
174 /* DIFF not written */
176 /* DIFF not written */
178 /* DIFF not written */
180 /* DIFF not written */
182 /* DIFF not written */
184 /* DIFF not written */
186 /* DIFF not written */
188 /* DIFF not written */
190 /* DIFF not written */
192 /* DIFF not written */
194 /* DIFF not written */
197 /* DIFF (0x3,0x28,0x3) */
200 /* DIFF not written */
204 /* Extra block copied from init to hopefully ensure CCD is in a sane state */
222 /* End of extra block */
289 /* Compress = OFF (0x1 to turn on) */
295 /* was 5 (Image Type ? ) */
327 * Made by Tomasz Zablocki (skalamandra@poczta.onet.pl)
328 * SPCA505b chip based cameras initialization data
331 #define initial_brightness 0x7f /* 0x0(white)-0xff(black) */
332 /* #define initial_brightness 0x0 //0x0(white)-0xff(black) */
334 * Data to initialize a SPCA505. Common to the CCD and external modes
336 static const u8 spca505b_init_data
[][3] = {
338 {0x02, 0x00, 0x00}, /* init */
394 * Data to initialize the camera using the internal CCD
396 static const u8 spca505b_open_data_ccd
[][3] = {
398 /* {0x02,0x00,0x00}, */
399 {0x03, 0x04, 0x01}, /* rst */
425 {0x05, initial_brightness
>> 6, 0x00},
426 {0x05, (initial_brightness
<< 2) & 0xff, 0x01},
436 {0x05, 0x80, 0x14}, /* max exposure off (0=on) */
455 {0x06, 0x11, 0x10}, /* contrast */
520 {0x06, 0x4d, 0x51}, /* maybe saturation (4d) */
521 {0x06, 0x84, 0x53}, /* making green (84) */
522 {0x06, 0x00, 0x57}, /* sharpness (1) */
527 {0x06, 0x18, 0x0c}, /* maybe hue (18) */
531 {0x06, 0x18, 0x10}, /* maybe contrast (18) */
535 {0x04, 0x00, 0x08}, /* compression */
540 {0x04, 0x1d, 0x00}, /* imagetype (1d) */
541 {0x04, 0x41, 0x01}, /* hardware snapcontrol */
559 {0x05, initial_brightness
>> 6, 0x00},
560 {0x05, (initial_brightness
<< 2) & 0xff, 0x01},
568 static int reg_write(struct usb_device
*dev
,
569 u16 req
, u16 index
, u16 value
)
573 ret
= usb_control_msg(dev
,
574 usb_sndctrlpipe(dev
, 0),
576 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
577 value
, index
, NULL
, 0, 500);
578 PDEBUG(D_USBO
, "reg write: 0x%02x,0x%02x:0x%02x, %d",
579 req
, index
, value
, ret
);
581 err("reg write: error %d", ret
);
585 /* returns: negative is error, pos or zero is data */
586 static int reg_read(struct gspca_dev
*gspca_dev
,
587 u16 req
, /* bRequest */
588 u16 index
) /* wIndex */
592 ret
= usb_control_msg(gspca_dev
->dev
,
593 usb_rcvctrlpipe(gspca_dev
->dev
, 0),
595 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
598 gspca_dev
->usb_buf
, 2,
602 return (gspca_dev
->usb_buf
[1] << 8) + gspca_dev
->usb_buf
[0];
605 static int write_vector(struct gspca_dev
*gspca_dev
,
608 struct usb_device
*dev
= gspca_dev
->dev
;
611 while (data
[i
][0] != 0) {
612 ret
= reg_write(dev
, data
[i
][0], data
[i
][2], data
[i
][1]);
620 /* this function is called at probe time */
621 static int sd_config(struct gspca_dev
*gspca_dev
,
622 const struct usb_device_id
*id
)
624 struct sd
*sd
= (struct sd
*) gspca_dev
;
627 cam
= &gspca_dev
->cam
;
628 cam
->cam_mode
= vga_mode
;
629 sd
->subtype
= id
->driver_info
;
630 if (sd
->subtype
!= IntelPCCameraPro
)
631 cam
->nmodes
= ARRAY_SIZE(vga_mode
);
632 else /* no 640x480 for IntelPCCameraPro */
633 cam
->nmodes
= ARRAY_SIZE(vga_mode
) - 1;
634 sd
->brightness
= BRIGHTNESS_DEF
;
639 /* this function is called at probe and resume time */
640 static int sd_init(struct gspca_dev
*gspca_dev
)
642 struct sd
*sd
= (struct sd
*) gspca_dev
;
644 if (write_vector(gspca_dev
,
645 sd
->subtype
== Nxultra
647 : spca505_init_data
))
652 static void setbrightness(struct gspca_dev
*gspca_dev
)
654 struct sd
*sd
= (struct sd
*) gspca_dev
;
655 u8 brightness
= sd
->brightness
;
657 reg_write(gspca_dev
->dev
, 0x05, 0x00, (255 - brightness
) >> 6);
658 reg_write(gspca_dev
->dev
, 0x05, 0x01, (255 - brightness
) << 2);
661 static int sd_start(struct gspca_dev
*gspca_dev
)
663 struct sd
*sd
= (struct sd
*) gspca_dev
;
664 struct usb_device
*dev
= gspca_dev
->dev
;
666 static u8 mode_tb
[][3] = {
668 {0x00, 0x10, 0x10}, /* 640x480 */
669 {0x01, 0x1a, 0x1a}, /* 352x288 */
670 {0x02, 0x1c, 0x1d}, /* 320x240 */
671 {0x04, 0x34, 0x34}, /* 176x144 */
672 {0x05, 0x40, 0x40} /* 160x120 */
675 if (sd
->subtype
== Nxultra
)
676 write_vector(gspca_dev
, spca505b_open_data_ccd
);
678 write_vector(gspca_dev
, spca505_open_data_ccd
);
679 ret
= reg_read(gspca_dev
, 0x06, 0x16);
683 "register read failed err: %d",
688 err("After vector read returns 0x%04x should be 0x0101",
692 ret
= reg_write(gspca_dev
->dev
, 0x06, 0x16, 0x0a);
695 reg_write(gspca_dev
->dev
, 0x05, 0xc2, 0x12);
697 /* necessary because without it we can see stream
698 * only once after loading module */
699 /* stopping usb registers Tomasz change */
700 reg_write(dev
, 0x02, 0x00, 0x00);
702 mode
= gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
;
703 reg_write(dev
, SPCA50X_REG_COMPRESS
, 0x00, mode_tb
[mode
][0]);
704 reg_write(dev
, SPCA50X_REG_COMPRESS
, 0x06, mode_tb
[mode
][1]);
705 reg_write(dev
, SPCA50X_REG_COMPRESS
, 0x07, mode_tb
[mode
][2]);
707 ret
= reg_write(dev
, SPCA50X_REG_USB
,
709 SPCA50X_CUSB_ENABLE
);
711 setbrightness(gspca_dev
);
716 static void sd_stopN(struct gspca_dev
*gspca_dev
)
718 /* Disable ISO packet machine */
719 reg_write(gspca_dev
->dev
, 0x02, 0x00, 0x00);
722 /* called on streamoff with alt 0 and on disconnect */
723 static void sd_stop0(struct gspca_dev
*gspca_dev
)
725 if (!gspca_dev
->present
)
728 /* This maybe reset or power control */
729 reg_write(gspca_dev
->dev
, 0x03, 0x03, 0x20);
730 reg_write(gspca_dev
->dev
, 0x03, 0x01, 0x00);
731 reg_write(gspca_dev
->dev
, 0x03, 0x00, 0x01);
732 reg_write(gspca_dev
->dev
, 0x05, 0x10, 0x01);
733 reg_write(gspca_dev
->dev
, 0x05, 0x11, 0x0f);
736 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
737 u8
*data
, /* isoc packet */
738 int len
) /* iso packet length */
741 case 0: /* start of frame */
742 gspca_frame_add(gspca_dev
, LAST_PACKET
, NULL
, 0);
743 data
+= SPCA50X_OFFSET_DATA
;
744 len
-= SPCA50X_OFFSET_DATA
;
745 gspca_frame_add(gspca_dev
, FIRST_PACKET
, data
, len
);
747 case 0xff: /* drop */
752 gspca_frame_add(gspca_dev
, INTER_PACKET
, data
, len
);
757 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
759 struct sd
*sd
= (struct sd
*) gspca_dev
;
761 sd
->brightness
= val
;
762 if (gspca_dev
->streaming
)
763 setbrightness(gspca_dev
);
767 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
769 struct sd
*sd
= (struct sd
*) gspca_dev
;
771 *val
= sd
->brightness
;
775 /* sub-driver description */
776 static const struct sd_desc sd_desc
= {
779 .nctrls
= ARRAY_SIZE(sd_ctrls
),
785 .pkt_scan
= sd_pkt_scan
,
788 /* -- module initialisation -- */
789 static const struct usb_device_id device_table
[] = {
790 {USB_DEVICE(0x041e, 0x401d), .driver_info
= Nxultra
},
791 {USB_DEVICE(0x0733, 0x0430), .driver_info
= IntelPCCameraPro
},
792 /*fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
795 MODULE_DEVICE_TABLE(usb
, device_table
);
797 /* -- device connect -- */
798 static int sd_probe(struct usb_interface
*intf
,
799 const struct usb_device_id
*id
)
801 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
805 static struct usb_driver sd_driver
= {
807 .id_table
= device_table
,
809 .disconnect
= gspca_disconnect
,
811 .suspend
= gspca_suspend
,
812 .resume
= gspca_resume
,
816 /* -- module insert / remove -- */
817 static int __init
sd_mod_init(void)
819 return usb_register(&sd_driver
);
821 static void __exit
sd_mod_exit(void)
823 usb_deregister(&sd_driver
);
826 module_init(sd_mod_init
);
827 module_exit(sd_mod_exit
);