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