2 * Mars-Semi MR97311A library
3 * Copyright (C) 2005 <bradlch@hotmail.com>
5 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define MODULE_NAME "mars"
27 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
28 MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
29 MODULE_LICENSE("GPL");
31 /* specific webcam descriptor */
33 struct gspca_dev gspca_dev; /* !! must be the first item */
38 /* V4L2 controls supported by the driver */
39 static struct ctrl sd_ctrls[] = {
42 static struct v4l2_pix_format vga_mode[] = {
43 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
45 .sizeimage = 320 * 240 * 3 / 8 + 589,
46 .colorspace = V4L2_COLORSPACE_JPEG,
48 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
50 .sizeimage = 640 * 480 * 3 / 8 + 590,
51 .colorspace = V4L2_COLORSPACE_JPEG,
55 /* MI Register table //elvis */
83 ATTR_TOTAL_MI_REG = 0xf2
86 /* the bytes to write are in gspca_dev->usb_buf */
87 static int reg_w(struct gspca_dev *gspca_dev,
92 rc = usb_control_msg(gspca_dev->dev,
93 usb_sndbulkpipe(gspca_dev->dev, 4),
97 index, gspca_dev->usb_buf, len, 500);
99 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc);
103 static int reg_w_buf(struct gspca_dev *gspca_dev,
104 __u16 index, __u8 *buf, int len)
108 rc = usb_control_msg(gspca_dev->dev,
109 usb_sndbulkpipe(gspca_dev->dev, 4),
113 index, buf, len, 500);
115 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc);
119 static void bulk_w(struct gspca_dev *gspca_dev,
123 gspca_dev->usb_buf[0] = 0x1f;
124 gspca_dev->usb_buf[1] = 0; /* control byte */
125 gspca_dev->usb_buf[2] = Address;
126 gspca_dev->usb_buf[3] = *pch >> 8; /* high byte */
127 gspca_dev->usb_buf[4] = *pch; /* low byte */
129 reg_w(gspca_dev, Address, 5);
132 /* this function is called at probe time */
133 static int sd_config(struct gspca_dev *gspca_dev,
134 const struct usb_device_id *id)
136 struct sd *sd = (struct sd *) gspca_dev;
139 cam = &gspca_dev->cam;
141 cam->cam_mode = vga_mode;
142 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
143 sd->qindex = 1; /* set the quantization table */
147 /* this function is called at open time */
148 static int sd_open(struct gspca_dev *gspca_dev)
153 static void sd_start(struct gspca_dev *gspca_dev)
161 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface);
162 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8) < 0) {
163 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error");
167 data = gspca_dev->usb_buf;
168 data[0] = 0x01; /* address */
171 err_code = reg_w(gspca_dev, data[0], 2);
176 Initialize the MR97113 chip register
178 data = kmalloc(16, GFP_KERNEL);
179 data[0] = 0x00; /* address */
180 data[1] = 0x0c | 0x01; /* reg 0 */
181 data[2] = 0x01; /* reg 1 */
182 h_size = gspca_dev->width;
183 v_size = gspca_dev->height;
184 data[3] = h_size / 8; /* h_size , reg 2 */
185 data[4] = v_size / 8; /* v_size , reg 3 */
186 data[5] = 0x30; /* reg 4, MI, PAS5101 :
187 * 0x30 for 24mhz , 0x28 for 12mhz */
188 data[6] = 4; /* reg 5, H start */
189 data[7] = 0xc0; /* reg 6, gamma 1.5 */
190 data[8] = 3; /* reg 7, V start */
191 /* if (h_size == 320 ) */
192 /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */
194 data[9] = 0x52; /* reg 8, 24MHz, no scale down */
195 data[10] = 0x5d; /* reg 9, I2C device address
196 * [for PAS5101 (0x40)] [for MI (0x5d)] */
198 err_code = reg_w_buf(gspca_dev, data[0], data, 11);
203 data = gspca_dev->usb_buf;
204 data[0] = 0x23; /* address */
205 data[1] = 0x09; /* reg 35, append frame header */
207 err_code = reg_w(gspca_dev, data[0], 2);
211 data[0] = 0x3c; /* address */
212 /* if (gspca_dev->width == 1280) */
213 /* data[1] = 200; * reg 60, pc-cam frame size
214 * (unit: 4KB) 800KB */
216 data[1] = 50; /* 50 reg 60, pc-cam frame size
217 * (unit: 4KB) 200KB */
218 err_code = reg_w(gspca_dev, data[0], 2);
222 if (0) { /* fixed dark-gain */
223 data[1] = 0; /* reg 94, Y Gain (1.75) */
224 data[2] = 0; /* reg 95, UV Gain (1.75) */
225 data[3] = 0x3f; /* reg 96, Y Gain/UV Gain/disable
227 data[4] = 0; /* reg 97, set fixed dark level */
228 data[5] = 0; /* reg 98, don't care */
229 } else { /* auto dark-gain */
230 data[1] = 0; /* reg 94, Y Gain (auto) */
231 data[2] = 0; /* reg 95, UV Gain (1.75) */
232 data[3] = 0x78; /* reg 96, Y Gain/UV Gain/disable
234 switch (gspca_dev->width) {
237 * reg 97, %3 shadow point (unit: 256 pixel) */
239 * reg 98, %1 highlight point
240 * (uint: 256 pixel) */
244 data[4] = 36; /* reg 97, %3 shadow point
245 * (unit: 256 pixel) */
246 data[5] = 12; /* reg 98, %1 highlight point
247 * (uint: 256 pixel) */
250 data[4] = 9; /* reg 97, %3 shadow point
251 * (unit: 256 pixel) */
252 data[5] = 3; /* reg 98, %1 highlight point
253 * (uint: 256 pixel) */
258 data[0] = 0x5e; /* address */
260 err_code = reg_w(gspca_dev, data[0], 6);
265 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */
266 err_code = reg_w(gspca_dev, data[0], 2);
271 * initialize the value of MI sensor...
273 MI_buf = kzalloc(ATTR_TOTAL_MI_REG * sizeof *MI_buf, GFP_KERNEL);
274 MI_buf[REG_HW_MI_1] = 0x000a;
275 MI_buf[REG_HW_MI_2] = 0x000c;
276 MI_buf[REG_HW_MI_3] = 0x0405;
277 MI_buf[REG_HW_MI_4] = 0x0507;
278 /* mi_Attr_Reg_[REG_HW_MI_5] = 0x01ff;//13 */
279 MI_buf[REG_HW_MI_5] = 0x0013; /* 13 */
280 MI_buf[REG_HW_MI_6] = 0x001f; /* vertical blanking */
281 /* mi_Attr_Reg_[REG_HW_MI_6] = 0x0400; // vertical blanking */
282 MI_buf[REG_HW_MI_7] = 0x0002;
283 /* mi_Attr_Reg_[REG_HW_MI_9] = 0x015f; */
284 /* mi_Attr_Reg_[REG_HW_MI_9] = 0x030f; */
285 MI_buf[REG_HW_MI_9] = 0x0374;
286 MI_buf[REG_HW_MI_B] = 0x0000;
287 MI_buf[REG_HW_MI_C] = 0x0000;
288 MI_buf[REG_HW_MI_D] = 0x0000;
289 MI_buf[REG_HW_MI_1E] = 0x8000;
290 /* mi_Attr_Reg_[REG_HW_MI_20] = 0x1104; */
291 MI_buf[REG_HW_MI_20] = 0x1104; /* 0x111c; */
292 MI_buf[REG_HW_MI_2B] = 0x0008;
293 /* mi_Attr_Reg_[REG_HW_MI_2C] = 0x000f; */
294 MI_buf[REG_HW_MI_2C] = 0x001f; /* lita suggest */
295 MI_buf[REG_HW_MI_2D] = 0x0008;
296 MI_buf[REG_HW_MI_2E] = 0x0008;
297 MI_buf[REG_HW_MI_35] = 0x0051;
298 MI_buf[REG_HW_MI_5F] = 0x0904; /* fail to write */
299 MI_buf[REG_HW_MI_60] = 0x0000;
300 MI_buf[REG_HW_MI_61] = 0x0000;
301 MI_buf[REG_HW_MI_62] = 0x0498;
302 MI_buf[REG_HW_MI_63] = 0x0000;
303 MI_buf[REG_HW_MI_64] = 0x0000;
304 MI_buf[REG_HW_MI_F1] = 0x0001;
305 /* changing while setting up the different value of dx/dy */
307 if (gspca_dev->width != 1280) {
308 MI_buf[0x01] = 0x010a;
309 MI_buf[0x02] = 0x014c;
310 MI_buf[0x03] = 0x01e5;
311 MI_buf[0x04] = 0x0287;
313 MI_buf[0x20] = 0x1104;
315 bulk_w(gspca_dev, MI_buf + 1, 1);
316 bulk_w(gspca_dev, MI_buf + 2, 2);
317 bulk_w(gspca_dev, MI_buf + 3, 3);
318 bulk_w(gspca_dev, MI_buf + 4, 4);
319 bulk_w(gspca_dev, MI_buf + 5, 5);
320 bulk_w(gspca_dev, MI_buf + 6, 6);
321 bulk_w(gspca_dev, MI_buf + 7, 7);
322 bulk_w(gspca_dev, MI_buf + 9, 9);
323 bulk_w(gspca_dev, MI_buf + 0x0b, 0x0b);
324 bulk_w(gspca_dev, MI_buf + 0x0c, 0x0c);
325 bulk_w(gspca_dev, MI_buf + 0x0d, 0x0d);
326 bulk_w(gspca_dev, MI_buf + 0x1e, 0x1e);
327 bulk_w(gspca_dev, MI_buf + 0x20, 0x20);
328 bulk_w(gspca_dev, MI_buf + 0x2b, 0x2b);
329 bulk_w(gspca_dev, MI_buf + 0x2c, 0x2c);
330 bulk_w(gspca_dev, MI_buf + 0x2d, 0x2d);
331 bulk_w(gspca_dev, MI_buf + 0x2e, 0x2e);
332 bulk_w(gspca_dev, MI_buf + 0x35, 0x35);
333 bulk_w(gspca_dev, MI_buf + 0x5f, 0x5f);
334 bulk_w(gspca_dev, MI_buf + 0x60, 0x60);
335 bulk_w(gspca_dev, MI_buf + 0x61, 0x61);
336 bulk_w(gspca_dev, MI_buf + 0x62, 0x62);
337 bulk_w(gspca_dev, MI_buf + 0x63, 0x63);
338 bulk_w(gspca_dev, MI_buf + 0x64, 0x64);
339 bulk_w(gspca_dev, MI_buf + 0xf1, 0xf1);
342 intpipe = usb_sndintpipe(gspca_dev->dev, 0);
343 err_code = usb_clear_halt(gspca_dev->dev, intpipe);
346 data[1] = 0x4d; /* ISOC transfering enable... */
347 reg_w(gspca_dev, data[0], 2);
350 static void sd_stopN(struct gspca_dev *gspca_dev)
354 gspca_dev->usb_buf[0] = 1;
355 gspca_dev->usb_buf[1] = 0;
356 result = reg_w(gspca_dev, gspca_dev->usb_buf[0], 2);
358 PDEBUG(D_ERR, "Camera Stop failed");
361 static void sd_stop0(struct gspca_dev *gspca_dev)
365 static void sd_close(struct gspca_dev *gspca_dev)
369 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
370 struct gspca_frame *frame, /* target */
371 __u8 *data, /* isoc packet */
372 int len) /* iso packet length */
374 struct sd *sd = (struct sd *) gspca_dev;
378 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
381 for (p = 0; p < len - 6; p++) {
382 if (data[0 + p] == 0xff
383 && data[1 + p] == 0xff
384 && data[2 + p] == 0x00
385 && data[3 + p] == 0xff
386 && data[4 + p] == 0x96) {
387 if (data[5 + p] == 0x64
388 || data[5 + p] == 0x65
389 || data[5 + p] == 0x66
390 || data[5 + p] == 0x67) {
391 PDEBUG(D_PACK, "sof offset: %d leng: %d",
393 frame = gspca_frame_add(gspca_dev, LAST_PACKET,
396 /* put the JPEG header */
397 jpeg_put_header(gspca_dev, frame,
405 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
408 /* sub-driver description */
409 static const struct sd_desc sd_desc = {
412 .nctrls = ARRAY_SIZE(sd_ctrls),
419 .pkt_scan = sd_pkt_scan,
422 /* -- module initialisation -- */
423 static const __devinitdata struct usb_device_id device_table[] = {
424 {USB_DEVICE(0x093a, 0x050f)},
427 MODULE_DEVICE_TABLE(usb, device_table);
429 /* -- device connect -- */
430 static int sd_probe(struct usb_interface *intf,
431 const struct usb_device_id *id)
433 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
437 static struct usb_driver sd_driver = {
439 .id_table = device_table,
441 .disconnect = gspca_disconnect,
444 /* -- module insert / remove -- */
445 static int __init sd_mod_init(void)
447 if (usb_register(&sd_driver) < 0)
449 PDEBUG(D_PROBE, "registered");
452 static void __exit sd_mod_exit(void)
454 usb_deregister(&sd_driver);
455 PDEBUG(D_PROBE, "deregistered");
458 module_init(sd_mod_init);
459 module_exit(sd_mod_exit);