Merge branch 'sched-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[pandora-kernel.git] / drivers / media / video / se401.h
1
2 #ifndef __LINUX_se401_H
3 #define __LINUX_se401_H
4
5 #include <asm/uaccess.h>
6 #include <linux/videodev.h>
7 #include <media/v4l2-common.h>
8 #include <linux/mutex.h>
9
10 #define se401_DEBUG     /* Turn on debug messages */
11
12 #ifdef se401_DEBUG
13 #  define PDEBUG(level, fmt, args...) \
14 if (debug >= level) info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args)
15 #else
16 #  define PDEBUG(level, fmt, args...) do {} while(0)
17 #endif
18
19 /* An almost drop-in replacement for sleep_on_interruptible */
20 #define wait_interruptible(test, queue, wait) \
21 { \
22         add_wait_queue(queue, wait); \
23         set_current_state(TASK_INTERRUPTIBLE); \
24         if (test) \
25                 schedule(); \
26         remove_wait_queue(queue, wait); \
27         set_current_state(TASK_RUNNING); \
28         if (signal_pending(current)) \
29                 break; \
30 }
31
32 #define SE401_REQ_GET_CAMERA_DESCRIPTOR         0x06
33 #define SE401_REQ_START_CONTINUOUS_CAPTURE      0x41
34 #define SE401_REQ_STOP_CONTINUOUS_CAPTURE       0x42
35 #define SE401_REQ_CAPTURE_FRAME                 0x43
36 #define SE401_REQ_GET_BRT                       0x44
37 #define SE401_REQ_SET_BRT                       0x45
38 #define SE401_REQ_GET_WIDTH                     0x4c
39 #define SE401_REQ_SET_WIDTH                     0x4d
40 #define SE401_REQ_GET_HEIGHT                    0x4e
41 #define SE401_REQ_SET_HEIGHT                    0x4f
42 #define SE401_REQ_GET_OUTPUT_MODE               0x50
43 #define SE401_REQ_SET_OUTPUT_MODE               0x51
44 #define SE401_REQ_GET_EXT_FEATURE               0x52
45 #define SE401_REQ_SET_EXT_FEATURE               0x53
46 #define SE401_REQ_CAMERA_POWER                  0x56
47 #define SE401_REQ_LED_CONTROL                   0x57
48 #define SE401_REQ_BIOS                          0xff
49
50 #define SE401_BIOS_READ                         0x07
51
52 #define SE401_FORMAT_BAYER      0x40
53
54 /* Hyundai hv7131b registers
55    7121 and 7141 should be the same (haven't really checked...) */
56 /* Mode registers: */
57 #define HV7131_REG_MODE_A               0x00
58 #define HV7131_REG_MODE_B               0x01
59 #define HV7131_REG_MODE_C               0x02
60 /* Frame registers: */
61 #define HV7131_REG_FRSU         0x10
62 #define HV7131_REG_FRSL         0x11
63 #define HV7131_REG_FCSU         0x12
64 #define HV7131_REG_FCSL         0x13
65 #define HV7131_REG_FWHU         0x14
66 #define HV7131_REG_FWHL         0x15
67 #define HV7131_REG_FWWU         0x16
68 #define HV7131_REG_FWWL         0x17
69 /* Timing registers: */
70 #define HV7131_REG_THBU         0x20
71 #define HV7131_REG_THBL         0x21
72 #define HV7131_REG_TVBU         0x22
73 #define HV7131_REG_TVBL         0x23
74 #define HV7131_REG_TITU         0x25
75 #define HV7131_REG_TITM         0x26
76 #define HV7131_REG_TITL         0x27
77 #define HV7131_REG_TMCD         0x28
78 /* Adjust Registers: */
79 #define HV7131_REG_ARLV         0x30
80 #define HV7131_REG_ARCG         0x31
81 #define HV7131_REG_AGCG         0x32
82 #define HV7131_REG_ABCG         0x33
83 #define HV7131_REG_APBV         0x34
84 #define HV7131_REG_ASLP         0x54
85 /* Offset Registers: */
86 #define HV7131_REG_OFSR         0x50
87 #define HV7131_REG_OFSG         0x51
88 #define HV7131_REG_OFSB         0x52
89 /* REset level statistics registers: */
90 #define HV7131_REG_LOREFNOH     0x57
91 #define HV7131_REG_LOREFNOL     0x58
92 #define HV7131_REG_HIREFNOH     0x59
93 #define HV7131_REG_HIREFNOL     0x5a
94
95 /* se401 registers */
96 #define SE401_OPERATINGMODE     0x2000
97
98
99 /* size of usb transfers */
100 #define SE401_PACKETSIZE        4096
101 /* number of queued bulk transfers to use, should be about 8 */
102 #define SE401_NUMSBUF           1
103 /* read the usb specs for this one :) */
104 #define SE401_VIDEO_ENDPOINT    1
105 #define SE401_BUTTON_ENDPOINT   2
106 /* number of frames supported by the v4l part */
107 #define SE401_NUMFRAMES         2
108 /* scratch buffers for passing data to the decoders */
109 #define SE401_NUMSCRATCH        32
110 /* maximum amount of data in a JangGu packet */
111 #define SE401_VLCDATALEN        1024
112 /* number of nul sized packets to receive before kicking the camera */
113 #define SE401_MAX_NULLPACKETS   4000
114 /* number of decoding errors before kicking the camera */
115 #define SE401_MAX_ERRORS        200
116
117 struct usb_device;
118
119 struct se401_sbuf {
120         unsigned char *data;
121 };
122
123 enum {
124         FRAME_UNUSED,           /* Unused (no MCAPTURE) */
125         FRAME_READY,            /* Ready to start grabbing */
126         FRAME_GRABBING,         /* In the process of being grabbed into */
127         FRAME_DONE,             /* Finished grabbing, but not been synced yet */
128         FRAME_ERROR,            /* Something bad happened while processing */
129 };
130
131 enum {
132         FMT_BAYER,
133         FMT_JANGGU,
134 };
135
136 enum {
137         BUFFER_UNUSED,
138         BUFFER_READY,
139         BUFFER_BUSY,
140         BUFFER_DONE,
141 };
142
143 struct se401_scratch {
144         unsigned char *data;
145         volatile int state;
146         int offset;
147         int length;
148 };
149
150 struct se401_frame {
151         unsigned char *data;            /* Frame buffer */
152
153         volatile int grabstate; /* State of grabbing */
154
155         unsigned char *curline;
156         int curlinepix;
157         int curpix;
158 };
159
160 struct usb_se401 {
161         struct video_device vdev;
162
163         /* Device structure */
164         struct usb_device *dev;
165
166         unsigned char iface;
167
168         char *camera_name;
169
170         int change;
171         int brightness;
172         int hue;
173         int rgain;
174         int ggain;
175         int bgain;
176         int expose_h;
177         int expose_m;
178         int expose_l;
179         int resetlevel;
180
181         int enhance;
182
183         int format;
184         int sizes;
185         int *width;
186         int *height;
187         int cwidth;             /* current width */
188         int cheight;            /* current height */
189         int palette;
190         int maxframesize;
191         int cframesize;         /* current framesize */
192
193         struct mutex lock;
194         int user;               /* user count for exclusive use */
195         int removed;            /* device disconnected */
196
197         int streaming;          /* Are we streaming video? */
198
199         char *fbuf;             /* Videodev buffer area */
200
201         struct urb *urb[SE401_NUMSBUF];
202         struct urb *inturb;
203
204         int button;
205         int buttonpressed;
206
207         int curframe;           /* Current receiving frame */
208         struct se401_frame frame[SE401_NUMFRAMES];
209         int readcount;
210         int framecount;
211         int error;
212         int dropped;
213
214         int scratch_next;
215         int scratch_use;
216         int scratch_overflow;
217         struct se401_scratch scratch[SE401_NUMSCRATCH];
218
219         /* Decoder specific data: */
220         unsigned char vlcdata[SE401_VLCDATALEN];
221         int vlcdatapos;
222         int bayeroffset;
223
224         struct se401_sbuf sbuf[SE401_NUMSBUF];
225
226         wait_queue_head_t wq;   /* Processes waiting */
227
228         int nullpackets;
229 };
230
231
232
233 #endif
234