sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / firewire / tascam / tascam-hwdep.c
blob106406cbfaa3926f294ad0831180472a1e50523d
1 /*
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.
7 */
9 /*
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
17 #include "tascam.h"
19 static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,
20 loff_t *offset)
22 struct snd_tscm *tscm = hwdep->private_data;
23 DEFINE_WAIT(wait);
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);
33 schedule();
34 finish_wait(&tscm->hwdep_wait, &wait);
35 if (signal_pending(current))
36 return -ERESTARTSYS;
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))
48 return -EFAULT;
50 return count;
53 static unsigned int hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
54 poll_table *wait)
56 struct snd_tscm *tscm = hwdep->private_data;
57 unsigned int events;
59 poll_wait(file, &tscm->hwdep_wait, wait);
61 spin_lock_irq(&tscm->lock);
62 if (tscm->dev_lock_changed)
63 events = POLLIN | POLLRDNORM;
64 else
65 events = 0;
66 spin_unlock_irq(&tscm->lock);
68 return events;
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)))
85 return -EFAULT;
87 return 0;
90 static int hwdep_lock(struct snd_tscm *tscm)
92 int err;
94 spin_lock_irq(&tscm->lock);
96 if (tscm->dev_lock_count == 0) {
97 tscm->dev_lock_count = -1;
98 err = 0;
99 } else {
100 err = -EBUSY;
103 spin_unlock_irq(&tscm->lock);
105 return err;
108 static int hwdep_unlock(struct snd_tscm *tscm)
110 int err;
112 spin_lock_irq(&tscm->lock);
114 if (tscm->dev_lock_count == -1) {
115 tscm->dev_lock_count = 0;
116 err = 0;
117 } else {
118 err = -EBADFD;
121 spin_unlock_irq(&tscm->lock);
123 return err;
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);
135 return 0;
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;
143 switch (cmd) {
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);
150 default:
151 return -ENOIOCTLCMD;
155 #ifdef CONFIG_COMPAT
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));
162 #else
163 #define hwdep_compat_ioctl NULL
164 #endif
166 static const struct snd_hwdep_ops hwdep_ops = {
167 .read = hwdep_read,
168 .release = hwdep_release,
169 .poll = hwdep_poll,
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;
177 int err;
179 err = snd_hwdep_new(tscm->card, "Tascam", 0, &hwdep);
180 if (err < 0)
181 return err;
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;
189 return err;