initial commit with v2.6.9
[linux-2.6.9-moxart.git] / sound / drivers / mtpav.c
blob2c572345c90bf138ad6607bf7f017a19b160baf8
1 /*
2 * MOTU Midi Timepiece ALSA Main routines
3 * Copyright by Michael T. Mayers (c) Jan 09, 2000
4 * mail: michael@tweakoz.com
5 * Thanks to John Galbraith
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * This driver is for the 'Mark Of The Unicorn' (MOTU)
23 * MidiTimePiece AV multiport MIDI interface
25 * IOPORTS
26 * -------
27 * 8 MIDI Ins and 8 MIDI outs
28 * Video Sync In (BNC), Word Sync Out (BNC),
29 * ADAT Sync Out (DB9)
30 * SMPTE in/out (1/4")
31 * 2 programmable pedal/footswitch inputs and 4 programmable MIDI controller knobs.
32 * Macintosh RS422 serial port
33 * RS422 "network" port for ganging multiple MTP's
34 * PC Parallel Port ( which this driver currently uses )
36 * MISC FEATURES
37 * -------------
38 * Hardware MIDI routing, merging, and filtering
39 * MIDI Synchronization to Video, ADAT, SMPTE and other Clock sources
40 * 128 'scene' memories, recallable from MIDI program change
43 * ChangeLog
44 * Jun 11 2001 Takashi Iwai <tiwai@suse.de>
45 * - Recoded & debugged
46 * - Added timer interrupt for midi outputs
47 * - hwports is between 1 and 8, which specifies the number of hardware ports.
48 * The three global ports, computer, adat and broadcast ports, are created
49 * always after h/w and remote ports.
53 #include <sound/driver.h>
54 #include <linux/init.h>
55 #include <linux/interrupt.h>
56 #include <linux/slab.h>
57 #include <linux/ioport.h>
58 #include <linux/moduleparam.h>
59 #include <sound/core.h>
60 #include <sound/initval.h>
61 #include <sound/rawmidi.h>
62 #include <linux/delay.h>
64 #include <asm/io.h>
67 * globals
69 MODULE_AUTHOR("Michael T. Mayers");
70 MODULE_DESCRIPTION("MOTU MidiTimePiece AV multiport MIDI");
71 MODULE_LICENSE("GPL");
72 MODULE_SUPPORTED_DEVICE("{{MOTU,MidiTimePiece AV multiport MIDI}}");
74 // io resources
75 #define MTPAV_IOBASE 0x378
76 #define MTPAV_IRQ 7
77 #define MTPAV_MAX_PORTS 8
79 static int index = SNDRV_DEFAULT_IDX1;
80 static char *id = SNDRV_DEFAULT_STR1;
81 static long port = MTPAV_IOBASE; /* 0x378, 0x278 */
82 static int irq = MTPAV_IRQ; /* 7, 5 */
83 static int hwports = MTPAV_MAX_PORTS; /* use hardware ports 1-8 */
85 module_param(index, int, 0444);
86 MODULE_PARM_DESC(index, "Index value for MotuMTPAV MIDI.");
87 module_param(id, charp, 0444);
88 MODULE_PARM_DESC(id, "ID string for MotuMTPAV MIDI.");
89 module_param(port, long, 0444);
90 MODULE_PARM_DESC(port, "Parallel port # for MotuMTPAV MIDI.");
91 module_param(irq, int, 0444);
92 MODULE_PARM_DESC(irq, "Parallel IRQ # for MotuMTPAV MIDI.");
93 module_param(hwports, int, 0444);
94 MODULE_PARM_DESC(hwports, "Hardware ports # for MotuMTPAV MIDI.");
97 * defines
99 //#define USE_FAKE_MTP // don't actually read/write to MTP device (for debugging without an actual unit) (does not work yet)
101 // parallel port usage masks
102 #define SIGS_BYTE 0x08
103 #define SIGS_RFD 0x80
104 #define SIGS_IRQ 0x40
105 #define SIGS_IN0 0x10
106 #define SIGS_IN1 0x20
108 #define SIGC_WRITE 0x04
109 #define SIGC_READ 0x08
110 #define SIGC_INTEN 0x10
112 #define DREG 0
113 #define SREG 1
114 #define CREG 2
117 #define MTPAV_MODE_INPUT_OPENED 0x01
118 #define MTPAV_MODE_OUTPUT_OPENED 0x02
119 #define MTPAV_MODE_INPUT_TRIGGERED 0x04
120 #define MTPAV_MODE_OUTPUT_TRIGGERED 0x08
122 #define NUMPORTS (0x12+1)
128 typedef struct mtpav_port {
129 u8 number;
130 u8 hwport;
131 u8 mode;
132 u8 running_status;
133 snd_rawmidi_substream_t *input;
134 snd_rawmidi_substream_t *output;
135 } mtpav_port_t;
137 typedef struct mtpav {
138 snd_card_t *card;
139 unsigned long port;
140 struct resource *res_port;
141 int irq; /* interrupt (for inputs) */
142 spinlock_t spinlock;
143 int share_irq; /* number of accesses to input interrupts */
144 int istimer; /* number of accesses to timer interrupts */
145 struct timer_list timer; /* timer interrupts for outputs */
146 snd_rawmidi_t *rmidi;
147 int num_ports; /* number of hw ports (1-8) */
148 mtpav_port_t ports[NUMPORTS]; /* all ports including computer, adat and bc */
150 u32 inmidiport; /* selected input midi port */
151 u32 inmidistate; /* during midi command 0xf5 */
153 u32 outmidihwport; /* selected output midi hw port */
154 } mtpav_t;
158 * global instance
159 * hey, we handle at most only one card..
161 static mtpav_t *mtp_card;
164 * possible hardware ports (selected by 0xf5 port message)
165 * 0x00 all ports
166 * 0x01 .. 0x08 this MTP's ports 1..8
167 * 0x09 .. 0x10 networked MTP's ports (9..16)
168 * 0x11 networked MTP's computer port
169 * 0x63 to ADAT
171 * mappig:
172 * subdevice 0 - (X-1) ports
173 * X - (2*X-1) networked ports
174 * X computer
175 * X+1 ADAT
176 * X+2 all ports
178 * where X = chip->num_ports
181 #define MTPAV_PIDX_COMPUTER 0
182 #define MTPAV_PIDX_ADAT 1
183 #define MTPAV_PIDX_BROADCAST 2
186 static int translate_subdevice_to_hwport(mtpav_t *chip, int subdev)
188 if (subdev < 0)
189 return 0x01; /* invalid - use port 0 as default */
190 else if (subdev < chip->num_ports)
191 return subdev + 1; /* single mtp port */
192 else if (subdev < chip->num_ports * 2)
193 return subdev - chip->num_ports + 0x09; /* remote port */
194 else if (subdev == chip->num_ports * 2 + MTPAV_PIDX_COMPUTER)
195 return 0x11; /* computer port */
196 else if (subdev == chip->num_ports + MTPAV_PIDX_ADAT)
197 return 0x63; /* ADAT */
198 return 0; /* all ports */
201 static int translate_hwport_to_subdevice(mtpav_t *chip, int hwport)
203 int p;
204 if (hwport <= 0x00) /* all ports */
205 return chip->num_ports + MTPAV_PIDX_BROADCAST;
206 else if (hwport <= 0x08) { /* single port */
207 p = hwport - 1;
208 if (p >= chip->num_ports)
209 p = 0;
210 return p;
211 } else if (hwport <= 0x10) { /* remote port */
212 p = hwport - 0x09 + chip->num_ports;
213 if (p >= chip->num_ports * 2)
214 p = chip->num_ports;
215 return p;
216 } else if (hwport == 0x11) /* computer port */
217 return chip->num_ports + MTPAV_PIDX_COMPUTER;
218 else /* ADAT */
219 return chip->num_ports + MTPAV_PIDX_ADAT;
226 static u8 snd_mtpav_getreg(mtpav_t *chip, u16 reg)
228 u8 rval = 0;
230 if (reg == SREG) {
231 rval = inb(chip->port + SREG);
232 rval = (rval & 0xf8);
233 } else if (reg == CREG) {
234 rval = inb(chip->port + CREG);
235 rval = (rval & 0x1c);
238 return rval;
244 static void snd_mtpav_mputreg(mtpav_t *chip, u16 reg, u8 val)
246 if (reg == DREG) {
247 outb(val, chip->port + DREG);
248 } else if (reg == CREG) {
249 outb(val, chip->port + CREG);
256 static void snd_mtpav_wait_rfdhi(mtpav_t *chip)
258 int counts = 10000;
259 u8 sbyte;
261 sbyte = snd_mtpav_getreg(chip, SREG);
262 while (!(sbyte & SIGS_RFD) && counts--) {
263 sbyte = snd_mtpav_getreg(chip, SREG);
264 udelay(10);
268 static void snd_mtpav_send_byte(mtpav_t *chip, u8 byte)
270 u8 tcbyt;
271 u8 clrwrite;
272 u8 setwrite;
274 snd_mtpav_wait_rfdhi(chip);
276 /////////////////
278 tcbyt = snd_mtpav_getreg(chip, CREG);
279 clrwrite = tcbyt & (SIGC_WRITE ^ 0xff);
280 setwrite = tcbyt | SIGC_WRITE;
282 snd_mtpav_mputreg(chip, DREG, byte);
283 snd_mtpav_mputreg(chip, CREG, clrwrite); // clear write bit
285 snd_mtpav_mputreg(chip, CREG, setwrite); // set write bit
293 /* call this with spin lock held */
294 static void snd_mtpav_output_port_write(mtpav_port_t *port,
295 snd_rawmidi_substream_t *substream)
297 u8 outbyte;
299 // Get the outbyte first, so we can emulate running status if
300 // necessary
301 if (snd_rawmidi_transmit(substream, &outbyte, 1) != 1)
302 return;
304 // send port change command if necessary
306 if (port->hwport != mtp_card->outmidihwport) {
307 mtp_card->outmidihwport = port->hwport;
309 snd_mtpav_send_byte(mtp_card, 0xf5);
310 snd_mtpav_send_byte(mtp_card, port->hwport);
311 //snd_printk("new outport: 0x%x\n", (unsigned int) port->hwport);
313 if (!(outbyte & 0x80) && port->running_status)
314 snd_mtpav_send_byte(mtp_card, port->running_status);
317 // send data
319 do {
320 if (outbyte & 0x80)
321 port->running_status = outbyte;
323 snd_mtpav_send_byte(mtp_card, outbyte);
324 } while (snd_rawmidi_transmit(substream, &outbyte, 1) == 1);
327 static void snd_mtpav_output_write(snd_rawmidi_substream_t * substream)
329 mtpav_port_t *port = &mtp_card->ports[substream->number];
330 unsigned long flags;
332 spin_lock_irqsave(&mtp_card->spinlock, flags);
333 snd_mtpav_output_port_write(port, substream);
334 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
339 * mtpav control
342 static void snd_mtpav_portscan(mtpav_t *chip) // put mtp into smart routing mode
344 u8 p;
346 for (p = 0; p < 8; p++) {
347 snd_mtpav_send_byte(chip, 0xf5);
348 snd_mtpav_send_byte(chip, p);
349 snd_mtpav_send_byte(chip, 0xfe);
356 static int snd_mtpav_input_open(snd_rawmidi_substream_t * substream)
358 unsigned long flags;
359 mtpav_port_t *portp = &mtp_card->ports[substream->number];
361 //printk("mtpav port: %d opened\n", (int) substream->number);
362 spin_lock_irqsave(&mtp_card->spinlock, flags);
363 portp->mode |= MTPAV_MODE_INPUT_OPENED;
364 portp->input = substream;
365 if (mtp_card->share_irq++ == 0)
366 snd_mtpav_mputreg(mtp_card, CREG, (SIGC_INTEN | SIGC_WRITE)); // enable pport interrupts
367 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
368 return 0;
374 static int snd_mtpav_input_close(snd_rawmidi_substream_t *substream)
376 unsigned long flags;
377 mtpav_port_t *portp = &mtp_card->ports[substream->number];
379 //printk("mtpav port: %d closed\n", (int) portp);
381 spin_lock_irqsave(&mtp_card->spinlock, flags);
383 portp->mode &= (~MTPAV_MODE_INPUT_OPENED);
384 portp->input = NULL;
385 if (--mtp_card->share_irq == 0)
386 snd_mtpav_mputreg(mtp_card, CREG, 0); // disable pport interrupts
388 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
389 return 0;
395 static void snd_mtpav_input_trigger(snd_rawmidi_substream_t * substream, int up)
397 unsigned long flags;
398 mtpav_port_t *portp = &mtp_card->ports[substream->number];
400 spin_lock_irqsave(&mtp_card->spinlock, flags);
401 if (up)
402 portp->mode |= MTPAV_MODE_INPUT_TRIGGERED;
403 else
404 portp->mode &= ~MTPAV_MODE_INPUT_TRIGGERED;
405 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
411 * timer interrupt for outputs
414 static void snd_mtpav_output_timer(unsigned long data)
416 mtpav_t *chip = (mtpav_t *)data;
417 int p;
419 spin_lock(&chip->spinlock);
420 /* reprogram timer */
421 chip->timer.expires = 1 + jiffies;
422 add_timer(&chip->timer);
423 /* process each port */
424 for (p = 0; p <= chip->num_ports * 2 + MTPAV_PIDX_BROADCAST; p++) {
425 mtpav_port_t *portp = &mtp_card->ports[p];
426 if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output)
427 snd_mtpav_output_port_write(portp, portp->output);
429 spin_unlock(&chip->spinlock);
432 /* spinlock held! */
433 static void snd_mtpav_add_output_timer(mtpav_t *chip)
435 init_timer(&chip->timer);
436 chip->timer.function = snd_mtpav_output_timer;
437 chip->timer.data = (unsigned long) mtp_card;
438 chip->timer.expires = 1 + jiffies;
439 add_timer(&chip->timer);
442 /* spinlock held! */
443 static void snd_mtpav_remove_output_timer(mtpav_t *chip)
445 del_timer(&chip->timer);
451 static int snd_mtpav_output_open(snd_rawmidi_substream_t * substream)
453 unsigned long flags;
454 mtpav_port_t *portp = &mtp_card->ports[substream->number];
456 spin_lock_irqsave(&mtp_card->spinlock, flags);
457 portp->mode |= MTPAV_MODE_OUTPUT_OPENED;
458 portp->output = substream;
459 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
460 return 0;
466 static int snd_mtpav_output_close(snd_rawmidi_substream_t * substream)
468 unsigned long flags;
469 mtpav_port_t *portp = &mtp_card->ports[substream->number];
471 spin_lock_irqsave(&mtp_card->spinlock, flags);
472 portp->mode &= (~MTPAV_MODE_OUTPUT_OPENED);
473 portp->output = NULL;
474 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
475 return 0;
481 static void snd_mtpav_output_trigger(snd_rawmidi_substream_t * substream, int up)
483 unsigned long flags;
484 mtpav_port_t *portp = &mtp_card->ports[substream->number];
486 spin_lock_irqsave(&mtp_card->spinlock, flags);
487 if (up) {
488 if (! (portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) {
489 if (mtp_card->istimer++ == 0)
490 snd_mtpav_add_output_timer(mtp_card);
491 portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED;
493 } else {
494 portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED;
495 if (--mtp_card->istimer == 0)
496 snd_mtpav_remove_output_timer(mtp_card);
498 spin_unlock_irqrestore(&mtp_card->spinlock, flags);
500 if (up)
501 snd_mtpav_output_write(substream);
505 * midi interrupt for inputs
508 static void snd_mtpav_inmidi_process(mtpav_t *mcrd, u8 inbyte)
510 mtpav_port_t *portp;
512 if ((int)mcrd->inmidiport > mcrd->num_ports * 2 + MTPAV_PIDX_BROADCAST)
513 return;
515 portp = &mcrd->ports[mcrd->inmidiport];
516 if (portp->mode & MTPAV_MODE_INPUT_TRIGGERED) {
517 spin_unlock(&mcrd->spinlock);
518 snd_rawmidi_receive(portp->input, &inbyte, 1);
519 spin_lock(&mcrd->spinlock);
523 static void snd_mtpav_inmidi_h(mtpav_t * mcrd, u8 inbyte)
525 snd_assert(mcrd, return);
527 if (inbyte >= 0xf8) {
528 /* real-time midi code */
529 snd_mtpav_inmidi_process(mcrd, inbyte);
530 return;
533 if (mcrd->inmidistate == 0) { // awaiting command
534 if (inbyte == 0xf5) // MTP port #
535 mcrd->inmidistate = 1;
536 else
537 snd_mtpav_inmidi_process(mcrd, inbyte);
538 } else if (mcrd->inmidistate) {
539 mcrd->inmidiport = translate_hwport_to_subdevice(mcrd, inbyte);
540 mcrd->inmidistate = 0;
544 static void snd_mtpav_read_bytes(mtpav_t * mcrd)
546 u8 clrread, setread;
547 u8 mtp_read_byte;
548 u8 sr, cbyt;
549 int i;
551 u8 sbyt = snd_mtpav_getreg(mcrd, SREG);
553 //printk("snd_mtpav_read_bytes() sbyt: 0x%x\n", sbyt);
555 if (!(sbyt & SIGS_BYTE))
556 return;
558 cbyt = snd_mtpav_getreg(mcrd, CREG);
559 clrread = cbyt & (SIGC_READ ^ 0xff);
560 setread = cbyt | SIGC_READ;
562 do {
564 mtp_read_byte = 0;
565 for (i = 0; i < 4; i++) {
566 snd_mtpav_mputreg(mcrd, CREG, setread);
567 sr = snd_mtpav_getreg(mcrd, SREG);
568 snd_mtpav_mputreg(mcrd, CREG, clrread);
570 sr &= SIGS_IN0 | SIGS_IN1;
571 sr >>= 4;
572 mtp_read_byte |= sr << (i * 2);
575 snd_mtpav_inmidi_h(mcrd, mtp_read_byte);
577 sbyt = snd_mtpav_getreg(mcrd, SREG);
579 } while (sbyt & SIGS_BYTE);
582 static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id, struct pt_regs *regs)
584 mtpav_t *mcard = dev_id;
586 //printk("irqh()\n");
587 spin_lock(&mcard->spinlock);
588 snd_mtpav_read_bytes(mcard);
589 spin_unlock(&mcard->spinlock);
590 return IRQ_HANDLED;
594 * get ISA resources
596 static int snd_mtpav_get_ISA(mtpav_t * mcard)
598 if ((mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI")) == NULL) {
599 snd_printk("MTVAP port 0x%lx is busy\n", port);
600 return -EBUSY;
602 mcard->port = port;
603 if (request_irq(irq, snd_mtpav_irqh, SA_INTERRUPT, "MOTU MTPAV", (void *)mcard)) {
604 snd_printk("MTVAP IRQ %d busy\n", irq);
605 return -EBUSY;
607 mcard->irq = irq;
608 return 0;
615 static snd_rawmidi_ops_t snd_mtpav_output = {
616 .open = snd_mtpav_output_open,
617 .close = snd_mtpav_output_close,
618 .trigger = snd_mtpav_output_trigger,
621 static snd_rawmidi_ops_t snd_mtpav_input = {
622 .open = snd_mtpav_input_open,
623 .close = snd_mtpav_input_close,
624 .trigger = snd_mtpav_input_trigger,
629 * get RAWMIDI resources
632 static void snd_mtpav_set_name(mtpav_t *chip, snd_rawmidi_substream_t *substream)
634 if (substream->number >= 0 && substream->number < chip->num_ports)
635 sprintf(substream->name, "MTP direct %d", (substream->number % chip->num_ports) + 1);
636 else if (substream->number >= 8 && substream->number < chip->num_ports * 2)
637 sprintf(substream->name, "MTP remote %d", (substream->number % chip->num_ports) + 1);
638 else if (substream->number == chip->num_ports * 2)
639 strcpy(substream->name, "MTP computer");
640 else if (substream->number == chip->num_ports * 2 + 1)
641 strcpy(substream->name, "MTP ADAT");
642 else
643 strcpy(substream->name, "MTP broadcast");
646 static int snd_mtpav_get_RAWMIDI(mtpav_t * mcard)
648 int rval = 0;
649 snd_rawmidi_t *rawmidi;
650 snd_rawmidi_substream_t *substream;
651 struct list_head *list;
653 //printk("entering snd_mtpav_get_RAWMIDI\n");
655 if (hwports < 1)
656 mcard->num_ports = 1;
657 else if (hwports > 8)
658 mcard->num_ports = 8;
659 else
660 mcard->num_ports = hwports;
662 if ((rval = snd_rawmidi_new(mcard->card, "MotuMIDI", 0,
663 mcard->num_ports * 2 + MTPAV_PIDX_BROADCAST + 1,
664 mcard->num_ports * 2 + MTPAV_PIDX_BROADCAST + 1,
665 &mcard->rmidi)) < 0)
666 return rval;
667 rawmidi = mcard->rmidi;
669 list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) {
670 substream = list_entry(list, snd_rawmidi_substream_t, list);
671 snd_mtpav_set_name(mcard, substream);
672 substream->ops = &snd_mtpav_input;
674 list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) {
675 substream = list_entry(list, snd_rawmidi_substream_t, list);
676 snd_mtpav_set_name(mcard, substream);
677 substream->ops = &snd_mtpav_output;
678 mcard->ports[substream->number].hwport = translate_subdevice_to_hwport(mcard, substream->number);
680 rawmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT |
681 SNDRV_RAWMIDI_INFO_DUPLEX;
682 sprintf(rawmidi->name, "MTP AV MIDI");
683 //printk("exiting snd_mtpav_get_RAWMIDI() \n");
684 return 0;
690 static mtpav_t *new_mtpav(void)
692 mtpav_t *ncrd = kcalloc(1, sizeof(*ncrd), GFP_KERNEL);
693 if (ncrd != NULL) {
694 spin_lock_init(&ncrd->spinlock);
696 init_timer(&ncrd->timer);
697 ncrd->card = NULL;
698 ncrd->irq = -1;
699 ncrd->share_irq = 0;
701 ncrd->inmidiport = 0xffffffff;
702 ncrd->inmidistate = 0;
703 ncrd->outmidihwport = 0xffffffff;
705 return ncrd;
711 static void free_mtpav(mtpav_t * crd)
713 unsigned long flags;
715 spin_lock_irqsave(&crd->spinlock, flags);
716 if (crd->istimer > 0)
717 snd_mtpav_remove_output_timer(crd);
718 spin_unlock_irqrestore(&crd->spinlock, flags);
719 if (crd->irq >= 0)
720 free_irq(crd->irq, (void *)crd);
721 if (crd->res_port) {
722 release_resource(crd->res_port);
723 kfree_nocheck(crd->res_port);
725 kfree(crd);
731 static int __init alsa_card_mtpav_init(void)
733 int err = 0;
734 char longname_buffer[80];
736 mtp_card = new_mtpav();
737 if (mtp_card == NULL)
738 return -ENOMEM;
740 mtp_card->card = snd_card_new(index, id, THIS_MODULE, 0);
741 if (mtp_card->card == NULL) {
742 free_mtpav(mtp_card);
743 return -ENOMEM;
746 err = snd_mtpav_get_ISA(mtp_card);
747 //printk("snd_mtpav_get_ISA returned: %d\n", err);
748 if (err < 0)
749 goto __error;
751 strcpy(mtp_card->card->driver, "MTPAV");
752 strcpy(mtp_card->card->shortname, "MTPAV on parallel port");
753 memset(longname_buffer, 0, sizeof(longname_buffer));
754 sprintf(longname_buffer, "MTPAV on parallel port at");
756 err = snd_mtpav_get_RAWMIDI(mtp_card);
757 //snd_printk("snd_mtapv_get_RAWMIDI returned: %d\n", err);
758 if (err < 0)
759 goto __error;
761 err = snd_card_register(mtp_card->card); // don't snd_card_register until AFTER all cards reources done!
763 //printk("snd_card_register returned %d\n", err);
764 if (err < 0)
765 goto __error;
768 snd_mtpav_portscan(mtp_card);
770 printk(KERN_INFO "Motu MidiTimePiece on parallel port irq: %d ioport: 0x%lx\n", irq, port);
772 return 0;
774 __error:
775 snd_card_free(mtp_card->card);
776 free_mtpav(mtp_card);
777 return err;
783 static void __exit alsa_card_mtpav_exit(void)
785 if (mtp_card == NULL)
786 return;
787 if (mtp_card->card)
788 snd_card_free(mtp_card->card);
789 free_mtpav(mtp_card);
795 module_init(alsa_card_mtpav_init)
796 module_exit(alsa_card_mtpav_exit)