2 * Mars MR97310A library
4 * Copyright (C) 2009 Kyle Guinn <elyk03@gmail.com>
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
21 #define MODULE_NAME "mr97310a"
25 MODULE_AUTHOR("Kyle Guinn <elyk03@gmail.com>");
26 MODULE_DESCRIPTION("GSPCA/Mars-Semi MR97310A USB Camera Driver");
27 MODULE_LICENSE("GPL");
29 /* specific webcam descriptor */
31 struct gspca_dev gspca_dev; /* !! must be the first item */
37 /* V4L2 controls supported by the driver */
38 static struct ctrl sd_ctrls[] = {
41 static const struct v4l2_pix_format vga_mode[] = {
42 {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
44 .sizeimage = 160 * 120,
45 .colorspace = V4L2_COLORSPACE_SRGB,
47 {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
49 .sizeimage = 176 * 144,
50 .colorspace = V4L2_COLORSPACE_SRGB,
52 {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
54 .sizeimage = 320 * 240,
55 .colorspace = V4L2_COLORSPACE_SRGB,
57 {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
59 .sizeimage = 352 * 288,
60 .colorspace = V4L2_COLORSPACE_SRGB,
62 {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
64 .sizeimage = 640 * 480,
65 .colorspace = V4L2_COLORSPACE_SRGB,
69 /* the bytes to write are in gspca_dev->usb_buf */
70 static int reg_w(struct gspca_dev *gspca_dev, int len)
74 rc = usb_bulk_msg(gspca_dev->dev,
75 usb_sndbulkpipe(gspca_dev->dev, 4),
76 gspca_dev->usb_buf, len, NULL, 500);
78 PDEBUG(D_ERR, "reg write [%02x] error %d",
79 gspca_dev->usb_buf[0], rc);
83 /* this function is called at probe time */
84 static int sd_config(struct gspca_dev *gspca_dev,
85 const struct usb_device_id *id)
89 cam = &gspca_dev->cam;
90 cam->cam_mode = vga_mode;
91 cam->nmodes = ARRAY_SIZE(vga_mode);
95 /* this function is called at probe and resume time */
96 static int sd_init(struct gspca_dev *gspca_dev)
101 static int sd_start(struct gspca_dev *gspca_dev)
103 struct sd *sd = (struct sd *) gspca_dev;
104 __u8 *data = gspca_dev->usb_buf;
109 /* Note: register descriptions guessed from MR97113A driver */
113 err_code = reg_w(gspca_dev, 2);
122 data[9] = 0x50; /* reg 8, no scale down */
125 switch (gspca_dev->width) {
127 data[9] |= 0x0c; /* reg 8, 4:1 scale down */
130 data[9] |= 0x04; /* reg 8, 2:1 scale down */
134 data[3] = 0x50; /* reg 2, H size */
135 data[4] = 0x78; /* reg 3, V size */
136 data[6] = 0x04; /* reg 5, H start */
137 data[8] = 0x03; /* reg 7, V start */
141 data[9] |= 0x04; /* reg 8, 2:1 scale down */
144 data[3] = 0x2c; /* reg 2, H size */
145 data[4] = 0x48; /* reg 3, V size */
146 data[6] = 0x94; /* reg 5, H start */
147 data[8] = 0x63; /* reg 7, V start */
151 err_code = reg_w(gspca_dev, 11);
157 err_code = reg_w(gspca_dev, 2);
163 err_code = reg_w(gspca_dev, 2);
169 err_code = reg_w(gspca_dev, 2);
175 err_code = reg_w(gspca_dev, 2);
181 err_code = reg_w(gspca_dev, 2);
187 err_code = reg_w(gspca_dev, 2);
193 err_code = reg_w(gspca_dev, 2);
208 err_code = reg_w(gspca_dev, 11);
216 err_code = reg_w(gspca_dev, 4);
230 err_code = reg_w(gspca_dev, 10);
238 err_code = reg_w(gspca_dev, 4);
251 err_code = reg_w(gspca_dev, 9);
259 err_code = reg_w(gspca_dev, 4);
264 data[1] = 0x4d; /* ISOC transfering enable... */
265 err_code = reg_w(gspca_dev, 2);
269 static void sd_stopN(struct gspca_dev *gspca_dev)
273 gspca_dev->usb_buf[0] = 1;
274 gspca_dev->usb_buf[1] = 0;
275 result = reg_w(gspca_dev, 2);
277 PDEBUG(D_ERR, "Camera Stop failed");
280 /* Include pac common sof detection functions */
281 #include "pac_common.h"
283 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
284 struct gspca_frame *frame, /* target */
285 __u8 *data, /* isoc packet */
286 int len) /* iso packet length */
288 struct sd *sd = (struct sd *) gspca_dev;
291 sof = pac_find_sof(gspca_dev, data, len);
295 /* finish decoding current frame */
297 if (n > sizeof pac_sof_marker)
298 n -= sizeof pac_sof_marker;
301 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
304 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, NULL, 0);
308 if (sd->header_read < 7) {
311 /* skip the rest of the header */
312 needed = 7 - sd->header_read;
314 sd->header_read += len;
322 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
325 /* sub-driver description */
326 static const struct sd_desc sd_desc = {
329 .nctrls = ARRAY_SIZE(sd_ctrls),
334 .pkt_scan = sd_pkt_scan,
337 /* -- module initialisation -- */
338 static const __devinitdata struct usb_device_id device_table[] = {
339 {USB_DEVICE(0x08ca, 0x0111)},
342 MODULE_DEVICE_TABLE(usb, device_table);
344 /* -- device connect -- */
345 static int sd_probe(struct usb_interface *intf,
346 const struct usb_device_id *id)
348 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
352 static struct usb_driver sd_driver = {
354 .id_table = device_table,
356 .disconnect = gspca_disconnect,
358 .suspend = gspca_suspend,
359 .resume = gspca_resume,
363 /* -- module insert / remove -- */
364 static int __init sd_mod_init(void)
366 if (usb_register(&sd_driver) < 0)
368 PDEBUG(D_PROBE, "registered");
371 static void __exit sd_mod_exit(void)
373 usb_deregister(&sd_driver);
374 PDEBUG(D_PROBE, "deregistered");
377 module_init(sd_mod_init);
378 module_exit(sd_mod_exit);