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");
41 /*********************************************************************
43 *********************************************************************/
44 #define MTS64_NUM_INPUT_PORTS 5
45 #define MTS64_NUM_OUTPUT_PORTS 4
46 #define MTS64_SMPTE_SUBSTREAM 4
50 struct snd_card *card;
51 struct snd_rawmidi *rmidi;
52 struct pardevice *pardev;
54 int current_midi_output_port;
55 int current_midi_input_port;
56 u8 mode[MTS64_NUM_INPUT_PORTS];
57 struct snd_rawmidi_substream *midi_input_substream[MTS64_NUM_INPUT_PORTS];
59 u8 time[4]; /* [0]=hh, [1]=mm, [2]=ss, [3]=ff */
63 static int snd_mts64_free(struct mts64 *mts)
69 static int snd_mts64_create(struct snd_card *card,
70 struct pardevice *pardev,
77 mts = kzalloc(sizeof(struct mts64), GFP_KERNEL);
81 /* Init chip specific data */
82 spin_lock_init(&mts->lock);
85 mts->current_midi_output_port = -1;
86 mts->current_midi_input_port = -1;
93 /*********************************************************************
94 * HW register related constants
95 *********************************************************************/
98 #define MTS64_STAT_BSY 0x80
99 #define MTS64_STAT_BIT_SET 0x20 /* readout process, bit is set */
100 #define MTS64_STAT_PORT 0x10 /* read byte is a port number */
103 #define MTS64_CTL_READOUT 0x08 /* enable readout */
104 #define MTS64_CTL_WRITE_CMD 0x06
105 #define MTS64_CTL_WRITE_DATA 0x02
106 #define MTS64_CTL_STROBE 0x01
109 #define MTS64_CMD_RESET 0xfe
110 #define MTS64_CMD_PROBE 0x8f /* Used in probing procedure */
111 #define MTS64_CMD_SMPTE_SET_TIME 0xe8
112 #define MTS64_CMD_SMPTE_SET_FPS 0xee
113 #define MTS64_CMD_SMPTE_STOP 0xef
114 #define MTS64_CMD_SMPTE_FPS_24 0xe3
115 #define MTS64_CMD_SMPTE_FPS_25 0xe2
116 #define MTS64_CMD_SMPTE_FPS_2997 0xe4
117 #define MTS64_CMD_SMPTE_FPS_30D 0xe1
118 #define MTS64_CMD_SMPTE_FPS_30 0xe0
119 #define MTS64_CMD_COM_OPEN 0xf8 /* setting the communication mode */
120 #define MTS64_CMD_COM_CLOSE1 0xff /* clearing communication mode */
121 #define MTS64_CMD_COM_CLOSE2 0xf5
123 /*********************************************************************
124 * Hardware specific functions
125 *********************************************************************/
126 static void mts64_enable_readout(struct parport *p);
127 static void mts64_disable_readout(struct parport *p);
128 static int mts64_device_ready(struct parport *p);
129 static int mts64_device_init(struct parport *p);
130 static int mts64_device_open(struct mts64 *mts);
131 static int mts64_device_close(struct mts64 *mts);
132 static u8 mts64_map_midi_input(u8 c);
133 static int mts64_probe(struct parport *p);
134 static u16 mts64_read(struct parport *p);
135 static u8 mts64_read_char(struct parport *p);
136 static void mts64_smpte_start(struct parport *p,
137 u8 hours, u8 minutes,
138 u8 seconds, u8 frames,
140 static void mts64_smpte_stop(struct parport *p);
141 static void mts64_write_command(struct parport *p, u8 c);
142 static void mts64_write_data(struct parport *p, u8 c);
143 static void mts64_write_midi(struct mts64 *mts, u8 c, int midiport);
146 /* Enables the readout procedure
148 * Before we can read a midi byte from the device, we have to set
149 * bit 3 of control port.
151 static void mts64_enable_readout(struct parport *p)
155 c = parport_read_control(p);
156 c |= MTS64_CTL_READOUT;
157 parport_write_control(p, c);
162 * Readout is disabled by clearing bit 3 of control
164 static void mts64_disable_readout(struct parport *p)
168 c = parport_read_control(p);
169 c &= ~MTS64_CTL_READOUT;
170 parport_write_control(p, c);
173 /* waits for device ready
175 * Checks if BUSY (Bit 7 of status) is clear
179 static int mts64_device_ready(struct parport *p)
184 for (i = 0; i < 0xffff; ++i) {
185 c = parport_read_status(p);
194 /* Init device (LED blinking startup magic)
200 static int mts64_device_init(struct parport *p)
204 mts64_write_command(p, MTS64_CMD_RESET);
206 for (i = 0; i < 64; ++i) {
209 if (mts64_probe(p) == 0) {
211 mts64_disable_readout(p);
215 mts64_disable_readout(p);
221 * Opens the device (set communication mode)
223 static int mts64_device_open(struct mts64 *mts)
226 struct parport *p = mts->pardev->port;
228 for (i = 0; i < 5; ++i)
229 mts64_write_command(p, MTS64_CMD_COM_OPEN);
235 * Close device (clear communication mode)
237 static int mts64_device_close(struct mts64 *mts)
240 struct parport *p = mts->pardev->port;
242 for (i = 0; i < 5; ++i) {
243 mts64_write_command(p, MTS64_CMD_COM_CLOSE1);
244 mts64_write_command(p, MTS64_CMD_COM_CLOSE2);
250 /* map hardware port to substream number
252 * When reading a byte from the device, the device tells us
253 * on what port the byte is. This HW port has to be mapped to
254 * the midiport (substream number).
255 * substream 0-3 are Midiports 1-4
256 * substream 4 is SMPTE Timecode
257 * The mapping is done by the table:
258 * HW | 0 | 1 | 2 | 3 | 4
259 * SW | 0 | 1 | 4 | 2 | 3
261 static u8 mts64_map_midi_input(u8 c)
263 static const u8 map[] = { 0, 1, 4, 2, 3 };
269 /* Probe parport for device
271 * Do we have a Miditerminal 4140 on parport?
276 static int mts64_probe(struct parport *p)
281 mts64_write_command(p, MTS64_CMD_PROBE);
288 if (c != MTS64_CMD_PROBE)
295 /* Read byte incl. status from device
298 * data in lower 8 bits and status in upper 8 bits
300 static u16 mts64_read(struct parport *p)
304 mts64_device_ready(p);
305 mts64_enable_readout(p);
306 status = parport_read_status(p);
307 data = mts64_read_char(p);
308 mts64_disable_readout(p);
310 return (status << 8) | data;
313 /* Read a byte from device
315 * Note, that readout mode has to be enabled.
316 * readout procedure is as follows:
317 * - Write number of the Bit to read to DATA
319 * - Bit 5 of STATUS indicates if Bit is set
322 * Byte read from device
324 static u8 mts64_read_char(struct parport *p)
330 for (i = 0; i < 8; ++i) {
331 parport_write_data(p, i);
333 status = parport_read_status(p);
334 if (status & MTS64_STAT_BIT_SET)
341 /* Starts SMPTE Timecode generation
343 * The device creates SMPTE Timecode by hardware.
347 * 3 30 fps (Drop-frame)
350 static void mts64_smpte_start(struct parport *p,
351 u8 hours, u8 minutes,
352 u8 seconds, u8 frames,
355 static const u8 fps[5] = { MTS64_CMD_SMPTE_FPS_24,
356 MTS64_CMD_SMPTE_FPS_25,
357 MTS64_CMD_SMPTE_FPS_2997,
358 MTS64_CMD_SMPTE_FPS_30D,
359 MTS64_CMD_SMPTE_FPS_30 };
361 mts64_write_command(p, MTS64_CMD_SMPTE_SET_TIME);
362 mts64_write_command(p, frames);
363 mts64_write_command(p, seconds);
364 mts64_write_command(p, minutes);
365 mts64_write_command(p, hours);
367 mts64_write_command(p, MTS64_CMD_SMPTE_SET_FPS);
368 mts64_write_command(p, fps[idx]);
371 /* Stops SMPTE Timecode generation
373 static void mts64_smpte_stop(struct parport *p)
375 mts64_write_command(p, MTS64_CMD_SMPTE_STOP);
378 /* Write a command byte to device
380 static void mts64_write_command(struct parport *p, u8 c)
382 mts64_device_ready(p);
384 parport_write_data(p, c);
386 parport_write_control(p, MTS64_CTL_WRITE_CMD);
387 parport_write_control(p, MTS64_CTL_WRITE_CMD | MTS64_CTL_STROBE);
388 parport_write_control(p, MTS64_CTL_WRITE_CMD);
391 /* Write a data byte to device
393 static void mts64_write_data(struct parport *p, u8 c)
395 mts64_device_ready(p);
397 parport_write_data(p, c);
399 parport_write_control(p, MTS64_CTL_WRITE_DATA);
400 parport_write_control(p, MTS64_CTL_WRITE_DATA | MTS64_CTL_STROBE);
401 parport_write_control(p, MTS64_CTL_WRITE_DATA);
404 /* Write a MIDI byte to midiport
406 * midiport ranges from 0-3 and maps to Ports 1-4
407 * assumptions: communication mode is on
409 static void mts64_write_midi(struct mts64 *mts, u8 c,
412 struct parport *p = mts->pardev->port;
414 /* check current midiport */
415 if (mts->current_midi_output_port != midiport)
416 mts64_write_command(p, midiport);
418 /* write midi byte */
419 mts64_write_data(p, c);
422 /*********************************************************************
424 *********************************************************************/
427 #define snd_mts64_ctl_smpte_switch_info snd_ctl_boolean_mono_info
429 static int snd_mts64_ctl_smpte_switch_get(struct snd_kcontrol* kctl,
430 struct snd_ctl_elem_value *uctl)
432 struct mts64 *mts = snd_kcontrol_chip(kctl);
434 spin_lock_irq(&mts->lock);
435 uctl->value.integer.value[0] = mts->smpte_switch;
436 spin_unlock_irq(&mts->lock);
441 /* smpte_switch is not accessed from IRQ handler, so we just need
442 to protect the HW access */
443 static int snd_mts64_ctl_smpte_switch_put(struct snd_kcontrol* kctl,
444 struct snd_ctl_elem_value *uctl)
446 struct mts64 *mts = snd_kcontrol_chip(kctl);
448 int val = !!uctl->value.integer.value[0];
450 spin_lock_irq(&mts->lock);
451 if (mts->smpte_switch == val)
455 mts->smpte_switch = val;
456 if (mts->smpte_switch) {
457 mts64_smpte_start(mts->pardev->port,
458 mts->time[0], mts->time[1],
459 mts->time[2], mts->time[3],
462 mts64_smpte_stop(mts->pardev->port);
465 spin_unlock_irq(&mts->lock);
469 static const struct snd_kcontrol_new mts64_ctl_smpte_switch = {
470 .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI,
471 .name = "SMPTE Playback Switch",
473 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
475 .info = snd_mts64_ctl_smpte_switch_info,
476 .get = snd_mts64_ctl_smpte_switch_get,
477 .put = snd_mts64_ctl_smpte_switch_put
481 static int snd_mts64_ctl_smpte_time_h_info(struct snd_kcontrol *kctl,
482 struct snd_ctl_elem_info *uinfo)
484 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
486 uinfo->value.integer.min = 0;
487 uinfo->value.integer.max = 23;
491 static int snd_mts64_ctl_smpte_time_f_info(struct snd_kcontrol *kctl,
492 struct snd_ctl_elem_info *uinfo)
494 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
496 uinfo->value.integer.min = 0;
497 uinfo->value.integer.max = 99;
501 static int snd_mts64_ctl_smpte_time_info(struct snd_kcontrol *kctl,
502 struct snd_ctl_elem_info *uinfo)
504 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
506 uinfo->value.integer.min = 0;
507 uinfo->value.integer.max = 59;
511 static int snd_mts64_ctl_smpte_time_get(struct snd_kcontrol *kctl,
512 struct snd_ctl_elem_value *uctl)
514 struct mts64 *mts = snd_kcontrol_chip(kctl);
515 int idx = kctl->private_value;
517 spin_lock_irq(&mts->lock);
518 uctl->value.integer.value[0] = mts->time[idx];
519 spin_unlock_irq(&mts->lock);
524 static int snd_mts64_ctl_smpte_time_put(struct snd_kcontrol *kctl,
525 struct snd_ctl_elem_value *uctl)
527 struct mts64 *mts = snd_kcontrol_chip(kctl);
528 int idx = kctl->private_value;
529 unsigned int time = uctl->value.integer.value[0] % 60;
532 spin_lock_irq(&mts->lock);
533 if (mts->time[idx] != time) {
535 mts->time[idx] = time;
537 spin_unlock_irq(&mts->lock);
542 static const struct snd_kcontrol_new mts64_ctl_smpte_time_hours = {
543 .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI,
544 .name = "SMPTE Time Hours",
546 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
548 .info = snd_mts64_ctl_smpte_time_h_info,
549 .get = snd_mts64_ctl_smpte_time_get,
550 .put = snd_mts64_ctl_smpte_time_put
553 static const struct snd_kcontrol_new mts64_ctl_smpte_time_minutes = {
554 .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI,
555 .name = "SMPTE Time Minutes",
557 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
559 .info = snd_mts64_ctl_smpte_time_info,
560 .get = snd_mts64_ctl_smpte_time_get,
561 .put = snd_mts64_ctl_smpte_time_put
564 static const struct snd_kcontrol_new mts64_ctl_smpte_time_seconds = {
565 .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI,
566 .name = "SMPTE Time Seconds",
568 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
570 .info = snd_mts64_ctl_smpte_time_info,
571 .get = snd_mts64_ctl_smpte_time_get,
572 .put = snd_mts64_ctl_smpte_time_put
575 static const struct snd_kcontrol_new mts64_ctl_smpte_time_frames = {
576 .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI,
577 .name = "SMPTE Time Frames",
579 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
581 .info = snd_mts64_ctl_smpte_time_f_info,
582 .get = snd_mts64_ctl_smpte_time_get,
583 .put = snd_mts64_ctl_smpte_time_put
587 static int snd_mts64_ctl_smpte_fps_info(struct snd_kcontrol *kctl,
588 struct snd_ctl_elem_info *uinfo)
590 static const char * const texts[5] = {
591 "24", "25", "29.97", "30D", "30"
594 return snd_ctl_enum_info(uinfo, 1, 5, texts);
597 static int snd_mts64_ctl_smpte_fps_get(struct snd_kcontrol *kctl,
598 struct snd_ctl_elem_value *uctl)
600 struct mts64 *mts = snd_kcontrol_chip(kctl);
602 spin_lock_irq(&mts->lock);
603 uctl->value.enumerated.item[0] = mts->fps;
604 spin_unlock_irq(&mts->lock);
609 static int snd_mts64_ctl_smpte_fps_put(struct snd_kcontrol *kctl,
610 struct snd_ctl_elem_value *uctl)
612 struct mts64 *mts = snd_kcontrol_chip(kctl);
615 if (uctl->value.enumerated.item[0] >= 5)
617 spin_lock_irq(&mts->lock);
618 if (mts->fps != uctl->value.enumerated.item[0]) {
620 mts->fps = uctl->value.enumerated.item[0];
622 spin_unlock_irq(&mts->lock);
627 static const struct snd_kcontrol_new mts64_ctl_smpte_fps = {
628 .iface = SNDRV_CTL_ELEM_IFACE_RAWMIDI,
631 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
633 .info = snd_mts64_ctl_smpte_fps_info,
634 .get = snd_mts64_ctl_smpte_fps_get,
635 .put = snd_mts64_ctl_smpte_fps_put
639 static int snd_mts64_ctl_create(struct snd_card *card,
643 static const struct snd_kcontrol_new *control[] = {
644 &mts64_ctl_smpte_switch,
645 &mts64_ctl_smpte_time_hours,
646 &mts64_ctl_smpte_time_minutes,
647 &mts64_ctl_smpte_time_seconds,
648 &mts64_ctl_smpte_time_frames,
649 &mts64_ctl_smpte_fps,
652 for (i = 0; control[i]; ++i) {
653 err = snd_ctl_add(card, snd_ctl_new1(control[i], mts));
655 snd_printd("Cannot create control: %s\n",
664 /*********************************************************************
666 *********************************************************************/
667 #define MTS64_MODE_INPUT_TRIGGERED 0x01
669 static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
671 struct mts64 *mts = substream->rmidi->private_data;
673 if (mts->open_count == 0) {
674 /* We don't need a spinlock here, because this is just called
675 if the device has not been opened before.
676 So there aren't any IRQs from the device */
677 mts64_device_open(mts);
686 static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
688 struct mts64 *mts = substream->rmidi->private_data;
692 if (mts->open_count == 0) {
693 /* We need the spinlock_irqsave here because we can still
694 have IRQs at this point */
695 spin_lock_irqsave(&mts->lock, flags);
696 mts64_device_close(mts);
697 spin_unlock_irqrestore(&mts->lock, flags);
701 } else if (mts->open_count < 0)
707 static void snd_mts64_rawmidi_output_trigger(struct snd_rawmidi_substream *substream,
710 struct mts64 *mts = substream->rmidi->private_data;
714 spin_lock_irqsave(&mts->lock, flags);
715 while (snd_rawmidi_transmit_peek(substream, &data, 1) == 1) {
716 mts64_write_midi(mts, data, substream->number+1);
717 snd_rawmidi_transmit_ack(substream, 1);
719 spin_unlock_irqrestore(&mts->lock, flags);
722 static void snd_mts64_rawmidi_input_trigger(struct snd_rawmidi_substream *substream,
725 struct mts64 *mts = substream->rmidi->private_data;
728 spin_lock_irqsave(&mts->lock, flags);
730 mts->mode[substream->number] |= MTS64_MODE_INPUT_TRIGGERED;
732 mts->mode[substream->number] &= ~MTS64_MODE_INPUT_TRIGGERED;
734 spin_unlock_irqrestore(&mts->lock, flags);
737 static const struct snd_rawmidi_ops snd_mts64_rawmidi_output_ops = {
738 .open = snd_mts64_rawmidi_open,
739 .close = snd_mts64_rawmidi_close,
740 .trigger = snd_mts64_rawmidi_output_trigger
743 static const struct snd_rawmidi_ops snd_mts64_rawmidi_input_ops = {
744 .open = snd_mts64_rawmidi_open,
745 .close = snd_mts64_rawmidi_close,
746 .trigger = snd_mts64_rawmidi_input_trigger
749 /* Create and initialize the rawmidi component */
750 static int snd_mts64_rawmidi_create(struct snd_card *card)
752 struct mts64 *mts = card->private_data;
753 struct snd_rawmidi *rmidi;
754 struct snd_rawmidi_substream *substream;
755 struct list_head *list;
758 err = snd_rawmidi_new(card, CARD_NAME, 0,
759 MTS64_NUM_OUTPUT_PORTS,
760 MTS64_NUM_INPUT_PORTS,
765 rmidi->private_data = mts;
766 strcpy(rmidi->name, CARD_NAME);
767 rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT |
768 SNDRV_RAWMIDI_INFO_INPUT |
769 SNDRV_RAWMIDI_INFO_DUPLEX;
773 /* register rawmidi ops */
774 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
775 &snd_mts64_rawmidi_output_ops);
776 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
777 &snd_mts64_rawmidi_input_ops);
779 /* name substreams */
782 &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) {
783 substream = list_entry(list, struct snd_rawmidi_substream, list);
784 sprintf(substream->name,
785 "Miditerminal %d", substream->number+1);
789 &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) {
790 substream = list_entry(list, struct snd_rawmidi_substream, list);
791 mts->midi_input_substream[substream->number] = substream;
792 switch(substream->number) {
793 case MTS64_SMPTE_SUBSTREAM:
794 strcpy(substream->name, "Miditerminal SMPTE");
797 sprintf(substream->name,
798 "Miditerminal %d", substream->number+1);
803 err = snd_mts64_ctl_create(card, mts);
808 /*********************************************************************
810 *********************************************************************/
811 static void snd_mts64_interrupt(void *private)
813 struct mts64 *mts = ((struct snd_card*)private)->private_data;
816 struct snd_rawmidi_substream *substream;
818 spin_lock(&mts->lock);
819 ret = mts64_read(mts->pardev->port);
823 if (status & MTS64_STAT_PORT) {
824 mts->current_midi_input_port = mts64_map_midi_input(data);
826 if (mts->current_midi_input_port == -1)
828 substream = mts->midi_input_substream[mts->current_midi_input_port];
829 if (mts->mode[substream->number] & MTS64_MODE_INPUT_TRIGGERED)
830 snd_rawmidi_receive(substream, &data, 1);
833 spin_unlock(&mts->lock);
836 static void snd_mts64_attach(struct parport *p)
838 struct platform_device *device;
840 device = platform_device_alloc(PLATFORM_DRIVER, device_count);
844 /* Temporary assignment to forward the parport */
845 platform_set_drvdata(device, p);
847 if (platform_device_add(device) < 0) {
848 platform_device_put(device);
852 /* Since we dont get the return value of probe
853 * We need to check if device probing succeeded or not */
854 if (!platform_get_drvdata(device)) {
855 platform_device_unregister(device);
859 /* register device in global table */
860 platform_devices[device_count] = device;
864 static void snd_mts64_detach(struct parport *p)
866 /* nothing to do here */
869 static int snd_mts64_dev_probe(struct pardevice *pardev)
871 if (strcmp(pardev->name, DRIVER_NAME))
877 static struct parport_driver mts64_parport_driver = {
879 .probe = snd_mts64_dev_probe,
880 .match_port = snd_mts64_attach,
881 .detach = snd_mts64_detach,
885 /*********************************************************************
887 *********************************************************************/
888 static void snd_mts64_card_private_free(struct snd_card *card)
890 struct mts64 *mts = card->private_data;
891 struct pardevice *pardev = mts->pardev;
894 parport_release(pardev);
895 parport_unregister_device(pardev);
901 static int snd_mts64_probe(struct platform_device *pdev)
903 struct pardevice *pardev;
906 struct snd_card *card = NULL;
907 struct mts64 *mts = NULL;
909 struct pardev_cb mts64_cb = {
912 .irq_func = snd_mts64_interrupt, /* ISR */
913 .flags = PARPORT_DEV_EXCL, /* flags */
916 p = platform_get_drvdata(pdev);
917 platform_set_drvdata(pdev, NULL);
919 if (dev >= SNDRV_CARDS)
924 err = snd_card_new(&pdev->dev, index[dev], id[dev], THIS_MODULE,
927 snd_printd("Cannot create card\n");
930 strcpy(card->driver, DRIVER_NAME);
931 strcpy(card->shortname, "ESI " CARD_NAME);
932 sprintf(card->longname, "%s at 0x%lx, irq %i",
933 card->shortname, p->base, p->irq);
935 mts64_cb.private = card; /* private */
936 pardev = parport_register_dev_model(p, /* port */
937 DRIVER_NAME, /* name */
938 &mts64_cb, /* callbacks */
939 pdev->id); /* device number */
941 snd_printd("Cannot register pardevice\n");
947 if (parport_claim(pardev)) {
948 snd_printd("Cannot claim parport 0x%lx\n", pardev->port->base);
953 err = snd_mts64_create(card, pardev, &mts);
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 err = snd_mts64_rawmidi_create(card);
969 snd_printd("Creating Rawmidi component failed\n");
974 err = mts64_device_init(p);
978 platform_set_drvdata(pdev, card);
980 /* At this point card will be usable */
981 err = snd_card_register(card);
983 snd_printd("Cannot register card\n");
987 snd_printk(KERN_INFO "ESI Miditerminal 4140 on 0x%lx\n", p->base);
991 parport_release(pardev);
993 parport_unregister_device(pardev);
999 static int snd_mts64_remove(struct platform_device *pdev)
1001 struct snd_card *card = platform_get_drvdata(pdev);
1004 snd_card_free(card);
1009 static struct platform_driver snd_mts64_driver = {
1010 .probe = snd_mts64_probe,
1011 .remove = snd_mts64_remove,
1013 .name = PLATFORM_DRIVER,
1017 /*********************************************************************
1019 *********************************************************************/
1020 static void snd_mts64_unregister_all(void)
1024 for (i = 0; i < SNDRV_CARDS; ++i) {
1025 if (platform_devices[i]) {
1026 platform_device_unregister(platform_devices[i]);
1027 platform_devices[i] = NULL;
1030 platform_driver_unregister(&snd_mts64_driver);
1031 parport_unregister_driver(&mts64_parport_driver);
1034 static int __init snd_mts64_module_init(void)
1038 err = platform_driver_register(&snd_mts64_driver);
1042 if (parport_register_driver(&mts64_parport_driver) != 0) {
1043 platform_driver_unregister(&snd_mts64_driver);
1047 if (device_count == 0) {
1048 snd_mts64_unregister_all();
1055 static void __exit snd_mts64_module_exit(void)
1057 snd_mts64_unregister_all();
1060 module_init(snd_mts64_module_init);
1061 module_exit(snd_mts64_module_exit);