2 * ALSA Driver for Ego Systems Inc. (ESI) Miditerminal 4140
3 * Copyright (c) 2006 by Matthias König <mk@phasorlab.de>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/platform_device.h>
24 #include <linux/parport.h>
25 #include <linux/spinlock.h>
26 #include <linux/delay.h>
27 #include <sound/core.h>
28 #include <sound/initval.h>
29 #include <sound/rawmidi.h>
30 #include <sound/control.h>
32 #define CARD_NAME "Miditerminal 4140"
33 #define DRIVER_NAME "MTS64"
34 #define PLATFORM_DRIVER "snd_mts64"
36 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
37 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
38 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
40 static struct platform_device
*platform_devices
[SNDRV_CARDS
];
41 static int device_count
;
43 module_param_array(index
, int, NULL
, S_IRUGO
);
44 MODULE_PARM_DESC(index
, "Index value for " CARD_NAME
" soundcard.");
45 module_param_array(id
, charp
, NULL
, S_IRUGO
);
46 MODULE_PARM_DESC(id
, "ID string for " CARD_NAME
" soundcard.");
47 module_param_array(enable
, bool, NULL
, S_IRUGO
);
48 MODULE_PARM_DESC(enable
, "Enable " CARD_NAME
" soundcard.");
50 MODULE_AUTHOR("Matthias Koenig <mk@phasorlab.de>");
51 MODULE_DESCRIPTION("ESI Miditerminal 4140");
52 MODULE_LICENSE("GPL");
53 MODULE_SUPPORTED_DEVICE("{{ESI,Miditerminal 4140}}");
55 /*********************************************************************
57 *********************************************************************/
58 #define MTS64_NUM_INPUT_PORTS 5
59 #define MTS64_NUM_OUTPUT_PORTS 4
60 #define MTS64_SMPTE_SUBSTREAM 4
64 struct snd_card
*card
;
65 struct snd_rawmidi
*rmidi
;
66 struct pardevice
*pardev
;
70 int current_midi_output_port
;
71 int current_midi_input_port
;
72 u8 mode
[MTS64_NUM_INPUT_PORTS
];
73 struct snd_rawmidi_substream
*midi_input_substream
[MTS64_NUM_INPUT_PORTS
];
75 u8 time
[4]; /* [0]=hh, [1]=mm, [2]=ss, [3]=ff */
79 static int snd_mts64_free(struct mts64
*mts
)
85 static int __devinit
snd_mts64_create(struct snd_card
*card
,
86 struct pardevice
*pardev
,
93 mts
= kzalloc(sizeof(struct mts64
), GFP_KERNEL
);
97 /* Init chip specific data */
98 spin_lock_init(&mts
->lock
);
100 mts
->pardev
= pardev
;
101 mts
->current_midi_output_port
= -1;
102 mts
->current_midi_input_port
= -1;
109 /*********************************************************************
110 * HW register related constants
111 *********************************************************************/
114 #define MTS64_STAT_BSY 0x80
115 #define MTS64_STAT_BIT_SET 0x20 /* readout process, bit is set */
116 #define MTS64_STAT_PORT 0x10 /* read byte is a port number */
119 #define MTS64_CTL_READOUT 0x08 /* enable readout */
120 #define MTS64_CTL_WRITE_CMD 0x06
121 #define MTS64_CTL_WRITE_DATA 0x02
122 #define MTS64_CTL_STROBE 0x01
125 #define MTS64_CMD_RESET 0xfe
126 #define MTS64_CMD_PROBE 0x8f /* Used in probing procedure */
127 #define MTS64_CMD_SMPTE_SET_TIME 0xe8
128 #define MTS64_CMD_SMPTE_SET_FPS 0xee
129 #define MTS64_CMD_SMPTE_STOP 0xef
130 #define MTS64_CMD_SMPTE_FPS_24 0xe3
131 #define MTS64_CMD_SMPTE_FPS_25 0xe2
132 #define MTS64_CMD_SMPTE_FPS_2997 0xe4
133 #define MTS64_CMD_SMPTE_FPS_30D 0xe1
134 #define MTS64_CMD_SMPTE_FPS_30 0xe0
135 #define MTS64_CMD_COM_OPEN 0xf8 /* setting the communication mode */
136 #define MTS64_CMD_COM_CLOSE1 0xff /* clearing communication mode */
137 #define MTS64_CMD_COM_CLOSE2 0xf5
139 /*********************************************************************
140 * Hardware specific functions
141 *********************************************************************/
142 static void mts64_enable_readout(struct parport
*p
);
143 static void mts64_disable_readout(struct parport
*p
);
144 static int mts64_device_ready(struct parport
*p
);
145 static int mts64_device_init(struct parport
*p
);
146 static int mts64_device_open(struct mts64
*mts
);
147 static int mts64_device_close(struct mts64
*mts
);
148 static u8
mts64_map_midi_input(u8 c
);
149 static int mts64_probe(struct parport
*p
);
150 static u16
mts64_read(struct parport
*p
);
151 static u8
mts64_read_char(struct parport
*p
);
152 static void mts64_smpte_start(struct parport
*p
,
153 u8 hours
, u8 minutes
,
154 u8 seconds
, u8 frames
,
156 static void mts64_smpte_stop(struct parport
*p
);
157 static void mts64_write_command(struct parport
*p
, u8 c
);
158 static void mts64_write_data(struct parport
*p
, u8 c
);
159 static void mts64_write_midi(struct mts64
*mts
, u8 c
, int midiport
);
162 /* Enables the readout procedure
164 * Before we can read a midi byte from the device, we have to set
165 * bit 3 of control port.
167 static void mts64_enable_readout(struct parport
*p
)
171 c
= parport_read_control(p
);
172 c
|= MTS64_CTL_READOUT
;
173 parport_write_control(p
, c
);
178 * Readout is disabled by clearing bit 3 of control
180 static void mts64_disable_readout(struct parport
*p
)
184 c
= parport_read_control(p
);
185 c
&= ~MTS64_CTL_READOUT
;
186 parport_write_control(p
, c
);
189 /* waits for device ready
191 * Checks if BUSY (Bit 7 of status) is clear
195 static int mts64_device_ready(struct parport
*p
)
200 for (i
= 0; i
< 0xffff; ++i
) {
201 c
= parport_read_status(p
);
210 /* Init device (LED blinking startup magic)
216 static int __devinit
mts64_device_init(struct parport
*p
)
220 mts64_write_command(p
, MTS64_CMD_RESET
);
222 for (i
= 0; i
< 64; ++i
) {
225 if (mts64_probe(p
) == 0) {
227 mts64_disable_readout(p
);
231 mts64_disable_readout(p
);
237 * Opens the device (set communication mode)
239 static int mts64_device_open(struct mts64
*mts
)
242 struct parport
*p
= mts
->pardev
->port
;
244 for (i
= 0; i
< 5; ++i
)
245 mts64_write_command(p
, MTS64_CMD_COM_OPEN
);
251 * Close device (clear communication mode)
253 static int mts64_device_close(struct mts64
*mts
)
256 struct parport
*p
= mts
->pardev
->port
;
258 for (i
= 0; i
< 5; ++i
) {
259 mts64_write_command(p
, MTS64_CMD_COM_CLOSE1
);
260 mts64_write_command(p
, MTS64_CMD_COM_CLOSE2
);
266 /* map hardware port to substream number
268 * When reading a byte from the device, the device tells us
269 * on what port the byte is. This HW port has to be mapped to
270 * the midiport (substream number).
271 * substream 0-3 are Midiports 1-4
272 * substream 4 is SMPTE Timecode
273 * The mapping is done by the table:
274 * HW | 0 | 1 | 2 | 3 | 4
275 * SW | 0 | 1 | 4 | 2 | 3
277 static u8
mts64_map_midi_input(u8 c
)
279 static u8 map
[] = { 0, 1, 4, 2, 3 };
285 /* Probe parport for device
287 * Do we have a Miditerminal 4140 on parport?
292 static int __devinit
mts64_probe(struct parport
*p
)
297 mts64_write_command(p
, MTS64_CMD_PROBE
);
304 if (c
!= MTS64_CMD_PROBE
)
311 /* Read byte incl. status from device
314 * data in lower 8 bits and status in upper 8 bits
316 static u16
mts64_read(struct parport
*p
)
320 mts64_device_ready(p
);
321 mts64_enable_readout(p
);
322 status
= parport_read_status(p
);
323 data
= mts64_read_char(p
);
324 mts64_disable_readout(p
);
326 return (status
<< 8) | data
;
329 /* Read a byte from device
331 * Note, that readout mode has to be enabled.
332 * readout procedure is as follows:
333 * - Write number of the Bit to read to DATA
335 * - Bit 5 of STATUS indicates if Bit is set
338 * Byte read from device
340 static u8
mts64_read_char(struct parport
*p
)
346 for (i
= 0; i
< 8; ++i
) {
347 parport_write_data(p
, i
);
349 status
= parport_read_status(p
);
350 if (status
& MTS64_STAT_BIT_SET
)
357 /* Starts SMPTE Timecode generation
359 * The device creates SMPTE Timecode by hardware.
363 * 3 30 fps (Drop-frame)
366 static void mts64_smpte_start(struct parport
*p
,
367 u8 hours
, u8 minutes
,
368 u8 seconds
, u8 frames
,
371 static u8 fps
[5] = { MTS64_CMD_SMPTE_FPS_24
,
372 MTS64_CMD_SMPTE_FPS_25
,
373 MTS64_CMD_SMPTE_FPS_2997
,
374 MTS64_CMD_SMPTE_FPS_30D
,
375 MTS64_CMD_SMPTE_FPS_30
};
377 mts64_write_command(p
, MTS64_CMD_SMPTE_SET_TIME
);
378 mts64_write_command(p
, frames
);
379 mts64_write_command(p
, seconds
);
380 mts64_write_command(p
, minutes
);
381 mts64_write_command(p
, hours
);
383 mts64_write_command(p
, MTS64_CMD_SMPTE_SET_FPS
);
384 mts64_write_command(p
, fps
[idx
]);
387 /* Stops SMPTE Timecode generation
389 static void mts64_smpte_stop(struct parport
*p
)
391 mts64_write_command(p
, MTS64_CMD_SMPTE_STOP
);
394 /* Write a command byte to device
396 static void mts64_write_command(struct parport
*p
, u8 c
)
398 mts64_device_ready(p
);
400 parport_write_data(p
, c
);
402 parport_write_control(p
, MTS64_CTL_WRITE_CMD
);
403 parport_write_control(p
, MTS64_CTL_WRITE_CMD
| MTS64_CTL_STROBE
);
404 parport_write_control(p
, MTS64_CTL_WRITE_CMD
);
407 /* Write a data byte to device
409 static void mts64_write_data(struct parport
*p
, u8 c
)
411 mts64_device_ready(p
);
413 parport_write_data(p
, c
);
415 parport_write_control(p
, MTS64_CTL_WRITE_DATA
);
416 parport_write_control(p
, MTS64_CTL_WRITE_DATA
| MTS64_CTL_STROBE
);
417 parport_write_control(p
, MTS64_CTL_WRITE_DATA
);
420 /* Write a MIDI byte to midiport
422 * midiport ranges from 0-3 and maps to Ports 1-4
423 * assumptions: communication mode is on
425 static void mts64_write_midi(struct mts64
*mts
, u8 c
,
428 struct parport
*p
= mts
->pardev
->port
;
430 /* check current midiport */
431 if (mts
->current_midi_output_port
!= midiport
)
432 mts64_write_command(p
, midiport
);
434 /* write midi byte */
435 mts64_write_data(p
, c
);
438 /*********************************************************************
440 *********************************************************************/
443 static int snd_mts64_ctl_smpte_switch_info(struct snd_kcontrol
*kctl
,
444 struct snd_ctl_elem_info
*uinfo
)
446 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
448 uinfo
->value
.integer
.min
= 0;
449 uinfo
->value
.integer
.max
= 1;
453 static int snd_mts64_ctl_smpte_switch_get(struct snd_kcontrol
* kctl
,
454 struct snd_ctl_elem_value
*uctl
)
456 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
458 spin_lock_irq(&mts
->lock
);
459 uctl
->value
.integer
.value
[0] = mts
->smpte_switch
;
460 spin_unlock_irq(&mts
->lock
);
465 /* smpte_switch is not accessed from IRQ handler, so we just need
466 to protect the HW access */
467 static int snd_mts64_ctl_smpte_switch_put(struct snd_kcontrol
* kctl
,
468 struct snd_ctl_elem_value
*uctl
)
470 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
473 spin_lock_irq(&mts
->lock
);
474 if (mts
->smpte_switch
== uctl
->value
.integer
.value
[0])
478 mts
->smpte_switch
= uctl
->value
.integer
.value
[0];
479 if (mts
->smpte_switch
) {
480 mts64_smpte_start(mts
->pardev
->port
,
481 mts
->time
[0], mts
->time
[1],
482 mts
->time
[2], mts
->time
[3],
485 mts64_smpte_stop(mts
->pardev
->port
);
488 spin_unlock_irq(&mts
->lock
);
492 static struct snd_kcontrol_new mts64_ctl_smpte_switch __devinitdata
= {
493 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
494 .name
= "SMPTE Playback Switch",
496 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
498 .info
= snd_mts64_ctl_smpte_switch_info
,
499 .get
= snd_mts64_ctl_smpte_switch_get
,
500 .put
= snd_mts64_ctl_smpte_switch_put
504 static int snd_mts64_ctl_smpte_time_h_info(struct snd_kcontrol
*kctl
,
505 struct snd_ctl_elem_info
*uinfo
)
507 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
509 uinfo
->value
.integer
.min
= 0;
510 uinfo
->value
.integer
.max
= 23;
514 static int snd_mts64_ctl_smpte_time_f_info(struct snd_kcontrol
*kctl
,
515 struct snd_ctl_elem_info
*uinfo
)
517 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
519 uinfo
->value
.integer
.min
= 0;
520 uinfo
->value
.integer
.max
= 99;
524 static int snd_mts64_ctl_smpte_time_info(struct snd_kcontrol
*kctl
,
525 struct snd_ctl_elem_info
*uinfo
)
527 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
529 uinfo
->value
.integer
.min
= 0;
530 uinfo
->value
.integer
.max
= 59;
534 static int snd_mts64_ctl_smpte_time_get(struct snd_kcontrol
*kctl
,
535 struct snd_ctl_elem_value
*uctl
)
537 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
538 int idx
= kctl
->private_value
;
540 spin_lock_irq(&mts
->lock
);
541 uctl
->value
.integer
.value
[0] = mts
->time
[idx
];
542 spin_unlock_irq(&mts
->lock
);
547 static int snd_mts64_ctl_smpte_time_put(struct snd_kcontrol
*kctl
,
548 struct snd_ctl_elem_value
*uctl
)
550 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
551 int idx
= kctl
->private_value
;
554 spin_lock_irq(&mts
->lock
);
555 if (mts
->time
[idx
] != uctl
->value
.integer
.value
[0]) {
557 mts
->time
[idx
] = uctl
->value
.integer
.value
[0];
559 spin_unlock_irq(&mts
->lock
);
564 static struct snd_kcontrol_new mts64_ctl_smpte_time_hours __devinitdata
= {
565 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
566 .name
= "SMPTE Time Hours",
568 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
570 .info
= snd_mts64_ctl_smpte_time_h_info
,
571 .get
= snd_mts64_ctl_smpte_time_get
,
572 .put
= snd_mts64_ctl_smpte_time_put
575 static struct snd_kcontrol_new mts64_ctl_smpte_time_minutes __devinitdata
= {
576 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
577 .name
= "SMPTE Time Minutes",
579 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
581 .info
= snd_mts64_ctl_smpte_time_info
,
582 .get
= snd_mts64_ctl_smpte_time_get
,
583 .put
= snd_mts64_ctl_smpte_time_put
586 static struct snd_kcontrol_new mts64_ctl_smpte_time_seconds __devinitdata
= {
587 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
588 .name
= "SMPTE Time Seconds",
590 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
592 .info
= snd_mts64_ctl_smpte_time_info
,
593 .get
= snd_mts64_ctl_smpte_time_get
,
594 .put
= snd_mts64_ctl_smpte_time_put
597 static struct snd_kcontrol_new mts64_ctl_smpte_time_frames __devinitdata
= {
598 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
599 .name
= "SMPTE Time Frames",
601 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
603 .info
= snd_mts64_ctl_smpte_time_f_info
,
604 .get
= snd_mts64_ctl_smpte_time_get
,
605 .put
= snd_mts64_ctl_smpte_time_put
609 static int snd_mts64_ctl_smpte_fps_info(struct snd_kcontrol
*kctl
,
610 struct snd_ctl_elem_info
*uinfo
)
612 static char *texts
[5] = { "24",
618 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
620 uinfo
->value
.enumerated
.items
= 5;
621 if (uinfo
->value
.enumerated
.item
> 4)
622 uinfo
->value
.enumerated
.item
= 4;
623 strcpy(uinfo
->value
.enumerated
.name
,
624 texts
[uinfo
->value
.enumerated
.item
]);
629 static int snd_mts64_ctl_smpte_fps_get(struct snd_kcontrol
*kctl
,
630 struct snd_ctl_elem_value
*uctl
)
632 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
634 spin_lock_irq(&mts
->lock
);
635 uctl
->value
.enumerated
.item
[0] = mts
->fps
;
636 spin_unlock_irq(&mts
->lock
);
641 static int snd_mts64_ctl_smpte_fps_put(struct snd_kcontrol
*kctl
,
642 struct snd_ctl_elem_value
*uctl
)
644 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
647 spin_lock_irq(&mts
->lock
);
648 if (mts
->fps
!= uctl
->value
.enumerated
.item
[0]) {
650 mts
->fps
= uctl
->value
.enumerated
.item
[0];
652 spin_unlock_irq(&mts
->lock
);
657 static struct snd_kcontrol_new mts64_ctl_smpte_fps __devinitdata
= {
658 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
661 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
663 .info
= snd_mts64_ctl_smpte_fps_info
,
664 .get
= snd_mts64_ctl_smpte_fps_get
,
665 .put
= snd_mts64_ctl_smpte_fps_put
669 static int __devinit
snd_mts64_ctl_create(struct snd_card
*card
,
673 static struct snd_kcontrol_new
*control
[] = {
674 &mts64_ctl_smpte_switch
,
675 &mts64_ctl_smpte_time_hours
,
676 &mts64_ctl_smpte_time_minutes
,
677 &mts64_ctl_smpte_time_seconds
,
678 &mts64_ctl_smpte_time_frames
,
679 &mts64_ctl_smpte_fps
,
682 for (i
= 0; control
[i
]; ++i
) {
683 err
= snd_ctl_add(card
, snd_ctl_new1(control
[i
], mts
));
685 snd_printd("Cannot create control: %s\n",
694 /*********************************************************************
696 *********************************************************************/
697 #define MTS64_MODE_INPUT_TRIGGERED 0x01
699 static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream
*substream
)
701 struct mts64
*mts
= substream
->rmidi
->private_data
;
703 if (mts
->open_count
== 0) {
704 /* We don't need a spinlock here, because this is just called
705 if the device has not been opened before.
706 So there aren't any IRQs from the device */
707 mts64_device_open(mts
);
716 static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream
*substream
)
718 struct mts64
*mts
= substream
->rmidi
->private_data
;
722 if (mts
->open_count
== 0) {
723 /* We need the spinlock_irqsave here because we can still
724 have IRQs at this point */
725 spin_lock_irqsave(&mts
->lock
, flags
);
726 mts64_device_close(mts
);
727 spin_unlock_irqrestore(&mts
->lock
, flags
);
731 } else if (mts
->open_count
< 0)
737 static void snd_mts64_rawmidi_output_trigger(struct snd_rawmidi_substream
*substream
,
740 struct mts64
*mts
= substream
->rmidi
->private_data
;
744 spin_lock_irqsave(&mts
->lock
, flags
);
745 while (snd_rawmidi_transmit_peek(substream
, &data
, 1) == 1) {
746 mts64_write_midi(mts
, data
, substream
->number
+1);
747 snd_rawmidi_transmit_ack(substream
, 1);
749 spin_unlock_irqrestore(&mts
->lock
, flags
);
752 static void snd_mts64_rawmidi_input_trigger(struct snd_rawmidi_substream
*substream
,
755 struct mts64
*mts
= substream
->rmidi
->private_data
;
758 spin_lock_irqsave(&mts
->lock
, flags
);
760 mts
->mode
[substream
->number
] |= MTS64_MODE_INPUT_TRIGGERED
;
762 mts
->mode
[substream
->number
] &= ~MTS64_MODE_INPUT_TRIGGERED
;
764 spin_unlock_irqrestore(&mts
->lock
, flags
);
767 static struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops
= {
768 .open
= snd_mts64_rawmidi_open
,
769 .close
= snd_mts64_rawmidi_close
,
770 .trigger
= snd_mts64_rawmidi_output_trigger
773 static struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops
= {
774 .open
= snd_mts64_rawmidi_open
,
775 .close
= snd_mts64_rawmidi_close
,
776 .trigger
= snd_mts64_rawmidi_input_trigger
779 /* Create and initialize the rawmidi component */
780 static int __devinit
snd_mts64_rawmidi_create(struct snd_card
*card
)
782 struct mts64
*mts
= card
->private_data
;
783 struct snd_rawmidi
*rmidi
;
784 struct snd_rawmidi_substream
*substream
;
785 struct list_head
*list
;
788 err
= snd_rawmidi_new(card
, CARD_NAME
, 0,
789 MTS64_NUM_OUTPUT_PORTS
,
790 MTS64_NUM_INPUT_PORTS
,
795 rmidi
->private_data
= mts
;
796 strcpy(rmidi
->name
, CARD_NAME
);
797 rmidi
->info_flags
= SNDRV_RAWMIDI_INFO_OUTPUT
|
798 SNDRV_RAWMIDI_INFO_INPUT
|
799 SNDRV_RAWMIDI_INFO_DUPLEX
;
803 /* register rawmidi ops */
804 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
,
805 &snd_mts64_rawmidi_output_ops
);
806 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
,
807 &snd_mts64_rawmidi_input_ops
);
809 /* name substreams */
812 &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_OUTPUT
].substreams
) {
813 substream
= list_entry(list
, struct snd_rawmidi_substream
, list
);
814 sprintf(substream
->name
,
815 "Miditerminal %d", substream
->number
+1);
819 &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_INPUT
].substreams
) {
820 substream
= list_entry(list
, struct snd_rawmidi_substream
, list
);
821 mts
->midi_input_substream
[substream
->number
] = substream
;
822 switch(substream
->number
) {
823 case MTS64_SMPTE_SUBSTREAM
:
824 strcpy(substream
->name
, "Miditerminal SMPTE");
827 sprintf(substream
->name
,
828 "Miditerminal %d", substream
->number
+1);
833 err
= snd_mts64_ctl_create(card
, mts
);
838 /*********************************************************************
840 *********************************************************************/
841 static void snd_mts64_interrupt(int irq
, void *private)
843 struct mts64
*mts
= ((struct snd_card
*)private)->private_data
;
846 struct snd_rawmidi_substream
*substream
;
848 spin_lock(&mts
->lock
);
849 ret
= mts64_read(mts
->pardev
->port
);
853 if (status
& MTS64_STAT_PORT
) {
854 mts
->current_midi_input_port
= mts64_map_midi_input(data
);
856 if (mts
->current_midi_input_port
== -1)
858 substream
= mts
->midi_input_substream
[mts
->current_midi_input_port
];
859 if (mts
->mode
[substream
->number
] & MTS64_MODE_INPUT_TRIGGERED
)
860 snd_rawmidi_receive(substream
, &data
, 1);
863 spin_unlock(&mts
->lock
);
866 static int __devinit
snd_mts64_probe_port(struct parport
*p
)
868 struct pardevice
*pardev
;
871 pardev
= parport_register_device(p
, DRIVER_NAME
,
877 if (parport_claim(pardev
)) {
878 parport_unregister_device(pardev
);
882 res
= mts64_probe(p
);
884 parport_release(pardev
);
885 parport_unregister_device(pardev
);
890 static void __devinit
snd_mts64_attach(struct parport
*p
)
892 struct platform_device
*device
;
894 device
= platform_device_alloc(PLATFORM_DRIVER
, device_count
);
898 /* Temporary assignment to forward the parport */
899 platform_set_drvdata(device
, p
);
901 if (platform_device_add(device
) < 0) {
902 platform_device_put(device
);
906 /* Since we dont get the return value of probe
907 * We need to check if device probing succeeded or not */
908 if (!platform_get_drvdata(device
)) {
909 platform_device_unregister(device
);
913 /* register device in global table */
914 platform_devices
[device_count
] = device
;
918 static void snd_mts64_detach(struct parport
*p
)
920 /* nothing to do here */
923 static struct parport_driver mts64_parport_driver
= {
925 .attach
= snd_mts64_attach
,
926 .detach
= snd_mts64_detach
929 /*********************************************************************
931 *********************************************************************/
932 static void snd_mts64_card_private_free(struct snd_card
*card
)
934 struct mts64
*mts
= card
->private_data
;
935 struct pardevice
*pardev
= mts
->pardev
;
938 if (mts
->pardev_claimed
)
939 parport_release(pardev
);
940 parport_unregister_device(pardev
);
946 static int __devinit
snd_mts64_probe(struct platform_device
*pdev
)
948 struct pardevice
*pardev
;
951 struct snd_card
*card
= NULL
;
952 struct mts64
*mts
= NULL
;
955 p
= platform_get_drvdata(pdev
);
956 platform_set_drvdata(pdev
, NULL
);
958 if (dev
>= SNDRV_CARDS
)
962 if ((err
= snd_mts64_probe_port(p
)) < 0)
965 card
= snd_card_new(index
[dev
], id
[dev
], THIS_MODULE
, 0);
967 snd_printd("Cannot create card\n");
970 strcpy(card
->driver
, DRIVER_NAME
);
971 strcpy(card
->shortname
, "ESI " CARD_NAME
);
972 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
973 card
->shortname
, p
->base
, p
->irq
);
975 pardev
= parport_register_device(p
, /* port */
976 DRIVER_NAME
, /* name */
979 snd_mts64_interrupt
, /* ISR */
980 PARPORT_DEV_EXCL
, /* flags */
981 (void *)card
); /* private */
982 if (pardev
== NULL
) {
983 snd_printd("Cannot register pardevice\n");
988 if ((err
= snd_mts64_create(card
, pardev
, &mts
)) < 0) {
989 snd_printd("Cannot create main component\n");
990 parport_unregister_device(pardev
);
993 card
->private_data
= mts
;
994 card
->private_free
= snd_mts64_card_private_free
;
996 if ((err
= snd_mts64_rawmidi_create(card
)) < 0) {
997 snd_printd("Creating Rawmidi component failed\n");
1002 if (parport_claim(pardev
)) {
1003 snd_printd("Cannot claim parport 0x%lx\n", pardev
->port
->base
);
1007 mts
->pardev_claimed
= 1;
1010 if ((err
= mts64_device_init(p
)) < 0)
1013 platform_set_drvdata(pdev
, card
);
1015 /* At this point card will be usable */
1016 if ((err
= snd_card_register(card
)) < 0) {
1017 snd_printd("Cannot register card\n");
1021 snd_printk("ESI Miditerminal 4140 on 0x%lx\n", p
->base
);
1025 snd_card_free(card
);
1029 static int __devexit
snd_mts64_remove(struct platform_device
*pdev
)
1031 struct snd_card
*card
= platform_get_drvdata(pdev
);
1034 snd_card_free(card
);
1040 static struct platform_driver snd_mts64_driver
= {
1041 .probe
= snd_mts64_probe
,
1042 .remove
= __devexit_p(snd_mts64_remove
),
1044 .name
= PLATFORM_DRIVER
1048 /*********************************************************************
1050 *********************************************************************/
1051 static void snd_mts64_unregister_all(void)
1055 for (i
= 0; i
< SNDRV_CARDS
; ++i
) {
1056 if (platform_devices
[i
]) {
1057 platform_device_unregister(platform_devices
[i
]);
1058 platform_devices
[i
] = NULL
;
1061 platform_driver_unregister(&snd_mts64_driver
);
1062 parport_unregister_driver(&mts64_parport_driver
);
1065 static int __init
snd_mts64_module_init(void)
1069 if ((err
= platform_driver_register(&snd_mts64_driver
)) < 0)
1072 if (parport_register_driver(&mts64_parport_driver
) != 0) {
1073 platform_driver_unregister(&snd_mts64_driver
);
1077 if (device_count
== 0) {
1078 snd_mts64_unregister_all();
1085 static void __exit
snd_mts64_module_exit(void)
1087 snd_mts64_unregister_all();
1090 module_init(snd_mts64_module_init
);
1091 module_exit(snd_mts64_module_exit
);