Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 1 | #ifndef GSPCAV2_H |
| 2 | #define GSPCAV2_H |
| 3 | |
| 4 | #include <linux/module.h> |
| 5 | #include <linux/version.h> |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/usb.h> |
| 8 | #include <linux/videodev2.h> |
| 9 | #include <media/v4l2-common.h> |
| 10 | #include <linux/mutex.h> |
| 11 | |
Jean-Francois Moine | 335b3f8 | 2008-07-30 04:53:02 -0300 | [diff] [blame] | 12 | /* compilation option */ |
| 13 | #define GSPCA_DEBUG 1 |
| 14 | |
| 15 | #ifdef GSPCA_DEBUG |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 16 | /* GSPCA our debug messages */ |
| 17 | extern int gspca_debug; |
| 18 | #define PDEBUG(level, fmt, args...) \ |
| 19 | do {\ |
| 20 | if (gspca_debug & (level)) \ |
| 21 | printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \ |
| 22 | } while (0) |
| 23 | #define D_ERR 0x01 |
| 24 | #define D_PROBE 0x02 |
| 25 | #define D_CONF 0x04 |
| 26 | #define D_STREAM 0x08 |
| 27 | #define D_FRAM 0x10 |
| 28 | #define D_PACK 0x20 |
| 29 | #define D_USBI 0x40 |
| 30 | #define D_USBO 0x80 |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 31 | #define D_V4L2 0x0100 |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 32 | #else |
| 33 | #define PDEBUG(level, fmt, args...) |
| 34 | #endif |
| 35 | #undef err |
| 36 | #define err(fmt, args...) \ |
| 37 | do {\ |
| 38 | printk(KERN_ERR MODULE_NAME ": " fmt "\n", ## args); \ |
| 39 | } while (0) |
| 40 | #undef info |
| 41 | #define info(fmt, args...) \ |
| 42 | do {\ |
| 43 | printk(KERN_INFO MODULE_NAME ": " fmt "\n", ## args); \ |
| 44 | } while (0) |
| 45 | #undef warn |
| 46 | #define warn(fmt, args...) \ |
| 47 | do {\ |
| 48 | printk(KERN_WARNING MODULE_NAME ": " fmt "\n", ## args); \ |
| 49 | } while (0) |
| 50 | |
| 51 | #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */ |
Jean-Francois Moine | 0be0100 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 52 | /* image transfers */ |
| 53 | #define MAX_NURBS 4 /* max number of URBs */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 54 | #define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 55 | #define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 56 | |
| 57 | /* device information - set at probe time */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 58 | struct cam { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 59 | struct v4l2_pix_format *cam_mode; /* size nmodes */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 60 | char nmodes; |
| 61 | __u8 epaddr; |
| 62 | }; |
| 63 | |
| 64 | struct gspca_dev; |
| 65 | struct gspca_frame; |
| 66 | |
| 67 | /* subdriver operations */ |
| 68 | typedef int (*cam_op) (struct gspca_dev *); |
| 69 | typedef void (*cam_v_op) (struct gspca_dev *); |
| 70 | typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *); |
| 71 | typedef int (*cam_jpg_op) (struct gspca_dev *, |
| 72 | struct v4l2_jpegcompression *); |
| 73 | typedef int (*cam_qmnu_op) (struct gspca_dev *, |
| 74 | struct v4l2_querymenu *); |
| 75 | typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, |
| 76 | struct gspca_frame *frame, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 77 | __u8 *data, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 78 | int len); |
| 79 | |
| 80 | struct ctrl { |
| 81 | struct v4l2_queryctrl qctrl; |
| 82 | int (*set)(struct gspca_dev *, __s32); |
| 83 | int (*get)(struct gspca_dev *, __s32 *); |
| 84 | }; |
| 85 | |
| 86 | /* subdriver description */ |
| 87 | struct sd_desc { |
| 88 | /* information */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 89 | const char *name; /* sub-driver name */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 90 | /* controls */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 91 | const struct ctrl *ctrls; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 92 | int nctrls; |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 93 | /* mandatory operations */ |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 94 | cam_cf_op config; /* called on probe */ |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 95 | cam_op init; /* called on probe and resume */ |
Hans de Goede | e2997a7 | 2008-04-23 08:09:12 -0300 | [diff] [blame] | 96 | cam_v_op start; /* called on stream on */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 97 | cam_pkt_op pkt_scan; |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 98 | /* optional operations */ |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 99 | cam_v_op stopN; /* called on stream off - main alt */ |
| 100 | cam_v_op stop0; /* called on stream off - alt 0 */ |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 101 | cam_v_op dq_callback; /* called when a frame has been dequeued */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 102 | cam_jpg_op get_jcomp; |
| 103 | cam_jpg_op set_jcomp; |
| 104 | cam_qmnu_op querymenu; |
| 105 | }; |
| 106 | |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 107 | /* packet types when moving from iso buf to frame buf */ |
| 108 | #define DISCARD_PACKET 0 |
| 109 | #define FIRST_PACKET 1 |
| 110 | #define INTER_PACKET 2 |
| 111 | #define LAST_PACKET 3 |
| 112 | |
| 113 | struct gspca_frame { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 114 | __u8 *data; /* frame buffer */ |
| 115 | __u8 *data_end; /* end of frame while filling */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 116 | int vma_use_count; |
| 117 | struct v4l2_buffer v4l2_buf; |
| 118 | }; |
| 119 | |
| 120 | struct gspca_dev { |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 121 | struct video_device vdev; /* !! must be the first item */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 122 | struct file_operations fops; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 123 | struct usb_device *dev; |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 124 | struct file *capt_file; /* file doing video capture */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 125 | |
| 126 | struct cam cam; /* device information */ |
| 127 | const struct sd_desc *sd_desc; /* subdriver description */ |
Jean-Francois Moine | f50ba1b | 2008-09-03 17:12:14 -0300 | [diff] [blame] | 128 | unsigned ctrl_dis; /* disabled controls (bit map) */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 129 | |
Jean-Francois Moine | 8295d99 | 2008-09-03 17:12:19 -0300 | [diff] [blame] | 130 | #define USB_BUF_SZ 64 |
| 131 | __u8 *usb_buf; /* buffer for USB exchanges */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 132 | struct urb *urb[MAX_NURBS]; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 133 | |
| 134 | __u8 *frbuf; /* buffer for nframes */ |
| 135 | struct gspca_frame frame[GSPCA_MAX_FRAMES]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 136 | __u32 frsz; /* frame size */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 137 | char nframes; /* number of frames */ |
| 138 | char fr_i; /* frame being filled */ |
| 139 | char fr_q; /* next frame to queue */ |
| 140 | char fr_o; /* next frame to dequeue */ |
| 141 | signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */ |
| 142 | char last_packet_type; |
| 143 | |
| 144 | __u8 iface; /* USB interface number */ |
| 145 | __u8 alt; /* USB alternate setting */ |
Jean-Francois Moine | 0be0100 | 2008-09-04 07:01:50 -0300 | [diff] [blame] | 146 | __u8 bulk; /* image transfer by isoc (0) or bulk (1) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 147 | __u8 curr_mode; /* current camera mode */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 148 | __u32 pixfmt; /* current mode parameters */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 149 | __u16 width; |
| 150 | __u16 height; |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 151 | |
| 152 | atomic_t nevent; /* number of frames done */ |
| 153 | wait_queue_head_t wq; /* wait queue */ |
| 154 | struct mutex usb_lock; /* usb exchange protection */ |
| 155 | struct mutex read_lock; /* read protection */ |
| 156 | struct mutex queue_lock; /* ISOC queue protection */ |
| 157 | __u32 sequence; /* frame sequence number */ |
Jean-Francois Moine | 4aa0d03 | 2008-05-04 06:46:21 -0300 | [diff] [blame] | 158 | char streaming; |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 159 | #ifdef CONFIG_PM |
| 160 | char frozen; /* suspend - resume */ |
| 161 | #endif |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 162 | char users; /* number of opens */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 163 | char present; /* device connected */ |
| 164 | char nbufread; /* number of buffers for read() */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 165 | char nurbs; /* number of allocated URBs */ |
| 166 | char memory; /* memory type (V4L2_MEMORY_xxx) */ |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 167 | __u8 nbalt; /* number of USB alternate settings */ |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | int gspca_dev_probe(struct usb_interface *intf, |
| 171 | const struct usb_device_id *id, |
| 172 | const struct sd_desc *sd_desc, |
Jean-Francois Moine | d43fa32 | 2008-06-12 10:58:58 -0300 | [diff] [blame] | 173 | int dev_size, |
| 174 | struct module *module); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 175 | void gspca_disconnect(struct usb_interface *intf); |
| 176 | struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev, |
| 177 | int packet_type, |
| 178 | struct gspca_frame *frame, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 179 | const __u8 *data, |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 180 | int len); |
Jean-Francois Moine | 1b60e1a | 2008-09-20 05:44:21 -0300 | [diff] [blame^] | 181 | struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev); |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 182 | #ifdef CONFIG_PM |
| 183 | int gspca_suspend(struct usb_interface *intf, pm_message_t message); |
| 184 | int gspca_resume(struct usb_interface *intf); |
| 185 | #endif |
Hans de Goede | dcef323 | 2008-07-10 10:40:53 -0300 | [diff] [blame] | 186 | int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum, |
| 187 | int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee); |
Jean-Francois Moine | 63eb954 | 2008-04-12 09:58:09 -0300 | [diff] [blame] | 188 | #endif /* GSPCAV2_H */ |