60 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
62 #define MODULE_NAME "pac7311"
64 #include <linux/input.h>
69 #define PAC7311_GAIN_DEFAULT 122
70 #define PAC7311_EXPOSURE_DEFAULT 3
91 .sizeimage = 160 * 120 * 3 / 8 + 590,
96 .sizeimage = 320 * 240 * 3 / 8 + 590,
101 .sizeimage = 640 * 480 * 3 / 8 + 590,
106 #define LOAD_PAGE4 254
107 #define END_OF_SEQUENCE 0
109 static const __u8 init_7311[] = {
123 static const __u8 start_7311[] = {
126 0x02, 43, 0x48, 0x0a, 0x40, 0x08, 0x00, 0x00, 0x08, 0x00,
127 0x06, 0xff, 0x11, 0xff, 0x5a, 0x30, 0x90, 0x4c,
128 0x00, 0x07, 0x00, 0x0a, 0x10, 0x00, 0xa0, 0x10,
129 0x02, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x00,
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 0x3e, 42, 0x00, 0x00, 0x78, 0x52, 0x4a, 0x52, 0x78, 0x6e,
133 0x48, 0x46, 0x48, 0x6e, 0x5f, 0x49, 0x42, 0x49,
134 0x5f, 0x5f, 0x49, 0x42, 0x49, 0x5f, 0x6e, 0x48,
135 0x46, 0x48, 0x6e, 0x78, 0x52, 0x4a, 0x52, 0x78,
136 0x00, 0x00, 0x09, 0x1b, 0x34, 0x49, 0x5c, 0x9b,
138 0x78, 6, 0x44, 0x00, 0xf2, 0x01, 0x01, 0x80,
139 0x7f, 18, 0x2a, 0x1c, 0x00, 0xc8, 0x02, 0x58, 0x03, 0x84,
140 0x12, 0x00, 0x1a, 0x04, 0x08, 0x0c, 0x10, 0x14,
142 0x96, 3, 0x01, 0x08, 0x04,
143 0xa0, 4, 0x44, 0x44, 0x44, 0x04,
144 0xf0, 13, 0x01, 0x00, 0x00, 0x00, 0x22, 0x00, 0x20, 0x00,
145 0x3f, 0x00, 0x0a, 0x01, 0x00,
154 static const __u8 page4_7311[] = {
155 SKIP,
SKIP, 0x04, 0x54, 0x07, 0x2b, 0x09, 0x0f,
156 0x09, 0x00,
SKIP,
SKIP, 0x07, 0x00, 0x00, 0x62,
157 0x08,
SKIP, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
158 0x00, 0x00, 0x00, 0x03, 0xa0, 0x01, 0xf4,
SKIP,
160 0xca, 0x10, 0x06, 0x78, 0x00, 0x00, 0x00, 0x00,
161 0x23, 0x28, 0x04, 0x11, 0x00, 0x00
174 usb_sndctrlpipe(gspca_dev->
dev, 0),
178 index, gspca_dev->
usb_buf, len,
181 pr_err(
"reg_w_buf() failed index 0x%02x, error %d\n",
188 static void reg_w(
struct gspca_dev *gspca_dev,
198 usb_sndctrlpipe(gspca_dev->
dev, 0),
201 0, index, gspca_dev->
usb_buf, 1,
204 pr_err(
"reg_w() failed index 0x%02x, value 0x%02x, error %d\n",
210 static void reg_w_seq(
struct gspca_dev *gspca_dev,
211 const __u8 *seq,
int len)
214 reg_w(gspca_dev, seq[0], seq[1]);
220 static void reg_w_page(
struct gspca_dev *gspca_dev,
228 for (index = 0; index < len; index++) {
229 if (page[index] ==
SKIP)
233 usb_sndctrlpipe(gspca_dev->
dev, 0),
236 0, index, gspca_dev->
usb_buf, 1,
239 pr_err(
"reg_w_page() failed index 0x%02x, value 0x%02x, error %d\n",
240 index, page[index], ret);
248 static void reg_w_var(
struct gspca_dev *gspca_dev,
250 const __u8 *page4,
unsigned int page4_len)
261 reg_w_page(gspca_dev, page4, page4_len);
266 "Incorrect variable sequence");
276 reg_w_buf(gspca_dev, index, seq, 8);
287 static int sd_config(
struct gspca_dev *gspca_dev,
299 static void setcontrast(
struct gspca_dev *gspca_dev,
s32 val)
301 reg_w(gspca_dev, 0xff, 0x04);
302 reg_w(gspca_dev, 0x10, val);
304 reg_w(gspca_dev, 0x11, 0x01);
307 static void setgain(
struct gspca_dev *gspca_dev,
s32 val)
309 reg_w(gspca_dev, 0xff, 0x04);
310 reg_w(gspca_dev, 0x0e, 0x00);
311 reg_w(gspca_dev, 0x0f, gspca_dev->
gain->maximum - val + 1);
314 reg_w(gspca_dev, 0x11, 0x01);
317 static void setexposure(
struct gspca_dev *gspca_dev,
s32 val)
319 reg_w(gspca_dev, 0xff, 0x04);
320 reg_w(gspca_dev, 0x02, val);
323 reg_w(gspca_dev, 0x11, 0x01);
329 reg_w(gspca_dev, 0xff, 0x01);
330 if (gspca_dev->
width != 640 && val <= 3)
331 reg_w(gspca_dev, 0x08, 0x09);
333 reg_w(gspca_dev, 0x08, 0x08);
341 if (gspca_dev->
width == 640 && val == 2)
342 reg_w(gspca_dev, 0x80, 0x01);
344 reg_w(gspca_dev, 0x80, 0x1c);
347 reg_w(gspca_dev, 0x11, 0x01);
350 static void sethvflip(
struct gspca_dev *gspca_dev,
s32 hflip,
s32 vflip)
354 reg_w(gspca_dev, 0xff, 0x04);
355 data = (hflip ? 0x04 : 0x00) |
356 (vflip ? 0x08 : 0x00);
357 reg_w(gspca_dev, 0x21, data);
360 reg_w(gspca_dev, 0x11, 0x01);
364 static int sd_init(
struct gspca_dev *gspca_dev)
366 reg_w_seq(gspca_dev, init_7311,
sizeof(init_7311)/2);
372 struct gspca_dev *gspca_dev =
374 struct sd *
sd = (
struct sd *)gspca_dev;
393 setcontrast(gspca_dev, ctrl->
val);
397 setexposure(gspca_dev, gspca_dev->
exposure->val);
399 setgain(gspca_dev, gspca_dev->
gain->val);
402 sethvflip(gspca_dev, sd->
hflip->val, 1);
415 static int sd_init_controls(
struct gspca_dev *gspca_dev)
417 struct sd *sd = (
struct sd *) gspca_dev;
420 gspca_dev->
vdev.ctrl_handler = hdl;
437 pr_err(
"Could not initialize controls\n");
446 static int sd_start(
struct gspca_dev *gspca_dev)
448 struct sd *sd = (
struct sd *) gspca_dev;
452 reg_w_var(gspca_dev, start_7311,
453 page4_7311,
sizeof(page4_7311));
460 switch (gspca_dev->
cam.cam_mode[(
int) gspca_dev->
curr_mode].priv) {
462 reg_w(gspca_dev, 0xff, 0x01);
463 reg_w(gspca_dev, 0x17, 0x20);
464 reg_w(gspca_dev, 0x87, 0x10);
467 reg_w(gspca_dev, 0xff, 0x01);
468 reg_w(gspca_dev, 0x17, 0x30);
469 reg_w(gspca_dev, 0x87, 0x11);
472 reg_w(gspca_dev, 0xff, 0x01);
473 reg_w(gspca_dev, 0x17, 0x00);
474 reg_w(gspca_dev, 0x87, 0x12);
483 reg_w(gspca_dev, 0xff, 0x01);
484 reg_w(gspca_dev, 0x78, 0x05);
489 static void sd_stopN(
struct gspca_dev *gspca_dev)
491 reg_w(gspca_dev, 0xff, 0x04);
492 reg_w(gspca_dev, 0x27, 0x80);
493 reg_w(gspca_dev, 0x28, 0xca);
494 reg_w(gspca_dev, 0x29, 0x53);
495 reg_w(gspca_dev, 0x2a, 0x0e);
496 reg_w(gspca_dev, 0xff, 0x01);
497 reg_w(gspca_dev, 0x3e, 0x20);
498 reg_w(gspca_dev, 0x78, 0x44);
499 reg_w(gspca_dev, 0x78, 0x44);
500 reg_w(gspca_dev, 0x78, 0x44);
503 static void do_autogain(
struct gspca_dev *gspca_dev)
505 struct sd *sd = (
struct sd *) gspca_dev;
507 int desired_lum, deadzone;
518 desired_lum, deadzone))
523 static const unsigned char pac_jpeg_header1[] = {
534 static const unsigned char pac_jpeg_header2[] = {
550 static void pac_start_frame(
struct gspca_dev *gspca_dev,
556 pac_jpeg_header1,
sizeof(pac_jpeg_header1));
558 tmpbuf[0] = lines >> 8;
559 tmpbuf[1] = lines & 0xff;
560 tmpbuf[2] = samples_per_line >> 8;
561 tmpbuf[3] = samples_per_line & 0xff;
564 tmpbuf,
sizeof(tmpbuf));
566 pac_jpeg_header2,
sizeof(pac_jpeg_header2));
570 static void sd_pkt_scan(
struct gspca_dev *gspca_dev,
574 struct sd *sd = (
struct sd *) gspca_dev;
578 sof = pac_find_sof(&sd->
sof_read, data, len);
580 int n, lum_offset, footer_length;
588 lum_offset = 24 +
sizeof pac_sof_marker;
592 n = (sof -
data) - (footer_length +
sizeof pac_sof_marker);
599 image = gspca_dev->
image;
601 && image[gspca_dev->
image_len - 2] == 0xff
602 && image[gspca_dev->
image_len - 1] == 0xd9)
613 data[-lum_offset + 1]);
618 pac_start_frame(gspca_dev,
624 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
625 static int sd_int_pkt_scan(
struct gspca_dev *gspca_dev,
635 if ((data0 == 0x00 && data1 == 0x11) ||
636 (data0 == 0x22 && data1 == 0x33) ||
637 (data0 == 0x44 && data1 == 0x55) ||
638 (data0 == 0x66 && data1 == 0x77) ||
639 (data0 == 0x88 && data1 == 0x99) ||
640 (data0 == 0xaa && data1 == 0xbb) ||
641 (data0 == 0xcc && data1 == 0xdd) ||
642 (data0 == 0xee && data1 == 0xff)) {
643 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 1);
644 input_sync(gspca_dev->input_dev);
645 input_report_key(gspca_dev->input_dev,
KEY_CAMERA, 0);
646 input_sync(gspca_dev->input_dev);
659 .init_controls = sd_init_controls,
662 .pkt_scan = sd_pkt_scan,
663 .dq_callback = do_autogain,
664 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
665 .int_pkt_scan = sd_int_pkt_scan,
671 {USB_DEVICE(0x093a, 0x2600)},
672 {USB_DEVICE(0x093a, 0x2601)},
673 {USB_DEVICE(0x093a, 0x2603)},
674 {USB_DEVICE(0x093a, 0x2608)},
675 {USB_DEVICE(0x093a, 0x260e)},
676 {USB_DEVICE(0x093a, 0x260f)},
689 static struct usb_driver sd_driver = {
691 .id_table = device_table,
695 .suspend = gspca_suspend,
696 .resume = gspca_resume,
697 .reset_resume = gspca_resume,