This interface is designed for mixer/control application. 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.
Unified · Split
| @@ -96,9 +96,10 @@ enum { · 95 unmodified lines | ||
| 96 | 96 | SNDRV_HWDEP_IFACE_FW_DICE, /* TC DICE FireWire device */ |
| 97 | 97 | SNDRV_HWDEP_IFACE_FW_FIREWORKS, /* Echo Audio Fireworks based device */ |
| 98 | 98 | SNDRV_HWDEP_IFACE_FW_BEBOB, /* BridgeCo BeBoB based device */ |
| 99 | + SNDRV_HWDEP_IFACE_FW_OXFW, /* Oxford OXFW970/971 based device */ | |
| 99 | 100 | |
| 100 | 101 | /* Don't forget to change the following: */ |
| 101 | − SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_BEBOB | |
| 102 | + SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_OXFW | |
| 102 | 103 | }; |
| 103 | 104 | |
| 104 | 105 | struct snd_hwdep_info { |
| @@ -55,7 +55,8 @@ union snd_firewire_event { · 54 unmodified lines | ||
| 55 | 55 | #define SNDRV_FIREWIRE_TYPE_DICE 1 |
| 56 | 56 | #define SNDRV_FIREWIRE_TYPE_FIREWORKS 2 |
| 57 | 57 | #define SNDRV_FIREWIRE_TYPE_BEBOB 3 |
| 58 | −/* AV/C, RME, MOTU, ... */ | |
| 58 | +#define SNDRV_FIREWIRE_TYPE_OXFW 4 | |
| 59 | +/* RME, MOTU, ... */ | |
| 59 | 60 | |
| 60 | 61 | struct snd_firewire_get_info { |
| 61 | 62 | unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */ |
| @@ -26,6 +26,7 @@ config SND_DICE · 25 unmodified lines | ||
| 26 | 26 | config SND_OXFW |
| 27 | 27 | tristate "Oxford Semiconductor FW970/971 chipset support" |
| 28 | 28 | select SND_FIREWIRE_LIB |
| 29 | + select SND_HWDEP | |
| 29 | 30 | help |
| 30 | 31 | Say Y here to include support for FireWire devices based on |
| 31 | 32 | Oxford Semiconductor FW970/971 chipset. |
| @@ -1,3 +1,3 @@ | ||
| 1 | 1 | snd-oxfw-objs := oxfw-command.o oxfw-stream.o oxfw-control.o oxfw-pcm.o \ |
| 2 | − oxfw-proc.o oxfw-midi.o oxfw.o | |
| 2 | + oxfw-proc.o oxfw-midi.o oxfw-hwdep.o oxfw.o | |
| 3 | 3 | obj-m += snd-oxfw.o |
| @@ -0,0 +1,190 @@ | ||
| 1 | +/* | |
| 2 | + * oxfw_hwdep.c - a part of driver for OXFW970/971 based devices | |
| 3 | + * | |
| 4 | + * Copyright (c) 2014 Takashi Sakamoto | |
| 5 | + * | |
| 6 | + * Licensed under the terms of the GNU General Public License, version 2. | |
| 7 | + */ | |
| 8 | + | |
| 9 | +/* | |
| 10 | + * This codes give three functionality. | |
| 11 | + * | |
| 12 | + * 1.get firewire node information | |
| 13 | + * 2.get notification about starting/stopping stream | |
| 14 | + * 3.lock/unlock stream | |
| 15 | + */ | |
| 16 | + | |
| 17 | +#include "oxfw.h" | |
| 18 | + | |
| 19 | +static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count, | |
| 20 | + loff_t *offset) | |
| 21 | +{ | |
| 22 | + struct snd_oxfw *oxfw = hwdep->private_data; | |
| 23 | + DEFINE_WAIT(wait); | |
| 24 | + union snd_firewire_event event; | |
| 25 | + | |
| 26 | + spin_lock_irq(&oxfw->lock); | |
| 27 | + | |
| 28 | + while (!oxfw->dev_lock_changed) { | |
| 29 | + prepare_to_wait(&oxfw->hwdep_wait, &wait, TASK_INTERRUPTIBLE); | |
| 30 | + spin_unlock_irq(&oxfw->lock); | |
| 31 | + schedule(); | |
| 32 | + finish_wait(&oxfw->hwdep_wait, &wait); | |
| 33 | + if (signal_pending(current)) | |
| 34 | + return -ERESTARTSYS; | |
| 35 | + spin_lock_irq(&oxfw->lock); | |
| 36 | + } | |
| 37 | + | |
| 38 | + memset(&event, 0, sizeof(event)); | |
| 39 | + if (oxfw->dev_lock_changed) { | |
| 40 | + event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS; | |
| 41 | + event.lock_status.status = (oxfw->dev_lock_count > 0); | |
| 42 | + oxfw->dev_lock_changed = false; | |
| 43 | + | |
| 44 | + count = min_t(long, count, sizeof(event.lock_status)); | |
| 45 | + } | |
| 46 | + | |
| 47 | + spin_unlock_irq(&oxfw->lock); | |
| 48 | + | |
| 49 | + if (copy_to_user(buf, &event, count)) | |
| 50 | + return -EFAULT; | |
| 51 | + | |
| 52 | + return count; | |
| 53 | +} | |
| 54 | + | |
| 55 | +static unsigned int hwdep_poll(struct snd_hwdep *hwdep, struct file *file, | |
| 56 | + poll_table *wait) | |
| 57 | +{ | |
| 58 | + struct snd_oxfw *oxfw = hwdep->private_data; | |
| 59 | + unsigned int events; | |
| 60 | + | |
| 61 | + poll_wait(file, &oxfw->hwdep_wait, wait); | |
| 62 | + | |
| 63 | + spin_lock_irq(&oxfw->lock); | |
| 64 | + if (oxfw->dev_lock_changed) | |
| 65 | + events = POLLIN | POLLRDNORM; | |
| 66 | + else | |
| 67 | + events = 0; | |
| 68 | + spin_unlock_irq(&oxfw->lock); | |
| 69 | + | |
| 70 | + return events; | |
| 71 | +} | |
| 72 | + | |
| 73 | +static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg) | |
| 74 | +{ | |
| 75 | + struct fw_device *dev = fw_parent_device(oxfw->unit); | |
| 76 | + struct snd_firewire_get_info info; | |
| 77 | + | |
| 78 | + memset(&info, 0, sizeof(info)); | |
| 79 | + info.type = SNDRV_FIREWIRE_TYPE_OXFW; | |
| 80 | + info.card = dev->card->index; | |
| 81 | + *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]); | |
| 82 | + *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]); | |
| 83 | + strlcpy(info.device_name, dev_name(&dev->device), | |
| 84 | + sizeof(info.device_name)); | |
| 85 | + | |
| 86 | + if (copy_to_user(arg, &info, sizeof(info))) | |
| 87 | + return -EFAULT; | |
| 88 | + | |
| 89 | + return 0; | |
| 90 | +} | |
| 91 | + | |
| 92 | +static int hwdep_lock(struct snd_oxfw *oxfw) | |
| 93 | +{ | |
| 94 | + int err; | |
| 95 | + | |
| 96 | + spin_lock_irq(&oxfw->lock); | |
| 97 | + | |
| 98 | + if (oxfw->dev_lock_count == 0) { | |
| 99 | + oxfw->dev_lock_count = -1; | |
| 100 | + err = 0; | |
| 101 | + } else { | |
| 102 | + err = -EBUSY; | |
| 103 | + } | |
| 104 | + | |
| 105 | + spin_unlock_irq(&oxfw->lock); | |
| 106 | + | |
| 107 | + return err; | |
| 108 | +} | |
| 109 | + | |
| 110 | +static int hwdep_unlock(struct snd_oxfw *oxfw) | |
| 111 | +{ | |
| 112 | + int err; | |
| 113 | + | |
| 114 | + spin_lock_irq(&oxfw->lock); | |
| 115 | + | |
| 116 | + if (oxfw->dev_lock_count == -1) { | |
| 117 | + oxfw->dev_lock_count = 0; | |
| 118 | + err = 0; | |
| 119 | + } else { | |
| 120 | + err = -EBADFD; | |
| 121 | + } | |
| 122 | + | |
| 123 | + spin_unlock_irq(&oxfw->lock); | |
| 124 | + | |
| 125 | + return err; | |
| 126 | +} | |
| 127 | + | |
| 128 | +static int hwdep_release(struct snd_hwdep *hwdep, struct file *file) | |
| 129 | +{ | |
| 130 | + struct snd_oxfw *oxfw = hwdep->private_data; | |
| 131 | + | |
| 132 | + spin_lock_irq(&oxfw->lock); | |
| 133 | + if (oxfw->dev_lock_count == -1) | |
| 134 | + oxfw->dev_lock_count = 0; | |
| 135 | + spin_unlock_irq(&oxfw->lock); | |
| 136 | + | |
| 137 | + return 0; | |
| 138 | +} | |
| 139 | + | |
| 140 | +static int hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file, | |
| 141 | + unsigned int cmd, unsigned long arg) | |
| 142 | +{ | |
| 143 | + struct snd_oxfw *oxfw = hwdep->private_data; | |
| 144 | + | |
| 145 | + switch (cmd) { | |
| 146 | + case SNDRV_FIREWIRE_IOCTL_GET_INFO: | |
| 147 | + return hwdep_get_info(oxfw, (void __user *)arg); | |
| 148 | + case SNDRV_FIREWIRE_IOCTL_LOCK: | |
| 149 | + return hwdep_lock(oxfw); | |
| 150 | + case SNDRV_FIREWIRE_IOCTL_UNLOCK: | |
| 151 | + return hwdep_unlock(oxfw); | |
| 152 | + default: | |
| 153 | + return -ENOIOCTLCMD; | |
| 154 | + } | |
| 155 | +} | |
| 156 | + | |
| 157 | +#ifdef CONFIG_COMPAT | |
| 158 | +static int hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file, | |
| 159 | + unsigned int cmd, unsigned long arg) | |
| 160 | +{ | |
| 161 | + return hwdep_ioctl(hwdep, file, cmd, | |
| 162 | + (unsigned long)compat_ptr(arg)); | |
| 163 | +} | |
| 164 | +#else | |
| 165 | +#define hwdep_compat_ioctl NULL | |
| 166 | +#endif | |
| 167 | + | |
| 168 | +int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw) | |
| 169 | +{ | |
| 170 | + static const struct snd_hwdep_ops hwdep_ops = { | |
| 171 | + .read = hwdep_read, | |
| 172 | + .release = hwdep_release, | |
| 173 | + .poll = hwdep_poll, | |
| 174 | + .ioctl = hwdep_ioctl, | |
| 175 | + .ioctl_compat = hwdep_compat_ioctl, | |
| 176 | + }; | |
| 177 | + struct snd_hwdep *hwdep; | |
| 178 | + int err; | |
| 179 | + | |
| 180 | + err = snd_hwdep_new(oxfw->card, oxfw->card->driver, 0, &hwdep); | |
| 181 | + if (err < 0) | |
| 182 | + goto end; | |
| 183 | + strcpy(hwdep->name, oxfw->card->driver); | |
| 184 | + hwdep->iface = SNDRV_HWDEP_IFACE_FW_OXFW; | |
| 185 | + hwdep->ops = hwdep_ops; | |
| 186 | + hwdep->private_data = oxfw; | |
| 187 | + hwdep->exclusive = true; | |
| 188 | +end: | |
| 189 | + return err; | |
| 190 | +} | |
| @@ -13,6 +13,10 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream) · 12 unmodified lines | ||
| 13 | 13 | struct snd_oxfw *oxfw = substream->rmidi->private_data; |
| 14 | 14 | int err; |
| 15 | 15 | |
| 16 | + err = snd_oxfw_stream_lock_try(oxfw); | |
| 17 | + if (err < 0) | |
| 18 | + return err; | |
| 19 | + | |
| 16 | 20 | mutex_lock(&oxfw->mutex); |
| 17 | 21 | |
| 18 | 22 | oxfw->capture_substreams++; |
| @@ -20,6 +24,9 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream) · 1 unmodified line | ||
| 20 | 24 | |
| 21 | 25 | mutex_unlock(&oxfw->mutex); |
| 22 | 26 | |
| 27 | + if (err < 0) | |
| 28 | + snd_oxfw_stream_lock_release(oxfw); | |
| 29 | + | |
| 23 | 30 | return err; |
| 24 | 31 | } |
| 25 | 32 | |
| @@ -28,6 +35,10 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream) · 2 unmodified lines | ||
| 28 | 35 | struct snd_oxfw *oxfw = substream->rmidi->private_data; |
| 29 | 36 | int err; |
| 30 | 37 | |
| 38 | + err = snd_oxfw_stream_lock_try(oxfw); | |
| 39 | + if (err < 0) | |
| 40 | + return err; | |
| 41 | + | |
| 31 | 42 | mutex_lock(&oxfw->mutex); |
| 32 | 43 | |
| 33 | 44 | oxfw->playback_substreams++; |
| @@ -35,6 +46,9 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream) · 1 unmodified line | ||
| 35 | 46 | |
| 36 | 47 | mutex_unlock(&oxfw->mutex); |
| 37 | 48 | |
| 49 | + if (err < 0) | |
| 50 | + snd_oxfw_stream_lock_release(oxfw); | |
| 51 | + | |
| 38 | 52 | return err; |
| 39 | 53 | } |
| 40 | 54 | |
| @@ -49,6 +63,7 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream) · 8 unmodified lines | ||
| 49 | 63 | |
| 50 | 64 | mutex_unlock(&oxfw->mutex); |
| 51 | 65 | |
| 66 | + snd_oxfw_stream_lock_release(oxfw); | |
| 52 | 67 | return 0; |
| 53 | 68 | } |
| 54 | 69 | |
| @@ -63,6 +78,7 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream) · 8 unmodified lines | ||
| 63 | 78 | |
| 64 | 79 | mutex_unlock(&oxfw->mutex); |
| 65 | 80 | |
| 81 | + snd_oxfw_stream_lock_release(oxfw); | |
| 66 | 82 | return 0; |
| 67 | 83 | } |
| 68 | 84 | |
| @@ -192,10 +192,14 @@ static int pcm_open(struct snd_pcm_substream *substream) · 191 unmodified lines | ||
| 192 | 192 | struct snd_oxfw *oxfw = substream->private_data; |
| 193 | 193 | int err; |
| 194 | 194 | |
| 195 | − err = init_hw_params(oxfw, substream); | |
| 195 | + err = snd_oxfw_stream_lock_try(oxfw); | |
| 196 | 196 | if (err < 0) |
| 197 | 197 | goto end; |
| 198 | 198 | |
| 199 | + err = init_hw_params(oxfw, substream); | |
| 200 | + if (err < 0) | |
| 201 | + goto err_locked; | |
| 202 | + | |
| 199 | 203 | /* |
| 200 | 204 | * When any PCM streams are already running, the available sampling |
| 201 | 205 | * rate is limited at current value. |
| @@ -210,10 +214,16 @@ static int pcm_open(struct snd_pcm_substream *substream) · 8 unmodified lines | ||
| 210 | 214 | snd_pcm_set_sync(substream); |
| 211 | 215 | end: |
| 212 | 216 | return err; |
| 217 | +err_locked: | |
| 218 | + snd_oxfw_stream_lock_release(oxfw); | |
| 219 | + return err; | |
| 213 | 220 | } |
| 214 | 221 | |
| 215 | 222 | static int pcm_close(struct snd_pcm_substream *substream) |
| 216 | 223 | { |
| 224 | + struct snd_oxfw *oxfw = substream->private_data; | |
| 225 | + | |
| 226 | + snd_oxfw_stream_lock_release(oxfw); | |
| 217 | 227 | return 0; |
| 218 | 228 | } |
| 219 | 229 | |
| @@ -644,3 +644,42 @@ int snd_oxfw_stream_discover(struct snd_oxfw *oxfw) · 643 unmodified lines | ||
| 644 | 644 | end: |
| 645 | 645 | return err; |
| 646 | 646 | } |
| 647 | + | |
| 648 | +void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw) | |
| 649 | +{ | |
| 650 | + oxfw->dev_lock_changed = true; | |
| 651 | + wake_up(&oxfw->hwdep_wait); | |
| 652 | +} | |
| 653 | + | |
| 654 | +int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw) | |
| 655 | +{ | |
| 656 | + int err; | |
| 657 | + | |
| 658 | + spin_lock_irq(&oxfw->lock); | |
| 659 | + | |
| 660 | + /* user land lock this */ | |
| 661 | + if (oxfw->dev_lock_count < 0) { | |
| 662 | + err = -EBUSY; | |
| 663 | + goto end; | |
| 664 | + } | |
| 665 | + | |
| 666 | + /* this is the first time */ | |
| 667 | + if (oxfw->dev_lock_count++ == 0) | |
| 668 | + snd_oxfw_stream_lock_changed(oxfw); | |
| 669 | + err = 0; | |
| 670 | +end: | |
| 671 | + spin_unlock_irq(&oxfw->lock); | |
| 672 | + return err; | |
| 673 | +} | |
| 674 | + | |
| 675 | +void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw) | |
| 676 | +{ | |
| 677 | + spin_lock_irq(&oxfw->lock); | |
| 678 | + | |
| 679 | + if (WARN_ON(oxfw->dev_lock_count <= 0)) | |
| 680 | + goto end; | |
| 681 | + if (--oxfw->dev_lock_count == 0) | |
| 682 | + snd_oxfw_stream_lock_changed(oxfw); | |
| 683 | +end: | |
| 684 | + spin_unlock_irq(&oxfw->lock); | |
| 685 | +} | |
| @@ -139,6 +139,7 @@ static int oxfw_probe(struct fw_unit *unit, · 138 unmodified lines | ||
| 139 | 139 | oxfw->unit = unit; |
| 140 | 140 | oxfw->device_info = (const struct device_info *)id->driver_data; |
| 141 | 141 | spin_lock_init(&oxfw->lock); |
| 142 | + init_waitqueue_head(&oxfw->hwdep_wait); | |
| 142 | 143 | |
| 143 | 144 | err = snd_oxfw_stream_discover(oxfw); |
| 144 | 145 | if (err < 0) |
| @@ -164,6 +165,10 @@ static int oxfw_probe(struct fw_unit *unit, · 19 unmodified lines | ||
| 164 | 165 | if (err < 0) |
| 165 | 166 | goto error; |
| 166 | 167 | |
| 168 | + err = snd_oxfw_create_hwdep(oxfw); | |
| 169 | + if (err < 0) | |
| 170 | + goto error; | |
| 171 | + | |
| 167 | 172 | err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream); |
| 168 | 173 | if (err < 0) |
| 169 | 174 | goto error; |
| @@ -12,6 +12,7 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <linux/mod_devicetable.h> |
| 13 | 13 | #include <linux/mutex.h> |
| 14 | 14 | #include <linux/slab.h> |
| 15 | +#include <linux/compat.h> | |
| 15 | 16 | |
| 16 | 17 | #include <sound/control.h> |
| 17 | 18 | #include <sound/core.h> |
| @@ -20,6 +21,8 @@ · 2 unmodified lines | ||
| 20 | 21 | #include <sound/pcm_params.h> |
| 21 | 22 | #include <sound/info.h> |
| 22 | 23 | #include <sound/rawmidi.h> |
| 24 | +#include <sound/firewire.h> | |
| 25 | +#include <sound/hwdep.h> | |
| 23 | 26 | |
| 24 | 27 | #include "../lib.h" |
| 25 | 28 | #include "../fcp.h" |
| @@ -64,6 +67,10 @@ struct snd_oxfw { · 38 unmodified lines | ||
| 64 | 67 | s16 volume[6]; |
| 65 | 68 | s16 volume_min; |
| 66 | 69 | s16 volume_max; |
| 70 | + | |
| 71 | + int dev_lock_count; | |
| 72 | + bool dev_lock_changed; | |
| 73 | + wait_queue_head_t hwdep_wait; | |
| 67 | 74 | }; |
| 68 | 75 | |
| 69 | 76 | /* |
| @@ -124,6 +131,10 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw, · 54 unmodified lines | ||
| 124 | 131 | |
| 125 | 132 | int snd_oxfw_stream_discover(struct snd_oxfw *oxfw); |
| 126 | 133 | |
| 134 | +void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw); | |
| 135 | +int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw); | |
| 136 | +void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw); | |
| 137 | + | |
| 127 | 138 | int snd_oxfw_create_pcm(struct snd_oxfw *oxfw); |
| 128 | 139 | |
| 129 | 140 | int snd_oxfw_create_mixer(struct snd_oxfw *oxfw); |
| @@ -131,3 +142,5 @@ int snd_oxfw_create_mixer(struct snd_oxfw *oxfw); · 1 unmodified line | ||
| 131 | 142 | void snd_oxfw_proc_init(struct snd_oxfw *oxfw); |
| 132 | 143 | |
| 133 | 144 | int snd_oxfw_create_midi(struct snd_oxfw *oxfw); |
| 145 | + | |
| 146 | +int snd_oxfw_create_hwdep(struct snd_oxfw *oxfw); | |