diff options
author | James Courtier-Dutton <James@superbug.co.uk> | 2005-10-20 16:57:51 -0400 |
---|---|---|
committer | Jaroslav Kysela <perex@suse.cz> | 2005-11-04 07:19:26 -0500 |
commit | 8a5afd29dc16a9e687f63195cb635ecd611482d0 (patch) | |
tree | dff1950bd5302e5b2752e32075166638be1436dd | |
parent | b0b9811956db489ca43596c37ef2f38582454e51 (diff) |
[ALSA] snd-ca0106: Add midi support.
Modules: PCI drivers,CA0106 driver
Author: Tilman Kranz <tilde@tk-sls.de>
Signed-off-by: James Courtier-Dutton <James@superbug.co.uk>
-rw-r--r-- | sound/pci/Kconfig | 1 | ||||
-rw-r--r-- | sound/pci/ca0106/Makefile | 2 | ||||
-rw-r--r-- | sound/pci/ca0106/ca0106.h | 27 | ||||
-rw-r--r-- | sound/pci/ca0106/ca0106_main.c | 111 | ||||
-rw-r--r-- | sound/pci/ca0106/ca_midi.c | 304 | ||||
-rw-r--r-- | sound/pci/ca0106/ca_midi.h | 72 |
6 files changed, 512 insertions, 5 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig index d140e93d37b6..0fb16cf335ea 100644 --- a/sound/pci/Kconfig +++ b/sound/pci/Kconfig | |||
@@ -184,6 +184,7 @@ config SND_CA0106 | |||
184 | tristate "SB Audigy LS / Live 24bit" | 184 | tristate "SB Audigy LS / Live 24bit" |
185 | depends on SND | 185 | depends on SND |
186 | select SND_AC97_CODEC | 186 | select SND_AC97_CODEC |
187 | select SND_RAWMIDI | ||
187 | help | 188 | help |
188 | Say Y here to include support for the Sound Blaster Audigy LS | 189 | Say Y here to include support for the Sound Blaster Audigy LS |
189 | and Live 24bit. | 190 | and Live 24bit. |
diff --git a/sound/pci/ca0106/Makefile b/sound/pci/ca0106/Makefile index 89c6ceee21f3..dcbae7b31546 100644 --- a/sound/pci/ca0106/Makefile +++ b/sound/pci/ca0106/Makefile | |||
@@ -1,3 +1,3 @@ | |||
1 | snd-ca0106-objs := ca0106_main.o ca0106_proc.o ca0106_mixer.o | 1 | snd-ca0106-objs := ca0106_main.o ca0106_proc.o ca0106_mixer.o ca_midi.o |
2 | 2 | ||
3 | obj-$(CONFIG_SND_CA0106) += snd-ca0106.o | 3 | obj-$(CONFIG_SND_CA0106) += snd-ca0106.o |
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h index da09cab405a9..9a4b6406f7a5 100644 --- a/sound/pci/ca0106/ca0106.h +++ b/sound/pci/ca0106/ca0106.h | |||
@@ -399,10 +399,24 @@ | |||
399 | #define PLAYBACK_VOLUME2 0x6a /* Playback Analog volume per channel. Does not effect AC3 output */ | 399 | #define PLAYBACK_VOLUME2 0x6a /* Playback Analog volume per channel. Does not effect AC3 output */ |
400 | /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */ | 400 | /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */ |
401 | #define UNKNOWN6b 0x6b /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */ | 401 | #define UNKNOWN6b 0x6b /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */ |
402 | #define UART_A_DATA 0x6c /* Uart, used in setting sample rates, bits per sample etc. */ | 402 | #define MIDI_UART_A_DATA 0x6c /* Midi Uart A Data */ |
403 | #define UART_A_CMD 0x6d /* Uart, used in setting sample rates, bits per sample etc. */ | 403 | #define MIDI_UART_A_CMD 0x6d /* Midi Uart A Command/Status */ |
404 | #define UART_B_DATA 0x6e /* Uart, Unknown. */ | 404 | #define MIDI_UART_B_DATA 0x6e /* Midi Uart B Data (currently unused) */ |
405 | #define UART_B_CMD 0x6f /* Uart, Unknown. */ | 405 | #define MIDI_UART_B_CMD 0x6f /* Midi Uart B Command/Status (currently unused) */ |
406 | |||
407 | /* unique channel identifier for midi->channel */ | ||
408 | |||
409 | #define CA0106_MIDI_CHAN_A 0x1 | ||
410 | #define CA0106_MIDI_CHAN_B 0x2 | ||
411 | |||
412 | /* from mpu401 */ | ||
413 | |||
414 | #define CA0106_MIDI_INPUT_AVAIL 0x80 | ||
415 | #define CA0106_MIDI_OUTPUT_READY 0x40 | ||
416 | #define CA0106_MPU401_RESET 0xff | ||
417 | #define CA0106_MPU401_ENTER_UART 0x3f | ||
418 | #define CA0106_MPU401_ACK 0xfe | ||
419 | |||
406 | #define SAMPLE_RATE_TRACKER_STATUS 0x70 /* Readonly. Default 00108000 00108000 00500000 00500000 */ | 420 | #define SAMPLE_RATE_TRACKER_STATUS 0x70 /* Readonly. Default 00108000 00108000 00500000 00500000 */ |
407 | /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 = 1.0 | 421 | /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 = 1.0 |
408 | * Rate Locked [20] | 422 | * Rate Locked [20] |
@@ -538,6 +552,8 @@ | |||
538 | #define CONTROL_CENTER_LFE_CHANNEL 1 | 552 | #define CONTROL_CENTER_LFE_CHANNEL 1 |
539 | #define CONTROL_UNKNOWN_CHANNEL 2 | 553 | #define CONTROL_UNKNOWN_CHANNEL 2 |
540 | 554 | ||
555 | #include "ca_midi.h" | ||
556 | |||
541 | typedef struct snd_ca0106_channel ca0106_channel_t; | 557 | typedef struct snd_ca0106_channel ca0106_channel_t; |
542 | typedef struct snd_ca0106 ca0106_t; | 558 | typedef struct snd_ca0106 ca0106_t; |
543 | typedef struct snd_ca0106_pcm ca0106_pcm_t; | 559 | typedef struct snd_ca0106_pcm ca0106_pcm_t; |
@@ -592,6 +608,9 @@ struct snd_ca0106 { | |||
592 | int capture_mic_line_in; | 608 | int capture_mic_line_in; |
593 | 609 | ||
594 | struct snd_dma_buffer buffer; | 610 | struct snd_dma_buffer buffer; |
611 | |||
612 | ca_midi_t midi; | ||
613 | ca_midi_t midi2; | ||
595 | }; | 614 | }; |
596 | 615 | ||
597 | int __devinit snd_ca0106_mixer(ca0106_t *emu); | 616 | int __devinit snd_ca0106_mixer(ca0106_t *emu); |
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c index f6920ef5b4ea..aaaef9e66af6 100644 --- a/sound/pci/ca0106/ca0106_main.c +++ b/sound/pci/ca0106/ca0106_main.c | |||
@@ -338,6 +338,18 @@ static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb) | |||
338 | spin_unlock_irqrestore(&emu->emu_lock, flags); | 338 | spin_unlock_irqrestore(&emu->emu_lock, flags); |
339 | } | 339 | } |
340 | 340 | ||
341 | static void snd_ca0106_intr_disable(ca0106_t *emu, unsigned int intrenb) | ||
342 | { | ||
343 | unsigned long flags; | ||
344 | unsigned int enable; | ||
345 | |||
346 | spin_lock_irqsave(&emu->emu_lock, flags); | ||
347 | enable = inl(emu->port + INTE) & ~intrenb; | ||
348 | outl(enable, emu->port + INTE); | ||
349 | spin_unlock_irqrestore(&emu->emu_lock, flags); | ||
350 | } | ||
351 | |||
352 | |||
341 | static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime) | 353 | static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime) |
342 | { | 354 | { |
343 | kfree(runtime->private_data); | 355 | kfree(runtime->private_data); |
@@ -1040,6 +1052,15 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id, | |||
1040 | 1052 | ||
1041 | snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); | 1053 | snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); |
1042 | spin_lock(&chip->emu_lock); | 1054 | spin_lock(&chip->emu_lock); |
1055 | |||
1056 | if (chip->midi.dev_id && | ||
1057 | (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) { | ||
1058 | if (chip->midi.interrupt) | ||
1059 | chip->midi.interrupt(&chip->midi, status); | ||
1060 | else | ||
1061 | chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable); | ||
1062 | } | ||
1063 | |||
1043 | // acknowledge the interrupt if necessary | 1064 | // acknowledge the interrupt if necessary |
1044 | outl(status, chip->port+IPR); | 1065 | outl(status, chip->port+IPR); |
1045 | 1066 | ||
@@ -1309,6 +1330,82 @@ static int __devinit snd_ca0106_create(snd_card_t *card, | |||
1309 | return 0; | 1330 | return 0; |
1310 | } | 1331 | } |
1311 | 1332 | ||
1333 | |||
1334 | void ca0106_midi_interrupt_enable(ca_midi_t *midi, int intr){ | ||
1335 | snd_ca0106_intr_enable((ca0106_t *)(midi->dev_id), intr); | ||
1336 | } | ||
1337 | |||
1338 | void ca0106_midi_interrupt_disable(ca_midi_t *midi, int intr){ | ||
1339 | snd_ca0106_intr_disable((ca0106_t *)(midi->dev_id), intr); | ||
1340 | } | ||
1341 | |||
1342 | unsigned char ca0106_midi_read(ca_midi_t *midi, int idx){ | ||
1343 | return (unsigned char)snd_ca0106_ptr_read((ca0106_t *)(midi->dev_id), midi->port + idx, 0); | ||
1344 | } | ||
1345 | |||
1346 | void ca0106_midi_write(ca_midi_t *midi, int data, int idx){ | ||
1347 | snd_ca0106_ptr_write((ca0106_t *)(midi->dev_id), midi->port + idx, 0, data); | ||
1348 | } | ||
1349 | |||
1350 | snd_card_t *ca0106_dev_id_card(void *dev_id){ | ||
1351 | return ((ca0106_t *)dev_id)->card; | ||
1352 | } | ||
1353 | |||
1354 | int ca0106_dev_id_port(void *dev_id){ | ||
1355 | return ((ca0106_t *)dev_id)->port; | ||
1356 | } | ||
1357 | |||
1358 | static int __devinit snd_ca0106_midi(ca0106_t *chip, unsigned int channel) | ||
1359 | { | ||
1360 | ca_midi_t *midi; | ||
1361 | char *name; | ||
1362 | int err; | ||
1363 | |||
1364 | if(channel==CA0106_MIDI_CHAN_B) { | ||
1365 | name = "CA0106 MPU-401 (UART) B"; | ||
1366 | midi = &chip->midi2; | ||
1367 | midi->tx_enable = INTE_MIDI_TX_B; | ||
1368 | midi->rx_enable = INTE_MIDI_RX_B; | ||
1369 | midi->ipr_tx = IPR_MIDI_TX_B; | ||
1370 | midi->ipr_rx = IPR_MIDI_RX_B; | ||
1371 | midi->port = MIDI_UART_B_DATA; | ||
1372 | } else { | ||
1373 | name = "CA0106 MPU-401 (UART)"; | ||
1374 | midi = &chip->midi; | ||
1375 | midi->tx_enable = INTE_MIDI_TX_A; | ||
1376 | midi->rx_enable = INTE_MIDI_TX_B; | ||
1377 | midi->ipr_tx = IPR_MIDI_TX_A; | ||
1378 | midi->ipr_rx = IPR_MIDI_RX_A; | ||
1379 | midi->port = MIDI_UART_A_DATA; | ||
1380 | } | ||
1381 | |||
1382 | midi->reset = CA0106_MPU401_RESET; | ||
1383 | midi->enter_uart = CA0106_MPU401_ENTER_UART; | ||
1384 | midi->ack = CA0106_MPU401_ACK; | ||
1385 | |||
1386 | midi->input_avail = CA0106_MIDI_INPUT_AVAIL; | ||
1387 | midi->output_ready = CA0106_MIDI_OUTPUT_READY; | ||
1388 | |||
1389 | midi->channel = channel; | ||
1390 | |||
1391 | midi->interrupt_enable = ca0106_midi_interrupt_enable; | ||
1392 | midi->interrupt_disable = ca0106_midi_interrupt_disable; | ||
1393 | |||
1394 | midi->read = ca0106_midi_read; | ||
1395 | midi->write = ca0106_midi_write; | ||
1396 | |||
1397 | midi->get_dev_id_card = ca0106_dev_id_card; | ||
1398 | midi->get_dev_id_port = ca0106_dev_id_port; | ||
1399 | |||
1400 | midi->dev_id = chip; | ||
1401 | |||
1402 | if ((err = ca_midi_init(chip, midi, 0, name)) < 0) | ||
1403 | return err; | ||
1404 | |||
1405 | return 0; | ||
1406 | } | ||
1407 | |||
1408 | |||
1312 | static int __devinit snd_ca0106_probe(struct pci_dev *pci, | 1409 | static int __devinit snd_ca0106_probe(struct pci_dev *pci, |
1313 | const struct pci_device_id *pci_id) | 1410 | const struct pci_device_id *pci_id) |
1314 | { | 1411 | { |
@@ -1360,6 +1457,20 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci, | |||
1360 | return err; | 1457 | return err; |
1361 | } | 1458 | } |
1362 | 1459 | ||
1460 | #ifdef CONFIG_SND_DEBUG_DETECT | ||
1461 | printk("ca0106: probe for MIDI channel A ..."); | ||
1462 | #endif | ||
1463 | if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) { | ||
1464 | snd_card_free(card); | ||
1465 | #ifdef CONFIG_SND_DEBUG_DETECT | ||
1466 | printk(" failed, err=0x%x\n",err); | ||
1467 | #endif | ||
1468 | return err; | ||
1469 | } | ||
1470 | #ifdef CONFIG_SND_DEBUG_DETECT | ||
1471 | printk(" done.\n"); | ||
1472 | #endif | ||
1473 | |||
1363 | snd_ca0106_proc_init(chip); | 1474 | snd_ca0106_proc_init(chip); |
1364 | 1475 | ||
1365 | if ((err = snd_card_register(card)) < 0) { | 1476 | if ((err = snd_card_register(card)) < 0) { |
diff --git a/sound/pci/ca0106/ca_midi.c b/sound/pci/ca0106/ca_midi.c new file mode 100644 index 000000000000..f439d14876b0 --- /dev/null +++ b/sound/pci/ca0106/ca_midi.c | |||
@@ -0,0 +1,304 @@ | |||
1 | /* | ||
2 | * Copyright 10/16/2005 Tilman Kranz <tilde@tk-sls.de> | ||
3 | * Creative Audio MIDI, for the CA0106 Driver | ||
4 | * Version: 0.0.1 | ||
5 | * | ||
6 | * Changelog: | ||
7 | * Implementation is based on mpu401 and emu10k1x and | ||
8 | * tested with ca0106. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | * | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include <linux/spinlock.h> | ||
28 | #include <sound/driver.h> | ||
29 | #include <sound/core.h> | ||
30 | #include <sound/rawmidi.h> | ||
31 | |||
32 | #include "ca_midi.h" | ||
33 | |||
34 | #define ca_midi_write_data(midi, data) midi->write(midi, data, 0) | ||
35 | #define ca_midi_write_cmd(midi, data) midi->write(midi, data, 1) | ||
36 | #define ca_midi_read_data(midi) midi->read(midi, 0) | ||
37 | #define ca_midi_read_stat(midi) midi->read(midi, 1) | ||
38 | #define ca_midi_input_avail(midi) (!(ca_midi_read_stat(midi) & midi->input_avail)) | ||
39 | #define ca_midi_output_ready(midi) (!(ca_midi_read_stat(midi) & midi->output_ready)) | ||
40 | |||
41 | static void ca_midi_clear_rx(ca_midi_t *midi) | ||
42 | { | ||
43 | int timeout = 100000; | ||
44 | for (; timeout > 0 && ca_midi_input_avail(midi); timeout--) | ||
45 | ca_midi_read_data(midi); | ||
46 | #ifdef CONFIG_SND_DEBUG | ||
47 | if (timeout <= 0) | ||
48 | snd_printk(KERN_ERR "ca_midi_clear_rx: timeout (status = 0x%x)\n", ca_midi_read_stat(midi)); | ||
49 | #endif | ||
50 | } | ||
51 | |||
52 | void ca_midi_interrupt(ca_midi_t *midi, unsigned int status) { | ||
53 | unsigned char byte; | ||
54 | |||
55 | if (midi->rmidi == NULL) { | ||
56 | midi->interrupt_disable(midi,midi->tx_enable | midi->rx_enable); | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | spin_lock(&midi->input_lock); | ||
61 | if ((status & midi->ipr_rx) && ca_midi_input_avail(midi)) { | ||
62 | if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) { | ||
63 | ca_midi_clear_rx(midi); | ||
64 | } else { | ||
65 | byte = ca_midi_read_data(midi); | ||
66 | if(midi->substream_input) | ||
67 | snd_rawmidi_receive(midi->substream_input, &byte, 1); | ||
68 | |||
69 | |||
70 | } | ||
71 | } | ||
72 | spin_unlock(&midi->input_lock); | ||
73 | |||
74 | spin_lock(&midi->output_lock); | ||
75 | if ((status & midi->ipr_tx) && ca_midi_output_ready(midi)) { | ||
76 | if (midi->substream_output && | ||
77 | snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) { | ||
78 | ca_midi_write_data(midi, byte); | ||
79 | } else { | ||
80 | midi->interrupt_disable(midi,midi->tx_enable); | ||
81 | } | ||
82 | } | ||
83 | spin_unlock(&midi->output_lock); | ||
84 | |||
85 | } | ||
86 | |||
87 | static void ca_midi_cmd(ca_midi_t *midi, unsigned char cmd, int ack) | ||
88 | { | ||
89 | unsigned long flags; | ||
90 | int timeout, ok; | ||
91 | |||
92 | spin_lock_irqsave(&midi->input_lock, flags); | ||
93 | ca_midi_write_data(midi, 0x00); | ||
94 | /* ca_midi_clear_rx(midi); */ | ||
95 | |||
96 | ca_midi_write_cmd(midi, cmd); | ||
97 | if (ack) { | ||
98 | ok = 0; | ||
99 | timeout = 10000; | ||
100 | while (!ok && timeout-- > 0) { | ||
101 | if (ca_midi_input_avail(midi)) { | ||
102 | if (ca_midi_read_data(midi) == midi->ack) | ||
103 | ok = 1; | ||
104 | } | ||
105 | } | ||
106 | if (!ok && ca_midi_read_data(midi) == midi->ack) | ||
107 | ok = 1; | ||
108 | } else { | ||
109 | ok = 1; | ||
110 | } | ||
111 | spin_unlock_irqrestore(&midi->input_lock, flags); | ||
112 | if (!ok) | ||
113 | snd_printk(KERN_ERR "ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n", | ||
114 | cmd, | ||
115 | midi->get_dev_id_port(midi->dev_id), | ||
116 | ca_midi_read_stat(midi), | ||
117 | ca_midi_read_data(midi)); | ||
118 | } | ||
119 | |||
120 | static int ca_midi_input_open(snd_rawmidi_substream_t * substream) | ||
121 | { | ||
122 | ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data; | ||
123 | unsigned long flags; | ||
124 | |||
125 | snd_assert(midi->dev_id, return -ENXIO); | ||
126 | spin_lock_irqsave(&midi->open_lock, flags); | ||
127 | midi->midi_mode |= CA_MIDI_MODE_INPUT; | ||
128 | midi->substream_input = substream; | ||
129 | if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) { | ||
130 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
131 | ca_midi_cmd(midi, midi->reset, 1); | ||
132 | ca_midi_cmd(midi, midi->enter_uart, 1); | ||
133 | } else { | ||
134 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
135 | } | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | static int ca_midi_output_open(snd_rawmidi_substream_t * substream) | ||
140 | { | ||
141 | ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data; | ||
142 | unsigned long flags; | ||
143 | |||
144 | snd_assert(midi->dev_id, return -ENXIO); | ||
145 | spin_lock_irqsave(&midi->open_lock, flags); | ||
146 | midi->midi_mode |= CA_MIDI_MODE_OUTPUT; | ||
147 | midi->substream_output = substream; | ||
148 | if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) { | ||
149 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
150 | ca_midi_cmd(midi, midi->reset, 1); | ||
151 | ca_midi_cmd(midi, midi->enter_uart, 1); | ||
152 | } else { | ||
153 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
154 | } | ||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | static int ca_midi_input_close(snd_rawmidi_substream_t * substream) | ||
159 | { | ||
160 | ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data; | ||
161 | unsigned long flags; | ||
162 | |||
163 | snd_assert(midi->dev_id, return -ENXIO); | ||
164 | spin_lock_irqsave(&midi->open_lock, flags); | ||
165 | midi->interrupt_disable(midi,midi->rx_enable); | ||
166 | midi->midi_mode &= ~CA_MIDI_MODE_INPUT; | ||
167 | midi->substream_input = NULL; | ||
168 | if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) { | ||
169 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
170 | ca_midi_cmd(midi, midi->reset, 0); | ||
171 | } else { | ||
172 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
173 | } | ||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static int ca_midi_output_close(snd_rawmidi_substream_t * substream) | ||
178 | { | ||
179 | ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data; | ||
180 | unsigned long flags; | ||
181 | snd_assert(midi->dev_id, return -ENXIO); | ||
182 | |||
183 | spin_lock_irqsave(&midi->open_lock, flags); | ||
184 | |||
185 | midi->interrupt_disable(midi,midi->tx_enable); | ||
186 | midi->midi_mode &= ~CA_MIDI_MODE_OUTPUT; | ||
187 | midi->substream_output = NULL; | ||
188 | |||
189 | if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) { | ||
190 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
191 | ca_midi_cmd(midi, midi->reset, 0); | ||
192 | } else { | ||
193 | spin_unlock_irqrestore(&midi->open_lock, flags); | ||
194 | } | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static void ca_midi_input_trigger(snd_rawmidi_substream_t * substream, int up) | ||
199 | { | ||
200 | ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data; | ||
201 | snd_assert(midi->dev_id, return); | ||
202 | |||
203 | if (up) { | ||
204 | midi->interrupt_enable(midi,midi->rx_enable); | ||
205 | } else { | ||
206 | midi->interrupt_disable(midi, midi->rx_enable); | ||
207 | } | ||
208 | } | ||
209 | |||
210 | static void ca_midi_output_trigger(snd_rawmidi_substream_t * substream, int up) | ||
211 | { | ||
212 | ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data; | ||
213 | unsigned long flags; | ||
214 | |||
215 | snd_assert(midi->dev_id, return); | ||
216 | |||
217 | if (up) { | ||
218 | int max = 4; | ||
219 | unsigned char byte; | ||
220 | |||
221 | spin_lock_irqsave(&midi->output_lock, flags); | ||
222 | |||
223 | /* try to send some amount of bytes here before interrupts */ | ||
224 | while (max > 0) { | ||
225 | if (ca_midi_output_ready(midi)) { | ||
226 | if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT) || | ||
227 | snd_rawmidi_transmit(substream, &byte, 1) != 1) { | ||
228 | /* no more data */ | ||
229 | spin_unlock_irqrestore(&midi->output_lock, flags); | ||
230 | return; | ||
231 | } | ||
232 | ca_midi_write_data(midi, byte); | ||
233 | max--; | ||
234 | } else { | ||
235 | break; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | spin_unlock_irqrestore(&midi->output_lock, flags); | ||
240 | midi->interrupt_enable(midi,midi->tx_enable); | ||
241 | |||
242 | } else { | ||
243 | midi->interrupt_disable(midi,midi->tx_enable); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | static snd_rawmidi_ops_t ca_midi_output = | ||
248 | { | ||
249 | .open = ca_midi_output_open, | ||
250 | .close = ca_midi_output_close, | ||
251 | .trigger = ca_midi_output_trigger, | ||
252 | }; | ||
253 | |||
254 | static snd_rawmidi_ops_t ca_midi_input = | ||
255 | { | ||
256 | .open = ca_midi_input_open, | ||
257 | .close = ca_midi_input_close, | ||
258 | .trigger = ca_midi_input_trigger, | ||
259 | }; | ||
260 | |||
261 | void ca_midi_free(ca_midi_t *midi) { | ||
262 | midi->interrupt = NULL; | ||
263 | midi->interrupt_enable = NULL; | ||
264 | midi->interrupt_disable = NULL; | ||
265 | midi->read = NULL; | ||
266 | midi->write = NULL; | ||
267 | midi->get_dev_id_card = NULL; | ||
268 | midi->get_dev_id_port = NULL; | ||
269 | midi->rmidi = NULL; | ||
270 | } | ||
271 | |||
272 | static void ca_rmidi_free(snd_rawmidi_t *rmidi) | ||
273 | { | ||
274 | ca_midi_free((ca_midi_t *)rmidi->private_data); | ||
275 | } | ||
276 | |||
277 | int __devinit ca_midi_init(void *dev_id, ca_midi_t *midi, int device, char *name) | ||
278 | { | ||
279 | snd_rawmidi_t *rmidi; | ||
280 | int err; | ||
281 | |||
282 | if ((err = snd_rawmidi_new(midi->get_dev_id_card(midi->dev_id), name, device, 1, 1, &rmidi)) < 0) | ||
283 | return err; | ||
284 | |||
285 | midi->dev_id = dev_id; | ||
286 | midi->interrupt = ca_midi_interrupt; | ||
287 | |||
288 | spin_lock_init(&midi->open_lock); | ||
289 | spin_lock_init(&midi->input_lock); | ||
290 | spin_lock_init(&midi->output_lock); | ||
291 | |||
292 | strcpy(rmidi->name, name); | ||
293 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &ca_midi_output); | ||
294 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &ca_midi_input); | ||
295 | rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | | ||
296 | SNDRV_RAWMIDI_INFO_INPUT | | ||
297 | SNDRV_RAWMIDI_INFO_DUPLEX; | ||
298 | rmidi->private_data = midi; | ||
299 | rmidi->private_free = ca_rmidi_free; | ||
300 | |||
301 | midi->rmidi = rmidi; | ||
302 | return 0; | ||
303 | } | ||
304 | |||
diff --git a/sound/pci/ca0106/ca_midi.h b/sound/pci/ca0106/ca_midi.h new file mode 100644 index 000000000000..95c8e1c170b1 --- /dev/null +++ b/sound/pci/ca0106/ca_midi.h | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * Copyright 10/16/2005 Tilman Kranz <tilde@tk-sls.de> | ||
3 | * Creative Audio MIDI, for the CA0106 Driver | ||
4 | * Version: 0.0.1 | ||
5 | * | ||
6 | * Changelog: | ||
7 | * See ca_midi.c | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | * GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include<linux/spinlock.h> | ||
26 | #include<sound/rawmidi.h> | ||
27 | #include<sound/mpu401.h> | ||
28 | |||
29 | #define CA_MIDI_MODE_INPUT MPU401_MODE_INPUT | ||
30 | #define CA_MIDI_MODE_OUTPUT MPU401_MODE_OUTPUT | ||
31 | |||
32 | typedef struct ca_midi ca_midi_t; | ||
33 | struct ca_midi { | ||
34 | |||
35 | snd_rawmidi_t *rmidi; | ||
36 | snd_rawmidi_substream_t *substream_input; | ||
37 | snd_rawmidi_substream_t *substream_output; | ||
38 | |||
39 | void *dev_id; | ||
40 | |||
41 | spinlock_t input_lock; | ||
42 | spinlock_t output_lock; | ||
43 | spinlock_t open_lock; | ||
44 | |||
45 | unsigned int channel; | ||
46 | |||
47 | unsigned int midi_mode; | ||
48 | int port; | ||
49 | int tx_enable, rx_enable; | ||
50 | int ipr_tx, ipr_rx; | ||
51 | |||
52 | int input_avail, output_ready; | ||
53 | int ack, reset, enter_uart; | ||
54 | |||
55 | void (*interrupt)(ca_midi_t *midi, unsigned int status); | ||
56 | void (*interrupt_enable)(ca_midi_t *midi, int intr); | ||
57 | void (*interrupt_disable)(ca_midi_t *midi, int intr); | ||
58 | |||
59 | unsigned char (*read)(ca_midi_t *midi, int idx); | ||
60 | void (*write)(ca_midi_t *midi, int data, int idx); | ||
61 | |||
62 | /* get info from dev_id */ | ||
63 | snd_card_t *(*get_dev_id_card)(void *dev_id); | ||
64 | int (*get_dev_id_port)(void *dev_id); | ||
65 | }; | ||
66 | |||
67 | void ca_midi_interrupt(ca_midi_t *midi, unsigned int status); | ||
68 | |||
69 | int __devinit ca_midi_init(void *card, ca_midi_t *midi, int device, char *name); | ||
70 | |||
71 | void ca_midi_free(ca_midi_t *midi); | ||
72 | |||