Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
| 6 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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 |
| 20 | * |
| 21 | * |
| 22 | * This driver is for the 'Mark Of The Unicorn' (MOTU) |
| 23 | * MidiTimePiece AV multiport MIDI interface |
| 24 | * |
| 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 ) |
| 35 | * |
| 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 |
| 41 | * |
| 42 | * |
| 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. |
| 50 | * |
| 51 | */ |
| 52 | |
| 53 | #include <sound/driver.h> |
| 54 | #include <linux/init.h> |
| 55 | #include <linux/interrupt.h> |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 56 | #include <linux/err.h> |
| 57 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <linux/slab.h> |
| 59 | #include <linux/ioport.h> |
| 60 | #include <linux/moduleparam.h> |
| 61 | #include <sound/core.h> |
| 62 | #include <sound/initval.h> |
| 63 | #include <sound/rawmidi.h> |
| 64 | #include <linux/delay.h> |
| 65 | |
| 66 | #include <asm/io.h> |
| 67 | |
| 68 | /* |
| 69 | * globals |
| 70 | */ |
| 71 | MODULE_AUTHOR("Michael T. Mayers"); |
| 72 | MODULE_DESCRIPTION("MOTU MidiTimePiece AV multiport MIDI"); |
| 73 | MODULE_LICENSE("GPL"); |
| 74 | MODULE_SUPPORTED_DEVICE("{{MOTU,MidiTimePiece AV multiport MIDI}}"); |
| 75 | |
| 76 | // io resources |
| 77 | #define MTPAV_IOBASE 0x378 |
| 78 | #define MTPAV_IRQ 7 |
| 79 | #define MTPAV_MAX_PORTS 8 |
| 80 | |
| 81 | static int index = SNDRV_DEFAULT_IDX1; |
| 82 | static char *id = SNDRV_DEFAULT_STR1; |
| 83 | static long port = MTPAV_IOBASE; /* 0x378, 0x278 */ |
| 84 | static int irq = MTPAV_IRQ; /* 7, 5 */ |
| 85 | static int hwports = MTPAV_MAX_PORTS; /* use hardware ports 1-8 */ |
| 86 | |
| 87 | module_param(index, int, 0444); |
| 88 | MODULE_PARM_DESC(index, "Index value for MotuMTPAV MIDI."); |
| 89 | module_param(id, charp, 0444); |
| 90 | MODULE_PARM_DESC(id, "ID string for MotuMTPAV MIDI."); |
| 91 | module_param(port, long, 0444); |
| 92 | MODULE_PARM_DESC(port, "Parallel port # for MotuMTPAV MIDI."); |
| 93 | module_param(irq, int, 0444); |
| 94 | MODULE_PARM_DESC(irq, "Parallel IRQ # for MotuMTPAV MIDI."); |
| 95 | module_param(hwports, int, 0444); |
| 96 | MODULE_PARM_DESC(hwports, "Hardware ports # for MotuMTPAV MIDI."); |
| 97 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 98 | static struct platform_device *device; |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* |
| 101 | * defines |
| 102 | */ |
| 103 | //#define USE_FAKE_MTP // don't actually read/write to MTP device (for debugging without an actual unit) (does not work yet) |
| 104 | |
| 105 | // parallel port usage masks |
| 106 | #define SIGS_BYTE 0x08 |
| 107 | #define SIGS_RFD 0x80 |
| 108 | #define SIGS_IRQ 0x40 |
| 109 | #define SIGS_IN0 0x10 |
| 110 | #define SIGS_IN1 0x20 |
| 111 | |
| 112 | #define SIGC_WRITE 0x04 |
| 113 | #define SIGC_READ 0x08 |
| 114 | #define SIGC_INTEN 0x10 |
| 115 | |
| 116 | #define DREG 0 |
| 117 | #define SREG 1 |
| 118 | #define CREG 2 |
| 119 | |
| 120 | // |
| 121 | #define MTPAV_MODE_INPUT_OPENED 0x01 |
| 122 | #define MTPAV_MODE_OUTPUT_OPENED 0x02 |
| 123 | #define MTPAV_MODE_INPUT_TRIGGERED 0x04 |
| 124 | #define MTPAV_MODE_OUTPUT_TRIGGERED 0x08 |
| 125 | |
| 126 | #define NUMPORTS (0x12+1) |
| 127 | |
| 128 | |
| 129 | /* |
| 130 | */ |
| 131 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 132 | struct mtpav_port { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | u8 number; |
| 134 | u8 hwport; |
| 135 | u8 mode; |
| 136 | u8 running_status; |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 137 | struct snd_rawmidi_substream *input; |
| 138 | struct snd_rawmidi_substream *output; |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 139 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 141 | struct mtpav { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 142 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | unsigned long port; |
| 144 | struct resource *res_port; |
| 145 | int irq; /* interrupt (for inputs) */ |
| 146 | spinlock_t spinlock; |
| 147 | int share_irq; /* number of accesses to input interrupts */ |
| 148 | int istimer; /* number of accesses to timer interrupts */ |
| 149 | struct timer_list timer; /* timer interrupts for outputs */ |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 150 | struct snd_rawmidi *rmidi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | int num_ports; /* number of hw ports (1-8) */ |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 152 | struct mtpav_port ports[NUMPORTS]; /* all ports including computer, adat and bc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | u32 inmidiport; /* selected input midi port */ |
| 155 | u32 inmidistate; /* during midi command 0xf5 */ |
| 156 | |
| 157 | u32 outmidihwport; /* selected output midi hw port */ |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 158 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | |
| 161 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | * possible hardware ports (selected by 0xf5 port message) |
| 163 | * 0x00 all ports |
| 164 | * 0x01 .. 0x08 this MTP's ports 1..8 |
| 165 | * 0x09 .. 0x10 networked MTP's ports (9..16) |
| 166 | * 0x11 networked MTP's computer port |
| 167 | * 0x63 to ADAT |
| 168 | * |
| 169 | * mappig: |
| 170 | * subdevice 0 - (X-1) ports |
| 171 | * X - (2*X-1) networked ports |
| 172 | * X computer |
| 173 | * X+1 ADAT |
| 174 | * X+2 all ports |
| 175 | * |
| 176 | * where X = chip->num_ports |
| 177 | */ |
| 178 | |
| 179 | #define MTPAV_PIDX_COMPUTER 0 |
| 180 | #define MTPAV_PIDX_ADAT 1 |
| 181 | #define MTPAV_PIDX_BROADCAST 2 |
| 182 | |
| 183 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 184 | static int translate_subdevice_to_hwport(struct mtpav *chip, int subdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | if (subdev < 0) |
| 187 | return 0x01; /* invalid - use port 0 as default */ |
| 188 | else if (subdev < chip->num_ports) |
| 189 | return subdev + 1; /* single mtp port */ |
| 190 | else if (subdev < chip->num_ports * 2) |
| 191 | return subdev - chip->num_ports + 0x09; /* remote port */ |
| 192 | else if (subdev == chip->num_ports * 2 + MTPAV_PIDX_COMPUTER) |
| 193 | return 0x11; /* computer port */ |
| 194 | else if (subdev == chip->num_ports + MTPAV_PIDX_ADAT) |
| 195 | return 0x63; /* ADAT */ |
| 196 | return 0; /* all ports */ |
| 197 | } |
| 198 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 199 | static int translate_hwport_to_subdevice(struct mtpav *chip, int hwport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
| 201 | int p; |
| 202 | if (hwport <= 0x00) /* all ports */ |
| 203 | return chip->num_ports + MTPAV_PIDX_BROADCAST; |
| 204 | else if (hwport <= 0x08) { /* single port */ |
| 205 | p = hwport - 1; |
| 206 | if (p >= chip->num_ports) |
| 207 | p = 0; |
| 208 | return p; |
| 209 | } else if (hwport <= 0x10) { /* remote port */ |
| 210 | p = hwport - 0x09 + chip->num_ports; |
| 211 | if (p >= chip->num_ports * 2) |
| 212 | p = chip->num_ports; |
| 213 | return p; |
| 214 | } else if (hwport == 0x11) /* computer port */ |
| 215 | return chip->num_ports + MTPAV_PIDX_COMPUTER; |
| 216 | else /* ADAT */ |
| 217 | return chip->num_ports + MTPAV_PIDX_ADAT; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /* |
| 222 | */ |
| 223 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 224 | static u8 snd_mtpav_getreg(struct mtpav *chip, u16 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | u8 rval = 0; |
| 227 | |
| 228 | if (reg == SREG) { |
| 229 | rval = inb(chip->port + SREG); |
| 230 | rval = (rval & 0xf8); |
| 231 | } else if (reg == CREG) { |
| 232 | rval = inb(chip->port + CREG); |
| 233 | rval = (rval & 0x1c); |
| 234 | } |
| 235 | |
| 236 | return rval; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | */ |
| 241 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 242 | static inline void snd_mtpav_mputreg(struct mtpav *chip, u16 reg, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 244 | if (reg == DREG || reg == CREG) |
| 245 | outb(val, chip->port + reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* |
| 249 | */ |
| 250 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 251 | static void snd_mtpav_wait_rfdhi(struct mtpav *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
| 253 | int counts = 10000; |
| 254 | u8 sbyte; |
| 255 | |
| 256 | sbyte = snd_mtpav_getreg(chip, SREG); |
| 257 | while (!(sbyte & SIGS_RFD) && counts--) { |
| 258 | sbyte = snd_mtpav_getreg(chip, SREG); |
| 259 | udelay(10); |
| 260 | } |
| 261 | } |
| 262 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 263 | static void snd_mtpav_send_byte(struct mtpav *chip, u8 byte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | u8 tcbyt; |
| 266 | u8 clrwrite; |
| 267 | u8 setwrite; |
| 268 | |
| 269 | snd_mtpav_wait_rfdhi(chip); |
| 270 | |
| 271 | ///////////////// |
| 272 | |
| 273 | tcbyt = snd_mtpav_getreg(chip, CREG); |
| 274 | clrwrite = tcbyt & (SIGC_WRITE ^ 0xff); |
| 275 | setwrite = tcbyt | SIGC_WRITE; |
| 276 | |
| 277 | snd_mtpav_mputreg(chip, DREG, byte); |
| 278 | snd_mtpav_mputreg(chip, CREG, clrwrite); // clear write bit |
| 279 | |
| 280 | snd_mtpav_mputreg(chip, CREG, setwrite); // set write bit |
| 281 | |
| 282 | } |
| 283 | |
| 284 | |
| 285 | /* |
| 286 | */ |
| 287 | |
| 288 | /* call this with spin lock held */ |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 289 | static void snd_mtpav_output_port_write(struct mtpav *mtp_card, |
| 290 | struct mtpav_port *portp, |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 291 | struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
| 293 | u8 outbyte; |
| 294 | |
| 295 | // Get the outbyte first, so we can emulate running status if |
| 296 | // necessary |
| 297 | if (snd_rawmidi_transmit(substream, &outbyte, 1) != 1) |
| 298 | return; |
| 299 | |
| 300 | // send port change command if necessary |
| 301 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 302 | if (portp->hwport != mtp_card->outmidihwport) { |
| 303 | mtp_card->outmidihwport = portp->hwport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | snd_mtpav_send_byte(mtp_card, 0xf5); |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 306 | snd_mtpav_send_byte(mtp_card, portp->hwport); |
| 307 | //snd_printk("new outport: 0x%x\n", (unsigned int) portp->hwport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 309 | if (!(outbyte & 0x80) && portp->running_status) |
| 310 | snd_mtpav_send_byte(mtp_card, portp->running_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | // send data |
| 314 | |
| 315 | do { |
| 316 | if (outbyte & 0x80) |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 317 | portp->running_status = outbyte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | snd_mtpav_send_byte(mtp_card, outbyte); |
| 320 | } while (snd_rawmidi_transmit(substream, &outbyte, 1) == 1); |
| 321 | } |
| 322 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 323 | static void snd_mtpav_output_write(struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 325 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 326 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | unsigned long flags; |
| 328 | |
| 329 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 330 | snd_mtpav_output_port_write(mtp_card, portp, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | /* |
| 336 | * mtpav control |
| 337 | */ |
| 338 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 339 | static void snd_mtpav_portscan(struct mtpav *chip) // put mtp into smart routing mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
| 341 | u8 p; |
| 342 | |
| 343 | for (p = 0; p < 8; p++) { |
| 344 | snd_mtpav_send_byte(chip, 0xf5); |
| 345 | snd_mtpav_send_byte(chip, p); |
| 346 | snd_mtpav_send_byte(chip, 0xfe); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | */ |
| 352 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 353 | static int snd_mtpav_input_open(struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 355 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 356 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
| 360 | portp->mode |= MTPAV_MODE_INPUT_OPENED; |
| 361 | portp->input = substream; |
| 362 | if (mtp_card->share_irq++ == 0) |
| 363 | snd_mtpav_mputreg(mtp_card, CREG, (SIGC_INTEN | SIGC_WRITE)); // enable pport interrupts |
| 364 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | */ |
| 370 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 371 | static int snd_mtpav_input_close(struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 373 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 374 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 378 | portp->mode &= ~MTPAV_MODE_INPUT_OPENED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | portp->input = NULL; |
| 380 | if (--mtp_card->share_irq == 0) |
| 381 | snd_mtpav_mputreg(mtp_card, CREG, 0); // disable pport interrupts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | */ |
| 388 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 389 | static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 391 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 392 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
| 396 | if (up) |
| 397 | portp->mode |= MTPAV_MODE_INPUT_TRIGGERED; |
| 398 | else |
| 399 | portp->mode &= ~MTPAV_MODE_INPUT_TRIGGERED; |
| 400 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 401 | |
| 402 | } |
| 403 | |
| 404 | |
| 405 | /* |
| 406 | * timer interrupt for outputs |
| 407 | */ |
| 408 | |
| 409 | static void snd_mtpav_output_timer(unsigned long data) |
| 410 | { |
| 411 | unsigned long flags; |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 412 | struct mtpav *chip = (struct mtpav *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | int p; |
| 414 | |
| 415 | spin_lock_irqsave(&chip->spinlock, flags); |
| 416 | /* reprogram timer */ |
| 417 | chip->timer.expires = 1 + jiffies; |
| 418 | add_timer(&chip->timer); |
| 419 | /* process each port */ |
| 420 | for (p = 0; p <= chip->num_ports * 2 + MTPAV_PIDX_BROADCAST; p++) { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 421 | struct mtpav_port *portp = &chip->ports[p]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | if ((portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED) && portp->output) |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 423 | snd_mtpav_output_port_write(chip, portp, portp->output); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | spin_unlock_irqrestore(&chip->spinlock, flags); |
| 426 | } |
| 427 | |
| 428 | /* spinlock held! */ |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 429 | static void snd_mtpav_add_output_timer(struct mtpav *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | chip->timer.expires = 1 + jiffies; |
| 432 | add_timer(&chip->timer); |
| 433 | } |
| 434 | |
| 435 | /* spinlock held! */ |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 436 | static void snd_mtpav_remove_output_timer(struct mtpav *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
| 438 | del_timer(&chip->timer); |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | */ |
| 443 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 444 | static int snd_mtpav_output_open(struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 446 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 447 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
| 451 | portp->mode |= MTPAV_MODE_OUTPUT_OPENED; |
| 452 | portp->output = substream; |
| 453 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 454 | return 0; |
| 455 | }; |
| 456 | |
| 457 | /* |
| 458 | */ |
| 459 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 460 | static int snd_mtpav_output_close(struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 462 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 463 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 467 | portp->mode &= ~MTPAV_MODE_OUTPUT_OPENED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | portp->output = NULL; |
| 469 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 470 | return 0; |
| 471 | }; |
| 472 | |
| 473 | /* |
| 474 | */ |
| 475 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 476 | static void snd_mtpav_output_trigger(struct snd_rawmidi_substream *substream, int up) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 478 | struct mtpav *mtp_card = substream->rmidi->private_data; |
| 479 | struct mtpav_port *portp = &mtp_card->ports[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | spin_lock_irqsave(&mtp_card->spinlock, flags); |
| 483 | if (up) { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 484 | if (! (portp->mode & MTPAV_MODE_OUTPUT_TRIGGERED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | if (mtp_card->istimer++ == 0) |
| 486 | snd_mtpav_add_output_timer(mtp_card); |
| 487 | portp->mode |= MTPAV_MODE_OUTPUT_TRIGGERED; |
| 488 | } |
| 489 | } else { |
| 490 | portp->mode &= ~MTPAV_MODE_OUTPUT_TRIGGERED; |
| 491 | if (--mtp_card->istimer == 0) |
| 492 | snd_mtpav_remove_output_timer(mtp_card); |
| 493 | } |
| 494 | spin_unlock_irqrestore(&mtp_card->spinlock, flags); |
| 495 | |
| 496 | if (up) |
| 497 | snd_mtpav_output_write(substream); |
| 498 | } |
| 499 | |
| 500 | /* |
| 501 | * midi interrupt for inputs |
| 502 | */ |
| 503 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 504 | static void snd_mtpav_inmidi_process(struct mtpav *mcrd, u8 inbyte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 506 | struct mtpav_port *portp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | if ((int)mcrd->inmidiport > mcrd->num_ports * 2 + MTPAV_PIDX_BROADCAST) |
| 509 | return; |
| 510 | |
| 511 | portp = &mcrd->ports[mcrd->inmidiport]; |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 512 | if (portp->mode & MTPAV_MODE_INPUT_TRIGGERED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | snd_rawmidi_receive(portp->input, &inbyte, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 516 | static void snd_mtpav_inmidi_h(struct mtpav *mcrd, u8 inbyte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (inbyte >= 0xf8) { |
| 519 | /* real-time midi code */ |
| 520 | snd_mtpav_inmidi_process(mcrd, inbyte); |
| 521 | return; |
| 522 | } |
| 523 | |
| 524 | if (mcrd->inmidistate == 0) { // awaiting command |
| 525 | if (inbyte == 0xf5) // MTP port # |
| 526 | mcrd->inmidistate = 1; |
| 527 | else |
| 528 | snd_mtpav_inmidi_process(mcrd, inbyte); |
| 529 | } else if (mcrd->inmidistate) { |
| 530 | mcrd->inmidiport = translate_hwport_to_subdevice(mcrd, inbyte); |
| 531 | mcrd->inmidistate = 0; |
| 532 | } |
| 533 | } |
| 534 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 535 | static void snd_mtpav_read_bytes(struct mtpav *mcrd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | { |
| 537 | u8 clrread, setread; |
| 538 | u8 mtp_read_byte; |
| 539 | u8 sr, cbyt; |
| 540 | int i; |
| 541 | |
| 542 | u8 sbyt = snd_mtpav_getreg(mcrd, SREG); |
| 543 | |
| 544 | //printk("snd_mtpav_read_bytes() sbyt: 0x%x\n", sbyt); |
| 545 | |
| 546 | if (!(sbyt & SIGS_BYTE)) |
| 547 | return; |
| 548 | |
| 549 | cbyt = snd_mtpav_getreg(mcrd, CREG); |
| 550 | clrread = cbyt & (SIGC_READ ^ 0xff); |
| 551 | setread = cbyt | SIGC_READ; |
| 552 | |
| 553 | do { |
| 554 | |
| 555 | mtp_read_byte = 0; |
| 556 | for (i = 0; i < 4; i++) { |
| 557 | snd_mtpav_mputreg(mcrd, CREG, setread); |
| 558 | sr = snd_mtpav_getreg(mcrd, SREG); |
| 559 | snd_mtpav_mputreg(mcrd, CREG, clrread); |
| 560 | |
| 561 | sr &= SIGS_IN0 | SIGS_IN1; |
| 562 | sr >>= 4; |
| 563 | mtp_read_byte |= sr << (i * 2); |
| 564 | } |
| 565 | |
| 566 | snd_mtpav_inmidi_h(mcrd, mtp_read_byte); |
| 567 | |
| 568 | sbyt = snd_mtpav_getreg(mcrd, SREG); |
| 569 | |
| 570 | } while (sbyt & SIGS_BYTE); |
| 571 | } |
| 572 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 573 | static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 575 | struct mtpav *mcard = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | spin_lock(&mcard->spinlock); |
| 578 | snd_mtpav_read_bytes(mcard); |
| 579 | spin_unlock(&mcard->spinlock); |
| 580 | return IRQ_HANDLED; |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | * get ISA resources |
| 585 | */ |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 586 | static int __devinit snd_mtpav_get_ISA(struct mtpav * mcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
| 588 | if ((mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI")) == NULL) { |
| 589 | snd_printk("MTVAP port 0x%lx is busy\n", port); |
| 590 | return -EBUSY; |
| 591 | } |
| 592 | mcard->port = port; |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 593 | if (request_irq(irq, snd_mtpav_irqh, IRQF_DISABLED, "MOTU MTPAV", mcard)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | snd_printk("MTVAP IRQ %d busy\n", irq); |
| 595 | return -EBUSY; |
| 596 | } |
| 597 | mcard->irq = irq; |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | |
| 602 | /* |
| 603 | */ |
| 604 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 605 | static struct snd_rawmidi_ops snd_mtpav_output = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | .open = snd_mtpav_output_open, |
| 607 | .close = snd_mtpav_output_close, |
| 608 | .trigger = snd_mtpav_output_trigger, |
| 609 | }; |
| 610 | |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 611 | static struct snd_rawmidi_ops snd_mtpav_input = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | .open = snd_mtpav_input_open, |
| 613 | .close = snd_mtpav_input_close, |
| 614 | .trigger = snd_mtpav_input_trigger, |
| 615 | }; |
| 616 | |
| 617 | |
| 618 | /* |
| 619 | * get RAWMIDI resources |
| 620 | */ |
| 621 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 622 | static void __devinit snd_mtpav_set_name(struct mtpav *chip, |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 623 | struct snd_rawmidi_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | { |
| 625 | if (substream->number >= 0 && substream->number < chip->num_ports) |
| 626 | sprintf(substream->name, "MTP direct %d", (substream->number % chip->num_ports) + 1); |
| 627 | else if (substream->number >= 8 && substream->number < chip->num_ports * 2) |
| 628 | sprintf(substream->name, "MTP remote %d", (substream->number % chip->num_ports) + 1); |
| 629 | else if (substream->number == chip->num_ports * 2) |
| 630 | strcpy(substream->name, "MTP computer"); |
| 631 | else if (substream->number == chip->num_ports * 2 + 1) |
| 632 | strcpy(substream->name, "MTP ADAT"); |
| 633 | else |
| 634 | strcpy(substream->name, "MTP broadcast"); |
| 635 | } |
| 636 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 637 | static int __devinit snd_mtpav_get_RAWMIDI(struct mtpav *mcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 639 | int rval; |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 640 | struct snd_rawmidi *rawmidi; |
| 641 | struct snd_rawmidi_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | struct list_head *list; |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | if (hwports < 1) |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 645 | hwports = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | else if (hwports > 8) |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 647 | hwports = 8; |
| 648 | mcard->num_ports = hwports; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | if ((rval = snd_rawmidi_new(mcard->card, "MotuMIDI", 0, |
| 651 | mcard->num_ports * 2 + MTPAV_PIDX_BROADCAST + 1, |
| 652 | mcard->num_ports * 2 + MTPAV_PIDX_BROADCAST + 1, |
| 653 | &mcard->rmidi)) < 0) |
| 654 | return rval; |
| 655 | rawmidi = mcard->rmidi; |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 656 | rawmidi->private_data = mcard; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
| 658 | list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 659 | substream = list_entry(list, struct snd_rawmidi_substream, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | snd_mtpav_set_name(mcard, substream); |
| 661 | substream->ops = &snd_mtpav_input; |
| 662 | } |
| 663 | list_for_each(list, &rawmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) { |
Takashi Iwai | 4a4d2cf | 2005-11-17 14:27:28 +0100 | [diff] [blame] | 664 | substream = list_entry(list, struct snd_rawmidi_substream, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | snd_mtpav_set_name(mcard, substream); |
| 666 | substream->ops = &snd_mtpav_output; |
| 667 | mcard->ports[substream->number].hwport = translate_subdevice_to_hwport(mcard, substream->number); |
| 668 | } |
| 669 | rawmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | |
| 670 | SNDRV_RAWMIDI_INFO_DUPLEX; |
| 671 | sprintf(rawmidi->name, "MTP AV MIDI"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | */ |
| 677 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 678 | static void snd_mtpav_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 680 | struct mtpav *crd = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | unsigned long flags; |
| 682 | |
| 683 | spin_lock_irqsave(&crd->spinlock, flags); |
| 684 | if (crd->istimer > 0) |
| 685 | snd_mtpav_remove_output_timer(crd); |
| 686 | spin_unlock_irqrestore(&crd->spinlock, flags); |
| 687 | if (crd->irq >= 0) |
| 688 | free_irq(crd->irq, (void *)crd); |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 689 | release_and_free_resource(crd->res_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /* |
| 693 | */ |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 694 | static int __devinit snd_mtpav_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 696 | struct snd_card *card; |
| 697 | int err; |
| 698 | struct mtpav *mtp_card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 700 | card = snd_card_new(index, id, THIS_MODULE, sizeof(*mtp_card)); |
| 701 | if (! card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | return -ENOMEM; |
| 703 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 704 | mtp_card = card->private_data; |
| 705 | spin_lock_init(&mtp_card->spinlock); |
| 706 | init_timer(&mtp_card->timer); |
| 707 | mtp_card->card = card; |
| 708 | mtp_card->irq = -1; |
| 709 | mtp_card->share_irq = 0; |
| 710 | mtp_card->inmidiport = 0xffffffff; |
| 711 | mtp_card->inmidistate = 0; |
| 712 | mtp_card->outmidihwport = 0xffffffff; |
| 713 | init_timer(&mtp_card->timer); |
| 714 | mtp_card->timer.function = snd_mtpav_output_timer; |
| 715 | mtp_card->timer.data = (unsigned long) mtp_card; |
| 716 | |
| 717 | card->private_free = snd_mtpav_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
| 719 | err = snd_mtpav_get_ISA(mtp_card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | if (err < 0) |
| 721 | goto __error; |
| 722 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 723 | strcpy(card->driver, "MTPAV"); |
| 724 | strcpy(card->shortname, "MTPAV on parallel port"); |
| 725 | snprintf(card->longname, sizeof(card->longname), |
| 726 | "MTPAV on parallel port at 0x%lx", port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | err = snd_mtpav_get_RAWMIDI(mtp_card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | if (err < 0) |
| 730 | goto __error; |
| 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | snd_mtpav_portscan(mtp_card); |
| 733 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 734 | snd_card_set_dev(card, &dev->dev); |
| 735 | err = snd_card_register(mtp_card->card); |
| 736 | if (err < 0) |
| 737 | goto __error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 739 | platform_set_drvdata(dev, card); |
| 740 | printk(KERN_INFO "Motu MidiTimePiece on parallel port irq: %d ioport: 0x%lx\n", irq, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | return 0; |
| 742 | |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 743 | __error: |
| 744 | snd_card_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | return err; |
| 746 | } |
| 747 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 748 | static int __devexit snd_mtpav_remove(struct platform_device *devptr) |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 749 | { |
| 750 | snd_card_free(platform_get_drvdata(devptr)); |
| 751 | platform_set_drvdata(devptr, NULL); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | #define SND_MTPAV_DRIVER "snd_mtpav" |
| 756 | |
| 757 | static struct platform_driver snd_mtpav_driver = { |
| 758 | .probe = snd_mtpav_probe, |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 759 | .remove = __devexit_p(snd_mtpav_remove), |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 760 | .driver = { |
| 761 | .name = SND_MTPAV_DRIVER |
| 762 | }, |
| 763 | }; |
| 764 | |
| 765 | static int __init alsa_card_mtpav_init(void) |
| 766 | { |
| 767 | int err; |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 768 | |
| 769 | if ((err = platform_driver_register(&snd_mtpav_driver)) < 0) |
| 770 | return err; |
| 771 | |
| 772 | device = platform_device_register_simple(SND_MTPAV_DRIVER, -1, NULL, 0); |
Rene Herman | 7152447 | 2006-04-13 12:58:06 +0200 | [diff] [blame] | 773 | if (!IS_ERR(device)) { |
| 774 | if (platform_get_drvdata(device)) |
| 775 | return 0; |
| 776 | platform_device_unregister(device); |
| 777 | err = -ENODEV; |
| 778 | } else |
| 779 | err = PTR_ERR(device); |
| 780 | platform_driver_unregister(&snd_mtpav_driver); |
| 781 | return err; |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
| 784 | static void __exit alsa_card_mtpav_exit(void) |
| 785 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 786 | platform_device_unregister(device); |
Takashi Iwai | 077d0ac | 2005-11-17 16:02:15 +0100 | [diff] [blame] | 787 | platform_driver_unregister(&snd_mtpav_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | module_init(alsa_card_mtpav_init) |
| 791 | module_exit(alsa_card_mtpav_exit) |