Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Digital Audio (PCM) abstract layer |
| 3 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> |
| 4 | * |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sound/driver.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/time.h> |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <sound/core.h> |
| 28 | #include <sound/minors.h> |
| 29 | #include <sound/pcm.h> |
| 30 | #include <sound/control.h> |
| 31 | #include <sound/info.h> |
| 32 | |
| 33 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Abramo Bagnara <abramo@alsa-project.org>"); |
| 34 | MODULE_DESCRIPTION("Midlevel PCM code for ALSA."); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 37 | static LIST_HEAD(snd_pcm_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static LIST_HEAD(snd_pcm_notify_list); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 39 | static DEFINE_MUTEX(register_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 41 | static int snd_pcm_free(struct snd_pcm *pcm); |
| 42 | static int snd_pcm_dev_free(struct snd_device *device); |
| 43 | static int snd_pcm_dev_register(struct snd_device *device); |
| 44 | static int snd_pcm_dev_disconnect(struct snd_device *device); |
| 45 | static int snd_pcm_dev_unregister(struct snd_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 47 | static struct snd_pcm *snd_pcm_search(struct snd_card *card, int device) |
| 48 | { |
| 49 | struct list_head *p; |
| 50 | struct snd_pcm *pcm; |
| 51 | |
| 52 | list_for_each(p, &snd_pcm_devices) { |
| 53 | pcm = list_entry(p, struct snd_pcm, list); |
| 54 | if (pcm->card == card && pcm->device == device) |
| 55 | return pcm; |
| 56 | } |
| 57 | return NULL; |
| 58 | } |
| 59 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 60 | static int snd_pcm_control_ioctl(struct snd_card *card, |
| 61 | struct snd_ctl_file *control, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | unsigned int cmd, unsigned long arg) |
| 63 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | switch (cmd) { |
| 65 | case SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE: |
| 66 | { |
| 67 | int device; |
| 68 | |
| 69 | if (get_user(device, (int __user *)arg)) |
| 70 | return -EFAULT; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 71 | mutex_lock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | device = device < 0 ? 0 : device + 1; |
| 73 | while (device < SNDRV_PCM_DEVICES) { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 74 | if (snd_pcm_search(card, device)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | break; |
| 76 | device++; |
| 77 | } |
| 78 | if (device == SNDRV_PCM_DEVICES) |
| 79 | device = -1; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 80 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | if (put_user(device, (int __user *)arg)) |
| 82 | return -EFAULT; |
| 83 | return 0; |
| 84 | } |
| 85 | case SNDRV_CTL_IOCTL_PCM_INFO: |
| 86 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 87 | struct snd_pcm_info __user *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | unsigned int device, subdevice; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 89 | int stream; |
| 90 | struct snd_pcm *pcm; |
| 91 | struct snd_pcm_str *pstr; |
| 92 | struct snd_pcm_substream *substream; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 93 | int err; |
| 94 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 95 | info = (struct snd_pcm_info __user *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | if (get_user(device, &info->device)) |
| 97 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | if (get_user(stream, &info->stream)) |
| 99 | return -EFAULT; |
| 100 | if (stream < 0 || stream > 1) |
| 101 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (get_user(subdevice, &info->subdevice)) |
| 103 | return -EFAULT; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 104 | mutex_lock(®ister_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 105 | pcm = snd_pcm_search(card, device); |
| 106 | if (pcm == NULL) { |
| 107 | err = -ENXIO; |
| 108 | goto _error; |
| 109 | } |
| 110 | pstr = &pcm->streams[stream]; |
| 111 | if (pstr->substream_count == 0) { |
| 112 | err = -ENOENT; |
| 113 | goto _error; |
| 114 | } |
| 115 | if (subdevice >= pstr->substream_count) { |
| 116 | err = -ENXIO; |
| 117 | goto _error; |
| 118 | } |
| 119 | for (substream = pstr->substream; substream; |
| 120 | substream = substream->next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if (substream->number == (int)subdevice) |
| 122 | break; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 123 | if (substream == NULL) { |
| 124 | err = -ENXIO; |
| 125 | goto _error; |
| 126 | } |
| 127 | err = snd_pcm_info_user(substream, info); |
| 128 | _error: |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 129 | mutex_unlock(®ister_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 130 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | case SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE: |
| 133 | { |
| 134 | int val; |
| 135 | |
| 136 | if (get_user(val, (int __user *)arg)) |
| 137 | return -EFAULT; |
| 138 | control->prefer_pcm_subdevice = val; |
| 139 | return 0; |
| 140 | } |
| 141 | } |
| 142 | return -ENOIOCTLCMD; |
| 143 | } |
Jaroslav Kysela | 21a3479 | 2006-01-13 09:12:11 +0100 | [diff] [blame] | 144 | |
Takashi Iwai | b7d90a3 | 2006-04-25 12:56:04 +0200 | [diff] [blame] | 145 | #ifdef CONFIG_SND_VERBOSE_PROCFS |
Jaroslav Kysela | 21a3479 | 2006-01-13 09:12:11 +0100 | [diff] [blame] | 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #define STATE(v) [SNDRV_PCM_STATE_##v] = #v |
| 148 | #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v |
| 149 | #define READY(v) [SNDRV_PCM_READY_##v] = #v |
| 150 | #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v |
| 151 | #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v |
| 152 | #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v |
| 153 | #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v |
| 154 | #define START(v) [SNDRV_PCM_START_##v] = #v |
| 155 | #define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v |
| 156 | #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | static char *snd_pcm_format_names[] = { |
| 159 | FORMAT(S8), |
| 160 | FORMAT(U8), |
| 161 | FORMAT(S16_LE), |
| 162 | FORMAT(S16_BE), |
| 163 | FORMAT(U16_LE), |
| 164 | FORMAT(U16_BE), |
| 165 | FORMAT(S24_LE), |
| 166 | FORMAT(S24_BE), |
| 167 | FORMAT(U24_LE), |
| 168 | FORMAT(U24_BE), |
| 169 | FORMAT(S32_LE), |
| 170 | FORMAT(S32_BE), |
| 171 | FORMAT(U32_LE), |
| 172 | FORMAT(U32_BE), |
| 173 | FORMAT(FLOAT_LE), |
| 174 | FORMAT(FLOAT_BE), |
| 175 | FORMAT(FLOAT64_LE), |
| 176 | FORMAT(FLOAT64_BE), |
| 177 | FORMAT(IEC958_SUBFRAME_LE), |
| 178 | FORMAT(IEC958_SUBFRAME_BE), |
| 179 | FORMAT(MU_LAW), |
| 180 | FORMAT(A_LAW), |
| 181 | FORMAT(IMA_ADPCM), |
| 182 | FORMAT(MPEG), |
| 183 | FORMAT(GSM), |
| 184 | FORMAT(SPECIAL), |
| 185 | FORMAT(S24_3LE), |
| 186 | FORMAT(S24_3BE), |
| 187 | FORMAT(U24_3LE), |
| 188 | FORMAT(U24_3BE), |
| 189 | FORMAT(S20_3LE), |
| 190 | FORMAT(S20_3BE), |
| 191 | FORMAT(U20_3LE), |
| 192 | FORMAT(U20_3BE), |
| 193 | FORMAT(S18_3LE), |
| 194 | FORMAT(S18_3BE), |
| 195 | FORMAT(U18_3LE), |
| 196 | FORMAT(U18_3BE), |
| 197 | }; |
| 198 | |
Adrian Bunk | 12831c1 | 2006-04-11 11:12:46 +0200 | [diff] [blame] | 199 | static const char *snd_pcm_format_name(snd_pcm_format_t format) |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 200 | { |
| 201 | return snd_pcm_format_names[format]; |
| 202 | } |
| 203 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 204 | static char *snd_pcm_stream_names[] = { |
| 205 | STREAM(PLAYBACK), |
| 206 | STREAM(CAPTURE), |
| 207 | }; |
| 208 | |
| 209 | static char *snd_pcm_state_names[] = { |
| 210 | STATE(OPEN), |
| 211 | STATE(SETUP), |
| 212 | STATE(PREPARED), |
| 213 | STATE(RUNNING), |
| 214 | STATE(XRUN), |
| 215 | STATE(DRAINING), |
| 216 | STATE(PAUSED), |
| 217 | STATE(SUSPENDED), |
| 218 | }; |
| 219 | |
| 220 | static char *snd_pcm_access_names[] = { |
| 221 | ACCESS(MMAP_INTERLEAVED), |
| 222 | ACCESS(MMAP_NONINTERLEAVED), |
| 223 | ACCESS(MMAP_COMPLEX), |
| 224 | ACCESS(RW_INTERLEAVED), |
| 225 | ACCESS(RW_NONINTERLEAVED), |
| 226 | }; |
| 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | static char *snd_pcm_subformat_names[] = { |
| 229 | SUBFORMAT(STD), |
| 230 | }; |
| 231 | |
| 232 | static char *snd_pcm_tstamp_mode_names[] = { |
| 233 | TSTAMP(NONE), |
| 234 | TSTAMP(MMAP), |
| 235 | }; |
| 236 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 237 | static const char *snd_pcm_stream_name(int stream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | snd_assert(stream <= SNDRV_PCM_STREAM_LAST, return NULL); |
| 240 | return snd_pcm_stream_names[stream]; |
| 241 | } |
| 242 | |
| 243 | static const char *snd_pcm_access_name(snd_pcm_access_t access) |
| 244 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | return snd_pcm_access_names[access]; |
| 246 | } |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat) |
| 249 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return snd_pcm_subformat_names[subformat]; |
| 251 | } |
| 252 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 253 | static const char *snd_pcm_tstamp_mode_name(int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | snd_assert(mode <= SNDRV_PCM_TSTAMP_LAST, return NULL); |
| 256 | return snd_pcm_tstamp_mode_names[mode]; |
| 257 | } |
| 258 | |
| 259 | static const char *snd_pcm_state_name(snd_pcm_state_t state) |
| 260 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return snd_pcm_state_names[state]; |
| 262 | } |
| 263 | |
| 264 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) |
| 265 | #include <linux/soundcard.h> |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | static const char *snd_pcm_oss_format_name(int format) |
| 268 | { |
| 269 | switch (format) { |
| 270 | case AFMT_MU_LAW: |
| 271 | return "MU_LAW"; |
| 272 | case AFMT_A_LAW: |
| 273 | return "A_LAW"; |
| 274 | case AFMT_IMA_ADPCM: |
| 275 | return "IMA_ADPCM"; |
| 276 | case AFMT_U8: |
| 277 | return "U8"; |
| 278 | case AFMT_S16_LE: |
| 279 | return "S16_LE"; |
| 280 | case AFMT_S16_BE: |
| 281 | return "S16_BE"; |
| 282 | case AFMT_S8: |
| 283 | return "S8"; |
| 284 | case AFMT_U16_LE: |
| 285 | return "U16_LE"; |
| 286 | case AFMT_U16_BE: |
| 287 | return "U16_BE"; |
| 288 | case AFMT_MPEG: |
| 289 | return "MPEG"; |
| 290 | default: |
| 291 | return "unknown"; |
| 292 | } |
| 293 | } |
| 294 | #endif |
| 295 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 296 | static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream, |
| 297 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 299 | struct snd_pcm_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | int err; |
| 301 | |
Takashi Iwai | 7c22f1a | 2005-10-10 11:46:31 +0200 | [diff] [blame] | 302 | if (! substream) |
| 303 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 306 | if (! info) { |
| 307 | printk(KERN_DEBUG "snd_pcm_proc_info_read: cannot malloc\n"); |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | err = snd_pcm_info(substream, info); |
| 312 | if (err < 0) { |
| 313 | snd_iprintf(buffer, "error %d\n", err); |
| 314 | kfree(info); |
| 315 | return; |
| 316 | } |
| 317 | snd_iprintf(buffer, "card: %d\n", info->card); |
| 318 | snd_iprintf(buffer, "device: %d\n", info->device); |
| 319 | snd_iprintf(buffer, "subdevice: %d\n", info->subdevice); |
| 320 | snd_iprintf(buffer, "stream: %s\n", snd_pcm_stream_name(info->stream)); |
| 321 | snd_iprintf(buffer, "id: %s\n", info->id); |
| 322 | snd_iprintf(buffer, "name: %s\n", info->name); |
| 323 | snd_iprintf(buffer, "subname: %s\n", info->subname); |
| 324 | snd_iprintf(buffer, "class: %d\n", info->dev_class); |
| 325 | snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass); |
| 326 | snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count); |
| 327 | snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail); |
| 328 | kfree(info); |
| 329 | } |
| 330 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 331 | static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry, |
| 332 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 334 | snd_pcm_proc_info_read(((struct snd_pcm_str *)entry->private_data)->substream, |
| 335 | buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 338 | static void snd_pcm_substream_proc_info_read(struct snd_info_entry *entry, |
| 339 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 341 | snd_pcm_proc_info_read((struct snd_pcm_substream *)entry->private_data, |
| 342 | buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 345 | static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry, |
| 346 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 348 | struct snd_pcm_substream *substream = entry->private_data; |
| 349 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (!runtime) { |
| 351 | snd_iprintf(buffer, "closed\n"); |
| 352 | return; |
| 353 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { |
| 355 | snd_iprintf(buffer, "no setup\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return; |
| 357 | } |
| 358 | snd_iprintf(buffer, "access: %s\n", snd_pcm_access_name(runtime->access)); |
| 359 | snd_iprintf(buffer, "format: %s\n", snd_pcm_format_name(runtime->format)); |
| 360 | snd_iprintf(buffer, "subformat: %s\n", snd_pcm_subformat_name(runtime->subformat)); |
| 361 | snd_iprintf(buffer, "channels: %u\n", runtime->channels); |
| 362 | snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den); |
| 363 | snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size); |
| 364 | snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size); |
| 365 | snd_iprintf(buffer, "tick_time: %u\n", runtime->tick_time); |
| 366 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) |
| 367 | if (substream->oss.oss) { |
| 368 | snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format)); |
| 369 | snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels); |
| 370 | snd_iprintf(buffer, "OSS rate: %u\n", runtime->oss.rate); |
| 371 | snd_iprintf(buffer, "OSS period bytes: %lu\n", (unsigned long)runtime->oss.period_bytes); |
| 372 | snd_iprintf(buffer, "OSS periods: %u\n", runtime->oss.periods); |
| 373 | snd_iprintf(buffer, "OSS period frames: %lu\n", (unsigned long)runtime->oss.period_frames); |
| 374 | } |
| 375 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 378 | static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry, |
| 379 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 381 | struct snd_pcm_substream *substream = entry->private_data; |
| 382 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | if (!runtime) { |
| 384 | snd_iprintf(buffer, "closed\n"); |
| 385 | return; |
| 386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { |
| 388 | snd_iprintf(buffer, "no setup\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return; |
| 390 | } |
| 391 | snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode)); |
| 392 | snd_iprintf(buffer, "period_step: %u\n", runtime->period_step); |
| 393 | snd_iprintf(buffer, "sleep_min: %u\n", runtime->sleep_min); |
| 394 | snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min); |
| 395 | snd_iprintf(buffer, "xfer_align: %lu\n", runtime->xfer_align); |
| 396 | snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold); |
| 397 | snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold); |
| 398 | snd_iprintf(buffer, "silence_threshold: %lu\n", runtime->silence_threshold); |
| 399 | snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size); |
| 400 | snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 403 | static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry, |
| 404 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 406 | struct snd_pcm_substream *substream = entry->private_data; |
| 407 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 408 | struct snd_pcm_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | int err; |
| 410 | if (!runtime) { |
| 411 | snd_iprintf(buffer, "closed\n"); |
| 412 | return; |
| 413 | } |
| 414 | memset(&status, 0, sizeof(status)); |
| 415 | err = snd_pcm_status(substream, &status); |
| 416 | if (err < 0) { |
| 417 | snd_iprintf(buffer, "error %d\n", err); |
| 418 | return; |
| 419 | } |
| 420 | snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state)); |
| 421 | snd_iprintf(buffer, "trigger_time: %ld.%09ld\n", |
| 422 | status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec); |
| 423 | snd_iprintf(buffer, "tstamp : %ld.%09ld\n", |
| 424 | status.tstamp.tv_sec, status.tstamp.tv_nsec); |
| 425 | snd_iprintf(buffer, "delay : %ld\n", status.delay); |
| 426 | snd_iprintf(buffer, "avail : %ld\n", status.avail); |
| 427 | snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max); |
| 428 | snd_iprintf(buffer, "-----\n"); |
| 429 | snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr); |
| 430 | snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr); |
| 431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Jaroslav Kysela | 61fb63c | 2006-04-24 21:57:16 +0200 | [diff] [blame] | 433 | #ifdef CONFIG_SND_PCM_XRUN_DEBUG |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 434 | static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry, |
| 435 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 437 | struct snd_pcm_str *pstr = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | snd_iprintf(buffer, "%d\n", pstr->xrun_debug); |
| 439 | } |
| 440 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 441 | static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry, |
| 442 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 444 | struct snd_pcm_str *pstr = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | char line[64]; |
| 446 | if (!snd_info_get_line(buffer, line, sizeof(line))) |
| 447 | pstr->xrun_debug = simple_strtoul(line, NULL, 10); |
| 448 | } |
| 449 | #endif |
| 450 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 451 | static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 453 | struct snd_pcm *pcm = pstr->pcm; |
| 454 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | char name[16]; |
| 456 | |
| 457 | sprintf(name, "pcm%i%c", pcm->device, |
| 458 | pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c'); |
| 459 | if ((entry = snd_info_create_card_entry(pcm->card, name, pcm->card->proc_root)) == NULL) |
| 460 | return -ENOMEM; |
| 461 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 462 | if (snd_info_register(entry) < 0) { |
| 463 | snd_info_free_entry(entry); |
| 464 | return -ENOMEM; |
| 465 | } |
| 466 | pstr->proc_root = entry; |
| 467 | |
| 468 | if ((entry = snd_info_create_card_entry(pcm->card, "info", pstr->proc_root)) != NULL) { |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 469 | snd_info_set_text_ops(entry, pstr, snd_pcm_stream_proc_info_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (snd_info_register(entry) < 0) { |
| 471 | snd_info_free_entry(entry); |
| 472 | entry = NULL; |
| 473 | } |
| 474 | } |
| 475 | pstr->proc_info_entry = entry; |
| 476 | |
Jaroslav Kysela | 61fb63c | 2006-04-24 21:57:16 +0200 | [diff] [blame] | 477 | #ifdef CONFIG_SND_PCM_XRUN_DEBUG |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 478 | if ((entry = snd_info_create_card_entry(pcm->card, "xrun_debug", |
| 479 | pstr->proc_root)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | entry->c.text.read = snd_pcm_xrun_debug_read; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | entry->c.text.write = snd_pcm_xrun_debug_write; |
Takashi Iwai | bd7bf04 | 2005-04-12 16:27:28 +0200 | [diff] [blame] | 482 | entry->mode |= S_IWUSR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | entry->private_data = pstr; |
| 484 | if (snd_info_register(entry) < 0) { |
| 485 | snd_info_free_entry(entry); |
| 486 | entry = NULL; |
| 487 | } |
| 488 | } |
| 489 | pstr->proc_xrun_debug_entry = entry; |
| 490 | #endif |
| 491 | return 0; |
| 492 | } |
| 493 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 494 | static int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
Jaroslav Kysela | 61fb63c | 2006-04-24 21:57:16 +0200 | [diff] [blame] | 496 | #ifdef CONFIG_SND_PCM_XRUN_DEBUG |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame^] | 497 | snd_info_free_entry(pstr->proc_xrun_debug_entry); |
| 498 | pstr->proc_xrun_debug_entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | #endif |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame^] | 500 | snd_info_free_entry(pstr->proc_info_entry); |
| 501 | pstr->proc_info_entry = NULL; |
| 502 | snd_info_free_entry(pstr->proc_root); |
| 503 | pstr->proc_root = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 507 | static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 509 | struct snd_info_entry *entry; |
| 510 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | char name[16]; |
| 512 | |
| 513 | card = substream->pcm->card; |
| 514 | |
| 515 | sprintf(name, "sub%i", substream->number); |
| 516 | if ((entry = snd_info_create_card_entry(card, name, substream->pstr->proc_root)) == NULL) |
| 517 | return -ENOMEM; |
| 518 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 519 | if (snd_info_register(entry) < 0) { |
| 520 | snd_info_free_entry(entry); |
| 521 | return -ENOMEM; |
| 522 | } |
| 523 | substream->proc_root = entry; |
| 524 | |
| 525 | if ((entry = snd_info_create_card_entry(card, "info", substream->proc_root)) != NULL) { |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 526 | snd_info_set_text_ops(entry, substream, |
| 527 | snd_pcm_substream_proc_info_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | if (snd_info_register(entry) < 0) { |
| 529 | snd_info_free_entry(entry); |
| 530 | entry = NULL; |
| 531 | } |
| 532 | } |
| 533 | substream->proc_info_entry = entry; |
| 534 | |
| 535 | if ((entry = snd_info_create_card_entry(card, "hw_params", substream->proc_root)) != NULL) { |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 536 | snd_info_set_text_ops(entry, substream, |
| 537 | snd_pcm_substream_proc_hw_params_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | if (snd_info_register(entry) < 0) { |
| 539 | snd_info_free_entry(entry); |
| 540 | entry = NULL; |
| 541 | } |
| 542 | } |
| 543 | substream->proc_hw_params_entry = entry; |
| 544 | |
| 545 | if ((entry = snd_info_create_card_entry(card, "sw_params", substream->proc_root)) != NULL) { |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 546 | snd_info_set_text_ops(entry, substream, |
| 547 | snd_pcm_substream_proc_sw_params_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (snd_info_register(entry) < 0) { |
| 549 | snd_info_free_entry(entry); |
| 550 | entry = NULL; |
| 551 | } |
| 552 | } |
| 553 | substream->proc_sw_params_entry = entry; |
| 554 | |
| 555 | if ((entry = snd_info_create_card_entry(card, "status", substream->proc_root)) != NULL) { |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 556 | snd_info_set_text_ops(entry, substream, |
| 557 | snd_pcm_substream_proc_status_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | if (snd_info_register(entry) < 0) { |
| 559 | snd_info_free_entry(entry); |
| 560 | entry = NULL; |
| 561 | } |
| 562 | } |
| 563 | substream->proc_status_entry = entry; |
| 564 | |
| 565 | return 0; |
| 566 | } |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame^] | 567 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 568 | static int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | { |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame^] | 570 | snd_info_free_entry(substream->proc_info_entry); |
| 571 | substream->proc_info_entry = NULL; |
| 572 | snd_info_free_entry(substream->proc_hw_params_entry); |
| 573 | substream->proc_hw_params_entry = NULL; |
| 574 | snd_info_free_entry(substream->proc_sw_params_entry); |
| 575 | substream->proc_sw_params_entry = NULL; |
| 576 | snd_info_free_entry(substream->proc_status_entry); |
| 577 | substream->proc_status_entry = NULL; |
| 578 | snd_info_free_entry(substream->proc_root); |
| 579 | substream->proc_root = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | return 0; |
| 581 | } |
Takashi Iwai | b7d90a3 | 2006-04-25 12:56:04 +0200 | [diff] [blame] | 582 | #else /* !CONFIG_SND_VERBOSE_PROCFS */ |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 583 | static inline int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) { return 0; } |
| 584 | static inline int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) { return 0; } |
| 585 | static inline int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) { return 0; } |
| 586 | static inline int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream) { return 0; } |
Takashi Iwai | b7d90a3 | 2006-04-25 12:56:04 +0200 | [diff] [blame] | 587 | #endif /* CONFIG_SND_VERBOSE_PROCFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | /** |
| 590 | * snd_pcm_new_stream - create a new PCM stream |
| 591 | * @pcm: the pcm instance |
| 592 | * @stream: the stream direction, SNDRV_PCM_STREAM_XXX |
| 593 | * @substream_count: the number of substreams |
| 594 | * |
| 595 | * Creates a new stream for the pcm. |
| 596 | * The corresponding stream on the pcm must have been empty before |
| 597 | * calling this, i.e. zero must be given to the argument of |
| 598 | * snd_pcm_new(). |
| 599 | * |
| 600 | * Returns zero if successful, or a negative error code on failure. |
| 601 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 602 | int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
| 604 | int idx, err; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 605 | struct snd_pcm_str *pstr = &pcm->streams[stream]; |
| 606 | struct snd_pcm_substream *substream, *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 609 | mutex_init(&pstr->oss.setup_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | #endif |
| 611 | pstr->stream = stream; |
| 612 | pstr->pcm = pcm; |
| 613 | pstr->substream_count = substream_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | if (substream_count > 0) { |
| 615 | err = snd_pcm_stream_proc_init(pstr); |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 616 | if (err < 0) { |
| 617 | snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | return err; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | prev = NULL; |
| 622 | for (idx = 0, prev = NULL; idx < substream_count; idx++) { |
Takashi Iwai | ca2c096 | 2005-09-09 14:20:23 +0200 | [diff] [blame] | 623 | substream = kzalloc(sizeof(*substream), GFP_KERNEL); |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 624 | if (substream == NULL) { |
| 625 | snd_printk(KERN_ERR "Cannot allocate PCM substream\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return -ENOMEM; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | substream->pcm = pcm; |
| 629 | substream->pstr = pstr; |
| 630 | substream->number = idx; |
| 631 | substream->stream = stream; |
| 632 | sprintf(substream->name, "subdevice #%i", idx); |
| 633 | substream->buffer_bytes_max = UINT_MAX; |
| 634 | if (prev == NULL) |
| 635 | pstr->substream = substream; |
| 636 | else |
| 637 | prev->next = substream; |
| 638 | err = snd_pcm_substream_proc_init(substream); |
| 639 | if (err < 0) { |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 640 | snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | kfree(substream); |
| 642 | return err; |
| 643 | } |
| 644 | substream->group = &substream->self_group; |
| 645 | spin_lock_init(&substream->self_group.lock); |
| 646 | INIT_LIST_HEAD(&substream->self_group.substreams); |
| 647 | list_add_tail(&substream->link_list, &substream->self_group.substreams); |
| 648 | spin_lock_init(&substream->timer_lock); |
Takashi Iwai | 9c323fc | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 649 | atomic_set(&substream->mmap_count, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | prev = substream; |
| 651 | } |
| 652 | return 0; |
| 653 | } |
| 654 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 655 | EXPORT_SYMBOL(snd_pcm_new_stream); |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /** |
| 658 | * snd_pcm_new - create a new PCM instance |
| 659 | * @card: the card instance |
| 660 | * @id: the id string |
| 661 | * @device: the device index (zero based) |
| 662 | * @playback_count: the number of substreams for playback |
| 663 | * @capture_count: the number of substreams for capture |
| 664 | * @rpcm: the pointer to store the new pcm instance |
| 665 | * |
| 666 | * Creates a new PCM instance. |
| 667 | * |
| 668 | * The pcm operators have to be set afterwards to the new instance |
| 669 | * via snd_pcm_set_ops(). |
| 670 | * |
| 671 | * Returns zero if successful, or a negative error code on failure. |
| 672 | */ |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 673 | int snd_pcm_new(struct snd_card *card, char *id, int device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | int playback_count, int capture_count, |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 675 | struct snd_pcm ** rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 677 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | int err; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 679 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | .dev_free = snd_pcm_dev_free, |
| 681 | .dev_register = snd_pcm_dev_register, |
| 682 | .dev_disconnect = snd_pcm_dev_disconnect, |
| 683 | .dev_unregister = snd_pcm_dev_unregister |
| 684 | }; |
| 685 | |
| 686 | snd_assert(rpcm != NULL, return -EINVAL); |
| 687 | *rpcm = NULL; |
| 688 | snd_assert(card != NULL, return -ENXIO); |
Takashi Iwai | ca2c096 | 2005-09-09 14:20:23 +0200 | [diff] [blame] | 689 | pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 690 | if (pcm == NULL) { |
| 691 | snd_printk(KERN_ERR "Cannot allocate PCM\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | return -ENOMEM; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | pcm->card = card; |
| 695 | pcm->device = device; |
Takashi Iwai | 73e77ba | 2005-11-17 17:44:01 +0100 | [diff] [blame] | 696 | if (id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | strlcpy(pcm->id, id, sizeof(pcm->id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { |
| 699 | snd_pcm_free(pcm); |
| 700 | return err; |
| 701 | } |
| 702 | if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) { |
| 703 | snd_pcm_free(pcm); |
| 704 | return err; |
| 705 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 706 | mutex_init(&pcm->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | init_waitqueue_head(&pcm->open_wait); |
| 708 | if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) { |
| 709 | snd_pcm_free(pcm); |
| 710 | return err; |
| 711 | } |
| 712 | *rpcm = pcm; |
| 713 | return 0; |
| 714 | } |
| 715 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 716 | EXPORT_SYMBOL(snd_pcm_new); |
| 717 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 718 | static void snd_pcm_free_stream(struct snd_pcm_str * pstr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 720 | struct snd_pcm_substream *substream, *substream_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 722 | struct snd_pcm_oss_setup *setup, *setupn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | #endif |
| 724 | substream = pstr->substream; |
| 725 | while (substream) { |
| 726 | substream_next = substream->next; |
| 727 | snd_pcm_substream_proc_done(substream); |
| 728 | kfree(substream); |
| 729 | substream = substream_next; |
| 730 | } |
| 731 | snd_pcm_stream_proc_done(pstr); |
| 732 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) |
| 733 | for (setup = pstr->oss.setup_list; setup; setup = setupn) { |
| 734 | setupn = setup->next; |
| 735 | kfree(setup->task_name); |
| 736 | kfree(setup); |
| 737 | } |
| 738 | #endif |
| 739 | } |
| 740 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 741 | static int snd_pcm_free(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { |
| 743 | snd_assert(pcm != NULL, return -ENXIO); |
| 744 | if (pcm->private_free) |
| 745 | pcm->private_free(pcm); |
| 746 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 747 | snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]); |
| 748 | snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]); |
| 749 | kfree(pcm); |
| 750 | return 0; |
| 751 | } |
| 752 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 753 | static int snd_pcm_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 755 | struct snd_pcm *pcm = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | return snd_pcm_free(pcm); |
| 757 | } |
| 758 | |
| 759 | static void snd_pcm_tick_timer_func(unsigned long data) |
| 760 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 761 | struct snd_pcm_substream *substream = (struct snd_pcm_substream *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | snd_pcm_tick_elapsed(substream); |
| 763 | } |
| 764 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 765 | int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, |
| 766 | struct file *file, |
| 767 | struct snd_pcm_substream **rsubstream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 769 | struct snd_pcm_str * pstr; |
| 770 | struct snd_pcm_substream *substream; |
| 771 | struct snd_pcm_runtime *runtime; |
| 772 | struct snd_ctl_file *kctl; |
| 773 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | struct list_head *list; |
| 775 | int prefer_subdevice = -1; |
| 776 | size_t size; |
| 777 | |
| 778 | snd_assert(rsubstream != NULL, return -EINVAL); |
| 779 | *rsubstream = NULL; |
| 780 | snd_assert(pcm != NULL, return -ENXIO); |
| 781 | pstr = &pcm->streams[stream]; |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 782 | if (pstr->substream == NULL || pstr->substream_count == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | return -ENODEV; |
| 784 | |
| 785 | card = pcm->card; |
| 786 | down_read(&card->controls_rwsem); |
| 787 | list_for_each(list, &card->ctl_files) { |
| 788 | kctl = snd_ctl_file(list); |
| 789 | if (kctl->pid == current->pid) { |
| 790 | prefer_subdevice = kctl->prefer_pcm_subdevice; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | up_read(&card->controls_rwsem); |
| 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | switch (stream) { |
| 797 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 798 | if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { |
| 799 | for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) { |
| 800 | if (SUBSTREAM_BUSY(substream)) |
| 801 | return -EAGAIN; |
| 802 | } |
| 803 | } |
| 804 | break; |
| 805 | case SNDRV_PCM_STREAM_CAPTURE: |
| 806 | if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) { |
| 807 | for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) { |
| 808 | if (SUBSTREAM_BUSY(substream)) |
| 809 | return -EAGAIN; |
| 810 | } |
| 811 | } |
| 812 | break; |
| 813 | default: |
| 814 | return -EINVAL; |
| 815 | } |
| 816 | |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 817 | if (file->f_flags & O_APPEND) { |
| 818 | if (prefer_subdevice < 0) { |
| 819 | if (pstr->substream_count > 1) |
| 820 | return -EINVAL; /* must be unique */ |
| 821 | substream = pstr->substream; |
| 822 | } else { |
| 823 | for (substream = pstr->substream; substream; |
| 824 | substream = substream->next) |
| 825 | if (substream->number == prefer_subdevice) |
| 826 | break; |
| 827 | } |
| 828 | if (! substream) |
| 829 | return -ENODEV; |
| 830 | if (! SUBSTREAM_BUSY(substream)) |
| 831 | return -EBADFD; |
| 832 | substream->ref_count++; |
| 833 | *rsubstream = substream; |
| 834 | return 0; |
| 835 | } |
| 836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | if (prefer_subdevice >= 0) { |
| 838 | for (substream = pstr->substream; substream; substream = substream->next) |
| 839 | if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice) |
| 840 | goto __ok; |
| 841 | } |
| 842 | for (substream = pstr->substream; substream; substream = substream->next) |
| 843 | if (!SUBSTREAM_BUSY(substream)) |
| 844 | break; |
| 845 | __ok: |
| 846 | if (substream == NULL) |
| 847 | return -EAGAIN; |
| 848 | |
Takashi Iwai | ca2c096 | 2005-09-09 14:20:23 +0200 | [diff] [blame] | 849 | runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | if (runtime == NULL) |
| 851 | return -ENOMEM; |
| 852 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 853 | size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | runtime->status = snd_malloc_pages(size, GFP_KERNEL); |
| 855 | if (runtime->status == NULL) { |
| 856 | kfree(runtime); |
| 857 | return -ENOMEM; |
| 858 | } |
| 859 | memset((void*)runtime->status, 0, size); |
| 860 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 861 | size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | runtime->control = snd_malloc_pages(size, GFP_KERNEL); |
| 863 | if (runtime->control == NULL) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 864 | snd_free_pages((void*)runtime->status, |
| 865 | PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | kfree(runtime); |
| 867 | return -ENOMEM; |
| 868 | } |
| 869 | memset((void*)runtime->control, 0, size); |
| 870 | |
| 871 | init_waitqueue_head(&runtime->sleep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | init_timer(&runtime->tick_timer); |
| 873 | runtime->tick_timer.function = snd_pcm_tick_timer_func; |
| 874 | runtime->tick_timer.data = (unsigned long) substream; |
| 875 | |
| 876 | runtime->status->state = SNDRV_PCM_STATE_OPEN; |
| 877 | |
| 878 | substream->runtime = runtime; |
| 879 | substream->private_data = pcm->private_data; |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 880 | substream->ref_count = 1; |
| 881 | substream->f_flags = file->f_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | pstr->substream_opened++; |
| 883 | *rsubstream = substream; |
| 884 | return 0; |
| 885 | } |
| 886 | |
Takashi Iwai | 3bf75f9 | 2006-03-27 16:40:49 +0200 | [diff] [blame] | 887 | void snd_pcm_detach_substream(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 889 | struct snd_pcm_runtime *runtime; |
Takashi Iwai | 0df63e4 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | runtime = substream->runtime; |
| 892 | snd_assert(runtime != NULL, return); |
| 893 | if (runtime->private_free != NULL) |
| 894 | runtime->private_free(runtime); |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 895 | snd_free_pages((void*)runtime->status, |
| 896 | PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))); |
| 897 | snd_free_pages((void*)runtime->control, |
| 898 | PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | kfree(runtime->hw_constraints.rules); |
| 900 | kfree(runtime); |
| 901 | substream->runtime = NULL; |
| 902 | substream->pstr->substream_opened--; |
| 903 | } |
| 904 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 905 | static int snd_pcm_dev_register(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 907 | int cidx, err; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 908 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | struct list_head *list; |
| 910 | char str[16]; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 911 | struct snd_pcm *pcm = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | snd_assert(pcm != NULL && device != NULL, return -ENXIO); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 914 | mutex_lock(®ister_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 915 | if (snd_pcm_search(pcm->card, pcm->device)) { |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 916 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | return -EBUSY; |
| 918 | } |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 919 | list_add_tail(&pcm->list, &snd_pcm_devices); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | for (cidx = 0; cidx < 2; cidx++) { |
| 921 | int devtype = -1; |
| 922 | if (pcm->streams[cidx].substream == NULL) |
| 923 | continue; |
| 924 | switch (cidx) { |
| 925 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 926 | sprintf(str, "pcmC%iD%ip", pcm->card->number, pcm->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK; |
| 928 | break; |
| 929 | case SNDRV_PCM_STREAM_CAPTURE: |
| 930 | sprintf(str, "pcmC%iD%ic", pcm->card->number, pcm->device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE; |
| 932 | break; |
| 933 | } |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 934 | if ((err = snd_register_device(devtype, pcm->card, |
| 935 | pcm->device, |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 936 | &snd_pcm_f_ops[cidx], |
| 937 | pcm, str)) < 0) |
Clemens Ladisch | 2af677f | 2005-11-20 14:03:48 +0100 | [diff] [blame] | 938 | { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 939 | list_del(&pcm->list); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 940 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | return err; |
| 942 | } |
| 943 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) |
| 944 | snd_pcm_timer_init(substream); |
| 945 | } |
| 946 | list_for_each(list, &snd_pcm_notify_list) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 947 | struct snd_pcm_notify *notify; |
| 948 | notify = list_entry(list, struct snd_pcm_notify, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | notify->n_register(pcm); |
| 950 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 951 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | return 0; |
| 953 | } |
| 954 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 955 | static int snd_pcm_dev_disconnect(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 957 | struct snd_pcm *pcm = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | struct list_head *list; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 959 | struct snd_pcm_substream *substream; |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 960 | int cidx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 962 | mutex_lock(®ister_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 963 | list_del_init(&pcm->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | for (cidx = 0; cidx < 2; cidx++) |
| 965 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) |
| 966 | if (substream->runtime) |
| 967 | substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED; |
| 968 | list_for_each(list, &snd_pcm_notify_list) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 969 | struct snd_pcm_notify *notify; |
| 970 | notify = list_entry(list, struct snd_pcm_notify, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | notify->n_disconnect(pcm); |
| 972 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 973 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 977 | static int snd_pcm_dev_unregister(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 979 | int cidx, devtype; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 980 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | struct list_head *list; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 982 | struct snd_pcm *pcm = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | snd_assert(pcm != NULL, return -ENXIO); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 985 | mutex_lock(®ister_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 986 | list_del(&pcm->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | for (cidx = 0; cidx < 2; cidx++) { |
| 988 | devtype = -1; |
| 989 | switch (cidx) { |
| 990 | case SNDRV_PCM_STREAM_PLAYBACK: |
| 991 | devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK; |
| 992 | break; |
| 993 | case SNDRV_PCM_STREAM_CAPTURE: |
| 994 | devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE; |
| 995 | break; |
| 996 | } |
| 997 | snd_unregister_device(devtype, pcm->card, pcm->device); |
| 998 | for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) |
| 999 | snd_pcm_timer_done(substream); |
| 1000 | } |
| 1001 | list_for_each(list, &snd_pcm_notify_list) { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1002 | struct snd_pcm_notify *notify; |
| 1003 | notify = list_entry(list, struct snd_pcm_notify, list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | notify->n_unregister(pcm); |
| 1005 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 1006 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | return snd_pcm_free(pcm); |
| 1008 | } |
| 1009 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1010 | int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1012 | struct list_head *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
| 1014 | snd_assert(notify != NULL && notify->n_register != NULL && notify->n_unregister != NULL, return -EINVAL); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 1015 | mutex_lock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | if (nfree) { |
| 1017 | list_del(¬ify->list); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1018 | list_for_each(p, &snd_pcm_devices) |
| 1019 | notify->n_unregister(list_entry(p, |
| 1020 | struct snd_pcm, list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } else { |
| 1022 | list_add_tail(¬ify->list, &snd_pcm_notify_list); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1023 | list_for_each(p, &snd_pcm_devices) |
| 1024 | notify->n_register(list_entry(p, struct snd_pcm, list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 1026 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | |
Takashi Iwai | e88e8ae6 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 1030 | EXPORT_SYMBOL(snd_pcm_notify); |
| 1031 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 1032 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | /* |
| 1034 | * Info interface |
| 1035 | */ |
| 1036 | |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1037 | static void snd_pcm_proc_read(struct snd_info_entry *entry, |
| 1038 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | { |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1040 | struct list_head *p; |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1041 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 1043 | mutex_lock(®ister_mutex); |
Clemens Ladisch | f87135f | 2005-11-20 14:06:59 +0100 | [diff] [blame] | 1044 | list_for_each(p, &snd_pcm_devices) { |
| 1045 | pcm = list_entry(p, struct snd_pcm, list); |
| 1046 | snd_iprintf(buffer, "%02i-%02i: %s : %s", |
| 1047 | pcm->card->number, pcm->device, pcm->id, pcm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1049 | snd_iprintf(buffer, " : playback %i", |
| 1050 | pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1052 | snd_iprintf(buffer, " : capture %i", |
| 1053 | pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | snd_iprintf(buffer, "\n"); |
| 1055 | } |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 1056 | mutex_unlock(®ister_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 1059 | static struct snd_info_entry *snd_pcm_proc_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 1061 | static void snd_pcm_proc_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
Takashi Iwai | 877211f | 2005-11-17 13:59:38 +0100 | [diff] [blame] | 1063 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | if ((entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL)) != NULL) { |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1066 | snd_info_set_text_ops(entry, NULL, snd_pcm_proc_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | if (snd_info_register(entry) < 0) { |
| 1068 | snd_info_free_entry(entry); |
| 1069 | entry = NULL; |
| 1070 | } |
| 1071 | } |
| 1072 | snd_pcm_proc_entry = entry; |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | static void snd_pcm_proc_done(void) |
| 1076 | { |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame^] | 1077 | snd_info_free_entry(snd_pcm_proc_entry); |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | #else /* !CONFIG_PROC_FS */ |
| 1081 | #define snd_pcm_proc_init() |
| 1082 | #define snd_pcm_proc_done() |
| 1083 | #endif /* CONFIG_PROC_FS */ |
| 1084 | |
| 1085 | |
| 1086 | /* |
| 1087 | * ENTRY functions |
| 1088 | */ |
| 1089 | |
| 1090 | static int __init alsa_pcm_init(void) |
| 1091 | { |
| 1092 | snd_ctl_register_ioctl(snd_pcm_control_ioctl); |
| 1093 | snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl); |
| 1094 | snd_pcm_proc_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | static void __exit alsa_pcm_exit(void) |
| 1099 | { |
| 1100 | snd_ctl_unregister_ioctl(snd_pcm_control_ioctl); |
| 1101 | snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl); |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 1102 | snd_pcm_proc_done(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | module_init(alsa_pcm_init) |
| 1106 | module_exit(alsa_pcm_exit) |