21 #define MODULE_NAME "jl2005bcd"
24 #include <linux/slab.h>
33 #define JL2005C_CMD_TIMEOUT 500
34 #define JL2005C_DATA_TIMEOUT 1000
37 #define JL2005C_MAX_TRANSFER 0x200
38 #define FRAME_HEADER_LEN 16
59 .sizeimage = 176 * 144,
64 .sizeimage = 352 * 288,
72 .sizeimage = 320 * 240,
77 .sizeimage = 640 * 480,
94 usb_sndbulkpipe(gspca_dev->
dev, 3),
97 pr_err(
"command write [%02x] error %d\n",
103 static int jl2005c_read1(
struct gspca_dev *gspca_dev)
108 usb_rcvbulkpipe(gspca_dev->
dev, 0x84),
111 pr_err(
"read command [0x%02x] error %d\n",
112 gspca_dev->
usb_buf[0], retval);
117 static int jl2005c_read_reg(
struct gspca_dev *gspca_dev,
unsigned char reg)
123 instruction[1] =
reg;
125 retval = jl2005c_write2(gspca_dev, instruction);
128 retval = jl2005c_read1(gspca_dev);
133 static int jl2005c_start_new_frame(
struct gspca_dev *gspca_dev)
137 int frame_brightness = 0;
139 static u8 instruction[2] = {0x7f, 0x01};
141 retval = jl2005c_write2(gspca_dev, instruction);
146 while (i < 20 && !frame_brightness) {
148 retval = jl2005c_read_reg(gspca_dev, 0x7e);
151 frame_brightness = gspca_dev->
usb_buf[0];
152 retval = jl2005c_read_reg(gspca_dev, 0x7d);
157 PDEBUG(D_FRAM,
"frame_brightness is 0x%02x", gspca_dev->
usb_buf[0]);
161 static int jl2005c_write_reg(
struct gspca_dev *gspca_dev,
unsigned char reg,
167 instruction[0] =
reg;
168 instruction[1] =
value;
170 retval = jl2005c_write2(gspca_dev, instruction);
177 static int jl2005c_get_firmware_id(
struct gspca_dev *gspca_dev)
179 struct sd *
sd = (
struct sd *)gspca_dev;
182 unsigned char regs_to_read[] = {0x57, 0x02, 0x03, 0x5d, 0x5e, 0x5f};
184 PDEBUG(D_PROBE,
"Running jl2005c_get_firmware_id");
186 retval = jl2005c_read_reg(gspca_dev, regs_to_read[0]);
191 for (i = 0; i < 6; i++) {
192 retval = jl2005c_read_reg(gspca_dev, regs_to_read[i]);
197 PDEBUG(D_PROBE,
"firmware ID is %02x%02x%02x%02x%02x%02x",
207 static int jl2005c_stream_start_vga_lg
208 (
struct gspca_dev *gspca_dev)
212 static u8 instruction[][2] = {
221 for (i = 0; i <
ARRAY_SIZE(instruction); i++) {
223 retval = jl2005c_write2(gspca_dev, instruction[i]);
231 static int jl2005c_stream_start_vga_small(
struct gspca_dev *gspca_dev)
235 static u8 instruction[][2] = {
244 for (i = 0; i <
ARRAY_SIZE(instruction); i++) {
246 retval = jl2005c_write2(gspca_dev, instruction[i]);
254 static int jl2005c_stream_start_cif_lg(
struct gspca_dev *gspca_dev)
258 static u8 instruction[][2] = {
267 for (i = 0; i <
ARRAY_SIZE(instruction); i++) {
269 retval = jl2005c_write2(gspca_dev, instruction[i]);
277 static int jl2005c_stream_start_cif_small(
struct gspca_dev *gspca_dev)
281 static u8 instruction[][2] = {
290 for (i = 0; i <
ARRAY_SIZE(instruction); i++) {
292 retval = jl2005c_write2(gspca_dev, instruction[i]);
301 static int jl2005c_stop(
struct gspca_dev *gspca_dev)
305 retval = jl2005c_write_reg(gspca_dev, 0x07, 0x00);
320 struct gspca_dev *gspca_dev = &dev->
gspca_dev;
324 unsigned char header_sig[2] = {0x4a, 0x4c};
332 pr_err(
"Couldn't allocate USB buffer\n");
338 if (gspca_dev->frozen)
344 ret = jl2005c_start_new_frame(gspca_dev);
349 usb_rcvbulkpipe(gspca_dev->
dev, 0x82),
353 "Got %d bytes out of %d for header",
358 if (
memcmp(header_sig, buffer, 2) != 0) {
359 pr_err(
"First block is not the first block\n");
364 bytes_left = buffer[0x07] * dev->
block_size - act_len;
365 PDEBUG(D_PACK,
"bytes_left = 0x%x", bytes_left);
372 while (bytes_left > 0 && gspca_dev->
present) {
376 usb_rcvbulkpipe(gspca_dev->
dev, 0x82),
377 buffer, data_len, &act_len,
379 if (ret < 0 || act_len < data_len)
382 "Got %d bytes out of %d for frame",
383 data_len, bytes_left);
385 if (bytes_left == 0) {
397 jl2005c_stop(gspca_dev);
407 static int sd_config(
struct gspca_dev *gspca_dev,
411 struct sd *sd = (
struct sd *) gspca_dev;
413 cam = &gspca_dev->
cam;
418 jl2005c_get_firmware_id(gspca_dev);
447 static int sd_init(
struct gspca_dev *gspca_dev)
452 static int sd_start(
struct gspca_dev *gspca_dev)
455 struct sd *sd = (
struct sd *) gspca_dev;
458 switch (gspca_dev->
width) {
460 PDEBUG(D_STREAM,
"Start streaming at vga resolution");
461 jl2005c_stream_start_vga_lg(gspca_dev);
464 PDEBUG(D_STREAM,
"Start streaming at qvga resolution");
465 jl2005c_stream_start_vga_small(gspca_dev);
468 PDEBUG(D_STREAM,
"Start streaming at cif resolution");
469 jl2005c_stream_start_cif_lg(gspca_dev);
472 PDEBUG(D_STREAM,
"Start streaming at qcif resolution");
473 jl2005c_stream_start_cif_small(gspca_dev);
476 pr_err(
"Unknown resolution specified\n");
489 static void sd_stop0(
struct gspca_dev *gspca_dev)
491 struct sd *dev = (
struct sd *) gspca_dev;
514 {USB_DEVICE(0x0979, 0x0227)},
527 static struct usb_driver sd_driver = {
529 .id_table = device_table,
533 .suspend = gspca_suspend,
534 .resume = gspca_resume,
535 .reset_resume = gspca_resume,
540 static int __init sd_mod_init(
void)
544 ret = usb_register(&sd_driver);
549 static void __exit sd_mod_exit(
void)