aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/usbvideo/ultracam.c
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab@infradead.org>2006-03-25 07:05:39 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-03-25 07:29:04 -0500
commit9f6933be665ce3b049c274c99810ac754edabf19 (patch)
tree70a670d030c5d5a4175076724e4720a5b967e2bc /drivers/media/video/usbvideo/ultracam.c
parent7fa033b103bc3f5c37f934695473f63adf140dba (diff)
V4L/DVB (3599a): Move drivers/usb/media to drivers/media/video
Because of historic reasons, there are two separate directories with V4L stuff. Most drivers are located at driver/media/video. However, some code for USB Webcams were inserted under drivers/usb/media. This makes difficult for module authors to know were things should be. Also, makes Kconfig menu confusing for normal users. This patch moves all V4L content under drivers/usb/media to drivers/media/video, and fixes Kconfig/Makefile entries. Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/usbvideo/ultracam.c')
-rw-r--r--drivers/media/video/usbvideo/ultracam.c679
1 files changed, 679 insertions, 0 deletions
diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
new file mode 100644
index 00000000000..75ff755224d
--- /dev/null
+++ b/drivers/media/video/usbvideo/ultracam.c
@@ -0,0 +1,679 @@
1/*
2 * USB NB Camera driver
3 *
4 * HISTORY:
5 * 25-Dec-2002 Dmitri Removed lighting, sharpness parameters, methods.
6 */
7
8#include <linux/kernel.h>
9#include <linux/sched.h>
10#include <linux/module.h>
11#include <linux/init.h>
12
13#include "usbvideo.h"
14
15#define ULTRACAM_VENDOR_ID 0x0461
16#define ULTRACAM_PRODUCT_ID 0x0813
17
18#define MAX_CAMERAS 4 /* How many devices we allow to connect */
19
20/*
21 * This structure lives in uvd_t->user field.
22 */
23typedef struct {
24 int initialized; /* Had we already sent init sequence? */
25 int camera_model; /* What type of IBM camera we got? */
26 int has_hdr;
27} ultracam_t;
28#define ULTRACAM_T(uvd) ((ultracam_t *)((uvd)->user_data))
29
30static struct usbvideo *cams = NULL;
31
32static int debug = 0;
33
34static int flags = 0; /* FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */
35
36static const int min_canvasWidth = 8;
37static const int min_canvasHeight = 4;
38
39#define FRAMERATE_MIN 0
40#define FRAMERATE_MAX 6
41static int framerate = -1;
42
43/*
44 * Here we define several initialization variables. They may
45 * be used to automatically set color, hue, brightness and
46 * contrast to desired values. This is particularly useful in
47 * case of webcams (which have no controls and no on-screen
48 * output) and also when a client V4L software is used that
49 * does not have some of those controls. In any case it's
50 * good to have startup values as options.
51 *
52 * These values are all in [0..255] range. This simplifies
53 * operation. Note that actual values of V4L variables may
54 * be scaled up (as much as << 8). User can see that only
55 * on overlay output, however, or through a V4L client.
56 */
57static int init_brightness = 128;
58static int init_contrast = 192;
59static int init_color = 128;
60static int init_hue = 128;
61static int hue_correction = 128;
62
63module_param(debug, int, S_IRUGO | S_IWUSR);
64MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
65module_param(flags, int, 0);
66MODULE_PARM_DESC(flags,
67 "Bitfield: 0=VIDIOCSYNC, "
68 "1=B/W, "
69 "2=show hints, "
70 "3=show stats, "
71 "4=test pattern, "
72 "5=separate frames, "
73 "6=clean frames");
74module_param(framerate, int, 0);
75MODULE_PARM_DESC(framerate, "Framerate setting: 0=slowest, 6=fastest (default=2)");
76
77module_param(init_brightness, int, 0);
78MODULE_PARM_DESC(init_brightness, "Brightness preconfiguration: 0-255 (default=128)");
79module_param(init_contrast, int, 0);
80MODULE_PARM_DESC(init_contrast, "Contrast preconfiguration: 0-255 (default=192)");
81module_param(init_color, int, 0);
82MODULE_PARM_DESC(init_color, "Color preconfiguration: 0-255 (default=128)");
83module_param(init_hue, int, 0);
84MODULE_PARM_DESC(init_hue, "Hue preconfiguration: 0-255 (default=128)");
85module_param(hue_correction, int, 0);
86MODULE_PARM_DESC(hue_correction, "YUV colorspace regulation: 0-255 (default=128)");
87
88/*
89 * ultracam_ProcessIsocData()
90 *
91 * Generic routine to parse the ring queue data. It employs either
92 * ultracam_find_header() or ultracam_parse_lines() to do most
93 * of work.
94 *
95 * 02-Nov-2000 First (mostly dummy) version.
96 * 06-Nov-2000 Rewrote to dump all data into frame.
97 */
98static void ultracam_ProcessIsocData(struct uvd *uvd, struct usbvideo_frame *frame)
99{
100 int n;
101
102 assert(uvd != NULL);
103 assert(frame != NULL);
104
105 /* Try to move data from queue into frame buffer */
106 n = RingQueue_GetLength(&uvd->dp);
107 if (n > 0) {
108 int m;
109 /* See how much spare we have left */
110 m = uvd->max_frame_size - frame->seqRead_Length;
111 if (n > m)
112 n = m;
113 /* Now move that much data into frame buffer */
114 RingQueue_Dequeue(
115 &uvd->dp,
116 frame->data + frame->seqRead_Length,
117 m);
118 frame->seqRead_Length += m;
119 }
120 /* See if we filled the frame */
121 if (frame->seqRead_Length >= uvd->max_frame_size) {
122 frame->frameState = FrameState_Done;
123 uvd->curframe = -1;
124 uvd->stats.frame_num++;
125 }
126}
127
128/*
129 * ultracam_veio()
130 *
131 * History:
132 * 1/27/00 Added check for dev == NULL; this happens if camera is unplugged.
133 */
134static int ultracam_veio(
135 struct uvd *uvd,
136 unsigned char req,
137 unsigned short value,
138 unsigned short index,
139 int is_out)
140{
141 static const char proc[] = "ultracam_veio";
142 unsigned char cp[8] /* = { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef } */;
143 int i;
144
145 if (!CAMERA_IS_OPERATIONAL(uvd))
146 return 0;
147
148 if (!is_out) {
149 i = usb_control_msg(
150 uvd->dev,
151 usb_rcvctrlpipe(uvd->dev, 0),
152 req,
153 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
154 value,
155 index,
156 cp,
157 sizeof(cp),
158 1000);
159#if 1
160 info("USB => %02x%02x%02x%02x%02x%02x%02x%02x "
161 "(req=$%02x val=$%04x ind=$%04x)",
162 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
163 req, value, index);
164#endif
165 } else {
166 i = usb_control_msg(
167 uvd->dev,
168 usb_sndctrlpipe(uvd->dev, 0),
169 req,
170 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
171 value,
172 index,
173 NULL,
174 0,
175 1000);
176 }
177 if (i < 0) {
178 err("%s: ERROR=%d. Camera stopped; Reconnect or reload driver.",
179 proc, i);
180 uvd->last_error = i;
181 }
182 return i;
183}
184
185/*
186 * ultracam_calculate_fps()
187 */
188static int ultracam_calculate_fps(struct uvd *uvd)
189{
190 return 3 + framerate*4 + framerate/2;
191}
192
193/*
194 * ultracam_adjust_contrast()
195 */
196static void ultracam_adjust_contrast(struct uvd *uvd)
197{
198}
199
200/*
201 * ultracam_set_brightness()
202 *
203 * This procedure changes brightness of the picture.
204 */
205static void ultracam_set_brightness(struct uvd *uvd)
206{
207}
208
209static void ultracam_set_hue(struct uvd *uvd)
210{
211}
212
213/*
214 * ultracam_adjust_picture()
215 *
216 * This procedure gets called from V4L interface to update picture settings.
217 * Here we change brightness and contrast.
218 */
219static void ultracam_adjust_picture(struct uvd *uvd)
220{
221 ultracam_adjust_contrast(uvd);
222 ultracam_set_brightness(uvd);
223 ultracam_set_hue(uvd);
224}
225
226/*
227 * ultracam_video_stop()
228 *
229 * This code tells camera to stop streaming. The interface remains
230 * configured and bandwidth - claimed.
231 */
232static void ultracam_video_stop(struct uvd *uvd)
233{
234}
235
236/*
237 * ultracam_reinit_iso()
238 *
239 * This procedure sends couple of commands to the camera and then
240 * resets the video pipe. This sequence was observed to reinit the
241 * camera or, at least, to initiate ISO data stream.
242 */
243static void ultracam_reinit_iso(struct uvd *uvd, int do_stop)
244{
245}
246
247static void ultracam_video_start(struct uvd *uvd)
248{
249 ultracam_reinit_iso(uvd, 0);
250}
251
252static int ultracam_resetPipe(struct uvd *uvd)
253{
254 usb_clear_halt(uvd->dev, uvd->video_endp);
255 return 0;
256}
257
258static int ultracam_alternateSetting(struct uvd *uvd, int setting)
259{
260 static const char proc[] = "ultracam_alternateSetting";
261 int i;
262 i = usb_set_interface(uvd->dev, uvd->iface, setting);
263 if (i < 0) {
264 err("%s: usb_set_interface error", proc);
265 uvd->last_error = i;
266 return -EBUSY;
267 }
268 return 0;
269}
270
271/*
272 * Return negative code on failure, 0 on success.
273 */
274static int ultracam_setup_on_open(struct uvd *uvd)
275{
276 int setup_ok = 0; /* Success by default */
277 /* Send init sequence only once, it's large! */
278 if (!ULTRACAM_T(uvd)->initialized) {
279 ultracam_alternateSetting(uvd, 0x04);
280 ultracam_alternateSetting(uvd, 0x00);
281 ultracam_veio(uvd, 0x02, 0x0004, 0x000b, 1);
282 ultracam_veio(uvd, 0x02, 0x0001, 0x0005, 1);
283 ultracam_veio(uvd, 0x02, 0x8000, 0x0000, 1);
284 ultracam_veio(uvd, 0x00, 0x0000, 0x0000, 1);
285 ultracam_veio(uvd, 0x00, 0x00b0, 0x0001, 1);
286 ultracam_veio(uvd, 0x00, 0x0000, 0x0002, 1);
287 ultracam_veio(uvd, 0x00, 0x000c, 0x0003, 1);
288 ultracam_veio(uvd, 0x00, 0x000b, 0x0004, 1);
289 ultracam_veio(uvd, 0x00, 0x0000, 0x0005, 1);
290 ultracam_veio(uvd, 0x00, 0x0000, 0x0006, 1);
291 ultracam_veio(uvd, 0x00, 0x0079, 0x0007, 1);
292 ultracam_veio(uvd, 0x00, 0x003b, 0x0008, 1);
293 ultracam_veio(uvd, 0x00, 0x0002, 0x000f, 1);
294 ultracam_veio(uvd, 0x00, 0x0001, 0x0010, 1);
295 ultracam_veio(uvd, 0x00, 0x0000, 0x0011, 1);
296 ultracam_veio(uvd, 0x00, 0x0000, 0x00bf, 1);
297 ultracam_veio(uvd, 0x00, 0x0001, 0x00c0, 1);
298 ultracam_veio(uvd, 0x00, 0x0010, 0x00cb, 1);
299 ultracam_veio(uvd, 0x01, 0x00a4, 0x0001, 1);
300 ultracam_veio(uvd, 0x01, 0x0010, 0x0002, 1);
301 ultracam_veio(uvd, 0x01, 0x0066, 0x0007, 1);
302 ultracam_veio(uvd, 0x01, 0x000b, 0x0008, 1);
303 ultracam_veio(uvd, 0x01, 0x0034, 0x0009, 1);
304 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 1);
305 ultracam_veio(uvd, 0x01, 0x002e, 0x000b, 1);
306 ultracam_veio(uvd, 0x01, 0x00d6, 0x000c, 1);
307 ultracam_veio(uvd, 0x01, 0x00fc, 0x000d, 1);
308 ultracam_veio(uvd, 0x01, 0x00f1, 0x000e, 1);
309 ultracam_veio(uvd, 0x01, 0x00da, 0x000f, 1);
310 ultracam_veio(uvd, 0x01, 0x0036, 0x0010, 1);
311 ultracam_veio(uvd, 0x01, 0x000b, 0x0011, 1);
312 ultracam_veio(uvd, 0x01, 0x0001, 0x0012, 1);
313 ultracam_veio(uvd, 0x01, 0x0000, 0x0013, 1);
314 ultracam_veio(uvd, 0x01, 0x0000, 0x0014, 1);
315 ultracam_veio(uvd, 0x01, 0x0087, 0x0051, 1);
316 ultracam_veio(uvd, 0x01, 0x0040, 0x0052, 1);
317 ultracam_veio(uvd, 0x01, 0x0058, 0x0053, 1);
318 ultracam_veio(uvd, 0x01, 0x0040, 0x0054, 1);
319 ultracam_veio(uvd, 0x01, 0x0000, 0x0040, 1);
320 ultracam_veio(uvd, 0x01, 0x0010, 0x0041, 1);
321 ultracam_veio(uvd, 0x01, 0x0020, 0x0042, 1);
322 ultracam_veio(uvd, 0x01, 0x0030, 0x0043, 1);
323 ultracam_veio(uvd, 0x01, 0x0040, 0x0044, 1);
324 ultracam_veio(uvd, 0x01, 0x0050, 0x0045, 1);
325 ultracam_veio(uvd, 0x01, 0x0060, 0x0046, 1);
326 ultracam_veio(uvd, 0x01, 0x0070, 0x0047, 1);
327 ultracam_veio(uvd, 0x01, 0x0080, 0x0048, 1);
328 ultracam_veio(uvd, 0x01, 0x0090, 0x0049, 1);
329 ultracam_veio(uvd, 0x01, 0x00a0, 0x004a, 1);
330 ultracam_veio(uvd, 0x01, 0x00b0, 0x004b, 1);
331 ultracam_veio(uvd, 0x01, 0x00c0, 0x004c, 1);
332 ultracam_veio(uvd, 0x01, 0x00d0, 0x004d, 1);
333 ultracam_veio(uvd, 0x01, 0x00e0, 0x004e, 1);
334 ultracam_veio(uvd, 0x01, 0x00f0, 0x004f, 1);
335 ultracam_veio(uvd, 0x01, 0x00ff, 0x0050, 1);
336 ultracam_veio(uvd, 0x01, 0x0000, 0x0056, 1);
337 ultracam_veio(uvd, 0x00, 0x0080, 0x00c1, 1);
338 ultracam_veio(uvd, 0x00, 0x0000, 0x00c2, 1);
339 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
340 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
341 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
342 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
343 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
344 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
345 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
346 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
347 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
348 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
349 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
350 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
351 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
352 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
353 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
354 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
355 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
356 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
357 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
358 ultracam_veio(uvd, 0x00, 0x0080, 0x00c1, 1);
359 ultracam_veio(uvd, 0x00, 0x0004, 0x00c2, 1);
360 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
361 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
362 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
363 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
364 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
365 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
366 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
367 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
368 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
369 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
370 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
371 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
372 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
373 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
374 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
375 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
376 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
377 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
378 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
379 ultracam_veio(uvd, 0x00, 0x0002, 0x00c1, 1);
380 ultracam_veio(uvd, 0x00, 0x0020, 0x00c2, 1);
381 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
382 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
383 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
384 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
385 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
386 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
387 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
388 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
389 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
390 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
391 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
392 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
393 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
394 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
395 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
396 ultracam_veio(uvd, 0x00, 0x0040, 0x00c1, 1);
397 ultracam_veio(uvd, 0x00, 0x0017, 0x00c2, 1);
398 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
399 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
400 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
401 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
402 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
403 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
404 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
405 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
406 ultracam_veio(uvd, 0x00, 0x0000, 0x00c3, 1);
407 ultracam_veio(uvd, 0x00, 0x0000, 0x00c4, 1);
408 ultracam_veio(uvd, 0x00, 0x0000, 0x00c5, 1);
409 ultracam_veio(uvd, 0x00, 0x0000, 0x00c6, 1);
410 ultracam_veio(uvd, 0x00, 0x0000, 0x00c7, 1);
411 ultracam_veio(uvd, 0x00, 0x0000, 0x00c8, 1);
412 ultracam_veio(uvd, 0x00, 0x0000, 0x00c9, 1);
413 ultracam_veio(uvd, 0x00, 0x00c0, 0x00c1, 1);
414 ultracam_veio(uvd, 0x00, 0x0000, 0x00c2, 1);
415 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
416 ultracam_veio(uvd, 0x02, 0xc040, 0x0001, 1);
417 ultracam_veio(uvd, 0x01, 0x0000, 0x0008, 0);
418 ultracam_veio(uvd, 0x01, 0x0000, 0x0009, 0);
419 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 0);
420 ultracam_veio(uvd, 0x01, 0x0000, 0x000b, 0);
421 ultracam_veio(uvd, 0x01, 0x0000, 0x000c, 0);
422 ultracam_veio(uvd, 0x01, 0x0000, 0x000d, 0);
423 ultracam_veio(uvd, 0x01, 0x0000, 0x000e, 0);
424 ultracam_veio(uvd, 0x01, 0x0000, 0x000f, 0);
425 ultracam_veio(uvd, 0x01, 0x0000, 0x0010, 0);
426 ultracam_veio(uvd, 0x01, 0x000b, 0x0008, 1);
427 ultracam_veio(uvd, 0x01, 0x0034, 0x0009, 1);
428 ultracam_veio(uvd, 0x01, 0x0000, 0x000a, 1);
429 ultracam_veio(uvd, 0x01, 0x002e, 0x000b, 1);
430 ultracam_veio(uvd, 0x01, 0x00d6, 0x000c, 1);
431 ultracam_veio(uvd, 0x01, 0x00fc, 0x000d, 1);
432 ultracam_veio(uvd, 0x01, 0x00f1, 0x000e, 1);
433 ultracam_veio(uvd, 0x01, 0x00da, 0x000f, 1);
434 ultracam_veio(uvd, 0x01, 0x0036, 0x0010, 1);
435 ultracam_veio(uvd, 0x01, 0x0000, 0x0001, 0);
436 ultracam_veio(uvd, 0x01, 0x0064, 0x0001, 1);
437 ultracam_veio(uvd, 0x01, 0x0059, 0x0051, 1);
438 ultracam_veio(uvd, 0x01, 0x003f, 0x0052, 1);
439 ultracam_veio(uvd, 0x01, 0x0094, 0x0053, 1);
440 ultracam_veio(uvd, 0x01, 0x00ff, 0x0011, 1);
441 ultracam_veio(uvd, 0x01, 0x0003, 0x0012, 1);
442 ultracam_veio(uvd, 0x01, 0x00f7, 0x0013, 1);
443 ultracam_veio(uvd, 0x00, 0x0009, 0x0011, 1);
444 ultracam_veio(uvd, 0x00, 0x0000, 0x0001, 1);
445 ultracam_veio(uvd, 0x00, 0x0000, 0x0000, 1);
446 ultracam_veio(uvd, 0x00, 0x0020, 0x00c1, 1);
447 ultracam_veio(uvd, 0x00, 0x0010, 0x00c2, 1);
448 ultracam_veio(uvd, 0x00, 0x0000, 0x00ca, 1);
449 ultracam_alternateSetting(uvd, 0x04);
450 ultracam_veio(uvd, 0x02, 0x0000, 0x0001, 1);
451 ultracam_veio(uvd, 0x02, 0x0000, 0x0001, 1);
452 ultracam_veio(uvd, 0x02, 0x0000, 0x0006, 1);
453 ultracam_veio(uvd, 0x02, 0x9000, 0x0007, 1);
454 ultracam_veio(uvd, 0x02, 0x0042, 0x0001, 1);
455 ultracam_veio(uvd, 0x02, 0x0000, 0x000b, 0);
456 ultracam_resetPipe(uvd);
457 ULTRACAM_T(uvd)->initialized = (setup_ok != 0);
458 }
459 return setup_ok;
460}
461
462static void ultracam_configure_video(struct uvd *uvd)
463{
464 if (uvd == NULL)
465 return;
466
467 RESTRICT_TO_RANGE(init_brightness, 0, 255);
468 RESTRICT_TO_RANGE(init_contrast, 0, 255);
469 RESTRICT_TO_RANGE(init_color, 0, 255);
470 RESTRICT_TO_RANGE(init_hue, 0, 255);
471 RESTRICT_TO_RANGE(hue_correction, 0, 255);
472
473 memset(&uvd->vpic, 0, sizeof(uvd->vpic));
474 memset(&uvd->vpic_old, 0x55, sizeof(uvd->vpic_old));
475
476 uvd->vpic.colour = init_color << 8;
477 uvd->vpic.hue = init_hue << 8;
478 uvd->vpic.brightness = init_brightness << 8;
479 uvd->vpic.contrast = init_contrast << 8;
480 uvd->vpic.whiteness = 105 << 8; /* This one isn't used */
481 uvd->vpic.depth = 24;
482 uvd->vpic.palette = VIDEO_PALETTE_RGB24;
483
484 memset(&uvd->vcap, 0, sizeof(uvd->vcap));
485 strcpy(uvd->vcap.name, "IBM Ultra Camera");
486 uvd->vcap.type = VID_TYPE_CAPTURE;
487 uvd->vcap.channels = 1;
488 uvd->vcap.audios = 0;
489 uvd->vcap.maxwidth = VIDEOSIZE_X(uvd->canvas);
490 uvd->vcap.maxheight = VIDEOSIZE_Y(uvd->canvas);
491 uvd->vcap.minwidth = min_canvasWidth;
492 uvd->vcap.minheight = min_canvasHeight;
493
494 memset(&uvd->vchan, 0, sizeof(uvd->vchan));
495 uvd->vchan.flags = 0;
496 uvd->vchan.tuners = 0;
497 uvd->vchan.channel = 0;
498 uvd->vchan.type = VIDEO_TYPE_CAMERA;
499 strcpy(uvd->vchan.name, "Camera");
500}
501
502/*
503 * ultracam_probe()
504 *
505 * This procedure queries device descriptor and accepts the interface
506 * if it looks like our camera.
507 *
508 * History:
509 * 12-Nov-2000 Reworked to comply with new probe() signature.
510 * 23-Jan-2001 Added compatibility with 2.2.x kernels.
511 */
512static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id *devid)
513{
514 struct usb_device *dev = interface_to_usbdev(intf);
515 struct uvd *uvd = NULL;
516 int ix, i, nas;
517 int actInterface=-1, inactInterface=-1, maxPS=0;
518 unsigned char video_ep = 0;
519
520 if (debug >= 1)
521 info("ultracam_probe(%p)", intf);
522
523 /* We don't handle multi-config cameras */
524 if (dev->descriptor.bNumConfigurations != 1)
525 return -ENODEV;
526
527 info("IBM Ultra camera found (rev. 0x%04x)",
528 le16_to_cpu(dev->descriptor.bcdDevice));
529
530 /* Validate found interface: must have one ISO endpoint */
531 nas = intf->num_altsetting;
532 if (debug > 0)
533 info("Number of alternate settings=%d.", nas);
534 if (nas < 8) {
535 err("Too few alternate settings for this camera!");
536 return -ENODEV;
537 }
538 /* Validate all alternate settings */
539 for (ix=0; ix < nas; ix++) {
540 const struct usb_host_interface *interface;
541 const struct usb_endpoint_descriptor *endpoint;
542
543 interface = &intf->altsetting[ix];
544 i = interface->desc.bAlternateSetting;
545 if (interface->desc.bNumEndpoints != 1) {
546 err("Interface %d. has %u. endpoints!",
547 interface->desc.bInterfaceNumber,
548 (unsigned)(interface->desc.bNumEndpoints));
549 return -ENODEV;
550 }
551 endpoint = &interface->endpoint[0].desc;
552 if (video_ep == 0)
553 video_ep = endpoint->bEndpointAddress;
554 else if (video_ep != endpoint->bEndpointAddress) {
555 err("Alternate settings have different endpoint addresses!");
556 return -ENODEV;
557 }
558 if ((endpoint->bmAttributes & 0x03) != 0x01) {
559 err("Interface %d. has non-ISO endpoint!",
560 interface->desc.bInterfaceNumber);
561 return -ENODEV;
562 }
563 if ((endpoint->bEndpointAddress & 0x80) == 0) {
564 err("Interface %d. has ISO OUT endpoint!",
565 interface->desc.bInterfaceNumber);
566 return -ENODEV;
567 }
568 if (le16_to_cpu(endpoint->wMaxPacketSize) == 0) {
569 if (inactInterface < 0)
570 inactInterface = i;
571 else {
572 err("More than one inactive alt. setting!");
573 return -ENODEV;
574 }
575 } else {
576 if (actInterface < 0) {
577 actInterface = i;
578 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
579 if (debug > 0)
580 info("Active setting=%d. maxPS=%d.", i, maxPS);
581 } else {
582 /* Got another active alt. setting */
583 if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) {
584 /* This one is better! */
585 actInterface = i;
586 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
587 if (debug > 0) {
588 info("Even better ctive setting=%d. maxPS=%d.",
589 i, maxPS);
590 }
591 }
592 }
593 }
594 }
595 if ((maxPS <= 0) || (actInterface < 0) || (inactInterface < 0)) {
596 err("Failed to recognize the camera!");
597 return -ENODEV;
598 }
599
600 uvd = usbvideo_AllocateDevice(cams);
601 if (uvd != NULL) {
602 /* Here uvd is a fully allocated uvd object */
603 uvd->flags = flags;
604 uvd->debug = debug;
605 uvd->dev = dev;
606 uvd->iface = intf->altsetting->desc.bInterfaceNumber;
607 uvd->ifaceAltInactive = inactInterface;
608 uvd->ifaceAltActive = actInterface;
609 uvd->video_endp = video_ep;
610 uvd->iso_packet_len = maxPS;
611 uvd->paletteBits = 1L << VIDEO_PALETTE_RGB24;
612 uvd->defaultPalette = VIDEO_PALETTE_RGB24;
613 uvd->canvas = VIDEOSIZE(640, 480); /* FIXME */
614 uvd->videosize = uvd->canvas; /* ultracam_size_to_videosize(size);*/
615
616 /* Initialize ibmcam-specific data */
617 assert(ULTRACAM_T(uvd) != NULL);
618 ULTRACAM_T(uvd)->camera_model = 0; /* Not used yet */
619 ULTRACAM_T(uvd)->initialized = 0;
620
621 ultracam_configure_video(uvd);
622
623 i = usbvideo_RegisterVideoDevice(uvd);
624 if (i != 0) {
625 err("usbvideo_RegisterVideoDevice() failed.");
626 uvd = NULL;
627 }
628 }
629
630 if (uvd) {
631 usb_set_intfdata (intf, uvd);
632 return 0;
633 }
634 return -EIO;
635}
636
637
638static struct usb_device_id id_table[] = {
639 { USB_DEVICE(ULTRACAM_VENDOR_ID, ULTRACAM_PRODUCT_ID) },
640 { } /* Terminating entry */
641};
642
643/*
644 * ultracam_init()
645 *
646 * This code is run to initialize the driver.
647 */
648static int __init ultracam_init(void)
649{
650 struct usbvideo_cb cbTbl;
651 memset(&cbTbl, 0, sizeof(cbTbl));
652 cbTbl.probe = ultracam_probe;
653 cbTbl.setupOnOpen = ultracam_setup_on_open;
654 cbTbl.videoStart = ultracam_video_start;
655 cbTbl.videoStop = ultracam_video_stop;
656 cbTbl.processData = ultracam_ProcessIsocData;
657 cbTbl.postProcess = usbvideo_DeinterlaceFrame;
658 cbTbl.adjustPicture = ultracam_adjust_picture;
659 cbTbl.getFPS = ultracam_calculate_fps;
660 return usbvideo_register(
661 &cams,
662 MAX_CAMERAS,
663 sizeof(ultracam_t),
664 "ultracam",
665 &cbTbl,
666 THIS_MODULE,
667 id_table);
668}
669
670static void __exit ultracam_cleanup(void)
671{
672 usbvideo_Deregister(&cams);
673}
674
675MODULE_DEVICE_TABLE(usb, id_table);
676MODULE_LICENSE("GPL");
677
678module_init(ultracam_init);
679module_exit(ultracam_cleanup);