Lines Matching refs:gspca_dev
34 struct gspca_dev gspca_dev; /* !! must be the first item */ member
55 static u8 reg_r(struct gspca_dev *gspca_dev, u16 index) in reg_r() argument
57 struct usb_device *dev = gspca_dev->dev; in reg_r()
60 if (gspca_dev->usb_err < 0) in reg_r()
67 gspca_dev->usb_buf, 1, in reg_r()
70 gspca_dbg(gspca_dev, D_USBI, "reg_r 0x%x=0x%02x\n", in reg_r()
71 index, gspca_dev->usb_buf[0]); in reg_r()
74 gspca_dev->usb_err = ret; in reg_r()
78 return gspca_dev->usb_buf[0]; in reg_r()
82 static void reg_w(struct gspca_dev *gspca_dev, u16 index, u8 val) in reg_w() argument
85 struct usb_device *dev = gspca_dev->dev; in reg_w()
87 if (gspca_dev->usb_err < 0) in reg_w()
97 gspca_dbg(gspca_dev, D_USBO, "reg_w 0x%x:=0x%02x\n", index, val); in reg_w()
100 gspca_dev->usb_err = ret; in reg_w()
104 static void reg_w_mask(struct gspca_dev *gspca_dev, u16 index, u8 val, u8 mask) in reg_w_mask() argument
106 val = (reg_r(gspca_dev, index) & ~mask) | (val & mask); in reg_w_mask()
107 reg_w(gspca_dev, index, val); in reg_w_mask()
111 static int sd_config(struct gspca_dev *gspca_dev, in sd_config() argument
114 gspca_dev->cam.cam_mode = stk1135_modes; in sd_config()
115 gspca_dev->cam.nmodes = ARRAY_SIZE(stk1135_modes); in sd_config()
119 static int stk1135_serial_wait_ready(struct gspca_dev *gspca_dev) in stk1135_serial_wait_ready() argument
125 val = reg_r(gspca_dev, STK1135_REG_SICTL + 1); in stk1135_serial_wait_ready()
136 static u8 sensor_read_8(struct gspca_dev *gspca_dev, u8 addr) in sensor_read_8() argument
138 reg_w(gspca_dev, STK1135_REG_SBUSR, addr); in sensor_read_8()
140 reg_w(gspca_dev, STK1135_REG_SICTL, 0x20); in sensor_read_8()
142 if (stk1135_serial_wait_ready(gspca_dev)) { in sensor_read_8()
147 return reg_r(gspca_dev, STK1135_REG_SBUSR + 1); in sensor_read_8()
150 static u16 sensor_read_16(struct gspca_dev *gspca_dev, u8 addr) in sensor_read_16() argument
152 return (sensor_read_8(gspca_dev, addr) << 8) | in sensor_read_16()
153 sensor_read_8(gspca_dev, 0xf1); in sensor_read_16()
156 static void sensor_write_8(struct gspca_dev *gspca_dev, u8 addr, u8 data) in sensor_write_8() argument
159 reg_w(gspca_dev, STK1135_REG_SBUSW, addr); in sensor_write_8()
160 reg_w(gspca_dev, STK1135_REG_SBUSW + 1, data); in sensor_write_8()
162 reg_w(gspca_dev, STK1135_REG_SICTL, 0x01); in sensor_write_8()
164 if (stk1135_serial_wait_ready(gspca_dev)) { in sensor_write_8()
170 static void sensor_write_16(struct gspca_dev *gspca_dev, u8 addr, u16 data) in sensor_write_16() argument
172 sensor_write_8(gspca_dev, addr, data >> 8); in sensor_write_16()
173 sensor_write_8(gspca_dev, 0xf1, data & 0xff); in sensor_write_16()
176 static void sensor_set_page(struct gspca_dev *gspca_dev, u8 page) in sensor_set_page() argument
178 struct sd *sd = (struct sd *) gspca_dev; in sensor_set_page()
181 sensor_write_16(gspca_dev, 0xf0, page); in sensor_set_page()
186 static u16 sensor_read(struct gspca_dev *gspca_dev, u16 reg) in sensor_read() argument
188 sensor_set_page(gspca_dev, reg >> 8); in sensor_read()
189 return sensor_read_16(gspca_dev, reg & 0xff); in sensor_read()
192 static void sensor_write(struct gspca_dev *gspca_dev, u16 reg, u16 val) in sensor_write() argument
194 sensor_set_page(gspca_dev, reg >> 8); in sensor_write()
195 sensor_write_16(gspca_dev, reg & 0xff, val); in sensor_write()
198 static void sensor_write_mask(struct gspca_dev *gspca_dev, in sensor_write_mask() argument
201 val = (sensor_read(gspca_dev, reg) & ~mask) | (val & mask); in sensor_write_mask()
202 sensor_write(gspca_dev, reg, val); in sensor_write_mask()
211 static void stk1135_configure_mt9m112(struct gspca_dev *gspca_dev) in stk1135_configure_mt9m112() argument
313 sensor_write(gspca_dev, cfg[i].reg, cfg[i].val); in stk1135_configure_mt9m112()
316 width = gspca_dev->pixfmt.width; in stk1135_configure_mt9m112()
317 height = gspca_dev->pixfmt.height; in stk1135_configure_mt9m112()
319 sensor_write(gspca_dev, 0x1a7, width); in stk1135_configure_mt9m112()
320 sensor_write(gspca_dev, 0x1aa, height); in stk1135_configure_mt9m112()
322 sensor_write(gspca_dev, 0x0c8, 0x0000); in stk1135_configure_mt9m112()
324 sensor_write(gspca_dev, 0x2c8, 0x0000); in stk1135_configure_mt9m112()
326 sensor_write(gspca_dev, 0x1a1, width); in stk1135_configure_mt9m112()
327 sensor_write(gspca_dev, 0x1a4, height); in stk1135_configure_mt9m112()
329 sensor_write(gspca_dev, 0x0c8, 0x0008); in stk1135_configure_mt9m112()
331 sensor_write(gspca_dev, 0x2c8, 0x040b); in stk1135_configure_mt9m112()
335 static void stk1135_configure_clock(struct gspca_dev *gspca_dev) in stk1135_configure_clock() argument
338 reg_w(gspca_dev, STK1135_REG_TMGEN, 0x12); in stk1135_configure_clock()
341 reg_w(gspca_dev, STK1135_REG_TCP1 + 0, 0x41); in stk1135_configure_clock()
342 reg_w(gspca_dev, STK1135_REG_TCP1 + 1, 0x00); in stk1135_configure_clock()
343 reg_w(gspca_dev, STK1135_REG_TCP1 + 2, 0x00); in stk1135_configure_clock()
344 reg_w(gspca_dev, STK1135_REG_TCP1 + 3, 0x00); in stk1135_configure_clock()
347 reg_w(gspca_dev, STK1135_REG_SENSO + 0, 0x10); in stk1135_configure_clock()
349 reg_w(gspca_dev, STK1135_REG_SENSO + 1, 0x00); in stk1135_configure_clock()
351 reg_w(gspca_dev, STK1135_REG_SENSO + 3, 0x07); in stk1135_configure_clock()
353 reg_w(gspca_dev, STK1135_REG_PLLFD, 0x06); in stk1135_configure_clock()
355 reg_w(gspca_dev, STK1135_REG_TMGEN, 0x80); in stk1135_configure_clock()
357 reg_w(gspca_dev, STK1135_REG_SENSO + 2, 0x04); in stk1135_configure_clock()
360 reg_w(gspca_dev, STK1135_REG_SICTL + 2, 0x1f); in stk1135_configure_clock()
366 static void stk1135_camera_disable(struct gspca_dev *gspca_dev) in stk1135_camera_disable() argument
369 reg_w(gspca_dev, STK1135_REG_CIEPO + 2, 0x00); in stk1135_camera_disable()
370 reg_w(gspca_dev, STK1135_REG_CIEPO + 3, 0x00); in stk1135_camera_disable()
372 reg_w_mask(gspca_dev, STK1135_REG_SCTRL, 0x00, 0x80); in stk1135_camera_disable()
375 sensor_write_mask(gspca_dev, 0x00d, 0x0004, 0x000c); in stk1135_camera_disable()
378 reg_w_mask(gspca_dev, STK1135_REG_SENSO + 2, 0x00, 0x01); in stk1135_camera_disable()
380 reg_w(gspca_dev, STK1135_REG_TMGEN, 0x00); in stk1135_camera_disable()
382 reg_w(gspca_dev, STK1135_REG_SENSO + 1, 0x20); in stk1135_camera_disable()
384 reg_w(gspca_dev, STK1135_REG_SENSO, 0x00); in stk1135_camera_disable()
387 reg_w(gspca_dev, STK1135_REG_GCTRL, 0x49); in stk1135_camera_disable()
391 static int sd_init(struct gspca_dev *gspca_dev) in sd_init() argument
395 struct sd *sd = (struct sd *) gspca_dev; in sd_init()
398 reg_w(gspca_dev, STK1135_REG_GCTRL + 2, 0x78); in sd_init()
400 reg_w(gspca_dev, STK1135_REG_GCTRL, (1 << 5)); in sd_init()
402 reg_w(gspca_dev, STK1135_REG_GCTRL + 3, 0x80); in sd_init()
404 reg_w(gspca_dev, STK1135_REG_ICTRL + 1, 0x00); in sd_init()
405 reg_w(gspca_dev, STK1135_REG_ICTRL + 3, 0x03); in sd_init()
407 reg_w(gspca_dev, STK1135_REG_RMCTL + 1, 0x00); in sd_init()
408 reg_w(gspca_dev, STK1135_REG_RMCTL + 3, 0x02); in sd_init()
411 reg_w(gspca_dev, STK1135_REG_SICTL, 0x80); in sd_init()
412 reg_w(gspca_dev, STK1135_REG_SICTL, 0x00); in sd_init()
414 reg_w(gspca_dev, STK1135_REG_SICTL + 3, 0xba); in sd_init()
416 reg_w(gspca_dev, STK1135_REG_ASIC + 3, 0x00); in sd_init()
418 stk1135_configure_clock(gspca_dev); in sd_init()
422 sensor_id = sensor_read(gspca_dev, 0x000); in sd_init()
433 stk1135_camera_disable(gspca_dev); in sd_init()
435 return gspca_dev->usb_err; in sd_init()
439 static int sd_start(struct gspca_dev *gspca_dev) in sd_start() argument
441 struct sd *sd = (struct sd *) gspca_dev; in sd_start()
445 reg_w(gspca_dev, STK1135_REG_GCTRL, (1 << 5)); in sd_start()
447 stk1135_configure_clock(gspca_dev); in sd_start()
450 reg_w(gspca_dev, STK1135_REG_CISPO + 0, 0x00); in sd_start()
451 reg_w(gspca_dev, STK1135_REG_CISPO + 1, 0x00); in sd_start()
452 reg_w(gspca_dev, STK1135_REG_CISPO + 2, 0x00); in sd_start()
453 reg_w(gspca_dev, STK1135_REG_CISPO + 3, 0x00); in sd_start()
456 width = gspca_dev->pixfmt.width; in sd_start()
457 height = gspca_dev->pixfmt.height; in sd_start()
458 reg_w(gspca_dev, STK1135_REG_CIEPO + 0, width & 0xff); in sd_start()
459 reg_w(gspca_dev, STK1135_REG_CIEPO + 1, width >> 8); in sd_start()
460 reg_w(gspca_dev, STK1135_REG_CIEPO + 2, height & 0xff); in sd_start()
461 reg_w(gspca_dev, STK1135_REG_CIEPO + 3, height >> 8); in sd_start()
464 reg_w(gspca_dev, STK1135_REG_SCTRL, 0x20); in sd_start()
466 stk1135_configure_mt9m112(gspca_dev); in sd_start()
469 reg_w_mask(gspca_dev, STK1135_REG_SCTRL, 0x80, 0x80); in sd_start()
471 if (gspca_dev->usb_err >= 0) in sd_start()
472 gspca_dbg(gspca_dev, D_STREAM, "camera started alt: 0x%02x\n", in sd_start()
473 gspca_dev->alt); in sd_start()
477 return gspca_dev->usb_err; in sd_start()
480 static void sd_stopN(struct gspca_dev *gspca_dev) in sd_stopN() argument
482 struct usb_device *dev = gspca_dev->dev; in sd_stopN()
484 usb_set_interface(dev, gspca_dev->iface, 0); in sd_stopN()
486 stk1135_camera_disable(gspca_dev); in sd_stopN()
488 gspca_dbg(gspca_dev, D_STREAM, "camera stopped\n"); in sd_stopN()
491 static void sd_pkt_scan(struct gspca_dev *gspca_dev, in sd_pkt_scan() argument
495 struct sd *sd = (struct sd *) gspca_dev; in sd_pkt_scan()
503 gspca_dbg(gspca_dev, D_PACK, "received short packet (less than 4 bytes)\n"); in sd_pkt_scan()
519 gspca_dbg(gspca_dev, D_PACK, "received out-of-sequence packet\n"); in sd_pkt_scan()
522 gspca_dev->last_packet_type = DISCARD_PACKET; in sd_pkt_scan()
535 gspca_frame_add(gspca_dev, LAST_PACKET, data, 0); in sd_pkt_scan()
538 gspca_frame_add(gspca_dev, pkt_type, data + skip, len - skip); in sd_pkt_scan()
541 static void sethflip(struct gspca_dev *gspca_dev, s32 val) in sethflip() argument
543 struct sd *sd = (struct sd *) gspca_dev; in sethflip()
547 sensor_write_mask(gspca_dev, 0x020, val ? 0x0002 : 0x0000 , 0x0002); in sethflip()
550 static void setvflip(struct gspca_dev *gspca_dev, s32 val) in setvflip() argument
552 struct sd *sd = (struct sd *) gspca_dev; in setvflip()
556 sensor_write_mask(gspca_dev, 0x020, val ? 0x0001 : 0x0000 , 0x0001); in setvflip()
559 static void stk1135_dq_callback(struct gspca_dev *gspca_dev) in stk1135_dq_callback() argument
561 struct sd *sd = (struct sd *) gspca_dev; in stk1135_dq_callback()
565 sethflip(gspca_dev, v4l2_ctrl_g_ctrl(sd->hflip)); in stk1135_dq_callback()
566 setvflip(gspca_dev, v4l2_ctrl_g_ctrl(sd->vflip)); in stk1135_dq_callback()
572 struct gspca_dev *gspca_dev = in sd_s_ctrl() local
573 container_of(ctrl->handler, struct gspca_dev, ctrl_handler); in sd_s_ctrl()
575 gspca_dev->usb_err = 0; in sd_s_ctrl()
577 if (!gspca_dev->streaming) in sd_s_ctrl()
582 sethflip(gspca_dev, ctrl->val); in sd_s_ctrl()
585 setvflip(gspca_dev, ctrl->val); in sd_s_ctrl()
589 return gspca_dev->usb_err; in sd_s_ctrl()
596 static int sd_init_controls(struct gspca_dev *gspca_dev) in sd_init_controls() argument
598 struct sd *sd = (struct sd *) gspca_dev; in sd_init_controls()
599 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; in sd_init_controls()
601 gspca_dev->vdev.ctrl_handler = hdl; in sd_init_controls()
615 static void stk1135_try_fmt(struct gspca_dev *gspca_dev, struct v4l2_format *fmt) in stk1135_try_fmt() argument
627 static int stk1135_enum_framesizes(struct gspca_dev *gspca_dev, in stk1135_enum_framesizes() argument