2 * oxfw_hwdep.c - a part of driver for OXFW970/971 based devices
4 * Copyright (c) 2014 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_oxfw
*oxfw
= hwdep
->private_data
;
24 union snd_firewire_event event
;
26 spin_lock_irq(&oxfw
->lock
);
28 while (!oxfw
->dev_lock_changed
) {
29 prepare_to_wait(&oxfw
->hwdep_wait
, &wait
, TASK_INTERRUPTIBLE
);
30 spin_unlock_irq(&oxfw
->lock
);
32 finish_wait(&oxfw
->hwdep_wait
, &wait
);
33 if (signal_pending(current
))
35 spin_lock_irq(&oxfw
->lock
);
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;
44 count
= min_t(long, count
, sizeof(event
.lock_status
));
47 spin_unlock_irq(&oxfw
->lock
);
49 if (copy_to_user(buf
, &event
, count
))
55 static unsigned int hwdep_poll(struct snd_hwdep
*hwdep
, struct file
*file
,
58 struct snd_oxfw
*oxfw
= hwdep
->private_data
;
61 poll_wait(file
, &oxfw
->hwdep_wait
, wait
);
63 spin_lock_irq(&oxfw
->lock
);
64 if (oxfw
->dev_lock_changed
)
65 events
= POLLIN
| POLLRDNORM
;
68 spin_unlock_irq(&oxfw
->lock
);
73 static int hwdep_get_info(struct snd_oxfw
*oxfw
, void __user
*arg
)
75 struct fw_device
*dev
= fw_parent_device(oxfw
->unit
);
76 struct snd_firewire_get_info info
;
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
));
86 if (copy_to_user(arg
, &info
, sizeof(info
)))
92 static int hwdep_lock(struct snd_oxfw
*oxfw
)
96 spin_lock_irq(&oxfw
->lock
);
98 if (oxfw
->dev_lock_count
== 0) {
99 oxfw
->dev_lock_count
= -1;
105 spin_unlock_irq(&oxfw
->lock
);
110 static int hwdep_unlock(struct snd_oxfw
*oxfw
)
114 spin_lock_irq(&oxfw
->lock
);
116 if (oxfw
->dev_lock_count
== -1) {
117 oxfw
->dev_lock_count
= 0;
123 spin_unlock_irq(&oxfw
->lock
);
128 static int hwdep_release(struct snd_hwdep
*hwdep
, struct file
*file
)
130 struct snd_oxfw
*oxfw
= hwdep
->private_data
;
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
);
140 static int hwdep_ioctl(struct snd_hwdep
*hwdep
, struct file
*file
,
141 unsigned int cmd
, unsigned long arg
)
143 struct snd_oxfw
*oxfw
= hwdep
->private_data
;
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
);
158 static int hwdep_compat_ioctl(struct snd_hwdep
*hwdep
, struct file
*file
,
159 unsigned int cmd
, unsigned long arg
)
161 return hwdep_ioctl(hwdep
, file
, cmd
,
162 (unsigned long)compat_ptr(arg
));
165 #define hwdep_compat_ioctl NULL
168 int snd_oxfw_create_hwdep(struct snd_oxfw
*oxfw
)
170 static const struct snd_hwdep_ops hwdep_ops
= {
172 .release
= hwdep_release
,
174 .ioctl
= hwdep_ioctl
,
175 .ioctl_compat
= hwdep_compat_ioctl
,
177 struct snd_hwdep
*hwdep
;
180 err
= snd_hwdep_new(oxfw
->card
, oxfw
->card
->driver
, 0, &hwdep
);
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;