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