2 * video1394.c - video driver for OHCI 1394 boards
3 * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
4 * Peter Schlaile <udbz@rz.uni-karlsruhe.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /* jds -- add private data to file to keep track of iso contexts associated
22 with each open -- so release won't kill all iso transfers */
24 /* Damien Douxchamps: Fix failure when the number of DMA pages per frame is
27 #include <linux/config.h>
28 #include <linux/kernel.h>
29 #include <linux/list.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/wait.h>
33 #include <linux/errno.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/pci.h>
38 #include <linux/poll.h>
39 #include <linux/smp_lock.h>
40 #include <linux/delay.h>
41 #include <linux/devfs_fs_kernel.h>
42 #include <linux/bitops.h>
43 #include <linux/types.h>
44 #include <linux/vmalloc.h>
45 #include <linux/timex.h>
47 #include <linux/ioctl32.h>
48 #include <linux/compat.h>
49 #include <linux/cdev.h>
52 #include "ieee1394_types.h"
54 #include "ieee1394_core.h"
55 #include "highlevel.h"
56 #include "video1394.h"
62 #define ISO_CHANNELS 64
65 #define virt_to_page(x) MAP_NR(x)
69 #define vmalloc_32(x) vmalloc(x)
76 quadlet_t pad[4]; /* FIXME: quick hack for memory alignment */
81 int type; /* OHCI_ISO_TRANSMIT or OHCI_ISO_RECEIVE */
82 struct ohci1394_iso_tasklet iso_tasklet;
86 int * next_buffer; /* For ISO Transmit of video packets
87 to write the correct SYT field
88 into the next block */
89 unsigned int num_desc;
90 unsigned int buf_size;
91 unsigned int frame_size;
92 unsigned int packet_size;
93 unsigned int left_size;
96 struct dma_region dma;
98 struct dma_prog_region *prg_reg;
100 struct dma_cmd **ir_prg;
101 struct it_dma_prg **it_prg;
103 unsigned int *buffer_status;
104 struct timeval *buffer_time; /* time when the buffer was received */
105 unsigned int *last_used_cmd; /* For ISO Transmit with
106 variable sized packets only ! */
111 wait_queue_head_t waitq;
113 unsigned int syt_offset;
116 struct list_head link;
121 struct ti_ohci *ohci;
122 struct list_head context_list;
123 struct dma_iso_ctx *current_ctx;
126 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
127 #define VIDEO1394_DEBUG
134 #ifdef VIDEO1394_DEBUG
135 #define DBGMSG(card, fmt, args...) \
136 printk(KERN_INFO "video1394_%d: " fmt "\n" , card , ## args)
138 #define DBGMSG(card, fmt, args...)
141 /* print general (card independent) information */
142 #define PRINT_G(level, fmt, args...) \
143 printk(level "video1394: " fmt "\n" , ## args)
145 /* print card specific information */
146 #define PRINT(level, card, fmt, args...) \
147 printk(level "video1394_%d: " fmt "\n" , card , ## args)
149 void wakeup_dma_ir_ctx(unsigned long l);
150 void wakeup_dma_it_ctx(unsigned long l);
152 static struct hpsb_highlevel video1394_highlevel;
154 static int free_dma_iso_ctx(struct dma_iso_ctx *d)
158 DBGMSG(d->ohci->host->id, "Freeing dma_iso_ctx %d", d->ctx);
160 ohci1394_stop_context(d->ohci, d->ctrlClear, NULL);
161 if (d->iso_tasklet.link.next != NULL)
162 ohci1394_unregister_iso_tasklet(d->ohci, &d->iso_tasklet);
164 dma_region_free(&d->dma);
167 for (i = 0; i < d->num_desc; i++)
168 dma_prog_region_free(&d->prg_reg[i]);
178 if (d->buffer_status)
179 kfree(d->buffer_status);
181 kfree(d->buffer_time);
182 if (d->last_used_cmd)
183 kfree(d->last_used_cmd);
185 kfree(d->next_buffer);
194 static struct dma_iso_ctx *
195 alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
196 int buf_size, int channel, unsigned int packet_size)
198 struct dma_iso_ctx *d;
201 d = kmalloc(sizeof(struct dma_iso_ctx), GFP_KERNEL);
203 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx");
207 memset(d, 0, sizeof *d);
211 d->channel = channel;
212 d->num_desc = num_desc;
213 d->frame_size = buf_size;
214 d->buf_size = PAGE_ALIGN(buf_size);
216 INIT_LIST_HEAD(&d->link);
217 init_waitqueue_head(&d->waitq);
219 /* Init the regions for easy cleanup */
220 dma_region_init(&d->dma);
222 if (dma_region_alloc(&d->dma, d->num_desc * d->buf_size, ohci->dev,
223 PCI_DMA_BIDIRECTIONAL)) {
224 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma buffer");
229 if (type == OHCI_ISO_RECEIVE)
230 ohci1394_init_iso_tasklet(&d->iso_tasklet, type,
234 ohci1394_init_iso_tasklet(&d->iso_tasklet, type,
238 if (ohci1394_register_iso_tasklet(ohci, &d->iso_tasklet) < 0) {
239 PRINT(KERN_ERR, ohci->host->id, "no free iso %s contexts",
240 type == OHCI_ISO_RECEIVE ? "receive" : "transmit");
244 d->ctx = d->iso_tasklet.context;
246 d->prg_reg = kmalloc(d->num_desc * sizeof(struct dma_prog_region),
248 if (d->prg_reg == NULL) {
249 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs");
253 /* Makes for easier cleanup */
254 for (i = 0; i < d->num_desc; i++)
255 dma_prog_region_init(&d->prg_reg[i]);
257 if (type == OHCI_ISO_RECEIVE) {
258 d->ctrlSet = OHCI1394_IsoRcvContextControlSet+32*d->ctx;
259 d->ctrlClear = OHCI1394_IsoRcvContextControlClear+32*d->ctx;
260 d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx;
261 d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx;
263 d->ir_prg = kmalloc(d->num_desc * sizeof(struct dma_cmd *),
266 if (d->ir_prg == NULL) {
267 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg");
271 memset(d->ir_prg, 0, d->num_desc * sizeof(struct dma_cmd *));
273 d->nb_cmd = d->buf_size / PAGE_SIZE + 1;
274 d->left_size = (d->frame_size % PAGE_SIZE) ?
275 d->frame_size % PAGE_SIZE : PAGE_SIZE;
277 for (i = 0;i < d->num_desc; i++) {
278 if (dma_prog_region_alloc(&d->prg_reg[i], d->nb_cmd *
279 sizeof(struct dma_cmd), ohci->dev)) {
280 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg");
284 d->ir_prg[i] = (struct dma_cmd *)d->prg_reg[i].kvirt;
287 } else { /* OHCI_ISO_TRANSMIT */
288 d->ctrlSet = OHCI1394_IsoXmitContextControlSet+16*d->ctx;
289 d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx;
290 d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx;
292 d->it_prg = kmalloc(d->num_desc * sizeof(struct it_dma_prg *),
295 if (d->it_prg == NULL) {
296 PRINT(KERN_ERR, ohci->host->id,
297 "Failed to allocate dma it prg");
301 memset(d->it_prg, 0, d->num_desc*sizeof(struct it_dma_prg *));
303 d->packet_size = packet_size;
305 if (PAGE_SIZE % packet_size || packet_size>4096) {
306 PRINT(KERN_ERR, ohci->host->id,
307 "Packet size %d (page_size: %ld) "
308 "not yet supported\n",
309 packet_size, PAGE_SIZE);
314 d->nb_cmd = d->frame_size / d->packet_size;
315 if (d->frame_size % d->packet_size) {
317 d->left_size = d->frame_size % d->packet_size;
319 d->left_size = d->packet_size;
321 for (i = 0; i < d->num_desc; i++) {
322 if (dma_prog_region_alloc(&d->prg_reg[i], d->nb_cmd *
323 sizeof(struct it_dma_prg), ohci->dev)) {
324 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma it prg");
328 d->it_prg[i] = (struct it_dma_prg *)d->prg_reg[i].kvirt;
332 d->buffer_status = kmalloc(d->num_desc * sizeof(unsigned int),
334 d->buffer_time = kmalloc(d->num_desc * sizeof(struct timeval),
336 d->last_used_cmd = kmalloc(d->num_desc * sizeof(unsigned int),
338 d->next_buffer = kmalloc(d->num_desc * sizeof(int),
341 if (d->buffer_status == NULL) {
342 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_status");
346 if (d->buffer_time == NULL) {
347 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_time");
351 if (d->last_used_cmd == NULL) {
352 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate last_used_cmd");
356 if (d->next_buffer == NULL) {
357 PRINT(KERN_ERR, ohci->host->id, "Failed to allocate next_buffer");
361 memset(d->buffer_status, 0, d->num_desc * sizeof(unsigned int));
362 memset(d->buffer_time, 0, d->num_desc * sizeof(struct timeval));
363 memset(d->last_used_cmd, 0, d->num_desc * sizeof(unsigned int));
364 memset(d->next_buffer, -1, d->num_desc * sizeof(int));
366 spin_lock_init(&d->lock);
368 PRINT(KERN_INFO, ohci->host->id, "Iso %s DMA: %d buffers "
369 "of size %d allocated for a frame size %d, each with %d prgs",
370 (type == OHCI_ISO_RECEIVE) ? "receive" : "transmit",
371 d->num_desc, d->buf_size, d->frame_size, d->nb_cmd);
376 static void reset_ir_status(struct dma_iso_ctx *d, int n)
379 d->ir_prg[n][0].status = cpu_to_le32(4);
380 d->ir_prg[n][1].status = cpu_to_le32(PAGE_SIZE-4);
381 for (i = 2; i < d->nb_cmd - 1; i++)
382 d->ir_prg[n][i].status = cpu_to_le32(PAGE_SIZE);
383 d->ir_prg[n][i].status = cpu_to_le32(d->left_size);
386 static void initialize_dma_ir_prg(struct dma_iso_ctx *d, int n, int flags)
388 struct dma_cmd *ir_prg = d->ir_prg[n];
389 struct dma_prog_region *ir_reg = &d->prg_reg[n];
390 unsigned long buf = (unsigned long)d->dma.kvirt + n * d->buf_size;
393 /* the first descriptor will read only 4 bytes */
394 ir_prg[0].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
397 /* set the sync flag */
398 if (flags & VIDEO1394_SYNC_FRAMES)
399 ir_prg[0].control |= cpu_to_le32(DMA_CTL_WAIT);
401 ir_prg[0].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma, buf -
402 (unsigned long)d->dma.kvirt));
403 ir_prg[0].branchAddress = cpu_to_le32((dma_prog_region_offset_to_bus(ir_reg,
404 1 * sizeof(struct dma_cmd)) & 0xfffffff0) | 0x1);
406 /* If there is *not* only one DMA page per frame (hence, d->nb_cmd==2) */
408 /* The second descriptor will read PAGE_SIZE-4 bytes */
409 ir_prg[1].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
410 DMA_CTL_BRANCH | (PAGE_SIZE-4));
411 ir_prg[1].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma, (buf + 4) -
412 (unsigned long)d->dma.kvirt));
413 ir_prg[1].branchAddress = cpu_to_le32((dma_prog_region_offset_to_bus(ir_reg,
414 2 * sizeof(struct dma_cmd)) & 0xfffffff0) | 0x1);
416 for (i = 2; i < d->nb_cmd - 1; i++) {
417 ir_prg[i].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
418 DMA_CTL_BRANCH | PAGE_SIZE);
419 ir_prg[i].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
420 (buf+(i-1)*PAGE_SIZE) -
421 (unsigned long)d->dma.kvirt));
423 ir_prg[i].branchAddress =
424 cpu_to_le32((dma_prog_region_offset_to_bus(ir_reg,
425 (i + 1) * sizeof(struct dma_cmd)) & 0xfffffff0) | 0x1);
428 /* The last descriptor will generate an interrupt */
429 ir_prg[i].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
430 DMA_CTL_IRQ | DMA_CTL_BRANCH | d->left_size);
431 ir_prg[i].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
432 (buf+(i-1)*PAGE_SIZE) -
433 (unsigned long)d->dma.kvirt));
435 /* Only one DMA page is used. Read d->left_size immediately and */
436 /* generate an interrupt as this is also the last page. */
437 ir_prg[1].control = cpu_to_le32(DMA_CTL_INPUT_MORE | DMA_CTL_UPDATE |
438 DMA_CTL_IRQ | DMA_CTL_BRANCH | (d->left_size-4));
439 ir_prg[1].address = cpu_to_le32(dma_region_offset_to_bus(&d->dma,
440 (buf + 4) - (unsigned long)d->dma.kvirt));
444 static void initialize_dma_ir_ctx(struct dma_iso_ctx *d, int tag, int flags)
446 struct ti_ohci *ohci = (struct ti_ohci *)d->ohci;
451 ohci1394_stop_context(ohci, d->ctrlClear, NULL);
453 for (i=0;i<d->num_desc;i++) {
454 initialize_dma_ir_prg(d, i, flags);
455 reset_ir_status(d, i);
458 /* reset the ctrl register */
459 reg_write(ohci, d->ctrlClear, 0xf0000000);
462 reg_write(ohci, d->ctrlSet, 0x80000000);
464 /* Set isoch header */
465 if (flags & VIDEO1394_INCLUDE_ISO_HEADERS)
466 reg_write(ohci, d->ctrlSet, 0x40000000);
468 /* Set the context match register to match on all tags,
469 sync for sync tag, and listen to d->channel */
470 reg_write(ohci, d->ctxMatch, 0xf0000000|((tag&0xf)<<8)|d->channel);
472 /* Set up isoRecvIntMask to generate interrupts */
473 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1<<d->ctx);
476 /* find which context is listening to this channel */
477 static struct dma_iso_ctx *
478 find_ctx(struct list_head *list, int type, int channel)
480 struct dma_iso_ctx *ctx;
482 list_for_each_entry(ctx, list, link) {
483 if (ctx->type == type && ctx->channel == channel)
490 void wakeup_dma_ir_ctx(unsigned long l)
492 struct dma_iso_ctx *d = (struct dma_iso_ctx *) l;
497 for (i = 0; i < d->num_desc; i++) {
498 if (d->ir_prg[i][d->nb_cmd-1].status & cpu_to_le32(0xFFFF0000)) {
499 reset_ir_status(d, i);
500 d->buffer_status[i] = VIDEO1394_BUFFER_READY;
501 do_gettimeofday(&d->buffer_time[i]);
505 spin_unlock(&d->lock);
507 if (waitqueue_active(&d->waitq))
508 wake_up_interruptible(&d->waitq);
511 static inline void put_timestamp(struct ti_ohci *ohci, struct dma_iso_ctx * d,
514 unsigned char* buf = d->dma.kvirt + n * d->buf_size;
522 cycleTimer = reg_read(ohci, OHCI1394_IsochronousCycleTimer);
524 timeStamp = ((cycleTimer & 0x0fff) + d->syt_offset); /* 11059 = 450 us */
525 timeStamp = (timeStamp % 3072 + ((timeStamp / 3072) << 12)
526 + (cycleTimer & 0xf000)) & 0xffff;
528 buf[6] = timeStamp >> 8;
529 buf[7] = timeStamp & 0xff;
531 /* if first packet is empty packet, then put timestamp into the next full one too */
532 if ( (le32_to_cpu(d->it_prg[n][0].data[1]) >>16) == 0x008) {
533 buf += d->packet_size;
534 buf[6] = timeStamp >> 8;
535 buf[7] = timeStamp & 0xff;
538 /* do the next buffer frame too in case of irq latency */
539 n = d->next_buffer[n];
543 buf = d->dma.kvirt + n * d->buf_size;
545 timeStamp += (d->last_used_cmd[n] << 12) & 0xffff;
547 buf[6] = timeStamp >> 8;
548 buf[7] = timeStamp & 0xff;
550 /* if first packet is empty packet, then put timestamp into the next full one too */
551 if ( (le32_to_cpu(d->it_prg[n][0].data[1]) >>16) == 0x008) {
552 buf += d->packet_size;
553 buf[6] = timeStamp >> 8;
554 buf[7] = timeStamp & 0xff;
558 printk("curr: %d, next: %d, cycleTimer: %08x timeStamp: %08x\n",
559 curr, n, cycleTimer, timeStamp);
563 void wakeup_dma_it_ctx(unsigned long l)
565 struct dma_iso_ctx *d = (struct dma_iso_ctx *) l;
566 struct ti_ohci *ohci = d->ohci;
571 for (i = 0; i < d->num_desc; i++) {
572 if (d->it_prg[i][d->last_used_cmd[i]].end.status &
573 cpu_to_le32(0xFFFF0000)) {
574 int next = d->next_buffer[i];
575 put_timestamp(ohci, d, next);
576 d->it_prg[i][d->last_used_cmd[i]].end.status = 0;
577 d->buffer_status[i] = VIDEO1394_BUFFER_READY;
581 spin_unlock(&d->lock);
583 if (waitqueue_active(&d->waitq))
584 wake_up_interruptible(&d->waitq);
587 static void initialize_dma_it_prg(struct dma_iso_ctx *d, int n, int sync_tag)
589 struct it_dma_prg *it_prg = d->it_prg[n];
590 struct dma_prog_region *it_reg = &d->prg_reg[n];
591 unsigned long buf = (unsigned long)d->dma.kvirt + n * d->buf_size;
593 d->last_used_cmd[n] = d->nb_cmd - 1;
594 for (i=0;i<d->nb_cmd;i++) {
596 it_prg[i].begin.control = cpu_to_le32(DMA_CTL_OUTPUT_MORE |
597 DMA_CTL_IMMEDIATE | 8) ;
598 it_prg[i].begin.address = 0;
600 it_prg[i].begin.status = 0;
602 it_prg[i].data[0] = cpu_to_le32(
603 (IEEE1394_SPEED_100 << 16)
604 | (/* tag */ 1 << 14)
606 | (TCODE_ISO_DATA << 4));
607 if (i==0) it_prg[i].data[0] |= cpu_to_le32(sync_tag);
608 it_prg[i].data[1] = cpu_to_le32(d->packet_size << 16);
609 it_prg[i].data[2] = 0;
610 it_prg[i].data[3] = 0;
612 it_prg[i].end.control = cpu_to_le32(DMA_CTL_OUTPUT_LAST |
614 it_prg[i].end.address =
615 cpu_to_le32(dma_region_offset_to_bus(&d->dma, (buf+i*d->packet_size) -
616 (unsigned long)d->dma.kvirt));
619 it_prg[i].end.control |= cpu_to_le32(d->packet_size);
620 it_prg[i].begin.branchAddress =
621 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
622 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
623 it_prg[i].end.branchAddress =
624 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
625 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
627 /* the last prg generates an interrupt */
628 it_prg[i].end.control |= cpu_to_le32(DMA_CTL_UPDATE |
629 DMA_CTL_IRQ | d->left_size);
630 /* the last prg doesn't branch */
631 it_prg[i].begin.branchAddress = 0;
632 it_prg[i].end.branchAddress = 0;
634 it_prg[i].end.status = 0;
638 static void initialize_dma_it_prg_var_packet_queue(
639 struct dma_iso_ctx *d, int n, unsigned int * packet_sizes,
640 struct ti_ohci *ohci)
642 struct it_dma_prg *it_prg = d->it_prg[n];
643 struct dma_prog_region *it_reg = &d->prg_reg[n];
648 put_timestamp(ohci, d, n);
651 d->last_used_cmd[n] = d->nb_cmd - 1;
653 for (i = 0; i < d->nb_cmd; i++) {
655 if (packet_sizes[i] > d->packet_size) {
656 size = d->packet_size;
658 size = packet_sizes[i];
660 it_prg[i].data[1] = cpu_to_le32(size << 16);
661 it_prg[i].end.control = cpu_to_le32(DMA_CTL_OUTPUT_LAST | DMA_CTL_BRANCH);
663 if (i < d->nb_cmd-1 && packet_sizes[i+1] != 0) {
664 it_prg[i].end.control |= cpu_to_le32(size);
665 it_prg[i].begin.branchAddress =
666 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
667 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
668 it_prg[i].end.branchAddress =
669 cpu_to_le32((dma_prog_region_offset_to_bus(it_reg, (i + 1) *
670 sizeof(struct it_dma_prg)) & 0xfffffff0) | 0x3);
672 /* the last prg generates an interrupt */
673 it_prg[i].end.control |= cpu_to_le32(DMA_CTL_UPDATE |
675 /* the last prg doesn't branch */
676 it_prg[i].begin.branchAddress = 0;
677 it_prg[i].end.branchAddress = 0;
678 d->last_used_cmd[n] = i;
684 static void initialize_dma_it_ctx(struct dma_iso_ctx *d, int sync_tag,
685 unsigned int syt_offset, int flags)
687 struct ti_ohci *ohci = (struct ti_ohci *)d->ohci;
691 d->syt_offset = (syt_offset == 0 ? 11000 : syt_offset);
693 ohci1394_stop_context(ohci, d->ctrlClear, NULL);
695 for (i=0;i<d->num_desc;i++)
696 initialize_dma_it_prg(d, i, sync_tag);
698 /* Set up isoRecvIntMask to generate interrupts */
699 reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1<<d->ctx);
702 static int video1394_ioctl(struct inode *inode, struct file *file,
703 unsigned int cmd, unsigned long arg)
705 struct file_ctx *ctx = (struct file_ctx *)file->private_data;
706 struct ti_ohci *ohci = ctx->ohci;
708 void __user *argp = (void __user *)arg;
712 case VIDEO1394_IOC_LISTEN_CHANNEL:
713 case VIDEO1394_IOC_TALK_CHANNEL:
715 struct video1394_mmap v;
717 struct dma_iso_ctx *d;
720 if (copy_from_user(&v, argp, sizeof(v)))
723 /* if channel < 0, find lowest available one */
726 for (i=0; i<ISO_CHANNELS; i++) {
727 if (!(ohci->ISO_channel_usage & mask)) {
729 PRINT(KERN_INFO, ohci->host->id, "Found free channel %d", i);
736 if (v.channel<0 || v.channel>(ISO_CHANNELS-1)) {
737 PRINT(KERN_ERR, ohci->host->id,
738 "Iso channel %d out of bounds", v.channel);
741 mask = (u64)0x1<<v.channel;
742 printk("mask: %08X%08X usage: %08X%08X\n",
743 (u32)(mask>>32),(u32)(mask&0xffffffff),
744 (u32)(ohci->ISO_channel_usage>>32),
745 (u32)(ohci->ISO_channel_usage&0xffffffff));
746 if (ohci->ISO_channel_usage & mask) {
747 PRINT(KERN_ERR, ohci->host->id,
748 "Channel %d is already taken", v.channel);
751 ohci->ISO_channel_usage |= mask;
753 if (v.buf_size == 0 || v.buf_size > VIDEO1394_MAX_SIZE) {
754 PRINT(KERN_ERR, ohci->host->id,
755 "Invalid %d length buffer requested",v.buf_size);
759 if (v.nb_buffers == 0 || v.nb_buffers > VIDEO1394_MAX_SIZE) {
760 PRINT(KERN_ERR, ohci->host->id,
761 "Invalid %d buffers requested",v.nb_buffers);
765 if (v.nb_buffers * v.buf_size > VIDEO1394_MAX_SIZE) {
766 PRINT(KERN_ERR, ohci->host->id,
767 "%d buffers of size %d bytes is too big",
768 v.nb_buffers, v.buf_size);
772 if (cmd == VIDEO1394_IOC_LISTEN_CHANNEL) {
773 d = alloc_dma_iso_ctx(ohci, OHCI_ISO_RECEIVE,
774 v.nb_buffers, v.buf_size,
778 PRINT(KERN_ERR, ohci->host->id,
779 "Couldn't allocate ir context");
782 initialize_dma_ir_ctx(d, v.sync_tag, v.flags);
784 ctx->current_ctx = d;
786 v.buf_size = d->buf_size;
787 list_add_tail(&d->link, &ctx->context_list);
789 PRINT(KERN_INFO, ohci->host->id,
790 "iso context %d listen on channel %d",
794 d = alloc_dma_iso_ctx(ohci, OHCI_ISO_TRANSMIT,
795 v.nb_buffers, v.buf_size,
796 v.channel, v.packet_size);
799 PRINT(KERN_ERR, ohci->host->id,
800 "Couldn't allocate it context");
803 initialize_dma_it_ctx(d, v.sync_tag,
804 v.syt_offset, v.flags);
806 ctx->current_ctx = d;
808 v.buf_size = d->buf_size;
810 list_add_tail(&d->link, &ctx->context_list);
812 PRINT(KERN_INFO, ohci->host->id,
813 "Iso context %d talk on channel %d", d->ctx,
817 if (copy_to_user(argp, &v, sizeof(v)))
822 case VIDEO1394_IOC_UNLISTEN_CHANNEL:
823 case VIDEO1394_IOC_UNTALK_CHANNEL:
827 struct dma_iso_ctx *d;
829 if (copy_from_user(&channel, argp, sizeof(int)))
832 if (channel<0 || channel>(ISO_CHANNELS-1)) {
833 PRINT(KERN_ERR, ohci->host->id,
834 "Iso channel %d out of bound", channel);
837 mask = (u64)0x1<<channel;
838 if (!(ohci->ISO_channel_usage & mask)) {
839 PRINT(KERN_ERR, ohci->host->id,
840 "Channel %d is not being used", channel);
844 /* Mark this channel as unused */
845 ohci->ISO_channel_usage &= ~mask;
847 if (cmd == VIDEO1394_IOC_UNLISTEN_CHANNEL)
848 d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, channel);
850 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, channel);
852 if (d == NULL) return -EFAULT;
853 PRINT(KERN_INFO, ohci->host->id, "Iso context %d "
854 "stop talking on channel %d", d->ctx, channel);
859 case VIDEO1394_IOC_LISTEN_QUEUE_BUFFER:
861 struct video1394_wait v;
862 struct dma_iso_ctx *d;
864 if (copy_from_user(&v, argp, sizeof(v)))
867 d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
868 if (d == NULL) return -EFAULT;
870 if ((v.buffer<0) || (v.buffer>d->num_desc)) {
871 PRINT(KERN_ERR, ohci->host->id,
872 "Buffer %d out of range",v.buffer);
876 spin_lock_irqsave(&d->lock,flags);
878 if (d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED) {
879 PRINT(KERN_ERR, ohci->host->id,
880 "Buffer %d is already used",v.buffer);
881 spin_unlock_irqrestore(&d->lock,flags);
885 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_QUEUED;
887 if (d->last_buffer>=0)
888 d->ir_prg[d->last_buffer][d->nb_cmd-1].branchAddress =
889 cpu_to_le32((dma_prog_region_offset_to_bus(&d->prg_reg[v.buffer], 0)
890 & 0xfffffff0) | 0x1);
892 d->last_buffer = v.buffer;
894 d->ir_prg[d->last_buffer][d->nb_cmd-1].branchAddress = 0;
896 spin_unlock_irqrestore(&d->lock,flags);
898 if (!(reg_read(ohci, d->ctrlSet) & 0x8000))
900 DBGMSG(ohci->host->id, "Starting iso DMA ctx=%d",d->ctx);
902 /* Tell the controller where the first program is */
903 reg_write(ohci, d->cmdPtr,
904 dma_prog_region_offset_to_bus(&d->prg_reg[v.buffer], 0) | 0x1);
907 reg_write(ohci, d->ctrlSet, 0x8000);
910 /* Wake up dma context if necessary */
911 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) {
912 PRINT(KERN_INFO, ohci->host->id,
913 "Waking up iso dma ctx=%d", d->ctx);
914 reg_write(ohci, d->ctrlSet, 0x1000);
920 case VIDEO1394_IOC_LISTEN_WAIT_BUFFER:
921 case VIDEO1394_IOC_LISTEN_POLL_BUFFER:
923 struct video1394_wait v;
924 struct dma_iso_ctx *d;
927 if (copy_from_user(&v, argp, sizeof(v)))
930 d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
931 if (d == NULL) return -EFAULT;
933 if ((v.buffer<0) || (v.buffer>d->num_desc)) {
934 PRINT(KERN_ERR, ohci->host->id,
935 "Buffer %d out of range",v.buffer);
940 * I change the way it works so that it returns
941 * the last received frame.
943 spin_lock_irqsave(&d->lock, flags);
944 switch(d->buffer_status[v.buffer]) {
945 case VIDEO1394_BUFFER_READY:
946 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
948 case VIDEO1394_BUFFER_QUEUED:
949 if (cmd == VIDEO1394_IOC_LISTEN_POLL_BUFFER) {
950 /* for polling, return error code EINTR */
951 spin_unlock_irqrestore(&d->lock, flags);
956 while (d->buffer_status[v.buffer]!=
957 VIDEO1394_BUFFER_READY) {
958 spin_unlock_irqrestore(&d->lock, flags);
959 interruptible_sleep_on(&d->waitq);
960 spin_lock_irqsave(&d->lock, flags);
961 if (signal_pending(current)) {
962 spin_unlock_irqrestore(&d->lock,flags);
967 if (wait_event_interruptible(d->waitq,
968 d->buffer_status[v.buffer]
969 == VIDEO1394_BUFFER_READY)
973 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
976 PRINT(KERN_ERR, ohci->host->id,
977 "Buffer %d is not queued",v.buffer);
978 spin_unlock_irqrestore(&d->lock, flags);
982 /* set time of buffer */
983 v.filltime = d->buffer_time[v.buffer];
984 // printk("Buffer %d time %d\n", v.buffer, (d->buffer_time[v.buffer]).tv_usec);
987 * Look ahead to see how many more buffers have been received
990 while (d->buffer_status[(v.buffer+1)%d->num_desc]==
991 VIDEO1394_BUFFER_READY) {
992 v.buffer=(v.buffer+1)%d->num_desc;
995 spin_unlock_irqrestore(&d->lock, flags);
998 if (copy_to_user(argp, &v, sizeof(v)))
1003 case VIDEO1394_IOC_TALK_QUEUE_BUFFER:
1005 struct video1394_wait v;
1006 unsigned int *psizes = NULL;
1007 struct dma_iso_ctx *d;
1009 if (copy_from_user(&v, argp, sizeof(v)))
1012 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
1013 if (d == NULL) return -EFAULT;
1015 if ((v.buffer<0) || (v.buffer>d->num_desc)) {
1016 PRINT(KERN_ERR, ohci->host->id,
1017 "Buffer %d out of range",v.buffer);
1021 if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) {
1022 int buf_size = d->nb_cmd * sizeof(unsigned int);
1023 struct video1394_queue_variable __user *p = argp;
1024 unsigned int __user *qv;
1026 if (get_user(qv, &p->packet_sizes))
1029 psizes = kmalloc(buf_size, GFP_KERNEL);
1033 if (copy_from_user(psizes, qv, buf_size)) {
1039 spin_lock_irqsave(&d->lock,flags);
1041 if (d->buffer_status[v.buffer]!=VIDEO1394_BUFFER_FREE) {
1042 PRINT(KERN_ERR, ohci->host->id,
1043 "Buffer %d is already used",v.buffer);
1044 spin_unlock_irqrestore(&d->lock,flags);
1050 if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) {
1051 initialize_dma_it_prg_var_packet_queue(
1052 d, v.buffer, psizes,
1056 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_QUEUED;
1058 if (d->last_buffer >= 0) {
1059 d->it_prg[d->last_buffer]
1060 [ d->last_used_cmd[d->last_buffer] ].end.branchAddress =
1061 cpu_to_le32((dma_prog_region_offset_to_bus(&d->prg_reg[v.buffer],
1062 0) & 0xfffffff0) | 0x3);
1064 d->it_prg[d->last_buffer]
1065 [ d->last_used_cmd[d->last_buffer] ].begin.branchAddress =
1066 cpu_to_le32((dma_prog_region_offset_to_bus(&d->prg_reg[v.buffer],
1067 0) & 0xfffffff0) | 0x3);
1068 d->next_buffer[d->last_buffer] = v.buffer;
1070 d->last_buffer = v.buffer;
1071 d->next_buffer[d->last_buffer] = -1;
1073 d->it_prg[d->last_buffer][d->last_used_cmd[d->last_buffer]].end.branchAddress = 0;
1075 spin_unlock_irqrestore(&d->lock,flags);
1077 if (!(reg_read(ohci, d->ctrlSet) & 0x8000))
1079 DBGMSG(ohci->host->id, "Starting iso transmit DMA ctx=%d",
1081 put_timestamp(ohci, d, d->last_buffer);
1083 /* Tell the controller where the first program is */
1084 reg_write(ohci, d->cmdPtr,
1085 dma_prog_region_offset_to_bus(&d->prg_reg[v.buffer], 0) | 0x3);
1087 /* Run IT context */
1088 reg_write(ohci, d->ctrlSet, 0x8000);
1091 /* Wake up dma context if necessary */
1092 if (!(reg_read(ohci, d->ctrlSet) & 0x400)) {
1093 PRINT(KERN_INFO, ohci->host->id,
1094 "Waking up iso transmit dma ctx=%d",
1096 put_timestamp(ohci, d, d->last_buffer);
1097 reg_write(ohci, d->ctrlSet, 0x1000);
1107 case VIDEO1394_IOC_TALK_WAIT_BUFFER:
1109 struct video1394_wait v;
1110 struct dma_iso_ctx *d;
1112 if (copy_from_user(&v, argp, sizeof(v)))
1115 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
1116 if (d == NULL) return -EFAULT;
1118 if ((v.buffer<0) || (v.buffer>d->num_desc)) {
1119 PRINT(KERN_ERR, ohci->host->id,
1120 "Buffer %d out of range",v.buffer);
1124 switch(d->buffer_status[v.buffer]) {
1125 case VIDEO1394_BUFFER_READY:
1126 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
1128 case VIDEO1394_BUFFER_QUEUED:
1130 while (d->buffer_status[v.buffer]!=
1131 VIDEO1394_BUFFER_READY) {
1132 interruptible_sleep_on(&d->waitq);
1133 if (signal_pending(current)) return -EINTR;
1136 if (wait_event_interruptible(d->waitq,
1137 d->buffer_status[v.buffer]
1138 == VIDEO1394_BUFFER_READY)
1142 d->buffer_status[v.buffer]=VIDEO1394_BUFFER_FREE;
1145 PRINT(KERN_ERR, ohci->host->id,
1146 "Buffer %d is not queued",v.buffer);
1156 * This maps the vmalloced and reserved buffer to user space.
1159 * - PAGE_READONLY should suffice!?
1160 * - remap_page_range is kind of inefficient for page by page remapping.
1161 * But e.g. pte_alloc() does not work in modules ... :-(
1164 int video1394_mmap(struct file *file, struct vm_area_struct *vma)
1166 struct file_ctx *ctx = (struct file_ctx *)file->private_data;
1170 if (ctx->current_ctx == NULL) {
1171 PRINT(KERN_ERR, ctx->ohci->host->id, "Current iso context not set");
1173 res = dma_region_mmap(&ctx->current_ctx->dma, file, vma);
1179 static int video1394_open(struct inode *inode, struct file *file)
1181 int i = ieee1394_file_to_instance(file);
1182 struct ti_ohci *ohci;
1183 struct file_ctx *ctx;
1185 ohci = hpsb_get_hostinfo_bykey(&video1394_highlevel, i);
1189 ctx = kmalloc(sizeof(struct file_ctx), GFP_KERNEL);
1191 PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx");
1195 memset(ctx, 0, sizeof(struct file_ctx));
1197 INIT_LIST_HEAD(&ctx->context_list);
1198 ctx->current_ctx = NULL;
1199 file->private_data = ctx;
1204 static int video1394_release(struct inode *inode, struct file *file)
1206 struct file_ctx *ctx = (struct file_ctx *)file->private_data;
1207 struct ti_ohci *ohci = ctx->ohci;
1208 struct list_head *lh, *next;
1212 list_for_each_safe(lh, next, &ctx->context_list) {
1213 struct dma_iso_ctx *d;
1214 d = list_entry(lh, struct dma_iso_ctx, link);
1215 mask = (u64) 1 << d->channel;
1217 if (!(ohci->ISO_channel_usage & mask))
1218 PRINT(KERN_ERR, ohci->host->id, "On release: Channel %d "
1219 "is not being used", d->channel);
1221 ohci->ISO_channel_usage &= ~mask;
1222 PRINT(KERN_INFO, ohci->host->id, "On release: Iso %s context "
1223 "%d stop listening on channel %d",
1224 d->type == OHCI_ISO_RECEIVE ? "receive" : "transmit",
1225 d->ctx, d->channel);
1226 free_dma_iso_ctx(d);
1230 file->private_data = NULL;
1236 static struct cdev video1394_cdev;
1237 static struct file_operations video1394_fops=
1239 .owner = THIS_MODULE,
1240 .ioctl = video1394_ioctl,
1241 .mmap = video1394_mmap,
1242 .open = video1394_open,
1243 .release = video1394_release
1246 /*** HOTPLUG STUFF **********************************************************/
1248 * Export information about protocols/devices supported by this driver.
1250 static struct ieee1394_device_id video1394_id_table[] = {
1252 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
1253 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
1254 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff
1259 MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
1261 static struct hpsb_protocol_driver video1394_driver = {
1262 .name = "1394 Digital Camera Driver",
1263 .id_table = video1394_id_table,
1265 .name = VIDEO1394_DRIVER_NAME,
1266 .bus = &ieee1394_bus_type,
1271 static void video1394_add_host (struct hpsb_host *host)
1273 struct ti_ohci *ohci;
1276 /* We only work with the OHCI-1394 driver */
1277 if (strcmp(host->driver->name, OHCI1394_DRIVER_NAME))
1280 ohci = (struct ti_ohci *)host->hostdata;
1282 if (!hpsb_create_hostinfo(&video1394_highlevel, host, 0)) {
1283 PRINT(KERN_ERR, ohci->host->id, "Cannot allocate hostinfo");
1287 hpsb_set_hostinfo(&video1394_highlevel, host, ohci);
1288 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id);
1290 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id;
1291 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, minor),
1292 S_IFCHR | S_IRUSR | S_IWUSR,
1293 "%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1297 static void video1394_remove_host (struct hpsb_host *host)
1299 struct ti_ohci *ohci = hpsb_get_hostinfo(&video1394_highlevel, host);
1302 devfs_remove("%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1308 static struct hpsb_highlevel video1394_highlevel = {
1309 .name = VIDEO1394_DRIVER_NAME,
1310 .add_host = video1394_add_host,
1311 .remove_host = video1394_remove_host,
1314 MODULE_AUTHOR("Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>");
1315 MODULE_DESCRIPTION("driver for digital video on OHCI board");
1316 MODULE_SUPPORTED_DEVICE(VIDEO1394_DRIVER_NAME);
1317 MODULE_LICENSE("GPL");
1319 #ifdef CONFIG_COMPAT
1321 #define VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER \
1322 _IOW ('#', 0x12, struct video1394_wait32)
1323 #define VIDEO1394_IOC32_LISTEN_WAIT_BUFFER \
1324 _IOWR('#', 0x13, struct video1394_wait32)
1325 #define VIDEO1394_IOC32_TALK_WAIT_BUFFER \
1326 _IOW ('#', 0x17, struct video1394_wait32)
1327 #define VIDEO1394_IOC32_LISTEN_POLL_BUFFER \
1328 _IOWR('#', 0x18, struct video1394_wait32)
1330 struct video1394_wait32 {
1333 struct compat_timeval filltime;
1336 static int video1394_wr_wait32(unsigned int fd, unsigned int cmd, unsigned long arg,
1339 struct video1394_wait32 __user *argp = (void __user *)arg;
1340 struct video1394_wait32 wait32;
1341 struct video1394_wait wait;
1342 mm_segment_t old_fs;
1345 if (file->f_op->ioctl != video1394_ioctl)
1348 if (copy_from_user(&wait32, argp, sizeof(wait32)))
1351 wait.channel = wait32.channel;
1352 wait.buffer = wait32.buffer;
1353 wait.filltime.tv_sec = (time_t)wait32.filltime.tv_sec;
1354 wait.filltime.tv_usec = (suseconds_t)wait32.filltime.tv_usec;
1358 if (cmd == VIDEO1394_IOC32_LISTEN_WAIT_BUFFER)
1359 ret = video1394_ioctl(file->f_dentry->d_inode, file,
1360 VIDEO1394_IOC_LISTEN_WAIT_BUFFER,
1361 (unsigned long) &wait);
1363 ret = video1394_ioctl(file->f_dentry->d_inode, file,
1364 VIDEO1394_IOC_LISTEN_POLL_BUFFER,
1365 (unsigned long) &wait);
1369 wait32.channel = wait.channel;
1370 wait32.buffer = wait.buffer;
1371 wait32.filltime.tv_sec = (int)wait.filltime.tv_sec;
1372 wait32.filltime.tv_usec = (int)wait.filltime.tv_usec;
1374 if (copy_to_user(argp, &wait32, sizeof(wait32)))
1381 static int video1394_w_wait32(unsigned int fd, unsigned int cmd, unsigned long arg,
1384 struct video1394_wait32 wait32;
1385 struct video1394_wait wait;
1386 mm_segment_t old_fs;
1389 if (file->f_op->ioctl != video1394_ioctl)
1392 if (copy_from_user(&wait32, (void __user *)arg, sizeof(wait32)))
1395 wait.channel = wait32.channel;
1396 wait.buffer = wait32.buffer;
1397 wait.filltime.tv_sec = (time_t)wait32.filltime.tv_sec;
1398 wait.filltime.tv_usec = (suseconds_t)wait32.filltime.tv_usec;
1402 if (cmd == VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER)
1403 ret = video1394_ioctl(file->f_dentry->d_inode, file,
1404 VIDEO1394_IOC_LISTEN_QUEUE_BUFFER,
1405 (unsigned long) &wait);
1407 ret = video1394_ioctl(file->f_dentry->d_inode, file,
1408 VIDEO1394_IOC_TALK_WAIT_BUFFER,
1409 (unsigned long) &wait);
1415 static int video1394_queue_buf32(unsigned int fd, unsigned int cmd, unsigned long arg,
1418 if (file->f_op->ioctl != video1394_ioctl)
1423 return video1394_ioctl(file->f_dentry->d_inode, file,
1424 VIDEO1394_IOC_TALK_QUEUE_BUFFER, arg);
1427 #endif /* CONFIG_COMPAT */
1429 static void __exit video1394_exit_module (void)
1431 #ifdef CONFIG_COMPAT
1434 ret = unregister_ioctl32_conversion(VIDEO1394_IOC_LISTEN_CHANNEL);
1435 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC_UNLISTEN_CHANNEL);
1436 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC_TALK_CHANNEL);
1437 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC_UNTALK_CHANNEL);
1438 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER);
1439 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC32_LISTEN_WAIT_BUFFER);
1440 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC_TALK_QUEUE_BUFFER);
1441 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC32_TALK_WAIT_BUFFER);
1442 ret |= unregister_ioctl32_conversion(VIDEO1394_IOC32_LISTEN_POLL_BUFFER);
1444 PRINT_G(KERN_CRIT, "Error unregistering ioctl32 translations");
1447 hpsb_unregister_protocol(&video1394_driver);
1449 hpsb_unregister_highlevel(&video1394_highlevel);
1451 devfs_remove(VIDEO1394_DRIVER_NAME);
1452 cdev_del(&video1394_cdev);
1454 PRINT_G(KERN_INFO, "Removed " VIDEO1394_DRIVER_NAME " module");
1457 static int __init video1394_init_module (void)
1461 cdev_init(&video1394_cdev, &video1394_fops);
1462 video1394_cdev.owner = THIS_MODULE;
1463 kobject_set_name(&video1394_cdev.kobj, VIDEO1394_DRIVER_NAME);
1464 ret = cdev_add(&video1394_cdev, IEEE1394_VIDEO1394_DEV, 16);
1466 PRINT_G(KERN_ERR, "video1394: unable to get minor device block");
1470 devfs_mk_dir(VIDEO1394_DRIVER_NAME);
1472 hpsb_register_highlevel(&video1394_highlevel);
1474 ret = hpsb_register_protocol(&video1394_driver);
1476 PRINT_G(KERN_ERR, "video1394: failed to register protocol");
1477 hpsb_unregister_highlevel(&video1394_highlevel);
1478 devfs_remove(VIDEO1394_DRIVER_NAME);
1479 cdev_del(&video1394_cdev);
1483 #ifdef CONFIG_COMPAT
1485 /* First the compatible ones */
1486 ret = register_ioctl32_conversion(VIDEO1394_IOC_LISTEN_CHANNEL, NULL);
1487 ret |= register_ioctl32_conversion(VIDEO1394_IOC_UNLISTEN_CHANNEL, NULL);
1488 ret |= register_ioctl32_conversion(VIDEO1394_IOC_TALK_CHANNEL, NULL);
1489 ret |= register_ioctl32_conversion(VIDEO1394_IOC_UNTALK_CHANNEL, NULL);
1491 /* These need translation */
1492 ret |= register_ioctl32_conversion(VIDEO1394_IOC32_LISTEN_QUEUE_BUFFER,
1493 video1394_w_wait32);
1494 ret |= register_ioctl32_conversion(VIDEO1394_IOC32_LISTEN_WAIT_BUFFER,
1495 video1394_wr_wait32);
1496 ret |= register_ioctl32_conversion(VIDEO1394_IOC_TALK_QUEUE_BUFFER,
1497 video1394_queue_buf32);
1498 ret |= register_ioctl32_conversion(VIDEO1394_IOC32_TALK_WAIT_BUFFER,
1499 video1394_w_wait32);
1500 ret |= register_ioctl32_conversion(VIDEO1394_IOC32_LISTEN_POLL_BUFFER,
1501 video1394_wr_wait32);
1503 PRINT_G(KERN_INFO, "Error registering ioctl32 translations");
1507 PRINT_G(KERN_INFO, "Installed " VIDEO1394_DRIVER_NAME " module");
1512 module_init(video1394_init_module);
1513 module_exit(video1394_exit_module);
1514 MODULE_ALIAS_CHARDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16);