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 #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 4)
28 static const char version[] = "2.1.4";
30 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31 MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
32 MODULE_LICENSE("GPL");
34 /* specific webcam descriptor */
36 struct gspca_dev gspca_dev; /* !! must be the first item */
41 /* V4L2 controls supported by the driver */
42 static struct ctrl sd_ctrls[] = {
45 static struct cam_mode vga_mode[] = {
46 {V4L2_PIX_FMT_JPEG, 320, 240, 2},
47 {V4L2_PIX_FMT_JPEG, 640, 480, 1},
50 /* MI Register table //elvis */
78 ATTR_TOTAL_MI_REG = 242
81 static int pcam_reg_write(struct usb_device *dev,
82 __u16 index, __u8 *value, int len)
86 rc = usb_control_msg(dev,
87 usb_sndbulkpipe(dev, 4),
89 /* ?? 0xc8 = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_??? !? */
92 index, value, len, 500);
94 PDEBUG(D_ERR, "reg write [%02x] error %d", index, rc);
98 static void MISensor_BulkWrite(struct usb_device *dev,
105 data[1] = 0; /* control byte */
107 data[3] = *pch >> 8; /* high byte */
108 data[4] = *pch; /* low byte */
110 pcam_reg_write(dev, Address, data, 5);
113 /* this function is called at probe time */
114 static int sd_config(struct gspca_dev *gspca_dev,
115 const struct usb_device_id *id)
117 struct sd *sd = (struct sd *) gspca_dev;
120 cam = &gspca_dev->cam;
121 cam->dev_name = (char *) id->driver_info;
123 cam->cam_mode = vga_mode;
124 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
125 sd->qindex = 1; /* set the quantization table */
129 /* this function is called at open time */
130 static int sd_open(struct gspca_dev *gspca_dev)
135 static void sd_start(struct gspca_dev *gspca_dev)
137 struct usb_device *dev = gspca_dev->dev;
143 /* struct usb_device *dev = pcam->dev; */
145 memset(data, 0, sizeof data);
146 memset(MI_buf, 0, sizeof MI_buf);
148 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface);
149 if (usb_set_interface(dev, gspca_dev->iface, 8) < 0) {
150 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error");
154 data[0] = 0x01; /* address */
157 err_code = pcam_reg_write(dev, data[0], data, 2);
162 Initialize the MR97113 chip register
164 data[0] = 0x00; /* address */
165 data[1] = 0x0c | 0x01; /* reg 0 */
166 data[2] = 0x01; /* reg 1 */
167 h_size = gspca_dev->width;
168 v_size = gspca_dev->height;
169 data[3] = h_size / 8; /* h_size , reg 2 */
170 data[4] = v_size / 8; /* v_size , reg 3 */
171 data[5] = 0x30; /* reg 4, MI, PAS5101 :
172 * 0x30 for 24mhz , 0x28 for 12mhz */
173 data[6] = 4; /* reg 5, H start */
174 data[7] = 0xc0; /* reg 6, gamma 1.5 */
175 data[8] = 3; /* reg 7, V start */
176 /* if(h_size == 320 ) */
177 /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */
179 data[9] = 0x52; /* reg 8, 24MHz, no scale down */
180 data[10] = 0x5d; /* reg 9, I2C device address
181 * [for PAS5101 (0x40)] [for MI (0x5d)] */
183 err_code = pcam_reg_write(dev, data[0], data, 11);
187 data[0] = 0x23; /* address */
188 data[1] = 0x09; /* reg 35, append frame header */
190 err_code = pcam_reg_write(dev, data[0], data, 2);
192 PDEBUG(D_ERR, "Register write failed");
196 data[0] = 0x3C; /* address */
197 /* if (pcam->width == 1280) */
198 /* data[1] = 200; * reg 60, pc-cam frame size
199 * (unit: 4KB) 800KB */
201 data[1] = 50; /* 50 reg 60, pc-cam frame size
202 * (unit: 4KB) 200KB */
203 err_code = pcam_reg_write(dev, data[0], data, 2);
207 if (0) { /* fixed dark-gain */
208 data[1] = 0; /* reg 94, Y Gain (1.75) */
209 data[2] = 0; /* reg 95, UV Gain (1.75) */
210 data[3] = 0x3f; /* reg 96, Y Gain/UV Gain/disable
212 data[4] = 0; /* reg 97, set fixed dark level */
213 data[5] = 0; /* reg 98, don't care */
214 } else { /* auto dark-gain */
215 data[1] = 0; /* reg 94, Y Gain (auto) */
216 data[2] = 0; /* reg 95, UV Gain (1.75) */
217 data[3] = 0x78; /* reg 96, Y Gain/UV Gain/disable
219 switch (gspca_dev->width) {
222 * reg 97, %3 shadow point (unit: 256 pixel) */
224 * reg 98, %1 highlight point
225 * (uint: 256 pixel) */
229 data[4] = 36; /* reg 97, %3 shadow point
230 * (unit: 256 pixel) */
231 data[5] = 12; /* reg 98, %1 highlight point
232 * (uint: 256 pixel) */
235 data[4] = 9; /* reg 97, %3 shadow point
236 * (unit: 256 pixel) */
237 data[5] = 3; /* reg 98, %1 highlight point
238 * (uint: 256 pixel) */
243 data[0] = 0x5e; /* address */
245 err_code = pcam_reg_write(dev, data[0], data, 6);
250 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */
251 err_code = pcam_reg_write(dev, data[0], data, 2);
256 * initialize the value of MI sensor...
258 MI_buf[REG_HW_MI_1] = 0x000a;
259 MI_buf[REG_HW_MI_2] = 0x000c;
260 MI_buf[REG_HW_MI_3] = 0x0405;
261 MI_buf[REG_HW_MI_4] = 0x0507;
262 /* mi_Attr_Reg_[REG_HW_MI_5] = 0x01ff;//13 */
263 MI_buf[REG_HW_MI_5] = 0x0013; /* 13 */
264 MI_buf[REG_HW_MI_6] = 0x001f; /* vertical blanking */
265 /* mi_Attr_Reg_[REG_HW_MI_6] = 0x0400; // vertical blanking */
266 MI_buf[REG_HW_MI_7] = 0x0002;
267 /* mi_Attr_Reg_[REG_HW_MI_9] = 0x015f; */
268 /* mi_Attr_Reg_[REG_HW_MI_9] = 0x030f; */
269 MI_buf[REG_HW_MI_9] = 0x0374;
270 MI_buf[REG_HW_MI_B] = 0x0000;
271 MI_buf[REG_HW_MI_C] = 0x0000;
272 MI_buf[REG_HW_MI_D] = 0x0000;
273 MI_buf[REG_HW_MI_1E] = 0x8000;
274 /* mi_Attr_Reg_[REG_HW_MI_20] = 0x1104; */
275 MI_buf[REG_HW_MI_20] = 0x1104; /* 0x111c; */
276 MI_buf[REG_HW_MI_2B] = 0x0008;
277 /* mi_Attr_Reg_[REG_HW_MI_2C] = 0x000f; */
278 MI_buf[REG_HW_MI_2C] = 0x001f; /* lita suggest */
279 MI_buf[REG_HW_MI_2D] = 0x0008;
280 MI_buf[REG_HW_MI_2E] = 0x0008;
281 MI_buf[REG_HW_MI_35] = 0x0051;
282 MI_buf[REG_HW_MI_5F] = 0x0904; /* fail to write */
283 MI_buf[REG_HW_MI_60] = 0x0000;
284 MI_buf[REG_HW_MI_61] = 0x0000;
285 MI_buf[REG_HW_MI_62] = 0x0498;
286 MI_buf[REG_HW_MI_63] = 0x0000;
287 MI_buf[REG_HW_MI_64] = 0x0000;
288 MI_buf[REG_HW_MI_F1] = 0x0001;
289 /* changing while setting up the different value of dx/dy */
291 if (gspca_dev->width != 1280) {
292 MI_buf[0x01] = 0x010a;
293 MI_buf[0x02] = 0x014c;
294 MI_buf[0x03] = 0x01e5;
295 MI_buf[0x04] = 0x0287;
297 MI_buf[0x20] = 0x1104;
299 MISensor_BulkWrite(dev, MI_buf + 1, 1);
300 MISensor_BulkWrite(dev, MI_buf + 2, 2);
301 MISensor_BulkWrite(dev, MI_buf + 3, 3);
302 MISensor_BulkWrite(dev, MI_buf + 4, 4);
303 MISensor_BulkWrite(dev, MI_buf + 5, 5);
304 MISensor_BulkWrite(dev, MI_buf + 6, 6);
305 MISensor_BulkWrite(dev, MI_buf + 7, 7);
306 MISensor_BulkWrite(dev, MI_buf + 9, 9);
307 MISensor_BulkWrite(dev, MI_buf + 0x0b, 0x0b);
308 MISensor_BulkWrite(dev, MI_buf + 0x0c, 0x0c);
309 MISensor_BulkWrite(dev, MI_buf + 0x0d, 0x0d);
310 MISensor_BulkWrite(dev, MI_buf + 0x1e, 0x1e);
311 MISensor_BulkWrite(dev, MI_buf + 0x20, 0x20);
312 MISensor_BulkWrite(dev, MI_buf + 0x2b, 0x2b);
313 MISensor_BulkWrite(dev, MI_buf + 0x2c, 0x2c);
314 MISensor_BulkWrite(dev, MI_buf + 0x2d, 0x2d);
315 MISensor_BulkWrite(dev, MI_buf + 0x2e, 0x2e);
316 MISensor_BulkWrite(dev, MI_buf + 0x35, 0x35);
317 MISensor_BulkWrite(dev, MI_buf + 0x5f, 0x5f);
318 MISensor_BulkWrite(dev, MI_buf + 0x60, 0x60);
319 MISensor_BulkWrite(dev, MI_buf + 0x61, 0x61);
320 MISensor_BulkWrite(dev, MI_buf + 0x62, 0x62);
321 MISensor_BulkWrite(dev, MI_buf + 0x63, 0x63);
322 MISensor_BulkWrite(dev, MI_buf + 0x64, 0x64);
323 MISensor_BulkWrite(dev, MI_buf + 0xf1, 0xf1);
325 intpipe = usb_sndintpipe(dev, 0);
326 err_code = usb_clear_halt(dev, intpipe);
329 data[1] = 0x4d; /* ISOC transfering enable... */
330 pcam_reg_write(dev, data[0], data, 2);
333 static void sd_stopN(struct gspca_dev *gspca_dev)
340 result = pcam_reg_write(gspca_dev->dev, data[0], data, 2);
342 PDEBUG(D_ERR, "Camera Stop failed");
345 static void sd_stop0(struct gspca_dev *gspca_dev)
349 static void sd_close(struct gspca_dev *gspca_dev)
353 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
354 struct gspca_frame *frame, /* target */
355 __u8 *data, /* isoc packet */
356 int len) /* iso packet length */
358 struct sd *sd = (struct sd *) gspca_dev;
362 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
365 for (p = 0; p < len - 6; p++) {
366 if (data[0 + p] == 0xff
367 && data[1 + p] == 0xff
368 && data[2 + p] == 0x00
369 && data[3 + p] == 0xff
370 && data[4 + p] == 0x96) {
371 if (data[5 + p] == 0x64
372 || data[5 + p] == 0x65
373 || data[5 + p] == 0x66
374 || data[5 + p] == 0x67) {
375 PDEBUG(D_PACK, "sof offset: %d leng: %d",
377 frame = gspca_frame_add(gspca_dev, LAST_PACKET,
380 /* put the JPEG header */
381 jpeg_put_header(gspca_dev, frame,
389 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
392 /* sub-driver description */
393 static const struct sd_desc sd_desc = {
396 .nctrls = ARRAY_SIZE(sd_ctrls),
403 .pkt_scan = sd_pkt_scan,
406 /* -- module initialisation -- */
407 #define DVNM(name) .driver_info = (kernel_ulong_t) name
408 static const __devinitdata struct usb_device_id device_table[] = {
409 {USB_DEVICE(0x093a, 0x050f), DVNM("Mars-Semi Pc-Camera")},
412 MODULE_DEVICE_TABLE(usb, device_table);
414 /* -- device connect -- */
415 static int sd_probe(struct usb_interface *intf,
416 const struct usb_device_id *id)
418 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
422 static struct usb_driver sd_driver = {
424 .id_table = device_table,
426 .disconnect = gspca_disconnect,
429 /* -- module insert / remove -- */
430 static int __init sd_mod_init(void)
432 if (usb_register(&sd_driver) < 0)
434 PDEBUG(D_PROBE, "v%s registered", version);
437 static void __exit sd_mod_exit(void)
439 usb_deregister(&sd_driver);
440 PDEBUG(D_PROBE, "deregistered");
443 module_init(sd_mod_init);
444 module_exit(sd_mod_exit);