1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA Driver for Ego Systems Inc. (ESI) Miditerminal 4140
4 * Copyright (c) 2006 by Matthias König <mk@phasorlab.de>
7 #include <linux/init.h>
8 #include <linux/platform_device.h>
9 #include <linux/parport.h>
10 #include <linux/spinlock.h>
11 #include <linux/module.h>
12 #include <linux/delay.h>
13 #include <linux/slab.h>
14 #include <sound/core.h>
15 #include <sound/initval.h>
16 #include <sound/rawmidi.h>
17 #include <sound/control.h>
19 #define CARD_NAME "Miditerminal 4140"
20 #define DRIVER_NAME "MTS64"
21 #define PLATFORM_DRIVER "snd_mts64"
23 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
24 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
25 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
27 static struct platform_device
*platform_devices
[SNDRV_CARDS
];
28 static int device_count
;
30 module_param_array(index
, int, NULL
, 0444);
31 MODULE_PARM_DESC(index
, "Index value for " CARD_NAME
" soundcard.");
32 module_param_array(id
, charp
, NULL
, 0444);
33 MODULE_PARM_DESC(id
, "ID string for " CARD_NAME
" soundcard.");
34 module_param_array(enable
, bool, NULL
, 0444);
35 MODULE_PARM_DESC(enable
, "Enable " CARD_NAME
" soundcard.");
37 MODULE_AUTHOR("Matthias Koenig <mk@phasorlab.de>");
38 MODULE_DESCRIPTION("ESI Miditerminal 4140");
39 MODULE_LICENSE("GPL");
40 MODULE_SUPPORTED_DEVICE("{{ESI,Miditerminal 4140}}");
42 /*********************************************************************
44 *********************************************************************/
45 #define MTS64_NUM_INPUT_PORTS 5
46 #define MTS64_NUM_OUTPUT_PORTS 4
47 #define MTS64_SMPTE_SUBSTREAM 4
51 struct snd_card
*card
;
52 struct snd_rawmidi
*rmidi
;
53 struct pardevice
*pardev
;
55 int current_midi_output_port
;
56 int current_midi_input_port
;
57 u8 mode
[MTS64_NUM_INPUT_PORTS
];
58 struct snd_rawmidi_substream
*midi_input_substream
[MTS64_NUM_INPUT_PORTS
];
60 u8 time
[4]; /* [0]=hh, [1]=mm, [2]=ss, [3]=ff */
64 static int snd_mts64_free(struct mts64
*mts
)
70 static int snd_mts64_create(struct snd_card
*card
,
71 struct pardevice
*pardev
,
78 mts
= kzalloc(sizeof(struct mts64
), GFP_KERNEL
);
82 /* Init chip specific data */
83 spin_lock_init(&mts
->lock
);
86 mts
->current_midi_output_port
= -1;
87 mts
->current_midi_input_port
= -1;
94 /*********************************************************************
95 * HW register related constants
96 *********************************************************************/
99 #define MTS64_STAT_BSY 0x80
100 #define MTS64_STAT_BIT_SET 0x20 /* readout process, bit is set */
101 #define MTS64_STAT_PORT 0x10 /* read byte is a port number */
104 #define MTS64_CTL_READOUT 0x08 /* enable readout */
105 #define MTS64_CTL_WRITE_CMD 0x06
106 #define MTS64_CTL_WRITE_DATA 0x02
107 #define MTS64_CTL_STROBE 0x01
110 #define MTS64_CMD_RESET 0xfe
111 #define MTS64_CMD_PROBE 0x8f /* Used in probing procedure */
112 #define MTS64_CMD_SMPTE_SET_TIME 0xe8
113 #define MTS64_CMD_SMPTE_SET_FPS 0xee
114 #define MTS64_CMD_SMPTE_STOP 0xef
115 #define MTS64_CMD_SMPTE_FPS_24 0xe3
116 #define MTS64_CMD_SMPTE_FPS_25 0xe2
117 #define MTS64_CMD_SMPTE_FPS_2997 0xe4
118 #define MTS64_CMD_SMPTE_FPS_30D 0xe1
119 #define MTS64_CMD_SMPTE_FPS_30 0xe0
120 #define MTS64_CMD_COM_OPEN 0xf8 /* setting the communication mode */
121 #define MTS64_CMD_COM_CLOSE1 0xff /* clearing communication mode */
122 #define MTS64_CMD_COM_CLOSE2 0xf5
124 /*********************************************************************
125 * Hardware specific functions
126 *********************************************************************/
127 static void mts64_enable_readout(struct parport
*p
);
128 static void mts64_disable_readout(struct parport
*p
);
129 static int mts64_device_ready(struct parport
*p
);
130 static int mts64_device_init(struct parport
*p
);
131 static int mts64_device_open(struct mts64
*mts
);
132 static int mts64_device_close(struct mts64
*mts
);
133 static u8
mts64_map_midi_input(u8 c
);
134 static int mts64_probe(struct parport
*p
);
135 static u16
mts64_read(struct parport
*p
);
136 static u8
mts64_read_char(struct parport
*p
);
137 static void mts64_smpte_start(struct parport
*p
,
138 u8 hours
, u8 minutes
,
139 u8 seconds
, u8 frames
,
141 static void mts64_smpte_stop(struct parport
*p
);
142 static void mts64_write_command(struct parport
*p
, u8 c
);
143 static void mts64_write_data(struct parport
*p
, u8 c
);
144 static void mts64_write_midi(struct mts64
*mts
, u8 c
, int midiport
);
147 /* Enables the readout procedure
149 * Before we can read a midi byte from the device, we have to set
150 * bit 3 of control port.
152 static void mts64_enable_readout(struct parport
*p
)
156 c
= parport_read_control(p
);
157 c
|= MTS64_CTL_READOUT
;
158 parport_write_control(p
, c
);
163 * Readout is disabled by clearing bit 3 of control
165 static void mts64_disable_readout(struct parport
*p
)
169 c
= parport_read_control(p
);
170 c
&= ~MTS64_CTL_READOUT
;
171 parport_write_control(p
, c
);
174 /* waits for device ready
176 * Checks if BUSY (Bit 7 of status) is clear
180 static int mts64_device_ready(struct parport
*p
)
185 for (i
= 0; i
< 0xffff; ++i
) {
186 c
= parport_read_status(p
);
195 /* Init device (LED blinking startup magic)
201 static int mts64_device_init(struct parport
*p
)
205 mts64_write_command(p
, MTS64_CMD_RESET
);
207 for (i
= 0; i
< 64; ++i
) {
210 if (mts64_probe(p
) == 0) {
212 mts64_disable_readout(p
);
216 mts64_disable_readout(p
);
222 * Opens the device (set communication mode)
224 static int mts64_device_open(struct mts64
*mts
)
227 struct parport
*p
= mts
->pardev
->port
;
229 for (i
= 0; i
< 5; ++i
)
230 mts64_write_command(p
, MTS64_CMD_COM_OPEN
);
236 * Close device (clear communication mode)
238 static int mts64_device_close(struct mts64
*mts
)
241 struct parport
*p
= mts
->pardev
->port
;
243 for (i
= 0; i
< 5; ++i
) {
244 mts64_write_command(p
, MTS64_CMD_COM_CLOSE1
);
245 mts64_write_command(p
, MTS64_CMD_COM_CLOSE2
);
251 /* map hardware port to substream number
253 * When reading a byte from the device, the device tells us
254 * on what port the byte is. This HW port has to be mapped to
255 * the midiport (substream number).
256 * substream 0-3 are Midiports 1-4
257 * substream 4 is SMPTE Timecode
258 * The mapping is done by the table:
259 * HW | 0 | 1 | 2 | 3 | 4
260 * SW | 0 | 1 | 4 | 2 | 3
262 static u8
mts64_map_midi_input(u8 c
)
264 static const u8 map
[] = { 0, 1, 4, 2, 3 };
270 /* Probe parport for device
272 * Do we have a Miditerminal 4140 on parport?
277 static int mts64_probe(struct parport
*p
)
282 mts64_write_command(p
, MTS64_CMD_PROBE
);
289 if (c
!= MTS64_CMD_PROBE
)
296 /* Read byte incl. status from device
299 * data in lower 8 bits and status in upper 8 bits
301 static u16
mts64_read(struct parport
*p
)
305 mts64_device_ready(p
);
306 mts64_enable_readout(p
);
307 status
= parport_read_status(p
);
308 data
= mts64_read_char(p
);
309 mts64_disable_readout(p
);
311 return (status
<< 8) | data
;
314 /* Read a byte from device
316 * Note, that readout mode has to be enabled.
317 * readout procedure is as follows:
318 * - Write number of the Bit to read to DATA
320 * - Bit 5 of STATUS indicates if Bit is set
323 * Byte read from device
325 static u8
mts64_read_char(struct parport
*p
)
331 for (i
= 0; i
< 8; ++i
) {
332 parport_write_data(p
, i
);
334 status
= parport_read_status(p
);
335 if (status
& MTS64_STAT_BIT_SET
)
342 /* Starts SMPTE Timecode generation
344 * The device creates SMPTE Timecode by hardware.
348 * 3 30 fps (Drop-frame)
351 static void mts64_smpte_start(struct parport
*p
,
352 u8 hours
, u8 minutes
,
353 u8 seconds
, u8 frames
,
356 static const u8 fps
[5] = { MTS64_CMD_SMPTE_FPS_24
,
357 MTS64_CMD_SMPTE_FPS_25
,
358 MTS64_CMD_SMPTE_FPS_2997
,
359 MTS64_CMD_SMPTE_FPS_30D
,
360 MTS64_CMD_SMPTE_FPS_30
};
362 mts64_write_command(p
, MTS64_CMD_SMPTE_SET_TIME
);
363 mts64_write_command(p
, frames
);
364 mts64_write_command(p
, seconds
);
365 mts64_write_command(p
, minutes
);
366 mts64_write_command(p
, hours
);
368 mts64_write_command(p
, MTS64_CMD_SMPTE_SET_FPS
);
369 mts64_write_command(p
, fps
[idx
]);
372 /* Stops SMPTE Timecode generation
374 static void mts64_smpte_stop(struct parport
*p
)
376 mts64_write_command(p
, MTS64_CMD_SMPTE_STOP
);
379 /* Write a command byte to device
381 static void mts64_write_command(struct parport
*p
, u8 c
)
383 mts64_device_ready(p
);
385 parport_write_data(p
, c
);
387 parport_write_control(p
, MTS64_CTL_WRITE_CMD
);
388 parport_write_control(p
, MTS64_CTL_WRITE_CMD
| MTS64_CTL_STROBE
);
389 parport_write_control(p
, MTS64_CTL_WRITE_CMD
);
392 /* Write a data byte to device
394 static void mts64_write_data(struct parport
*p
, u8 c
)
396 mts64_device_ready(p
);
398 parport_write_data(p
, c
);
400 parport_write_control(p
, MTS64_CTL_WRITE_DATA
);
401 parport_write_control(p
, MTS64_CTL_WRITE_DATA
| MTS64_CTL_STROBE
);
402 parport_write_control(p
, MTS64_CTL_WRITE_DATA
);
405 /* Write a MIDI byte to midiport
407 * midiport ranges from 0-3 and maps to Ports 1-4
408 * assumptions: communication mode is on
410 static void mts64_write_midi(struct mts64
*mts
, u8 c
,
413 struct parport
*p
= mts
->pardev
->port
;
415 /* check current midiport */
416 if (mts
->current_midi_output_port
!= midiport
)
417 mts64_write_command(p
, midiport
);
419 /* write midi byte */
420 mts64_write_data(p
, c
);
423 /*********************************************************************
425 *********************************************************************/
428 #define snd_mts64_ctl_smpte_switch_info snd_ctl_boolean_mono_info
430 static int snd_mts64_ctl_smpte_switch_get(struct snd_kcontrol
* kctl
,
431 struct snd_ctl_elem_value
*uctl
)
433 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
435 spin_lock_irq(&mts
->lock
);
436 uctl
->value
.integer
.value
[0] = mts
->smpte_switch
;
437 spin_unlock_irq(&mts
->lock
);
442 /* smpte_switch is not accessed from IRQ handler, so we just need
443 to protect the HW access */
444 static int snd_mts64_ctl_smpte_switch_put(struct snd_kcontrol
* kctl
,
445 struct snd_ctl_elem_value
*uctl
)
447 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
449 int val
= !!uctl
->value
.integer
.value
[0];
451 spin_lock_irq(&mts
->lock
);
452 if (mts
->smpte_switch
== val
)
456 mts
->smpte_switch
= val
;
457 if (mts
->smpte_switch
) {
458 mts64_smpte_start(mts
->pardev
->port
,
459 mts
->time
[0], mts
->time
[1],
460 mts
->time
[2], mts
->time
[3],
463 mts64_smpte_stop(mts
->pardev
->port
);
466 spin_unlock_irq(&mts
->lock
);
470 static const struct snd_kcontrol_new mts64_ctl_smpte_switch
= {
471 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
472 .name
= "SMPTE Playback Switch",
474 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
476 .info
= snd_mts64_ctl_smpte_switch_info
,
477 .get
= snd_mts64_ctl_smpte_switch_get
,
478 .put
= snd_mts64_ctl_smpte_switch_put
482 static int snd_mts64_ctl_smpte_time_h_info(struct snd_kcontrol
*kctl
,
483 struct snd_ctl_elem_info
*uinfo
)
485 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
487 uinfo
->value
.integer
.min
= 0;
488 uinfo
->value
.integer
.max
= 23;
492 static int snd_mts64_ctl_smpte_time_f_info(struct snd_kcontrol
*kctl
,
493 struct snd_ctl_elem_info
*uinfo
)
495 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
497 uinfo
->value
.integer
.min
= 0;
498 uinfo
->value
.integer
.max
= 99;
502 static int snd_mts64_ctl_smpte_time_info(struct snd_kcontrol
*kctl
,
503 struct snd_ctl_elem_info
*uinfo
)
505 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
507 uinfo
->value
.integer
.min
= 0;
508 uinfo
->value
.integer
.max
= 59;
512 static int snd_mts64_ctl_smpte_time_get(struct snd_kcontrol
*kctl
,
513 struct snd_ctl_elem_value
*uctl
)
515 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
516 int idx
= kctl
->private_value
;
518 spin_lock_irq(&mts
->lock
);
519 uctl
->value
.integer
.value
[0] = mts
->time
[idx
];
520 spin_unlock_irq(&mts
->lock
);
525 static int snd_mts64_ctl_smpte_time_put(struct snd_kcontrol
*kctl
,
526 struct snd_ctl_elem_value
*uctl
)
528 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
529 int idx
= kctl
->private_value
;
530 unsigned int time
= uctl
->value
.integer
.value
[0] % 60;
533 spin_lock_irq(&mts
->lock
);
534 if (mts
->time
[idx
] != time
) {
536 mts
->time
[idx
] = time
;
538 spin_unlock_irq(&mts
->lock
);
543 static const struct snd_kcontrol_new mts64_ctl_smpte_time_hours
= {
544 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
545 .name
= "SMPTE Time Hours",
547 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
549 .info
= snd_mts64_ctl_smpte_time_h_info
,
550 .get
= snd_mts64_ctl_smpte_time_get
,
551 .put
= snd_mts64_ctl_smpte_time_put
554 static const struct snd_kcontrol_new mts64_ctl_smpte_time_minutes
= {
555 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
556 .name
= "SMPTE Time Minutes",
558 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
560 .info
= snd_mts64_ctl_smpte_time_info
,
561 .get
= snd_mts64_ctl_smpte_time_get
,
562 .put
= snd_mts64_ctl_smpte_time_put
565 static const struct snd_kcontrol_new mts64_ctl_smpte_time_seconds
= {
566 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
567 .name
= "SMPTE Time Seconds",
569 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
571 .info
= snd_mts64_ctl_smpte_time_info
,
572 .get
= snd_mts64_ctl_smpte_time_get
,
573 .put
= snd_mts64_ctl_smpte_time_put
576 static const struct snd_kcontrol_new mts64_ctl_smpte_time_frames
= {
577 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
578 .name
= "SMPTE Time Frames",
580 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
582 .info
= snd_mts64_ctl_smpte_time_f_info
,
583 .get
= snd_mts64_ctl_smpte_time_get
,
584 .put
= snd_mts64_ctl_smpte_time_put
588 static int snd_mts64_ctl_smpte_fps_info(struct snd_kcontrol
*kctl
,
589 struct snd_ctl_elem_info
*uinfo
)
591 static const char * const texts
[5] = {
592 "24", "25", "29.97", "30D", "30"
595 return snd_ctl_enum_info(uinfo
, 1, 5, texts
);
598 static int snd_mts64_ctl_smpte_fps_get(struct snd_kcontrol
*kctl
,
599 struct snd_ctl_elem_value
*uctl
)
601 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
603 spin_lock_irq(&mts
->lock
);
604 uctl
->value
.enumerated
.item
[0] = mts
->fps
;
605 spin_unlock_irq(&mts
->lock
);
610 static int snd_mts64_ctl_smpte_fps_put(struct snd_kcontrol
*kctl
,
611 struct snd_ctl_elem_value
*uctl
)
613 struct mts64
*mts
= snd_kcontrol_chip(kctl
);
616 if (uctl
->value
.enumerated
.item
[0] >= 5)
618 spin_lock_irq(&mts
->lock
);
619 if (mts
->fps
!= uctl
->value
.enumerated
.item
[0]) {
621 mts
->fps
= uctl
->value
.enumerated
.item
[0];
623 spin_unlock_irq(&mts
->lock
);
628 static const struct snd_kcontrol_new mts64_ctl_smpte_fps
= {
629 .iface
= SNDRV_CTL_ELEM_IFACE_RAWMIDI
,
632 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
634 .info
= snd_mts64_ctl_smpte_fps_info
,
635 .get
= snd_mts64_ctl_smpte_fps_get
,
636 .put
= snd_mts64_ctl_smpte_fps_put
640 static int snd_mts64_ctl_create(struct snd_card
*card
,
644 static const struct snd_kcontrol_new
*control
[] = {
645 &mts64_ctl_smpte_switch
,
646 &mts64_ctl_smpte_time_hours
,
647 &mts64_ctl_smpte_time_minutes
,
648 &mts64_ctl_smpte_time_seconds
,
649 &mts64_ctl_smpte_time_frames
,
650 &mts64_ctl_smpte_fps
,
653 for (i
= 0; control
[i
]; ++i
) {
654 err
= snd_ctl_add(card
, snd_ctl_new1(control
[i
], mts
));
656 snd_printd("Cannot create control: %s\n",
665 /*********************************************************************
667 *********************************************************************/
668 #define MTS64_MODE_INPUT_TRIGGERED 0x01
670 static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream
*substream
)
672 struct mts64
*mts
= substream
->rmidi
->private_data
;
674 if (mts
->open_count
== 0) {
675 /* We don't need a spinlock here, because this is just called
676 if the device has not been opened before.
677 So there aren't any IRQs from the device */
678 mts64_device_open(mts
);
687 static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream
*substream
)
689 struct mts64
*mts
= substream
->rmidi
->private_data
;
693 if (mts
->open_count
== 0) {
694 /* We need the spinlock_irqsave here because we can still
695 have IRQs at this point */
696 spin_lock_irqsave(&mts
->lock
, flags
);
697 mts64_device_close(mts
);
698 spin_unlock_irqrestore(&mts
->lock
, flags
);
702 } else if (mts
->open_count
< 0)
708 static void snd_mts64_rawmidi_output_trigger(struct snd_rawmidi_substream
*substream
,
711 struct mts64
*mts
= substream
->rmidi
->private_data
;
715 spin_lock_irqsave(&mts
->lock
, flags
);
716 while (snd_rawmidi_transmit_peek(substream
, &data
, 1) == 1) {
717 mts64_write_midi(mts
, data
, substream
->number
+1);
718 snd_rawmidi_transmit_ack(substream
, 1);
720 spin_unlock_irqrestore(&mts
->lock
, flags
);
723 static void snd_mts64_rawmidi_input_trigger(struct snd_rawmidi_substream
*substream
,
726 struct mts64
*mts
= substream
->rmidi
->private_data
;
729 spin_lock_irqsave(&mts
->lock
, flags
);
731 mts
->mode
[substream
->number
] |= MTS64_MODE_INPUT_TRIGGERED
;
733 mts
->mode
[substream
->number
] &= ~MTS64_MODE_INPUT_TRIGGERED
;
735 spin_unlock_irqrestore(&mts
->lock
, flags
);
738 static const struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops
= {
739 .open
= snd_mts64_rawmidi_open
,
740 .close
= snd_mts64_rawmidi_close
,
741 .trigger
= snd_mts64_rawmidi_output_trigger
744 static const struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops
= {
745 .open
= snd_mts64_rawmidi_open
,
746 .close
= snd_mts64_rawmidi_close
,
747 .trigger
= snd_mts64_rawmidi_input_trigger
750 /* Create and initialize the rawmidi component */
751 static int snd_mts64_rawmidi_create(struct snd_card
*card
)
753 struct mts64
*mts
= card
->private_data
;
754 struct snd_rawmidi
*rmidi
;
755 struct snd_rawmidi_substream
*substream
;
756 struct list_head
*list
;
759 err
= snd_rawmidi_new(card
, CARD_NAME
, 0,
760 MTS64_NUM_OUTPUT_PORTS
,
761 MTS64_NUM_INPUT_PORTS
,
766 rmidi
->private_data
= mts
;
767 strcpy(rmidi
->name
, CARD_NAME
);
768 rmidi
->info_flags
= SNDRV_RAWMIDI_INFO_OUTPUT
|
769 SNDRV_RAWMIDI_INFO_INPUT
|
770 SNDRV_RAWMIDI_INFO_DUPLEX
;
774 /* register rawmidi ops */
775 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
,
776 &snd_mts64_rawmidi_output_ops
);
777 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
,
778 &snd_mts64_rawmidi_input_ops
);
780 /* name substreams */
783 &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_OUTPUT
].substreams
) {
784 substream
= list_entry(list
, struct snd_rawmidi_substream
, list
);
785 sprintf(substream
->name
,
786 "Miditerminal %d", substream
->number
+1);
790 &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_INPUT
].substreams
) {
791 substream
= list_entry(list
, struct snd_rawmidi_substream
, list
);
792 mts
->midi_input_substream
[substream
->number
] = substream
;
793 switch(substream
->number
) {
794 case MTS64_SMPTE_SUBSTREAM
:
795 strcpy(substream
->name
, "Miditerminal SMPTE");
798 sprintf(substream
->name
,
799 "Miditerminal %d", substream
->number
+1);
804 err
= snd_mts64_ctl_create(card
, mts
);
809 /*********************************************************************
811 *********************************************************************/
812 static void snd_mts64_interrupt(void *private)
814 struct mts64
*mts
= ((struct snd_card
*)private)->private_data
;
817 struct snd_rawmidi_substream
*substream
;
819 spin_lock(&mts
->lock
);
820 ret
= mts64_read(mts
->pardev
->port
);
824 if (status
& MTS64_STAT_PORT
) {
825 mts
->current_midi_input_port
= mts64_map_midi_input(data
);
827 if (mts
->current_midi_input_port
== -1)
829 substream
= mts
->midi_input_substream
[mts
->current_midi_input_port
];
830 if (mts
->mode
[substream
->number
] & MTS64_MODE_INPUT_TRIGGERED
)
831 snd_rawmidi_receive(substream
, &data
, 1);
834 spin_unlock(&mts
->lock
);
837 static void snd_mts64_attach(struct parport
*p
)
839 struct platform_device
*device
;
841 device
= platform_device_alloc(PLATFORM_DRIVER
, device_count
);
845 /* Temporary assignment to forward the parport */
846 platform_set_drvdata(device
, p
);
848 if (platform_device_add(device
) < 0) {
849 platform_device_put(device
);
853 /* Since we dont get the return value of probe
854 * We need to check if device probing succeeded or not */
855 if (!platform_get_drvdata(device
)) {
856 platform_device_unregister(device
);
860 /* register device in global table */
861 platform_devices
[device_count
] = device
;
865 static void snd_mts64_detach(struct parport
*p
)
867 /* nothing to do here */
870 static int snd_mts64_dev_probe(struct pardevice
*pardev
)
872 if (strcmp(pardev
->name
, DRIVER_NAME
))
878 static struct parport_driver mts64_parport_driver
= {
880 .probe
= snd_mts64_dev_probe
,
881 .match_port
= snd_mts64_attach
,
882 .detach
= snd_mts64_detach
,
886 /*********************************************************************
888 *********************************************************************/
889 static void snd_mts64_card_private_free(struct snd_card
*card
)
891 struct mts64
*mts
= card
->private_data
;
892 struct pardevice
*pardev
= mts
->pardev
;
895 parport_release(pardev
);
896 parport_unregister_device(pardev
);
902 static int snd_mts64_probe(struct platform_device
*pdev
)
904 struct pardevice
*pardev
;
907 struct snd_card
*card
= NULL
;
908 struct mts64
*mts
= NULL
;
910 struct pardev_cb mts64_cb
= {
913 .irq_func
= snd_mts64_interrupt
, /* ISR */
914 .flags
= PARPORT_DEV_EXCL
, /* flags */
917 p
= platform_get_drvdata(pdev
);
918 platform_set_drvdata(pdev
, NULL
);
920 if (dev
>= SNDRV_CARDS
)
925 err
= snd_card_new(&pdev
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
928 snd_printd("Cannot create card\n");
931 strcpy(card
->driver
, DRIVER_NAME
);
932 strcpy(card
->shortname
, "ESI " CARD_NAME
);
933 sprintf(card
->longname
, "%s at 0x%lx, irq %i",
934 card
->shortname
, p
->base
, p
->irq
);
936 mts64_cb
.private = card
; /* private */
937 pardev
= parport_register_dev_model(p
, /* port */
938 DRIVER_NAME
, /* name */
939 &mts64_cb
, /* callbacks */
940 pdev
->id
); /* device number */
942 snd_printd("Cannot register pardevice\n");
948 if (parport_claim(pardev
)) {
949 snd_printd("Cannot claim parport 0x%lx\n", pardev
->port
->base
);
954 if ((err
= snd_mts64_create(card
, pardev
, &mts
)) < 0) {
955 snd_printd("Cannot create main component\n");
958 card
->private_data
= mts
;
959 card
->private_free
= snd_mts64_card_private_free
;
961 err
= mts64_probe(p
);
967 if ((err
= snd_mts64_rawmidi_create(card
)) < 0) {
968 snd_printd("Creating Rawmidi component failed\n");
973 if ((err
= mts64_device_init(p
)) < 0)
976 platform_set_drvdata(pdev
, card
);
978 /* At this point card will be usable */
979 if ((err
= snd_card_register(card
)) < 0) {
980 snd_printd("Cannot register card\n");
984 snd_printk(KERN_INFO
"ESI Miditerminal 4140 on 0x%lx\n", p
->base
);
988 parport_release(pardev
);
990 parport_unregister_device(pardev
);
996 static int snd_mts64_remove(struct platform_device
*pdev
)
998 struct snd_card
*card
= platform_get_drvdata(pdev
);
1001 snd_card_free(card
);
1006 static struct platform_driver snd_mts64_driver
= {
1007 .probe
= snd_mts64_probe
,
1008 .remove
= snd_mts64_remove
,
1010 .name
= PLATFORM_DRIVER
,
1014 /*********************************************************************
1016 *********************************************************************/
1017 static void snd_mts64_unregister_all(void)
1021 for (i
= 0; i
< SNDRV_CARDS
; ++i
) {
1022 if (platform_devices
[i
]) {
1023 platform_device_unregister(platform_devices
[i
]);
1024 platform_devices
[i
] = NULL
;
1027 platform_driver_unregister(&snd_mts64_driver
);
1028 parport_unregister_driver(&mts64_parport_driver
);
1031 static int __init
snd_mts64_module_init(void)
1035 if ((err
= platform_driver_register(&snd_mts64_driver
)) < 0)
1038 if (parport_register_driver(&mts64_parport_driver
) != 0) {
1039 platform_driver_unregister(&snd_mts64_driver
);
1043 if (device_count
== 0) {
1044 snd_mts64_unregister_all();
1051 static void __exit
snd_mts64_module_exit(void)
1053 snd_mts64_unregister_all();
1056 module_init(snd_mts64_module_init
);
1057 module_exit(snd_mts64_module_exit
);