23 #include <linux/parport.h>
25 #include <linux/module.h>
27 #include <linux/slab.h>
33 #define CARD_NAME "Miditerminal 4140"
34 #define DRIVER_NAME "MTS64"
35 #define PLATFORM_DRIVER "snd_mts64"
42 static int device_count;
59 #define MTS64_NUM_INPUT_PORTS 5
60 #define MTS64_NUM_OUTPUT_PORTS 4
61 #define MTS64_SMPTE_SUBSTREAM 4
80 static int snd_mts64_free(
struct mts64 *mts)
115 #define MTS64_STAT_BSY 0x80
116 #define MTS64_STAT_BIT_SET 0x20
117 #define MTS64_STAT_PORT 0x10
120 #define MTS64_CTL_READOUT 0x08
121 #define MTS64_CTL_WRITE_CMD 0x06
122 #define MTS64_CTL_WRITE_DATA 0x02
123 #define MTS64_CTL_STROBE 0x01
126 #define MTS64_CMD_RESET 0xfe
127 #define MTS64_CMD_PROBE 0x8f
128 #define MTS64_CMD_SMPTE_SET_TIME 0xe8
129 #define MTS64_CMD_SMPTE_SET_FPS 0xee
130 #define MTS64_CMD_SMPTE_STOP 0xef
131 #define MTS64_CMD_SMPTE_FPS_24 0xe3
132 #define MTS64_CMD_SMPTE_FPS_25 0xe2
133 #define MTS64_CMD_SMPTE_FPS_2997 0xe4
134 #define MTS64_CMD_SMPTE_FPS_30D 0xe1
135 #define MTS64_CMD_SMPTE_FPS_30 0xe0
136 #define MTS64_CMD_COM_OPEN 0xf8
137 #define MTS64_CMD_COM_CLOSE1 0xff
138 #define MTS64_CMD_COM_CLOSE2 0xf5
143 static void mts64_enable_readout(
struct parport *
p);
144 static void mts64_disable_readout(
struct parport *
p);
145 static int mts64_device_ready(
struct parport *
p);
146 static int mts64_device_init(
struct parport *
p);
147 static int mts64_device_open(
struct mts64 *mts);
148 static int mts64_device_close(
struct mts64 *mts);
149 static u8 mts64_map_midi_input(
u8 c);
150 static int mts64_probe(
struct parport *
p);
153 static void mts64_smpte_start(
struct parport *
p,
154 u8 hours,
u8 minutes,
157 static void mts64_smpte_stop(
struct parport *
p);
158 static void mts64_write_command(
struct parport *
p,
u8 c);
159 static void mts64_write_data(
struct parport *
p,
u8 c);
160 static void mts64_write_midi(
struct mts64 *mts,
u8 c,
int midiport);
168 static void mts64_enable_readout(
struct parport *
p)
181 static void mts64_disable_readout(
struct parport *
p)
196 static int mts64_device_ready(
struct parport *
p)
201 for (i = 0; i < 0xffff; ++
i) {
223 for (i = 0; i < 64; ++
i) {
226 if (mts64_probe(p) == 0) {
228 mts64_disable_readout(p);
232 mts64_disable_readout(p);
240 static int mts64_device_open(
struct mts64 *mts)
245 for (i = 0; i < 5; ++
i)
254 static int mts64_device_close(
struct mts64 *mts)
259 for (i = 0; i < 5; ++
i) {
278 static u8 mts64_map_midi_input(
u8 c)
280 static u8 map[] = { 0, 1, 4, 2, 3 };
321 mts64_device_ready(p);
322 mts64_enable_readout(p);
324 data = mts64_read_char(p);
325 mts64_disable_readout(p);
327 return (status << 8) |
data;
341 static u8 mts64_read_char(
struct parport *p)
347 for (i = 0; i < 8; ++
i) {
367 static void mts64_smpte_start(
struct parport *p,
368 u8 hours,
u8 minutes,
379 mts64_write_command(p, frames);
380 mts64_write_command(p, seconds);
381 mts64_write_command(p, minutes);
382 mts64_write_command(p, hours);
385 mts64_write_command(p, fps[idx]);
390 static void mts64_smpte_stop(
struct parport *p)
397 static void mts64_write_command(
struct parport *p,
u8 c)
399 mts64_device_ready(p);
410 static void mts64_write_data(
struct parport *p,
u8 c)
412 mts64_device_ready(p);
426 static void mts64_write_midi(
struct mts64 *mts,
u8 c,
433 mts64_write_command(p, midiport);
436 mts64_write_data(p, c);
444 #define snd_mts64_ctl_smpte_switch_info snd_ctl_boolean_mono_info
446 static int snd_mts64_ctl_smpte_switch_get(
struct snd_kcontrol* kctl,
451 spin_lock_irq(&mts->
lock);
453 spin_unlock_irq(&mts->
lock);
460 static int snd_mts64_ctl_smpte_switch_put(
struct snd_kcontrol* kctl,
465 int val = !!uctl->
value.integer.value[0];
467 spin_lock_irq(&mts->
lock);
474 mts64_smpte_start(mts->
pardev->port,
479 mts64_smpte_stop(mts->
pardev->port);
482 spin_unlock_irq(&mts->
lock);
488 .name =
"SMPTE Playback Switch",
493 .get = snd_mts64_ctl_smpte_switch_get,
494 .put = snd_mts64_ctl_smpte_switch_put
498 static int snd_mts64_ctl_smpte_time_h_info(
struct snd_kcontrol *kctl,
508 static int snd_mts64_ctl_smpte_time_f_info(
struct snd_kcontrol *kctl,
518 static int snd_mts64_ctl_smpte_time_info(
struct snd_kcontrol *kctl,
528 static int snd_mts64_ctl_smpte_time_get(
struct snd_kcontrol *kctl,
534 spin_lock_irq(&mts->
lock);
536 spin_unlock_irq(&mts->
lock);
541 static int snd_mts64_ctl_smpte_time_put(
struct snd_kcontrol *kctl,
546 unsigned int time = uctl->
value.integer.value[0] % 60;
549 spin_lock_irq(&mts->
lock);
550 if (mts->
time[idx] != time) {
554 spin_unlock_irq(&mts->
lock);
561 .name =
"SMPTE Time Hours",
565 .info = snd_mts64_ctl_smpte_time_h_info,
566 .get = snd_mts64_ctl_smpte_time_get,
567 .put = snd_mts64_ctl_smpte_time_put
570 static struct snd_kcontrol_new mts64_ctl_smpte_time_minutes __devinitdata = {
572 .name =
"SMPTE Time Minutes",
576 .info = snd_mts64_ctl_smpte_time_info,
577 .get = snd_mts64_ctl_smpte_time_get,
578 .put = snd_mts64_ctl_smpte_time_put
581 static struct snd_kcontrol_new mts64_ctl_smpte_time_seconds __devinitdata = {
583 .name =
"SMPTE Time Seconds",
587 .info = snd_mts64_ctl_smpte_time_info,
588 .get = snd_mts64_ctl_smpte_time_get,
589 .put = snd_mts64_ctl_smpte_time_put
592 static struct snd_kcontrol_new mts64_ctl_smpte_time_frames __devinitdata = {
594 .name =
"SMPTE Time Frames",
598 .info = snd_mts64_ctl_smpte_time_f_info,
599 .get = snd_mts64_ctl_smpte_time_get,
600 .put = snd_mts64_ctl_smpte_time_put
604 static int snd_mts64_ctl_smpte_fps_info(
struct snd_kcontrol *kctl,
607 static char *texts[5] = {
"24",
624 static int snd_mts64_ctl_smpte_fps_get(
struct snd_kcontrol *kctl,
629 spin_lock_irq(&mts->
lock);
630 uctl->
value.enumerated.item[0] = mts->
fps;
631 spin_unlock_irq(&mts->
lock);
636 static int snd_mts64_ctl_smpte_fps_put(
struct snd_kcontrol *kctl,
642 if (uctl->
value.enumerated.item[0] >= 5)
644 spin_lock_irq(&mts->
lock);
645 if (mts->
fps != uctl->
value.enumerated.item[0]) {
647 mts->
fps = uctl->
value.enumerated.item[0];
649 spin_unlock_irq(&mts->
lock);
660 .info = snd_mts64_ctl_smpte_fps_info,
661 .get = snd_mts64_ctl_smpte_fps_get,
662 .put = snd_mts64_ctl_smpte_fps_put
671 &mts64_ctl_smpte_switch,
672 &mts64_ctl_smpte_time_hours,
673 &mts64_ctl_smpte_time_minutes,
674 &mts64_ctl_smpte_time_seconds,
675 &mts64_ctl_smpte_time_frames,
676 &mts64_ctl_smpte_fps,
694 #define MTS64_MODE_INPUT_TRIGGERED 0x01
698 struct mts64 *mts = substream->
rmidi->private_data;
704 mts64_device_open(mts);
715 struct mts64 *mts = substream->
rmidi->private_data;
723 mts64_device_close(mts);
724 spin_unlock_irqrestore(&mts->
lock, flags);
737 struct mts64 *mts = substream->
rmidi->private_data;
743 mts64_write_midi(mts, data, substream->
number+1);
746 spin_unlock_irqrestore(&mts->
lock, flags);
752 struct mts64 *mts = substream->
rmidi->private_data;
761 spin_unlock_irqrestore(&mts->
lock, flags);
765 .open = snd_mts64_rawmidi_open,
766 .close = snd_mts64_rawmidi_close,
767 .trigger = snd_mts64_rawmidi_output_trigger
771 .open = snd_mts64_rawmidi_open,
772 .close = snd_mts64_rawmidi_close,
773 .trigger = snd_mts64_rawmidi_input_trigger
802 &snd_mts64_rawmidi_output_ops);
804 &snd_mts64_rawmidi_input_ops);
812 "Miditerminal %d", substream->
number+1);
819 switch(substream->
number) {
821 strcpy(substream->
name,
"Miditerminal SMPTE");
825 "Miditerminal %d", substream->
number+1);
830 err = snd_mts64_ctl_create(card, mts);
838 static void snd_mts64_interrupt(
void *
private)
840 struct mts64 *mts = ((
struct snd_card*)
private)->private_data;
845 spin_lock(&mts->
lock);
846 ret = mts64_read(mts->
pardev->port);
860 spin_unlock(&mts->
lock);
879 res = mts64_probe(p);
896 platform_set_drvdata(device, p);
905 if (!platform_get_drvdata(device)) {
911 platform_devices[device_count] = device;
915 static void snd_mts64_detach(
struct parport *p)
922 .attach = snd_mts64_attach,
923 .detach = snd_mts64_detach
929 static void snd_mts64_card_private_free(
struct snd_card *card)
952 p = platform_get_drvdata(pdev);
953 platform_set_drvdata(pdev,
NULL);
959 if ((err = snd_mts64_probe_port(p)) < 0)
979 if (pardev ==
NULL) {
985 if ((err = snd_mts64_create(card, pardev, &mts)) < 0) {
993 if ((err = snd_mts64_rawmidi_create(card)) < 0) {
994 snd_printd(
"Creating Rawmidi component failed\n");
1007 if ((err = mts64_device_init(p)) < 0)
1010 platform_set_drvdata(pdev, card);
1030 struct snd_card *card = platform_get_drvdata(pdev);
1040 .probe = snd_mts64_probe,
1051 static void snd_mts64_unregister_all(
void)
1056 if (platform_devices[i]) {
1058 platform_devices[
i] =
NULL;
1065 static int __init snd_mts64_module_init(
void)
1077 if (device_count == 0) {
1078 snd_mts64_unregister_all();
1085 static void __exit snd_mts64_module_exit(
void)
1087 snd_mts64_unregister_all();