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 */
35 /* V4L2 controls supported by the driver */
36 static struct ctrl sd_ctrls[] = {
39 static const struct v4l2_pix_format vga_mode[] = {
40 {160, 120, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
42 .sizeimage = 160 * 120,
43 .colorspace = V4L2_COLORSPACE_SRGB,
45 {176, 144, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
47 .sizeimage = 176 * 144,
48 .colorspace = V4L2_COLORSPACE_SRGB,
50 {320, 240, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
52 .sizeimage = 320 * 240,
53 .colorspace = V4L2_COLORSPACE_SRGB,
55 {352, 288, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
57 .sizeimage = 352 * 288,
58 .colorspace = V4L2_COLORSPACE_SRGB,
60 {640, 480, V4L2_PIX_FMT_MR97310A, V4L2_FIELD_NONE,
62 .sizeimage = 640 * 480,
63 .colorspace = V4L2_COLORSPACE_SRGB,
67 /* the bytes to write are in gspca_dev->usb_buf */
68 static int reg_w(struct gspca_dev *gspca_dev, int len)
72 rc = usb_bulk_msg(gspca_dev->dev,
73 usb_sndbulkpipe(gspca_dev->dev, 4),
74 gspca_dev->usb_buf, len, NULL, 500);
76 PDEBUG(D_ERR, "reg write [%02x] error %d",
77 gspca_dev->usb_buf[0], rc);
81 /* this function is called at probe time */
82 static int sd_config(struct gspca_dev *gspca_dev,
83 const struct usb_device_id *id)
87 cam = &gspca_dev->cam;
88 cam->cam_mode = vga_mode;
89 cam->nmodes = ARRAY_SIZE(vga_mode);
93 /* this function is called at probe and resume time */
94 static int sd_init(struct gspca_dev *gspca_dev)
99 static int sd_start(struct gspca_dev *gspca_dev)
101 struct sd *sd = (struct sd *) gspca_dev;
102 __u8 *data = gspca_dev->usb_buf;
107 /* Note: register descriptions guessed from MR97113A driver */
111 err_code = reg_w(gspca_dev, 2);
120 data[9] = 0x50; /* reg 8, no scale down */
123 switch (gspca_dev->width) {
125 data[9] |= 0x0c; /* reg 8, 4:1 scale down */
128 data[9] |= 0x04; /* reg 8, 2:1 scale down */
132 data[3] = 0x50; /* reg 2, H size */
133 data[4] = 0x78; /* reg 3, V size */
134 data[6] = 0x04; /* reg 5, H start */
135 data[8] = 0x03; /* reg 7, V start */
139 data[9] |= 0x04; /* reg 8, 2:1 scale down */
142 data[3] = 0x2c; /* reg 2, H size */
143 data[4] = 0x48; /* reg 3, V size */
144 data[6] = 0x94; /* reg 5, H start */
145 data[8] = 0x63; /* reg 7, V start */
149 err_code = reg_w(gspca_dev, 11);
155 err_code = reg_w(gspca_dev, 2);
161 err_code = reg_w(gspca_dev, 2);
167 err_code = reg_w(gspca_dev, 2);
173 err_code = reg_w(gspca_dev, 2);
179 err_code = reg_w(gspca_dev, 2);
185 err_code = reg_w(gspca_dev, 2);
191 err_code = reg_w(gspca_dev, 2);
206 err_code = reg_w(gspca_dev, 11);
214 err_code = reg_w(gspca_dev, 4);
228 err_code = reg_w(gspca_dev, 10);
236 err_code = reg_w(gspca_dev, 4);
249 err_code = reg_w(gspca_dev, 9);
257 err_code = reg_w(gspca_dev, 4);
262 data[1] = 0x4d; /* ISOC transfering enable... */
263 err_code = reg_w(gspca_dev, 2);
267 static void sd_stopN(struct gspca_dev *gspca_dev)
271 gspca_dev->usb_buf[0] = 1;
272 gspca_dev->usb_buf[1] = 0;
273 result = reg_w(gspca_dev, 2);
275 PDEBUG(D_ERR, "Camera Stop failed");
278 /* Include pac common sof detection functions */
279 #include "pac_common.h"
281 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
282 struct gspca_frame *frame, /* target */
283 __u8 *data, /* isoc packet */
284 int len) /* iso packet length */
288 sof = pac_find_sof(gspca_dev, data, len);
292 /* finish decoding current frame */
294 if (n > sizeof pac_sof_marker)
295 n -= sizeof pac_sof_marker;
298 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
300 /* Start next frame. */
301 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
302 pac_sof_marker, sizeof pac_sof_marker);
306 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
309 /* sub-driver description */
310 static const struct sd_desc sd_desc = {
313 .nctrls = ARRAY_SIZE(sd_ctrls),
318 .pkt_scan = sd_pkt_scan,
321 /* -- module initialisation -- */
322 static const __devinitdata struct usb_device_id device_table[] = {
323 {USB_DEVICE(0x08ca, 0x0111)},
326 MODULE_DEVICE_TABLE(usb, device_table);
328 /* -- device connect -- */
329 static int sd_probe(struct usb_interface *intf,
330 const struct usb_device_id *id)
332 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
336 static struct usb_driver sd_driver = {
338 .id_table = device_table,
340 .disconnect = gspca_disconnect,
342 .suspend = gspca_suspend,
343 .resume = gspca_resume,
347 /* -- module insert / remove -- */
348 static int __init sd_mod_init(void)
350 if (usb_register(&sd_driver) < 0)
352 PDEBUG(D_PROBE, "registered");
355 static void __exit sd_mod_exit(void)
357 usb_deregister(&sd_driver);
358 PDEBUG(D_PROBE, "deregistered");
361 module_init(sd_mod_init);
362 module_exit(sd_mod_exit);