[ALSA] add more sequencer port type information bits
[firefly-linux-kernel-4.4.55.git] / sound / core / seq / seq_midi.c
index 0a65eb2f976b862f8e37fb8c0ff05e8cd168491a..f873742c6532f18080abf4d75f6f690d33128165 100644 (file)
@@ -32,7 +32,7 @@ Possible options for midisynth module:
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/moduleparam.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #include <sound/core.h>
 #include <sound/rawmidi.h>
 #include <sound/seq_kernel.h>
@@ -70,7 +70,7 @@ struct seq_midisynth_client {
 };
 
 static struct seq_midisynth_client *synths[SNDRV_CARDS];
-static DECLARE_MUTEX(register_mutex);
+static DEFINE_MUTEX(register_mutex);
 
 /* handle rawmidi input event (MIDI v1.0 stream) */
 static void snd_midi_input_event(struct snd_rawmidi_substream *substream)
@@ -270,21 +270,6 @@ static void snd_seq_midisynth_delete(struct seq_midisynth *msynth)
                snd_midi_event_free(msynth->parser);
 }
 
-/* set our client name */
-static int set_client_name(struct seq_midisynth_client *client, struct snd_card *card,
-                          struct snd_rawmidi_info *rmidi)
-{
-       struct snd_seq_client_info cinfo;
-       const char *name;
-
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = client->seq_client;
-       cinfo.type = KERNEL_CLIENT;
-       name = rmidi->name[0] ? (const char *)rmidi->name : "External MIDI";
-       strlcpy(cinfo.name, name, sizeof(cinfo.name));
-       return snd_seq_kernel_client_ctl(client->seq_client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-}
-
 /* register new midi synth port */
 static int
 snd_seq_midisynth_register_port(struct snd_seq_device *dev)
@@ -295,7 +280,6 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
        struct snd_rawmidi_info *info;
        int newclient = 0;
        unsigned int p, ports;
-       struct snd_seq_client_callback callbacks;
        struct snd_seq_port_callback pcallbacks;
        struct snd_card *card = dev->card;
        int device = dev->device;
@@ -324,29 +308,27 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
        if (ports > (256 / SNDRV_RAWMIDI_DEVICES))
                ports = 256 / SNDRV_RAWMIDI_DEVICES;
 
-       down(&register_mutex);
+       mutex_lock(&register_mutex);
        client = synths[card->number];
        if (client == NULL) {
                newclient = 1;
                client = kzalloc(sizeof(*client), GFP_KERNEL);
                if (client == NULL) {
-                       up(&register_mutex);
+                       mutex_unlock(&register_mutex);
                        kfree(info);
                        return -ENOMEM;
                }
-               memset(&callbacks, 0, sizeof(callbacks));
-               callbacks.private_data = client;
-               callbacks.allow_input = callbacks.allow_output = 1;
-               client->seq_client = snd_seq_create_kernel_client(card, 0, &callbacks);
+               client->seq_client =
+                       snd_seq_create_kernel_client(
+                               card, 0, "%s", card->shortname[0] ?
+                               (const char *)card->shortname : "External MIDI");
                if (client->seq_client < 0) {
                        kfree(client);
-                       up(&register_mutex);
+                       mutex_unlock(&register_mutex);
                        kfree(info);
                        return -ENOMEM;
                }
-               set_client_name(client, card, info);
-       } else if (device == 0)
-               set_client_name(client, card, info); /* use the first device's name */
+       }
 
        msynth = kcalloc(ports, sizeof(struct seq_midisynth), GFP_KERNEL);
        port = kmalloc(sizeof(*port), GFP_KERNEL);
@@ -394,7 +376,9 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
                if ((port->capability & (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_READ)) == (SNDRV_SEQ_PORT_CAP_WRITE|SNDRV_SEQ_PORT_CAP_READ) &&
                    info->flags & SNDRV_RAWMIDI_INFO_DUPLEX)
                        port->capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
-               port->type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC;
+               port->type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC
+                       | SNDRV_SEQ_PORT_TYPE_HARDWARE
+                       | SNDRV_SEQ_PORT_TYPE_PORT;
                port->midi_channels = 16;
                memset(&pcallbacks, 0, sizeof(pcallbacks));
                pcallbacks.owner = THIS_MODULE;
@@ -415,7 +399,7 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
        client->num_ports++;
        if (newclient)
                synths[card->number] = client;
-       up(&register_mutex);
+       mutex_unlock(&register_mutex);
        kfree(info);
        kfree(port);
        return 0;       /* success */
@@ -432,7 +416,7 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
        }
        kfree(info);
        kfree(port);
-       up(&register_mutex);
+       mutex_unlock(&register_mutex);
        return -ENOMEM;
 }
 
@@ -445,10 +429,10 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
        struct snd_card *card = dev->card;
        int device = dev->device, p, ports;
        
-       down(&register_mutex);
+       mutex_lock(&register_mutex);
        client = synths[card->number];
        if (client == NULL || client->ports[device] == NULL) {
-               up(&register_mutex);
+               mutex_unlock(&register_mutex);
                return -ENODEV;
        }
        ports = client->ports_per_device[device];
@@ -464,7 +448,7 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
                synths[card->number] = NULL;
                kfree(client);
        }
-       up(&register_mutex);
+       mutex_unlock(&register_mutex);
        return 0;
 }