diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2010-03-22 03:33:56 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-05-17 23:51:26 -0400 |
commit | 51224aa436238940e09e479db9c600cecfbebd20 (patch) | |
tree | 4ca4f85b6650b2da0db35a8256974d135b2048a3 /drivers/media/video | |
parent | 380de498e264cca27d19deafe4dc44f624820d09 (diff) |
V4L/DVB: c-qcam: coding style cleanup
Clean up the coding style before we convert this driver to V4L2.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video')
-rw-r--r-- | drivers/media/video/c-qcam.c | 483 |
1 files changed, 237 insertions, 246 deletions
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c index e2cbebab959b..8f1dd88b32a6 100644 --- a/drivers/media/video/c-qcam.c +++ b/drivers/media/video/c-qcam.c | |||
@@ -79,17 +79,17 @@ static inline void qcam_set_ack(struct qcam_device *qcam, unsigned int i) | |||
79 | { | 79 | { |
80 | /* note: the QC specs refer to the PCAck pin by voltage, not | 80 | /* note: the QC specs refer to the PCAck pin by voltage, not |
81 | software level. PC ports have builtin inverters. */ | 81 | software level. PC ports have builtin inverters. */ |
82 | parport_frob_control(qcam->pport, 8, i?8:0); | 82 | parport_frob_control(qcam->pport, 8, i ? 8 : 0); |
83 | } | 83 | } |
84 | 84 | ||
85 | static inline unsigned int qcam_ready1(struct qcam_device *qcam) | 85 | static inline unsigned int qcam_ready1(struct qcam_device *qcam) |
86 | { | 86 | { |
87 | return (parport_read_status(qcam->pport) & 0x8)?1:0; | 87 | return (parport_read_status(qcam->pport) & 0x8) ? 1 : 0; |
88 | } | 88 | } |
89 | 89 | ||
90 | static inline unsigned int qcam_ready2(struct qcam_device *qcam) | 90 | static inline unsigned int qcam_ready2(struct qcam_device *qcam) |
91 | { | 91 | { |
92 | return (parport_read_data(qcam->pport) & 0x1)?1:0; | 92 | return (parport_read_data(qcam->pport) & 0x1) ? 1 : 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | static unsigned int qcam_await_ready1(struct qcam_device *qcam, | 95 | static unsigned int qcam_await_ready1(struct qcam_device *qcam, |
@@ -99,14 +99,13 @@ static unsigned int qcam_await_ready1(struct qcam_device *qcam, | |||
99 | unsigned int i; | 99 | unsigned int i; |
100 | 100 | ||
101 | for (oldjiffies = jiffies; | 101 | for (oldjiffies = jiffies; |
102 | time_before(jiffies, oldjiffies + msecs_to_jiffies(40)); ) | 102 | time_before(jiffies, oldjiffies + msecs_to_jiffies(40));) |
103 | if (qcam_ready1(qcam) == value) | 103 | if (qcam_ready1(qcam) == value) |
104 | return 0; | 104 | return 0; |
105 | 105 | ||
106 | /* If the camera didn't respond within 1/25 second, poll slowly | 106 | /* If the camera didn't respond within 1/25 second, poll slowly |
107 | for a while. */ | 107 | for a while. */ |
108 | for (i = 0; i < 50; i++) | 108 | for (i = 0; i < 50; i++) { |
109 | { | ||
110 | if (qcam_ready1(qcam) == value) | 109 | if (qcam_ready1(qcam) == value) |
111 | return 0; | 110 | return 0; |
112 | msleep_interruptible(100); | 111 | msleep_interruptible(100); |
@@ -125,14 +124,13 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value) | |||
125 | unsigned int i; | 124 | unsigned int i; |
126 | 125 | ||
127 | for (oldjiffies = jiffies; | 126 | for (oldjiffies = jiffies; |
128 | time_before(jiffies, oldjiffies + msecs_to_jiffies(40)); ) | 127 | time_before(jiffies, oldjiffies + msecs_to_jiffies(40));) |
129 | if (qcam_ready2(qcam) == value) | 128 | if (qcam_ready2(qcam) == value) |
130 | return 0; | 129 | return 0; |
131 | 130 | ||
132 | /* If the camera didn't respond within 1/25 second, poll slowly | 131 | /* If the camera didn't respond within 1/25 second, poll slowly |
133 | for a while. */ | 132 | for a while. */ |
134 | for (i = 0; i < 50; i++) | 133 | for (i = 0; i < 50; i++) { |
135 | { | ||
136 | if (qcam_ready2(qcam) == value) | 134 | if (qcam_ready2(qcam) == value) |
137 | return 0; | 135 | return 0; |
138 | msleep_interruptible(100); | 136 | msleep_interruptible(100); |
@@ -149,22 +147,25 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value) | |||
149 | static int qcam_read_data(struct qcam_device *qcam) | 147 | static int qcam_read_data(struct qcam_device *qcam) |
150 | { | 148 | { |
151 | unsigned int idata; | 149 | unsigned int idata; |
150 | |||
152 | qcam_set_ack(qcam, 0); | 151 | qcam_set_ack(qcam, 0); |
153 | if (qcam_await_ready1(qcam, 1)) return -1; | 152 | if (qcam_await_ready1(qcam, 1)) |
153 | return -1; | ||
154 | idata = parport_read_status(qcam->pport) & 0xf0; | 154 | idata = parport_read_status(qcam->pport) & 0xf0; |
155 | qcam_set_ack(qcam, 1); | 155 | qcam_set_ack(qcam, 1); |
156 | if (qcam_await_ready1(qcam, 0)) return -1; | 156 | if (qcam_await_ready1(qcam, 0)) |
157 | idata |= (parport_read_status(qcam->pport) >> 4); | 157 | return -1; |
158 | idata |= parport_read_status(qcam->pport) >> 4; | ||
158 | return idata; | 159 | return idata; |
159 | } | 160 | } |
160 | 161 | ||
161 | static int qcam_write_data(struct qcam_device *qcam, unsigned int data) | 162 | static int qcam_write_data(struct qcam_device *qcam, unsigned int data) |
162 | { | 163 | { |
163 | unsigned int idata; | 164 | unsigned int idata; |
165 | |||
164 | parport_write_data(qcam->pport, data); | 166 | parport_write_data(qcam->pport, data); |
165 | idata = qcam_read_data(qcam); | 167 | idata = qcam_read_data(qcam); |
166 | if (data != idata) | 168 | if (data != idata) { |
167 | { | ||
168 | printk(KERN_WARNING "cqcam: sent %x but received %x\n", data, | 169 | printk(KERN_WARNING "cqcam: sent %x but received %x\n", data, |
169 | idata); | 170 | idata); |
170 | return 1; | 171 | return 1; |
@@ -212,13 +213,12 @@ static int qc_detect(struct qcam_device *qcam) | |||
212 | 213 | ||
213 | /* look for a heartbeat */ | 214 | /* look for a heartbeat */ |
214 | ostat = stat = parport_read_status(qcam->pport); | 215 | ostat = stat = parport_read_status(qcam->pport); |
215 | for (i=0; i<250; i++) | 216 | for (i = 0; i < 250; i++) { |
216 | { | ||
217 | mdelay(1); | 217 | mdelay(1); |
218 | stat = parport_read_status(qcam->pport); | 218 | stat = parport_read_status(qcam->pport); |
219 | if (ostat != stat) | 219 | if (ostat != stat) { |
220 | { | 220 | if (++count >= 3) |
221 | if (++count >= 3) return 1; | 221 | return 1; |
222 | ostat = stat; | 222 | ostat = stat; |
223 | } | 223 | } |
224 | } | 224 | } |
@@ -232,13 +232,12 @@ static int qc_detect(struct qcam_device *qcam) | |||
232 | count = 0; | 232 | count = 0; |
233 | 233 | ||
234 | ostat = stat = parport_read_status(qcam->pport); | 234 | ostat = stat = parport_read_status(qcam->pport); |
235 | for (i=0; i<250; i++) | 235 | for (i = 0; i < 250; i++) { |
236 | { | ||
237 | mdelay(1); | 236 | mdelay(1); |
238 | stat = parport_read_status(qcam->pport); | 237 | stat = parport_read_status(qcam->pport); |
239 | if (ostat != stat) | 238 | if (ostat != stat) { |
240 | { | 239 | if (++count >= 3) |
241 | if (++count >= 3) return 1; | 240 | return 1; |
242 | ostat = stat; | 241 | ostat = stat; |
243 | } | 242 | } |
244 | } | 243 | } |
@@ -263,7 +262,7 @@ static void qc_setup(struct qcam_device *q) | |||
263 | { | 262 | { |
264 | qc_reset(q); | 263 | qc_reset(q); |
265 | 264 | ||
266 | /* Set the brightness. */ | 265 | /* Set the brightness. */ |
267 | qcam_set(q, 11, q->brightness); | 266 | qcam_set(q, 11, q->brightness); |
268 | 267 | ||
269 | /* Set the height and width. These refer to the actual | 268 | /* Set the height and width. These refer to the actual |
@@ -292,25 +291,25 @@ static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, u | |||
292 | unsigned int bytes = 0; | 291 | unsigned int bytes = 0; |
293 | 292 | ||
294 | qcam_set_ack(q, 0); | 293 | qcam_set_ack(q, 0); |
295 | if (q->bidirectional) | 294 | if (q->bidirectional) { |
296 | { | ||
297 | /* It's a bidirectional port */ | 295 | /* It's a bidirectional port */ |
298 | while (bytes < nbytes) | 296 | while (bytes < nbytes) { |
299 | { | ||
300 | unsigned int lo1, hi1, lo2, hi2; | 297 | unsigned int lo1, hi1, lo2, hi2; |
301 | unsigned char r, g, b; | 298 | unsigned char r, g, b; |
302 | 299 | ||
303 | if (qcam_await_ready2(q, 1)) return bytes; | 300 | if (qcam_await_ready2(q, 1)) |
301 | return bytes; | ||
304 | lo1 = parport_read_data(q->pport) >> 1; | 302 | lo1 = parport_read_data(q->pport) >> 1; |
305 | hi1 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10; | 303 | hi1 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10; |
306 | qcam_set_ack(q, 1); | 304 | qcam_set_ack(q, 1); |
307 | if (qcam_await_ready2(q, 0)) return bytes; | 305 | if (qcam_await_ready2(q, 0)) |
306 | return bytes; | ||
308 | lo2 = parport_read_data(q->pport) >> 1; | 307 | lo2 = parport_read_data(q->pport) >> 1; |
309 | hi2 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10; | 308 | hi2 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10; |
310 | qcam_set_ack(q, 0); | 309 | qcam_set_ack(q, 0); |
311 | r = (lo1 | ((hi1 & 1)<<7)); | 310 | r = lo1 | ((hi1 & 1) << 7); |
312 | g = ((hi1 & 0x1e)<<3) | ((hi2 & 0x1e)>>1); | 311 | g = ((hi1 & 0x1e) << 3) | ((hi2 & 0x1e) >> 1); |
313 | b = (lo2 | ((hi2 & 1)<<7)); | 312 | b = lo2 | ((hi2 & 1) << 7); |
314 | if (force_rgb) { | 313 | if (force_rgb) { |
315 | buf[bytes++] = r; | 314 | buf[bytes++] = r; |
316 | buf[bytes++] = g; | 315 | buf[bytes++] = g; |
@@ -321,21 +320,20 @@ static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, u | |||
321 | buf[bytes++] = r; | 320 | buf[bytes++] = r; |
322 | } | 321 | } |
323 | } | 322 | } |
324 | } | 323 | } else { |
325 | else | ||
326 | { | ||
327 | /* It's a unidirectional port */ | 324 | /* It's a unidirectional port */ |
328 | int i = 0, n = bytes; | 325 | int i = 0, n = bytes; |
329 | unsigned char rgb[3]; | 326 | unsigned char rgb[3]; |
330 | 327 | ||
331 | while (bytes < nbytes) | 328 | while (bytes < nbytes) { |
332 | { | ||
333 | unsigned int hi, lo; | 329 | unsigned int hi, lo; |
334 | 330 | ||
335 | if (qcam_await_ready1(q, 1)) return bytes; | 331 | if (qcam_await_ready1(q, 1)) |
332 | return bytes; | ||
336 | hi = (parport_read_status(q->pport) & 0xf0); | 333 | hi = (parport_read_status(q->pport) & 0xf0); |
337 | qcam_set_ack(q, 1); | 334 | qcam_set_ack(q, 1); |
338 | if (qcam_await_ready1(q, 0)) return bytes; | 335 | if (qcam_await_ready1(q, 0)) |
336 | return bytes; | ||
339 | lo = (parport_read_status(q->pport) & 0xf0); | 337 | lo = (parport_read_status(q->pport) & 0xf0); |
340 | qcam_set_ack(q, 0); | 338 | qcam_set_ack(q, 0); |
341 | /* flip some bits */ | 339 | /* flip some bits */ |
@@ -374,28 +372,26 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le | |||
374 | return -EFAULT; | 372 | return -EFAULT; |
375 | 373 | ||
376 | /* Wait for camera to become ready */ | 374 | /* Wait for camera to become ready */ |
377 | for (;;) | 375 | for (;;) { |
378 | { | ||
379 | int i = qcam_get(q, 41); | 376 | int i = qcam_get(q, 41); |
377 | |||
380 | if (i == -1) { | 378 | if (i == -1) { |
381 | qc_setup(q); | 379 | qc_setup(q); |
382 | return -EIO; | 380 | return -EIO; |
383 | } | 381 | } |
384 | if ((i & 0x80) == 0) | 382 | if ((i & 0x80) == 0) |
385 | break; | 383 | break; |
386 | else | 384 | schedule(); |
387 | schedule(); | ||
388 | } | 385 | } |
389 | 386 | ||
390 | if (qcam_set(q, 7, (q->mode | (is_bi_dir?1:0)) + 1)) | 387 | if (qcam_set(q, 7, (q->mode | (is_bi_dir ? 1 : 0)) + 1)) |
391 | return -EIO; | 388 | return -EIO; |
392 | 389 | ||
393 | lines = q->height; | 390 | lines = q->height; |
394 | pixelsperline = q->width; | 391 | pixelsperline = q->width; |
395 | bitsperxfer = (is_bi_dir) ? 24 : 8; | 392 | bitsperxfer = (is_bi_dir) ? 24 : 8; |
396 | 393 | ||
397 | if (is_bi_dir) | 394 | if (is_bi_dir) { |
398 | { | ||
399 | /* Turn the port around */ | 395 | /* Turn the port around */ |
400 | parport_data_reverse(q->pport); | 396 | parport_data_reverse(q->pport); |
401 | mdelay(3); | 397 | mdelay(3); |
@@ -413,16 +409,17 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le | |||
413 | 409 | ||
414 | wantlen = lines * pixelsperline * 24 / 8; | 410 | wantlen = lines * pixelsperline * 24 / 8; |
415 | 411 | ||
416 | while (wantlen) | 412 | while (wantlen) { |
417 | { | ||
418 | size_t t, s; | 413 | size_t t, s; |
419 | s = (wantlen > BUFSZ)?BUFSZ:wantlen; | 414 | |
415 | s = (wantlen > BUFSZ) ? BUFSZ : wantlen; | ||
420 | t = qcam_read_bytes(q, tmpbuf, s); | 416 | t = qcam_read_bytes(q, tmpbuf, s); |
421 | if (outptr < len) | 417 | if (outptr < len) { |
422 | { | ||
423 | size_t sz = len - outptr; | 418 | size_t sz = len - outptr; |
424 | if (sz > t) sz = t; | 419 | |
425 | if (__copy_to_user(buf+outptr, tmpbuf, sz)) | 420 | if (sz > t) |
421 | sz = t; | ||
422 | if (__copy_to_user(buf + outptr, tmpbuf, sz)) | ||
426 | break; | 423 | break; |
427 | outptr += sz; | 424 | outptr += sz; |
428 | } | 425 | } |
@@ -434,33 +431,31 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le | |||
434 | 431 | ||
435 | len = outptr; | 432 | len = outptr; |
436 | 433 | ||
437 | if (wantlen) | 434 | if (wantlen) { |
438 | { | 435 | printk(KERN_ERR "qcam: short read.\n"); |
439 | printk("qcam: short read.\n"); | ||
440 | if (is_bi_dir) | 436 | if (is_bi_dir) |
441 | parport_data_forward(q->pport); | 437 | parport_data_forward(q->pport); |
442 | qc_setup(q); | 438 | qc_setup(q); |
443 | return len; | 439 | return len; |
444 | } | 440 | } |
445 | 441 | ||
446 | if (is_bi_dir) | 442 | if (is_bi_dir) { |
447 | { | ||
448 | int l; | 443 | int l; |
444 | |||
449 | do { | 445 | do { |
450 | l = qcam_read_bytes(q, tmpbuf, 3); | 446 | l = qcam_read_bytes(q, tmpbuf, 3); |
451 | cond_resched(); | 447 | cond_resched(); |
452 | } while (l && (tmpbuf[0] == 0x7e || tmpbuf[1] == 0x7e || tmpbuf[2] == 0x7e)); | 448 | } while (l && (tmpbuf[0] == 0x7e || tmpbuf[1] == 0x7e || tmpbuf[2] == 0x7e)); |
453 | if (force_rgb) { | 449 | if (force_rgb) { |
454 | if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf) | 450 | if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf) |
455 | printk("qcam: bad EOF\n"); | 451 | printk(KERN_ERR "qcam: bad EOF\n"); |
456 | } else { | 452 | } else { |
457 | if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe) | 453 | if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe) |
458 | printk("qcam: bad EOF\n"); | 454 | printk(KERN_ERR "qcam: bad EOF\n"); |
459 | } | 455 | } |
460 | qcam_set_ack(q, 0); | 456 | qcam_set_ack(q, 0); |
461 | if (qcam_await_ready1(q, 1)) | 457 | if (qcam_await_ready1(q, 1)) { |
462 | { | 458 | printk(KERN_ERR "qcam: no ack after EOF\n"); |
463 | printk("qcam: no ack after EOF\n"); | ||
464 | parport_data_forward(q->pport); | 459 | parport_data_forward(q->pport); |
465 | qc_setup(q); | 460 | qc_setup(q); |
466 | return len; | 461 | return len; |
@@ -468,27 +463,25 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le | |||
468 | parport_data_forward(q->pport); | 463 | parport_data_forward(q->pport); |
469 | mdelay(3); | 464 | mdelay(3); |
470 | qcam_set_ack(q, 1); | 465 | qcam_set_ack(q, 1); |
471 | if (qcam_await_ready1(q, 0)) | 466 | if (qcam_await_ready1(q, 0)) { |
472 | { | 467 | printk(KERN_ERR "qcam: no ack to port turnaround\n"); |
473 | printk("qcam: no ack to port turnaround\n"); | ||
474 | qc_setup(q); | 468 | qc_setup(q); |
475 | return len; | 469 | return len; |
476 | } | 470 | } |
477 | } | 471 | } else { |
478 | else | ||
479 | { | ||
480 | int l; | 472 | int l; |
473 | |||
481 | do { | 474 | do { |
482 | l = qcam_read_bytes(q, tmpbuf, 1); | 475 | l = qcam_read_bytes(q, tmpbuf, 1); |
483 | cond_resched(); | 476 | cond_resched(); |
484 | } while (l && tmpbuf[0] == 0x7e); | 477 | } while (l && tmpbuf[0] == 0x7e); |
485 | l = qcam_read_bytes(q, tmpbuf+1, 2); | 478 | l = qcam_read_bytes(q, tmpbuf + 1, 2); |
486 | if (force_rgb) { | 479 | if (force_rgb) { |
487 | if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf) | 480 | if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf) |
488 | printk("qcam: bad EOF\n"); | 481 | printk(KERN_ERR "qcam: bad EOF\n"); |
489 | } else { | 482 | } else { |
490 | if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe) | 483 | if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe) |
491 | printk("qcam: bad EOF\n"); | 484 | printk(KERN_ERR "qcam: bad EOF\n"); |
492 | } | 485 | } |
493 | } | 486 | } |
494 | 487 | ||
@@ -503,164 +496,166 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le | |||
503 | static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg) | 496 | static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg) |
504 | { | 497 | { |
505 | struct video_device *dev = video_devdata(file); | 498 | struct video_device *dev = video_devdata(file); |
506 | struct qcam_device *qcam=(struct qcam_device *)dev; | 499 | struct qcam_device *qcam = (struct qcam_device *)dev; |
507 | 500 | ||
508 | switch(cmd) | 501 | switch (cmd) { |
502 | case VIDIOCGCAP: | ||
509 | { | 503 | { |
510 | case VIDIOCGCAP: | 504 | struct video_capability *b = arg; |
511 | { | 505 | |
512 | struct video_capability *b = arg; | 506 | strcpy(b->name, "Quickcam"); |
513 | strcpy(b->name, "Quickcam"); | 507 | b->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES; |
514 | b->type = VID_TYPE_CAPTURE|VID_TYPE_SCALES; | 508 | b->channels = 1; |
515 | b->channels = 1; | 509 | b->audios = 0; |
516 | b->audios = 0; | 510 | b->maxwidth = 320; |
517 | b->maxwidth = 320; | 511 | b->maxheight = 240; |
518 | b->maxheight = 240; | 512 | b->minwidth = 80; |
519 | b->minwidth = 80; | 513 | b->minheight = 60; |
520 | b->minheight = 60; | 514 | return 0; |
521 | return 0; | 515 | } |
522 | } | 516 | case VIDIOCGCHAN: |
523 | case VIDIOCGCHAN: | 517 | { |
524 | { | 518 | struct video_channel *v = arg; |
525 | struct video_channel *v = arg; | 519 | |
526 | if(v->channel!=0) | 520 | if (v->channel != 0) |
527 | return -EINVAL; | 521 | return -EINVAL; |
528 | v->flags=0; | 522 | v->flags = 0; |
529 | v->tuners=0; | 523 | v->tuners = 0; |
530 | /* Good question.. its composite or SVHS so.. */ | 524 | /* Good question.. its composite or SVHS so.. */ |
531 | v->type = VIDEO_TYPE_CAMERA; | 525 | v->type = VIDEO_TYPE_CAMERA; |
532 | strcpy(v->name, "Camera"); | 526 | strcpy(v->name, "Camera"); |
533 | return 0; | 527 | return 0; |
534 | } | 528 | } |
535 | case VIDIOCSCHAN: | 529 | case VIDIOCSCHAN: |
536 | { | 530 | { |
537 | struct video_channel *v = arg; | 531 | struct video_channel *v = arg; |
538 | if(v->channel!=0) | 532 | |
539 | return -EINVAL; | 533 | if (v->channel != 0) |
540 | return 0; | 534 | return -EINVAL; |
541 | } | 535 | return 0; |
542 | case VIDIOCGTUNER: | 536 | } |
543 | { | 537 | case VIDIOCGTUNER: |
544 | struct video_tuner *v = arg; | 538 | { |
545 | if(v->tuner) | 539 | struct video_tuner *v = arg; |
546 | return -EINVAL; | 540 | |
547 | memset(v,0,sizeof(*v)); | 541 | if (v->tuner) |
548 | strcpy(v->name, "Format"); | 542 | return -EINVAL; |
549 | v->mode = VIDEO_MODE_AUTO; | 543 | memset(v, 0, sizeof(*v)); |
550 | return 0; | 544 | strcpy(v->name, "Format"); |
551 | } | 545 | v->mode = VIDEO_MODE_AUTO; |
552 | case VIDIOCSTUNER: | 546 | return 0; |
553 | { | 547 | } |
554 | struct video_tuner *v = arg; | 548 | case VIDIOCSTUNER: |
555 | if(v->tuner) | 549 | { |
556 | return -EINVAL; | 550 | struct video_tuner *v = arg; |
557 | if(v->mode!=VIDEO_MODE_AUTO) | 551 | |
558 | return -EINVAL; | 552 | if (v->tuner) |
559 | return 0; | 553 | return -EINVAL; |
560 | } | 554 | if (v->mode != VIDEO_MODE_AUTO) |
561 | case VIDIOCGPICT: | 555 | return -EINVAL; |
562 | { | 556 | return 0; |
563 | struct video_picture *p = arg; | 557 | } |
564 | p->colour=0x8000; | 558 | case VIDIOCGPICT: |
565 | p->hue=0x8000; | 559 | { |
566 | p->brightness=qcam->brightness<<8; | 560 | struct video_picture *p = arg; |
567 | p->contrast=qcam->contrast<<8; | 561 | |
568 | p->whiteness=qcam->whitebal<<8; | 562 | p->colour = 0x8000; |
569 | p->depth=24; | 563 | p->hue = 0x8000; |
570 | p->palette=VIDEO_PALETTE_RGB24; | 564 | p->brightness = qcam->brightness << 8; |
571 | return 0; | 565 | p->contrast = qcam->contrast << 8; |
566 | p->whiteness = qcam->whitebal << 8; | ||
567 | p->depth = 24; | ||
568 | p->palette = VIDEO_PALETTE_RGB24; | ||
569 | return 0; | ||
570 | } | ||
571 | case VIDIOCSPICT: | ||
572 | { | ||
573 | struct video_picture *p = arg; | ||
574 | |||
575 | /* | ||
576 | * Sanity check args | ||
577 | */ | ||
578 | if (p->depth != 24 || p->palette != VIDEO_PALETTE_RGB24) | ||
579 | return -EINVAL; | ||
580 | |||
581 | /* | ||
582 | * Now load the camera. | ||
583 | */ | ||
584 | qcam->brightness = p->brightness >> 8; | ||
585 | qcam->contrast = p->contrast >> 8; | ||
586 | qcam->whitebal = p->whiteness >> 8; | ||
587 | |||
588 | mutex_lock(&qcam->lock); | ||
589 | parport_claim_or_block(qcam->pdev); | ||
590 | qc_setup(qcam); | ||
591 | parport_release(qcam->pdev); | ||
592 | mutex_unlock(&qcam->lock); | ||
593 | return 0; | ||
594 | } | ||
595 | case VIDIOCSWIN: | ||
596 | { | ||
597 | struct video_window *vw = arg; | ||
598 | |||
599 | if (vw->flags) | ||
600 | return -EINVAL; | ||
601 | if (vw->clipcount) | ||
602 | return -EINVAL; | ||
603 | if (vw->height < 60 || vw->height > 240) | ||
604 | return -EINVAL; | ||
605 | if (vw->width < 80 || vw->width > 320) | ||
606 | return -EINVAL; | ||
607 | |||
608 | qcam->width = 80; | ||
609 | qcam->height = 60; | ||
610 | qcam->mode = QC_DECIMATION_4; | ||
611 | |||
612 | if (vw->width >= 160 && vw->height >= 120) { | ||
613 | qcam->width = 160; | ||
614 | qcam->height = 120; | ||
615 | qcam->mode = QC_DECIMATION_2; | ||
572 | } | 616 | } |
573 | case VIDIOCSPICT: | 617 | if (vw->width >= 320 && vw->height >= 240) { |
574 | { | 618 | qcam->width = 320; |
575 | struct video_picture *p = arg; | 619 | qcam->height = 240; |
576 | 620 | qcam->mode = QC_DECIMATION_1; | |
577 | /* | ||
578 | * Sanity check args | ||
579 | */ | ||
580 | if (p->depth != 24 || p->palette != VIDEO_PALETTE_RGB24) | ||
581 | return -EINVAL; | ||
582 | |||
583 | /* | ||
584 | * Now load the camera. | ||
585 | */ | ||
586 | qcam->brightness = p->brightness>>8; | ||
587 | qcam->contrast = p->contrast>>8; | ||
588 | qcam->whitebal = p->whiteness>>8; | ||
589 | |||
590 | mutex_lock(&qcam->lock); | ||
591 | parport_claim_or_block(qcam->pdev); | ||
592 | qc_setup(qcam); | ||
593 | parport_release(qcam->pdev); | ||
594 | mutex_unlock(&qcam->lock); | ||
595 | return 0; | ||
596 | } | 621 | } |
597 | case VIDIOCSWIN: | 622 | qcam->mode |= QC_MILLIONS; |
598 | { | ||
599 | struct video_window *vw = arg; | ||
600 | |||
601 | if(vw->flags) | ||
602 | return -EINVAL; | ||
603 | if(vw->clipcount) | ||
604 | return -EINVAL; | ||
605 | if(vw->height<60||vw->height>240) | ||
606 | return -EINVAL; | ||
607 | if(vw->width<80||vw->width>320) | ||
608 | return -EINVAL; | ||
609 | |||
610 | qcam->width = 80; | ||
611 | qcam->height = 60; | ||
612 | qcam->mode = QC_DECIMATION_4; | ||
613 | |||
614 | if(vw->width>=160 && vw->height>=120) | ||
615 | { | ||
616 | qcam->width = 160; | ||
617 | qcam->height = 120; | ||
618 | qcam->mode = QC_DECIMATION_2; | ||
619 | } | ||
620 | if(vw->width>=320 && vw->height>=240) | ||
621 | { | ||
622 | qcam->width = 320; | ||
623 | qcam->height = 240; | ||
624 | qcam->mode = QC_DECIMATION_1; | ||
625 | } | ||
626 | qcam->mode |= QC_MILLIONS; | ||
627 | #if 0 | 623 | #if 0 |
628 | if(vw->width>=640 && vw->height>=480) | 624 | if (vw->width >= 640 && vw->height >= 480) { |
629 | { | 625 | qcam->width = 640; |
630 | qcam->width = 640; | 626 | qcam->height = 480; |
631 | qcam->height = 480; | 627 | qcam->mode = QC_BILLIONS | QC_DECIMATION_1; |
632 | qcam->mode = QC_BILLIONS | QC_DECIMATION_1; | ||
633 | } | ||
634 | #endif | ||
635 | /* Ok we figured out what to use from our | ||
636 | wide choice */ | ||
637 | mutex_lock(&qcam->lock); | ||
638 | parport_claim_or_block(qcam->pdev); | ||
639 | qc_setup(qcam); | ||
640 | parport_release(qcam->pdev); | ||
641 | mutex_unlock(&qcam->lock); | ||
642 | return 0; | ||
643 | } | ||
644 | case VIDIOCGWIN: | ||
645 | { | ||
646 | struct video_window *vw = arg; | ||
647 | memset(vw, 0, sizeof(*vw)); | ||
648 | vw->width=qcam->width; | ||
649 | vw->height=qcam->height; | ||
650 | return 0; | ||
651 | } | 628 | } |
652 | case VIDIOCKEY: | 629 | #endif |
653 | return 0; | 630 | /* Ok we figured out what to use from our |
654 | case VIDIOCCAPTURE: | 631 | wide choice */ |
655 | case VIDIOCGFBUF: | 632 | mutex_lock(&qcam->lock); |
656 | case VIDIOCSFBUF: | 633 | parport_claim_or_block(qcam->pdev); |
657 | case VIDIOCGFREQ: | 634 | qc_setup(qcam); |
658 | case VIDIOCSFREQ: | 635 | parport_release(qcam->pdev); |
659 | case VIDIOCGAUDIO: | 636 | mutex_unlock(&qcam->lock); |
660 | case VIDIOCSAUDIO: | 637 | return 0; |
661 | return -EINVAL; | 638 | } |
662 | default: | 639 | case VIDIOCGWIN: |
663 | return -ENOIOCTLCMD; | 640 | { |
641 | struct video_window *vw = arg; | ||
642 | memset(vw, 0, sizeof(*vw)); | ||
643 | vw->width = qcam->width; | ||
644 | vw->height = qcam->height; | ||
645 | return 0; | ||
646 | } | ||
647 | case VIDIOCKEY: | ||
648 | return 0; | ||
649 | case VIDIOCCAPTURE: | ||
650 | case VIDIOCGFBUF: | ||
651 | case VIDIOCSFBUF: | ||
652 | case VIDIOCGFREQ: | ||
653 | case VIDIOCSFREQ: | ||
654 | case VIDIOCGAUDIO: | ||
655 | case VIDIOCSAUDIO: | ||
656 | return -EINVAL; | ||
657 | default: | ||
658 | return -ENOIOCTLCMD; | ||
664 | } | 659 | } |
665 | return 0; | 660 | return 0; |
666 | } | 661 | } |
@@ -675,13 +670,13 @@ static ssize_t qcam_read(struct file *file, char __user *buf, | |||
675 | size_t count, loff_t *ppos) | 670 | size_t count, loff_t *ppos) |
676 | { | 671 | { |
677 | struct video_device *v = video_devdata(file); | 672 | struct video_device *v = video_devdata(file); |
678 | struct qcam_device *qcam=(struct qcam_device *)v; | 673 | struct qcam_device *qcam = (struct qcam_device *)v; |
679 | int len; | 674 | int len; |
680 | 675 | ||
681 | mutex_lock(&qcam->lock); | 676 | mutex_lock(&qcam->lock); |
682 | parport_claim_or_block(qcam->pdev); | 677 | parport_claim_or_block(qcam->pdev); |
683 | /* Probably should have a semaphore against multiple users */ | 678 | /* Probably should have a semaphore against multiple users */ |
684 | len = qc_capture(qcam, buf,count); | 679 | len = qc_capture(qcam, buf, count); |
685 | parport_release(qcam->pdev); | 680 | parport_release(qcam->pdev); |
686 | mutex_unlock(&qcam->lock); | 681 | mutex_unlock(&qcam->lock); |
687 | return len; | 682 | return len; |
@@ -713,8 +708,7 @@ static const struct v4l2_file_operations qcam_fops = { | |||
713 | .read = qcam_read, | 708 | .read = qcam_read, |
714 | }; | 709 | }; |
715 | 710 | ||
716 | static struct video_device qcam_template= | 711 | static struct video_device qcam_template = { |
717 | { | ||
718 | .name = "Colour QuickCam", | 712 | .name = "Colour QuickCam", |
719 | .fops = &qcam_fops, | 713 | .fops = &qcam_fops, |
720 | .release = video_device_release_empty, | 714 | .release = video_device_release_empty, |
@@ -727,17 +721,16 @@ static struct qcam_device *qcam_init(struct parport *port) | |||
727 | struct qcam_device *q; | 721 | struct qcam_device *q; |
728 | 722 | ||
729 | q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL); | 723 | q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL); |
730 | if(q==NULL) | 724 | if (q == NULL) |
731 | return NULL; | 725 | return NULL; |
732 | 726 | ||
733 | q->pport = port; | 727 | q->pport = port; |
734 | q->pdev = parport_register_device(port, "c-qcam", NULL, NULL, | 728 | q->pdev = parport_register_device(port, "c-qcam", NULL, NULL, |
735 | NULL, 0, NULL); | 729 | NULL, 0, NULL); |
736 | 730 | ||
737 | q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE)?1:0; | 731 | q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE) ? 1 : 0; |
738 | 732 | ||
739 | if (q->pdev == NULL) | 733 | if (q->pdev == NULL) { |
740 | { | ||
741 | printk(KERN_ERR "c-qcam: couldn't register for %s.\n", | 734 | printk(KERN_ERR "c-qcam: couldn't register for %s.\n", |
742 | port->name); | 735 | port->name); |
743 | kfree(q); | 736 | kfree(q); |
@@ -765,12 +758,11 @@ static int init_cqcam(struct parport *port) | |||
765 | { | 758 | { |
766 | struct qcam_device *qcam; | 759 | struct qcam_device *qcam; |
767 | 760 | ||
768 | if (parport[0] != -1) | 761 | if (parport[0] != -1) { |
769 | { | ||
770 | /* The user gave specific instructions */ | 762 | /* The user gave specific instructions */ |
771 | int i, found = 0; | 763 | int i, found = 0; |
772 | for (i = 0; i < MAX_CAMS && parport[i] != -1; i++) | 764 | |
773 | { | 765 | for (i = 0; i < MAX_CAMS && parport[i] != -1; i++) { |
774 | if (parport[0] == port->number) | 766 | if (parport[0] == port->number) |
775 | found = 1; | 767 | found = 1; |
776 | } | 768 | } |
@@ -782,15 +774,14 @@ static int init_cqcam(struct parport *port) | |||
782 | return -ENOSPC; | 774 | return -ENOSPC; |
783 | 775 | ||
784 | qcam = qcam_init(port); | 776 | qcam = qcam_init(port); |
785 | if (qcam==NULL) | 777 | if (qcam == NULL) |
786 | return -ENODEV; | 778 | return -ENODEV; |
787 | 779 | ||
788 | parport_claim_or_block(qcam->pdev); | 780 | parport_claim_or_block(qcam->pdev); |
789 | 781 | ||
790 | qc_reset(qcam); | 782 | qc_reset(qcam); |
791 | 783 | ||
792 | if (probe && qc_detect(qcam)==0) | 784 | if (probe && qc_detect(qcam) == 0) { |
793 | { | ||
794 | parport_release(qcam->pdev); | 785 | parport_release(qcam->pdev); |
795 | parport_unregister_device(qcam->pdev); | 786 | parport_unregister_device(qcam->pdev); |
796 | kfree(qcam); | 787 | kfree(qcam); |
@@ -840,14 +831,14 @@ static struct parport_driver cqcam_driver = { | |||
840 | .detach = cq_detach, | 831 | .detach = cq_detach, |
841 | }; | 832 | }; |
842 | 833 | ||
843 | static int __init cqcam_init (void) | 834 | static int __init cqcam_init(void) |
844 | { | 835 | { |
845 | printk(BANNER "\n"); | 836 | printk(BANNER "\n"); |
846 | 837 | ||
847 | return parport_register_driver(&cqcam_driver); | 838 | return parport_register_driver(&cqcam_driver); |
848 | } | 839 | } |
849 | 840 | ||
850 | static void __exit cqcam_cleanup (void) | 841 | static void __exit cqcam_cleanup(void) |
851 | { | 842 | { |
852 | unsigned int i; | 843 | unsigned int i; |
853 | 844 | ||
@@ -862,9 +853,9 @@ MODULE_DESCRIPTION(BANNER); | |||
862 | MODULE_LICENSE("GPL"); | 853 | MODULE_LICENSE("GPL"); |
863 | 854 | ||
864 | /* FIXME: parport=auto would never have worked, surely? --RR */ | 855 | /* FIXME: parport=auto would never have worked, surely? --RR */ |
865 | MODULE_PARM_DESC(parport ,"parport=<auto|n[,n]...> for port detection method\n\ | 856 | MODULE_PARM_DESC(parport, "parport=<auto|n[,n]...> for port detection method\n" |
866 | probe=<0|1|2> for camera detection method\n\ | 857 | "probe=<0|1|2> for camera detection method\n" |
867 | force_rgb=<0|1> for RGB data format (default BGR)"); | 858 | "force_rgb=<0|1> for RGB data format (default BGR)"); |
868 | module_param_array(parport, int, NULL, 0); | 859 | module_param_array(parport, int, NULL, 0); |
869 | module_param(probe, int, 0); | 860 | module_param(probe, int, 0); |
870 | module_param(force_rgb, bool, 0); | 861 | module_param(force_rgb, bool, 0); |