24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #define GSPCA_VERSION "2.14.0"
31 #include <linux/sched.h>
32 #include <linux/slab.h>
34 #include <linux/string.h>
47 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
48 #include <linux/input.h>
54 #if DEF_NURBS > MAX_NURBS
55 #error "DEF_NURBS too big"
58 MODULE_AUTHOR(
"Jean-François Moine <http://moinejf.free.fr>");
64 int gspca_debug =
D_ERR | D_PROBE;
69 if ((pixfmt >> 24) >=
'0' && (pixfmt >> 24) <=
'z') {
70 PDEBUG(D_CONF|D_STREAM,
"%s %c%c%c%c %dx%d",
74 (pixfmt >> 16) & 0xff,
78 PDEBUG(D_CONF|D_STREAM,
"%s 0x%08x %dx%d",
85 #define PDEBUG_MODE(txt, pixfmt, w, h)
89 #define GSPCA_MEMORY_NO 0
90 #define GSPCA_MEMORY_READ 7
92 #define BUF_ALL_FLAGS (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE)
113 static const struct vm_operations_struct gspca_vm_ops = {
114 .open = gspca_vm_open,
115 .close = gspca_vm_close,
121 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
122 static void int_irq(
struct urb *
urb)
130 if (gspca_dev->
sd_desc->int_pkt_scan(gspca_dev,
131 urb->transfer_buffer, urb->actual_length) < 0) {
146 PDEBUG(
D_ERR,
"URB error %i, resubmitting", urb->status);
154 pr_err(
"Resubmit URB failed with error %i\n",
ret);
158 static int gspca_input_connect(
struct gspca_dev *
dev)
160 struct input_dev *input_dev;
163 dev->input_dev =
NULL;
165 input_dev = input_allocate_device();
169 usb_make_path(dev->
dev, dev->phys,
sizeof(dev->phys));
170 strlcat(dev->phys,
"/input0",
sizeof(dev->phys));
172 input_dev->name = dev->
sd_desc->name;
173 input_dev->phys = dev->phys;
175 usb_to_input_id(dev->
dev, &input_dev->id);
179 input_dev->dev.parent = &dev->
dev->dev;
181 err = input_register_device(input_dev);
183 pr_err(
"Input device registration failed with error %i\n",
185 input_dev->dev.parent =
NULL;
186 input_free_device(input_dev);
188 dev->input_dev = input_dev;
195 static int alloc_and_submit_int_urb(
struct gspca_dev *gspca_dev,
198 unsigned int buffer_len;
201 struct usb_device *
dev;
207 PDEBUG(D_CONF,
"found int in endpoint: 0x%x, "
208 "buffer_len=%u, interval=%u",
211 dev = gspca_dev->
dev;
225 usb_fill_int_urb(urb, dev,
228 int_irq, (
void *)gspca_dev, interval);
229 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
232 PDEBUG(
D_ERR,
"submit int URB failed with error %i", ret);
235 gspca_dev->int_urb =
urb;
240 urb->transfer_buffer_length,
241 urb->transfer_buffer,
249 static void gspca_input_create_urb(
struct gspca_dev *gspca_dev)
252 struct usb_host_interface *intf_desc;
256 if (gspca_dev->
sd_desc->int_pkt_scan) {
258 intf_desc = intf->cur_altsetting;
259 for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) {
260 ep = &intf_desc->endpoint[
i].desc;
261 if (usb_endpoint_dir_in(ep) &&
262 usb_endpoint_xfer_int(ep)) {
264 alloc_and_submit_int_urb(gspca_dev, ep);
271 static void gspca_input_destroy_urb(
struct gspca_dev *gspca_dev)
275 urb = gspca_dev->int_urb;
277 gspca_dev->int_urb =
NULL;
280 urb->transfer_buffer_length,
281 urb->transfer_buffer,
287 static inline void gspca_input_destroy_urb(
struct gspca_dev *gspca_dev)
291 static inline void gspca_input_create_urb(
struct gspca_dev *gspca_dev)
295 static inline int gspca_input_connect(
struct gspca_dev *dev)
304 static void fill_frame(
struct gspca_dev *gspca_dev,
311 if (urb->status != 0) {
315 if (gspca_dev->frozen)
318 PDEBUG(
D_ERR|D_PACK,
"urb status: %d", urb->status);
322 pkt_scan = gspca_dev->
sd_desc->pkt_scan;
323 for (i = 0; i < urb->number_of_packets; i++) {
324 len = urb->iso_frame_desc[
i].actual_length;
327 st = urb->iso_frame_desc[
i].status;
329 pr_err(
"ISOC data error: [%d] len=%d, status=%d\n",
341 PDEBUG(D_PACK,
"packet [%d] o:%d l:%d",
342 i, urb->iso_frame_desc[i].offset, len);
343 data = (
u8 *) urb->transfer_buffer
344 + urb->iso_frame_desc[i].offset;
345 pkt_scan(gspca_dev, data, len);
352 pr_err(
"usb_submit_urb() ret %d\n", st);
360 static void isoc_irq(
struct urb *urb)
362 struct gspca_dev *gspca_dev = (
struct gspca_dev *) urb->context;
364 PDEBUG(D_PACK,
"isoc irq");
367 fill_frame(gspca_dev, urb);
373 static void bulk_irq(
struct urb *urb)
375 struct gspca_dev *gspca_dev = (
struct gspca_dev *) urb->context;
378 PDEBUG(D_PACK,
"bulk irq");
381 switch (urb->status) {
388 if (gspca_dev->frozen)
391 PDEBUG(
D_ERR|D_PACK,
"urb status: %d", urb->status);
396 PDEBUG(D_PACK,
"packet l:%d", urb->actual_length);
397 gspca_dev->
sd_desc->pkt_scan(gspca_dev,
398 urb->transfer_buffer,
403 if (gspca_dev->
cam.bulk_nurbs != 0) {
406 pr_err(
"usb_submit_urb() ret %d\n", st);
429 PDEBUG(D_PACK,
"add t:%d l:%d", packet_type, len);
441 frame = &gspca_dev->
frame[
j];
487 frame = &gspca_dev->
frame[
j];
495 PDEBUG(D_FRAM,
"frame complete len:%d",
503 static int frame_alloc(
struct gspca_dev *gspca_dev,
struct file *
file,
511 frsz = gspca_dev->
cam.cam_mode[
i].sizeimage;
512 PDEBUG(D_STREAM,
"frame alloc frsz: %d", frsz);
517 if (!gspca_dev->
frbuf) {
518 pr_err(
"frame alloc failed\n");
523 gspca_dev->
frsz = frsz;
525 for (i = 0; i <
count; i++) {
526 frame = &gspca_dev->
frame[
i];
534 frame->
data = gspca_dev->
frbuf + i * frsz;
535 frame->
v4l2_buf.m.offset = i * frsz;
543 static void frame_free(
struct gspca_dev *gspca_dev)
547 PDEBUG(D_STREAM,
"frame free");
551 for (i = 0; i < gspca_dev->
nframes; i++)
560 static void destroy_urbs(
struct gspca_dev *gspca_dev)
565 PDEBUG(D_STREAM,
"kill transfer");
567 urb = gspca_dev->
urb[
i];
573 if (urb->transfer_buffer !=
NULL)
575 urb->transfer_buffer_length,
576 urb->transfer_buffer,
582 static int gspca_set_alt0(
struct gspca_dev *gspca_dev)
586 if (gspca_dev->
alt == 0)
590 pr_err(
"set alt 0 err %d\n", ret);
595 static void gspca_stream_off(
struct gspca_dev *gspca_dev)
600 gspca_dev->
sd_desc->stopN(gspca_dev);
601 destroy_urbs(gspca_dev);
602 gspca_input_destroy_urb(gspca_dev);
603 gspca_set_alt0(gspca_dev);
604 gspca_input_create_urb(gspca_dev);
606 gspca_dev->
sd_desc->stop0(gspca_dev);
607 PDEBUG(D_STREAM,
"stream off OK");
613 static struct usb_host_endpoint *alt_xfer(
struct usb_host_interface *alt,
616 struct usb_host_endpoint *ep;
619 for (i = 0; i < alt->desc.bNumEndpoints; i++) {
620 ep = &alt->endpoint[
i];
623 && ep->desc.wMaxPacketSize != 0
624 && usb_endpoint_dir_in(&ep->desc))
631 static u32 which_bandwidth(
struct gspca_dev *gspca_dev)
638 bandwidth = gspca_dev->
cam.cam_mode[
i].sizeimage;
641 if (!gspca_dev->
cam.needs_full_bandwidth &&
643 gspca_dev->
cam.cam_mode[i].height)
644 bandwidth = bandwidth * 3 / 8;
647 if (gspca_dev->
sd_desc->get_streamparm) {
650 gspca_dev->
sd_desc->get_streamparm(gspca_dev, &
parm);
651 bandwidth *=
parm.parm.capture.timeperframe.denominator;
652 bandwidth /=
parm.parm.capture.timeperframe.numerator;
657 if (gspca_dev->
width >= 640
664 PDEBUG(D_STREAM,
"min bandwidth: %d", bandwidth);
679 static int build_isoc_ep_tb(
struct gspca_dev *gspca_dev,
683 struct usb_host_endpoint *ep;
684 int i,
j, nbalt, psize, found;
687 nbalt = intf->num_altsetting;
697 for (j = 0; j < nbalt; j++) {
698 ep = alt_xfer(&intf->altsetting[j],
702 if (ep->desc.bInterval == 0) {
703 pr_err(
"alt %d iso endp with 0 interval\n", j);
707 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
708 bandwidth = psize * 1000;
712 bandwidth /= 1 << (ep->desc.bInterval - 1);
713 if (bandwidth <= last_bw)
715 if (bandwidth < ep_tb->bandwidth) {
723 PDEBUG(D_STREAM,
"alt %d bandwidth %d",
738 if (gspca_dev->
audio &&
740 last_bw >= 1000000 &&
742 PDEBUG(D_STREAM,
"dev has usb audio, skipping highest alt");
748 bandwidth = which_bandwidth(gspca_dev);
762 static int create_urbs(
struct gspca_dev *gspca_dev,
763 struct usb_host_endpoint *ep)
766 int n, nurbs,
i, psize, npkt, bsize;
771 if (!gspca_dev->
cam.bulk) {
775 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
778 npkt = gspca_dev->
cam.npkt;
781 bsize = psize * npkt;
783 "isoc %d pkts size %d = bsize:%d",
788 bsize = gspca_dev->
cam.bulk_size;
791 PDEBUG(D_STREAM,
"bulk bsize:%d", bsize);
792 if (gspca_dev->
cam.bulk_nurbs != 0)
793 nurbs = gspca_dev->
cam.bulk_nurbs;
798 for (n = 0; n < nurbs; n++) {
801 pr_err(
"usb_alloc_urb failed\n");
810 if (urb->transfer_buffer ==
NULL) {
811 pr_err(
"usb_alloc_coherent failed\n");
814 urb->dev = gspca_dev->
dev;
815 urb->context = gspca_dev;
816 urb->transfer_buffer_length = bsize;
818 urb->pipe = usb_rcvisocpipe(gspca_dev->
dev,
819 ep->desc.bEndpointAddress);
820 urb->transfer_flags = URB_ISO_ASAP
821 | URB_NO_TRANSFER_DMA_MAP;
822 urb->interval = 1 << (ep->desc.bInterval - 1);
823 urb->complete = isoc_irq;
824 urb->number_of_packets = npkt;
825 for (i = 0; i < npkt; i++) {
826 urb->iso_frame_desc[
i].length = psize;
827 urb->iso_frame_desc[
i].offset = psize *
i;
830 urb->pipe = usb_rcvbulkpipe(gspca_dev->
dev,
831 ep->desc.bEndpointAddress);
832 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
833 urb->complete = bulk_irq;
842 static int gspca_init_transfer(
struct gspca_dev *gspca_dev)
845 struct usb_host_endpoint *ep;
848 int n,
ret, xfer,
alt, alt_idx;
860 gspca_dev->
alt = gspca_dev->
cam.bulk ? intf->num_altsetting : 0;
861 if (gspca_dev->
sd_desc->isoc_init) {
862 ret = gspca_dev->
sd_desc->isoc_init(gspca_dev);
870 if (gspca_dev->
alt != 0) {
872 ep = alt_xfer(&intf->altsetting[gspca_dev->
alt], xfer);
874 pr_err(
"bad altsetting %d\n", gspca_dev->
alt);
877 ep_tb[0].
alt = gspca_dev->
alt;
883 alt_idx = build_isoc_ep_tb(gspca_dev, intf, ep_tb);
885 pr_err(
"no transfer endpoint found\n");
892 gspca_input_destroy_urb(gspca_dev);
894 gspca_dev->
alt = ep_tb[--alt_idx].
alt;
897 if (alt != gspca_dev->
alt) {
898 alt = gspca_dev->
alt;
899 if (intf->num_altsetting > 1) {
906 pr_err(
"set alt %d err %d\n", alt, ret);
911 if (!gspca_dev->
cam.no_urb_create) {
912 PDEBUG(D_STREAM,
"init transfer alt %d", alt);
913 ret = create_urbs(gspca_dev,
914 alt_xfer(&intf->altsetting[alt], xfer));
916 destroy_urbs(gspca_dev);
922 if (gspca_dev->
cam.bulk)
924 gspca_dev->
urb[0]->pipe);
927 ret = gspca_dev->
sd_desc->start(gspca_dev);
929 destroy_urbs(gspca_dev);
936 if (gspca_dev->
cam.bulk && gspca_dev->
cam.bulk_nurbs == 0)
941 urb = gspca_dev->
urb[
n];
953 gspca_stream_off(gspca_dev);
955 pr_err(
"usb_submit_urb alt %d err %d\n",
956 gspca_dev->
alt, ret);
964 "alt %d - bandwidth not wide enough - trying again",
967 if (gspca_dev->
sd_desc->isoc_nego) {
968 ret = gspca_dev->
sd_desc->isoc_nego(gspca_dev);
973 pr_err(
"no transfer endpoint found\n");
977 gspca_dev->
alt = ep_tb[--alt_idx].
alt;
981 gspca_input_create_urb(gspca_dev);
985 static void gspca_set_default_mode(
struct gspca_dev *gspca_dev)
990 i = gspca_dev->
cam.nmodes - 1;
992 gspca_dev->
width = gspca_dev->
cam.cam_mode[
i].width;
993 gspca_dev->
height = gspca_dev->
cam.cam_mode[
i].height;
994 gspca_dev->
pixfmt = gspca_dev->
cam.cam_mode[
i].pixelformat;
1000 ctrl = gspca_dev->
cam.ctrls;
1003 i < gspca_dev->
sd_desc->nctrls;
1009 static int wxh_to_mode(
struct gspca_dev *gspca_dev,
1014 for (i = gspca_dev->
cam.nmodes; --i > 0; ) {
1015 if (width >= gspca_dev->
cam.cam_mode[i].width
1016 && height >= gspca_dev->
cam.cam_mode[i].height)
1025 static int gspca_get_mode(
struct gspca_dev *gspca_dev,
1031 modeU = modeD =
mode;
1032 while ((modeU < gspca_dev->
cam.
nmodes) || modeD >= 0) {
1034 if (gspca_dev->
cam.cam_mode[modeD].pixelformat
1039 if (gspca_dev->
cam.cam_mode[modeU].pixelformat
1047 #ifdef CONFIG_VIDEO_ADV_DEBUG
1048 static int vidioc_g_register(
struct file *file,
void *
priv,
1051 struct gspca_dev *gspca_dev = video_drvdata(file);
1054 return gspca_dev->
sd_desc->get_register(gspca_dev, reg);
1057 static int vidioc_s_register(
struct file *file,
void *priv,
1060 struct gspca_dev *gspca_dev = video_drvdata(file);
1063 return gspca_dev->
sd_desc->set_register(gspca_dev, reg);
1067 static int vidioc_g_chip_ident(
struct file *file,
void *priv,
1070 struct gspca_dev *gspca_dev = video_drvdata(file);
1073 return gspca_dev->
sd_desc->get_chip_ident(gspca_dev, chip);
1076 static int vidioc_enum_fmt_vid_cap(
struct file *file,
void *priv,
1079 struct gspca_dev *gspca_dev = video_drvdata(file);
1086 for (i = gspca_dev->
cam.nmodes; --i >= 0; ) {
1087 fmt_tb[
index] = gspca_dev->
cam.cam_mode[
i].pixelformat;
1090 if (fmt_tb[j] == fmt_tb[index])
1095 if (fmtdesc->
index == index)
1106 if (gspca_dev->
cam.cam_mode[i].sizeimage <
1107 gspca_dev->
cam.cam_mode[i].width *
1108 gspca_dev->
cam.cam_mode[i].height)
1118 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *priv,
1121 struct gspca_dev *gspca_dev = video_drvdata(file);
1132 static int try_fmt_vid_cap(
struct gspca_dev *gspca_dev,
1141 if (gspca_debug & D_CONF)
1145 mode = wxh_to_mode(gspca_dev, w, h);
1148 if (gspca_dev->
cam.cam_mode[mode].pixelformat
1149 != fmt->
fmt.
pix.pixelformat) {
1152 mode2 = gspca_get_mode(gspca_dev, mode,
1153 fmt->
fmt.
pix.pixelformat);
1166 static int vidioc_try_fmt_vid_cap(
struct file *file,
1170 struct gspca_dev *gspca_dev = video_drvdata(file);
1173 ret = try_fmt_vid_cap(gspca_dev, fmt);
1179 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
1182 struct gspca_dev *gspca_dev = video_drvdata(file);
1188 ret = try_fmt_vid_cap(gspca_dev, fmt);
1193 && fmt->
fmt.
pix.sizeimage > gspca_dev->
frsz) {
1218 static int vidioc_enum_framesizes(
struct file *file,
void *priv,
1221 struct gspca_dev *gspca_dev = video_drvdata(file);
1225 for (i = 0; i < gspca_dev->
cam.nmodes; i++) {
1227 gspca_dev->
cam.cam_mode[i].pixelformat)
1230 if (fsize->
index == index) {
1233 gspca_dev->
cam.cam_mode[
i].width;
1235 gspca_dev->
cam.cam_mode[
i].height;
1244 static int vidioc_enum_frameintervals(
struct file *filp,
void *priv,
1247 struct gspca_dev *gspca_dev = video_drvdata(filp);
1248 int mode = wxh_to_mode(gspca_dev, fival->
width, fival->
height);
1251 if (gspca_dev->
cam.mode_framerates ==
NULL ||
1252 gspca_dev->
cam.mode_framerates[mode].nrates == 0)
1256 gspca_dev->
cam.cam_mode[mode].pixelformat)
1259 for (i = 0; i < gspca_dev->
cam.mode_framerates[
mode].nrates; i++) {
1260 if (fival->
index == i) {
1264 gspca_dev->
cam.mode_framerates[
mode].rates[
i];
1274 struct gspca_dev *gspca_dev =
1283 static int dev_open(
struct file *file)
1285 struct gspca_dev *gspca_dev = video_drvdata(file);
1290 if (!try_module_get(gspca_dev->
module))
1295 if (gspca_debug & D_V4L2)
1305 static int dev_close(
struct file *file)
1307 struct gspca_dev *gspca_dev = video_drvdata(file);
1323 gspca_stream_off(gspca_dev);
1324 frame_free(gspca_dev);
1326 module_put(gspca_dev->
module);
1330 PDEBUG(D_STREAM,
"close done");
1335 static int vidioc_querycap(
struct file *file,
void *priv,
1338 struct gspca_dev *gspca_dev = video_drvdata(file);
1342 if (gspca_dev->
dev->product !=
NULL) {
1347 "USB Camera (%04x:%04x)",
1351 usb_make_path(gspca_dev->
dev, (
char *) cap->
bus_info,
1360 static int get_ctrl(
struct gspca_dev *gspca_dev,
1363 const struct ctrl *ctrls;
1366 for (i = 0, ctrls = gspca_dev->
sd_desc->ctrls;
1369 if (gspca_dev->
ctrl_dis & (1 << i))
1371 if (
id == ctrls->
qctrl.id)
1377 static int vidioc_queryctrl(
struct file *file,
void *priv,
1380 struct gspca_dev *gspca_dev = video_drvdata(file);
1381 const struct ctrl *ctrls;
1391 for (i = 0; i < gspca_dev->
sd_desc->nctrls; i++) {
1392 if (gspca_dev->
ctrl_dis & (1 << i))
1394 if (gspca_dev->
sd_desc->ctrls[i].qctrl.id <
id)
1397 && gspca_dev->
sd_desc->ctrls[i].qctrl.id
1398 > gspca_dev->
sd_desc->ctrls[idx].qctrl.id)
1409 if (gspca_dev->
cam.ctrls !=
NULL) {
1410 gspca_ctrl = &gspca_dev->
cam.ctrls[
idx];
1420 static int vidioc_s_ctrl(
struct file *file,
void *priv,
1423 struct gspca_dev *gspca_dev = video_drvdata(file);
1424 const struct ctrl *ctrls;
1425 struct gspca_ctrl *gspca_ctrl;
1434 if (gspca_dev->
cam.ctrls !=
NULL) {
1435 gspca_ctrl = &gspca_dev->
cam.ctrls[
idx];
1445 PDEBUG(D_CONF,
"set ctrl [%08x] = %d", ctrl->
id, ctrl->
value);
1448 return ctrls->
set(gspca_dev, ctrl->
value);
1449 if (gspca_ctrl !=
NULL) {
1458 static int vidioc_g_ctrl(
struct file *file,
void *priv,
1461 struct gspca_dev *gspca_dev = video_drvdata(file);
1462 const struct ctrl *ctrls;
1472 return ctrls->
get(gspca_dev, &ctrl->
value);
1473 if (gspca_dev->
cam.ctrls !=
NULL)
1478 static int vidioc_querymenu(
struct file *file,
void *priv,
1481 struct gspca_dev *gspca_dev = video_drvdata(file);
1483 if (!gspca_dev->
sd_desc->querymenu)
1485 return gspca_dev->
sd_desc->querymenu(gspca_dev, qmenu);
1488 static int vidioc_enum_input(
struct file *file,
void *priv,
1491 struct gspca_dev *gspca_dev = video_drvdata(file);
1493 if (input->
index != 0)
1496 input->
status = gspca_dev->
cam.input_flags;
1498 sizeof input->
name);
1502 static int vidioc_g_input(
struct file *file,
void *priv,
unsigned int *i)
1508 static int vidioc_s_input(
struct file *file,
void *priv,
unsigned int i)
1515 static int vidioc_reqbufs(
struct file *file,
void *priv,
1518 struct gspca_dev *gspca_dev = video_drvdata(file);
1548 for (i = 0; i < gspca_dev->
nframes; i++) {
1549 if (gspca_dev->
frame[i].vma_use_count) {
1558 gspca_stream_off(gspca_dev);
1568 frame_free(gspca_dev);
1571 ret = frame_alloc(gspca_dev, file, rb->
memory, rb->
count);
1575 ret = gspca_init_transfer(gspca_dev);
1579 PDEBUG(D_STREAM,
"reqbufs st:%d c:%d", ret, rb->
count);
1583 static int vidioc_querybuf(
struct file *file,
void *priv,
1586 struct gspca_dev *gspca_dev = video_drvdata(file);
1589 if (v4l2_buf->
index < 0
1598 static int vidioc_streamon(
struct file *file,
void *priv,
1601 struct gspca_dev *gspca_dev = video_drvdata(file);
1621 ret = gspca_init_transfer(gspca_dev);
1626 if (gspca_debug & D_STREAM) {
1639 static int vidioc_streamoff(
struct file *file,
void *priv,
1642 struct gspca_dev *gspca_dev = video_drvdata(file);
1663 gspca_stream_off(gspca_dev);
1668 for (i = 0; i < gspca_dev->
nframes; i++)
1672 gspca_dev->
fr_o = 0;
1679 static int vidioc_g_jpegcomp(
struct file *file,
void *priv,
1682 struct gspca_dev *gspca_dev = video_drvdata(file);
1685 return gspca_dev->
sd_desc->get_jcomp(gspca_dev, jpegcomp);
1688 static int vidioc_s_jpegcomp(
struct file *file,
void *priv,
1691 struct gspca_dev *gspca_dev = video_drvdata(file);
1694 return gspca_dev->
sd_desc->set_jcomp(gspca_dev, jpegcomp);
1697 static int vidioc_g_parm(
struct file *filp,
void *priv,
1700 struct gspca_dev *gspca_dev = video_drvdata(filp);
1704 if (gspca_dev->
sd_desc->get_streamparm) {
1706 gspca_dev->
sd_desc->get_streamparm(gspca_dev, parm);
1712 static int vidioc_s_parm(
struct file *filp,
void *priv,
1715 struct gspca_dev *gspca_dev = video_drvdata(filp);
1724 if (gspca_dev->
sd_desc->set_streamparm) {
1726 gspca_dev->
sd_desc->set_streamparm(gspca_dev, parm);
1733 static int dev_mmap(
struct file *file,
struct vm_area_struct *vma)
1735 struct gspca_dev *gspca_dev = video_drvdata(file);
1743 PDEBUG(D_STREAM,
"mmap start:%08x size:%d", (
int) start, (
int) size);
1753 for (i = 0; i < gspca_dev->
nframes; ++
i) {
1755 PDEBUG(D_STREAM,
"mmap bad memory type");
1760 frame = &gspca_dev->
frame[
i];
1764 if (frame ==
NULL) {
1765 PDEBUG(D_STREAM,
"mmap no frame buffer found");
1769 if (size != frame->
v4l2_buf.length) {
1770 PDEBUG(D_STREAM,
"mmap bad size");
1781 addr = (
unsigned long) frame->
data;
1792 vma->
vm_ops = &gspca_vm_ops;
1801 static int frame_ready_nolock(
struct gspca_dev *gspca_dev,
struct file *file,
1814 static int frame_ready(
struct gspca_dev *gspca_dev,
struct file *file,
1821 ret = frame_ready_nolock(gspca_dev, file, memory);
1831 static int vidioc_dqbuf(
struct file *file,
void *priv,
1834 struct gspca_dev *gspca_dev = video_drvdata(file);
1844 ret = frame_ready_nolock(gspca_dev, file, v4l2_buf->
memory);
1857 frame_ready(gspca_dev, file, v4l2_buf->
memory),
1868 i = gspca_dev->
fr_o;
1870 frame = &gspca_dev->
frame[
j];
1876 PDEBUG(D_FRAM,
"dqbuf %d", j);
1884 "dqbuf cp to user failed");
1891 if (ret == 0 && gspca_dev->
sd_desc->dq_callback) {
1895 gspca_dev->
sd_desc->dq_callback(gspca_dev);
1908 static int vidioc_qbuf(
struct file *file,
void *priv,
1911 struct gspca_dev *gspca_dev = video_drvdata(file);
1920 index = v4l2_buf->
index;
1921 if ((
unsigned) index >= gspca_dev->
nframes) {
1923 "qbuf idx %d >= %d", index, gspca_dev->
nframes);
1928 PDEBUG(D_FRAM,
"qbuf bad memory type");
1935 PDEBUG(D_FRAM,
"qbuf bad state");
1963 static int read_alloc(
struct gspca_dev *gspca_dev,
1969 PDEBUG(D_STREAM,
"read alloc");
1974 if (gspca_dev->
nframes == 0) {
1977 memset(&rb, 0,
sizeof rb);
1981 ret = vidioc_reqbufs(file, gspca_dev, &rb);
1983 PDEBUG(D_STREAM,
"read reqbuf err %d", ret);
1986 memset(&v4l2_buf, 0,
sizeof v4l2_buf);
1989 for (i = 0; i < gspca_dev->
nbufread; i++) {
1991 ret = vidioc_qbuf(file, gspca_dev, &v4l2_buf);
1993 PDEBUG(D_STREAM,
"read qbuf err: %d", ret);
2002 PDEBUG(D_STREAM,
"read streamon err %d", ret);
2008 static unsigned int dev_poll(
struct file *file,
poll_table *
wait)
2010 struct gspca_dev *gspca_dev = video_drvdata(file);
2011 unsigned long req_events = poll_requested_events(wait);
2022 if (read_alloc(gspca_dev, file) != 0) {
2028 poll_wait(file, &gspca_dev->
wq, wait);
2047 static ssize_t dev_read(
struct file *file,
char __user *data,
2048 size_t count, loff_t *ppos)
2050 struct gspca_dev *gspca_dev = video_drvdata(file);
2056 PDEBUG(D_FRAM,
"read (%zd)", count);
2058 ret = read_alloc(gspca_dev, file);
2068 memset(&v4l2_buf, 0,
sizeof v4l2_buf);
2071 ret = vidioc_dqbuf(file, gspca_dev, &v4l2_buf);
2073 PDEBUG(D_STREAM,
"read dqbuf err %d", ret);
2084 ret = vidioc_qbuf(file, gspca_dev, &v4l2_buf);
2086 PDEBUG(D_STREAM,
"read qbuf err %d", ret);
2092 if (count > frame->
v4l2_buf.bytesused)
2097 "read cp to user lack %d / %zd", ret, count);
2104 ret2 = vidioc_qbuf(file, gspca_dev, &v4l2_buf);
2113 .release = dev_close,
2145 #ifdef CONFIG_VIDEO_ADV_DEBUG
2146 .vidioc_g_register = vidioc_g_register,
2147 .vidioc_s_register = vidioc_s_register,
2155 .name =
"gspca main driver",
2157 .ioctl_ops = &dev_ioctl_ops,
2162 static void ctrls_init(
struct gspca_dev *gspca_dev)
2164 struct gspca_ctrl *
ctrl;
2167 for (i = 0, ctrl = gspca_dev->
cam.ctrls;
2170 ctrl->
def = gspca_dev->
sd_desc->ctrls[
i].qctrl.default_value;
2172 ctrl->
min = gspca_dev->
sd_desc->ctrls[
i].qctrl.minimum;
2173 ctrl->
max = gspca_dev->
sd_desc->ctrls[
i].qctrl.maximum;
2189 struct gspca_dev *gspca_dev;
2190 struct usb_device *dev = interface_to_usbdev(intf);
2197 if (dev_size <
sizeof *gspca_dev)
2198 dev_size =
sizeof *gspca_dev;
2201 pr_err(
"couldn't kzalloc gspca struct\n");
2206 pr_err(
"out of memory\n");
2211 gspca_dev->
iface = intf->cur_altsetting->desc.bInterfaceNumber;
2214 if (dev->actconfig->desc.bNumInterfaces != 1) {
2218 for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
2219 intf2 = dev->actconfig->interface[
i];
2221 && intf2->altsetting !=
NULL
2222 && intf2->altsetting->desc.bInterfaceClass ==
2224 gspca_dev->
audio = 1;
2230 gspca_dev->
v4l2_dev.release = gspca_release;
2237 gspca_dev->
vdev = gspca_template;
2239 video_set_drvdata(&gspca_dev->
vdev, gspca_dev);
2241 gspca_dev->
module = module;
2250 ret = sd_desc->
config(gspca_dev,
id);
2253 if (gspca_dev->
cam.ctrls !=
NULL)
2254 ctrls_init(gspca_dev);
2255 ret = sd_desc->
init(gspca_dev);
2262 gspca_set_default_mode(gspca_dev);
2264 ret = gspca_input_connect(gspca_dev);
2276 if (!gspca_dev->
sd_desc->get_chip_ident)
2278 #ifdef CONFIG_VIDEO_ADV_DEBUG
2279 if (!gspca_dev->
sd_desc->get_chip_ident ||
2280 !gspca_dev->
sd_desc->get_register)
2282 if (!gspca_dev->
sd_desc->get_chip_ident ||
2283 !gspca_dev->
sd_desc->set_register)
2286 if (!gspca_dev->
sd_desc->get_jcomp)
2288 if (!gspca_dev->
sd_desc->set_jcomp)
2292 ret = video_register_device(&gspca_dev->
vdev,
2296 pr_err(
"video_register_device err %d\n", ret);
2300 usb_set_intfdata(intf, gspca_dev);
2301 PDEBUG(D_PROBE,
"%s created", video_device_node_name(&gspca_dev->
vdev));
2303 gspca_input_create_urb(gspca_dev);
2307 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2308 if (gspca_dev->input_dev)
2309 input_unregister_device(gspca_dev->input_dev);
2325 struct usb_device *dev = interface_to_usbdev(intf);
2328 if (dev->descriptor.bNumConfigurations != 1) {
2329 pr_err(
"%04x:%04x too many config\n",
2335 if (dev->actconfig->desc.bNumInterfaces != 1
2336 && intf->cur_altsetting->desc.bInterfaceNumber != 0)
2351 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
2352 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2353 struct input_dev *input_dev;
2356 PDEBUG(D_PROBE,
"%s disconnect",
2357 video_device_node_name(&gspca_dev->
vdev));
2362 destroy_urbs(gspca_dev);
2364 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2365 gspca_input_destroy_urb(gspca_dev);
2366 input_dev = gspca_dev->input_dev;
2368 gspca_dev->input_dev =
NULL;
2369 input_unregister_device(input_dev);
2374 gspca_dev->
sd_desc->stop0(gspca_dev);
2392 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
2394 gspca_input_destroy_urb(gspca_dev);
2400 gspca_dev->frozen = 1;
2402 if (gspca_dev->
sd_desc->stopN)
2403 gspca_dev->
sd_desc->stopN(gspca_dev);
2404 destroy_urbs(gspca_dev);
2405 gspca_set_alt0(gspca_dev);
2406 if (gspca_dev->
sd_desc->stop0)
2407 gspca_dev->
sd_desc->stop0(gspca_dev);
2416 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
2420 gspca_dev->frozen = 0;
2422 gspca_dev->
sd_desc->init(gspca_dev);
2431 ret = gspca_init_transfer(gspca_dev);
2433 gspca_input_create_urb(gspca_dev);
2442 static int __init gspca_init(
void)
2447 static void __exit gspca_exit(
void)
2457 "Debug (bit) 0x01:error 0x02:probe 0x04:config"
2458 " 0x08:stream 0x10:frame 0x20:packet"