aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2017-03-22 08:30:24 -0400
committerTakashi Iwai <tiwai@suse.de>2017-03-28 06:34:02 -0400
commit71c3797779d3cd8378767f5b2d8cfd3b2f88c5c1 (patch)
treeb64eeb67394492017bb55b3123ad11a13e7de202
parent9e796e7d59e71f8a556cfbdc2ffa3aff0555dd0e (diff)
ALSA: firewire-motu: add hwdep interface
This commit adds hwdep interface so as the other sound drivers for units on IEEE 1394 bus have. This interface is designed for mixer/control applications. By using this interface, an application can get information about firewire node, can lock/unlock kernel streaming and can get notification at starting/stopping kernel streaming. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--include/uapi/sound/asound.h3
-rw-r--r--include/uapi/sound/firewire.h3
-rw-r--r--sound/firewire/motu/Makefile2
-rw-r--r--sound/firewire/motu/motu-hwdep.c192
-rw-r--r--sound/firewire/motu/motu-midi.c16
-rw-r--r--sound/firewire/motu/motu-pcm.c20
-rw-r--r--sound/firewire/motu/motu-stream.c38
-rw-r--r--sound/firewire/motu/motu.c5
-rw-r--r--sound/firewire/motu/motu.h13
9 files changed, 285 insertions, 7 deletions
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index be353a78c303..fd7b561af768 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -107,9 +107,10 @@ enum {
107 SNDRV_HWDEP_IFACE_FW_DIGI00X, /* Digidesign Digi 002/003 family */ 107 SNDRV_HWDEP_IFACE_FW_DIGI00X, /* Digidesign Digi 002/003 family */
108 SNDRV_HWDEP_IFACE_FW_TASCAM, /* TASCAM FireWire series */ 108 SNDRV_HWDEP_IFACE_FW_TASCAM, /* TASCAM FireWire series */
109 SNDRV_HWDEP_IFACE_LINE6, /* Line6 USB processors */ 109 SNDRV_HWDEP_IFACE_LINE6, /* Line6 USB processors */
110 SNDRV_HWDEP_IFACE_FW_MOTU, /* MOTU FireWire series */
110 111
111 /* Don't forget to change the following: */ 112 /* Don't forget to change the following: */
112 SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_LINE6 113 SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_MOTU
113}; 114};
114 115
115struct snd_hwdep_info { 116struct snd_hwdep_info {
diff --git a/include/uapi/sound/firewire.h b/include/uapi/sound/firewire.h
index db79a12fcc78..59c6d81f5364 100644
--- a/include/uapi/sound/firewire.h
+++ b/include/uapi/sound/firewire.h
@@ -65,7 +65,8 @@ union snd_firewire_event {
65#define SNDRV_FIREWIRE_TYPE_OXFW 4 65#define SNDRV_FIREWIRE_TYPE_OXFW 4
66#define SNDRV_FIREWIRE_TYPE_DIGI00X 5 66#define SNDRV_FIREWIRE_TYPE_DIGI00X 5
67#define SNDRV_FIREWIRE_TYPE_TASCAM 6 67#define SNDRV_FIREWIRE_TYPE_TASCAM 6
68/* RME, MOTU, ... */ 68#define SNDRV_FIREWIRE_TYPE_MOTU 7
69/* RME... */
69 70
70struct snd_firewire_get_info { 71struct snd_firewire_get_info {
71 unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */ 72 unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */
diff --git a/sound/firewire/motu/Makefile b/sound/firewire/motu/Makefile
index a512c1e0f49c..cc195d5a5a6e 100644
--- a/sound/firewire/motu/Makefile
+++ b/sound/firewire/motu/Makefile
@@ -1,3 +1,3 @@
1snd-firewire-motu-objs := motu.o amdtp-motu.o motu-transaction.o motu-stream.o \ 1snd-firewire-motu-objs := motu.o amdtp-motu.o motu-transaction.o motu-stream.o \
2 motu-proc.o motu-pcm.o motu-midi.o 2 motu-proc.o motu-pcm.o motu-midi.o motu-hwdep.o
3obj-$(CONFIG_SND_FIREWIRE_MOTU) += snd-firewire-motu.o 3obj-$(CONFIG_SND_FIREWIRE_MOTU) += snd-firewire-motu.o
diff --git a/sound/firewire/motu/motu-hwdep.c b/sound/firewire/motu/motu-hwdep.c
new file mode 100644
index 000000000000..e795a5219a21
--- /dev/null
+++ b/sound/firewire/motu/motu-hwdep.c
@@ -0,0 +1,192 @@
1/*
2 * motu-hwdep.c - a part of driver for MOTU FireWire series
3 *
4 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9/*
10 * This codes have five functionalities.
11 *
12 * 1.get information about firewire node
13 * 2.get notification about starting/stopping stream
14 * 3.lock/unlock streaming
15 *
16 */
17
18#include "motu.h"
19
20static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
21 loff_t *offset)
22{
23 struct snd_motu *motu = hwdep->private_data;
24 DEFINE_WAIT(wait);
25 union snd_firewire_event event;
26
27 spin_lock_irq(&motu->lock);
28
29 while (!motu->dev_lock_changed) {
30 prepare_to_wait(&motu->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
31 spin_unlock_irq(&motu->lock);
32 schedule();
33 finish_wait(&motu->hwdep_wait, &wait);
34 if (signal_pending(current))
35 return -ERESTARTSYS;
36 spin_lock_irq(&motu->lock);
37 }
38
39 memset(&event, 0, sizeof(event));
40 if (motu->dev_lock_changed) {
41 event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
42 event.lock_status.status = (motu->dev_lock_count > 0);
43 motu->dev_lock_changed = false;
44
45 count = min_t(long, count, sizeof(event.lock_status));
46 }
47
48 spin_unlock_irq(&motu->lock);
49
50 if (copy_to_user(buf, &event, count))
51 return -EFAULT;
52
53 return count;
54}
55
56static unsigned int hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
57 poll_table *wait)
58{
59 struct snd_motu *motu = hwdep->private_data;
60 unsigned int events;
61
62 poll_wait(file, &motu->hwdep_wait, wait);
63
64 spin_lock_irq(&motu->lock);
65 if (motu->dev_lock_changed)
66 events = POLLIN | POLLRDNORM;
67 else
68 events = 0;
69 spin_unlock_irq(&motu->lock);
70
71 return events | POLLOUT;
72}
73
74static int hwdep_get_info(struct snd_motu *motu, void __user *arg)
75{
76 struct fw_device *dev = fw_parent_device(motu->unit);
77 struct snd_firewire_get_info info;
78
79 memset(&info, 0, sizeof(info));
80 info.type = SNDRV_FIREWIRE_TYPE_MOTU;
81 info.card = dev->card->index;
82 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
83 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
84 strlcpy(info.device_name, dev_name(&dev->device),
85 sizeof(info.device_name));
86
87 if (copy_to_user(arg, &info, sizeof(info)))
88 return -EFAULT;
89
90 return 0;
91}
92
93static int hwdep_lock(struct snd_motu *motu)
94{
95 int err;
96
97 spin_lock_irq(&motu->lock);
98
99 if (motu->dev_lock_count == 0) {
100 motu->dev_lock_count = -1;
101 err = 0;
102 } else {
103 err = -EBUSY;
104 }
105
106 spin_unlock_irq(&motu->lock);
107
108 return err;
109}
110
111static int hwdep_unlock(struct snd_motu *motu)
112{
113 int err;
114
115 spin_lock_irq(&motu->lock);
116
117 if (motu->dev_lock_count == -1) {
118 motu->dev_lock_count = 0;
119 err = 0;
120 } else {
121 err = -EBADFD;
122 }
123
124 spin_unlock_irq(&motu->lock);
125
126 return err;
127}
128
129static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
130{
131 struct snd_motu *motu = hwdep->private_data;
132
133 spin_lock_irq(&motu->lock);
134 if (motu->dev_lock_count == -1)
135 motu->dev_lock_count = 0;
136 spin_unlock_irq(&motu->lock);
137
138 return 0;
139}
140
141static int hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
142 unsigned int cmd, unsigned long arg)
143{
144 struct snd_motu *motu = hwdep->private_data;
145
146 switch (cmd) {
147 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
148 return hwdep_get_info(motu, (void __user *)arg);
149 case SNDRV_FIREWIRE_IOCTL_LOCK:
150 return hwdep_lock(motu);
151 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
152 return hwdep_unlock(motu);
153 default:
154 return -ENOIOCTLCMD;
155 }
156}
157
158#ifdef CONFIG_COMPAT
159static int hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
160 unsigned int cmd, unsigned long arg)
161{
162 return hwdep_ioctl(hwdep, file, cmd,
163 (unsigned long)compat_ptr(arg));
164}
165#else
166#define hwdep_compat_ioctl NULL
167#endif
168
169int snd_motu_create_hwdep_device(struct snd_motu *motu)
170{
171 static const struct snd_hwdep_ops ops = {
172 .read = hwdep_read,
173 .release = hwdep_release,
174 .poll = hwdep_poll,
175 .ioctl = hwdep_ioctl,
176 .ioctl_compat = hwdep_compat_ioctl,
177 };
178 struct snd_hwdep *hwdep;
179 int err;
180
181 err = snd_hwdep_new(motu->card, motu->card->driver, 0, &hwdep);
182 if (err < 0)
183 return err;
184
185 strcpy(hwdep->name, "MOTU");
186 hwdep->iface = SNDRV_HWDEP_IFACE_FW_MOTU;
187 hwdep->ops = ops;
188 hwdep->private_data = motu;
189 hwdep->exclusive = true;
190
191 return 0;
192}
diff --git a/sound/firewire/motu/motu-midi.c b/sound/firewire/motu/motu-midi.c
index f232f29589d0..e3acfcc53f4e 100644
--- a/sound/firewire/motu/motu-midi.c
+++ b/sound/firewire/motu/motu-midi.c
@@ -12,6 +12,10 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
12 struct snd_motu *motu = substream->rmidi->private_data; 12 struct snd_motu *motu = substream->rmidi->private_data;
13 int err; 13 int err;
14 14
15 err = snd_motu_stream_lock_try(motu);
16 if (err < 0)
17 return err;
18
15 mutex_lock(&motu->mutex); 19 mutex_lock(&motu->mutex);
16 20
17 motu->capture_substreams++; 21 motu->capture_substreams++;
@@ -19,6 +23,9 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream)
19 23
20 mutex_unlock(&motu->mutex); 24 mutex_unlock(&motu->mutex);
21 25
26 if (err < 0)
27 snd_motu_stream_lock_release(motu);
28
22 return err; 29 return err;
23} 30}
24 31
@@ -27,6 +34,10 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
27 struct snd_motu *motu = substream->rmidi->private_data; 34 struct snd_motu *motu = substream->rmidi->private_data;
28 int err; 35 int err;
29 36
37 err = snd_motu_stream_lock_try(motu);
38 if (err < 0)
39 return err;
40
30 mutex_lock(&motu->mutex); 41 mutex_lock(&motu->mutex);
31 42
32 motu->playback_substreams++; 43 motu->playback_substreams++;
@@ -34,6 +45,9 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream)
34 45
35 mutex_unlock(&motu->mutex); 46 mutex_unlock(&motu->mutex);
36 47
48 if (err < 0)
49 snd_motu_stream_lock_release(motu);
50
37 return err; 51 return err;
38} 52}
39 53
@@ -48,6 +62,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream)
48 62
49 mutex_unlock(&motu->mutex); 63 mutex_unlock(&motu->mutex);
50 64
65 snd_motu_stream_lock_release(motu);
51 return 0; 66 return 0;
52} 67}
53 68
@@ -62,6 +77,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream)
62 77
63 mutex_unlock(&motu->mutex); 78 mutex_unlock(&motu->mutex);
64 79
80 snd_motu_stream_lock_release(motu);
65 return 0; 81 return 0;
66} 82}
67 83
diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c
index a50bcd6f4a63..94558f3d218b 100644
--- a/sound/firewire/motu/motu-pcm.c
+++ b/sound/firewire/motu/motu-pcm.c
@@ -159,15 +159,19 @@ static int pcm_open(struct snd_pcm_substream *substream)
159 unsigned int rate; 159 unsigned int rate;
160 int err; 160 int err;
161 161
162 err = snd_motu_stream_lock_try(motu);
163 if (err < 0)
164 return err;
165
162 mutex_lock(&motu->mutex); 166 mutex_lock(&motu->mutex);
163 167
164 err = protocol->cache_packet_formats(motu); 168 err = protocol->cache_packet_formats(motu);
165 if (err < 0) 169 if (err < 0)
166 return err; 170 goto err_locked;
167 171
168 err = init_hw_info(motu, substream); 172 err = init_hw_info(motu, substream);
169 if (err < 0) 173 if (err < 0)
170 return err; 174 goto err_locked;
171 175
172 /* 176 /*
173 * When source of clock is not internal or any PCM streams are running, 177 * When source of clock is not internal or any PCM streams are running,
@@ -175,13 +179,13 @@ static int pcm_open(struct snd_pcm_substream *substream)
175 */ 179 */
176 err = protocol->get_clock_source(motu, &src); 180 err = protocol->get_clock_source(motu, &src);
177 if (err < 0) 181 if (err < 0)
178 return err; 182 goto err_locked;
179 if (src != SND_MOTU_CLOCK_SOURCE_INTERNAL || 183 if (src != SND_MOTU_CLOCK_SOURCE_INTERNAL ||
180 amdtp_stream_pcm_running(&motu->tx_stream) || 184 amdtp_stream_pcm_running(&motu->tx_stream) ||
181 amdtp_stream_pcm_running(&motu->rx_stream)) { 185 amdtp_stream_pcm_running(&motu->rx_stream)) {
182 err = protocol->get_clock_rate(motu, &rate); 186 err = protocol->get_clock_rate(motu, &rate);
183 if (err < 0) 187 if (err < 0)
184 return err; 188 goto err_locked;
185 substream->runtime->hw.rate_min = rate; 189 substream->runtime->hw.rate_min = rate;
186 substream->runtime->hw.rate_max = rate; 190 substream->runtime->hw.rate_max = rate;
187 } 191 }
@@ -191,10 +195,18 @@ static int pcm_open(struct snd_pcm_substream *substream)
191 mutex_unlock(&motu->mutex); 195 mutex_unlock(&motu->mutex);
192 196
193 return err; 197 return err;
198err_locked:
199 mutex_unlock(&motu->mutex);
200 snd_motu_stream_lock_release(motu);
201 return err;
194} 202}
195 203
196static int pcm_close(struct snd_pcm_substream *substream) 204static int pcm_close(struct snd_pcm_substream *substream)
197{ 205{
206 struct snd_motu *motu = substream->private_data;
207
208 snd_motu_stream_lock_release(motu);
209
198 return 0; 210 return 0;
199} 211}
200 212
diff --git a/sound/firewire/motu/motu-stream.c b/sound/firewire/motu/motu-stream.c
index 911d3487f775..bd458029099e 100644
--- a/sound/firewire/motu/motu-stream.c
+++ b/sound/firewire/motu/motu-stream.c
@@ -341,3 +341,41 @@ void snd_motu_stream_destroy_duplex(struct snd_motu *motu)
341 motu->playback_substreams = 0; 341 motu->playback_substreams = 0;
342 motu->capture_substreams = 0; 342 motu->capture_substreams = 0;
343} 343}
344
345static void motu_lock_changed(struct snd_motu *motu)
346{
347 motu->dev_lock_changed = true;
348 wake_up(&motu->hwdep_wait);
349}
350
351int snd_motu_stream_lock_try(struct snd_motu *motu)
352{
353 int err;
354
355 spin_lock_irq(&motu->lock);
356
357 if (motu->dev_lock_count < 0) {
358 err = -EBUSY;
359 goto out;
360 }
361
362 if (motu->dev_lock_count++ == 0)
363 motu_lock_changed(motu);
364 err = 0;
365out:
366 spin_unlock_irq(&motu->lock);
367 return err;
368}
369
370void snd_motu_stream_lock_release(struct snd_motu *motu)
371{
372 spin_lock_irq(&motu->lock);
373
374 if (WARN_ON(motu->dev_lock_count <= 0))
375 goto out;
376
377 if (--motu->dev_lock_count == 0)
378 motu_lock_changed(motu);
379out:
380 spin_unlock_irq(&motu->lock);
381}
diff --git a/sound/firewire/motu/motu.c b/sound/firewire/motu/motu.c
index d4da1377fa50..619554b9dbef 100644
--- a/sound/firewire/motu/motu.c
+++ b/sound/firewire/motu/motu.c
@@ -109,6 +109,10 @@ static void do_registration(struct work_struct *work)
109 goto error; 109 goto error;
110 } 110 }
111 111
112 err = snd_motu_create_hwdep_device(motu);
113 if (err < 0)
114 goto error;
115
112 err = snd_card_register(motu->card); 116 err = snd_card_register(motu->card);
113 if (err < 0) 117 if (err < 0)
114 goto error; 118 goto error;
@@ -145,6 +149,7 @@ static int motu_probe(struct fw_unit *unit,
145 149
146 mutex_init(&motu->mutex); 150 mutex_init(&motu->mutex);
147 spin_lock_init(&motu->lock); 151 spin_lock_init(&motu->lock);
152 init_waitqueue_head(&motu->hwdep_wait);
148 153
149 /* Allocate and register this sound card later. */ 154 /* Allocate and register this sound card later. */
150 INIT_DEFERRABLE_WORK(&motu->dwork, do_registration); 155 INIT_DEFERRABLE_WORK(&motu->dwork, do_registration);
diff --git a/sound/firewire/motu/motu.h b/sound/firewire/motu/motu.h
index 338b35193001..7b1d85f29b49 100644
--- a/sound/firewire/motu/motu.h
+++ b/sound/firewire/motu/motu.h
@@ -16,12 +16,16 @@
16#include <linux/mod_devicetable.h> 16#include <linux/mod_devicetable.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/compat.h>
20#include <linux/sched/signal.h>
19 21
20#include <sound/control.h> 22#include <sound/control.h>
21#include <sound/core.h> 23#include <sound/core.h>
22#include <sound/pcm.h> 24#include <sound/pcm.h>
23#include <sound/info.h> 25#include <sound/info.h>
24#include <sound/rawmidi.h> 26#include <sound/rawmidi.h>
27#include <sound/firewire.h>
28#include <sound/hwdep.h>
25 29
26#include "../lib.h" 30#include "../lib.h"
27#include "../amdtp-stream.h" 31#include "../amdtp-stream.h"
@@ -62,6 +66,11 @@ struct snd_motu {
62 /* For notification. */ 66 /* For notification. */
63 struct fw_address_handler async_handler; 67 struct fw_address_handler async_handler;
64 u32 msg; 68 u32 msg;
69
70 /* For uapi */
71 int dev_lock_count;
72 bool dev_lock_changed;
73 wait_queue_head_t hwdep_wait;
65}; 74};
66 75
67enum snd_motu_spec_flags { 76enum snd_motu_spec_flags {
@@ -136,10 +145,14 @@ int snd_motu_stream_init_duplex(struct snd_motu *motu);
136void snd_motu_stream_destroy_duplex(struct snd_motu *motu); 145void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
137int snd_motu_stream_start_duplex(struct snd_motu *motu, unsigned int rate); 146int snd_motu_stream_start_duplex(struct snd_motu *motu, unsigned int rate);
138void snd_motu_stream_stop_duplex(struct snd_motu *motu); 147void snd_motu_stream_stop_duplex(struct snd_motu *motu);
148int snd_motu_stream_lock_try(struct snd_motu *motu);
149void snd_motu_stream_lock_release(struct snd_motu *motu);
139 150
140void snd_motu_proc_init(struct snd_motu *motu); 151void snd_motu_proc_init(struct snd_motu *motu);
141 152
142int snd_motu_create_pcm_devices(struct snd_motu *motu); 153int snd_motu_create_pcm_devices(struct snd_motu *motu);
143 154
144int snd_motu_create_midi_devices(struct snd_motu *motu); 155int snd_motu_create_midi_devices(struct snd_motu *motu);
156
157int snd_motu_create_hwdep_device(struct snd_motu *motu);
145#endif 158#endif