Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * |
| 3 | * Filename: stv680.h |
| 4 | * |
| 5 | * Description: |
| 6 | * This is a USB driver for STV0680 based usb video cameras. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | |
| 24 | /* size of usb transfers */ |
| 25 | #define STV680_PACKETSIZE 4096 |
| 26 | |
| 27 | /* number of queued bulk transfers to use, may have problems if > 1 */ |
| 28 | #define STV680_NUMSBUF 1 |
| 29 | |
| 30 | /* number of frames supported by the v4l part */ |
| 31 | #define STV680_NUMFRAMES 2 |
| 32 | |
| 33 | /* scratch buffers for passing data to the decoders: 2 or 4 are good */ |
| 34 | #define STV680_NUMSCRATCH 2 |
| 35 | |
| 36 | /* number of nul sized packets to receive before kicking the camera */ |
| 37 | #define STV680_MAX_NULLPACKETS 200 |
| 38 | |
| 39 | /* number of decoding errors before kicking the camera */ |
| 40 | #define STV680_MAX_ERRORS 100 |
| 41 | |
| 42 | #define USB_PENCAM_VENDOR_ID 0x0553 |
| 43 | #define USB_PENCAM_PRODUCT_ID 0x0202 |
Kiril Jovchev | 1636787 | 2005-06-05 01:52:33 +0300 | [diff] [blame] | 44 | |
| 45 | #define USB_CREATIVEGOMINI_VENDOR_ID 0x041e |
| 46 | #define USB_CREATIVEGOMINI_PRODUCT_ID 0x4007 |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define PENCAM_TIMEOUT 1000 |
| 49 | /* fmt 4 */ |
| 50 | #define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24 |
| 51 | |
| 52 | static struct usb_device_id device_table[] = { |
| 53 | {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)}, |
Kiril Jovchev | 1636787 | 2005-06-05 01:52:33 +0300 | [diff] [blame] | 54 | {USB_DEVICE (USB_CREATIVEGOMINI_VENDOR_ID, USB_CREATIVEGOMINI_PRODUCT_ID)}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | {} |
| 56 | }; |
| 57 | MODULE_DEVICE_TABLE (usb, device_table); |
| 58 | |
| 59 | struct stv680_sbuf { |
| 60 | unsigned char *data; |
| 61 | }; |
| 62 | |
| 63 | enum { |
| 64 | FRAME_UNUSED, /* Unused (no MCAPTURE) */ |
| 65 | FRAME_READY, /* Ready to start grabbing */ |
| 66 | FRAME_GRABBING, /* In the process of being grabbed into */ |
| 67 | FRAME_DONE, /* Finished grabbing, but not been synced yet */ |
| 68 | FRAME_ERROR, /* Something bad happened while processing */ |
| 69 | }; |
| 70 | |
| 71 | enum { |
| 72 | BUFFER_UNUSED, |
| 73 | BUFFER_READY, |
| 74 | BUFFER_BUSY, |
| 75 | BUFFER_DONE, |
| 76 | }; |
| 77 | |
| 78 | /* raw camera data <- sbuf (urb transfer buf) */ |
| 79 | struct stv680_scratch { |
| 80 | unsigned char *data; |
| 81 | volatile int state; |
| 82 | int offset; |
| 83 | int length; |
| 84 | }; |
| 85 | |
| 86 | /* processed data for display ends up here, after bayer */ |
| 87 | struct stv680_frame { |
| 88 | unsigned char *data; /* Frame buffer */ |
| 89 | volatile int grabstate; /* State of grabbing */ |
| 90 | unsigned char *curline; |
| 91 | int curlinepix; |
| 92 | int curpix; |
| 93 | }; |
| 94 | |
| 95 | /* this is almost the video structure uvd_t, with extra parameters for stv */ |
| 96 | struct usb_stv { |
| 97 | struct video_device *vdev; |
| 98 | |
| 99 | struct usb_device *udev; |
| 100 | |
| 101 | unsigned char bulk_in_endpointAddr; /* __u8 the address of the bulk in endpoint */ |
| 102 | char *camera_name; |
| 103 | |
| 104 | unsigned int VideoMode; /* 0x0100 = VGA, 0x0000 = CIF, 0x0300 = QVGA */ |
| 105 | int SupportedModes; |
| 106 | int CIF; |
| 107 | int VGA; |
| 108 | int QVGA; |
| 109 | int cwidth; /* camera width */ |
| 110 | int cheight; /* camera height */ |
| 111 | int maxwidth; /* max video width */ |
| 112 | int maxheight; /* max video height */ |
| 113 | int vwidth; /* current width for video window */ |
| 114 | int vheight; /* current height for video window */ |
| 115 | unsigned long int rawbufsize; |
| 116 | unsigned long int maxframesize; /* rawbufsize * 3 for RGB */ |
| 117 | |
| 118 | int origGain; |
| 119 | int origMode; /* original camera mode */ |
| 120 | |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 121 | struct mutex lock; /* to lock the structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int user; /* user count for exclusive use */ |
| 123 | int removed; /* device disconnected */ |
| 124 | int streaming; /* Are we streaming video? */ |
| 125 | char *fbuf; /* Videodev buffer area */ |
| 126 | struct urb *urb[STV680_NUMSBUF]; /* # of queued bulk transfers */ |
| 127 | int curframe; /* Current receiving frame */ |
| 128 | struct stv680_frame frame[STV680_NUMFRAMES]; /* # frames supported by v4l part */ |
| 129 | int readcount; |
| 130 | int framecount; |
| 131 | int error; |
| 132 | int dropped; |
| 133 | int scratch_next; |
| 134 | int scratch_use; |
| 135 | int scratch_overflow; |
| 136 | struct stv680_scratch scratch[STV680_NUMSCRATCH]; /* for decoders */ |
| 137 | struct stv680_sbuf sbuf[STV680_NUMSBUF]; |
| 138 | |
| 139 | unsigned int brightness; |
| 140 | unsigned int chgbright; |
| 141 | unsigned int whiteness; |
| 142 | unsigned int colour; |
| 143 | unsigned int contrast; |
| 144 | unsigned int hue; |
| 145 | unsigned int palette; |
| 146 | unsigned int depth; /* rgb24 in bits */ |
| 147 | |
| 148 | wait_queue_head_t wq; /* Processes waiting */ |
| 149 | |
| 150 | int nullpackets; |
| 151 | }; |
| 152 | |
| 153 | |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 154 | static const unsigned char red[256] = { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 155 | 0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, |
| 156 | 18, 18, 18, 18, 18, 18, 18, 25, 30, 35, 38, 42, |
| 157 | 44, 47, 50, 53, 54, 57, 59, 61, 63, 65, 67, 69, |
| 158 | 71, 71, 73, 75, 77, 78, 80, 81, 82, 84, 85, 87, |
| 159 | 88, 89, 90, 91, 93, 94, 95, 97, 98, 98, 99, 101, |
| 160 | 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, |
| 161 | 114, 115, 116, 116, 117, 118, 119, 120, 121, 122, 123, 124, |
| 162 | 125, 125, 126, 127, 128, 129, 129, 130, 131, 132, 133, 134, |
| 163 | 134, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, |
| 164 | 143, 143, 144, 145, 146, 147, 147, 148, 149, 150, 150, 151, |
| 165 | 152, 152, 152, 153, 154, 154, 155, 156, 157, 157, 158, 159, |
| 166 | 159, 160, 161, 161, 161, 162, 163, 163, 164, 165, 165, 166, |
| 167 | 167, 167, 168, 168, 169, 170, 170, 170, 171, 171, 172, 173, |
| 168 | 173, 174, 174, 175, 176, 176, 177, 178, 178, 179, 179, 179, |
| 169 | 180, 180, 181, 181, 182, 183, 183, 184, 184, 185, 185, 186, |
| 170 | 187, 187, 188, 188, 188, 188, 189, 190, 190, 191, 191, 192, |
| 171 | 192, 193, 193, 194, 195, 195, 196, 196, 197, 197, 197, 197, |
| 172 | 198, 198, 199, 199, 200, 201, 201, 202, 202, 203, 203, 204, |
| 173 | 204, 205, 205, 206, 206, 206, 206, 207, 207, 208, 208, 209, |
| 174 | 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215, |
| 175 | 215, 215, 215, 216, 216, 217, 217, 218, 218, 218, 219, 219, |
| 176 | 220, 220, 221, 221 |
| 177 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 179 | static const unsigned char green[256] = { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 180 | 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, |
| 181 | 21, 21, 21, 21, 21, 21, 21, 28, 34, 39, 43, 47, |
| 182 | 50, 53, 56, 59, 61, 64, 66, 68, 71, 73, 75, 77, |
| 183 | 79, 80, 82, 84, 86, 87, 89, 91, 92, 94, 95, 97, |
| 184 | 98, 100, 101, 102, 104, 105, 106, 108, 109, 110, 111, 113, |
| 185 | 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, |
| 186 | 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, |
| 187 | 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, |
| 188 | 150, 151, 151, 152, 153, 154, 155, 156, 156, 157, 158, 159, |
| 189 | 160, 160, 161, 162, 163, 164, 164, 165, 166, 167, 167, 168, |
| 190 | 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, |
| 191 | 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185, |
| 192 | 186, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, |
| 193 | 193, 194, 194, 195, 196, 196, 197, 198, 198, 199, 199, 200, |
| 194 | 201, 201, 202, 202, 203, 204, 204, 205, 205, 206, 206, 207, |
| 195 | 208, 208, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214, |
| 196 | 214, 215, 215, 216, 217, 217, 218, 218, 219, 219, 220, 220, |
| 197 | 221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227, |
| 198 | 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233, |
| 199 | 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239, |
| 200 | 239, 240, 240, 241, 241, 242, 242, 243, 243, 243, 244, 244, |
| 201 | 245, 245, 246, 246 |
| 202 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Arjan van de Ven | 4c4c943 | 2005-11-29 09:43:42 +0100 | [diff] [blame] | 204 | static const unsigned char blue[256] = { |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 205 | 0, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, |
| 206 | 23, 23, 23, 23, 23, 23, 23, 30, 37, 42, 47, 51, |
| 207 | 55, 58, 61, 64, 67, 70, 72, 74, 78, 80, 82, 84, |
| 208 | 86, 88, 90, 92, 94, 95, 97, 100, 101, 103, 104, 106, |
| 209 | 107, 110, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, |
| 210 | 125, 126, 127, 128, 129, 132, 133, 134, 135, 136, 137, 138, |
| 211 | 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, |
| 212 | 152, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, |
| 213 | 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, |
| 214 | 176, 176, 177, 178, 179, 180, 180, 181, 182, 183, 183, 184, |
| 215 | 185, 187, 187, 188, 189, 189, 190, 191, 192, 192, 193, 194, |
| 216 | 194, 195, 196, 196, 198, 199, 200, 200, 201, 202, 202, 203, |
| 217 | 204, 204, 205, 205, 206, 207, 207, 209, 210, 210, 211, 212, |
| 218 | 212, 213, 213, 214, 215, 215, 216, 217, 217, 218, 218, 220, |
| 219 | 221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227, |
| 220 | 228, 228, 229, 229, 231, 231, 232, 233, 233, 234, 234, 235, |
| 221 | 235, 236, 236, 237, 238, 238, 239, 239, 240, 240, 242, 242, |
| 222 | 243, 243, 244, 244, 245, 246, 246, 247, 247, 248, 248, 249, |
| 223 | 249, 250, 250, 251, 251, 253, 253, 254, 254, 255, 255, 255, |
| 224 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 225 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, |
| 226 | 255, 255, 255, 255 |
| 227 | }; |