2 * tascam-hwdep.c - a part of driver for TASCAM FireWire series
4 * Copyright (c) 2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
10 * This codes give three functionality.
12 * 1.get firewire node information
13 * 2.get notification about starting/stopping stream
14 * 3.lock/unlock stream
19 static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
22 struct snd_tscm *tscm = hwdep->private_data;
24 union snd_firewire_event event = {
25 .lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS,
28 spin_lock_irq(&tscm->lock);
30 while (!tscm->dev_lock_changed) {
31 prepare_to_wait(&tscm->hwdep_wait, &wait, TASK_INTERRUPTIBLE);
32 spin_unlock_irq(&tscm->lock);
34 finish_wait(&tscm->hwdep_wait, &wait);
35 if (signal_pending(current))
37 spin_lock_irq(&tscm->lock);
40 event.lock_status.status = (tscm->dev_lock_count > 0);
41 tscm->dev_lock_changed = false;
43 spin_unlock_irq(&tscm->lock);
45 count = min_t(long, count, sizeof(event.lock_status));
47 if (copy_to_user(buf, &event, count))
53 static unsigned int hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
56 struct snd_tscm *tscm = hwdep->private_data;
59 poll_wait(file, &tscm->hwdep_wait, wait);
61 spin_lock_irq(&tscm->lock);
62 if (tscm->dev_lock_changed)
63 events = POLLIN | POLLRDNORM;
66 spin_unlock_irq(&tscm->lock);
71 static int hwdep_get_info(struct snd_tscm *tscm, void __user *arg)
73 struct fw_device *dev = fw_parent_device(tscm->unit);
74 struct snd_firewire_get_info info;
76 memset(&info, 0, sizeof(info));
77 info.type = SNDRV_FIREWIRE_TYPE_TASCAM;
78 info.card = dev->card->index;
79 *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);
80 *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);
81 strlcpy(info.device_name, dev_name(&dev->device),
82 sizeof(info.device_name));
84 if (copy_to_user(arg, &info, sizeof(info)))
90 static int hwdep_lock(struct snd_tscm *tscm)
94 spin_lock_irq(&tscm->lock);
96 if (tscm->dev_lock_count == 0) {
97 tscm->dev_lock_count = -1;
103 spin_unlock_irq(&tscm->lock);
108 static int hwdep_unlock(struct snd_tscm *tscm)
112 spin_lock_irq(&tscm->lock);
114 if (tscm->dev_lock_count == -1) {
115 tscm->dev_lock_count = 0;
121 spin_unlock_irq(&tscm->lock);
126 static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
128 struct snd_tscm *tscm = hwdep->private_data;
130 spin_lock_irq(&tscm->lock);
131 if (tscm->dev_lock_count == -1)
132 tscm->dev_lock_count = 0;
133 spin_unlock_irq(&tscm->lock);
138 static int hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,
139 unsigned int cmd, unsigned long arg)
141 struct snd_tscm *tscm = hwdep->private_data;
144 case SNDRV_FIREWIRE_IOCTL_GET_INFO:
145 return hwdep_get_info(tscm, (void __user *)arg);
146 case SNDRV_FIREWIRE_IOCTL_LOCK:
147 return hwdep_lock(tscm);
148 case SNDRV_FIREWIRE_IOCTL_UNLOCK:
149 return hwdep_unlock(tscm);
156 static int hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,
157 unsigned int cmd, unsigned long arg)
159 return hwdep_ioctl(hwdep, file, cmd,
160 (unsigned long)compat_ptr(arg));
163 #define hwdep_compat_ioctl NULL
166 static const struct snd_hwdep_ops hwdep_ops = {
168 .release = hwdep_release,
170 .ioctl = hwdep_ioctl,
171 .ioctl_compat = hwdep_compat_ioctl,
174 int snd_tscm_create_hwdep_device(struct snd_tscm *tscm)
176 struct snd_hwdep *hwdep;
179 err = snd_hwdep_new(tscm->card, "Tascam", 0, &hwdep);
183 strcpy(hwdep->name, "Tascam");
184 hwdep->iface = SNDRV_HWDEP_IFACE_FW_TASCAM;
185 hwdep->ops = hwdep_ops;
186 hwdep->private_data = tscm;
187 hwdep->exclusive = true;